Package org.jdesktop.swingx.painter
Class AbstractLayoutPainter<T>
- java.lang.Object
-
- org.jdesktop.beans.AbstractBean
-
- org.jdesktop.swingx.painter.AbstractPainter<T>
-
- org.jdesktop.swingx.painter.AbstractLayoutPainter<T>
-
- All Implemented Interfaces:
Painter<T>
- Direct Known Subclasses:
AbstractAreaPainter
public abstract class AbstractLayoutPainter<T> extends AbstractPainter<T>
An abstract base class for any painter which can be positioned. This means the painter has some intrinsic size to what it is drawing and can be stretched or aligned both horizontally and vertically. The AbstractLayoutPainter class provides the following configuraable properties:- horizonalAlignment - the horizonal alignment (left, center, and right)
- verticalAlignment - the verticalAlignment alignment (top, center, and bottom)
- fillHorizontal - indicates if the painter should stretch to fill the available space horizontally
- fillVertical - indicates if the painter should stretch to fill the available space vertically
- insets - whitespace on the top, bottom, left, and right.
For something which is resizable, like a RectanglePainter, you can use the fill properties to make it resize along with the paintable area. For example, to make a rectangle with 20 px rounded corners, and which resizes with the paintable area but is inset by 10 pixels on all sides, you could do the following:ImagePainter p = new ImagePainter(null); p.setVerticalAlignment(AbstractLayoutPainter.VerticalAlignment.BOTTOM); p.setHorizontalAlignment(AbstractLayoutPainter.HorizontalAlignment.RIGHT); p.setInsets(new Insets(0,0,5,5));RectanglePainter p = new RectanglePainter(); p.setRoundHeight(20); p.setRoundWidth(20); p.setInsets(new Insets(10,10,10,10)); p.setFillHorizontal(true); p.setFillVertical(true);- Author:
- joshua@marinacci.org
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractLayoutPainter.HorizontalAlignmentAn enum which controls horizontalAlignment alignmentstatic classAbstractLayoutPainter.VerticalAlignmentAn enum which controls verticalAlignment alignment-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractPainter
AbstractPainter.Interpolation
-
-
Constructor Summary
Constructors Constructor Description AbstractLayoutPainter()Creates a new instance of AbstractLayoutPainter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.awt.RectanglecalculateLayout(int contentWidth, int contentHeight, int width, int height)A protected method used by subclasses to calculate the final position of the content.AbstractLayoutPainter.HorizontalAlignmentgetHorizontalAlignment()Gets the current horizontalAlignment alignment.java.awt.InsetsgetInsets()Gets the current whitespace insets.AbstractLayoutPainter.VerticalAlignmentgetVerticalAlignment()gets the current verticalAlignment alignmentbooleanisFillHorizontal()indicates if the painter content is stretched horizontallybooleanisFillVertical()indicates if the painter content is stretched verticallyvoidsetFillHorizontal(boolean fillHorizontal)Sets if the content should be stretched horizontally to fill all available horizontalAlignment space (minus the left and right insets).voidsetFillVertical(boolean verticalStretch)Sets if the content should be stretched vertically to fill all available verticalAlignment space (minus the top and bottom insets).voidsetHorizontalAlignment(AbstractLayoutPainter.HorizontalAlignment horizontal)Sets a new horizontalAlignment alignment.voidsetInsets(java.awt.Insets insets)Sets the current whitespace insets.voidsetVerticalAlignment(AbstractLayoutPainter.VerticalAlignment vertical)Sets a new verticalAlignment alignment.-
Methods inherited from class org.jdesktop.swingx.painter.AbstractPainter
clearCache, configureGraphics, doPaint, getFilters, getInterpolation, isAntialiasing, isCacheable, isDirty, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInterpolation, setVisible, shouldUseCache, validate
-
Methods inherited from class org.jdesktop.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Method Detail
-
getHorizontalAlignment
public AbstractLayoutPainter.HorizontalAlignment getHorizontalAlignment()
Gets the current horizontalAlignment alignment.- Returns:
- the current horizontalAlignment alignment
-
getInsets
public java.awt.Insets getInsets()
Gets the current whitespace insets.- Returns:
- the current insets
-
getVerticalAlignment
public AbstractLayoutPainter.VerticalAlignment getVerticalAlignment()
gets the current verticalAlignment alignment- Returns:
- current verticalAlignment alignment
-
isFillHorizontal
public boolean isFillHorizontal()
indicates if the painter content is stretched horizontally- Returns:
- the current horizontalAlignment stretch value
-
isFillVertical
public boolean isFillVertical()
indicates if the painter content is stretched vertically- Returns:
- the current verticalAlignment stretch value
-
setHorizontalAlignment
public void setHorizontalAlignment(AbstractLayoutPainter.HorizontalAlignment horizontal)
Sets a new horizontalAlignment alignment. Used to position the content at the left, right, or center.- Parameters:
horizontal- new horizontalAlignment alignment
-
setFillHorizontal
public void setFillHorizontal(boolean fillHorizontal)
Sets if the content should be stretched horizontally to fill all available horizontalAlignment space (minus the left and right insets).- Parameters:
fillHorizontal- new horizontal stretch value
-
setInsets
public void setInsets(java.awt.Insets insets)
Sets the current whitespace insets.- Parameters:
insets- new insets
-
setVerticalAlignment
public void setVerticalAlignment(AbstractLayoutPainter.VerticalAlignment vertical)
Sets a new verticalAlignment alignment. Used to position the content at the top, bottom, or center.- Parameters:
vertical- new verticalAlignment alignment
-
setFillVertical
public void setFillVertical(boolean verticalStretch)
Sets if the content should be stretched vertically to fill all available verticalAlignment space (minus the top and bottom insets).- Parameters:
verticalStretch- new verticalAlignment stretch value
-
calculateLayout
protected final java.awt.Rectangle calculateLayout(int contentWidth, int contentHeight, int width, int height)A protected method used by subclasses to calculate the final position of the content. This will position the content using the fillHorizontal, fillVertical horizontalAlignment, and verticalAlignment properties. This method is typically called by subclasses in their doPaint() methods.- Parameters:
contentWidth- The width of the content to be paintedcontentHeight- The height of the content to be paintedwidth- the width of the area that the content will be positioned inheight- the height of the area that the content will be positioned in- Returns:
- the rectangle for the content to be painted in
-
-