jview
Class JFrameCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by jview.JNormalizedCanvas
                  extended by jview.JViewportCanvas
                      extended by jview.JFrameCanvas
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, NormalizedCoordinates, NormalizedShapes, Zoomable, Initializable, ResourceAware, ResourceComposed, Savable
Direct Known Subclasses:
JBoxedCanvas, JFitsCanvas

public class JFrameCanvas
extends JViewportCanvas

A shape canvas is used to draw shapes into a pre-defined area. The entire space available to this component is splitted into a frame and a drawable area. It allows saving of the component as an image file using the JDK's 1.4 javax.imageio.ImageIO package. For convenience, methods are povided to allow adding of Shapes to the canvas which are draw in the JComponent.paint(java.awt.Graphics) method.

See Also:
Serialized Form

Nested Class Summary
static class JFrameCanvas.Test
          A test class aiming for saving of the image data.
 
Nested classes/interfaces inherited from class jview.JViewportCanvas
JViewportCanvas.ViewportKey
 
Nested classes/interfaces inherited from class jview.JNormalizedCanvas
JNormalizedCanvas.ShowImage
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  Rectangle activecanvas
          The drawable size of this component.
private static int DEFABSOLUTEHEIGHT
          The default height absoulte.
private static int DEFABSOLUTEWIDTH
          The default width absoulte.
private static double DEFRELATIVEHEIGHT
          The default heightt relative.
private static double DEFRELATIVEWIDTH
          The default width relative.
private static String DEFTITLEJUSTIFY
          The default title justification, center, center, bottom.
private static int DEFTITLEOFFSET
          The default title offset above the upper horizontal.
private static int DEFTOPOFFSET
          The default yop offset above the upper horizontal.
private static String DEFTOPSEPARATOR
          The default separator char in top texts.
private static int DEFXFRAME
          The default x-inset absoulte.
private static int DEFXINSETABSOLUTE
          The default x-inset absoulte.
private static double DEFXINSETRELATIVE
          The default x-inset relative.
private static int DEFYFRAME
          The default y-inset absoulte.
private static int DEFYINSETABSOLUTE
          The default y-inset absoulte.
private static double DEFYINSETRELATIVE
          The default y-inset relative.
static String KEY_ABSOLUTEHEIGHT
          The key to the draw size height, absolute pixel values.
static String KEY_ABSOLUTEWIDTH
          The key to the draw size width, absolute pixel values.
static String KEY_DRAWBOX
          If true, we add a box around the drawable area in foreground color.
static String KEY_RELATIVEHEIGHT
          The key to the draw size height, relative to size.
static String KEY_RELATIVEWIDTH
          The key to the draw size width, relative to size.
static String KEY_TITLECOLOR
          The main title color.
static String KEY_TITLEFONT
          The title font.
static String KEY_TITLEJUSTIFY
          The title justification.
static String KEY_TITLEOFFSET
          The y-tile distance to the upper box horizontal.
static String KEY_TITLETEXT
          The main title.
static String KEY_TOPCOLOR
          The main title color.
static String KEY_TOPFONT
          The title font.
static String KEY_TOPJUSTIFY
          The title justification.
static String KEY_TOPOFFSET
          The y-tile distance to the upper box horizontal.
static String KEY_TOPSEPARATOR
          The separator char in top texts and topjustifications.
static String KEY_TOPTEXT
          Additional texts at different justifications.
static String KEY_XFRAME
          The key to the allowed border overdraw in pixel values.
static String KEY_XINSETABSOLUTE
          The key to the top-left x-inset, absoulte pixel values.
static String KEY_XINSETRELATIVE
          The key to the top-left x-inset, relative value to size.
static String KEY_YFRAME
          The key to the allowed border-overdraw in pixel values.
static String KEY_YINSETABSOLUTE
          The key to the top-left y-inset, absoulte pixel values.
static String KEY_YINSETRELATIVE
          The key to the top-left y-inset, relative value to size.
 
Fields inherited from class jview.JViewportCanvas
MAXVIEW, VIEWPORTIMAGEPROPERTY, VIEWPORTPROPERTY
 
Fields inherited from class jview.JNormalizedCanvas
BACKGROUNDIMAGEPROPERTY, EXPORTACTION, GENERIC, inverse, KEY_BACKGROUND, KEY_CANVASNAME, KEY_CANVASTIP, KEY_CURSORCLASSES, KEY_CURSORPROPS, KEY_DRAWINGSETS, KEY_FOREGROUND, KEY_MAXIMUMHEIGHT, KEY_MAXIMUMWIDTH, KEY_MINIMUMHEIGHT, KEY_MINIMUMWIDTH, KEY_PREFERREDHEIGHT, KEY_PREFERREDWIDTH, KEY_PRINTFONT, KEY_PRINTFONTSCALE, KEY_PRINTSHAPESCALE, KEY_RESTORESHAPES, KEY_XFLIPIMAGE, KEY_YFLIPIMAGE, PRINTACTION, SAVEACTION, transform
 
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.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JFrameCanvas(ResourceSupplying prop)
          Constructs a new shape canvas with the provided property container.
 
Method Summary
protected  Rectangle calculateActiveCanvas()
          Calculates the current drawable size of this component after a resize event.
protected  AffineTransform calculateShapeTransform()
          Returns the affine transformation used to scale and shift shapes defined for 0,0 uper left corner and a 1x1 drawing size to the currently visible viewport and to the current size of the drawable area.
 Rectangle getArea()
          Returns the active canvas.
private  double getJustification(char j, double def)
          Converts a justification char into a justification double.
private  Point2D getTitleInset(FontMetrics fm, int width, String text, String just)
          Returns the title offset from the upper left corner of the active area.
private  Point2D getTopInset(FontMetrics fm, int width, String text, String just)
          Returns the top offset from the upper left corner of the active area.
 void init()
          Initializes the shape canvas.
 boolean isScreenInNormalized(Point cursor)
          Test, if a given screen point is within the currently visible normalized coordinate space.
protected  void paintObjects(Graphics g, AffineTransform af)
          Paint this component.
protected  void prepareCanvas(Graphics g)
          Prepares the canvas for drawing the shapes.
 void setComposedProperties(ResourceSupplying prop)
          Sets a ResourceSupplying object as a composite of the canvas.
protected  void wasReshaped()
          Called in this class after a reshape.
 
Methods inherited from class jview.JViewportCanvas
addAttachedViewport, addZoom, getViewport, getViewportImage, isMaximalViewport, isNormalizedOnScreen, removeAttachedViewport, resetViewport, selectArea, selectViewport, setViewportImage, silentlySelectViewport, transferView
 
Methods inherited from class jview.JNormalizedCanvas
addCrossCursor, addDrawable, addDrawable, addDrawable, addDrawingInfo, addLink, addLink, addPoint, addPoint, addText, addText, allInside, applyDrawingInfo, assignCursorLabel, clearAllDrawable, clearAllText, clearDrawable, clearText, createCanvasCursor, disabledCanvas, drawPoints, drawPointsMap, drawShapes, drawShapesMap, drawText, drawTextMap, firePropertyChange, getActions, getAllCanvasCursors, getAnimationInfo, getBackground, getBackgroundImage, getCanvasCursor, getClosest, getClosest, getClosest, getClosestShape, getComposedProperties, getFromName, getImageOperation, getInside, getInsideShapes, getInverseTransform, getLink, getLinkedTo, getMaximumSize, getMinimumSize, getNormalized, getNormalizedRect, getPreferredSize, getSaveBuffer, getScreen, getScreenRect, getShapeTransform, isEmpty, isFlipX, isFlipY, paintComponent, paintPointsList, paintShapesList, paintTextList, printComponent, removeDrawable, removeDrawable, removeLink, removeText, removeText, repaintLater, repaintNow, setBackgroundImage, setBounds, setComplete, setCursor, setCursor, setDrawable, setImageOperation, setLink, setPrepare, startAnimation, stopAnimation
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, 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, updateUI
 
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, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setComponentOrientation, 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
 

Field Detail

KEY_XINSETABSOLUTE

public static final String KEY_XINSETABSOLUTE
The key to the top-left x-inset, absoulte pixel values.

See Also:
Constant Field Values

KEY_YINSETABSOLUTE

public static final String KEY_YINSETABSOLUTE
The key to the top-left y-inset, absoulte pixel values.

See Also:
Constant Field Values

KEY_XINSETRELATIVE

public static final String KEY_XINSETRELATIVE
The key to the top-left x-inset, relative value to size.

See Also:
Constant Field Values

KEY_YINSETRELATIVE

public static final String KEY_YINSETRELATIVE
The key to the top-left y-inset, relative value to size.

See Also:
Constant Field Values

KEY_XFRAME

public static final String KEY_XFRAME
The key to the allowed border overdraw in pixel values.

See Also:
Constant Field Values

KEY_YFRAME

public static final String KEY_YFRAME
The key to the allowed border-overdraw in pixel values.

See Also:
Constant Field Values

KEY_ABSOLUTEWIDTH

public static final String KEY_ABSOLUTEWIDTH
The key to the draw size width, absolute pixel values.

See Also:
Constant Field Values

KEY_ABSOLUTEHEIGHT

public static final String KEY_ABSOLUTEHEIGHT
The key to the draw size height, absolute pixel values.

See Also:
Constant Field Values

KEY_RELATIVEWIDTH

public static final String KEY_RELATIVEWIDTH
The key to the draw size width, relative to size.

See Also:
Constant Field Values

KEY_RELATIVEHEIGHT

public static final String KEY_RELATIVEHEIGHT
The key to the draw size height, relative to size.

See Also:
Constant Field Values

KEY_DRAWBOX

public static final String KEY_DRAWBOX
If true, we add a box around the drawable area in foreground color.

See Also:
Constant Field Values

KEY_TITLETEXT

public static final String KEY_TITLETEXT
The main title.

See Also:
Constant Field Values

KEY_TITLECOLOR

public static final String KEY_TITLECOLOR
The main title color.

See Also:
Constant Field Values

KEY_TITLEFONT

public static final String KEY_TITLEFONT
The title font.

See Also:
Constant Field Values

KEY_TITLEJUSTIFY

public static final String KEY_TITLEJUSTIFY
The title justification.

See Also:
Constant Field Values

KEY_TITLEOFFSET

public static final String KEY_TITLEOFFSET
The y-tile distance to the upper box horizontal.

See Also:
Constant Field Values

KEY_TOPTEXT

public static final String KEY_TOPTEXT
Additional texts at different justifications.

See Also:
Constant Field Values

KEY_TOPCOLOR

public static final String KEY_TOPCOLOR
The main title color.

See Also:
Constant Field Values

KEY_TOPFONT

public static final String KEY_TOPFONT
The title font.

See Also:
Constant Field Values

KEY_TOPJUSTIFY

public static final String KEY_TOPJUSTIFY
The title justification.

See Also:
Constant Field Values

KEY_TOPOFFSET

public static final String KEY_TOPOFFSET
The y-tile distance to the upper box horizontal.

See Also:
Constant Field Values

KEY_TOPSEPARATOR

public static final String KEY_TOPSEPARATOR
The separator char in top texts and topjustifications.

See Also:
Constant Field Values

DEFXINSETABSOLUTE

private static final int DEFXINSETABSOLUTE
The default x-inset absoulte.

See Also:
Constant Field Values

DEFYINSETABSOLUTE

private static final int DEFYINSETABSOLUTE
The default y-inset absoulte.

See Also:
Constant Field Values

DEFXINSETRELATIVE

private static final double DEFXINSETRELATIVE
The default x-inset relative.

See Also:
Constant Field Values

DEFYINSETRELATIVE

private static final double DEFYINSETRELATIVE
The default y-inset relative.

See Also:
Constant Field Values

DEFXFRAME

private static final int DEFXFRAME
The default x-inset absoulte.

See Also:
Constant Field Values

DEFYFRAME

private static final int DEFYFRAME
The default y-inset absoulte.

See Also:
Constant Field Values

DEFABSOLUTEWIDTH

private static final int DEFABSOLUTEWIDTH
The default width absoulte.

See Also:
Constant Field Values

DEFABSOLUTEHEIGHT

private static final int DEFABSOLUTEHEIGHT
The default height absoulte.

See Also:
Constant Field Values

DEFRELATIVEWIDTH

private static final double DEFRELATIVEWIDTH
The default width relative.

See Also:
Constant Field Values

DEFRELATIVEHEIGHT

private static final double DEFRELATIVEHEIGHT
The default heightt relative.

See Also:
Constant Field Values

DEFTITLEJUSTIFY

private static final String DEFTITLEJUSTIFY
The default title justification, center, center, bottom.

See Also:
Constant Field Values

DEFTITLEOFFSET

private static final int DEFTITLEOFFSET
The default title offset above the upper horizontal.

See Also:
Constant Field Values

DEFTOPOFFSET

private static final int DEFTOPOFFSET
The default yop offset above the upper horizontal.

See Also:
Constant Field Values

DEFTOPSEPARATOR

private static final String DEFTOPSEPARATOR
The default separator char in top texts.

See Also:
Constant Field Values

activecanvas

private Rectangle activecanvas
The drawable size of this component. Changes when resized.

Constructor Detail

JFrameCanvas

public JFrameCanvas(ResourceSupplying prop)
Constructs a new shape canvas with the provided property container. Additionally, we add a component listener to ourself to catch resize events.

Method Detail

setComposedProperties

public void setComposedProperties(ResourceSupplying prop)
Sets a ResourceSupplying object as a composite of the canvas. Defaults the necessary parameter.

Specified by:
setComposedProperties in interface ResourceAware
Overrides:
setComposedProperties in class JNormalizedCanvas

init

public void init()
Initializes the shape canvas. This includes some default setting that might be overruled in subclasses.

Specified by:
init in interface Initializable
Overrides:
init in class JViewportCanvas

calculateActiveCanvas

protected Rectangle calculateActiveCanvas()
Calculates the current drawable size of this component after a resize event. Additionally calculates the active frame.


wasReshaped

protected void wasReshaped()
Called in this class after a reshape. Similar as adding a component-resized listener.

Overrides:
wasReshaped in class JNormalizedCanvas

calculateShapeTransform

protected AffineTransform calculateShapeTransform()
Returns the affine transformation used to scale and shift shapes defined for 0,0 uper left corner and a 1x1 drawing size to the currently visible viewport and to the current size of the drawable area. Additionally the inverse transform is set.

Overrides:
calculateShapeTransform in class JViewportCanvas
Returns:
The forward transform from normalixed to screen space.

isScreenInNormalized

public boolean isScreenInNormalized(Point cursor)
Test, if a given screen point is within the currently visible normalized coordinate space. This is useful for testing if a cursor hot-point is visible.

Specified by:
isScreenInNormalized in interface NormalizedCoordinates
Overrides:
isScreenInNormalized in class JNormalizedCanvas
Parameters:
cursor - A point on the screen.

getArea

public Rectangle getArea()
Returns the active canvas.

Specified by:
getArea in interface NormalizedCoordinates
Overrides:
getArea in class JNormalizedCanvas
See Also:
Zoomable

paintObjects

protected void paintObjects(Graphics g,
                            AffineTransform af)
Paint this component. Note that text components are not scaled to the drawable size, i.e. their position changes, but not their font size. To add text that scales with the component size, add it as a fillable/drawable object.

Overrides:
paintObjects in class JNormalizedCanvas

prepareCanvas

protected void prepareCanvas(Graphics g)
Prepares the canvas for drawing the shapes. This method clears the background to the background color, if the canvas is opaque.

Overrides:
prepareCanvas in class JViewportCanvas

getTitleInset

private Point2D getTitleInset(FontMetrics fm,
                              int width,
                              String text,
                              String just)
Returns the title offset from the upper left corner of the active area. Respects the justification of the titla and the title string.


getTopInset

private Point2D getTopInset(FontMetrics fm,
                            int width,
                            String text,
                            String just)
Returns the top offset from the upper left corner of the active area. Respects the justification of the title and the title string.


getJustification

private double getJustification(char j,
                                double def)
Converts a justification char into a justification double.