📄 tableproducer.java
字号:
// handle the band itself, the band's bounds are already translated.
boolean retval = processElement(bounds, band);
// process all elements
final Element[] l = band.getElementArray();
for (int i = 0; i < l.length; i++)
{
final Element e = l[i];
if (e instanceof Band)
{
final Rectangle2D bbounds = (Rectangle2D)
e.getStyle().getStyleProperty(ElementStyleSheet.BOUNDS);
if (processBand(translateSubRect(bounds, bbounds), (Band) e) == true)
{
retval = true;
}
}
else
{
final Rectangle2D elementBounds = (Rectangle2D)
e.getStyle().getStyleProperty(ElementStyleSheet.BOUNDS);
if (elementBounds == null)
{
throw new NullPointerException("No layout for element");
}
final Rectangle2D drawBounds = translateSubRect(bounds, elementBounds);
if (processElement(drawBounds, e) == true)
{
retval = true;
}
}
}
return retval;
}
/**
* Converts an inner rectangle to the coordinate space of the outer rectangle.
* The inner rectangle's origin (0,0) is mapped to the outer rectangles upper
* left corner.
*
* @param outer the outer rectangle in the global coordinate space
* @param inner the inner rectangle in the local coordinate space
* @return the translated sub rectangle.
*/
private Rectangle2D translateSubRect(final Rectangle2D outer, final Rectangle2D inner)
{
final float w =
(float) Math.min(outer.getX() + outer.getWidth() - inner.getX(), inner.getWidth());
final float h =
(float) Math.min(outer.getY() + outer.getHeight() - inner.getY(), inner.getHeight());
final Rectangle2D rc = new Rectangle2D.Float(
(float) (outer.getX() + inner.getX()),
(float) (outer.getY() + inner.getY()),
Math.max(0, w),
Math.max(0, h));
return rc;
}
/**
* Add the specified element to the logical page. Create content from the values
* contained in the element and format the content by using the element's attributes.
* <p>
* @param drawBounds the bounds where the element should be painted in the target area.
* @param e the element.
* @return true, if the cell was added to the table content, and false otherwise.
* @throws NullPointerException if the element has no valid layout (no BOUNDS defined).
* Bounds are usually defined by the BandLayoutManager.
*/
private boolean processElement(final Rectangle2D drawBounds, final Element e)
{
if (e.isVisible() == false)
{
return false;
}
final TableCellData data = getCellDataFactory().createCellData(e, drawBounds);
if (data != null)
{
addCell(data);
return true;
}
return false;
}
/**
* Merges all TableCellBackgrounds contained in the given list. The list must
* be sorted by preference, the first background in the list overlays all other
* backgrounds.
*
* @param background the collected backgrounds for a single table cell.
* @param cellBounds the bounds for the current backgound cell. The defined backgrounds
* may be defined for a larger area, but we want to merge all background for <b>this</b>
* particular area.
* @return the merged TableCellBackground.
*/
protected TableCellBackground createTableCellStyle
(final List background, final Rectangle2D cellBounds)
{
return createStaticTableCellStyle(background, cellBounds);
}
/**
* Created basicly for utility/debugging purposes.
*
* @param background the list of background definitions.
* @param cellBounds the bounds of the background cell that should be
* created.
* @return the created (merged) TableCellBackground instance.
*/
protected static TableCellBackground createStaticTableCellStyle
(final List background, final Rectangle2D cellBounds)
{
if (background == null)
{
return null;
}
TableCellBackground bg = null;
for (int i = 0; i < background.size(); i++)
{
final TableGridPosition listBgPos = (TableGridPosition) background.get(i);
final TableCellBackground listBg = (TableCellBackground) listBgPos.getElement();
if (bg == null)
{
bg = listBg;
}
else
{
bg = bg.merge(listBg, cellBounds);
}
}
if (bg == null)
{
return null;
}
return (bg);
}
/**
* Creates the cellbounds for the cell specified with x and y of the given
* layout. The bounds are filled in the given rectangle, if not null.
*
* @param layout the layout from where to read the content
* @param x the column within the layout
* @param y the row within the layout
* @param rect the rectangle which should receive the bounds. If the rectangle
* is null, a new rectangle will be created.
* @return the rectangle containing the bounds of the given cell.
*/
protected Rectangle2D createCellBounds
(final TableGridLayout layout, final int x, final int y, Rectangle2D rect)
{
if (rect == null)
{
rect = new Rectangle2D.Float();
}
final float x0 = layout.getColumnStart(x);
final float y0 = layout.getRowStart(y);
final float x1 = layout.getColumnEnd(x);
final float y1 = layout.getRowEnd(y);
rect.setRect(x0, y0, x1 - x0, y1 - y0);
return rect;
}
/**
* Gets the dummy mode state, in dummy mode no output is done.
*
* @return true, if the producer is working in dummy mode, no output is done.
*/
public boolean isDummy()
{
return dummy;
}
/**
* Defines a property for this output target. Properties are the standard way of configuring
* an output target.
*
* @param property the name of the property to set (<code>null</code> not permitted).
* @param value the value of the property. If the value is <code>null</code>, the property is
* removed from the output target.
*/
public void setProperty(final String property, final String value)
{
if (property == null)
{
throw new NullPointerException();
}
if (value == null)
{
properties.remove(property);
}
else
{
properties.put(property, value);
}
}
/**
* Queries the property named with <code>property</code>. If the property is not found, <code>
* null</code> is returned.
*
* @param property the name of the property to be queried
*
* @return the value stored under the given property name
*
* @throws java.lang.NullPointerException if <code>property</code> is null
*/
public String getProperty(final String property)
{
return getProperty(property, null);
}
/**
* Queries the property named with <code>property</code>. If the property is not found, the
* default value is returned.
*
* @param property the name of the property to be queried
* @param defaultValue the defaultvalue returned if there is no such property
*
* @return the value stored under the given property name
*
* @throws NullPointerException if <code>property</code> is null
*/
public String getProperty(final String property, final String defaultValue)
{
if (property == null)
{
throw new NullPointerException();
}
return properties.getProperty(property, defaultValue);
}
/**
* Returns an enumeration of the property names.
*
* @return the enumeration.
*/
protected Iterator getPropertyNames()
{
return properties.keySet().iterator();
}
/**
* Configures the table producer by reading the configuration settings from
* the given map.
*
* @param configuration the configuration supplied by the table processor.
*/
public void configure(final Properties configuration)
{
properties.putAll(configuration);
}
/**
* Write the collected data. This method is called when ever it is safe to
* commit all previous content. An auto-commit is also performed after the page
* has ended.
* <p>
* Implementations have to take care, that empty commits do not produce any
* output. Successfully written content must be removed.
*/
public abstract void commit();
/**
* Returns true, if the strict layouting algorithm is used.
*
* @return true if strict layouting is used, false otherwise.
*/
public boolean isStrictLayout()
{
return strictLayout;
}
/**
* Returns the value of the local gridBoundsCollection's Global Layout flag.
* The global layout makes sure, that all pages use the same table grid layout to
* format their contents. This makes sure that all pages have the same look.
*
* @return true, if a global layout is used, false otherwise
*/
protected boolean isGlobalLayout()
{
return gridBoundsCollection.isGlobalLayout();
}
/**
* The collected layout information.
*
* @return the collected bounds of the table grid.
*/
public TableLayoutInfo getGridBoundsCollection()
{
return gridBoundsCollection;
}
/**
* Returns the current page.
* @return the currently processed page.
*/
protected int getPage()
{
return page;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -