Source for org.jfree.report.structure.Node

   1: /**
   2:  * ========================================
   3:  * JFreeReport : a free Java report library
   4:  * ========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/
   7:  *
   8:  * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * $Id: Node.java 2725 2007-04-01 18:49:29Z taqua $
  27:  * ------------
  28:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  29:  * (C) Copyright 2005-2007, by Pentaho Corporation.
  30:  */
  31: package org.jfree.report.structure;
  32: 
  33: import java.io.Serializable;
  34: import java.util.Locale;
  35: 
  36: import org.jfree.report.JFreeReport;
  37: import org.jfree.report.expressions.Expression;
  38: 
  39: /**
  40:  * A node is the most basic unit in a report. It acts as general superclass for
  41:  * all other elements.
  42:  *
  43:  * @author Thomas Morgner
  44:  */
  45: public abstract class Node implements Serializable, Cloneable
  46: {
  47:   private Node parent;
  48: 
  49:   protected Node()
  50:   {
  51:   }
  52: 
  53:   public Node getParent()
  54:   {
  55:     return parent;
  56:   }
  57: 
  58:   protected void setParent(final Node parent)
  59:   {
  60:     this.parent = parent;
  61:   }
  62: 
  63:   /**
  64:    * This is an extra method to allow me to track all *illegal* write-accesses
  65:    * to the parent.
  66:    *
  67:    * @param parent
  68:    */
  69:   public void updateParent(final Node parent)
  70:   {
  71:     this.parent = parent;
  72:   }
  73: 
  74:   public Group getGroup()
  75:   {
  76:     Node parent = getParent();
  77:     while (parent != null)
  78:     {
  79:       if (parent instanceof Group)
  80:       {
  81:         return (Group) parent;
  82:       }
  83: 
  84:       parent = parent.getParent();
  85:     }
  86:     return null;
  87:   }
  88: 
  89:   public ReportDefinition getReport()
  90:   {
  91:     Node parent = getParent();
  92:     while (parent != null)
  93:     {
  94:       if (parent instanceof ReportDefinition)
  95:       {
  96:         return (ReportDefinition) parent;
  97:       }
  98: 
  99:       parent = parent.getParent();
 100:     }
 101:     return null;
 102:   }
 103: 
 104:   public JFreeReport getRootReport()
 105:   {
 106:     Node parent = getParent();
 107:     while (parent != null)
 108:     {
 109:       if (parent instanceof JFreeReport)
 110:       {
 111:         return (JFreeReport) parent;
 112:       }
 113: 
 114:       parent = parent.getParent();
 115:     }
 116:     return null;
 117:   }
 118: 
 119:   public Locale getLocale()
 120:   {
 121:     if (parent != null)
 122:     {
 123:       return parent.getLocale();
 124:     }
 125:     return Locale.getDefault();
 126:   }
 127: 
 128:   public Expression getDisplayCondition()
 129:   {
 130:     return null;
 131:   }
 132: 
 133:   public boolean isEnabled()
 134:   {
 135:     return true;
 136:   }
 137: 
 138:   public Object clone () throws CloneNotSupportedException
 139:   {
 140:     return super.clone();
 141:   }
 142: }