ilog.views.diagrammer.application
Class IlvDiagrammerPaletteAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by ilog.views.util.swing.context.ComponentAction
          extended by ilog.views.diagrammer.application.IlvDiagrammerAction
              extended by ilog.views.diagrammer.application.IlvDiagrammerPaletteAction
All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action

public class IlvDiagrammerPaletteAction
extends IlvDiagrammerAction

The class IlvDiagrammerPaletteAction provides an easy way to build "palettes" to create nodes and links interactively in a diagram component, IlvDiagrammer.

A palette is an IlvDiagrammerToolBar whose buttons represent various types of nodes and links. The user clicks a button to choose the type of node or link, then (s)he clicks in the view to create the node or link in the diagram.

Here is an example showing how to create a palette toolbar:

   IlvDiagrammer palette = new IlvDiagrammer();
   palette.setDataFile(new URL("file:palette.xml"));
   palette.setStyleSheet(new URL("file:style.css"));
   Action[] actions =
         IlvDiagrammerPaletteAction.getActions(palette,
                            new IlvDiagrammerHashFunction());
   IlvDiagrammerToolBar paletteToolbar =
         new IlvDiagrammerToolBar(actions, JToolBar.HORIZONTAL);
 

Or, even simpler, you can use the class IlvDiagrammerPaletteBar.

You can also add "palette" actions to an already populated toolbar as follows:

     Action[] paletteActions =
         IlvDiagrammerPaletteAction.getActions("file:palette.xml",
                                               "file:style.css");
     IlvDiagrammerToolBar editToolbar =
         new IlvDiagrammerToolBar(IlvDiagrammerToolbar.editActions, JToolBar.HORIZONTAL);
     editToolbar.addActions(paletteActions);
 

The icons associated with the actions are created automatically: they are reduced versions of the nodes and links contained in the XML file passed to the getActions(ilog.views.diagrammer.IlvDiagrammer, ilog.views.diagrammer.application.IlvDiagrammerHashFunction) method, rendered using the specified style sheet. The tooltip associated with each action displays a full-size version of the node or link.

Since:
JViews 6.5
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class ilog.views.diagrammer.application.IlvDiagrammerAction
IlvDiagrammerAction.ErrorHandler, IlvDiagrammerAction.FileAction, IlvDiagrammerAction.Handler, IlvDiagrammerAction.StatusEvent, IlvDiagrammerAction.StatusListener, IlvDiagrammerAction.ToggleAction
 
Field Summary
 
Fields inherited from class ilog.views.diagrammer.application.IlvDiagrammerAction
_new, about, ABOUT_APPLICATION_NAME, alignBottom, alignHorizontalCenter, alignLeft, alignRight, alignTop, alignVerticalCenter, autoEditLabel, autoLabelLayout, autoLinkLayout, autoNodeLayout, callBuilder, clearPrintArea, close, copy, createLink, createNode, cut, delete, distributeHorizontally, distributeVertically, duplicate, editing, editLabel, exit, fitToContents, grid, gridSpacing, group, help, layoutAllNodes, layoutSelectedNodes, open, openStyleSheet, pageSetup, pan, paste, printPreview, printToBitmap, printWithDialog, printWithoutDialog, read, redo, refresh, resetZoom, resizing, save, saveAs, select, selectAll, setPrintArea, stickyModes, undo, ungroup, zoom, zoomIn, zoomOut
 
Fields inherited from class ilog.views.util.swing.context.ComponentAction
hideToolbarButtonBordersOnOceanTheme
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
IlvDiagrammerPaletteAction(boolean link)
          Creates a new action that creates a new type of node or link.
IlvDiagrammerPaletteAction(IlvDiagrammer palette, Object object)
          Creates a new action that creates a copy of the specified node or link.
 
Method Summary
static IlvDiagrammerAction[] getActions(IlvDiagrammer palette, IlvDiagrammerHashFunction hashFunction)
          Creates a set of palette actions.
 IlvDiagrammer getPaletteDiagrammer()
          Returns the diagram component used as the "source" from which nodes or links are copied.
 Object getPaletteObject()
          Returns the source object that is copied when creating an object.
static int getSmallIconSize()
          Returns the size of the icons in the Diagrammer toolbar.
 void init()
          Initializes the properties of the action.
protected  boolean isEnabled(IlvDiagrammer diagrammer)
          Returns true if the target diagram component is not null.
 boolean isLink()
          Returns true if this action creates a link
 boolean isSelectable()
          Always returns true to state that this is a selectable action that should be associated with a toggle button.
protected  boolean isSelected(IlvDiagrammer diagrammer)
          Returns true if this action is currently selected, that is, if waiting for the user to create a node or link.
 void perform(ActionEvent e, IlvDiagrammer diagrammer)
          Installs a node or link creation interaction in the target diagram component.
static void setSmallIconSize(int smallIconSize)
          Sets the size of the icons in the Diagrammer toolbar.
protected  void update(IlvDiagrammer diagrammer)
          Updates this action according to the state of the diagram component.
 
Methods inherited from class ilog.views.diagrammer.application.IlvDiagrammerAction
addActionToUpdate, addStatusListener, call, chooseFile, getActionFileChooser, getDefaultResourceBundle, getDefaultSelectedFile, getErrorHandler, getFileChooserDirectory, getString, isEnabled, isSelected, perform, removeActionToUpdate, removeStatusListener, setDefaultSelectedFile, setErrorHandler, setFileChooserDirectory, setHandler, update, updateActions
 
Methods inherited from class ilog.views.util.swing.context.ComponentAction
actionPerformed, addActionToUpdate, addPropertyChangeListener, addStatusListener, call, clone, createMenuItem, createToolBarButton, delayedUpdateActions, error, fireActionFinished, fireActionStarted, getActionErrorHandler, getPrefix, getResourceBundle, isSelected, removeActions, removeActionToUpdate, removeStatusListener, setActionErrorHandler, setHandler, setSelected, updateActions
 
Methods inherited from class javax.swing.AbstractAction
firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvDiagrammerPaletteAction

public IlvDiagrammerPaletteAction(IlvDiagrammer palette,
                                  Object object)
Creates a new action that creates a copy of the specified node or link. Typical applications should use the getActions(ilog.views.diagrammer.IlvDiagrammer, ilog.views.diagrammer.application.IlvDiagrammerHashFunction) static method to create a set of palette actions in a single operation.

Parameters:
palette - The diagram component used as the "source" from which nodes or links are copied.
object - The node or link that will be copied when the user clicks in the target diagram component.

IlvDiagrammerPaletteAction

public IlvDiagrammerPaletteAction(boolean link)
Creates a new action that creates a new type of node or link. This action first prompts for the node or link's tag (type).

Parameters:
link - If true, a link will be created, otherwise a node is created.
Method Detail

isEnabled

protected boolean isEnabled(IlvDiagrammer diagrammer)
                     throws Exception
Returns true if the target diagram component is not null.

Specified by:
isEnabled in class IlvDiagrammerAction
Parameters:
diagrammer - The diagram component in which the object is to be created.
Returns:
true if action is enabled
Throws:
Exception - When an error occurs while getting the state of the action.

isSelectable

public boolean isSelectable()
Always returns true to state that this is a selectable action that should be associated with a toggle button.

Overrides:
isSelectable in class ilog.views.util.swing.context.ComponentAction

isLink

public boolean isLink()
Returns true if this action creates a link

Returns:
true if this action creates a link

perform

public final void perform(ActionEvent e,
                          IlvDiagrammer diagrammer)
                   throws Exception
Installs a node or link creation interaction in the target diagram component.

Specified by:
perform in class IlvDiagrammerAction
Parameters:
e - action to process
diagrammer - The target diagram component.
Throws:
Exception - When an error occurs while performing the action.

update

protected void update(IlvDiagrammer diagrammer)
Updates this action according to the state of the diagram component.

Overrides:
update in class IlvDiagrammerAction
Parameters:
diagrammer - The target diagram component.

isSelected

protected boolean isSelected(IlvDiagrammer diagrammer)
                      throws Exception
Returns true if this action is currently selected, that is, if waiting for the user to create a node or link.

Overrides:
isSelected in class IlvDiagrammerAction
Parameters:
diagrammer - The target diagram component.
Returns:
true if action is selected
Throws:
Exception - When an error occurs while getting the action's state.

init

public void init()
Initializes the properties of the action. This method generates the icon and tooltip for the action by rendering the associated object and dumping its image to create the icon and tooltip.

Overrides:
init in class ilog.views.util.swing.context.ComponentAction

getActions

public static IlvDiagrammerAction[] getActions(IlvDiagrammer palette,
                                               IlvDiagrammerHashFunction hashFunction)
Creates a set of palette actions. For each object in the Diagrammer palette, an action is created, with an icon and a tooltip representing the rendered object.

The resulting action array can be used to populate an IlvDiagrammerToolBar as follows:

     Action[] actions =
         IlvDiagrammerPaletteAction.getActions(palette, 
         new IlvDiagrammerHashFunction);
     IlvDiagrammerToolBar paletteToolbar =
         new IlvDiagrammerToolBar(actions, JToolBar.HORIZONTAL);
 

You can pass an IlvDiagrammerHashFunction to populate the palette with only one instance of each "type" of node or link. Nodes or links are considered equal if the hash function returns the same hash code.

Parameters:
palette - The diagram component containing the set of nodes and links to use as "prototypes" in the palette.
hashFunction - The hash function used to filter equivalent nodes and links. If a node or link is considered "equal" to another node or link that is already in the palette, it will not be added. Nodes or links are considered equal if the hash function returns the same hash code.
Returns:
array of actions

setSmallIconSize

public static void setSmallIconSize(int smallIconSize)
Sets the size of the icons in the Diagrammer toolbar. Default is 20


getSmallIconSize

public static int getSmallIconSize()
Returns the size of the icons in the Diagrammer toolbar.


getPaletteObject

public Object getPaletteObject()
Returns the source object that is copied when creating an object.

Returns:
source object
Since:
JViews 7.5

getPaletteDiagrammer

public IlvDiagrammer getPaletteDiagrammer()
Returns the diagram component used as the "source" from which nodes or links are copied.

Returns:
diagrammer
Since:
JViews 7.5


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