ilog.views.interactor
Class IlvEditLabelInteractor

java.lang.Object
  extended by ilog.views.IlvManagerViewInteractor
      extended by ilog.views.interactor.IlvEditLabelInteractor
All Implemented Interfaces:
IlvPermanentInteractorInterface, Serializable

public class IlvEditLabelInteractor
extends IlvManagerViewInteractor
implements IlvPermanentInteractorInterface

IlvEditLabelInteractor lets the user create and edit a graphic object containing a label.

Overview

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.

Using the Edit Label Interactor

When this interactor is installed on a view, the following functionality is available to the user:

An edit if validated in one of the following ways:

Example

The following code example shows how to use IlvEditLabelInteractor in a simple Java application:

 IlvManager mgr = new IlvManager();
 IlvManagerView view = new IlvManagerView(mgr);
 ...
 IlvDragRectangleInteractor inter = new IlvEditLabelInteractor();
 view.setInteractor(inter);
 

About Interactors and Accelerators

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:

See Also:
IlvLabelInterface, Serialized Form

Constructor Summary
IlvEditLabelInteractor()
          Creates the interactor.
 
Method Summary
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 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.
 void setObjectFactory(IlvLabelledObjectFactory factory)
          Deprecated. Please use setObjectFactory(IlvLabeledObjectFactory).
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.
 
Methods inherited from class ilog.views.IlvManagerViewInteractor
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvEditLabelInteractor

public IlvEditLabelInteractor()
Creates the interactor.

Method Detail

attach

protected void attach(IlvManagerView v)
Called when the interactor is attached to the manager view.

Overrides:
attach in class IlvManagerViewInteractor
Parameters:
v - The manager view.
See Also:
IlvManagerViewInteractor.detach()

detach

protected void detach()
Called when the interactor is detached from the view.

Overrides:
detach in class IlvManagerViewInteractor
See Also:
IlvManagerViewInteractor.attach(ilog.views.IlvManagerView)

isEditionAllowed

public final boolean isEditionAllowed()
Returns 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.


setEditionAllowed

public final void setEditionAllowed(boolean set)
Allows objects to be edited with this interactor (true). Note that if editing is not allowed, you can only create objects with this interactor.


isCreationAllowed

public final boolean isCreationAllowed()
Returns 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.


setCreationAllowed

public final void setCreationAllowed(boolean set)
Allows objects to be created with this interactor (true). Note that if creation is not allowed, you can only edit objects with this interactor.


setCreationInSubManagersAllowed

public void setCreationInSubManagersAllowed(boolean set)
Allows objects to be created in submanagers (see 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.

Since:
JViews 5.0

isCreationInSubManagersAllowed

public boolean isCreationInSubManagersAllowed()
Returns true if the creation of objects in submanagers is allowed, and false otherwise.

Since:
JViews 5.0

isPermanent

public final boolean isPermanent()
Returns false if the interactor is removed from the view once the object has been edited. The default value is false.

Specified by:
isPermanent in interface IlvPermanentInteractorInterface

setPermanent

public final void setPermanent(boolean permanent)
Specifies whether the interactor is removed from the view once the object has been edited. The default value is false.

Specified by:
setPermanent in interface IlvPermanentInteractorInterface
Parameters:
permanent - the new mode.

addObject

protected void addObject(IlvGraphic obj)
Called by the interactor to add a newly created object in the manager. It simply calls 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.

Parameters:
obj - The object to be added.
See Also:
setGrapherMode(boolean)

makeObject

protected IlvGraphic makeObject(IlvPoint p,
                                String label)
Creates the object. This method is called to create the graphic object in case you have not selected an object for editing. The default implementation creates an instance of IlvLabel. If a factory is set for the interactor, it will be used to create the object.

Parameters:
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.
See Also:
setObjectFactory(ilog.views.interactor.IlvLabeledObjectFactory)

setObjectFactory

public final void setObjectFactory(IlvLabeledObjectFactory factory)
Sets a factory of labeled objects for the interactor. When a factory is set, it is responsible for creating the graphic object. If not, an object of class IlvLabel will be created.

Parameters:
factory - The new factory or null to remove the factory.
Since:
JViews 8.0

setObjectFactory

public final void setObjectFactory(IlvLabelledObjectFactory factory)
Deprecated. Please use setObjectFactory(IlvLabeledObjectFactory).

Sets the factory of labeled objects for the interactor.


getObjectFactory

public IlvLabeledObjectFactory getObjectFactory()
Returns the factory installed, if any.

Since:
JViews 8.0

getObjectLabel

protected String getObjectLabel(IlvGraphic obj)
Retrieves the text from the edited object. This method is called to retrieve the text from the object that is being edited. The actual implementation uses the getLabel method of the interface IlvLabelInterface.


setObjectLabel

protected void setObjectLabel(IlvGraphic obj,
                              String str)
Changes the text of the edited object. This method is called to change the text of the object that is being edited. The actual implementation uses the setLabel method of the interface IlvLabelInterface.


supportMultiline

protected boolean supportMultiline(IlvGraphic obj)
Called to indicate whether the label of the object can have multiple lines. If 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.

Parameters:
obj - The object being edited or null. If this parameter is nullthen 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.

getLabelBBox

protected IlvRect getLabelBBox(IlvGraphic obj,
                               IlvTransformer t)
Used by the interactor to compute the bounding area of the text in the graphic object. The result of this method is used to set the size and position of the edit field. The current implementation returns the result of the getLabelBBox method of the interface IlvLabelInterface if the graphic object implements this interface; otherwise it returns the bounding box of the object.

See Also:
editObject(IlvGraphic, IlvPoint), getEditingAreaBBox(IlvGraphic, IlvPoint, int, int, int, int, IlvTransformer)

getEditionFont

protected Font getEditionFont(IlvGraphic obj)
Returns the font used to edit the object. This will be the font of the editing component. The current implementation returns the result of the method getFont of the interface IlvLabelInterface if the edited object implements this interface; otherwise a default font is returned.

Parameters:
obj - The edited object.

createEditComponent

protected Component createEditComponent(boolean useSwing,
                                        boolean multi,
                                        ActionListener actionListener,
                                        FocusListener focusListener)
Allocates a component that allows to edit the label. The default behavior is the following: in Swing, a 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.

Parameters:
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.
Since:
JViews 7.5

editObject

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. The default implementation is to pop up a text field to allow editing of the object.

Parameters:
obj - The graphic object to edit.
pt - The mouse position in view coordinates.
Since:
JViews 5.0
See Also:
getEditingAreaBBox(IlvGraphic, IlvPoint, int, int, int, int, IlvTransformer), getLabelBBox(IlvGraphic, IlvTransformer)

getEditingAreaBBox

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. The method takes into account the rectangle returned by getLabelBBox(IlvGraphic, IlvTransformer).

Parameters:
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.
Returns:
The bounding area of the text field used for editing the graphic object.
Since:
JViews 7.5
See Also:
editObject(IlvGraphic, IlvPoint), getLabelBBox(IlvGraphic, IlvTransformer)

accept

protected boolean accept(IlvGraphic obj)
Verifies whether editing of the object is allowed. This method is called by the interactor to check whether the object obj can be edited. The current implementation only allows the editing of objects that implement the IlvLabelInterface.


processMouseEvent

protected void processMouseEvent(MouseEvent event)
Processes the mouse events.

Overrides:
processMouseEvent in class IlvManagerViewInteractor
Parameters:
event - The event.
See Also:
IlvManagerViewInteractor.addMouseListener(java.awt.event.MouseListener)

getForeground

public Color getForeground()
Returns the foreground color used to create the object.


setForeground

public void setForeground(Color color)
Changes the foreground color used to create the object.


getFont

public Font getFont()
Returns the font used to create the object.


setFont

public void setFont(Font font)
Changes the font used to create the object.


isGrapherMode

public boolean isGrapherMode()
Returns true if the interactor is in grapher mode. The default is false.

See Also:
setGrapherMode(boolean)

setGrapherMode

public void setGrapherMode(boolean value)
Sets the grapher mode value. If 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.

Parameters:
value - The value to be set.
See Also:
isGrapherMode()

ensureEditAreaInView

protected boolean ensureEditAreaInView()
Returns 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.

Since:
JViews 7.5


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.