Class EditorKit
- java.lang.Object
-
- jpicedt.graphic.toolkit.EditorKit
-
public class EditorKit extends java.lang.ObjectA pluggable EditorKit for a PECanvas, that mainly provides mouse-tool management, e.g. zooming, selecting and drawing capabilities, together with a set of Action's.
Action's that make sense for this EditorKit are implemented as static inner classes to reduce name space. They can be shared across multiple PECanvas through the use of an ActionDispatcher given to the Action constructor.
New mouseTool's can be registered via the registerMouseTool method ; they're backed by a hashMap, and can be activated (ie set as the current mouse-tool) by using setCurrentMouseTool with the tool name as the parameter string.This EditorKit provides also a ViewFactory, which delegates most of its behaviour to an underlying factory (except for the View associated with the RootElement of the Drawing), and whose type depends on the current content-type, as set by setContentType. This allows the "root-view" to maintain a reference to the container (which this EditorKit can easily provide), while still allowing underlying ViewFactory's to be really independant of the exact structure of the Drawing (especially the existence of a RootElement). Besides, the EditorKit can plug a new ViewFactory on-the-fly when the content-type changed, w/o other objects having to be informed.
[todo]
- provide an EditorKit abstract class + a minimal implementation for developpers who don't need all the editing stuff (e.g. setting attributes, undoing,...) when just implementing a viewer
- Since:
- jPicEdt 1.3.2
- Version:
- $Id: EditorKit.java,v 1.41.2.1 2007/09/02 11:56:28 reynal Exp $
- Author:
- Sylvain Reynal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEditorKit.ActivateSnapActionToggles grid-snap activationstatic classEditorKit.CopyActionCopy target's content to clipboardstatic classEditorKit.CutActionCut target's content to clipboardstatic classEditorKit.DeleteActionDelete the current selectionstatic classEditorKit.EditBoundingBoxActionedit Drawing's bounding boxstatic classEditorKit.EditDispositionActionBring one or more selected objets to back, to front, forward or backward.static classEditorKit.EditGeometryActionOpen a dialog that allows the user to edit the geometry of the currently selected element from a dialog box.static classEditorKit.GroupActionGroup all selected objects into a new PicGroup.static classEditorKit.JoinCurvesActionJoin all selected objects of type PicMultiCurveConvertable into a new PicMultiCurve.static classEditorKit.PasteActionPaste the content of the given ClipBoard into the target canvasstatic classEditorKit.SelectAllActionselects all objects in the current active internal framestatic classEditorKit.SelectMouseToolActionSets the current mouse-tool for the editor-kit.static classEditorKit.ShowGridActionToggles grid's visible statestatic classEditorKit.ToggleEditPointsModeActionToggles the EditorKit's edit-points-mode b/w LOCAL_MODE and GLOBAL_MODE.static classEditorKit.UngroupActionUngroup the current selection if this makes sense.static classEditorKit.ZoomInActionzoom instatic classEditorKit.ZoomOutActionzoom out
-
Field Summary
Fields Modifier and Type Field Description protected PECanvasboardthe PECanvas this EditorKit is installed in.static java.lang.StringEDIT_MODE_CHANGEproperty name for edit mode change : "edit-mode"static java.lang.StringEDIT_POINTpoint edition toolprotected javax.swing.event.EventListenerListlistenerListlist of HelpMessageListener's and PropertyChangeListener's for this EditorKitstatic java.lang.StringMOVEmovestatic java.lang.StringROTATErotatestatic java.lang.StringSCALEscalestatic java.lang.StringSELECTselectionstatic java.lang.StringSHEARshearstatic java.lang.StringZOOMzoom mode
-
Constructor Summary
Constructors Constructor Description EditorKit()Construct a new EditorKit with SELECT being the default initial edit-mode, and a default viewfactory.EditorKit(ContentType contentType, EditorKit oldKit)Construct a new EditorKit with SELECT being the default initial edit-mode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHelpMessageListener(HelpMessageListener l)adds a HelpMessageListener to the listener listvoidaddPropertyChangeListener(java.beans.PropertyChangeListener l)adds a PropertyChangeListener to the listener liststatic javax.swing.ActionMapcreateActionMap(ActionDispatcher dispatcher, ActionLocalizer localizer)ContentTypecreateDefaultContentType()Creates a default content-type suited for this editorjavax.swing.InputMapcreateInputMap()voiddeinstall(PECanvas board)Called when the kit is being removed from a PECanvas This is used to unregister any previously registered mouse-tool.protected voidfirePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Notify all listeners that have registered interest for notification on this event type.static java.lang.String[][]getAvailableToolNames()Returns all mousetool-names registered by default with this EditorKit.PECanvasgetCanvas()Return the PECanvas into which this kit is installed, or null if the kit has not been installed yet.static java.awt.datatransfer.ClipboardgetClipboard()Return a static reference to the local ClipBoard shared across all instance of this EditorKitjava.lang.StringgetCurrentMouseTool()FormatterFactorygetFormatterFactory()HighlighterFactorygetHighlighterFactory()Return the factory delegate for producing View's HighlightersPicAttributeSetgetInputAttributes()get the input attributes for the PECanvas attached to this EditorKitPopupMenuFactorygetPopupMenuFactory()MouseTool[]getRegisteredMouseTools()java.lang.String[]getRegisteredMouseToolsByName()SelectionHandlergetSelectionHandler()ViewFactorygetViewFactory()voidinstall(PECanvas board)Called when the kit is being installed into a PECanvas.voidpaint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)Allow this EditorKit to paint shapes specific to the current tool, either directly, or through the paint method of its tools.protected voidpostHelpMessage(java.lang.String message)Notify all listeners that have registered interest for notification on this event type.voidregisterMouseTool(java.lang.String name, MouseTool mt)Registers the given mouse-tool by associating it with the given name in the hashtable of available mouse-tools.voidremoveHelpMessageListener(HelpMessageListener l)removes an HelpMessageListener from the EditorKitvoidremovePropertyChangeListener(java.beans.PropertyChangeListener l)removes an PropertyChangeListener from the EditorKitvoidsetCurrentMouseTool(java.lang.String editMode)set the current mouse tool for this editor kitvoidsetFactoriesFromContentType(ContentType ct)plugs new FormatterFactory and ViewFactory into this EditorKit, using the given ContentType to create them on-the-fly.voidsetHighlighterFactory(HighlighterFactory hf)Sets the factory delegate for producing View's HighlightersvoidsetInputAttributes(PicAttributeSet set)set the input attributes for the PECanvas attached to this EditorKitvoidsetPopupMenuFactory(PopupMenuFactory popupMenuFactory)Set the popup-menu factory that produces a JPopupMenu when the EditorKit asks for it.voidunRegisterMouseTool(java.lang.String name)Unregisters the mouse-tool having the given name from the table of available mouse-tools.
-
-
-
Field Detail
-
ZOOM
public static final java.lang.String ZOOM
zoom mode- See Also:
- Constant Field Values
-
SELECT
public static final java.lang.String SELECT
selection- See Also:
- Constant Field Values
-
EDIT_POINT
public static final java.lang.String EDIT_POINT
point edition tool- See Also:
- Constant Field Values
-
MOVE
public static final java.lang.String MOVE
move- See Also:
- Constant Field Values
-
SCALE
public static final java.lang.String SCALE
scale- See Also:
- Constant Field Values
-
ROTATE
public static final java.lang.String ROTATE
rotate- See Also:
- Constant Field Values
-
SHEAR
public static final java.lang.String SHEAR
shear- See Also:
- Constant Field Values
-
EDIT_MODE_CHANGE
public static final java.lang.String EDIT_MODE_CHANGE
property name for edit mode change : "edit-mode"- See Also:
- Constant Field Values
-
board
protected PECanvas board
the PECanvas this EditorKit is installed in. null if not installed
-
listenerList
protected javax.swing.event.EventListenerList listenerList
list of HelpMessageListener's and PropertyChangeListener's for this EditorKit
-
-
Constructor Detail
-
EditorKit
public EditorKit()
Construct a new EditorKit with SELECT being the default initial edit-mode, and a default viewfactory.
-
EditorKit
public EditorKit(ContentType contentType, EditorKit oldKit)
Construct a new EditorKit with SELECT being the default initial edit-mode.- Parameters:
contentType- if non-null, this set the view- and formatter- factories to use for rendering the associated content ; otherwise, default factories are created usingcreateDefaultContentType().oldKit- if an old instance already existed, and one wishes to reuse its properties, e.g. listener-list, popupmenu-factory, input-attributes,... except obviously for the ViewFactory and the FormatterFactory given as arguments. May be safely be set to null.
-
-
Method Detail
-
install
public void install(PECanvas board)
Called when the kit is being installed into a PECanvas. This registers default mouse-tools, ie :- tools corresponding to constant-fields SELECT, MOVE,... defined in this class ;
- all tools available from DrawToolFactory, and which may be accessed using constant-fields defined therein, e.g. DrawToolFactory.RECTANGLE to access the mousetool dedicated to drawing rectangles.
- Parameters:
board- the PECanvas
-
deinstall
public void deinstall(PECanvas board)
Called when the kit is being removed from a PECanvas This is used to unregister any previously registered mouse-tool.- Parameters:
board- the PECanvas
-
getCanvas
public PECanvas getCanvas()
Return the PECanvas into which this kit is installed, or null if the kit has not been installed yet.
-
setFactoriesFromContentType
public void setFactoriesFromContentType(ContentType ct)
plugs new FormatterFactory and ViewFactory into this EditorKit, using the given ContentType to create them on-the-fly.- Parameters:
ct- if null, a default content-type is used, as returned bycreateDefaultContentType
-
createDefaultContentType
public ContentType createDefaultContentType()
Creates a default content-type suited for this editor
-
getInputAttributes
public PicAttributeSet getInputAttributes()
get the input attributes for the PECanvas attached to this EditorKit
-
setInputAttributes
public void setInputAttributes(PicAttributeSet set)
set the input attributes for the PECanvas attached to this EditorKit
-
getFormatterFactory
public FormatterFactory getFormatterFactory()
- Returns:
- the FormatterFactory used to write the content of a Drawing to a stream, according to the type of content this kit can edit
-
getAvailableToolNames
public static java.lang.String[][] getAvailableToolNames()
Returns all mousetool-names registered by default with this EditorKit.- Returns:
- an array of arrays of String, each sub-array containing a group of tightly related tools
-
registerMouseTool
public void registerMouseTool(java.lang.String name, MouseTool mt)Registers the given mouse-tool by associating it with the given name in the hashtable of available mouse-tools. This name can then be fed as a parameter tosetCurrentMouseTool().
-
unRegisterMouseTool
public void unRegisterMouseTool(java.lang.String name)
Unregisters the mouse-tool having the given name from the table of available mouse-tools.
-
getRegisteredMouseToolsByName
public java.lang.String[] getRegisteredMouseToolsByName()
- Returns:
- an array containing the currently registered mouse-tools names
-
getRegisteredMouseTools
public MouseTool[] getRegisteredMouseTools()
- Returns:
- an array containing the currently registered mouse-tools
-
setCurrentMouseTool
public void setCurrentMouseTool(java.lang.String editMode)
set the current mouse tool for this editor kitWhen setting a new edit-mode, the editor kit fire a PropertyChange Event with key "EDIT_MODE_CHANGE" and the given edit-mode as the new value.
This may be used by the UI to get informed that a change occured (since some mouse-tools in this kit may change the edit-mode from the inside).- Parameters:
editMode- a previously registered mouseTool's name
-
getCurrentMouseTool
public java.lang.String getCurrentMouseTool()
- Returns:
- the current edit mode for this EditorKit
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
adds a PropertyChangeListener to the listener list
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
removes an PropertyChangeListener from the EditorKit
-
firePropertyChange
protected void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
-
addHelpMessageListener
public void addHelpMessageListener(HelpMessageListener l)
adds a HelpMessageListener to the listener list
-
removeHelpMessageListener
public void removeHelpMessageListener(HelpMessageListener l)
removes an HelpMessageListener from the EditorKit
-
postHelpMessage
protected void postHelpMessage(java.lang.String message)
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
-
setPopupMenuFactory
public void setPopupMenuFactory(PopupMenuFactory popupMenuFactory)
Set the popup-menu factory that produces a JPopupMenu when the EditorKit asks for it.In this implementation, a popup-menu gets raised if :
- a PopupTrigger mouse-event occured, (see MouseEvent.isPopupTrigger())
- the current edit mode is "SELECT"
- the PopupMenuFactory is not null
- the PopupMenuFactory.createPopupMenu() method returned a non-null JPopupMenu
-
getPopupMenuFactory
public PopupMenuFactory getPopupMenuFactory()
- Returns:
- the popup-menu factory that produces JPopupMenu's for this EditorKit
-
paint
public void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)Allow this EditorKit to paint shapes specific to the current tool, either directly, or through the paint method of its tools.- Parameters:
scale- the current scale factor b/w model-coordinates and view-coordinates ; this depends on the AffineTransform being currently active in PECanvas's paintComponent, and may be used, e.g. to scale down lines thickness so that they're displayed with a constant thickness whatever the scale factor attached to Graphics2D (this is faster than retrieving the AffineTransform attached to the graphic context given as parameter, and computing the scale factor by using getScaleX).
-
getViewFactory
public ViewFactory getViewFactory()
- Returns:
- the ViewFactory that produces View's for the kind of content-type this editor-kit can edit or create.
-
getHighlighterFactory
public HighlighterFactory getHighlighterFactory()
Return the factory delegate for producing View's Highlighters
-
setHighlighterFactory
public void setHighlighterFactory(HighlighterFactory hf)
Sets the factory delegate for producing View's Highlighters
-
getSelectionHandler
public SelectionHandler getSelectionHandler()
- Returns:
- the current selection-handler that suited for the kind of content this editorkit must edit
-
createActionMap
public static javax.swing.ActionMap createActionMap(ActionDispatcher dispatcher, ActionLocalizer localizer)
- Returns:
- an ActionMap that can be used on a PECanvas that is using a model, view and formatter produced by this kit. ActionCommand key is created from key ACTION_COMMAND_KEY.
-
createInputMap
public javax.swing.InputMap createInputMap()
- Returns:
- an ActionMap that can be used on a PECanvas that is using a model, view and formatter produced by this kit. ActionCommand key is created from key ACTION_COMMAND_KEY. [todo] provide a Properties object for key-bindings
-
getClipboard
public static java.awt.datatransfer.Clipboard getClipboard()
Return a static reference to the local ClipBoard shared across all instance of this EditorKit
-
-