jfig.canvas
Class FigSwingCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjfig.canvas.FigSwingCanvas
All Implemented Interfaces:
java.util.EventListener, FigCanvas, FullRedraw, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, ObjectPainter, java.io.Serializable, SyncPainter
Direct Known Subclasses:
JObjectCanvas

public class FigSwingCanvas
extends javax.swing.JComponent
implements FigCanvas, FullRedraw, ObjectPainter, SyncPainter, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

basic object canvas to draw FIG objects.

FigSwingCanvas provides a canvas for displaying of FIG objects (subclasses of jfig.objects.FigObject) with zoom, several redraw and animation options. Use this class or a subclass of it as the main drawing canvas for a graphics editor like jfig or the corresponding viewer.

FigSwingCanvas handles mouseDown, mouseMove, mouseDrag, and KeyDown events for automatic panning (via cursor-keys or mouseMoves near the border). Other events are passed to the parent applet.

Drawing into the canvas is done in three steps with an offscreen buffer for the grid and the 'objects' respectively:

  1. The selected snapping grid is drawn on a offscreen buffer called offscreenImage. This may take some time for a fine grid. Drawing the grid is usually only done when the viewport changes (panning, resize, zoom).

  2. All objects are drawn on the offscreenImage buffer, starting with the objects on the deepest layer. Actually, FigSwingCanvas just follows the object list passed to it by the specified FigDrawableEnumerator, and calls the paint() method for all the objects.

  3. Finally, the offImage is copied onto the screen on redraw events.
Editor rubberbanding and cursor snapping are provided directly on the screen image, using the usual XOR drawing mode.

Additionally, FigSwingCanvas supports the standard zoom functionality.

See Also:
Serialized Form

Nested Class Summary
 class FigSwingCanvas.Options2D
          Options2D: inner class to encapsulate access to Java2D rendering hints in a Java 1.1 compatible way.
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Color backgroundColor
           
protected  int BASE_ANCHOR_X
           
protected  int BASE_ANCHOR_Y
           
protected  FigCanvasListener canvasListener
           
protected  int cur_height
           
protected  int cur_width
           
protected  int cur_x
           
protected  int cur_y
           
protected  boolean debug
           
protected  java.awt.Color defaultColor
           
 java.awt.Cursor defaultCursor
           
protected  boolean enableRulerDragging
           
protected  boolean enableTimingInfo
           
protected  java.awt.Color gridColor
           
protected  int gridMode
           
protected  boolean gridVisible
           
protected  boolean hasRulers
           
protected  StatusMessage helper
           
protected  boolean Jdebug
           
protected  int mode
           
(package private)  int mouse_drag_x
           
(package private)  int mouse_drag_y
           
(package private)  int n_grid
           
(package private)  int n_redraws
           
(package private)  int n_trials_to_create_offscreenImage
           
(package private)  int n_updates
           
protected  FigDrawableEnumerator objectEnumerator
           
protected  java.awt.Graphics objectGR
           
protected  java.awt.Graphics offscreenGR
           
protected  java.awt.Image offscreenImage
           
protected  int old_x
           
protected  int old_y
           
static int PAINT_ALL
           
static int PAINT_CURSOR
           
static int PAINT_NO_CHANGES
           
static int PAINT_OBJECTS
           
static int PAINT_RIGHT_RULER
           
static int PAINT_RUBBERBAND
           
static int PAINT_TMP_TEXT
           
static int PAINT_TOP_RULER
           
protected  ConsoleMessage printer
           
protected  java.awt.Point ptmp
           
protected  FigCanvasRubberband rubberband
           
protected  int RULER_XL_OFFSET
           
protected  int RULER_XR_OFFSET
           
protected  int RULER_YB_OFFSET
           
protected  int RULER_YT_OFFSET
           
protected static java.awt.Font rulerFont
           
(package private)  long t_delay
           
(package private)  long t_grid
           
(package private)  long t_grid_mean
           
(package private)  long t_redraw
           
(package private)  long t_redraw_mean
           
protected  java.awt.image.ImageObserver theObserver
           
protected  java.awt.Point tmp_sc
           
protected  java.awt.Point tmp_wc
           
protected  FigTrafo2D trafo
           
protected  java.awt.Image tripleBuffer
           
protected  java.awt.Graphics tripleBufferGR
           
protected  Format two_decimals
           
protected  boolean useTripleBuffering
           
 java.awt.Cursor waitCursor
           
protected  java.awt.Dimension XXX
           
protected  int zoomFitBorderWidth
           
protected  java.util.Vector zoomListenerVector
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface jfig.canvas.FigCanvas
FullRedraw, MouseMotionRedraw, NoChanges, ObjectRedraw, panDOWN, panHOME, panLEFT, panRIGHT, panUP, SyncRedraw, SystemRedraw, TmpObjectRedraw, TmpTextRedraw
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FigSwingCanvas()
          The FigSwingCanvas public contructor.
 
Method Summary
 void addCanvasListener(FigCanvasListener listener)
           
 void addZoomListener(ZoomListener zl)
           
 void blitOffscreenBuffer(java.awt.Graphics g)
           
 void blitOffscreenBufferClipped(java.awt.Graphics g)
           
 void blitTripleBuffer(java.awt.Graphics g)
           
 boolean canvasSizeChanged()
           
 void changeRubberbandMode(int new_mode)
          changeRubberbandMode(): change the current mode of our rubberband
 void changeRubberbandMode(int mode, FigTrafo2D t, java.lang.Object b)
           
 void changeRubberbandMode(int new_mode, GeometryManager gm)
           
 void clearBuffer(java.awt.Graphics g)
          clear the Image before drawing the rulers and the grid itself.
 void clippedDrawTmpObject(java.awt.Graphics g)
          NOTE: this method is currently not used anywhere; and it is possibly broken.
 void doFullRedraw()
          doFullRedraw(): redraw everything...
 void doFullRedraw(long millis)
           
 void doMotionRedraw()
           
 void doObjectRedraw()
           
 void doPanning(int direction, boolean shift)
          automatic panning of the visible viewport on the world-coordinate system.
 void doSimpleRedraw()
          repaint the canvas under the assumption that at most the temporary FIG objects have changed.
 void doSyncRedraw()
          method stub for synchronous repaints: FigSwingCanvas itself just provides a doSimpleRedraw().
 void doSystemRedraw()
           
 void doTextRedraw()
           
 void doToggleRubberbandDebug()
           
 void doZoom11()
          restore to zoom-factor 1 and origin (0,0)
 void doZoomFit()
          doZoomFit(): calculate the bounding box of all objects from our FigDrawableEnumerator, then set the zoom and panning so that all objects are visible.
 void doZoomFull()
          restore to zoom factor 1
 void doZoomIn()
          zoom in by a factor of two.
 void doZoomIn14()
           
 void doZoomOut()
          try to halve the current zoom factor (if possible), then redraw all.
 void doZoomOut07()
           
 void doZoomRegion(int wx, int wy, int wx2, int wy2)
          doZoomRegion(): zoom into the world coordinate region given by corners (wx,wy) and (wx2, wy2).
 void drawAllObjects(java.awt.Graphics g)
          drawAllObjects(): This traverses the parent's object list and draws all objects marked visible.
 void drawGrid(java.awt.Graphics gridGR)
          Actually draw the grid, assuming that the offscreenBuffers are already created and of the right size.
 void drawGridByHand(java.awt.Graphics gridGR)
          This is the "naive" implementation of drawGrid, which actually draws all N*N grid points by individual calls to drawRect.
 void drawObject(java.awt.Graphics g, FigObject object)
          draw the specified object.
 void drawRulers(java.awt.Graphics g)
          drawRulers: draw the scale rulers on top and the right side of the canvas.
 void drawSliders(java.awt.Graphics g, boolean erase)
          draw the sliders to mark the current position.
 void drawSlidersAndCursor(java.awt.Graphics g, boolean erase)
          draw the sliders in the rulers and the cursor.
 void drawSlidersOnce(java.awt.Graphics g, int x, int y)
          drawSlidersOnce: internal helper function to draw the sliders/cross-hatch at position (x,y).
 void drawTmpObjects(java.awt.Graphics g)
           
 void drawTriangles(java.awt.Graphics g, int xmax, int ymax)
          draw the 'scrollbar triangles'
 void eraseObject(java.awt.Graphics g, FigObject object)
          erase the specified object.
 void flush()
          called to help the AWT to release OS resources; the FigSwingCanvas may NOT be used after this was called.
 java.awt.Color getBackground()
           
 java.awt.Component getComponent()
          return the AWT/Swing component that actually implements the canvas
 void getCurrentCanvasSize()
          get the current FigSwingCanvas dimensions and store in our instance vars cur_width and cur_height.
 boolean getDebug()
           
 java.awt.Color getGridColor()
           
 java.awt.Point getMousePosition()
           
 FigDrawableEnumerator getObjectEnumerator()
           
 java.awt.Graphics getOffscreenGraphics()
          return a reference to the offscreen Graphics when double-buffering
 FigSwingCanvas.Options2D getOptions2D()
           
 java.lang.String getSwingRepaintMode()
           
 FigTrafo2D getTrafo()
          return the current coordinate transformation used for this canvas.
 java.awt.Point getViewportWCmax()
          return the world coordinates of the right-bottom corner of this canvas (depending on it's size and the zoom-factor).
 FigBbox getVisibleRegionBoundingBox()
           
 int getZoomFitBorderWidth()
           
 boolean gotFocus()
           
 void handleRedraw(java.awt.Graphics g)
          The handleRedraw method is defined in the FigCanvas interface, but is only exposing details of the inner workings of FigBasicCanvas.
 void initializeOffscreenBuffers()
          update the offscreen buffer images.
 boolean isDoubleBuffered()
          we do not want that Swing should manage a double buffer for us.
 boolean isOpaque()
          returns true.
 boolean isOptimizedDrawingEnabled()
          returns true.
 boolean isRightYRuler()
          if rulers are enabled, should the Y ruler be drawn on the right side (true) or on the left side (false) of this canvas? Default return value is true (right side).
static void main(java.lang.String[] argv)
          main(): simple self test of FigSwingCanvas inside a Frame.
 void mouseClicked(java.awt.event.MouseEvent evt)
           
 void mouseDragged(java.awt.event.MouseEvent evt)
          Handle MouseDrag events: Currently, mouseDrag events are used for canvas panning.
 void mouseEntered(java.awt.event.MouseEvent evt)
          mouseEntered(): request the keyboard focus.
 void mouseExited(java.awt.event.MouseEvent evt)
           
 void mouseMoved(java.awt.event.MouseEvent evt)
          Handle mouseMove events: update sliders/cross hatch, provide rubberbanding Note that we don't need to synchronize in the Swing world: everything is executed in the event dispatcher thread Also note that we have to correct the clip rectangle for the cursor extension (currently three pixels...)
 void mousePressed(java.awt.event.MouseEvent evt)
          Handle mouseDown events: snap to the currently active grid, then call the parent mouseDown action function.
 void mouseReleased(java.awt.event.MouseEvent evt)
          mouseReleased() is used to detect mouseDrag() events.
 void msg(java.lang.String msg)
          print messages to console window or stdout
 void notifyZoomListeners()
           
 void paint(FigDrawable obj)
          a method that allows animated objects to update their current state.
 void paint(FigDrawable obj, int millis)
          repaint an (animated) object within millis milliseconds.
 void paint(java.awt.Graphics g)
          dispatches to paintComponent().
 void paintAllObjects(java.awt.Graphics g)
          repaint the canvas after update the offscreen buffer.
 void paintBorder(java.awt.Graphics g)
          does nothing.
 void paintComponent(java.awt.Graphics g)
          paint this FigSwingCanvas including grid, rulers, objects, rubberband.
 void paintCursor(java.awt.Graphics g)
           
 void paintImmediately(int x, int y, int w, int h)
          dispatches to JComponent.paintImmediately().
 void paintNoChanges(java.awt.Graphics g)
          repaint the canvas under the assumption that the visible FIG objects have not changed.
 void paintRubberband(java.awt.Graphics g)
           
 void paintTmpText(java.awt.Graphics g)
           
 void printTimingStats()
           
 void processKeyEvent(java.awt.event.KeyEvent ko)
           
 void removeZoomListener(ZoomListener zl)
           
 void repaint(int millis)
          request a standard repaint after (at most) millis milliseconds.
 void requestAntiAliasing(boolean b)
           
 void requestRenderQuality(boolean b)
           
 void setBackground(java.awt.Color c)
           
 void setConsole(ConsoleMessage printer)
          set the message console
 void setDebug(boolean debug)
           
 void setDefaultCursor(java.awt.Cursor c)
           
 void setEnableRulerDragging(boolean b)
           
 void setGrid(int gridMode)
          set a new grid spacing.
 void setGridColor(java.awt.Color c)
          set new grid color
 void setObjectEnumerator(FigDrawableEnumerator enumerator)
          specify the object that will provide this canvas with the Enumeration of drawable objects.
 void setRubberbandAspect(double d)
           
 void setRubberbandBasePoint(int sx, int sy)
           
 void setRubberbandBasePoint(java.awt.Point sp)
          set a new base point for the rubberband
 void setRubberbandBasePoint2(int sx, int sy)
           
 void setRubberbandBasePoint2(java.awt.Point P)
           
 void setRubberbandShowLineLengths(boolean b)
           
 void setRulerOffsets()
          calculate the offsets required when using rulers on this canvas.
 void setStatusMessage(StatusMessage helper)
           
 void setTrafo(FigTrafo2D trafo)
          set the coordinate transformation for this canvas.
 void setTripleBuffering(boolean b)
           
 void setZoomFitBorderWidth(int pixels)
           
 void showRulers(boolean b)
           
 void statusMessage(java.lang.String msg)
          show or print status msgs
 void synchronousRepaint()
          request a synchronous repaint of all pending animation repaints.
 void update(java.awt.Graphics g)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintChildren, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jfig.canvas.FigCanvas
getCursor, getSize, setCursor
 

Field Detail

objectEnumerator

protected FigDrawableEnumerator objectEnumerator

trafo

protected FigTrafo2D trafo

printer

protected ConsoleMessage printer

helper

protected StatusMessage helper

canvasListener

protected FigCanvasListener canvasListener

zoomListenerVector

protected java.util.Vector zoomListenerVector

waitCursor

public java.awt.Cursor waitCursor

defaultCursor

public java.awt.Cursor defaultCursor

rubberband

protected FigCanvasRubberband rubberband

theObserver

protected java.awt.image.ImageObserver theObserver

offscreenImage

protected java.awt.Image offscreenImage

tripleBuffer

protected java.awt.Image tripleBuffer

offscreenGR

protected java.awt.Graphics offscreenGR

objectGR

protected java.awt.Graphics objectGR

tripleBufferGR

protected java.awt.Graphics tripleBufferGR

cur_x

protected int cur_x

cur_y

protected int cur_y

old_x

protected int old_x

old_y

protected int old_y

cur_width

protected int cur_width

cur_height

protected int cur_height

XXX

protected java.awt.Dimension XXX

ptmp

protected java.awt.Point ptmp

tmp_sc

protected java.awt.Point tmp_sc

tmp_wc

protected java.awt.Point tmp_wc

backgroundColor

protected java.awt.Color backgroundColor

gridColor

protected java.awt.Color gridColor

defaultColor

protected java.awt.Color defaultColor

rulerFont

protected static final java.awt.Font rulerFont

gridVisible

protected boolean gridVisible

gridMode

protected int gridMode

zoomFitBorderWidth

protected int zoomFitBorderWidth

PAINT_TMP_TEXT

public static final int PAINT_TMP_TEXT
See Also:
Constant Field Values

PAINT_NO_CHANGES

public static final int PAINT_NO_CHANGES
See Also:
Constant Field Values

PAINT_TOP_RULER

public static final int PAINT_TOP_RULER
See Also:
Constant Field Values

PAINT_RIGHT_RULER

public static final int PAINT_RIGHT_RULER
See Also:
Constant Field Values

PAINT_CURSOR

public static final int PAINT_CURSOR
See Also:
Constant Field Values

PAINT_RUBBERBAND

public static final int PAINT_RUBBERBAND
See Also:
Constant Field Values

PAINT_OBJECTS

public static final int PAINT_OBJECTS
See Also:
Constant Field Values

PAINT_ALL

public static final int PAINT_ALL
See Also:
Constant Field Values

mode

protected int mode

BASE_ANCHOR_X

protected int BASE_ANCHOR_X

BASE_ANCHOR_Y

protected int BASE_ANCHOR_Y

RULER_XL_OFFSET

protected int RULER_XL_OFFSET

RULER_XR_OFFSET

protected int RULER_XR_OFFSET

RULER_YT_OFFSET

protected int RULER_YT_OFFSET

RULER_YB_OFFSET

protected int RULER_YB_OFFSET

mouse_drag_x

int mouse_drag_x

mouse_drag_y

int mouse_drag_y

hasRulers

protected boolean hasRulers

enableRulerDragging

protected boolean enableRulerDragging

debug

protected boolean debug

Jdebug

protected boolean Jdebug

enableTimingInfo

protected boolean enableTimingInfo

useTripleBuffering

protected boolean useTripleBuffering

n_updates

int n_updates

n_redraws

int n_redraws

t_redraw

long t_redraw

t_redraw_mean

long t_redraw_mean

n_grid

int n_grid

t_grid

long t_grid

t_grid_mean

long t_grid_mean

t_delay

long t_delay

two_decimals

protected Format two_decimals

n_trials_to_create_offscreenImage

int n_trials_to_create_offscreenImage
Constructor Detail

FigSwingCanvas

public FigSwingCanvas()
The FigSwingCanvas public contructor. Add's the hook back to the parent applet and tries to constructs the offscreen buffers images.

Method Detail

getSwingRepaintMode

public java.lang.String getSwingRepaintMode()

setRulerOffsets

public void setRulerOffsets()
Description copied from interface: FigCanvas
calculate the offsets required when using rulers on this canvas. For example, the basic xfig-compatibly canvas uses rulers on the top and right sides of the canvas, and Graphics operations might want to clip drawing operations only to the central part of the canvas.

Specified by:
setRulerOffsets in interface FigCanvas

isRightYRuler

public boolean isRightYRuler()
if rulers are enabled, should the Y ruler be drawn on the right side (true) or on the left side (false) of this canvas? Default return value is true (right side).


setDebug

public void setDebug(boolean debug)
Specified by:
setDebug in interface FigCanvas

getDebug

public boolean getDebug()
Specified by:
getDebug in interface FigCanvas

getTrafo

public FigTrafo2D getTrafo()
Description copied from interface: FigCanvas
return the current coordinate transformation used for this canvas.

Specified by:
getTrafo in interface FigCanvas

setTrafo

public void setTrafo(FigTrafo2D trafo)
Description copied from interface: FigCanvas
set the coordinate transformation for this canvas.

Specified by:
setTrafo in interface FigCanvas

getComponent

public java.awt.Component getComponent()
Description copied from interface: FigCanvas
return the AWT/Swing component that actually implements the canvas

Specified by:
getComponent in interface FigCanvas

getOffscreenGraphics

public java.awt.Graphics getOffscreenGraphics()
Description copied from interface: FigCanvas
return a reference to the offscreen Graphics when double-buffering

Specified by:
getOffscreenGraphics in interface FigCanvas

setDefaultCursor

public void setDefaultCursor(java.awt.Cursor c)
Specified by:
setDefaultCursor in interface FigCanvas

addCanvasListener

public void addCanvasListener(FigCanvasListener listener)
Specified by:
addCanvasListener in interface FigCanvas

setObjectEnumerator

public void setObjectEnumerator(FigDrawableEnumerator enumerator)
specify the object that will provide this canvas with the Enumeration of drawable objects.

Specified by:
setObjectEnumerator in interface FigCanvas

getObjectEnumerator

public FigDrawableEnumerator getObjectEnumerator()
Specified by:
getObjectEnumerator in interface FigCanvas

statusMessage

public void statusMessage(java.lang.String msg)
show or print status msgs

Specified by:
statusMessage in interface FigCanvas

setStatusMessage

public void setStatusMessage(StatusMessage helper)
Specified by:
setStatusMessage in interface FigCanvas

msg

public void msg(java.lang.String msg)
print messages to console window or stdout

Specified by:
msg in interface FigCanvas

setConsole

public void setConsole(ConsoleMessage printer)
set the message console

Specified by:
setConsole in interface FigCanvas

setBackground

public void setBackground(java.awt.Color c)
Specified by:
setBackground in interface FigCanvas

setGridColor

public void setGridColor(java.awt.Color c)
set new grid color

Specified by:
setGridColor in interface FigCanvas

getBackground

public java.awt.Color getBackground()
Specified by:
getBackground in interface FigCanvas

getGridColor

public java.awt.Color getGridColor()
Specified by:
getGridColor in interface FigCanvas

getMousePosition

public java.awt.Point getMousePosition()
Specified by:
getMousePosition in interface FigCanvas

showRulers

public void showRulers(boolean b)
Specified by:
showRulers in interface FigCanvas

setEnableRulerDragging

public void setEnableRulerDragging(boolean b)
Specified by:
setEnableRulerDragging in interface FigCanvas

setTripleBuffering

public void setTripleBuffering(boolean b)

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Handle mouseDown events: snap to the currently active grid, then call the parent mouseDown action function.

Specified by:
mousePressed in interface FigCanvas

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
mouseReleased() is used to detect mouseDrag() events. On each mouseDown() and at the end of a mouseUp() we reset the values of the mouse_drag_(x,y) variables.

If both the current and the previous mouse_drag_(x,y) position lie in the rulers and differ by more than 5 pixels (to suppress small 'jitter'), we calculate the corresponding viewport panning.

In the future, we should probably provide some kind of visual feedback about the current drag amout by using mouseDrag() to update the rulers correspondingly.

Specified by:
mouseReleased in interface FigCanvas

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
mouseEntered(): request the keyboard focus.

Specified by:
mouseEntered in interface FigCanvas

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Specified by:
mouseExited in interface FigCanvas

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Specified by:
mouseClicked in interface FigCanvas

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Handle mouseMove events: update sliders/cross hatch, provide rubberbanding Note that we don't need to synchronize in the Swing world: everything is executed in the event dispatcher thread Also note that we have to correct the clip rectangle for the cursor extension (currently three pixels...)

Specified by:
mouseMoved in interface FigCanvas

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Handle MouseDrag events: Currently, mouseDrag events are used for canvas panning. The (global) variables mouse_drag_(x,y) are set at each mouseDown() and mouseUp() event.

However, mouseDrag() at the moment is not used: The actual panning calculations are done in mouseUp(). We should probably provide visual feedback about the drag amout by redrawing the rulers in this function.

Specified by:
mouseDragged in interface FigCanvas

gotFocus

public boolean gotFocus()
Specified by:
gotFocus in interface FigCanvas

doPanning

public void doPanning(int direction,
                      boolean shift)
automatic panning of the visible viewport on the world-coordinate system. Possible directions are left, right, up, down, and home. The amount of panning is 1/5th of the current viewport.

Specified by:
doPanning in interface FigCanvas

isDoubleBuffered

public boolean isDoubleBuffered()
we do not want that Swing should manage a double buffer for us. Explanation: isDoubleBuffered() in Swing lingo decides whether the central RepaintManager should manage an extra double buffer for us. However, this class needs to manage its own redrawing with its own offscreen buffer, so we have to return false here.


isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()
returns true. This method decides whether the Swing redraw algorithm can assume that this component handles non-rectangular repaints. We probably do :-)


isOpaque

public boolean isOpaque()
returns true. In Swing lingo, the isOpaque() flag decides whether a JComponent always fills all its area, which a FigSwingCanvas does. Returning true is essential to avoid flickering due to repainting of parent containers and to improve rendering performance.


processKeyEvent

public void processKeyEvent(java.awt.event.KeyEvent ko)

paint

public void paint(java.awt.Graphics g)
dispatches to paintComponent(). Only overriden in order to help debugging the Swing redraw mysteries

Specified by:
paint in interface FigCanvas

paintBorder

public void paintBorder(java.awt.Graphics g)
does nothing. We don't want a border on a FIG canvas. Instead, put the FigSwingCanvas onto a JPanel with a border.


paintImmediately

public void paintImmediately(int x,
                             int y,
                             int w,
                             int h)
dispatches to JComponent.paintImmediately(). Only overridden to help debugging the Swing redraw stuff. All attempts to really improve rendering performance by doing tricks here (instead of dispatching to super.paintImmediate()) have failed miserably. It seems that JComponent.paintImmediately() provides a lot of black magic.


paintComponent

public void paintComponent(java.awt.Graphics g)
paint this FigSwingCanvas including grid, rulers, objects, rubberband. This method is the heart of the rendering algorithm used by FigSwingCanvas. It is called both in reaction to external window system events and in reaction to jfig internal redraw requests.

The current rendering algorithm is as follows: 1. We first check whether the current canvas size still agrees with our offscreen buffer size. If not, we have to re-create the offscreen buffer and set the PAINT_ALL mode. 2. If the PAINT_ALL mode is set, e.g. as a result of doFullRedraw() or a window resize, we update the offscreen buffer first. This consists of drawing the grid, all FIG objects, and the tmp FIG objects onto the background buffer. 3. We bitblt the offscreen buffer onto the screen. 4. We draw the rulers, rubberband, and cursor on the screen.

Note: Experiments with all current JDKs (1.3+, 1.4+) from Sun, Blackdown, and IBM show that the Graphics XOR-mode rendering does not work reliably, especially for font rendering. (to say the least). Therefore, the redraw cannot use the (potentially) much faster XOR-mode based rubberbanding, but always has to do a bitblt with subsequent overdraw...


paintNoChanges

public void paintNoChanges(java.awt.Graphics g)
repaint the canvas under the assumption that the visible FIG objects have not changed. The paintNoChanges() method is called from the WindowManager (this is, Swing) as a result of mouseMoved() or mouseDragged() events, or when the window needs to be repainted due to Window or Menu changes. This means that the visible objects have not changed and that our offscreen buffer is up-to-date. On the other hand, XOR-mode painting useful for rubberbanding does not work with JDK 1.3.x. This in turn implies we use the following repaint algorithm: 1. blit the offscreen buffer to the screen 2. draw the temporary objects, if any. 3. update the rulers (if visible) 4. update the rubberband and cursor


paintCursor

public void paintCursor(java.awt.Graphics g)

paintRubberband

public void paintRubberband(java.awt.Graphics g)

paintTmpText

public void paintTmpText(java.awt.Graphics g)

paintAllObjects

public void paintAllObjects(java.awt.Graphics g)
repaint the canvas after update the offscreen buffer. This method is the Swing equivalent of the "FullRedraw" mode repainting used in FigBasicCanvas. It first updates our offscreen buffer, bitblts this to the screen, and then draws rulers and rubberband. The individual steps are as follows: 1. initialize the offscreen buffer (i.e. handle resizing) 2. clear the offscreen buffer 3. draw the selected grid (if any) 4. draw all visible objects onto the offscreen buffer 5. bitblt the offscreen buffer to the screen 6. draw temporary objects, if any 7. update rulers, rubberband, and cursor


paint

public void paint(FigDrawable obj)
a method that allows animated objects to update their current state. The object is drawn to both the background buffer and the screen.

Specified by:
paint in interface FigCanvas

paint

public void paint(FigDrawable obj,
                  int millis)
repaint an (animated) object within millis milliseconds. To improve performance and smooth drawing, only the region covered by the object, calculated by its screen-coordinates bounding-box, is paint()ed.

Specified by:
paint in interface FigCanvas

repaint

public void repaint(int millis)
request a standard repaint after (at most) millis milliseconds.

Specified by:
repaint in interface FigCanvas

synchronousRepaint

public void synchronousRepaint()
request a synchronous repaint of all pending animation repaints. This request is ignored by FigSwingCanvas, but might be implemented as required by subclasses.

Specified by:
synchronousRepaint in interface FigCanvas

update

public void update(java.awt.Graphics g)
Specified by:
update in interface FigCanvas

drawTmpObjects

public void drawTmpObjects(java.awt.Graphics g)
Specified by:
drawTmpObjects in interface FigCanvas

clippedDrawTmpObject

public void clippedDrawTmpObject(java.awt.Graphics g)
NOTE: this method is currently not used anywhere; and it is possibly broken. See paint( object, millis ) for a better alternative.

Specified by:
clippedDrawTmpObject in interface FigCanvas

blitTripleBuffer

public void blitTripleBuffer(java.awt.Graphics g)

blitOffscreenBuffer

public void blitOffscreenBuffer(java.awt.Graphics g)
Specified by:
blitOffscreenBuffer in interface FigCanvas

blitOffscreenBufferClipped

public void blitOffscreenBufferClipped(java.awt.Graphics g)
Specified by:
blitOffscreenBufferClipped in interface FigCanvas

printTimingStats

public void printTimingStats()
Specified by:
printTimingStats in interface FigCanvas

doFullRedraw

public void doFullRedraw()
doFullRedraw(): redraw everything... Usually, we want to do this in the calling thread, while the AWT repaint-Thread should only bitblt the offscreen-Buffer.

Specified by:
doFullRedraw in interface FigCanvas

doFullRedraw

public void doFullRedraw(long millis)
Specified by:
doFullRedraw in interface FigCanvas

doSimpleRedraw

public void doSimpleRedraw()
repaint the canvas under the assumption that at most the temporary FIG objects have changed. This method simply calls repaint(), which results in a later call to paintNoChanges(). Unlike FigBasicCanvas, which needs to keep track of what has been drawn due to using XOR mode, a FigSwingCanvas needs no special algorithm here. The standard handling of bitblt, drawing any tmp objects, and updating the rulers, rubberband, and cursor should just work fine.

Specified by:
doSimpleRedraw in interface FigCanvas

doTextRedraw

public void doTextRedraw()
Specified by:
doTextRedraw in interface FigCanvas

doObjectRedraw

public void doObjectRedraw()
Specified by:
doObjectRedraw in interface FigCanvas

doMotionRedraw

public void doMotionRedraw()
Specified by:
doMotionRedraw in interface FigCanvas

doSystemRedraw

public void doSystemRedraw()
Specified by:
doSystemRedraw in interface FigCanvas

doSyncRedraw

public void doSyncRedraw()
method stub for synchronous repaints: FigSwingCanvas itself just provides a doSimpleRedraw().

This method should be overridden by subclasses as necessary.

Specified by:
doSyncRedraw in interface FigCanvas

handleRedraw

public void handleRedraw(java.awt.Graphics g)
The handleRedraw method is defined in the FigCanvas interface, but is only exposing details of the inner workings of FigBasicCanvas. It is no longer meaningful for FigSwingCanvas, because the repaint algorithm is completely different. Our implmentation of handleRedraw just dispatches to paintComponent.

Specified by:
handleRedraw in interface FigCanvas

eraseObject

public void eraseObject(java.awt.Graphics g,
                        FigObject object)
erase the specified object. This method is defined in the FigCanvas interface, but not currently used by jfig outside of FigBasicCanvas. We use XOR mode and paint the object once.

Specified by:
eraseObject in interface FigCanvas

drawObject

public void drawObject(java.awt.Graphics g,
                       FigObject object)
draw the specified object.

Specified by:
drawObject in interface FigCanvas

drawSlidersAndCursor

public void drawSlidersAndCursor(java.awt.Graphics g,
                                 boolean erase)
draw the sliders in the rulers and the cursor. This method is defined in the FigCanvas interface, but not currently used by jfig outside of FigBasicCanvas. Unfortunately, XOR mode does not seem to work well in current JDKs, which means that we have no fast way to actually implement the erase=true operation. We just try with XOR mode anyway, and hope that nobody uses this method for production quality applications...

Specified by:
drawSlidersAndCursor in interface FigCanvas

drawSlidersOnce

public void drawSlidersOnce(java.awt.Graphics g,
                            int x,
                            int y)
drawSlidersOnce: internal helper function to draw the sliders/cross-hatch at position (x,y).


drawSliders

public void drawSliders(java.awt.Graphics g,
                        boolean erase)
draw the sliders to mark the current position. For performance reasons this function uses the global variables (old_x, old_y), (cur_x, cur_y) directly.


getViewportWCmax

public final java.awt.Point getViewportWCmax()
return the world coordinates of the right-bottom corner of this canvas (depending on it's size and the zoom-factor).

Specified by:
getViewportWCmax in interface FigCanvas

getVisibleRegionBoundingBox

public FigBbox getVisibleRegionBoundingBox()
Specified by:
getVisibleRegionBoundingBox in interface FigCanvas

drawAllObjects

public void drawAllObjects(java.awt.Graphics g)
drawAllObjects(): This traverses the parent's object list and draws all objects marked visible. This method is called for Java-native print rendering by JExportOptionsDialog and PrintManager.

Specified by:
drawAllObjects in interface FigCanvas
Parameters:
g - the graphics-context to draw into (e.g. the FigCanvas screen or the offscreenImage buffer).

setGrid

public void setGrid(int gridMode)
set a new grid spacing. See class FigTrafo2D for a list of the possible values.

This function implies a full redraw, in order to generate the new grid.

Specified by:
setGrid in interface FigCanvas

drawRulers

public void drawRulers(java.awt.Graphics g)
drawRulers: draw the scale rulers on top and the right side of the canvas. Both rules are labelled every 2cm (approx), and 10 ticks are drawn between two labels. The labels drawn are either in mm or in inches spacing, depending on the value of FigTrafo2D.units.


drawTriangles

public void drawTriangles(java.awt.Graphics g,
                          int xmax,
                          int ymax)
draw the 'scrollbar triangles'


getCurrentCanvasSize

public void getCurrentCanvasSize()
get the current FigSwingCanvas dimensions and store in our instance vars cur_width and cur_height.


initializeOffscreenBuffers

public void initializeOffscreenBuffers()
update the offscreen buffer images. This is first done by the FigSwingCanvas constructor, but it may be necessary after resize-events etc.

In order to run jfig both as an applet or standalone application, we have to be a little cautious here: While the applet's browser will be visible, it will provide us with a working graphics context. The standalone application will only receive a graphics context, when its frame is fully constructed and finally visible. As we need some graphics context, before we can proceed to build the offscreen buffer images, this implies that we have to wait until the editor frame window is already show()ing.

I consider this to be a bad Java JDK-10 bug, but it may be a feature :-)


canvasSizeChanged

public boolean canvasSizeChanged()

flush

public void flush()
called to help the AWT to release OS resources; the FigSwingCanvas may NOT be used after this was called.

Specified by:
flush in interface FigCanvas

clearBuffer

public void clearBuffer(java.awt.Graphics g)
clear the Image before drawing the rulers and the grid itself.


drawGrid

public void drawGrid(java.awt.Graphics gridGR)
Actually draw the grid, assuming that the offscreenBuffers are already created and of the right size. This function blocks the editor for a possibly long time. The gridMode is taken from trafo.gridMode. The typical grid spacing is one point every 1cm of screen spacing.

Parameters:
gridGR - the Graphics for drawing.

drawGridByHand

public void drawGridByHand(java.awt.Graphics gridGR)
This is the "naive" implementation of drawGrid, which actually draws all N*N grid points by individual calls to drawRect. This algorithm was very slow on older JDKs (1.1.x), but avoids the undocumented race-conditions in the AWT when using the drawGridByCopyArea() variant. Also, the overhead of function calls and especially AWT rendering calls is greatly reduced on modern JVMs (JDK 1.3+).


setZoomFitBorderWidth

public void setZoomFitBorderWidth(int pixels)

getZoomFitBorderWidth

public int getZoomFitBorderWidth()

doZoomFit

public void doZoomFit()
Description copied from interface: FigCanvas
doZoomFit(): calculate the bounding box of all objects from our FigDrawableEnumerator, then set the zoom and panning so that all objects are visible. This method currently assumes a 10 pixel border.

Specified by:
doZoomFit in interface FigCanvas

doZoomOut

public void doZoomOut()
try to halve the current zoom factor (if possible), then redraw all. Fixed point is the viewport center.

Specified by:
doZoomOut in interface FigCanvas

doZoomIn

public void doZoomIn()
zoom in by a factor of two. Fixed point is the viewport center.

Specified by:
doZoomIn in interface FigCanvas

doZoomFull

public void doZoomFull()
restore to zoom factor 1

Specified by:
doZoomFull in interface FigCanvas

doZoom11

public void doZoom11()
restore to zoom-factor 1 and origin (0,0)

Specified by:
doZoom11 in interface FigCanvas

doZoomRegion

public void doZoomRegion(int wx,
                         int wy,
                         int wx2,
                         int wy2)
doZoomRegion(): zoom into the world coordinate region given by corners (wx,wy) and (wx2, wy2).

Specified by:
doZoomRegion in interface FigCanvas

doZoomIn14

public void doZoomIn14()

doZoomOut07

public void doZoomOut07()

addZoomListener

public void addZoomListener(ZoomListener zl)
Specified by:
addZoomListener in interface FigCanvas

removeZoomListener

public void removeZoomListener(ZoomListener zl)
Specified by:
removeZoomListener in interface FigCanvas

notifyZoomListeners

public void notifyZoomListeners()
Specified by:
notifyZoomListeners in interface FigCanvas

changeRubberbandMode

public final void changeRubberbandMode(int new_mode)
changeRubberbandMode(): change the current mode of our rubberband

Specified by:
changeRubberbandMode in interface FigCanvas

changeRubberbandMode

public final void changeRubberbandMode(int new_mode,
                                       GeometryManager gm)
Specified by:
changeRubberbandMode in interface FigCanvas

changeRubberbandMode

public final void changeRubberbandMode(int mode,
                                       FigTrafo2D t,
                                       java.lang.Object b)
Specified by:
changeRubberbandMode in interface FigCanvas

setRubberbandBasePoint

public final void setRubberbandBasePoint(java.awt.Point sp)
set a new base point for the rubberband

Specified by:
setRubberbandBasePoint in interface FigCanvas

setRubberbandBasePoint

public final void setRubberbandBasePoint(int sx,
                                         int sy)
Specified by:
setRubberbandBasePoint in interface FigCanvas

setRubberbandBasePoint2

public final void setRubberbandBasePoint2(java.awt.Point P)
Specified by:
setRubberbandBasePoint2 in interface FigCanvas

setRubberbandBasePoint2

public final void setRubberbandBasePoint2(int sx,
                                          int sy)
Specified by:
setRubberbandBasePoint2 in interface FigCanvas

setRubberbandAspect

public final void setRubberbandAspect(double d)
Specified by:
setRubberbandAspect in interface FigCanvas

doToggleRubberbandDebug

public void doToggleRubberbandDebug()
Specified by:
doToggleRubberbandDebug in interface FigCanvas

setRubberbandShowLineLengths

public void setRubberbandShowLineLengths(boolean b)
Specified by:
setRubberbandShowLineLengths in interface FigCanvas

requestRenderQuality

public void requestRenderQuality(boolean b)
Specified by:
requestRenderQuality in interface FigCanvas

requestAntiAliasing

public void requestAntiAliasing(boolean b)
Specified by:
requestAntiAliasing in interface FigCanvas

getOptions2D

public FigSwingCanvas.Options2D getOptions2D()

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
main(): simple self test of FigSwingCanvas inside a Frame.

Throws:
java.lang.Exception