001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * SpacerRenderNode.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout.model;
030:
031: import org.jfree.report.layout.style.SimpleStyleSheet;
032:
033: /**
034: * A spacer reserves space for whitespaces found in the text. When encountered
035: * at the beginning or end of lines, it gets removed.
036: * <p/>
037: * Spacers are always considered discardable, so when encountered alone, they
038: * will get pruned.
039: *
040: * @author Thomas Morgner
041: */
042: public class SpacerRenderNode extends RenderNode {
043: private boolean empty;
044: private boolean preserve;
045: private int spaceCount;
046:
047: public SpacerRenderNode() {
048: this (0, 0, false, 0);
049: }
050:
051: public SpacerRenderNode(final long width, final long height,
052: final boolean preserve, final int spaceCount) {
053: super (SimpleStyleSheet.EMPTY_STYLE);
054: this .preserve = preserve;
055: this .spaceCount = spaceCount;
056: setMaximumBoxWidth(width);
057: setMinimumChunkWidth(0);
058: empty = width == 0 && height == 0;
059:
060: // Major axis: All child boxes are placed from left-to-right
061: setMajorAxis(HORIZONTAL_AXIS);
062: // Minor: The childs might be aligned on their position (shifted up or down)
063: setMinorAxis(VERTICAL_AXIS);
064:
065: }
066:
067: /**
068: * Returns the number of space-characters that resulted in this spacer-node. This is a content-creator hint to make
069: * sure that the table-exports can create the represented space more easily. A space-count of zero means, that the
070: * value is not known. In that case a renderer should apply some font-metrics magic to compute a suitable space
071: * count from the known style information.
072: *
073: * @return the space count.
074: */
075: public int getSpaceCount() {
076: return spaceCount;
077: }
078:
079: public boolean isEmpty() {
080: return empty;
081: }
082:
083: public boolean isDiscardable() {
084: return preserve == false;
085: }
086:
087: /**
088: * If that method returns true, the element will not be used for rendering.
089: * For the purpose of computing sizes or performing the layouting (in the
090: * validate() step), this element will treated as if it is not there.
091: * <p/>
092: * If the element reports itself as non-empty, however, it will affect the
093: * margin computation.
094: *
095: * @return
096: */
097: public boolean isIgnorableForRendering() {
098: return true;
099: }
100:
101: }
|