jview
Class JViewportCanvas

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
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, NormalizedCoordinates, NormalizedShapes, Zoomable, Initializable, ResourceAware, ResourceComposed, Savable
Direct Known Subclasses:
JFrameCanvas, JNight

public class JViewportCanvas
extends JNormalizedCanvas
implements Zoomable

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 JViewportCanvas.Test
          A test class aiming for saving of the image data.
static class JViewportCanvas.ViewportKey
          The class that allows selecting of only a portion of an JViewport .
 
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  List<ViewportTransferring> attach
          The list of attached ViewportTransferring objects.
static Rectangle2D MAXVIEW
          The maximum active viewport, which is 0,0,1,1.
private  BufferedImage viewground
          If we set an image that should stay the background of any viewport.
private  Rectangle2D viewport
          The current visible viewport in natural coordinates.
static String VIEWPORTIMAGEPROPERTY
          The name of the view port image property.
static String VIEWPORTPROPERTY
          The name of the view port property.
 
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
JViewportCanvas(ResourceSupplying prop)
          Constructs a new shape canvas with the provided property container.
 
Method Summary
 void addAttachedViewport(ViewportTransferring ear)
          Adds a new ViewportTransferring instance to the notification list of zoom changes.
static void addZoom(JViewportCanvas jtf)
          Add a zoom cursor to the data canvas.
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.
 Rectangle2D getViewport()
          Returns the currently active viewport.
 BufferedImage getViewportImage()
          Returns the background image.
 void init()
          Initializes the shape canvas.
 boolean isMaximalViewport(Rectangle2D rec)
          Returns true, if the viewport is the maximum viewport.
 boolean isNormalizedOnScreen(Point2D visible)
          Test if this normalized pixel is related to a on-screen pixel that is within the drawable region.
protected  void prepareCanvas(Graphics g)
          Prepares the canvas for drawing the shapes.
 void removeAttachedViewport(ViewportTransferring ear)
          Removes a ViewportTransferring instance from the notification list of zoom changes.
 boolean resetViewport()
          Resets the viewport to show the entrie viewport.
 boolean selectArea(Rectangle cursor)
          Selects an area from the screen.
 boolean selectViewport(Rectangle2D norm)
          Selecting the viewport fires a VIEWPORTPROPERTY change.
 void setViewportImage(Image img)
          Sets the viewport background image.
protected  boolean silentlySelectViewport(Rectangle2D newview)
          Selecting the viewport is just setting the current viewport.
 void transferView(Rectangle2D newview)
          Part of viewport selection that transfers the new view to the attaced viewport canvases.
 
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, getArea, 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, isScreenInNormalized, paintComponent, paintObjects, paintPointsList, paintShapesList, paintTextList, printComponent, removeDrawable, removeDrawable, removeLink, removeText, removeText, repaintLater, repaintNow, setBackgroundImage, setBounds, setComplete, setComposedProperties, setCursor, setCursor, setDrawable, setImageOperation, setLink, setPrepare, startAnimation, stopAnimation, wasReshaped
 
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

VIEWPORTPROPERTY

public static final String VIEWPORTPROPERTY
The name of the view port property.

See Also:
Constant Field Values

VIEWPORTIMAGEPROPERTY

public static final String VIEWPORTIMAGEPROPERTY
The name of the view port image property.

See Also:
Constant Field Values

MAXVIEW

public static final Rectangle2D MAXVIEW
The maximum active viewport, which is 0,0,1,1.


viewport

private Rectangle2D viewport
The current visible viewport in natural coordinates.


viewground

private BufferedImage viewground
If we set an image that should stay the background of any viewport.


attach

private List<ViewportTransferring> attach
The list of attached ViewportTransferring objects.

Constructor Detail

JViewportCanvas

public JViewportCanvas(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

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 JNormalizedCanvas

setViewportImage

public void setViewportImage(Image img)
Sets the viewport background image. We construct a buffered image out of it. The image is interpreted in a way that its always visible in total in the current viewport. It overrules background images in a way that it is drawn after a background image. To make changes visible, redraw the component


getViewportImage

public BufferedImage getViewportImage()
Returns the background image. This is always a buffered image and can savely cast.


addZoom

public static void addZoom(JViewportCanvas jtf)
Add a zoom cursor to the data canvas. This is a convenience method to allow this often-used cursor to be added with a single line of code


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 JNormalizedCanvas
Returns:
The forward transform from normalixed to screen space.

isNormalizedOnScreen

public boolean isNormalizedOnScreen(Point2D visible)
Test if this normalized pixel is related to a on-screen pixel that is within the drawable region.

Specified by:
isNormalizedOnScreen in interface NormalizedCoordinates
Overrides:
isNormalizedOnScreen in class JNormalizedCanvas
Parameters:
visible - A point in normalized space, 0≤x,y&le1.

getViewport

public Rectangle2D getViewport()
Returns the currently active viewport.

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

selectViewport

public boolean selectViewport(Rectangle2D norm)
Selecting the viewport fires a VIEWPORTPROPERTY change. Calls silentlySelectViewport(java.awt.geom.Rectangle2D), then fires a property change. If this component has some ViewportTransferring instances attached to it, the newly selected viewport is transported to them after the property change event has been fired.

Specified by:
selectViewport in interface Zoomable

transferView

public void transferView(Rectangle2D newview)
Part of viewport selection that transfers the new view to the attaced viewport canvases.


addAttachedViewport

public void addAttachedViewport(ViewportTransferring ear)
Adds a new ViewportTransferring instance to the notification list of zoom changes.


removeAttachedViewport

public void removeAttachedViewport(ViewportTransferring ear)
Removes a ViewportTransferring instance from the notification list of zoom changes.


silentlySelectViewport

protected boolean silentlySelectViewport(Rectangle2D newview)
Selecting the viewport is just setting the current viewport. We always return true here, if we have non-empty shape lists.


resetViewport

public boolean resetViewport()
Resets the viewport to show the entrie viewport.


selectArea

public boolean selectArea(Rectangle cursor)
Selects an area from the screen. First we have to find out to which normalized pixel coordinates this area belongs and then we set the viewport accordingly.

Specified by:
selectArea in interface Zoomable

isMaximalViewport

public boolean isMaximalViewport(Rectangle2D rec)
Returns true, if the viewport is the maximum viewport.


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 JNormalizedCanvas