Class PECanvas
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- jpicedt.graphic.PECanvas
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.Scrollable
public class PECanvas extends javax.swing.JPanel implements javax.swing.ScrollableThis is a JComponent on which graphic elements are drawn. It's has an underlying model (a Drawing) to represent the content, an EditorKit to manipulate the content, and a View responsible for rendering the content. EditorKit, Drawing, and View's are pluggable : the EditorKit is responsible for creating 1) a default Drawing and 2) a ViewFactory that will populate the View tree associated with the Drawing, by attaching a View to each element in the model.Depending on the content type this Component is loaded with, it may plug a new EditorKit on-the-fly that's suited for the given content type (e.g. LaTeX, Postscript, SVG-XML, etc...).
Model to View/View to Model
Graphic objects are stored (e.g. in a Drawing) in natural coordinates, ie LaTeX/Postscript/... coordinates, using e.g. a "1 mm" unitlength : that's what we call "model coordinate". Obviously, we've to translate these coordinates to screen coordinates (e.g. JViewport-coordinate or JPanel-coordinate) before rendering, and this is done very simply by using an AffineTransform and adding it to the current Graphic2D context in the body of the "paintComponent" method. The following picture sums up the translation process that takes place b/w model- and view-coordinate.

The benefits of such an approach is to make it easy for someone willing to develop a parser/formater to handle objects coordinates with the fewest possible overhead, since objects coordinates are "natively" available in natural (ie from left to right and from bottom to top) coordinates, and this is perfectly suited for formatting language like LaTeX, Postscript or SVG-XML. Besides, this makes sense with the grid ticks marks.
Margins are encapsulated in a PageFormat (an inner class) object. Contrary to previous jpicedt releases, it's no longer necessary, as of jpicedt 1.3.2, to provide formater methods with the ptOrg parameter.
In addition to the standard behaviour inherited from JPanel, PropertyChangeEvent's are triggered when :
- changing the page format ;
- changing the zoom factor ;
- changing the editor kit ;
- Since:
- jpicedt 1.0
- Version:
- $Id: PECanvas.java,v 1.24.2.2 2007/09/02 11:56:16 reynal Exp $
- Author:
- Sylvain Reynal
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONTENT_TYPE_CHANGEproperty name for content-type's change eventsprotected ContentTypecontentTypethe current content-type for this PECanvas (determines the EditorKit behaviour)protected Drawingdrawingthe model for this canvasstatic java.lang.StringDRAWING_CHANGEproperty name for drawing-change eventsstatic java.lang.StringEDITOR_KIT_CHANGEproperty name for editorkit-change eventsprotected Gridgridthe grid attached to this canvasstatic java.lang.StringKEY_CONTENT_TYPEkey for Properties's content-type valuestatic java.lang.StringKEY_UNDOABLE_STEPSkey for Properties's nb of undoable steps valuestatic java.lang.StringKEY_ZOOMkey for Properties's zoom valueprotected EditorKitkitthe current editor kit for this componentstatic intMAX_UNDOABLE_STEPS_DEFAULTdefault undoable events to rememberprotected java.awt.geom.AffineTransformmodel2ViewTransformthe AffineTransform used to translate from model-coordinates to view-coordinates ; gets updated each time either the zoom factor or the page format changesprotected PageFormatpageFormatpageFormat encapsulates board size and margin datastatic java.lang.String[]PREDEFINED_ZOOM_STRINGSstatic double[]PREDEFINED_ZOOMSprotected java.awt.RenderingHintsrenderingHintsa Map storing RenderingHints to be applied to the graphic context when rendering the drawingprotected javax.swing.undo.StateEditstateEditthe UndoableEdit in progressprotected javax.swing.undo.UndoableEditSupportundoableEditSupportthe UndoableEditSupport delegate for UndoableEditEvent firingprotected javax.swing.undo.UndoManagerundoManagerthe UndoManager delegate for undo/redo operationprotected java.awt.geom.AffineTransformview2ModelTransformthe AffineTransform used to translate from mouse-coordinates to model-coordinates ; gets updated each time model2ViewTransform changesstatic doubleZOOM_DEFAULT-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description PECanvas()Construct a new PECanvas initialized with default values.PECanvas(double zoom, PageFormat pageFormat, Grid grid, ContentType contentType)Construct a new PECanvas with the default editor-kit and drawing as content storage.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPEMouseInputListener(PEMouseInputListener l)Adds the specified mouse listener to receive mouse events from this component.voidaddSelectionListener(SelectionListener l)adds a SelectionListener to the CanvasvoidaddUndoableEditListener(javax.swing.event.UndoableEditListener l)Register an UndoableEditListener for the Drawing hosted by this canvas.voidaddZoomListener(ZoomListener l)adds a ZoomListener to the CanvasvoidbeginUndoableUpdate(java.lang.String presentationName)Create a new UndoableEdit that holds the current state of the Drawing.booleancanRedo()booleancanUndo()voidcopy()Copy the content of the current selection to the System's clipboard (after a formatting to text)voidcopy(java.awt.datatransfer.Clipboard clipbrd)Copy the content of the current selection (through a GraphicTransferable) to the System's clipboard (after a formatting to text), AND to the given clipboard if non-null (the latter can be a local clipboard supporting more data-flavors than the system clipboard)protected EditorKitcreateDefaultEditorKit(ContentType contentType)Creates a default editor kit (EditorKit) whose factory delegates are initialized from the given content-type.voidcut()Cut the content of the current selection to the System clipboard, after formatting to text.voidcut(java.awt.datatransfer.Clipboard clipbrd)Cut the content of the current selection (through a GraphicTransferable) to the System clipboard, AND to the given ClipBoard if non-null.voiddeleteSelection()remove all selected objects from the drawingvoidendUndoableUpdate()Ends the current UndoableEdit and fire an event to registered listeners.protected voidfireSelectionUpdate(Element[] elements, SelectionEvent.EventType type)Notify all listeners that have registered interest for notification on this event type.protected voidfireSelectionUpdate(Element element, SelectionEvent.EventType type)Notify all listeners that have registered interest for notification on this event type.protected voidfireZoomUpdate(double oldZoom, double newZoom, PicPoint ptClick)Notify all listeners that have registered interest for notification on this event type.ContentTypegetContentType()DrawinggetDrawing()EditorKitgetEditorKit()Fetches the currently installed kit for handling content.GridgetGrid()java.awt.geom.AffineTransformgetModelToViewTransform()PageFormatgetPageFormat()java.awt.DimensiongetPreferredScrollableViewportSize()java.lang.StringgetRedoPresentationName()java.awt.RenderingHintsgetRenderingHints()Return the RenderingHints applied to the graphic context when rendering this componentdoublegetScaleFactor()intgetScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)booleangetScrollableTracksViewportHeight()booleangetScrollableTracksViewportWidth()intgetScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)intgetSelectionSize()PicPointgetSheetOrigin()java.lang.StringgetUndoPresentationName()java.awt.geom.AffineTransformgetViewToModelTransform()doublegetZoomFactor()static intgetZoomIndex(double zoom)utilities to retrieve the index of the given zoom in PREDEFINED_ZOOMS ; this may be used by GUI widgets, e.g.voidgroupSelection()group all selected objects into a new PicGroup and add it to the drawing.voidinsert(java.io.Reader reader, Parser parser)insert content from a reader into the current drawingbooleanisRequestFocusEnabled()Overriden from JComponent Signals that this component can receive focus (useful for handling keyevents)booleanisSelected(Element e)voidjoinSelection()join all selected objects of type PicMultiCurveConvertable into a new PicMulticurve and add it to the drawing.java.awt.ShapemodelToView(java.awt.Shape src)Converts a Shape from the model-coordinate system to the pixel-coordinate system.PicPointmodelToView(PicPoint src, PicPoint dst)Converts a point from the model-coordinate system to the pixel-coordinate system.voidpaintComponent(java.awt.Graphics g)paintComponent(Graphics g) is called by AWTEventDispatchThread via "paint(g)" it's absolutely necessary to call super.paintComponent(g) so that the background gets properly painted (PECanvas is opaque)voidpaste(boolean translate)Add the content of the System's ClipBoard to the current drawing, then select it.voidpaste(java.awt.datatransfer.Clipboard clipbrd, boolean translate)Add the content of the given ClipBoard to the current drawing, then select it.protected voidprocessMouseEvent(java.awt.event.MouseEvent e)Processes mouse events occurring on this component by dispatching them to any registeredPEMouseListenerobjects.protected voidprocessMouseMotionEvent(java.awt.event.MouseEvent e)Processes mouse motion events occurring on this component by dispatching them to any registeredPEMouseInputListenerobjects.voidread(java.io.Reader reader, Parser parser)read drawing content from a reader and erase old one.voidredo()Redo last changevoidremovePEMouseInputListener(PEMouseInputListener l)Removes the specified mouse listener so that it no longer receives mouse events from this component.voidremoveSelectionListener(SelectionListener l)removes a SelectionListener from the CanvasvoidremoveUndoableEditListener(javax.swing.event.UndoableEditListener l)Unregister an UndoableEditListener for the Drawing hosted by this canvas.voidremoveZoomListener(ZoomListener l)removes a ZoomListener from the CanvasvoidrepaintFromModelRect(java.awt.geom.Rectangle2D rect)add the given rectangle, given in model-coordinates, to the list of dirty regions.voidselect(java.util.Collection c, boolean incremental)select the elements in the given collection (if they belong to the drawing)voidselect(Element obj, boolean incremental)select the given elementvoidselectAll(boolean state)select or unselect every object in this drawingjava.util.Iteratorselection()voidsetContentType(ContentType newContentType)change the current content-type: this implies plugging a new ViewFactory and a new FormatterFactory to the currently installed EditorKit, as obtained from the given newContentType argument.voidsetDrawing(Drawing dr)set the Drawing model for this component.voidsetEditorKit(EditorKit kit)Sets the currently installed kit for handling content.voidsetPageFormat(PageFormat pageFormat)Set the size of the drawing board.voidsetUndoLimit(int limit)set the number of undoable events to remembervoidsetZoomFactor(double zoom)Convenience call to setZoomFactor(zoom,null)voidsetZoomFactor(double zoom, PicPoint ptClick)sets the current zoom factor to the given double, then updates various properties (model <-> view transforms, dimension, preferredSize...), finally, sources a ZoomEvent to give a chance to receiver to update their state accordingly (this may be used e.g.voidundo()Undo last changevoidunGroup(PicGroup g)fetch all Element's belonging to the given PicGroup and add them to its parent, removing the given PicGroup from its parent afterward.voidunSelect(Element obj)unselect the given objectPicPointview2Model(PicPoint src, PicPoint dst)Converts a point from the pixel-coordinate system to the model-coordinate system.java.awt.ShapeviewToModel(java.awt.Shape src)Converts a Shape from the pixel-coordinate system to the model-coordinate system.voidwrite(java.io.Writer writer, boolean writeSelectionOnly)Write drawing content to the given stream-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
PREDEFINED_ZOOM_STRINGS
public static final java.lang.String[] PREDEFINED_ZOOM_STRINGS
-
PREDEFINED_ZOOMS
public static final double[] PREDEFINED_ZOOMS
-
ZOOM_DEFAULT
public static final double ZOOM_DEFAULT
- See Also:
- Constant Field Values
-
KEY_ZOOM
public static final java.lang.String KEY_ZOOM
key for Properties's zoom value- See Also:
- Constant Field Values
-
KEY_CONTENT_TYPE
public static final java.lang.String KEY_CONTENT_TYPE
key for Properties's content-type value- See Also:
- Constant Field Values
-
KEY_UNDOABLE_STEPS
public static final java.lang.String KEY_UNDOABLE_STEPS
key for Properties's nb of undoable steps value- See Also:
- Constant Field Values
-
MAX_UNDOABLE_STEPS_DEFAULT
public static final int MAX_UNDOABLE_STEPS_DEFAULT
default undoable events to remember- See Also:
- Constant Field Values
-
DRAWING_CHANGE
public static final java.lang.String DRAWING_CHANGE
property name for drawing-change events- See Also:
- Constant Field Values
-
EDITOR_KIT_CHANGE
public static final java.lang.String EDITOR_KIT_CHANGE
property name for editorkit-change events- See Also:
- Constant Field Values
-
CONTENT_TYPE_CHANGE
public static final java.lang.String CONTENT_TYPE_CHANGE
property name for content-type's change events- See Also:
- Constant Field Values
-
drawing
protected Drawing drawing
the model for this canvas
-
pageFormat
protected PageFormat pageFormat
pageFormat encapsulates board size and margin data
-
contentType
protected ContentType contentType
the current content-type for this PECanvas (determines the EditorKit behaviour)
-
model2ViewTransform
protected java.awt.geom.AffineTransform model2ViewTransform
the AffineTransform used to translate from model-coordinates to view-coordinates ; gets updated each time either the zoom factor or the page format changes
-
view2ModelTransform
protected java.awt.geom.AffineTransform view2ModelTransform
the AffineTransform used to translate from mouse-coordinates to model-coordinates ; gets updated each time model2ViewTransform changes
-
grid
protected Grid grid
the grid attached to this canvas
-
kit
protected EditorKit kit
the current editor kit for this component
-
undoableEditSupport
protected javax.swing.undo.UndoableEditSupport undoableEditSupport
the UndoableEditSupport delegate for UndoableEditEvent firing
-
undoManager
protected javax.swing.undo.UndoManager undoManager
the UndoManager delegate for undo/redo operation
-
stateEdit
protected javax.swing.undo.StateEdit stateEdit
the UndoableEdit in progress
-
renderingHints
protected java.awt.RenderingHints renderingHints
a Map storing RenderingHints to be applied to the graphic context when rendering the drawing
-
-
Constructor Detail
-
PECanvas
public PECanvas()
Construct a new PECanvas initialized with default values.
-
PECanvas
public PECanvas(double zoom, PageFormat pageFormat, Grid grid, ContentType contentType)Construct a new PECanvas with the default editor-kit and drawing as content storage.- Parameters:
zoom- initial zoom factorinitial- page format (page size + page margins)content- -type (e.g. LaTeX, PsTricks,...) ; this will determine the EditorKit for editing the Drawing, and indirectly the ViewFactory that produces View's for the drawing, (since the ViewFactory is obtained through the currently installed EditorKit) and the FormatterFactory used to write the drawing to a writer. If null, the default editor-kit/content-type is used.- Since:
- PicEdt 1.0
-
-
Method Detail
-
paintComponent
public void paintComponent(java.awt.Graphics g)
paintComponent(Graphics g) is called by AWTEventDispatchThread via "paint(g)" it's absolutely necessary to call super.paintComponent(g) so that the background gets properly painted (PECanvas is opaque)This implementation first applies an AffineTransform to the graphic context : this transform maps in effect model-coordinates to screen-coordinates. Then invokes the paint() method in that order :
- on the Grid object attached to this PECanvas;
- on the root-view associated with Drawing.RootElement.
- on the EditorKit in which this PECanvas is installed.
- Overrides:
paintComponentin classjavax.swing.JComponent
-
repaintFromModelRect
public void repaintFromModelRect(java.awt.geom.Rectangle2D rect)
add the given rectangle, given in model-coordinates, to the list of dirty regions.
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
Return the RenderingHints applied to the graphic context when rendering this component
-
getDrawing
public Drawing getDrawing()
- Returns:
- the model, ie a Drawing containing only non-selected objects
-
setDrawing
public void setDrawing(Drawing dr)
set the Drawing model for this component. The currently registered EditorKit is used to build a viewtree for the drawing. A PropertyChange event (DRAWING_CHANGE) is sent to each listener.
-
getEditorKit
public EditorKit getEditorKit()
Fetches the currently installed kit for handling content.
-
createDefaultEditorKit
protected EditorKit createDefaultEditorKit(ContentType contentType)
Creates a default editor kit (EditorKit) whose factory delegates are initialized from the given content-type. If an EditorKit was already installed in this PECanvas, we try to reuse its properties in the new EditorKit, if applicable.- Parameters:
contentType- null if a default content-type should be used- Returns:
- the editor kit
-
setEditorKit
public void setEditorKit(EditorKit kit)
Sets the currently installed kit for handling content. This is the bound property that establishes the content type of the editor. Any old kit is first deinstalled, then if kit is non-null, the new kit is installed.A default drawing is created from it if there was no drawing set in this canvas before, otherwise the old drawing is reused : in both cases,
setDrawingis called, but this allows the caller to change the ContentType w/o changing the Drawing if it deems it unnecessary (otherwise, it may call setDrawing() afterwards). APropertyChangeevent (EDITOR_KIT_CHANGE) is always fired whensetEditorKitis called.- Parameters:
kit- the desired editor behavior- See Also:
getEditorKit()
-
getContentType
public ContentType getContentType()
- Returns:
- the current content-type
-
setContentType
public void setContentType(ContentType newContentType)
change the current content-type: this implies plugging a new ViewFactory and a new FormatterFactory to the currently installed EditorKit, as obtained from the given newContentType argument.- Parameters:
newContentType- if null, the DefaultContentType is installed.
-
setPageFormat
public void setPageFormat(PageFormat pageFormat)
Set the size of the drawing board. Length are given in mm (this should approximately represent true mm on the screen, however this might slightly depend on the underlying platform).
This in turn sets the preferred size of the component. .- Since:
- jPicEdt
-
getPageFormat
public PageFormat getPageFormat()
- Returns:
- the page format for this drawing board
- Since:
- jPicEdt
-
getSheetOrigin
public PicPoint getSheetOrigin()
- Returns:
- the pixel-coordinates of the (0,0) model origin when zoom = 1.0
-
getGrid
public Grid getGrid()
- Returns:
- the grid attached to this canvas
-
getModelToViewTransform
public java.awt.geom.AffineTransform getModelToViewTransform()
- Returns:
- an AffineTransform that represents the maping b/w the model-coordinate system and the pixel coordinate system. Guaranteed not to change over time.
- Since:
- jPicEdt
-
getViewToModelTransform
public java.awt.geom.AffineTransform getViewToModelTransform()
- Returns:
- an AffineTransform that represents the maping b/w the pixel-coordinate system and the model-coordinate system. Guaranteed not to change over time.
- Since:
- jPicEdt
-
modelToView
public PicPoint modelToView(PicPoint src, PicPoint dst)
Converts a point from the model-coordinate system to the pixel-coordinate system.- Parameters:
src- the source point in model-coordinatedst- the destination point ; if null, a new point is allocated, and returned for convenience.- Returns:
- the result (same as dst if non-null)
- Since:
- jPicEdt
-
view2Model
public PicPoint view2Model(PicPoint src, PicPoint dst)
Converts a point from the pixel-coordinate system to the model-coordinate system.- Parameters:
src- the source point in pixel-coordinatedst- the destination point ; if null, a new point is allocated, and returned for convenience.- Returns:
- the result (same as dst if non-null)
- Since:
- jPicEdt
-
modelToView
public java.awt.Shape modelToView(java.awt.Shape src)
Converts a Shape from the model-coordinate system to the pixel-coordinate system.- Parameters:
src- a Shape in the model-coordinate system- Returns:
- a new Shape corresponding to the given Shape once transformed to the pixel-coordinate system.
- Since:
- jPicEdt
-
viewToModel
public java.awt.Shape viewToModel(java.awt.Shape src)
Converts a Shape from the pixel-coordinate system to the model-coordinate system.- Parameters:
src- a Shape in the pixel-coordinate system- Returns:
- a new Shape corresponding to the given Shape once transformed to the model-coordinate system.
- Since:
- jPicEdt
-
read
public void read(java.io.Reader reader, Parser parser) throws ParserExceptionread drawing content from a reader and erase old one. Listener's interested in DrawingEvent's should register their listener anew (this can be done systematically by registering a PropertyCHangeListener to this canvas, and waiting for DRAWING_CHANGE events).- Parameters:
reader- the reader to read content from- Throws:
ParserException
-
insert
public void insert(java.io.Reader reader, Parser parser) throws ParserExceptioninsert content from a reader into the current drawing- Parameters:
reader- the reader to insert content from- Throws:
ParserException
-
write
public void write(java.io.Writer writer, boolean writeSelectionOnly) throws java.io.IOExceptionWrite drawing content to the given stream- Parameters:
writer- The writer to write towriteSelectionOnly- if true, only write selection content- Throws:
java.io.IOException- on any I/O error- Since:
- jPicEdt
-
setZoomFactor
public void setZoomFactor(double zoom)
Convenience call to setZoomFactor(zoom,null)
-
setZoomFactor
public void setZoomFactor(double zoom, PicPoint ptClick)sets the current zoom factor to the given double, then updates various properties (model <-> view transforms, dimension, preferredSize...), finally, sources a ZoomEvent to give a chance to receiver to update their state accordingly (this may be used e.g. by a parent scrollpane to update its view port location, or by a GUI widget to reflect the new zoom value).- Parameters:
zoom- the new zoom factorptClick- this only makes sense if the parent of this component is aka ScrollPane ;
Coordinates for this point are in the model-coordinate system.
-
getZoomFactor
public double getZoomFactor()
- Returns:
- the current zoom factor
-
getScaleFactor
public double getScaleFactor()
- Returns:
- the current scale factor between model- and view-coordinates, as given by the current model2ViewTransform. This is usually the product of the current zoom factor, and the DotPerMilliMeter screen factor.
-
fireZoomUpdate
protected void fireZoomUpdate(double oldZoom, double newZoom, PicPoint ptClick)Notify all listeners that have registered interest for notification on this event type.- Parameters:
oldZoom- previous zoom valuenewZoom- new zoom valueptClick- the point (in model-coordinates) that is expected to be at the center of the view-port ; can be null
-
addZoomListener
public void addZoomListener(ZoomListener l)
adds a ZoomListener to the Canvas
-
removeZoomListener
public void removeZoomListener(ZoomListener l)
removes a ZoomListener from the Canvas
-
getZoomIndex
public static int getZoomIndex(double zoom)
utilities to retrieve the index of the given zoom in PREDEFINED_ZOOMS ; this may be used by GUI widgets, e.g. JComboBox,...- Returns:
- index of the given zoom in array "PREDEFINED_ZOOMS" ; returns -1 if not found.
-
setUndoLimit
public void setUndoLimit(int limit)
set the number of undoable events to remember
-
undo
public void undo() throws javax.swing.undo.CannotUndoExceptionUndo last change- Throws:
javax.swing.undo.CannotUndoException- Since:
- PicEdt 1.1.3
-
redo
public void redo() throws javax.swing.undo.CannotRedoExceptionRedo last change- Throws:
javax.swing.undo.CannotRedoException- Since:
- PicEdt 1.1.3
-
addUndoableEditListener
public void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
Register an UndoableEditListener for the Drawing hosted by this canvas.
-
removeUndoableEditListener
public void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
Unregister an UndoableEditListener for the Drawing hosted by this canvas.
-
beginUndoableUpdate
public void beginUndoableUpdate(java.lang.String presentationName)
Create a new UndoableEdit that holds the current state of the Drawing.
-
endUndoableUpdate
public void endUndoableUpdate()
Ends the current UndoableEdit and fire an event to registered listeners.
-
canRedo
public boolean canRedo()
- Returns:
- true if a "redo" operation would be successfull
-
canUndo
public boolean canUndo()
- Returns:
- true if a "undo" operation would be successfull
-
getRedoPresentationName
public java.lang.String getRedoPresentationName()
- Returns:
- the presentation name of the next edit that can be redone
-
getUndoPresentationName
public java.lang.String getUndoPresentationName()
- Returns:
- the presentation name of the last edit that can be undone
-
selection
public java.util.Iterator selection()
- Returns:
- an Iterator over selected graphic elements
-
getSelectionSize
public int getSelectionSize()
- Returns:
- the number of selected elements in the current selection
-
isSelected
public boolean isSelected(Element e)
- Returns:
- whether the given element is selected or not
-
selectAll
public void selectAll(boolean state)
select or unselect every object in this drawing- Parameters:
state- if true, selectAll, otherwise unselect all.
-
select
public void select(java.util.Collection c, boolean incremental)select the elements in the given collection (if they belong to the drawing)- Parameters:
incremental- if true, add to the existing selection ; replace otherwise.
-
select
public void select(Element obj, boolean incremental)
select the given element- Parameters:
incremental- if true, add to the existing selection ; replace otherwise.
-
unSelect
public void unSelect(Element obj)
unselect the given object
-
deleteSelection
public void deleteSelection()
remove all selected objects from the drawing
-
paste
public void paste(java.awt.datatransfer.Clipboard clipbrd, boolean translate) throws ParserException, java.io.IOException, java.awt.datatransfer.UnsupportedFlavorExceptionAdd the content of the given ClipBoard to the current drawing, then select it. If only DataFlavor.stringFlavor is provided by the Transferable, we try to parse the string and insert the parsed content. Otherwise, it's taken for granted that the ClipBoard content support the jpicedt.graphic.toolkit.TransferableGraphic.JPICEDT_DATA_FLAVOR data flavor.- Parameters:
translate- if true, translate the pasted content by a grid step so that it doesn't hide old one- Throws:
ParserExceptionjava.io.IOExceptionjava.awt.datatransfer.UnsupportedFlavorException
-
paste
public void paste(boolean translate) throws ParserException, java.io.IOException, java.awt.datatransfer.UnsupportedFlavorExceptionAdd the content of the System's ClipBoard to the current drawing, then select it. More specifically, we try to parse the string and insert the parsed content.- Parameters:
translate- if true, translate the pasted content by a grid step so that it doesn't hide old one- Throws:
ParserExceptionjava.io.IOExceptionjava.awt.datatransfer.UnsupportedFlavorException
-
copy
public void copy(java.awt.datatransfer.Clipboard clipbrd)
Copy the content of the current selection (through a GraphicTransferable) to the System's clipboard (after a formatting to text), AND to the given clipboard if non-null (the latter can be a local clipboard supporting more data-flavors than the system clipboard)- Parameters:
clipbrd- the target clipboard ; can be null, in which case only the System clipboard is modified.
-
copy
public void copy()
Copy the content of the current selection to the System's clipboard (after a formatting to text)
-
cut
public void cut(java.awt.datatransfer.Clipboard clipbrd)
Cut the content of the current selection (through a GraphicTransferable) to the System clipboard, AND to the given ClipBoard if non-null.- Parameters:
clipbrd- the target clipboard ; can be null, in which case only the System clipboard is modified.
-
cut
public void cut()
Cut the content of the current selection to the System clipboard, after formatting to text.
-
groupSelection
public void groupSelection()
group all selected objects into a new PicGroup and add it to the drawing.- Since:
- jPicEdt 1.2.a
-
unGroup
public void unGroup(PicGroup g)
fetch all Element's belonging to the given PicGroup and add them to its parent, removing the given PicGroup from its parent afterward.
-
joinSelection
public void joinSelection()
join all selected objects of type PicMultiCurveConvertable into a new PicMulticurve and add it to the drawing.- Since:
- jPicEdt 1.4.pre5
-
fireSelectionUpdate
protected void fireSelectionUpdate(Element element, SelectionEvent.EventType type)
Notify all listeners that have registered interest for notification on this event type.- Parameters:
element- the Element that was (un)selectedtype- the event type
-
fireSelectionUpdate
protected void fireSelectionUpdate(Element[] elements, SelectionEvent.EventType type)
Notify all listeners that have registered interest for notification on this event type.- Parameters:
elements- the Element's that were (un)selectedtype- the event type
-
addSelectionListener
public void addSelectionListener(SelectionListener l)
adds a SelectionListener to the Canvas
-
removeSelectionListener
public void removeSelectionListener(SelectionListener l)
removes a SelectionListener from the Canvas
-
getPreferredScrollableViewportSize
public java.awt.Dimension getPreferredScrollableViewportSize()
- Specified by:
getPreferredScrollableViewportSizein interfacejavax.swing.Scrollable- Returns:
- the drawing board size (aka ScrollPane's View size, as opposed to ViewPort's size)
-
getScrollableUnitIncrement
public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)- Specified by:
getScrollableUnitIncrementin interfacejavax.swing.Scrollable- Returns:
- a grid step
-
getScrollableBlockIncrement
public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)- Specified by:
getScrollableBlockIncrementin interfacejavax.swing.Scrollable- Returns:
- the viewport size minus a grid step
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()
- Specified by:
getScrollableTracksViewportWidthin interfacejavax.swing.Scrollable- Returns:
- false for this implementation
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()
- Specified by:
getScrollableTracksViewportHeightin interfacejavax.swing.Scrollable- Returns:
- false for this implementation
-
isRequestFocusEnabled
public boolean isRequestFocusEnabled()
Overriden from JComponent Signals that this component can receive focus (useful for handling keyevents)- Overrides:
isRequestFocusEnabledin classjavax.swing.JComponent
-
addPEMouseInputListener
public void addPEMouseInputListener(PEMouseInputListener l)
Adds the specified mouse listener to receive mouse events from this component. If l is null, no exception is thrown and no action is performed.- Parameters:
l- the mouse listener.
-
removePEMouseInputListener
public void removePEMouseInputListener(PEMouseInputListener l)
Removes the specified mouse listener so that it no longer receives mouse events from this component. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. If l is null, no exception is thrown and no action is performed.- Parameters:
l- the mouse listener.
-
processMouseEvent
protected void processMouseEvent(java.awt.event.MouseEvent e)
Processes mouse events occurring on this component by dispatching them to any registeredPEMouseListenerobjects.- Overrides:
processMouseEventin classjavax.swing.JComponent- Parameters:
e- the mouse event.
-
processMouseMotionEvent
protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
Processes mouse motion events occurring on this component by dispatching them to any registeredPEMouseInputListenerobjects.- Overrides:
processMouseMotionEventin classjavax.swing.JComponent- Parameters:
e- the mouse motion event.
-
-