com.japisoft.xmlpad.action
Class XMLAction

java.lang.Object
  extended byjavax.swing.AbstractAction
      extended bycom.japisoft.xmlpad.action.XMLAction
All Implemented Interfaces:
javax.swing.Action, java.awt.event.ActionListener, java.lang.Cloneable, java.util.EventListener, Features, Properties, java.io.Serializable
Direct Known Subclasses:
AbstractTreeAction, CommentAction, CommentTagAction, CopyFileLocation, CopyXPathLocation, FormatAction, InsertAction, InsertAction, LoadAction, NewAction, ParseAction, PasteAction, RedoAction, SaveAction, SearchAction, SearchElement, SelectAllAction, SelectTagAction, SplitAction, SplitActionHorizontal, TreeVisibilityAction, UndoAction, XMLActionForSelection

public abstract class XMLAction
extends javax.swing.AbstractAction
implements Features, Properties

Abstract class for XML action.

The XMLAction class is shared between serveral XMLContainers. Each time an XMLContainers take the focus, all XMLAction are resetted for taking into account the current XMLContainer. This is possible with the setXMLContainer method. You can force the usage of an XMLContainer calling ActionModel.resetActionState

This action takes an XMLContainer and XMLEditor context for working. You can invoke an action by calling notifyAction. The icon is found from the current classpath searching for an "Action" class name an "Action16.gif" or "Action24.gif" depending on the IMAGE_SIZE value. Otherwise, user can have its own icon location by overriding the getDefaultIcon method.

If you don't wish to use .gif image, please call XMLAction.IMAGE_EXT = EXT

If your action works only on the real time tree, you must implement the TreeAction interface or inherit from the com.japisoft.xmlpad.tree.action.AbstractTreeAction

You can change or traduce default label and tooltip using Properties file (from PropertyResourceBundle spec). This property file is found using the getName() value. So if you have a com.MyAction class, the property file will be found in the com/MyAction.properties path from the classpath. Use a LABEL key and a TOOLTIP key... like :


 LABEL=myActionName
 TOOLTIP=This is ...
 MNEMONIC=A
 ACCELERATOR=ctrl A
 ICON=com/japisoft/xmlpad/action/edit/CopyAction16.gif
 GROUP=Edit
 

To override a default action descriptor. Create a file from the default action name and inserts it before in your classpath the xmlpad.jar. For instance if you want to change the label of the NewAction, create a com/japisoft/xmlpad/action/new/NewAction.properties with a LABEL key or change the default one inside the xmlpad.jar

When adding an action in an existing group, you can override the getActionGroup method to match the good group or called setActionReferenceGroup to use the same group than the action name argument :

 
 
 class MyAction extends XMLAction {
		public MyAction() {
			super();
		}
		public String getPopupGroup() { return "Edit"; }
 }
 
 or
 
 class MyAction extends XMLAction {
 	public MyAction() {
 		setActionReferenceGroup( ActionModel.CUT_ACTION );
 	}
 }
 
 

  UIManager properties : 
 - xmlpad.action.[FULL ACTION CLASS NAME].mnemonic (a string)
 - xmlpad.action.[FULL ACTION CLASS NAME].accelerator(a string)
 - xmlpad.action.[FULL ACTION CLASS NAME].label
 - xmlpad.action.[FULL ACTION CLASS NAME].tooltip
 - xmlpad.action.[FULL ACTION CLASS NAME].icon
 

Version:
1.7
Author:
(c) 2002-2003 JAPISoft
See Also:
Serialized Form

Nested Class Summary
static class XMLAction.EmptyIcon
          Empty icon for alignment on popup
 
Field Summary
static boolean AUTO_UI
          Use default method for building UI part.
protected  XMLContainer container
           
protected  XMLEditor editor
           
protected  java.lang.String groupName
          XMLAction group reference name
static java.lang.String IMAGE_EXT
          Default image file extension
static int IMAGE_SIZE
          Default image size
static boolean INVALID_ACTION
          Status returned by the notifyAction
protected  java.lang.Object param
           
static boolean RESOURCE_BUNDLE
          Use a resource bundle for tabel/tooltip/shortcut/icon.
static boolean VALID_ACTION
          Status returned by the notifyAction
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface com.japisoft.xmlpad.action.Features
VALIDATING_FEATURE
 
Fields inherited from interface com.japisoft.xmlpad.action.Properties
FILE_ENCODING, INDENT_CHAR_PROPERTY, INDENT_SIZE_PROPERTY
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
XMLAction()
           
XMLAction(java.lang.String actionReference)
          ActionReference is a way to use the same icon than another known action
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Don't override it, this method will call the notifyAction if an editor is available
protected  boolean autoRequestFocus()
           
 void dispose()
          Reset all reference to XMLEditor and XMLContainer.
protected  javax.swing.KeyStroke getDefaultAccelerator()
           
protected  javax.swing.Icon getDefaultIcon()
           
protected  java.lang.String getDefaultLabel()
           
protected  char getDefaultMnemonic()
           
protected  java.lang.String getDefaultTooltip()
           
protected  java.lang.String getLabel(java.lang.String name, java.lang.String def)
           
 java.lang.String getName()
          Return the name of the action.
 java.lang.Object getParam()
           
 java.lang.String getPopupGroup()
          With this group you can create sub-menu inside the popup.
 java.lang.Object getProperty(java.lang.String propertyName, java.lang.Object defaultValue)
           
 XMLContainer getXMLContainer()
           
 XMLEditor getXMLEditor()
           
 boolean hasFeature(java.lang.String feature)
           
protected  void installUIContent()
          Reset the default icon and the default text
 boolean isPopable()
           
 boolean isToolbarable()
           
abstract  boolean notifyAction()
          Notify action must be done.
protected  void notifyXMLContainer()
          Notify that an XMLContainer has been provided for futur action
protected  void notifyXMLEditor()
          Notify that an XMLEditor has been provided for futur action
 void setActionDelegate(javax.swing.Action listener)
          Set a delegate for receiving the action event.
 void setActionReferenceGroup(java.lang.String actionReference)
          Override the default group name using the group name used by this actionReference
 void setActionReferenceIcon(java.lang.String actionReference)
          Override the default icon using the icon of another action.
 void setFeature(java.lang.String feature, boolean enabled)
          Set a feature for the action
 void setParam(java.lang.Object param)
          Set an optionnal parameter.
 void setPopable(boolean popable)
          Decide to include this action in a popup menu
 void setProperty(java.lang.String propertyName, java.lang.Object value)
          Reset a property value for this action.
 void setToolbarable(boolean inToolbar)
          Decide to include this action in the main toolbar.
 void setXMLContainer(XMLContainer container)
          Set the current XMLEditor for action
 void setXMLEditor(XMLEditor editor)
          Set the current XMLEditor for action
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, 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
 

Field Detail

IMAGE_SIZE

public static int IMAGE_SIZE
Default image size


IMAGE_EXT

public static java.lang.String IMAGE_EXT
Default image file extension


RESOURCE_BUNDLE

public static boolean RESOURCE_BUNDLE
Use a resource bundle for tabel/tooltip/shortcut/icon. By default true. If you want to alter it, use the SharedProperties


AUTO_UI

public static boolean AUTO_UI
Use default method for building UI part. By default true


VALID_ACTION

public static boolean VALID_ACTION
Status returned by the notifyAction


INVALID_ACTION

public static boolean INVALID_ACTION
Status returned by the notifyAction


groupName

protected java.lang.String groupName
XMLAction group reference name


editor

protected XMLEditor editor

container

protected XMLContainer container

param

protected java.lang.Object param
Constructor Detail

XMLAction

public XMLAction()

XMLAction

public XMLAction(java.lang.String actionReference)
ActionReference is a way to use the same icon than another known action

Parameters:
actionReference - another action class name
Method Detail

dispose

public void dispose()
Reset all reference to XMLEditor and XMLContainer. This method should only be used when this action has no more usage


setActionReferenceIcon

public void setActionReferenceIcon(java.lang.String actionReference)
Override the default icon using the icon of another action. Usage sample : setActionReferenceIcon( ActionModel.FORMAT_ACTION ); will use the same icon than the format action

Parameters:
actionReference - Action name

setActionReferenceGroup

public void setActionReferenceGroup(java.lang.String actionReference)
Override the default group name using the group name used by this actionReference


setPopable

public void setPopable(boolean popable)
Decide to include this action in a popup menu


isPopable

public boolean isPopable()
Returns:
true if this action can be integrated in a popup menu. By default true

setToolbarable

public void setToolbarable(boolean inToolbar)
Decide to include this action in the main toolbar. By default true


isToolbarable

public boolean isToolbarable()
Returns:
true if the toolbar can be include in the main toolbar

getLabel

protected java.lang.String getLabel(java.lang.String name,
                                    java.lang.String def)
Returns:
a label from the resource bundle or the default one

installUIContent

protected void installUIContent()
Reset the default icon and the default text


getDefaultIcon

protected javax.swing.Icon getDefaultIcon()
Returns:
the default icon for this action. By default the location is defined from the current class name. For sample com.japisoft.xmlpad.action.edit.CutAction will have an image stored at com/japisoft/xmlpad/action/edit/CutAction16.gif

getDefaultLabel

protected java.lang.String getDefaultLabel()
Returns:
the default action text. It uses the current name and remove if it exists the "Action" part. It is only used if no DefaultAction is available.

getDefaultTooltip

protected java.lang.String getDefaultTooltip()
Returns:
the default tooltip for this action

getDefaultMnemonic

protected char getDefaultMnemonic()
Returns:
the default mnemonic for this action

getDefaultAccelerator

protected javax.swing.KeyStroke getDefaultAccelerator()
Returns:
the default accelarator for this action

getPopupGroup

public java.lang.String getPopupGroup()
With this group you can create sub-menu inside the popup. By default it returns null


setXMLEditor

public void setXMLEditor(XMLEditor editor)
Set the current XMLEditor for action


getXMLEditor

public XMLEditor getXMLEditor()
Returns:
the current used editor

notifyXMLEditor

protected void notifyXMLEditor()
Notify that an XMLEditor has been provided for futur action


setXMLContainer

public void setXMLContainer(XMLContainer container)
Set the current XMLEditor for action


getXMLContainer

public XMLContainer getXMLContainer()
Returns:
the current used XML container component

notifyXMLContainer

protected void notifyXMLContainer()
Notify that an XMLContainer has been provided for futur action


autoRequestFocus

protected boolean autoRequestFocus()
Returns:
true for editor focus at the end of the action. By default true

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Don't override it, this method will call the notifyAction if an editor is available

Specified by:
actionPerformed in interface java.awt.event.ActionListener

setActionDelegate

public void setActionDelegate(javax.swing.Action listener)
Set a delegate for receiving the action event. By calling this method, the current action wll not be performed. Note that before calling actionPerformed a value for the key XMLCONTAINER will contain the current XMLContainer component.


notifyAction

public abstract boolean notifyAction()
Notify action must be done. It returns INVALID_ACTION if the action is not accessible and VALID_ACTION if this is correct.

Returns:
VALID_ACTION if the action is possible and else INVALID_ACTION

getName

public java.lang.String getName()
Return the name of the action. By default the class name is returned


setParam

public void setParam(java.lang.Object param)
Set an optionnal parameter. Useful inside the notifyAction


getParam

public java.lang.Object getParam()
Returns:
the current parameter

setFeature

public void setFeature(java.lang.String feature,
                       boolean enabled)
Set a feature for the action


hasFeature

public boolean hasFeature(java.lang.String feature)
Returns:
true if this feature is available

getProperty

public java.lang.Object getProperty(java.lang.String propertyName,
                                    java.lang.Object defaultValue)
Returns:
a property value for this action. If the current XMLAction has not overrided it a null value will be returned

setProperty

public void setProperty(java.lang.String propertyName,
                        java.lang.Object value)
Reset a property value for this action. Note this is the reponsability of the XMLAction to store it

Parameters:
propertyName - Property name
value - Property value


Copyright © 2006 JAPISoft. All Rights Reserved.