public class TLcdGXYHatchedFillStyle extends Object implements ILcdGXYPainterStyle, ILcdCloneable
ILcdGXYPainterStyle
that fills areas by hatching them with a given line width and
color.
For performance reasons, a pattern is created by drawing one line in every necessary direction (horizontal, vertical, slash or back slash) on top of the background color (if background is enabled). This pattern is then tiled to fill the required area.
If you only intend to use this style for solid fills, it is better to use
TLcdGXYPainterColorStyle
for performance reasons.
Example code:
// Init painter modes
ALcdGXYAreaPainter painter = ...;
painter.setMode( ALcdGXYAreaPainter.OUTLINED_FILLED );
painter.setSelectionMode( ALcdGXYAreaPainter.OUTLINED_FILLED );
// Create fill style
painter.setFillStyle( new TLcdGXYHatchedFillStyle(
EnumSet.of( TLcdGXYHatchedFillStyle.Pattern.SLASH ), Color.ORANGE, Color.ORANGE.brighter() ) );
// Create matching line style
TLcdG2DLineStyle lineStyle = new TLcdG2DLineStyle();
lineStyle.setColor( Color.ORANGE.darker() );
lineStyle.setSelectionColor( Color.ORANGE );
lineStyle.setLineWidth( 2 );
lineStyle.setSelectionLineWidth( 2 );
lineStyle.setAntiAliasing( true );
painter.setLineStyle( lineStyle );
Modifier and Type | Class and Description |
---|---|
static class |
TLcdGXYHatchedFillStyle.Pattern
The fill pattern.
|
Constructor and Description |
---|
TLcdGXYHatchedFillStyle()
Creates a new
TLcdGXYHatchedFillStyle with default values for all properties. |
TLcdGXYHatchedFillStyle(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aPattern,
Color aLineColor)
Creates a new
TLcdGXYHatchedFillStyle . |
TLcdGXYHatchedFillStyle(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aPattern,
Color aLineColor,
Color aSelectionLineColor)
Creates a new
TLcdGXYHatchedFillStyle . |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aListener)
Adds the given listener to the list of listeners, so that it will receive property change
events.
|
void |
addPropertyChangeListener(String aProperty,
PropertyChangeListener aListener)
Adds the given listener to the list of listeners, so that it will receive notifications
about changes in
aProperty . |
ILcdIcon |
asIcon()
Returns this style as a tileable icon.
|
Object |
clone()
Makes
Object.clone() public. |
protected void |
firePropertyChange(String aProperty,
Object aOldValue,
Object aNewValue)
Fires the given event to the associated listeners.
|
Paint |
getBackgroundPaint()
Returns the background paint.
|
Color |
getLineColor()
Returns the line color.
|
int |
getLineWidth()
Returns the line width.
|
EnumSet<TLcdGXYHatchedFillStyle.Pattern> |
getPattern()
Returns the fill pattern.
|
Dimension |
getPatternSize()
Returns the pattern size.
|
Paint |
getSelectionBackgroundPaint()
Returns the selection background paint.
|
Color |
getSelectionLineColor()
Returns the selection line color.
|
int |
getSelectionLineWidth()
Returns the selection line width.
|
EnumSet<TLcdGXYHatchedFillStyle.Pattern> |
getSelectionPattern()
Returns the fill pattern for selection mode.
|
boolean |
isAntiAliasing()
Returns true if anti aliasing is enabled, false otherwise.
|
void |
removePropertyChangeListener(PropertyChangeListener aListener)
Removes the given listener so that it no longer receives property change events.
|
void |
removePropertyChangeListener(String aProperty,
PropertyChangeListener aListener)
Removes the given listener for the given property, so that it no longer receives
those change events.
|
void |
setAntiAliasing(boolean aAntiAliasing)
Sets the anti aliasing property.
|
void |
setBackgroundPaint(Paint aBackgroundPaint)
Sets the background paint (e.g. a
Color ). |
void |
setLineColor(Color aLineColor)
Sets the line color for filling shapes in their normal (unselected) mode.
|
void |
setLineWidth(int aLineWidth)
Sets the line width for filling shapes in their normal (unselected) mode.
|
void |
setPattern(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aPattern)
Sets the filling pattern.
|
void |
setPatternSize(Dimension aPatternSize)
Sets the pixel size of the filling pattern.
|
void |
setSelectionBackgroundPaint(Paint aSelectionBackgroundPaint)
Sets the selection background paint (e.g. a Color).
|
void |
setSelectionLineColor(Color aSelectionLineColor)
Sets the line color for filling shapes in their selected mode.
|
void |
setSelectionLineWidth(int aSelectionLineWidth)
Sets the line width for filling shapes in their selected mode.
|
void |
setSelectionPattern(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aSelectionPattern)
Sets the filling pattern for selection mode.
|
void |
setupGraphics(Graphics aGraphics,
Object aObject,
int aMode,
ILcdGXYContext aGXYContext)
Set up
aGraphics before painting aObject. |
public TLcdGXYHatchedFillStyle()
TLcdGXYHatchedFillStyle
with default values for all properties.public TLcdGXYHatchedFillStyle(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aPattern, Color aLineColor)
TLcdGXYHatchedFillStyle
.aPattern
- The pattern set, used for both regular and selection mode.aLineColor
- The color for painting shapes in their normal (unselected) mode.public TLcdGXYHatchedFillStyle(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aPattern, Color aLineColor, Color aSelectionLineColor)
TLcdGXYHatchedFillStyle
.aPattern
- The pattern set, used for both regular and selection mode.aLineColor
- The color for painting shapes in their normal (unselected) mode.aSelectionLineColor
- The color for painting shapes in their selected mode.public void addPropertyChangeListener(PropertyChangeListener aListener)
aListener
- The listener to add.public void addPropertyChangeListener(String aProperty, PropertyChangeListener aListener)
aProperty
.aProperty
- The property to watch for changes.aListener
- The listener to add.public void removePropertyChangeListener(PropertyChangeListener aListener)
aListener
- The listener to remove.public void removePropertyChangeListener(String aProperty, PropertyChangeListener aListener)
aProperty
- The property to stop listening to.aListener
- The listener to remove.protected void firePropertyChange(String aProperty, Object aOldValue, Object aNewValue)
aProperty
- The property that was changed.aOldValue
- The old value.aNewValue
- The new value.public EnumSet<TLcdGXYHatchedFillStyle.Pattern> getPattern()
public void setPattern(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aPattern)
aPattern
- An enum set of the defined Pattern
s, for example
EnumSet.of( Pattern.HORIZONTAL, Pattern.VERTICAL )
public EnumSet<TLcdGXYHatchedFillStyle.Pattern> getSelectionPattern()
public void setSelectionPattern(EnumSet<TLcdGXYHatchedFillStyle.Pattern> aSelectionPattern)
aSelectionPattern
- An enum set of the defined Pattern
s, for example
EnumSet.of( Pattern.HORIZONTAL, Pattern.VERTICAL )
public Dimension getPatternSize()
public void setPatternSize(Dimension aPatternSize)
Sets the pixel size of the filling pattern. The pattern is created by drawing one line in every necessary direction (horizontal, vertical, slash or back slash). This pattern is then tiled to fill the required area. Changing the size of this pattern allows to define the spacing between adjacent lines. Defining a non-square pattern size for slanted patterns (slash and back slash) allows to change the angle of the slanted lines. For example a slash pattern with a pattern size of 20x10 results in 26.6 degree lines (Math.atan(10/20)).
Width and height must be strictly larger than twice (line width + 2), where line width is the largest of the selection or regular line width. The values should be small for performance reasons, for example 10x10 or 20x10 pixels.
After the dimension is set, the instance must not be changed anymore.
aPatternSize
- The new pattern size.public int getLineWidth()
public void setLineWidth(int aLineWidth)
aLineWidth
- The line width in pixels.public int getSelectionLineWidth()
public void setSelectionLineWidth(int aSelectionLineWidth)
aSelectionLineWidth
- The selection line width in pixels.public Color getLineColor()
public void setLineColor(Color aLineColor)
aLineColor
- The line colorpublic Color getSelectionLineColor()
public void setSelectionLineColor(Color aSelectionLineColor)
Sets the line color for filling shapes in their selected mode.
Note that the ILcdGXYPainter
should paint its objects filled when selected
for this property to have effect, e.g.
ALcdGXYAreaPainter painter = ...;
painter.setSelectionMode( ALcdGXYAreaPainter.OUTLINED_FILLED );
painter.setFillStyle( new TLcdGXYHatchedFillStyle() );
aSelectionLineColor
- The color of the line when painting objects in their selected state.public Paint getBackgroundPaint()
public void setBackgroundPaint(Paint aBackgroundPaint)
Sets the background paint (e.g. a Color
). Only applicable if the fill pattern
contains TLcdGXYHatchedFillStyle.Pattern.BACKGROUND
.
In combination with Paint
's other than a simple Color
(e.g. a
GradientPaint
), one should realize that a (small) pattern is tiled to fill the
desired area. As a result it is for example not possible to have a gradient that extends
from the top to the bottom of the view.
aBackgroundPaint
- The paint to fill the background with, in regular (unselected) mode.public Paint getSelectionBackgroundPaint()
public void setSelectionBackgroundPaint(Paint aSelectionBackgroundPaint)
Sets the selection background paint (e.g. a Color). Only applicable if the fill pattern
contains TLcdGXYHatchedFillStyle.Pattern.BACKGROUND
. See
setBackgroundPaint(java.awt.Paint)
for more details.
aSelectionBackgroundPaint
- The paint to fill the background with, in selected mode.public boolean isAntiAliasing()
public void setAntiAliasing(boolean aAntiAliasing)
aAntiAliasing
- True to enable anti-aliasing, false otherwise.public void setupGraphics(Graphics aGraphics, Object aObject, int aMode, ILcdGXYContext aGXYContext)
ILcdGXYPainterStyle
aGraphics
before painting aObject.
For example, if ( ( aMode & ILcdGXYPainter.SELECTED ) != 0 ), you may want to
call aGraphics.setColor(Color.red)
for instance, to see the selected
representation of a aObject in red.setupGraphics
in interface ILcdGXYPainterStyle
aGraphics
- the Graphics
to set up.aObject
- the Object
to paint.aMode
- the painting mode to consider (defined in
ILcdGXYPainter
).aGXYContext
- the ILcdGXYContext
to consider.ILcdGXYPainter
public ILcdIcon asIcon()
Returns this style as a tileable icon. The resulting icon will have the same size as the pattern size. When changing the style instance after having created an icon, the icon will not change. I.e. the changes to the style are not applied to the icon.
public Object clone()
ILcdCloneable
Makes Object.clone()
public.
java.lang.Object
, it can be implemented like this:
public Object clone() {
try {
return super.clone();
} catch ( CloneNotSupportedException e ) {
// Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
throw new RuntimeException( e );
}
}
clone
in interface ILcdCloneable
clone
in class Object
Object.clone()