public class IlvEditLabelInteractor extends IlvManagerViewInteractor implements IlvPermanentInteractorInterface
IlvEditLabelInteractor
lets the user create and edit
a graphic object containing a label.
This class works in one of three available modes: creation only,
edit only, or creation and edition.
Any graphic object that displays a label and implements the
IlvLabelInterface
interface can be edited with an
IlvEditLabelInteractor
object.
You can create any type of labeled graphic object by setting a
factory of labeled objects.
When this interactor is installed on a view, the following functionality is available to the user:
IlvLabelInterface
, an editor opens to edit the object.IlvLabel
is created when the edit is
validated by the user.An edit if validated in one of the following ways:
RETURN
or
clicks elsewhere on the view.
When the text field is open in a Swing application, and the graphic object
supports the base text direction (see
IlvGraphic.setBaseTextDirection(int)
), the user can change the base text
direction while editing the label in the following way:
The following code example shows how to use
IlvEditLabelInteractor
in a simple Java application:
IlvManager mgr = new IlvManager(); IlvManagerView view = new IlvManagerView(mgr); ... IlvEditLabelInteractor inter = new IlvEditLabelInteractor(); view.setInteractor(inter);
IlvEditLabelInteractor
is a custom global interactor, that
is, a subclass of IlvManagerViewInteractor
. A global interactor
is a class that listens to a specific event in the manager view. All input events
are handled by means of interactors or accelerators. For information about
how to treat events in a manager, see
Handling Events. The following code
examples show how to handle user events:
IlvLabelInterface
,
Serialized FormConstructor and Description |
---|
IlvEditLabelInteractor()
Creates the interactor.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
accept(IlvGraphic obj)
Verifies whether editing of the object is allowed.
|
protected void |
addObject(IlvGraphic obj)
Called by the interactor to add a
newly created object in the manager.
|
protected void |
attach(IlvManagerView v)
Called when the
interactor is attached to the manager view.
|
protected Component |
createEditComponent(boolean useSwing,
boolean multi,
ActionListener actionListener,
FocusListener focusListener)
Allocates a component that allows you to edit the label.
|
protected void |
detach()
Called when the interactor
is detached from the view.
|
protected void |
editObject(IlvGraphic obj,
IlvPoint pt)
Called to do the actual editing of the graphic
object, which may be
null when creating a new one. |
protected boolean |
ensureEditAreaInView()
Returns
true if the label editing area used by this
interactor always remains inside the bounds of the view. |
protected IlvRect |
getEditingAreaBBox(IlvGraphic obj,
IlvPoint pt,
int nLines,
int labelWidth,
int lineHeight,
int borderWidth,
IlvTransformer t)
Used by the interactor to compute the bounding
area of the text field used for editing the
text in the graphic object.
|
protected Font |
getEditionFont(IlvGraphic obj)
Returns the font used to edit the object.
|
Font |
getFont()
Returns the font used to create the object.
|
Color |
getForeground()
Returns the foreground color used to create the object.
|
protected IlvRect |
getLabelBBox(IlvGraphic obj,
IlvTransformer t)
Used by the interactor to compute the bounding
area of the text in the graphic object.
|
IlvLabeledObjectFactory |
getObjectFactory()
Returns the factory installed, if any.
|
protected String |
getObjectLabel(IlvGraphic obj)
Retrieves the text from the edited object.
|
boolean |
isCreationAllowed()
Returns
true if the interactor allows objects to be created. |
boolean |
isCreationInSubManagersAllowed()
Returns
true if the creation of objects in submanagers
is allowed, and false otherwise. |
boolean |
isEditionAllowed()
Returns
true if the interactor allows objects to be edited. |
boolean |
isGrapherMode()
Returns
true if the interactor is in grapher mode. |
boolean |
isPermanent()
Returns
false if the interactor is removed from the
view once the object has been edited. |
protected IlvGraphic |
makeObject(IlvPoint p,
String label)
Creates the object.
|
protected void |
processMouseEvent(MouseEvent event)
Processes the mouse events.
|
void |
setCreationAllowed(boolean set)
Allows objects to be created with this interactor (
true ). |
void |
setCreationInSubManagersAllowed(boolean set)
Allows objects to be created in submanagers
(see
IlvManager.getManagers() ). |
void |
setEditionAllowed(boolean set)
Allows objects to be edited with this interactor (
true ). |
void |
setFont(Font font)
Changes the font used to create the object.
|
void |
setForeground(Color color)
Changes the foreground color used to create the object.
|
void |
setGrapherMode(boolean value)
Sets the grapher mode value.
|
void |
setObjectFactory(IlvLabeledObjectFactory factory)
Sets a factory of labeled objects for the interactor.
|
protected void |
setObjectLabel(IlvGraphic obj,
String str)
Changes the text of the edited object.
|
void |
setPermanent(boolean permanent)
Specifies whether the interactor is removed from the view once
the object has been edited.
|
protected boolean |
supportMultiline(IlvGraphic obj)
Called to indicate whether the label of the object can
have multiple lines.
|
addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, allowEnsureVisible, allowEnsureVisible, disableEvents, drawGhost, drawGhost, enableEvents, ensureVisible, ensureVisible, getManager, getManagerView, getTransformer, handleExpose, isXORGhost, processEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, setXORGhost
protected void attach(IlvManagerView v)
attach
in class IlvManagerViewInteractor
v
- The manager view.IlvManagerViewInteractor.detach()
protected void detach()
detach
in class IlvManagerViewInteractor
IlvManagerViewInteractor.attach(ilog.views.IlvManagerView)
public final boolean isEditionAllowed()
true
if the interactor allows objects to be edited.
The default value is true
. Note that if editing is
not allowed then you can only create objects with this interactor.public final void setEditionAllowed(boolean set)
true
).
Note that if editing is not allowed, you can only create objects
with this interactor.public final boolean isCreationAllowed()
true
if the interactor allows objects to be created.
The default value is true
. Note that if creation is
not allowed then you can only edit objects with this interactor.public final void setCreationAllowed(boolean set)
true
).
Note that if creation is not allowed, you can only edit objects
with this interactor.public void setCreationInSubManagersAllowed(boolean set)
IlvManager.getManagers()
). If creation in
submanagers is not allowed, the object is always created in the
IlvManager
displayed by the IlvManagerView
to which this interactor is attached.
The default value is true
.
public boolean isCreationInSubManagersAllowed()
true
if the creation of objects in submanagers
is allowed, and false
otherwise.public final boolean isPermanent()
false
if the interactor is removed from the
view once the object has been edited.
The default value is false
.isPermanent
in interface IlvPermanentInteractorInterface
public final void setPermanent(boolean permanent)
false
.setPermanent
in interface IlvPermanentInteractorInterface
permanent
- the new mode.protected void addObject(IlvGraphic obj)
addObject
on the manager in default mode.
It calls addNode
on the grapher in grapher mode if the
interactor is attached to a grapher view.obj
- The object to be added.setGrapherMode(boolean)
protected IlvGraphic makeObject(IlvPoint p, String label)
IlvLabel
.
If a factory is set for the interactor, it will be used to
create the object.p
- The point indicating the object's position in the coordinate
system of the manager to which the label will be added.label
- The label.setObjectFactory(ilog.views.interactor.IlvLabeledObjectFactory)
public final void setObjectFactory(IlvLabeledObjectFactory factory)
IlvLabel
will be created.factory
- The new factory or null
to remove
the factory.public IlvLabeledObjectFactory getObjectFactory()
protected String getObjectLabel(IlvGraphic obj)
getLabel
method of the interface IlvLabelInterface
.protected void setObjectLabel(IlvGraphic obj, String str)
setLabel
method of the interface IlvLabelInterface
.protected boolean supportMultiline(IlvGraphic obj)
true
, a multiline editor
is used for editing; otherwise, a single line editor is used.
The actual implementation uses the supportMultiline
method of the interface IlvLabelInterface
.obj
- The object being edited or null
. If this
parameter is null
then no object is edited, but
a new object will be created. In this case, the method must return
true
if the created object supports a multiline label.protected IlvRect getLabelBBox(IlvGraphic obj, IlvTransformer t)
getLabelBBox
method of the interface
IlvLabelInterface
if the graphic object implements this interface; otherwise it
returns the bounding box of the object.protected Font getEditionFont(IlvGraphic obj)
getFont
of the interface IlvLabelInterface
if the
edited object implements this interface; otherwise a default font is
returned.obj
- The edited object.protected Component createEditComponent(boolean useSwing, boolean multi, ActionListener actionListener, FocusListener focusListener)
JTextField
is used for the single-line labels, and a JTextArea
is used
for labels that support multiple lines. In AWT, a TextField
and a TextArea
are used correspondingly.
This message can be overridden if special components should be used for editing a label.
useSwing
- Whether the manager view is embedded in a Swing component.multi
- Whether the label support multiple lines.actionListener
- The action listener to be performed on the component.focusListener
- The focus listener to be performed on the component.protected void editObject(IlvGraphic obj, IlvPoint pt)
null
when creating a new one.
The default implementation is to pop up a text field to allow editing of
the object.obj
- The graphic object to edit.pt
- The mouse position in view coordinates.getEditingAreaBBox(IlvGraphic, IlvPoint, int, int, int, int, IlvTransformer)
,
getLabelBBox(IlvGraphic, IlvTransformer)
protected IlvRect getEditingAreaBBox(IlvGraphic obj, IlvPoint pt, int nLines, int labelWidth, int lineHeight, int borderWidth, IlvTransformer t)
getLabelBBox(IlvGraphic, IlvTransformer)
.obj
- The graphic object to edit.pt
- The mouse position in view coordinates.nLines
- The number of lines of the label.labelWidth
- The width of the label.lineHeight
- The height of the text line.borderWidth
- The width of the border to be preserved.t
- The transformer used to draw the object.editObject(IlvGraphic, IlvPoint)
,
getLabelBBox(IlvGraphic, IlvTransformer)
protected boolean accept(IlvGraphic obj)
obj
can be edited.
The current implementation only allows the
editing of objects that implement the IlvLabelInterface
.protected void processMouseEvent(MouseEvent event)
processMouseEvent
in class IlvManagerViewInteractor
event
- The event.IlvManagerViewInteractor.addMouseListener(java.awt.event.MouseListener)
public Color getForeground()
public void setForeground(Color color)
public Font getFont()
public void setFont(Font font)
public boolean isGrapherMode()
true
if the interactor is in grapher mode.
The default is false
.setGrapherMode(boolean)
public void setGrapherMode(boolean value)
true
, created objects will be added to
the grapher of the attached view with the addNode
method.
If false
, they will be added with addObject
.value
- The value to be set.isGrapherMode()
protected boolean ensureEditAreaInView()
true
if the label editing area used by this
interactor always remains inside the bounds of the view. When the view
is scrolled, the position of the label editing area may become different
to the position of the label because the label can scroll outside the
visible area of the view while the label editing area remains inside
this visible area.
Returns true
by default. You can override this method to
disable that the label editing area is limited to the view.
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.