1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
|
/**
* ===========================================
* LibLayout : a free Java layouting library
* ===========================================
*
* Project Info: http://reporting.pentaho.org/liblayout/
*
* (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------
* $Id: RenderNode.java 3524 2007-10-16 11:26:31Z tmorgner $
* ------------
* (C) Copyright 2006-2007, by Pentaho Corporation.
*/
package org.jfree.layouting.renderer.model;
import org.jfree.layouting.input.style.keys.line.LineStyleKeys;
import org.jfree.layouting.input.style.values.CSSNumericValue;
import org.jfree.layouting.input.style.values.CSSValue;
import org.jfree.layouting.layouter.context.LayoutContext;
import org.jfree.layouting.layouter.context.PageContext;
import org.jfree.layouting.output.OutputProcessorMetaData;
import org.jfree.layouting.renderer.border.RenderLength;
import org.jfree.layouting.renderer.model.page.LogicalPageBox;
/**
* A node of the rendering model. The renderer model keeps track of the
* rendering state - what has already been rendered, what is pending, etc.
* Things that have been rendered completely get removed from the model.
* <p/>
* The default model makes some assumptions about the node processing:
* <p/>
* <ul> <li>Once placed somewhere, nodes will never move anywhere else</li>
* <li>Once size computation is complete, nodes will not be modified
* anymore.</li> </ul>
* <p/>
* Finished nodes can be removed as soon as they have been physically rendered.
* <p/>
* In case a node cannot be rendered right now (think of tables, which need all
* cells before a row or in some cases even the columns can be computed), a cell
* receives the 'pending' flag. If a cell is added to a parent which is pending,
* the cell is pending as well. The pending state must be resolved by the
* outer-most element. An element cannot be finished or removed unless it
* resolved the pending state.
*
* @author Thomas Morgner
*/
public abstract class RenderNode implements Cloneable
{
public static final int HORIZONTAL_AXIS = 0;
public static final int VERTICAL_AXIS = 1;
private RenderBox parent;
private RenderNode prev;
private RenderNode next;
private long changeTracker;
// The element's positions.
private long width;
private long height;
private long x;
private long y;
private boolean frozen;
private boolean hibernated;
private Object instanceId;
private NodeLayoutProperties layoutProperties;
private LayoutContext layoutContext;
private boolean dirty;
private long maximumBoxWidth;
private long minimumChunkWidth;
private boolean icmMetricsFinished;
private long stickyMarker;
private ComputedLayoutProperties computedLayoutProperties;
public RenderNode()
{
this.instanceId = new Object();
this.layoutProperties = new NodeLayoutProperties();
}
public void appyStyle(final LayoutContext context, final OutputProcessorMetaData metaData)
{
this.layoutProperties.setAlignmentBaseline
(context.getValue(LineStyleKeys.ALIGNMENT_BASELINE));
final CSSValue alignmentAdjust = context.getValue(LineStyleKeys.ALIGNMENT_ADJUST);
this.layoutProperties.setAlignmentAdjust(alignmentAdjust);
if (alignmentAdjust instanceof CSSNumericValue)
{
this.layoutProperties.setAlignmentAdjustResolved
(RenderLength.convertToInternal (alignmentAdjust, context, metaData));
}
final CSSValue baselineShift = context.getValue(LineStyleKeys.BASELINE_SHIFT);
this.layoutProperties.setBaselineShift(baselineShift);
if (baselineShift instanceof CSSNumericValue)
{
this.layoutProperties.setBaselineShiftResolved(
RenderLength.convertToInternal(baselineShift, context, metaData));
}
this.layoutProperties.setVerticalAlignment
(normalizeAlignment(context.getValue(LineStyleKeys.VERTICAL_ALIGN)));
this.layoutProperties.setNamespace(context.getNamespace());
this.layoutProperties.setTagName (context.getTagName());
this.layoutContext = context;
}
public ComputedLayoutProperties getComputedLayoutProperties()
{
return computedLayoutProperties;
}
public void setComputedLayoutProperties(final ComputedLayoutProperties clp)
{
this.computedLayoutProperties = clp;
}
public LayoutContext getLayoutContext()
{
return layoutContext;
}
public boolean isDirty()
{
return dirty;
}
public void setDirty(final boolean dirty)
{
this.dirty = dirty;
}
public String getNamespace()
{
return layoutProperties.getNamespace();
}
public String getTagName()
{
return layoutProperties.getTagName();
}
protected CSSValue normalizeAlignment(final CSSValue verticalAlignment)
{
return verticalAlignment;
}
public CSSValue getVerticalAlignment()
{
return layoutProperties.getVerticalAlignment();
}
public RenderLength getBaselineShiftResolved()
{
return layoutProperties.getBaselineShiftResolved();
}
public CSSValue getAlignmentBaseline()
{
return layoutProperties.getAlignmentBaseline();
}
public CSSValue getBaselineShift()
{
return layoutProperties.getBaselineShift();
}
public CSSValue getAlignmentAdjust()
{
return layoutProperties.getAlignmentAdjust();
}
public RenderLength getAlignmentAdjustResolved()
{
return layoutProperties.getAlignmentAdjustResolved();
}
public PageContext getPageContext()
{
final RenderBox parent = getParent();
if (parent != null)
{
parent.getPageContext();
}
return null;
}
public Object getInstanceId()
{
return instanceId;
}
public int getMajorAxis()
{
return layoutProperties.getMajorAxis();
}
protected void setMajorAxis(final int majorAxis)
{
layoutProperties.setMajorAxis(majorAxis);
}
public int getMinorAxis()
{
return layoutProperties.getMinorAxis();
}
protected void setMinorAxis(final int minorAxis)
{
layoutProperties.setMinorAxis(minorAxis);
this.updateChangeTracker();
}
public void setWidth(final long width)
{
if (width < 0)
{
throw new IllegalArgumentException("Width cannot be negative: " + width);
}
this.width = width;
this.updateChangeTracker();
}
public long getWidth()
{
return width;
}
public void setHeight(final long height)
{
if (height < 0)
{
throw new IllegalArgumentException("Height cannot be negative: " + height);
}
this.height = height;
// this.updateChangeTracker();
}
public long getHeight()
{
return this.height;
}
public long getX()
{
return x;
}
public void setX(final long x)
{
this.x = x;
this.updateChangeTracker();
}
public final void setPosition(final int axis, final long value)
{
if (axis == HORIZONTAL_AXIS)
{
setX(value);
}
else
{
setY(value);
}
}
public final long getPosition(final int axis)
{
if (axis == HORIZONTAL_AXIS)
{
return getX();
}
else
{
return getY();
}
}
public final void setDimension(final int axis, final long value)
{
if (axis == HORIZONTAL_AXIS)
{
setWidth(value);
}
else
{
setHeight(value);
}
}
public final long getDimension(final int axis)
{
if (axis == HORIZONTAL_AXIS)
{
return getWidth();
}
else
{
return getHeight();
}
}
public long getY()
{
return y;
}
public void setY(final long y)
{
this.y = y;
}
public RenderBox getParent()
{
return parent;
}
protected void setParent(final RenderBox parent)
{
// Object oldParent = this.parent;
this.parent = parent;
if (parent != null && prev == parent)
{
throw new IllegalStateException();
}
}
public RenderNode getVisiblePrev()
{
RenderNode node = prev;
while (node != null)
{
if (node.isIgnorableForRendering() == false)
{
return node;
}
node = node.getPrev();
}
return null;
}
public RenderNode getPrev()
{
return prev;
}
protected void setPrev(final RenderNode prev)
{
this.prev = prev;
if (prev != null && prev == parent)
{
throw new IllegalStateException();
}
}
public RenderNode getVisibleNext()
{
RenderNode node = next;
while (node != null)
{
if (node.isIgnorableForRendering() == false)
{
return node;
}
node = node.getNext();
}
return null;
}
public RenderNode getNext()
{
return next;
}
protected void setNext(final RenderNode next)
{
this.next = next;
}
public LogicalPageBox getLogicalPage()
{
final RenderNode parent = getParent();
if (parent != null)
{
return parent.getLogicalPage();
}
return null;
}
public NormalFlowRenderBox getNormalFlow()
{
final RenderNode parent = getParent();
if (parent != null)
{
return parent.getNormalFlow();
}
return null;
}
/**
* Clones this node. Be aware that cloning can get you into deep trouble, as
* the relations this node has may no longer be valid.
*
* @return
*/
public Object clone()
{
try
{
final RenderNode renderNode = (RenderNode) super.clone();
return renderNode;
}
catch (CloneNotSupportedException e)
{
throw new IllegalStateException("Clone failed for some reason.");
}
}
/**
* Derive creates a disconnected node that shares all the properties of the
* original node. The derived node will no longer have any parent, silbling,
* child or any other relationships with other nodes.
*
* @return
*/
public RenderNode derive(final boolean deep)
{
final RenderNode node = (RenderNode) clone();
node.parent = null;
node.next = null;
node.prev = null;
node.hibernated = false;
return node;
}
/**
* Derives an hibernation copy. The resulting object should get stripped of
* all unnecessary caching information and all objects, which will be
* regenerated when the layouting restarts. Size does matter here.
*
* @return
*/
public RenderNode hibernate ()
{
final RenderNode node = (RenderNode) clone();
node.parent = null;
node.next = null;
node.prev = null;
node.hibernated = true;
return node;
}
public RenderNode deriveFrozen(final boolean deep)
{
final RenderNode node = (RenderNode) clone();
node.parent = null;
node.next = null;
node.prev = null;
node.frozen = true;
node.hibernated = false;
return node;
}
public boolean isFrozen()
{
return frozen;
}
public boolean isHibernated()
{
return hibernated;
}
protected void setHibernated(final boolean hibernated)
{
this.hibernated = hibernated;
}
public RenderNode findNodeById(final Object instanceId)
{
if (instanceId == getInstanceId())
{
return this;
}
return null;
}
public boolean isOpen()
{
return false;
}
public boolean isEmpty()
{
return false;
}
public RenderBox getParentBlockContext()
{
if (parent == null)
{
return null;
}
if (parent instanceof BlockRenderBox)
{
return parent;
}
return parent.getParentBlockContext();
}
public boolean isDiscardable()
{
return false;
}
/**
* If that method returns true, the element will not be used for rendering.
* For the purpose of computing sizes or performing the layouting (in the
* validate() step), this element will treated as if it is not there.
* <p/>
* If the element reports itself as non-empty, however, it will affect the
* margin computation.
*
* @return
*/
public boolean isIgnorableForRendering()
{
return isEmpty();
}
/**
* Returns the baseline info for the given node. This can be null, if the node
* does not have any baseline info at all. If the element has more than one
* set of baselines, the baseline of the first element is returned.
*
* @return
*/
// public abstract ExtendedBaselineInfo getBaselineInfo();
public NodeLayoutProperties getNodeLayoutProperties()
{
return layoutProperties;
}
public void freeze()
{
frozen = true;
}
public boolean isDirectionLTR()
{
return true;
}
public void updateChangeTracker()
{
changeTracker += 1;
if (parent != null)
{
parent.updateChangeTracker();
}
}
public long getChangeTracker()
{
return changeTracker;
}
public long getStickyMarker()
{
return stickyMarker;
}
public void setStickyMarker(final long stickyMarker)
{
this.stickyMarker = stickyMarker;
}
public long getEffectiveMarginTop()
{
return 0;
}
public long getEffectiveMarginBottom()
{
return 0;
}
public long getMaximumBoxWidth()
{
return maximumBoxWidth;
}
public void setMaximumBoxWidth(final long maximumBoxWidth)
{
this.maximumBoxWidth = maximumBoxWidth;
}
public long getMinimumChunkWidth()
{
return minimumChunkWidth;
}
public void setMinimumChunkWidth(final long minimumChunkWidth)
{
this.minimumChunkWidth = minimumChunkWidth;
}
public boolean isIcmMetricsFinished()
{
return icmMetricsFinished;
}
public void setIcmMetricsFinished(final boolean icmMetricsFinished)
{
this.icmMetricsFinished = icmMetricsFinished;
}
}
|