jfig.canvas
Class FigBasicCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended byjfig.canvas.FigBasicCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, 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:
EditorCanvas, PresentationViewerCanvas, SelectFromLibraryDialog.NakedCanvas, TopLeftRulerCanvas, ViewerCanvas

public class FigBasicCanvas
extends java.awt.Canvas
implements FigCanvas, FullRedraw, ObjectPainter, SyncPainter, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

basic object canvas to draw FIG objects.

FigBasicCanvas 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.

FigBasicCanvas 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, FigBasicCanvas just follows the object list passed to it by the parent applet, 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, FigBasicCanvas supports the standard zoom functionality.

See Also:
Serialized Form

Nested Class Summary
 class FigBasicCanvas.Options2D
          Options2D: inner class to encapsulate access to Java2D rendering hints in a Java 1.1 compatible way.
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
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
           
(package private)  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  java.awt.Graphics gridGR
           
(package private)  int gridMode
           
(package private)  boolean gridVisible
           
protected  boolean hasRulers
           
(package private)  StatusMessage helper
           
(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
           
(package private)  java.awt.Image offscreenImage
           
protected  int old_x
           
protected  int old_y
           
(package private)  boolean pdbg
           
(package private)  ConsoleMessage printer
           
(package private)  java.awt.Point ptmp
           
protected  int redrawMode
           
(package private)  FigCanvasRubberband rubberband
           
protected  int RULER_XL_OFFSET
           
protected  int RULER_XR_OFFSET
           
protected  int RULER_YB_OFFSET
           
protected  int RULER_YT_OFFSET
           
(package private) 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
           
(package private)  java.awt.image.ImageObserver theObserver
           
(package private)  java.awt.Point tmp_sc
           
(package private)  java.awt.Point tmp_wc
           
protected  FigTrafo2D trafo
           
 java.awt.Cursor waitCursor
           
(package private)  java.util.Vector zoomListenerVector
           
 
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
FigBasicCanvas()
          The FigBasicCanvas public contructor.
 
Method Summary
 void addCanvasListener(FigCanvasListener listener)
           
 void addZoomListener(ZoomListener zl)
           
 void blitOffscreenBuffer(java.awt.Graphics g)
           
 void blitOffscreenBufferClipped(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)
           
 void doFullRedraw_deadlocks(long millis)
           
 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()
           
 void doSyncRedraw()
          method stub for synchronous repaints: FigBasicCanvas 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 doZoomOut()
          try to halve the current zoom factor (if possible), then redraw all.
 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 found and 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)
          variant of drawGrid
 void drawGridViaCopyArea(java.awt.Graphics gridGR)
          An implementation of drawGrid.
 void drawObject(java.awt.Graphics g, FigObject 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)
           
 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)
           
 void err(java.lang.String msg)
          print an error message to stderr (but never use the Console)
 void flush()
          call flush() on any offscreen buffers this canvas might have used.
 void get_current_canvas_size()
           
 java.awt.Color getBackground()
           
 java.awt.Component getComponent()
          return the AWT/Swing component that actually implements the canvas
 void getCurrentCanvasSize()
          get the current FigBasicCanvas 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
 FigBasicCanvas.Options2D getOptions2D()
           
 java.lang.String getRedrawMode()
           
 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_OLD()
           
 FigBbox getVisibleRegionBoundingBox()
           
 boolean gotFocus()
           
 void handleRedraw(java.awt.Graphics g)
           
 void initializeOffscreenBuffers()
          update the offscreen buffer images.
 boolean isDoubleBuffered()
           
static void main(java.lang.String[] argv)
          main(): simple self test of FigBasicCanvas 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
 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 msgs 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)
           
 void print(java.awt.Graphics g)
           
 void printAll(java.awt.Graphics g)
           
 void printTimingStats()
           
 void removeZoomListener(ZoomListener zl)
           
 void repaint()
           
 void repaint(int millis)
          request a standard repaint after (at most) millis milliseconds.
 void repaint(int x, int y, int w, int h)
           
 void repaint(long millis, int x, int y, int w, int h)
           
 void requestAntiAliasing(boolean b)
           
 void requestRenderQuality(boolean b)
           
 void setBackground(java.awt.Color c)
           
 void setConsole(ConsoleMessage printer)
          set the msg 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 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 java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
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

ConsoleMessage printer

helper

StatusMessage helper

canvasListener

FigCanvasListener canvasListener

zoomListenerVector

java.util.Vector zoomListenerVector

waitCursor

public java.awt.Cursor waitCursor

defaultCursor

public java.awt.Cursor defaultCursor

rubberband

FigCanvasRubberband rubberband

offscreenImage

java.awt.Image offscreenImage

theObserver

java.awt.image.ImageObserver theObserver

gridGR

protected java.awt.Graphics gridGR

offscreenGR

protected java.awt.Graphics offscreenGR

objectGR

protected java.awt.Graphics objectGR

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

ptmp

java.awt.Point ptmp

tmp_sc

java.awt.Point tmp_sc

tmp_wc

java.awt.Point tmp_wc

backgroundColor

protected java.awt.Color backgroundColor

gridColor

protected java.awt.Color gridColor

defaultColor

protected java.awt.Color defaultColor

rulerFont

static final java.awt.Font rulerFont

pdbg

boolean pdbg

gridVisible

boolean gridVisible

gridMode

int gridMode

redrawMode

protected int redrawMode

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

enableTimingInfo

protected boolean enableTimingInfo

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

n_trials_to_create_offscreenImage

int n_trials_to_create_offscreenImage
Constructor Detail

FigBasicCanvas

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

Method Detail

getRedrawMode

public java.lang.String getRedrawMode()

isDoubleBuffered

public boolean isDoubleBuffered()

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

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 msgs to console window or stdout

Specified by:
msg in interface FigCanvas

setConsole

public void setConsole(ConsoleMessage printer)
set the msg console

Specified by:
setConsole in interface FigCanvas

err

public void err(java.lang.String msg)
print an error message to stderr (but never use the Console)


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

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

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

paint

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

print

public void print(java.awt.Graphics g)

printAll

public void printAll(java.awt.Graphics g)

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

repaint

public void repaint()

repaint

public void repaint(int x,
                    int y,
                    int w,
                    int h)

repaint

public void repaint(long millis,
                    int x,
                    int y,
                    int w,
                    int h)

synchronousRepaint

public void synchronousRepaint()
request a synchronous repaint of all pending animation repaints. This request is ignored by FigBasicCanvas, 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

handleRedraw

public void handleRedraw(java.awt.Graphics g)
Specified by:
handleRedraw 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)
Specified by:
clippedDrawTmpObject in interface FigCanvas

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

doFullRedraw_deadlocks

public void doFullRedraw_deadlocks(long millis)

doSimpleRedraw

public void doSimpleRedraw()
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: FigBasicCanvas itself just provides a doSimpleRedraw().

This method should be overridden by subclasses as necessary.

Specified by:
doSyncRedraw in interface FigCanvas

drawSlidersAndCursor

public void drawSlidersAndCursor(java.awt.Graphics g,
                                 boolean erase)
Specified by:
drawSlidersAndCursor in interface FigCanvas

eraseObject

public void eraseObject(java.awt.Graphics g,
                        FigObject object)
Specified by:
eraseObject in interface FigCanvas

drawObject

public void drawObject(java.awt.Graphics g,
                       FigObject object)
Specified by:
drawObject 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_OLD

public FigBbox getVisibleRegionBoundingBox_OLD()

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 found and visible.

Specified by:
drawAllObjects in interface FigCanvas
Parameters:
g - the graphics-context to draw into (e.g. the FigBasicCanvas 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

drawTriangles

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


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.


getCurrentCanvasSize

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


get_current_canvas_size

public void get_current_canvas_size()

initializeOffscreenBuffers

public void initializeOffscreenBuffers()
update the offscreen buffer images. This is first done by the FigBasicCanvas 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()
Description copied from interface: FigCanvas
call flush() on any offscreen buffers this canvas might have used.

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.

drawGridViaCopyArea

public void drawGridViaCopyArea(java.awt.Graphics gridGR)
An implementation of drawGrid. This method uses Graphics.copyArea in order to avoid N*N calls to Graphics.drawLine (for each grid point). Instead we draw one single "grid cell" in the center of the canvas, then copy this "grid cell" to the top and bottom to create one "grid column", and finally copy this column to the left and right to fill the whole canvas.

This method proved much faster than drawing all points on older JDKs, but has the SEVERE drawback of additional synchronisation issues, because copyArea() is not well documented and is implemented asynchronously by current JVMs.


drawGridByHand

public void drawGridByHand(java.awt.Graphics gridGR)
variant of drawGrid


main

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


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

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 FigBasicCanvas.Options2D getOptions2D()