jview
Class JNormalizedCanvas

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

public class JNormalizedCanvas
extends JComponent
implements Initializable, ResourceComposed, Savable, NormalizedCoordinates, NormalizedShapes

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. For convenience, methods are povided to allow adding of Shapes to the canvas which are draw in the JComponent.paint(java.awt.Graphics) method. Note that though this method allows adding with Paint objects, the performance using customized paints is generally much lower compared to using Colors. In particular, it can slow down the rendering process by a factor of 100. If you need customized strokes/ composites, try subclassing color.

See Also:
Serialized Form

Nested Class Summary
private  class JNormalizedCanvas.AnimateTask
          This timer task does an animation using the list of valid set names provided during construction.
static class JNormalizedCanvas.ShowImage
          Displays an image and an otherwise empty canvas.
static class JNormalizedCanvas.Test
          A test class aiming for saving of the image data.
 
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  JNormalizedCanvas.AnimateTask animate
          During an animation, this will be the animation task.
private  BufferedImage background
          A background image as displayed.
static String BACKGROUNDIMAGEPROPERTY
          The name of the view port image property.
private  Map<String,CanvasCursor> cursors
          All cursor this component knows of.
private  CanvasCursor customcursor
          If a customized cursor was set.
private static Color DEFGENERICCOLOR
          Default generic color, if no foreground was set.
private static boolean DEFXFLIPIMAGE
          Default flipping along x-axis.
private static boolean DEFYFLIPIMAGE
          Default flipping along y-axis.
private  Map<String,List<ShapeDraw>> draws
          A mapping of set names vs.
static String EXPORTACTION
          The label on the action for saving current zoom.
static String GENERIC
          The name of the generic DrawInfo, composed from foreground.
private  ResourceSupplying info
          My properties, composed from a PropertyBundles.
protected  AffineTransform inverse
          The inverse of transform.
static String KEY_BACKGROUND
          The key to background color.
static String KEY_CANVASNAME
          If set, the name of this component.
static String KEY_CANVASTIP
          If set, the tool tip of this component.
static String KEY_CURSORCLASSES
          A tokenizable list of cursor classes to optional names.
static String KEY_CURSORPROPS
          A list of cursor resources.
static String KEY_DRAWINGSETS
          A key for a general composite object as a MyAlphaComposite.
static String KEY_FOREGROUND
          The key to foreground color.
static String KEY_MAXIMUMHEIGHT
          A key to the maximum height of this component.
static String KEY_MAXIMUMWIDTH
          A key to the maximum width of this component.
static String KEY_MINIMUMHEIGHT
          A key to the minimum height of this component.
static String KEY_MINIMUMWIDTH
          A key to the minimum width of this component.
static String KEY_PREFERREDHEIGHT
          A key to the preferred height of this component.
static String KEY_PREFERREDWIDTH
          A key to the preferred width of this component.
static String KEY_PRINTFONT
          A list of font attributes to use for printing.
static String KEY_PRINTFONTSCALE
          A scale for the font to use for printing.
static String KEY_PRINTSHAPESCALE
          A scale for the shapes to use at printing.
static String KEY_RESTORESHAPES
          If we want to restore saved shapes.
static String KEY_XFLIPIMAGE
          The flipping along the x-axis for images.
static String KEY_YFLIPIMAGE
          The flipping along the y-axis for images.
private static String LINK
          File indicator for a linking object.
private  Map<String,List<FilledShape>> links
          A list of point-linkings.
private  Map<String,List<PointDraw>> points
          A mapping of set names to PointDraws.
private  PostUpdate post
          A post-update calling.
private  PreUpdate pre
          A pre-update calling.
static String PRINTACTION
          The label on the action for saving current zoom.
private  double printscale
          Used for scaling during print.
private  ImageOperation render
          Renders the background image before displaying it.
static String SAVEACTION
          The label on the action for saving current zoom.
private  Map<String,DrawingInfo> sets
          A mapping of names to DrawingInfos.
private  Map<String,List<TextDraw>> texts
          A mapping of TextDraw objects vs.
protected  AffineTransform transform
          The currently valid transform from normalized coordinates to screen.
 
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
JNormalizedCanvas(ResourceSupplying prop)
          Constructs a new shape canvas with the provided property container.
 
Method Summary
static void addCrossCursor(JNormalizedCanvas jtf)
          Add a zoom cursor to the data canvas.
 int addDrawable(ShapeDraw shape)
          Adds a shape to the drawable list of objects in the default color
 int addDrawable(String color, Shape shape, boolean fill)
          Adds a shape to the drawable list of objects.
 int addDrawable(String color, ShapeDraw shape)
          Adds a shape to the drawable list of objects.
 Object addDrawingInfo(String stylename, DrawingInfo color)
          We allow adding of a new drawing style.
 List<FilledShape> addLink(String key, FilledShape together)
          Adds a single object to a linking with the given name.
 List<FilledShape> addLink(String key, List<FilledShape> together)
          Adds an object to a linking with the given name.
 int addPoint(PointDraw note)
          Adds a text-draw object using the default color
 int addPoint(String name, PointDraw pixel)
          Adds a point-draw object specifying the name of the set.
 int addText(String name, TextDraw note)
          Adds a text-draw object specifying the name of the set.
 int addText(TextDraw note)
          Adds a text-draw object using the default color
protected static
<T extends Centerable>
List<T>
allInside(List<T> p, Rectangle2D norm)
          Returns all Centerables that center is within the normalized box.
protected static void applyDrawingInfo(Graphics2D g2d, DrawingInfo how)
          Applies a DrawingInfo object to a graphics2D object.
protected  void assignCursorLabel(JLabel curlab)
          Assigns a label to all cursors.
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.
 void clearAllDrawable()
          Clears all drawables.
 void clearAllText()
          Clears all text entries at all colors.
 Object clearDrawable(String color)
          Clears an entire list of drawables assigned to a single color.
 Object clearText(String color)
          Clears all text belonging to the specified color.
protected  CanvasCursor createCanvasCursor(String curcl, String curname, PropertySupplying curprop)
          Tries to create a customized canvas cursor from the given class name, assigning it the given cursor name, if any, using the properties handed over.
protected  void disabledCanvas(Graphics g)
          Prepares the canvas for drawing the shapes.
protected  void drawPoints(Graphics2D g2d, AffineTransform af)
          Draw now all shapes.
protected  void drawPointsMap(Graphics2D g2d, Map<String,List<PointDraw>> list, AffineTransform af)
          Paints a list of shapes onto this graphics2d object.
protected  void drawShapes(Graphics2D g2d, AffineTransform af)
          Draw now all shapes.
protected  void drawShapesMap(Graphics2D g2d, Map<String,List<ShapeDraw>> list, AffineTransform af)
          Paints a list of shapes onto this graphics2d object.
protected  void drawText(Graphics2D g2d, AffineTransform af)
          Draw all text objects.
protected  void drawTextMap(Graphics2D g2d, Map<String,List<TextDraw>> textmap, AffineTransform af)
          Paints a list of shapes onto this graphics2d object.
 void firePropertyChange(String s, Object oldo, Object newo)
          We make this public.
private  DrawingInfo fromName(String name, boolean addnew)
          Scans the name for the asociated drawing sets.
 Map<String,Action> getActions()
          Returns a mapping of action names to actions this component supports.
protected  Collection<CanvasCursor> getAllCanvasCursors()
          For daughter classes, get all custom cursors.
 Collection<DrawingInfo> getAnimationInfo(String name)
          Returns the animation-relevant drawing infos belonging to that set name.
 Rectangle getArea()
          Returns the active canvas.
 Color getBackground()
          Returns the background color or the default.
 BufferedImage getBackgroundImage()
          Returns the background image.
 CanvasCursor getCanvasCursor()
          Overrides get cursor, directly returns the cross cursor, if applicable.
protected static
<T extends Centerable>
T
getClosest(List<T> shapes, Point2D norm, double maxoff)
          Scans a list of shapes, calculates the bounding rectangle and returns the shape whose bounding rectangle's center has minimal distance to the normalized pixel.
protected
<T extends Centerable>
T
getClosest(Map<String,List<T>> sets, Point2D norm)
          Returns the shape that is closed to the normalized point.
protected
<T extends Centerable>
T
getClosest(Map<String,List<T>> sets, Point2D norm, double maxoff)
          Returns the shape that is closed to the normalized point.
<T extends Centerable>
T
getClosestShape(Point2D norm, Class<T> oftype)
          Locates the Centerable of the specified type that is closest to the given normalized point.
 ResourceSupplying getComposedProperties()
          Returns the ResourceSupplyings this canvas refers to.
 DrawingInfo getFromName(String name)
          If we know of a DrawingInfo of the stated name, return it.
protected  ImageOperation getImageOperation()
          Returns the image operation assigned to the background image.
protected
<T extends Centerable>
List<T>
getInside(Map<String,List<T>> set, Rectangle2D norm)
          Returns all Centerables that center is within the normalized box.
<T extends Centerable>
Collection<T>
getInsideShapes(Rectangle2D norm, Class<T> oftype)
          Returns the type of Centerables requested by forking into the three different methods #getInsideDrawables, #getInsidePoints, and #getInsideTexts.
 AffineTransform getInverseTransform()
          Returns the affine transformation used to transform the shapes.
 List<FilledShape> getLink(String name)
          Returns all linked object for the given name.
 List<FilledShape> getLinkedTo(FilledShape to)
          Returns a list of all shapes that are linked together to this shape.
 Dimension getMaximumSize()
          Returns a minimum size, if explicetly set in the properties or else diverts to the super method.
 Dimension getMinimumSize()
          Returns a minimum size, if explicetly set in the properties or else diverts to the super method.
 Point2D getNormalized(Point screen)
          Converts from screen pixels into normalized space.
 Rectangle2D getNormalizedRect(Rectangle cursor)
          This method translates a selcted area on the screen into normalized coordinate space.
 Dimension getPreferredSize()
          Returns the preferred size of this component.
 BufferedImage getSaveBuffer()
          Returns a bufferd image showing this canvas.
 Point getScreen(Point2D norm)
          Converts from normalized space into screen pixel.
 Rectangle getScreenRect(Rectangle2D cursor)
          This method translates a selcted area in normalized space into screen coordinates.
 AffineTransform getShapeTransform()
          Returns the affine transformation used to transform the shapes.
 Rectangle2D getViewport()
          Returns the maximum active viewport.
 void init()
          Initializes the shape canvas.
 boolean isEmpty()
          Returns true if all drawable objects have no entries.
protected  boolean isFlipX()
          Returns true, if the x-axis is flipped from its normal content.
protected  boolean isFlipY()
          Returns true, if the y-axis is flipped from its normal content.
 boolean isNormalizedOnScreen(Point2D visible)
          Test if this normalized pixel is related to a on-screen pixel that is within the drawable region.
 boolean isScreenInNormalized(Point cursor)
          Test, if a given screen point is within the currently visible normalized coordinate space.
 void paintComponent(Graphics g)
          Paint this component.
protected  void paintObjects(Graphics g, AffineTransform af)
          Draws the shapes and text.
protected  void paintPointsList(Graphics2D g2d, List<? extends PointDraw> pixels, AffineTransform af)
          We take a list of shapes and draw/fill them using current graphics setting.
protected  void paintShapesList(Graphics2D g2d, List<? extends ShapeDraw> shapes, AffineTransform af)
          We take a list of shapes and draw/fill them using current graphics setting.
protected  void paintTextList(Graphics2D g2d, List<? extends TextDraw> words, AffineTransform af)
          We take a list of TextDraw objects and draw them to the graphics supplied using the current graphics settings
private  boolean parseLine(String def)
          Tries to parse a single line into a known drawable object.
private  boolean parseLink(String def)
          Tries to restore linking between objects.
protected  void prepareCanvas(Graphics g)
          Prepares the canvas for drawing the shapes.
protected  void printComponent(Graphics g)
          Note that the graphics object we are handed over at that point is mutilated, as it is reprocessed twice in the parental method.
 ShapeDraw removeDrawable(String color, int index)
          Removes a drawable object from the list.
 boolean removeDrawable(String color, ShapeDraw shape)
          Removes a drawable object from the list.
 List<FilledShape> removeLink(String key)
          Links a list of shapes together.
 TextDraw removeText(String color, int index)
          Removes a text draw object.
 boolean removeText(String color, TextDraw note)
          Removes a text draw object.
 void repaintLater()
          Overrides the component repaint by putting it on the event queue, but delayed.
 void repaintNow()
          Overrides the component repaint by putting it on the event queue immediately.
private  boolean restoreShapes(URL load)
          Tries to restore saved shapes from a resource.
private  boolean saveShapes(File to)
          Writes all the shapes/text/points found in the drawing sets to the specified file.
private  Dimension screenRelated(int w, int h)
          Returns the dimension constructed from two integer values.
private static
<T> boolean
searchFor(T search, Map<String,List<T>> lookup, StringBuffer append)
          Searches an object in the specified mapping.
 void setBackgroundImage(Image img)
          Sets the background image.
 void setBounds(int x, int y, int w, int h)
          Sets the size of the component.
 void setComplete(PostUpdate pu)
          Sets a post-updateer.
 void setComposedProperties(ResourceSupplying prop)
          Sets a ResourceSupplying object as a composite of the canvas.
 void setCursor(Cursor cs)
          Overrides set cursor, if cursor is a cross-cursor.
 void setCursor(String name)
          Sets a cursor by a known cursor name
protected  int setDrawable(String color, List<ShapeDraw> shapes)
          Exchanges an entire list.
 void setImageOperation(ImageOperation io)
          Sets an image operation.
 List<FilledShape> setLink(String key, List<FilledShape> together)
          Links a list of shapes together.
 void setPrepare(PreUpdate pu)
          Sets a post-updateer.
 void startAnimation(List<String> these, long period)
          Animates the canvas by cycling through the list of provided set names.
 void stopAnimation()
          We stop an animation by making all the animated set visible again.
protected  void wasReshaped()
          Called in this class after a reshape.
private  boolean writeLink(BufferedWriter out, String name, List<FilledShape> fence)
          Writes a linking as object indices to the stream.
private static
<T> boolean
writeMap(BufferedWriter out, ShapeFactory.Drawings style, Map<String,List<T>> graph)
          Write a mapping to a writer.
 
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

GENERIC

public static final String GENERIC
The name of the generic DrawInfo, composed from foreground.

See Also:
Constant Field Values

SAVEACTION

public static final String SAVEACTION
The label on the action for saving current zoom.

See Also:
Constant Field Values

PRINTACTION

public static final String PRINTACTION
The label on the action for saving current zoom.

See Also:
Constant Field Values

EXPORTACTION

public static final String EXPORTACTION
The label on the action for saving current zoom.

See Also:
Constant Field Values

BACKGROUNDIMAGEPROPERTY

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

See Also:
Constant Field Values

KEY_CANVASNAME

public static final String KEY_CANVASNAME
If set, the name of this component.

See Also:
Constant Field Values

KEY_CANVASTIP

public static final String KEY_CANVASTIP
If set, the tool tip of this component.

See Also:
Constant Field Values

KEY_PREFERREDWIDTH

public static final String KEY_PREFERREDWIDTH
A key to the preferred width of this component.

See Also:
Constant Field Values

KEY_PREFERREDHEIGHT

public static final String KEY_PREFERREDHEIGHT
A key to the preferred height of this component.

See Also:
Constant Field Values

KEY_MINIMUMWIDTH

public static final String KEY_MINIMUMWIDTH
A key to the minimum width of this component.

See Also:
Constant Field Values

KEY_MINIMUMHEIGHT

public static final String KEY_MINIMUMHEIGHT
A key to the minimum height of this component.

See Also:
Constant Field Values

KEY_MAXIMUMWIDTH

public static final String KEY_MAXIMUMWIDTH
A key to the maximum width of this component.

See Also:
Constant Field Values

KEY_MAXIMUMHEIGHT

public static final String KEY_MAXIMUMHEIGHT
A key to the maximum height of this component.

See Also:
Constant Field Values

KEY_FOREGROUND

public static final String KEY_FOREGROUND
The key to foreground color. Also defines color of generic set.

See Also:
Constant Field Values

KEY_BACKGROUND

public static final String KEY_BACKGROUND
The key to background color.

See Also:
Constant Field Values

KEY_DRAWINGSETS

public static final String KEY_DRAWINGSETS
A key for a general composite object as a MyAlphaComposite.

See Also:
Constant Field Values

KEY_XFLIPIMAGE

public static final String KEY_XFLIPIMAGE
The flipping along the x-axis for images.

See Also:
Constant Field Values

KEY_YFLIPIMAGE

public static final String KEY_YFLIPIMAGE
The flipping along the y-axis for images.

See Also:
Constant Field Values

KEY_RESTORESHAPES

public static final String KEY_RESTORESHAPES
If we want to restore saved shapes.

See Also:
Constant Field Values

KEY_CURSORCLASSES

public static final String KEY_CURSORCLASSES
A tokenizable list of cursor classes to optional names.

See Also:
Constant Field Values

KEY_CURSORPROPS

public static final String KEY_CURSORPROPS
A list of cursor resources.

See Also:
Constant Field Values

KEY_PRINTFONT

public static final String KEY_PRINTFONT
A list of font attributes to use for printing.

See Also:
Constant Field Values

KEY_PRINTFONTSCALE

public static final String KEY_PRINTFONTSCALE
A scale for the font to use for printing.

See Also:
Constant Field Values

KEY_PRINTSHAPESCALE

public static final String KEY_PRINTSHAPESCALE
A scale for the shapes to use at printing.

See Also:
Constant Field Values

LINK

private static final String LINK
File indicator for a linking object.

See Also:
Constant Field Values

DEFGENERICCOLOR

private static final Color DEFGENERICCOLOR
Default generic color, if no foreground was set.


DEFXFLIPIMAGE

private static final boolean DEFXFLIPIMAGE
Default flipping along x-axis.

See Also:
Constant Field Values

DEFYFLIPIMAGE

private static final boolean DEFYFLIPIMAGE
Default flipping along y-axis.

See Also:
Constant Field Values

info

private ResourceSupplying info
My properties, composed from a PropertyBundles.


cursors

private Map<String,CanvasCursor> cursors
All cursor this component knows of. Loaded at setComposedProperties.


sets

private Map<String,DrawingInfo> sets
A mapping of names to DrawingInfos.


points

private Map<String,List<PointDraw>> points
A mapping of set names to PointDraws.


draws

private Map<String,List<ShapeDraw>> draws
A mapping of set names vs. drawable shapes.


texts

private Map<String,List<TextDraw>> texts
A mapping of TextDraw objects vs. their DrawingInfos.


links

private Map<String,List<FilledShape>> links
A list of point-linkings. Each entry is a list of Drawings.


transform

protected AffineTransform transform
The currently valid transform from normalized coordinates to screen.


inverse

protected AffineTransform inverse
The inverse of transform.


background

private BufferedImage background
A background image as displayed.


customcursor

private CanvasCursor customcursor
If a customized cursor was set.


render

private ImageOperation render
Renders the background image before displaying it.


pre

private PreUpdate pre
A pre-update calling.


post

private PostUpdate post
A post-update calling.


printscale

private double printscale
Used for scaling during print.


animate

private JNormalizedCanvas.AnimateTask animate
During an animation, this will be the animation task.

Constructor Detail

JNormalizedCanvas

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

firePropertyChange

public void firePropertyChange(String s,
                               Object oldo,
                               Object newo)
We make this public.

Overrides:
firePropertyChange in class Component

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

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

createCanvasCursor

protected CanvasCursor createCanvasCursor(String curcl,
                                          String curname,
                                          PropertySupplying curprop)
Tries to create a customized canvas cursor from the given class name, assigning it the given cursor name, if any, using the properties handed over. If creation was successful, the cursor is added to the internal list of possible cursors, but is not readyly assigned as the visible cursor of this component. The latter can be achieved using a call to #setCanvasCursor.


assignCursorLabel

protected void assignCursorLabel(JLabel curlab)
Assigns a label to all cursors.


restoreShapes

private boolean restoreShapes(URL load)
Tries to restore saved shapes from a resource. The format must follow this concept:

Returns:
True, if at least one shape was added.

parseLink

private boolean parseLink(String def)
                   throws ParseException
Tries to restore linking between objects. Objects have to be fully restored, as we try to get them by index. Format is
 LINK '$' Name-of-link '$' double tokenized List: 
        ShapeFactory.Drawings,set name, index;...
 

Throws:
ParseException

parseLine

private boolean parseLine(String def)
                   throws ParseException
Tries to parse a single line into a known drawable object. Format is:
 ShapeFactory.Drawings '$' set name '$' drawig-pattern '$'(true|false).
 
The last part is true for filled objects.

Throws:
ParseException

saveShapes

private boolean saveShapes(File to)
Writes all the shapes/text/points found in the drawing sets to the specified file.


writeLink

private boolean writeLink(BufferedWriter out,
                          String name,
                          List<FilledShape> fence)
                   throws IOException
Writes a linking as object indices to the stream.

Throws:
IOException

searchFor

private static <T> boolean searchFor(T search,
                                     Map<String,List<T>> lookup,
                                     StringBuffer append)
Searches an object in the specified mapping. If found, append to the string buffer the name of the drawing set plus index of object.


writeMap

private static <T> boolean writeMap(BufferedWriter out,
                                    ShapeFactory.Drawings style,
                                    Map<String,List<T>> graph)
                         throws IOException
Write a mapping to a writer. Each line consists of the type of the drawing, the name of the drawing set and a string representation of the object.

Throws:
IOException

setCursor

public void setCursor(String name)
Sets a cursor by a known cursor name


setCursor

public void setCursor(Cursor cs)
Overrides set cursor, if cursor is a cross-cursor.

Overrides:
setCursor in class Component

getCanvasCursor

public CanvasCursor getCanvasCursor()
Overrides get cursor, directly returns the cross cursor, if applicable.

See Also:
getAllCanvasCursors()

getAllCanvasCursors

protected Collection<CanvasCursor> getAllCanvasCursors()
For daughter classes, get all custom cursors.


addDrawingInfo

public Object addDrawingInfo(String stylename,
                             DrawingInfo color)
We allow adding of a new drawing style.


getComposedProperties

public ResourceSupplying getComposedProperties()
Returns the ResourceSupplyings this canvas refers to.

Specified by:
getComposedProperties in interface ResourceComposed

repaintLater

public void repaintLater()
Overrides the component repaint by putting it on the event queue, but delayed.


repaintNow

public void repaintNow()
                throws InterruptedException
Overrides the component repaint by putting it on the event queue immediately.

Throws:
InterruptedException

startAnimation

public void startAnimation(List<String> these,
                           long period)
Animates the canvas by cycling through the list of provided set names. All of them are set inactive, and are cycle-wise revived.


stopAnimation

public void stopAnimation()
We stop an animation by making all the animated set visible again.


getBackground

public Color getBackground()
Returns the background color or the default.

Overrides:
getBackground in class Component

setPrepare

public void setPrepare(PreUpdate pu)
Sets a post-updateer.


setComplete

public void setComplete(PostUpdate pu)
Sets a post-updateer.


setImageOperation

public void setImageOperation(ImageOperation io)
Sets an image operation.


getImageOperation

protected ImageOperation getImageOperation()
Returns the image operation assigned to the background image.


setBackgroundImage

public void setBackgroundImage(Image img)
Sets the background image. We construct a buffered image out of it. The image is interpreted in a way that its upper left corner is at normalized coordinates 0,0 and its bottom right corner at 1,1.


getBackgroundImage

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


getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size of this component. If it is not set explicetly in the properties, we return the saize of the background image. If we do not have such an image, we return the parent's preferred size.

Overrides:
getPreferredSize in class JComponent

getMinimumSize

public Dimension getMinimumSize()
Returns a minimum size, if explicetly set in the properties or else diverts to the super method.

Overrides:
getMinimumSize in class JComponent

getMaximumSize

public Dimension getMaximumSize()
Returns a minimum size, if explicetly set in the properties or else diverts to the super method. Negative values in the size means reduce the given values from the screen size

Overrides:
getMaximumSize in class JComponent

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Sets the size of the component. This also changes the affine transformation used to draw shapes onto the screen.

Overrides:
setBounds in class Component

wasReshaped

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


isEmpty

public boolean isEmpty()
Returns true if all drawable objects have no entries.


getShapeTransform

public AffineTransform getShapeTransform()
Returns the affine transformation used to transform the shapes.


getInverseTransform

public AffineTransform getInverseTransform()
Returns the affine transformation used to transform the shapes.


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.

Returns:
The forward transform from normalixed to screen space.

fromName

private DrawingInfo fromName(String name,
                             boolean addnew)
Scans the name for the asociated drawing sets. Synchronizes on sets. If the boolean addnew is true, a new Drawing set is generated from the name.


addPoint

public int addPoint(PointDraw note)
Adds a text-draw object using the default color

Returns:
The index of the object added in the list.

addPoint

public int addPoint(String name,
                    PointDraw pixel)
Adds a point-draw object specifying the name of the set. If the name cannot be found, we try to generate a new one by constructing a color from the name.


addText

public int addText(TextDraw note)
Adds a text-draw object using the default color

Returns:
The index of the object added in the list.

addText

public int addText(String name,
                   TextDraw note)
Adds a text-draw object specifying the name of the set. If the name cannot be found, we try to generate a new one by constructing a color from the name.


clearText

public Object clearText(String color)
Clears all text belonging to the specified color. Returns the old list of objects.


clearAllText

public void clearAllText()
Clears all text entries at all colors.


removeText

public TextDraw removeText(String color,
                           int index)
Removes a text draw object.


removeText

public boolean removeText(String color,
                          TextDraw note)
Removes a text draw object.


addDrawable

public int addDrawable(ShapeDraw shape)
Adds a shape to the drawable list of objects in the default color

Returns:
The index of the draw object added.

addDrawable

public int addDrawable(String color,
                       Shape shape,
                       boolean fill)
Adds a shape to the drawable list of objects.

Returns:
The index of the draw object added.

addDrawable

public int addDrawable(String color,
                       ShapeDraw shape)
Adds a shape to the drawable list of objects.

Returns:
The index of the draw object added.

removeLink

public List<FilledShape> removeLink(String key)
Links a list of shapes together. All shapes must be already present in the shapes mappings, they are not added to the draw/text etc. maps.

Returns:
The old link to that name

setLink

public List<FilledShape> setLink(String key,
                                 List<FilledShape> together)
Links a list of shapes together. All shapes must be already present in the shapes mappings, they are not added to the draw/text etc. maps.

Returns:
The old link to that name

addLink

public List<FilledShape> addLink(String key,
                                 FilledShape together)
Adds a single object to a linking with the given name. Returns the new linking.


addLink

public List<FilledShape> addLink(String key,
                                 List<FilledShape> together)
Adds an object to a linking with the given name. Returns the new linking.


getLink

public List<FilledShape> getLink(String name)
Returns all linked object for the given name.


getLinkedTo

public List<FilledShape> getLinkedTo(FilledShape to)
Returns a list of all shapes that are linked together to this shape.


getInsideShapes

public <T extends Centerable> Collection<T> getInsideShapes(Rectangle2D norm,
                                                            Class<T> oftype)
Returns the type of Centerables requested by forking into the three different methods #getInsideDrawables, #getInsidePoints, and #getInsideTexts. If neither of the types applies, null is returned.

Specified by:
getInsideShapes in interface NormalizedShapes
Parameters:
norm - The bounding rectangle in normalized coordinates.

getInside

protected <T extends Centerable> List<T> getInside(Map<String,List<T>> set,
                                                   Rectangle2D norm)
Returns all Centerables that center is within the normalized box.


allInside

protected static <T extends Centerable> List<T> allInside(List<T> p,
                                                          Rectangle2D norm)
Returns all Centerables that center is within the normalized box.


getClosestShape

public <T extends Centerable> T getClosestShape(Point2D norm,
                                                Class<T> oftype)
Locates the Centerable of the specified type that is closest to the given normalized point. Forks into the three different methods #getClosestDrawable, #getClosestPoint, and #getClosestText. If neither of the types applies, null is returned.

Specified by:
getClosestShape in interface NormalizedShapes
Parameters:
norm - The point-of-interest in normalized coordinates.

getClosest

protected <T extends Centerable> T getClosest(Map<String,List<T>> sets,
                                              Point2D norm)
Returns the shape that is closed to the normalized point. First, we check, if there are shapes that contain the point in question. If there is only a single such a Shape, we return it. If there is no such shape or we have more than one shape containing the point, we search the shape, whose bordering rectangle's center is closest to the given point.


getClosest

protected <T extends Centerable> T getClosest(Map<String,List<T>> sets,
                                              Point2D norm,
                                              double maxoff)
Returns the shape that is closed to the normalized point. First, we check, if there are shapes that contain the point in question. If there is only a single such a Shape, we return it. If there is no such shape or we have more than one shape containing the point, we search the shape, whose bordering rectangle's center is closest to the given point.


getClosest

protected static <T extends Centerable> T getClosest(List<T> shapes,
                                                     Point2D norm,
                                                     double maxoff)
Scans a list of shapes, calculates the bounding rectangle and returns the shape whose bounding rectangle's center has minimal distance to the normalized pixel.


setDrawable

protected int setDrawable(String color,
                          List<ShapeDraw> shapes)
Exchanges an entire list.


clearDrawable

public Object clearDrawable(String color)
Clears an entire list of drawables assigned to a single color. Returns the list of the cleared drawables.


clearAllDrawable

public void clearAllDrawable()
Clears all drawables. Calling this method also deletes any ticks and labels as they are also normal drawables.


removeDrawable

public ShapeDraw removeDrawable(String color,
                                int index)
Removes a drawable object from the list.


removeDrawable

public boolean removeDrawable(String color,
                              ShapeDraw shape)
Removes a drawable object from the list.

Returns:
True, if object was in list

getNormalized

public Point2D getNormalized(Point screen)
Converts from screen pixels into normalized space. Thus, the input type is a pure Point object, while the return value is a Point2D object.

Specified by:
getNormalized in interface NormalizedCoordinates
Parameters:
screen - A point on the screen.
Returns:
This point in normalized space, 0≤x,y&le1.

isFlipX

protected boolean isFlipX()
Returns true, if the x-axis is flipped from its normal content. The base class returns true here, if the KEY_XFLIPIMAGE property is true.


isFlipY

protected boolean isFlipY()
Returns true, if the y-axis is flipped from its normal content. The base class returns true here, if the KEY_YFLIPIMAGE property is true.


getNormalizedRect

public Rectangle2D getNormalizedRect(Rectangle cursor)
This method translates a selcted area on the screen into normalized coordinate space. First, we subtract the upper left corner and scale to the drawable size, then we match that with the current viewport.

Specified by:
getNormalizedRect in interface NormalizedCoordinates
Parameters:
cursor - A rectangle on the screen.
Returns:
This rectangle in normalized coordinate space.

getScreen

public Point getScreen(Point2D norm)
Converts from normalized space into screen pixel. Thus, the input type is a Point2D object, while the return value is a pure Point object.

Specified by:
getScreen in interface NormalizedCoordinates
Parameters:
norm - A point in normalized space
Returns:
This point in screen coordinates.

getScreenRect

public Rectangle getScreenRect(Rectangle2D cursor)
This method translates a selcted area in normalized space into screen coordinates.

Specified by:
getScreenRect in interface NormalizedCoordinates
Parameters:
cursor - A rectangle in normalized coordinate space.
Returns:
This rectangle on the screen.

getArea

public Rectangle getArea()
Returns the active canvas. This is the entire area

Specified by:
getArea in interface NormalizedCoordinates
See Also:
Zoomable

isScreenInNormalized

public boolean isScreenInNormalized(Point cursor)
Test, if a given screen point is within the currently visible normalized coordinate space. In the default implementation, this is always true.

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

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
Parameters:
visible - A point in normalized space, 0≤x,y&le1.

getViewport

public Rectangle2D getViewport()
Returns the maximum active viewport.

Specified by:
getViewport in interface NormalizedCoordinates
See Also:
Zoomable

getFromName

public DrawingInfo getFromName(String name)
If we know of a DrawingInfo of the stated name, return it.


getAnimationInfo

public Collection<DrawingInfo> getAnimationInfo(String name)
Returns the animation-relevant drawing infos belonging to that set name. Returns a single-lement collection here.


getSaveBuffer

public BufferedImage getSaveBuffer()
Returns a bufferd image showing this canvas. Can be used for off-screen saving.
Implementation note: We create a new Buffered image with type INT_RGB and draw into that, rather than creating the image directly from our (displayed) buffer, otherwise the performance goes to hell.

Specified by:
getSaveBuffer in interface Savable

getActions

public Map<String,Action> getActions()
Returns a mapping of action names to actions this component supports. They are not part of the JComponent.getActionMap(), but should be used by the application to further process it before adding it to the action map and input map of the component.


addCrossCursor

public static void addCrossCursor(JNormalizedCanvas 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


printComponent

protected void printComponent(Graphics g)
Note that the graphics object we are handed over at that point is mutilated, as it is reprocessed twice in the parental method. So, changing the default font is only possible here, this won't get thru.

Overrides:
printComponent in class JComponent

paintComponent

public void paintComponent(Graphics g)
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:
paintComponent in class JComponent

paintObjects

protected void paintObjects(Graphics g,
                            AffineTransform af)
Draws the shapes and text.


drawPoints

protected void drawPoints(Graphics2D g2d,
                          AffineTransform af)
Draw now all shapes. The basic canvas only has a list of drawable object, but subclasses may override here.

Changing drawing attributes here is okay, they will be reset later.


drawShapes

protected void drawShapes(Graphics2D g2d,
                          AffineTransform af)
Draw now all shapes. The basic canvas only has a list of drawable object, but subclasses may override here.

Changing drawing attributes here is okay, they will be reset later.


drawText

protected void drawText(Graphics2D g2d,
                        AffineTransform af)
Draw all text objects.


drawTextMap

protected void drawTextMap(Graphics2D g2d,
                           Map<String,List<TextDraw>> textmap,
                           AffineTransform af)
Paints a list of shapes onto this graphics2d object. If the objects in the list also implement the Composite, the Stroke, or the Paint interface, we set these attributes prior to drawing.

Parameters:
g - The graphics object to draw on.
list - A List of Shapes. May not be null.
outline - If true, we only draw instead of filling.

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.


disabledCanvas

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


drawShapesMap

protected void drawShapesMap(Graphics2D g2d,
                             Map<String,List<ShapeDraw>> list,
                             AffineTransform af)
Paints a list of shapes onto this graphics2d object. If the objects in the list also implement the Composite, the Stroke, or the Paint interface, we set these attributes prior to drawing.

Parameters:
g - The graphics object to draw on.
list - A List of Shapes. May not be null.
outline - If true, we only draw instead of filling.

drawPointsMap

protected void drawPointsMap(Graphics2D g2d,
                             Map<String,List<PointDraw>> list,
                             AffineTransform af)
Paints a list of shapes onto this graphics2d object. If the objects in the list also implement the Composite, the Stroke, or the Paint interface, we set these attributes prior to drawing.

Parameters:
g - The graphics object to draw on.
list - A List of Shapes. May not be null.
outline - If true, we only draw instead of filling.

paintPointsList

protected void paintPointsList(Graphics2D g2d,
                               List<? extends PointDraw> pixels,
                               AffineTransform af)
We take a list of shapes and draw/fill them using current graphics setting. This includes also the clip, so if painting at the active area, the clip must be set accordingly.


paintShapesList

protected void paintShapesList(Graphics2D g2d,
                               List<? extends ShapeDraw> shapes,
                               AffineTransform af)
We take a list of shapes and draw/fill them using current graphics setting. This includes also the clip, so if painting at the active area, the clip must be set accordingly.


paintTextList

protected void paintTextList(Graphics2D g2d,
                             List<? extends TextDraw> words,
                             AffineTransform af)
We take a list of TextDraw objects and draw them to the graphics supplied using the current graphics settings


applyDrawingInfo

protected static void applyDrawingInfo(Graphics2D g2d,
                                       DrawingInfo how)
Applies a DrawingInfo object to a graphics2D object. The old info is destroyed and must be cached outside this method if needed.


screenRelated

private Dimension screenRelated(int w,
                                int h)
Returns the dimension constructed from two integer values. Negative values mean subtract them from the screen size, positive values are used as-are.