Package org.jfree.chart.block
Class AbstractBlock
- java.lang.Object
-
- org.jfree.chart.block.AbstractBlock
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
BlockContainer,ColorBlock,EmptyBlock,LabelBlock,LegendGraphic,Title
public class AbstractBlock extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable
A convenience class for creating new classes that implement theBlockinterface.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBlock()Creates a new block.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description org.jfree.ui.Size2Darrange(java.awt.Graphics2D g2)Arranges the contents of the block, with no constraints, and returns the block size.org.jfree.ui.Size2Darrange(java.awt.Graphics2D g2, RectangleConstraint constraint)Arranges the contents of the block, within the given constraints, and returns the block size.protected doublecalculateTotalHeight(double contentHeight)Adds the margin, border and padding to the specified content height.protected doublecalculateTotalWidth(double contentWidth)Adds the margin, border and padding to the specified content width.java.lang.Objectclone()Returns a clone of this block.protected voiddrawBorder(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)Draws the border around the perimeter of the specified area.booleanequals(java.lang.Object obj)Tests this block for equality with an arbitrary object.BlockBordergetBorder()Deprecated.UsegetFrame()instead.java.awt.geom.Rectangle2DgetBounds()Returns the current bounds of the block.doublegetContentXOffset()Returns the x-offset for the content within the block.doublegetContentYOffset()Returns the y-offset for the content within the block.BlockFramegetFrame()Returns the current frame (border).doublegetHeight()Returns the natural height of the block, if this is known in advance.java.lang.StringgetID()Returns the id.org.jfree.ui.RectangleInsetsgetMargin()Returns the margin.org.jfree.ui.RectangleInsetsgetPadding()Returns the padding.doublegetWidth()Returns the natural width of the block, if this is known in advance.voidsetBorder(double top, double left, double bottom, double right)Sets a black border with the specified line widths.voidsetBorder(BlockBorder border)Deprecated.UsesetFrame(BlockFrame)instead.voidsetBounds(java.awt.geom.Rectangle2D bounds)Sets the bounds of the block.voidsetFrame(BlockFrame frame)Sets the frame (or border).voidsetHeight(double height)Sets the natural width of the block, if this is known in advance.voidsetID(java.lang.String id)Sets the id for the block.voidsetMargin(double top, double left, double bottom, double right)Sets the margin.voidsetMargin(org.jfree.ui.RectangleInsets margin)Sets the margin (useRectangleInsets.ZERO_INSETSfor no padding).voidsetPadding(double top, double left, double bottom, double right)Sets the padding.voidsetPadding(org.jfree.ui.RectangleInsets padding)Sets the padding (useRectangleInsets.ZERO_INSETSfor no padding).voidsetWidth(double width)Sets the natural width of the block, if this is known in advance.protected RectangleConstrainttoContentConstraint(RectangleConstraint c)Returns a constraint for the content of this block that will result in the bounds of the block matching the specified constraint.protected java.awt.geom.Rectangle2DtrimBorder(java.awt.geom.Rectangle2D area)Reduces the specified area by the amount of space consumed by the border.protected java.awt.geom.Rectangle2DtrimMargin(java.awt.geom.Rectangle2D area)Reduces the specified area by the amount of space consumed by the margin.protected java.awt.geom.Rectangle2DtrimPadding(java.awt.geom.Rectangle2D area)Reduces the specified area by the amount of space consumed by the padding.protected doubletrimToContentHeight(double fixedHeight)Calculate the height available for content after subtracting the margin, border and padding space from the specified fixed height.protected doubletrimToContentWidth(double fixedWidth)Calculate the width available for content after subtracting the margin, border and padding space from the specified fixed width.
-
-
-
Constructor Detail
-
AbstractBlock
protected AbstractBlock()
Creates a new block.
-
-
Method Detail
-
getID
public java.lang.String getID()
Returns the id.- Returns:
- The id (possibly
null). - See Also:
setID(String)
-
setID
public void setID(java.lang.String id)
Sets the id for the block.- Parameters:
id- the id (nullpermitted).- See Also:
getID()
-
getWidth
public double getWidth()
Returns the natural width of the block, if this is known in advance. The actual width of the block may be overridden if layout constraints make this necessary.- Returns:
- The width.
- See Also:
setWidth(double)
-
setWidth
public void setWidth(double width)
Sets the natural width of the block, if this is known in advance.- Parameters:
width- the width (in Java2D units)- See Also:
getWidth()
-
getHeight
public double getHeight()
Returns the natural height of the block, if this is known in advance. The actual height of the block may be overridden if layout constraints make this necessary.- Returns:
- The height.
- See Also:
setHeight(double)
-
setHeight
public void setHeight(double height)
Sets the natural width of the block, if this is known in advance.- Parameters:
height- the width (in Java2D units)- See Also:
getHeight()
-
getMargin
public org.jfree.ui.RectangleInsets getMargin()
Returns the margin.- Returns:
- The margin (never
null). - See Also:
getMargin()
-
setMargin
public void setMargin(org.jfree.ui.RectangleInsets margin)
Sets the margin (useRectangleInsets.ZERO_INSETSfor no padding).- Parameters:
margin- the margin (nullnot permitted).- See Also:
getMargin()
-
setMargin
public void setMargin(double top, double left, double bottom, double right)
Sets the margin.- Parameters:
top- the top margin.left- the left margin.bottom- the bottom margin.right- the right margin.- See Also:
getMargin()
-
getBorder
public BlockBorder getBorder()
Deprecated.UsegetFrame()instead.Returns the border.- Returns:
- The border (never
null).
-
setBorder
public void setBorder(BlockBorder border)
Deprecated.UsesetFrame(BlockFrame)instead.Sets the border for the block (useBlockBorder.NONEfor no border).- Parameters:
border- the border (nullnot permitted).- See Also:
getBorder()
-
setBorder
public void setBorder(double top, double left, double bottom, double right)
Sets a black border with the specified line widths.- Parameters:
top- the top border line width.left- the left border line width.bottom- the bottom border line width.right- the right border line width.
-
getFrame
public BlockFrame getFrame()
Returns the current frame (border).- Returns:
- The frame.
- Since:
- 1.0.5
- See Also:
setFrame(BlockFrame)
-
setFrame
public void setFrame(BlockFrame frame)
Sets the frame (or border).- Parameters:
frame- the frame (nullnot permitted).- Since:
- 1.0.5
- See Also:
getFrame()
-
getPadding
public org.jfree.ui.RectangleInsets getPadding()
Returns the padding.- Returns:
- The padding (never
null). - See Also:
setPadding(RectangleInsets)
-
setPadding
public void setPadding(org.jfree.ui.RectangleInsets padding)
Sets the padding (useRectangleInsets.ZERO_INSETSfor no padding).- Parameters:
padding- the padding (nullnot permitted).- See Also:
getPadding()
-
setPadding
public void setPadding(double top, double left, double bottom, double right)
Sets the padding.- Parameters:
top- the top padding.left- the left padding.bottom- the bottom padding.right- the right padding.
-
getContentXOffset
public double getContentXOffset()
Returns the x-offset for the content within the block.- Returns:
- The x-offset.
- See Also:
getContentYOffset()
-
getContentYOffset
public double getContentYOffset()
Returns the y-offset for the content within the block.- Returns:
- The y-offset.
- See Also:
getContentXOffset()
-
arrange
public org.jfree.ui.Size2D arrange(java.awt.Graphics2D g2)
Arranges the contents of the block, with no constraints, and returns the block size.- Parameters:
g2- the graphics device.- Returns:
- The block size (in Java2D units, never
null).
-
arrange
public org.jfree.ui.Size2D arrange(java.awt.Graphics2D g2, RectangleConstraint constraint)
Arranges the contents of the block, within the given constraints, and returns the block size.- Parameters:
g2- the graphics device.constraint- the constraint (nullnot permitted).- Returns:
- The block size (in Java2D units, never
null).
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Returns the current bounds of the block.- Returns:
- The bounds.
- See Also:
setBounds(Rectangle2D)
-
setBounds
public void setBounds(java.awt.geom.Rectangle2D bounds)
Sets the bounds of the block.- Parameters:
bounds- the bounds (nullnot permitted).- See Also:
getBounds()
-
trimToContentWidth
protected double trimToContentWidth(double fixedWidth)
Calculate the width available for content after subtracting the margin, border and padding space from the specified fixed width.- Parameters:
fixedWidth- the fixed width.- Returns:
- The available space.
- See Also:
trimToContentHeight(double)
-
trimToContentHeight
protected double trimToContentHeight(double fixedHeight)
Calculate the height available for content after subtracting the margin, border and padding space from the specified fixed height.- Parameters:
fixedHeight- the fixed height.- Returns:
- The available space.
- See Also:
trimToContentWidth(double)
-
toContentConstraint
protected RectangleConstraint toContentConstraint(RectangleConstraint c)
Returns a constraint for the content of this block that will result in the bounds of the block matching the specified constraint.- Parameters:
c- the outer constraint (nullnot permitted).- Returns:
- The content constraint.
-
calculateTotalWidth
protected double calculateTotalWidth(double contentWidth)
Adds the margin, border and padding to the specified content width.- Parameters:
contentWidth- the content width.- Returns:
- The adjusted width.
-
calculateTotalHeight
protected double calculateTotalHeight(double contentHeight)
Adds the margin, border and padding to the specified content height.- Parameters:
contentHeight- the content height.- Returns:
- The adjusted height.
-
trimMargin
protected java.awt.geom.Rectangle2D trimMargin(java.awt.geom.Rectangle2D area)
Reduces the specified area by the amount of space consumed by the margin.- Parameters:
area- the area (nullnot permitted).- Returns:
- The trimmed area.
-
trimBorder
protected java.awt.geom.Rectangle2D trimBorder(java.awt.geom.Rectangle2D area)
Reduces the specified area by the amount of space consumed by the border.- Parameters:
area- the area (nullnot permitted).- Returns:
- The trimmed area.
-
trimPadding
protected java.awt.geom.Rectangle2D trimPadding(java.awt.geom.Rectangle2D area)
Reduces the specified area by the amount of space consumed by the padding.- Parameters:
area- the area (nullnot permitted).- Returns:
- The trimmed area.
-
drawBorder
protected void drawBorder(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws the border around the perimeter of the specified area.- Parameters:
g2- the graphics device.area- the area.
-
equals
public boolean equals(java.lang.Object obj)
Tests this block for equality with an arbitrary object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a clone of this block.- Overrides:
clonein classjava.lang.Object- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException- if there is a problem creating the clone.
-
-