public class Painter<X extends java.lang.Number,Y extends java.lang.Number>
extends java.lang.Object
paint(int, int, int, int)
method is called in the loop to paint cells and lines
then it is recommended to take as many operations out of it as possible in order to improve the
the graphics performance. All the repetitive operations that are common to all elements,
like setting a font or a background color can be done in the init()
method, which is called only once.
It's also a good practice to restore any of the GC attributes modified by in init()
or paint(int, int, int, int)
back to the default value to provide a clean start for a next painter.
It can be done in the clean()
method.
This optimization is possible due to replacing of painting operations loop with the cell iteration loop. In Matrix cell iteration happens inside of the painters iteration and it can still fold to a single cell iteration if all the drawing is done by a single painter.
Modifier and Type | Field and Description |
---|---|
protected org.eclipse.swt.graphics.Image |
collapsedImage |
protected boolean |
expanded |
protected org.eclipse.swt.graphics.Image |
expandedImage |
protected Frozen |
frozenX |
protected Frozen |
frozenY |
protected org.eclipse.swt.graphics.GC |
gc
|
protected boolean |
hasChildren |
org.eclipse.swt.graphics.Image |
image
Image to be painted.
|
protected boolean |
isSelected
Expresses the selected state of the cell to paint set by default
by the
setup(Number, Number) method. |
static java.lang.String |
NAME_BACKGORUND
Default name of a painter belonging to a zone and responsible to paint its
background.
|
static java.lang.String |
NAME_CELLS
Default name of a painter belonging to a zone and responsible to paint its
cells.
|
static java.lang.String |
NAME_DRAG_ITEM_X
Default name of the painter belonging to a matrix responsible to paint the
items being dragged on x axis.
|
static java.lang.String |
NAME_DRAG_ITEM_Y
Default name of the painter belonging to a matrix responsible to paint the
items being dragged on y axis.
|
static java.lang.String |
NAME_EMBEDDED_CONTROLS
Default name of a painter belonging to a zone and responsible to
create/dispose or show/hide the embedded controls.
|
static java.lang.String |
NAME_EMULATED_CONTROLS
Default name of a painter belonging to a zone and responsible to paint the
emulated controls.
|
static java.lang.String |
NAME_FOCUS_CELL
Default name of a painter belonging to a matrix and responsible to paint
the focus cell.
|
static java.lang.String |
NAME_FREEZE_HEAD_LINE_X
Default name of the painter belonging to a matrix responsible to paint the
line dividing the frozen head on the horizontal axis.
|
static java.lang.String |
NAME_FREEZE_HEAD_LINE_Y
Default name of the painter belonging to a matrix responsible to paint the
line dividing the frozen head on the vertical axis.
|
static java.lang.String |
NAME_FREEZE_TAIL_LINE_X
Default name of the painter belonging to a matrix responsible to paint the
line dividing the frozen tail on the horizontal axis.
|
static java.lang.String |
NAME_FREEZE_TAIL_LINE_Y
Default name of the painter belonging to a matrix responsible to paint the
line dividing the frozen tail on the vertical axis.
|
static java.lang.String |
NAME_FROZEN_HEAD_HEAD
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen both at the vertical start and horizontal start of the
viewport.
|
static java.lang.String |
NAME_FROZEN_HEAD_NONE
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen only at the vertical start of the viewport.
|
static java.lang.String |
NAME_FROZEN_HEAD_TAIL
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen both at the vertical start and horizontal end of the
viewport.
|
static java.lang.String |
NAME_FROZEN_NONE_HEAD
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen only at the horizontal start of the viewport.
|
static java.lang.String |
NAME_FROZEN_NONE_NONE
Default name of a painter belonging to a matrix and responsible to paint the
area not frozen.
|
static java.lang.String |
NAME_FROZEN_NONE_TAIL
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen only at the horizontal end of the viewport.
|
static java.lang.String |
NAME_FROZEN_TAIL_HEAD
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen both at the vertical end and horizontal start of the
viewport.
|
static java.lang.String |
NAME_FROZEN_TAIL_NONE
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen only at the vertical end of the viewport.
|
static java.lang.String |
NAME_FROZEN_TAIL_TAIL
Default name of a painter belonging to a matrix and responsible to paint the
area that is frozen both at the vertical end and horizontal end of the
viewport.
|
static java.lang.String |
NAME_LINES_X
Default name of a painter belonging to a zone and responsible to paint its
lines along x axis.
|
static java.lang.String |
NAME_LINES_Y
Default name of a painter belonging to a zone and responsible to paint its
lines along y axis.
|
protected org.eclipse.swt.graphics.Point |
nodeImageSize |
static int |
SCOPE_CELLS
Shortcut for
SCOPE_CELLS_X |
static int |
SCOPE_CELLS_ITEM_X
Compound boundaries including all cells of an axis X item (column)
|
static int |
SCOPE_CELLS_ITEM_Y
Compound boundaries including all cells of an axis Y item (row)
|
static int |
SCOPE_CELLS_X
Individual cells in horizontal order first.
|
static int |
SCOPE_CELLS_Y
Individual cells in vertical order first.
|
static int |
SCOPE_ENTIRE
Single scope of the whole container
|
static int |
SCOPE_LINES_X
Horizontal lines stretching from the left to the right edge of the zone to which the painter belongs.
|
static int |
SCOPE_LINES_Y
Vertical lines stretching from the top to the bottom edge of the zone to which the painter belongs.
|
boolean |
selectionHighlight
Selected cells will be highlighted if true.
|
Style |
style
Painter style properties.
|
java.lang.String |
text
Text to be painted.
|
protected org.eclipse.swt.graphics.TextLayout |
textLayout |
protected org.eclipse.swt.graphics.Point |
textSize |
Constructor and Description |
---|
Painter(java.lang.String name)
Constructs a painter with the given name.
|
Painter(java.lang.String name,
int scope)
The main constructor.
|
Modifier and Type | Method and Description |
---|---|
static int |
align(int align,
int margin,
int width,
int bound)
Returns the distance of a graphical element based on the align mode and the padding margin.
|
void |
clean()
|
protected void |
clipText()
Called by paint method to adjust the text to be painted
in case the text does not fit the allotted area.
|
protected org.eclipse.swt.graphics.Point |
computeSize(X indexX,
Y indexY,
int wHint,
int hHint)
Returns the preferred size of the receiver.
|
void |
dispose() |
java.lang.Object |
getData()
Returns custom data of this painter.
|
java.lang.String |
getName()
Returns the painter name.
|
int |
getScope()
Returns the painter scope.
|
Zone<X,Y> |
getZone()
Returns the zone to which the painter is attached or null if it is attached to matrix.
|
boolean |
hasTreeLinesVisible()
Returns
true if the tree lines are visible, or
false otherwise. |
protected boolean |
init()
Allows graphic optimization by performing operation that can be taken out
of the cell painting loop.
|
boolean |
isEnabled()
Returns true if the painter is enabled, or false otherwise.
|
boolean |
isTreeEnabled()
Returns
true if the tree painting is enabled, or
false otherwise. |
protected void |
paint(int x,
int y,
int width,
int height)
Draws on the canvas within the given boundaries according to the given indexes.
|
void |
setData(java.lang.Object data)
Sets custom data for this painter.
|
void |
setEnabled(boolean enabled)
Sets the enabled state of the receiver.
|
void |
setNodeImages(org.eclipse.swt.graphics.Image collapsedImage,
org.eclipse.swt.graphics.Image expandedImage)
Sets the icons to represent collapsed/expanded state of a tree node.
|
void |
setTreeLinesVisible(boolean state)
Makes the tree lines connecting nodes visible if set to
true ,
or hidden otherwise. |
void |
setTreeVisible(boolean state)
Enables a vertical tree in the first column with node icons indicating
expanded/collapsed state.
|
void |
setup(X indexX,
Y indexY)
Configures the painter properties according to the given indexes.
|
void |
setupSpatial(X indexX,
Y indexY)
Sets the spatial properties for this painter.
|
public static final int SCOPE_ENTIRE
public static final int SCOPE_LINES_X
public static final int SCOPE_LINES_Y
public static final int SCOPE_CELLS_ITEM_X
public static final int SCOPE_CELLS_ITEM_Y
public static final int SCOPE_CELLS_X
public static final int SCOPE_CELLS_Y
public static final int SCOPE_CELLS
SCOPE_CELLS_X
public static final java.lang.String NAME_CELLS
ZoneEditor
and NAME_DRAG_ITEM_X
use it to perform their functions.public static final java.lang.String NAME_LINES_X
public static final java.lang.String NAME_LINES_Y
public static final java.lang.String NAME_BACKGORUND
public static final java.lang.String NAME_FROZEN_NONE_NONE
public static final java.lang.String NAME_FROZEN_NONE_TAIL
public static final java.lang.String NAME_FROZEN_TAIL_NONE
public static final java.lang.String NAME_FROZEN_NONE_HEAD
public static final java.lang.String NAME_FROZEN_HEAD_NONE
public static final java.lang.String NAME_FROZEN_HEAD_TAIL
public static final java.lang.String NAME_FROZEN_TAIL_HEAD
public static final java.lang.String NAME_FROZEN_TAIL_TAIL
public static final java.lang.String NAME_FROZEN_HEAD_HEAD
public static final java.lang.String NAME_FOCUS_CELL
public static final java.lang.String NAME_EMULATED_CONTROLS
public static final java.lang.String NAME_EMBEDDED_CONTROLS
public static final java.lang.String NAME_DRAG_ITEM_X
public static final java.lang.String NAME_DRAG_ITEM_Y
public static final java.lang.String NAME_FREEZE_HEAD_LINE_X
public static final java.lang.String NAME_FREEZE_HEAD_LINE_Y
public static final java.lang.String NAME_FREEZE_TAIL_LINE_X
public static final java.lang.String NAME_FREEZE_TAIL_LINE_Y
protected org.eclipse.swt.graphics.GC gc
init()
, clean()
,
paint(int, int, int, int)
methods.
It is not safe to use it inside of other methods.protected boolean isSelected
setup(Number, Number)
method.public java.lang.String text
Style.textAlignX
,
Style.textAlignY
, Style.textMarginX
, Style.textMarginY
properties.public org.eclipse.swt.graphics.Image image
Style.imageAlignX
,
Style.imageAlignY
, Style.imageMarginX
, Style.imageMarginY
properties.public boolean selectionHighlight
public Style style
protected org.eclipse.swt.graphics.Point textSize
protected org.eclipse.swt.graphics.TextLayout textLayout
protected org.eclipse.swt.graphics.Image collapsedImage
protected org.eclipse.swt.graphics.Image expandedImage
protected org.eclipse.swt.graphics.Point nodeImageSize
protected boolean hasChildren
protected boolean expanded
protected Frozen frozenX
protected Frozen frozenY
public Painter(java.lang.String name)
The scope of the painter is determined according to the following rules:
for name NAME_CELLS
scope = SCOPE_CELLS
for name NAME_LINES_X
scope = SCOPE_LINES_X
for name NAME_LINES_Y
scope = SCOPE_LINES_Y
for name NAME_EMBEDDED_CONTROLS
scope = SCOPE_CELLS
for name NAME_EMULATED_CONTROLS
scope = SCOPE_CELLS
else SCOPE_ENTIRE
.
name
- of the painter, must be unique in the collection to which it is addedPainter(String, int)
public Painter(java.lang.String name, int scope)
name
- the name of the painter, must be unique in the collection to which it is addedscope
- the scope of the painter deciding on the order and size of the boundaries
the paint(int, int, int, int)
method receives.
The value must be one of the Painter constants prefixed with SCOPE_
.public java.lang.String getName()
public int getScope()
protected boolean init()
If this method returns false the
paint(int, int, int, int)
and clean()
methods will not be executed.
clean()
public void clean()
init()
public void dispose()
protected void paint(int x, int y, int width, int height)
x
- the x coordinate of the painting boundariesy
- the y coordinate of the painting boundarieswidth
- the width of the painting boundariesheight
- the height of the painting boundariesprotected void clipText()
The size of allotted area for text is contained in textSize
field.
After the method determines new text to display it should modify the textSize properties
to match the size of the new text. It is needed for text alignment other then SWT.LEFT
.
public void setup(X indexX, Y indexY)
Default implementation invokes setupSpatial(Number, Number)
and determines if the cell is selected, therefore when overridden should
call super.setup
.
indexX
- cell index on the horizontal axisindexY
- cell index on the vertical axispublic void setupSpatial(X indexX, Y indexY)
Default implementation computes space of in first column when tree is enabled,
therefore when overridden should call super.setupSpatial
.
It is utilized by both painting mechanism as well as
computeSize(Number, Number, int, int)
routine.
The reason to separate it from setup(Number, Number)
method
is to improve performance of size computing by eliminating unnecessary
processing, like setting colors, determining whether the cell is selected, etc.
The most common usage is to set the text to display:
public void setupSpatial(Integer indexX, Integer indexY){ text = data[indexY][indexX]; }
indexX
- cell index on the horizontal axisindexY
- cell index on the vertical axispublic void setData(java.lang.Object data)
Painters NAME_DRAG_ITEM_X
and NAME_DRAG_ITEM_Y
use it to
get mouse coordinates and draw drag feedback indicator if supplied with
DropTargetEvent
object with this method. Example:
dropTarget.addDropListener(new DropTargetAdapter() { @Override public void dragOver(DropTargetEvent event) { dragPainterY.setData(event); } });
data
- data to setpublic java.lang.Object getData()
public void setEnabled(boolean enabled)
Allows to skip the receiver in the painting sequence. It can be used to hide/show the lines for example.
enabled
- the new enabled statepublic boolean isEnabled()
Communicates to the client to skip this painter in the painting sequence. It can be used to hide/show the lines for example.
public void setTreeVisible(boolean state)
state
- true
to enable tree painting or false
to disable it.public boolean isTreeEnabled()
true
if the tree painting is enabled, or
false
otherwise.true
if the tree painting is enabled, or
false
otherwisepublic void setTreeLinesVisible(boolean state)
true
,
or hidden otherwise.state
- true
to make the tree lines visible,
or false
otherwise.public boolean hasTreeLinesVisible()
true
if the tree lines are visible, or
false
otherwise.state
- public void setNodeImages(org.eclipse.swt.graphics.Image collapsedImage, org.eclipse.swt.graphics.Image expandedImage)
The image can be null and then no icon is displayed.
collapsedImage
- image representing collapsed state.expandedImage
- image representing expanded state.protected org.eclipse.swt.graphics.Point computeSize(X indexX, Y indexY, int wHint, int hHint)
indexX
- cell index on the horizontal axisindexY
- cell index on the vertical axiswHint
- the width hint (can be SWT.DEFAULT
)hHint
- the height hint (can be SWT.DEFAULT
)public static int align(int align, int margin, int width, int bound)
align
- the alignment mode, one of: SWT.LEFT
, SWT.RIGHT
, SWT.CENTER
,
SWT.TOP
, SWT.BOTTOM
, SWT.BEGINNING
, SWT.END
margin
- the number of pixels from the edge to which to align, does not matter with SWT.CENTER
width
- the width of the elementbound
- the width of the cellCopyright © 2011 netanel.pl. All Rights Reserved.