|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpl.netanel.swt.matrix.Painter<X,Y>
public class Painter<X extends java.lang.Number,Y extends java.lang.Number>
This class draws everything that appears on the matrix canvas: background, images, text, lines.
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.
Field Summary | |
---|---|
protected Point |
availableTextArea
|
protected Image |
collapsedImage
|
protected boolean |
expanded
|
protected Image |
expandedImage
|
protected Point |
extent
|
protected Frozen |
frozenX
|
protected Frozen |
frozenY
|
protected GC |
gc
Provides graphic to the init() , clean() ,
paint(int, int, int, int) methods. |
protected boolean |
hasChildren
|
Image |
image
Image to be painted. |
Image[] |
imagesAfter
Contains images that will be displayed after the text starting from the closest one. |
Image[] |
imagesBefore
Contains images that will be displayed before the text starting from the most distant one. |
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 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 TextLayout |
textLayout
|
Constructor Summary | |
---|---|
Painter(java.lang.String name)
Constructs a painter with the given name. |
|
Painter(java.lang.String name,
int scope)
The main constructor. |
Method Summary | |
---|---|
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()
Restores the default GC settings modified by modified by in init()
or paint(int, int, int, int) . |
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 Point |
computeSize(X indexX,
Y indexY,
int wHint,
int hHint)
Returns the preferred size of the receiver. |
protected void |
computeTextSize(java.lang.String s)
Computes size of the given text using the current font of the graphic context. |
void |
dispose()
|
java.lang.Object |
getData()
Returns custom data of this painter. |
Image |
getImageAt(int x,
int y)
Returns an image which bounds contain the given point or null otherwise. |
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(Image collapsedImage,
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. |
void |
trackPosition(Image image,
boolean state)
Tracking image positions during painting allows to refer to its position later with #getImageAt(int, int). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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 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 Image image
Style.imageAlignX
,
Style.imageAlignY
, Style.imageMarginX
, Style.imageMarginY
properties.
public Image[] imagesBefore
imagesAfter
public Image[] imagesAfter
imagesBefore
public boolean selectionHighlight
public Style style
protected Point availableTextArea
protected TextLayout textLayout
protected Point extent
protected Image collapsedImage
protected Image expandedImage
protected Point nodeImageSize
protected boolean hasChildren
protected boolean expanded
protected Frozen frozenX
protected Frozen frozenY
Constructor Detail |
---|
public Painter(java.lang.String name)
NAME_CELLS
scope = SCOPE_CELLS
NAME_LINES_X
scope = SCOPE_LINES_X
NAME_LINES_Y
scope = SCOPE_LINES_Y
NAME_EMBEDDED_CONTROLS
scope = SCOPE_CELLS
NAME_EMULATED_CONTROLS
scope = SCOPE_CELLS
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_
.Method Detail |
---|
public java.lang.String getName()
public int getScope()
protected boolean init()
paint(int, int, int, int)
and clean()
methods will not be executed.
clean()
public void clean()
GC
settings modified by modified by in init()
or paint(int, int, int, int)
.
init()
public void dispose()
protected 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
)
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()
availableTextArea
field.
After the method determines new text to display it should modify the availableTextArea properties
to match the size of the new text. It is needed for text alignment other then SWT#LEFT
.
protected void computeTextSize(java.lang.String s)
s
- text to compute the size forpublic void setup(X indexX, Y indexY)
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)
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)
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)
enabled
- the new enabled statepublic boolean isEnabled()
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.
public void setNodeImages(Image collapsedImage, Image expandedImage)
collapsedImage
- image representing collapsed state.expandedImage
- image representing expanded state.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 cell
public Zone<X,Y> getZone()
public void trackPosition(Image image, boolean state)
image
- image to track the positions forpublic Image getImageAt(int x, int y)
x
- the x screen coordinate in the zone to check for the image aty
- the y screen coordinate in the zone to check for the image at
getImageAt(int, int)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |