public class TLcdGXYTextPainter extends ALcdGXYPainter implements ILcdGXYPainter, ILcdGXYEditorProvider, ILcdGXYEditor
ILcdText
objects and enables visual editing of
ILcd2DEditableText
objects in an ILcdGXYView
.
This painter does not provides different paint modes to paint the body of an ILcdText
object.
However, a number of properties can be set to change the visualization of the text:
|
||||||
![]() |
|
![]() |
|
![]() |
|
![]() |
A text | |
A framed text |
|
A filled text |
|
A filled and framed text |
This painter defines the four corner points of the ILcdText
object as a handle of the
text. The following image clarifies the handle location, the corner points are represented by red
points.
This painter does not support snapping.
The visualization of the ILcdText
object is governed by the font style, frame style and fill
style set to this painter. Depending on the different paint properties some of these will be taken into
account.
The anchor point of the ILcdText
object is located at the center point of the bounds,
calculated by boundsSFCT
.
A ILcdText
object is touched when the mouse pointer is located within the rotated bounds
of the text.
To edit a text object, up to four corner handles are visualized. The amount of handles and their behavior depends on the vertical and horizontal alignment of the text, and on whether the handles are being translated or reshaped.
TRANSLATED
:
If the interior of the text bounds are touched, the whole shape is translated.
If a corner handle is translated, it stretches and rotates the shape starting from an anchor point determined by
the alignment. The images below illustrate the editing behavior when the text is aligned to the left and the bottom.
The small black arrow indicates the path of the mouse cursor while translating the bounds. ![]() |
|
![]() |
Moving a corner point. | |
Moving the interior. |
RESHAPED
:
The reshaping behavior allows stretching the shape by dragging one of its edges, starting from an anchor point determined by
the alignment. When touching a corner point, the behavior is identical as with the TRANSLATED mode. The images below
illustrate the editing behavior when the text is aligned to the left and the bottom.
The small black arrow indicates the path of the mouse cursor while reshaping the bounds. ![]() |
|
![]() |
Moving a corner point. | |
Moving a frame edge. |
When initializing a text via interaction through the view, a number of user interactions are required to
complete the initialization. This number depends on the creation mode
and
it is either 1 or 3 for the modes ONE_CLICK
or THREE_CLICK
.
Whenever the text string of the ILcdText
object needs to be edited, the protected method
getText
is called. Overwrite this method to customize the editing of the text string.
By default the class TLcdUserDialog
is used to pop up an input dialog.
This painter does not support snapping.
If either the width or the height of the text is 0, it will be painted using the original, unscaled font.
ILcdText
,
ILcd2DEditableText
,
Serialized FormModifier and Type | Field and Description |
---|---|
static Cursor |
cursorReshaping
The cursor shown when reshaping a text.
|
static Cursor[] |
cursorResizing
The cursors shown when resizing a text.
|
static Cursor |
cursorTranslating
The cursor shown when translating a text.
|
protected static int |
LEFT_BOTTOM
Constant value denoting the left bottom corner point of the text.
|
protected static int |
LEFT_TOP
Constant value denoting the left top corner point of the text.
|
static int |
ONE_CLICK
Constant for the one click creation mode.
|
protected static int |
RIGHT_BOTTOM
Constant value denoting the right bottom corner point of the text.
|
protected static int |
RIGHT_TOP
Constant value denoting the right top corner point of the text.
|
static int |
THREE_CLICK
Constant for the three click creation mode.
|
defaultCreationFillStyle, defaultCreationLineStyle, defaultFillStyle, defaultLineStyle, fWorkBounds
BODY, CREATING, DEFAULT, HANDLES, RESHAPING, SELECTED, SNAPS, TRANSLATING
CREATING, END_CREATION, RESHAPED, START_CREATION, TRANSLATED
Constructor and Description |
---|
TLcdGXYTextPainter()
Constructs a default
TLcdGXYTextPainter and sets the display name
to "Text". |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptSnapTarget(Graphics aGraphics,
ILcdGXYContext aGXYContext)
Returns
false because snapping is not supported. |
void |
boundsSFCT(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext,
ILcd2DEditableBounds aBoundsSFCT)
Computes the bounds of the representation of an
ILcdText in AWT coordinates. |
Object |
clone()
Makes
Object.clone() public. |
boolean |
edit(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
This implementation edits the
ILcdText object set to the painter. |
int |
getCreationClickCount()
Returns either 1 or 3 depending on the
creation mode
(ONE_CLICK or THREE_CLICK ) as the number of required user interactions. |
Cursor |
getCursor(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
Returns a
Cursor that clarifies the render mode and context this painter is operating
in. |
ILcdGXYPainterStyle |
getFillStyle()
Returns the style used to fill the background of the
ILcdText object. |
ILcdGXYPainterStyle |
getFontStyle()
Returns the style used to paint the
ILcdText object. |
ILcdGXYPainterStyle |
getFrameStyle()
Returns the style used to paint the frame around the
ILcdText object. |
ILcdGXYEditor |
getGXYEditor(Object aObject)
Returns this instance as editor for editing the specified
Object . |
int |
getMargin()
Returns the number of pixels of the margin used around the
ILcdText object. |
Object |
getObject()
Returns the object that can currently be painted or edited by this painter/editor.
|
ILcdIcon |
getSnapIcon()
Returns the icon that is used to paint snap target points of the object set to this painter.
|
protected void |
getText(ILcdGXYContext aGXYContext,
ILcd2DEditableText aTextSFCT)
Gets a new text for the
ILcd2DEditableText object. |
boolean |
isFilled()
Returns whether the text should be painted in a filled background.
|
boolean |
isFitTextInArea()
Returns whether the text should be stretched to fit in its
area , regardless of font. |
boolean |
isFramed()
Returns whether a frame should be painted around the text.
|
boolean |
isFramedWhenSelected()
Returns whether a frame should be painted around the text when it is painted in selected mode.
|
boolean |
isSnapToInvisiblePoints()
Returns whether the painter allows snapping to the invisible points of the shape.
|
boolean |
isTouched(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
Depending on the rendering mode, returns whether the mouse pointer is within the rotated bounds
of the
ILcdText object. |
protected boolean |
linkToSnapTarget(Graphics aGraphics,
ILcd2DEditableText aTextSFCT,
int aTouchedCorner,
ILcdGXYContext aGXYContext)
Sets the specified corner point at the given snap target, if the snap target is accepted.
|
void |
paint(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
Displays the representation of the object in the given mode on the Graphics passed, taking into
account the context passed.
|
void |
setCreationMode(int aCreationMode)
Sets the mode to decide how to create an
ILcdText object. |
void |
setFilled(boolean aFilled)
Sets whether the text should be painted in a filled background or not.
|
void |
setFillStyle(ILcdGXYPainterStyle aFillStyle)
Sets the style that will be used to fill the background of the
ILcdText object. |
void |
setFitTextInArea(boolean aFitTextInArea)
Sets whether the text should be stretched to fit in its
area , regardless of font. |
void |
setFontStyle(ILcdGXYPainterStyle aFontStyle)
Sets the style that will be used to paint the
ILcdText object. |
void |
setFramed(boolean aFramed)
Sets whether a frame should be painted around the text or not.
|
void |
setFramedWhenSelected(boolean aFramedWhenSelected)
Sets whether a frame should be painted around the text when it is painted in selected mode or not.
|
void |
setFrameStyle(ILcdGXYPainterStyle aFrameStyle)
Sets the style that will be used to paint the frame around the
ILcdText object. |
void |
setMargin(int aMargin)
Sets the number of pixels of the margin that will be used around the
ILcdText
object for drawing the handles, the frame, the filled background,... |
void |
setModelModelTransformationClass(Class aModel2ModelTransformationClass)
Empty implementation because snapping is not supported.
|
void |
setObject(Object aObject)
Sets the object to paint and edit.
|
void |
setSnapIcon(ILcdIcon aSnapIcon)
Sets the icon that marks snap targets of the object currently set to this painter.
|
void |
setSnapToInvisiblePoints(boolean aSnapToInvisiblePoints)
Sets whether the other shapes can snap to invisible points of this shape.
|
static void |
setStartLetterWidth(int aStartLetterWidth)
Sets the start width defined in pixels of the letters when created in
ONE_CLICK mode. |
static void |
setStartTextHeight(int aStartTextHeight)
Sets the start height defined in pixels of the text when created in
ONE_CLICK mode. |
protected void |
setupGraphicsForFill(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
Called just before filling the backgrounds on the specified
Graphics object. |
protected void |
setupGraphicsForFrame(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
Called just before painting the frame on the specified
Graphics object. |
protected void |
setupGraphicsForText(Graphics aGraphics,
int aRenderMode,
ILcdGXYContext aGXYContext)
Called just before drawing the text on the specified
Graphics object. |
Object |
snapTarget(Graphics aGraphics,
ILcdGXYContext aGXYContext)
Returns
null because snapping is not supported. |
boolean |
supportSnap(Graphics aGraphics,
ILcdGXYContext aGXYContext)
This implementation does not support snapping, always returns
false . |
addPropertyChangeListener, anchorPointSFCT, firePropertyChangeEvent, firePropertyChangeEvent, getDisplayName, getGXYPainter, isTraceOn, removePropertyChangeListener, setClassTraceOn, setDisplayName, setTraceOn
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
anchorPointSFCT, getDisplayName
getDisplayName
addPropertyChangeListener, removePropertyChangeListener
protected static final int LEFT_BOTTOM
protected static final int LEFT_TOP
protected static final int RIGHT_TOP
protected static final int RIGHT_BOTTOM
public static final int ONE_CLICK
ILcdText
object. The initial width and height of the text
are defined by the properties startLetterWidth
and startTextHeight
.setCreationMode(int)
,
Constant Field Valuespublic static final int THREE_CLICK
setCreationMode(int)
,
Constant Field Valuespublic static volatile Cursor cursorTranslating
public static Cursor cursorReshaping
public static Cursor[] cursorResizing
public TLcdGXYTextPainter()
TLcdGXYTextPainter
and sets the display name
to "Text".public void setObject(Object aObject)
Sets the object to paint and edit. The object should be an instance of ILcdText
for painting and an instance of ILcd2DEditableText
for editing.
This painter/editor can be used to paint the object without using the edit functionality. This
method shall therefore only check if the object implements ILcdText
and shall throw
a ClassCastException
if it does not.
When this painter is used as editor with an object that does not implement the interface ILcd2DEditableText
, the edit
method shall throw the necessary exception.
setObject
in interface ILcdGXYEditor
setObject
in interface ILcdGXYPainter
aObject
- The object to paint and edit.ClassCastException
- when the object does not implement ILcdText
.getObject()
public final Object getObject()
getObject
in interface ILcdGXYEditor
getObject
in interface ILcdGXYPainter
setObject(Object)
public void setCreationMode(int aCreationMode)
ILcdText
object. A text can be created
in the following modes. The default value is ONE_CLICK
.
ONE_CLICK
, which enables setting the location point,THREE_CLICK
, which enables setting the location point,
the rotation angle, and the width and height of the text.aCreationMode
- The mode deciding how to create an ILcdText
object.public static void setStartTextHeight(int aStartTextHeight)
ONE_CLICK
mode.
The default value of this property is 20
.aStartTextHeight
- the height of text when created in ONE_CLICK
mode.public static void setStartLetterWidth(int aStartLetterWidth)
ONE_CLICK
mode.
The default value of this property is 20
.aStartLetterWidth
- the width of the letters when created in ONE_CLICK
mode.public void setFramed(boolean aFramed)
false
.aFramed
- A flag indicating whether a frame should be painted around the text or not.isFramed()
public boolean isFramed()
setFramed(boolean)
public void setFramedWhenSelected(boolean aFramedWhenSelected)
false
.aFramedWhenSelected
- A flag indicating whether a frame should be painted around the text
when it is painted in selected mode or not.isFramedWhenSelected()
public boolean isFramedWhenSelected()
setFramedWhenSelected(boolean)
public void setFitTextInArea(boolean aFitTextInArea)
area
, regardless of font.
By default, the text is not stretched, the value is false
.
If set, the text will be stretched such that the displayed text is as wide as ILcdText.getTextWidth()
,
so based on character width
x text length
.
This may cause the letters' aspect to change.aFitTextInArea
- A flag indicating whether the text should be stretched to fit in its area.isFitTextInArea()
public boolean isFitTextInArea()
area
, regardless of font.setFitTextInArea(boolean)
public void setFilled(boolean aFilled)
false
.aFilled
- A flag indicating whether the text should be painted in a filled background or not.isFilled()
public boolean isFilled()
setFilled(boolean)
public void setMargin(int aMargin)
Sets the number of pixels of the margin that will be used around the ILcdText
object for drawing the handles, the frame, the filled background,...
The default value of this property is 2
pixels. Note that negative values are
not allowed and are converted to 0
.
aMargin
- the number of pixels of the margin around the ILcdText
object.getMargin()
public int getMargin()
ILcdText
object.ILcdText
object.setMargin(int)
public void setSnapToInvisiblePoints(boolean aSnapToInvisiblePoints)
false
.aSnapToInvisiblePoints
- A flag indicating whether snapping to the invisible points is allowed.isSnapToInvisiblePoints()
public boolean isSnapToInvisiblePoints()
setSnapToInvisiblePoints(boolean)
public void setFontStyle(ILcdGXYPainterStyle aFontStyle)
ILcdText
object.aFontStyle
- the style used to paint the ILcdText
object.getFontStyle()
public ILcdGXYPainterStyle getFontStyle()
ILcdText
object.ILcdText
object.setFontStyle(com.luciad.view.gxy.ILcdGXYPainterStyle)
public void setFrameStyle(ILcdGXYPainterStyle aFrameStyle)
ILcdText
object.aFrameStyle
- the style used to paint the frame around the ILcdText
object.getFrameStyle()
public ILcdGXYPainterStyle getFrameStyle()
ILcdText
object.ILcdText
object.setFrameStyle(com.luciad.view.gxy.ILcdGXYPainterStyle)
public void setFillStyle(ILcdGXYPainterStyle aFillStyle)
ILcdText
object.aFillStyle
- the style used to fill the background of the ILcdText
object.getFillStyle()
public ILcdGXYPainterStyle getFillStyle()
ILcdText
object.ILcdText
object.setFillStyle(com.luciad.view.gxy.ILcdGXYPainterStyle)
public void setSnapIcon(ILcdIcon aSnapIcon)
paint
method is called with the render mode ILcdGXYPainter.SNAPS
.aSnapIcon
- The icon that should be used to paint snap target points.getSnapIcon()
public ILcdIcon getSnapIcon()
setSnapIcon(ILcdIcon)
protected void setupGraphicsForText(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
Called just before drawing the text on the specified Graphics
object. It can be
redefined in order to set specific Graphics
properties like Color
,
etc...
This implementation calls ILcdGXYPainterStyle.setupGraphics(java.awt.Graphics, java.lang.Object, int, com.luciad.view.gxy.ILcdGXYContext)
on the fontStyle property
if a font style has been set to this instance.
aGraphics
- The graphics to paint the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context to render the object in.protected void setupGraphicsForFrame(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
Called just before painting the frame on the specified Graphics
object. It can be
redefined in order to set specific Graphics
properties like Color
,
etc...
This implementation calls ILcdGXYPainterStyle.setupGraphics(java.awt.Graphics, java.lang.Object, int, com.luciad.view.gxy.ILcdGXYContext)
on the frameStyle property
if a frame style has been set to this instance.
aGraphics
- The graphics to paint the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context to render the object in.protected void setupGraphicsForFill(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
Called just before filling the backgrounds on the specified Graphics
object. It can
be redefined in order to set specific Graphics
properties like Color
,
etc...
This implementation calls ILcdGXYPainterStyle.setupGraphics(java.awt.Graphics, java.lang.Object, int, com.luciad.view.gxy.ILcdGXYContext)
on the fillStyle property
if a fill style has been set to this instance.
aGraphics
- The graphics to paint the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context to render the object in.public Cursor getCursor(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
Cursor
that clarifies the render mode and context this painter is operating
in. When no specific Cursor
is required, null
is returned.getCursor
in interface ILcdGXYPainter
getCursor
in class ALcdGXYPainter
aGraphics
- The graphics on which the object is painted.aRenderMode
- The mode to render the object in.aGXYContext
- The context in which the object is rendered.null
if
no particular cursor is required.public void boundsSFCT(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException
ILcdText
in AWT coordinates. The bounds
will include the four corner point of the text.boundsSFCT
in interface ILcdGXYPainter
aGraphics
- The graphics to paint the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context to render the object in.aBoundsSFCT
- The bounds to update.TLcdNoBoundsException
- if no bounds can be determined for the representation of the object. This can
be when the object does not have a representation in the given context, for example when it is located in
a part of the world which is not visible in the projection as set in the views world reference.isTouched
public boolean isTouched(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
ILcdText
object.isTouched
in interface ILcdGXYPainter
aGraphics
- The graphics to paint the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context in which the object is rendered.ILcdText
object.boundsSFCT
public void paint(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
paint
in interface ILcdGXYPainter
aGraphics
- The graphics to paint the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context to render the object in.public ILcdGXYEditor getGXYEditor(Object aObject)
Object
. If this
Object
is not the same as the Object
set to this painter, the
setObject(Object)
method is called to update the object set to the painter.getGXYEditor
in interface ILcdGXYEditorProvider
aObject
- the object to be edited.Object
.public int getCreationClickCount()
creation mode
(ONE_CLICK
or THREE_CLICK
) as the number of required user interactions.getCreationClickCount
in interface ILcdGXYEditor
creation mode
.setCreationMode(int)
public boolean edit(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
This implementation edits the ILcdText
object set to the painter. The object needs to
implement the interface ILcd2DEditableText
otherwise a ClassCastException
will be thrown.
In ILcdGXYEditor.TRANSLATED
render mode, the ILcdText
object is edited as follows:
In ILcdGXYEditor.RESHAPED
render mode, the ILcdText
object is edited as follows:
The creation render mode behavior is defined by the creation mode
.
Further changes have to be done within edition mode.
ONE_CLICK
mode, that point will determine the location
point of the text. The initial width and height of the text are defined
by the properties startLetterWidth
and
startTextHeight
.THREE_CLICK
mode, the first point determines the location
point of the text, the second the rotation angle and the third the width
and height of the text.Note that this painter does not support snapping.
edit
in interface ILcdGXYEditor
aGraphics
- The graphics to edit the object on.aRenderMode
- The mode to render the object in.aGXYContext
- The context to render the object in.ClassCastException
- if the painter's object does not implement ILcd2DEditableText
.ILcdGXYContext
,
acceptSnapTarget
protected void getText(ILcdGXYContext aGXYContext, ILcd2DEditableText aTextSFCT)
ILcd2DEditableText
object.
The default implementation uses the com.luciad.gui.TLcdUserDialog
class to popup an input dialog.
aGXYContext
- the context in which to create the text.aTextSFCT
- the ILcd2DEditableText
for which the text will be set.TLcdUserDialog
protected boolean linkToSnapTarget(Graphics aGraphics, ILcd2DEditableText aTextSFCT, int aTouchedCorner, ILcdGXYContext aGXYContext)
LEFT_BOTTOM
,
LEFT_TOP
,RIGHT_BOTTOM
,RIGHT_TOP
). Note that this painter does
not support snapping, this implementation is therefore empty.aGraphics
- The graphics to paint the object on.aTextSFCT
- The bounds objects to be edited.aTouchedCorner
- The corner index to set at the snap target.aGXYContext
- The context to render the object in.LEFT_BOTTOM
,
LEFT_TOP
,
RIGHT_BOTTOM
,
RIGHT_TOP
public boolean supportSnap(Graphics aGraphics, ILcdGXYContext aGXYContext)
false
.supportSnap
in interface ILcdGXYPainter
supportSnap
in class ALcdGXYPainter
aGraphics
- the graphics on which is worked.aGXYContext
- the context of the snapping.false
.public Object snapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)
null
because snapping is not supported.snapTarget
in interface ILcdGXYPainter
snapTarget
in class ALcdGXYPainter
aGraphics
- the graphics on which is worked.aGXYContext
- the context of the snapping.null
.supportSnap
public void setModelModelTransformationClass(Class aModel2ModelTransformationClass)
aModel2ModelTransformationClass
- not taken into account.public boolean acceptSnapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)
false
because snapping is not supported.acceptSnapTarget
in interface ILcdGXYEditor
aGraphics
- the Graphics on which the snap target should be checked.aGXYContext
- the context in which the snap target should be checked.false
.ILcdGXYContext.getSnapTarget()
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 interface ILcdGXYEditorProvider
clone
in interface ILcdGXYPainterProvider
clone
in class ALcdGXYPainter
Object.clone()