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, CopyAction, CopyXPathLocation, CutAction, FastCommentUncommentAction, FormatAction, InsertAction, InsertAction, LoadAction, NewAction, ParseAction, PasteAction, RedoAction, SaveAction, SearchAction, SearchElement, SelectAllAction, SelectTagAction, SplitAction, TreeVisibilityAction, UndoAction

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

Abstract class for XML action.

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 / Alexandre Brillant
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.
static boolean BUNDLE
          Use bundle for tabel/tooltip/shortcut/icon.
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
static boolean VALID_ACTION
          Status returned by the notifyAction
 
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
 void dispose()
          Reset all reference to XMLEditor and XMLContainer.
 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)
           
 boolean isPopable()
           
 boolean isToolbarable()
           
abstract  boolean notifyAction()
          Notify action must be done.
 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, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, 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


BUNDLE

public static boolean BUNDLE
Use bundle for tabel/tooltip/shortcut/icon. By default true


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

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

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

setXMLContainer

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


getXMLContainer

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

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

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