cmsc420.drawing
Class CanvasPlus

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by cmsc420.drawing.CanvasPlus
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
CanvasPlusDemoApplet

public class CanvasPlus
extends javax.swing.JApplet

A general 2D drawing utility backed by Java AWT. CanvasPlus allows simple 2D graphics primitives to be placed into the scene and then drawn, by invoking the draw() method. The coordinate system used in CanvasPlus places (0,0) in the lower-left corner of the window.

This version of CanvasPlus includes several noticeable improvements over previous versions, including support for multiple viewport configurations. Specifically, users can now indicate how they want the image to be fit into the window, including support for scaling (see setScaleMode(int)). Background color can now be specified, and most notably, the draw() method no longer blocks execution until the window is closed. However, users can still invoke a blocking draw method (see drawBlocking()).

Animation is also supported by this version of CanvasPlus in a more sophisticated manner. By using the lookAt(int,int) method, users can programmatically scroll the canvas if the scale mode is fixed or scrollable (for scaled-to-fit and fixed aspect modes, the entire canvas is always visible within the window, so "looking at" a portion of the screen would serve no purpose). For animation, the ideal scale mode is none. Scale modes can be changed at any time (including while the scene is considered live, i.e., after its draw method has been invoked but before the window is closed).

Warning: be aware that any and all statements following draw() will continue to execute while the window is open, and may take precedence. For example:

This code will appear to do nothing; the window may flash for a second as it opens, but as soon as draw() returns, System.exit(0) is invoked and will force the window to close. If you want execution only to resume when the window is closed, use drawBlocking() instead, which will only return when the window is no longer open. Alternatively, suspendUntilClosed() can be called at any time after draw() to prevent further execution until the window is closed. Be advised, however, that in multi-threaded environments, other threads may still proceed.

Version:
3.0, 14 Feb 2007
Author:
Sean Dougherty (original author), Matt Lew (added functionality for circles, rectangles, and a basic priority queue), Evan Machusak (rewrote code for new version, documentation), Ben Zoller (added functionality for saving maps to file, removing shapes, rectangles are now drawn given its lower-left point)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static int SCALE_FIT
          A flag that, when specified, directs an instance of CanvasPlus to scale all coordinates to fit within the space provided by the enclosing window.
static int SCALE_FIXED_ASPECT
          A flag that, when specified, directs an instance of CanvasPlus to scale coordinates to fit within the space provided by the enclosing window with respect to the aspect ratio of the initial window.
static int SCALE_NONE
          A flag that, when specified, directs an instance of CanvasPlus not to use any scaling.
static int SCALE_SCROLL
          A flag that, when specified, directs an instance of CanvasPlus to display scroll bars as needed to to provide viewing access to all portions of the coordinate space.
 
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
CanvasPlus()
          Creates a new instance of CanvasPlus with the default title "untitled" and default width and height [512,512].
CanvasPlus(java.lang.String title)
          Creates a new instance of CanvasPlus with the specified title and default width and height [512,512].
CanvasPlus(java.lang.String title, java.awt.Dimension dim)
          Creates a new instance of CanvasPlus with the specified title, width, and height.
CanvasPlus(java.lang.String title, int width, int height)
          Creates a new instance of CanvasPlus with the specified title, width, and height.
 
Method Summary
 void add(Drawable2D obj)
          Adds an implementor of Drawable2D into the scene depicted by this CanvasPlus
 boolean addCircle(double x, double y, double radius, java.awt.Color color, boolean filled)
          Adds a circle into the scene.
 boolean addCircle(float x, float y, float radius, java.awt.Color color, boolean filled)
          Adds a circle into the scene.
 boolean addCross(double x, double y, double radius, java.awt.Color color)
          Adds an axis-aligned orthogonal cross into the scene.
 boolean addCross(float x, float y, float radius, java.awt.Color color)
          Adds an axis-aligned orthogonal cross into the scene.
 boolean addLine(double x1, double y1, double x2, double y2, java.awt.Color color)
          Adds a line segment into the scene.
 boolean addLine(float x1, float y1, float x2, float y2, java.awt.Color color)
          Adds a line segment into the scene.
 boolean addPoint(java.lang.String caption, double x, double y, java.awt.Color color)
          Adds a labeled point into the scene.
 boolean addPoint(java.lang.String caption, float x, float y, java.awt.Color color)
          Adds a labeled point into the scene.
 boolean addRectangle(double x, double y, double width, double height, java.awt.Color color, boolean filled)
          Adds a rectangle into the scene.
 boolean addRectangle(float x, float y, float width, float height, java.awt.Color color, boolean filled)
          Adds a rectangle into the scene.
 boolean addText(java.lang.String text, int x, int y)
          Adds a text label into the scene.
 void clear()
          Clears the map by clearing all of the shapes that are drawn when draw() is called.
 void dispose()
          Close the applet and release all of the native resources used by this Window, its subcomponents, and all of its children.
 void draw()
          Opens a window and displays the current scene depicted by this CanvasPlus.
 void draw(int scaleMode)
           
 void drawBlocking()
          Opens a window and displays the current scene depicted by this CanvasPlus, blocking all further execution until the user closes the window.
 void drawBlocking(int scaleMode)
           
 java.awt.Color getBackgroundColor()
          Returns the current background color of this CanvasPlus.
 java.awt.Font getFont()
          Returns the default font in which all future text added to this CanvasPlus will be rendered.
 java.awt.Dimension getFrameSize()
          Gets the current size of the visible window if this CanvasPlus is live.
 java.awt.geom.Point2D.Float getMax()
          Returns the point composed of the largest X-value and the largest Y-value so far added to this CanvasPlus.
 java.awt.geom.Point2D.Float getMin()
          Returns the point composed of the smallest X-value and the smallest Y-value so far added to this CanvasPlus.
 int getScaleMode()
          Returns the current scale mode in use by this CanvasPlus.
 java.awt.Dimension getScrollableRange()
          Returns the scrollable extent of this CanvasPlus.
 int getShapeCount()
          Returns the number of graphics primitives added to this CanvasPlus.
 java.awt.Dimension getSize()
          Returns the size of this CanvasPlus.
 void init()
          Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
 boolean isLive()
          Indicates whether or not the scene is currently live (i.e., the drawing window is open).
 void lookAt(double x, double y)
          Centers the visible portion of the scene depicted by this CanvasPlus around the point given in double precision.
 void lookAt(float x, float y)
          Centers the visible portion of the scene depicted by this CanvasPlus around the point given in floating point precision.
 void lookAt(int x, int y)
          Centers the visible portion of the scene depicted by this CanvasPlus around the given point.
 void lookAt(java.awt.geom.Point2D.Double p)
          Centers the visible portion of the scene depicted by this CanvasPlus around the specified point.
 void lookAt(java.awt.geom.Point2D.Float p)
          Centers the visible portion of the scene depicted by this CanvasPlus around the specified point.
 boolean removeCircle(double x, double y, double radius, java.awt.Color color, boolean filled)
          Adds a circle into the scene.
 boolean removeCircle(float x, float y, float radius, java.awt.Color color, boolean filled)
          Adds a circle into the scene.
 boolean removeCross(double x, double y, double radius, java.awt.Color color)
          Removes an axis-aligned orthogonal cross from the scene.
 boolean removeCross(float x, float y, float radius, java.awt.Color color)
          Removes an axis-aligned orthogonal cross from the scene.
 boolean removeLine(double x1, double y1, double x2, double y2, java.awt.Color color)
          Removes a line segment from the scene.
 boolean removeLine(float x1, float y1, float x2, float y2, java.awt.Color color)
          Removes a line segment from the scene.
 boolean removePoint(java.lang.String caption, double x, double y, java.awt.Color color)
          Removes a labeled point from the scene.
 boolean removePoint(java.lang.String caption, float x, float y, java.awt.Color color)
          Removes a labeled point from the scene.
 boolean removeRectangle(double x, double y, double width, double height, java.awt.Color color, boolean filled)
          Removes a rectangle from the scene.
 boolean removeRectangle(float x, float y, float width, float height, java.awt.Color color, boolean filled)
          Removes a rectangle from the scene.
 boolean removeText(java.lang.String text, int x, int y)
          Removes a text label from the scene.
 void repaint()
          Causes the Swing components of this CanvasPlus to repaint themselves.
 void save(java.lang.String name)
          Saves the current drawing pane to the file: <name>.png
 void setBackgroundColor(java.awt.Color color)
          Sets the background color of this CanvasPlus
 void setBounds(float xMin, float yMin, float xMax, float yMax)
           
 void setFont(java.awt.Font f)
          Sets the default font in which all future text added to this CanvasPlus will be rendered.
 void setFont(java.lang.String face, int style, int size)
          Sets the default font in which all future text added to this CanvasPlus will be rendered.
 void setFrameSize(java.awt.Dimension newSize)
          Sets the current size of the visible window if this CanvasPlus is live.
 void setFrameSize(int width, int height)
          Sets the current size of the visible window if this CanvasPlus is live.
 void setScaleMode(int scaleMode)
          Sets the scale mode for this CanvasPlus.
 void setSize(java.awt.Dimension newSize)
          Sets the size of this CanvasPlus.
 void setSize(int width, int height)
          Sets the size of this CanvasPlus.
 void start()
          Called by the browser or applet viewer to inform this applet that it should start its execution.
 void stop()
          See Applet.stop() for suggestions on overriding this method.
 void suspendUntilClosed()
          Causes the calling thread to perform busy-waiting until the window opened by draw() is closed.
 
Methods inherited from class javax.swing.JApplet
getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, requestFocus, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCALE_NONE

public static final int SCALE_NONE
A flag that, when specified, directs an instance of CanvasPlus not to use any scaling. Any objects that fit into the coordinate space contained within the visible window will be displayed; all others will be obscured from view.

See Also:
Constant Field Values

SCALE_SCROLL

public static final int SCALE_SCROLL
A flag that, when specified, directs an instance of CanvasPlus to display scroll bars as needed to to provide viewing access to all portions of the coordinate space.

See Also:
Constant Field Values

SCALE_FIT

public static final int SCALE_FIT
A flag that, when specified, directs an instance of CanvasPlus to scale all coordinates to fit within the space provided by the enclosing window. The canvas will be stretched both horizontally and vertically as needed to occupy the entire space in the window.

See Also:
Constant Field Values

SCALE_FIXED_ASPECT

public static final int SCALE_FIXED_ASPECT
A flag that, when specified, directs an instance of CanvasPlus to scale coordinates to fit within the space provided by the enclosing window with respect to the aspect ratio of the initial window. The image will be centered in the window as appropriate.

See Also:
Constant Field Values
Constructor Detail

CanvasPlus

public CanvasPlus()
Creates a new instance of CanvasPlus with the default title "untitled" and default width and height [512,512].

Since:
1.0

CanvasPlus

public CanvasPlus(java.lang.String title)
Creates a new instance of CanvasPlus with the specified title and default width and height [512,512].

Parameters:
title - the title caption of the window opened to view this canvas
Since:
1.0

CanvasPlus

public CanvasPlus(java.lang.String title,
                  java.awt.Dimension dim)
Creates a new instance of CanvasPlus with the specified title, width, and height.

Parameters:
title - the title caption of the window opened to view this canvas
dim - the dimensions of this CanvasPlus in screen space
Since:
1.0

CanvasPlus

public CanvasPlus(java.lang.String title,
                  int width,
                  int height)
Creates a new instance of CanvasPlus with the specified title, width, and height.

Parameters:
title - the title caption of the window opened to view this canvas
width - the width of this CanvasPlus in screen space
height - the height of this CanvasPlus in scree space
Since:
1.0
Method Detail

init

public final void init()
Called by the browser or applet viewer to inform this applet that it has been loaded into the system. Although granted public access for usability, the user should generally not invoke this method manually.

Note to extenders: this method is marked final; its body contains only a call to the non-final method setup(). To override this method, override setup() instead.

Overrides:
init in class java.applet.Applet
Since:
2.0
See Also:
setup()

start

public final void start()
Called by the browser or applet viewer to inform this applet that it should start its execution. Although granted public access for usability, the user should generally not invoke this method manually.

Note to extenders: this method is marked final; its body contains only a call to the non-final method run(). Because some browsers will not display anything in the applet body until this method exits, run() is wrapped in its own thread which will acquire a lock on this CanvasPlus, thus other threads wishing to invoke synchronized methods on this CanvasPlus will be blocked.

Overrides:
start in class java.applet.Applet
Since:
2.0
See Also:
run()

save

public void save(java.lang.String name)
          throws java.io.IOException
Saves the current drawing pane to the file: <name>.png

Note: The resources used by CanvasPlus will not be cleared until dispose() is called.

Parameters:
name - name of the png file the current drawing pane will be saved to
Throws:
java.io.IOException - problem accessing the image file
Since:
3.0

clear

public void clear()
Clears the map by clearing all of the shapes that are drawn when draw() is called.

Since:
3.0

dispose

public void dispose()
Close the applet and release all of the native resources used by this Window, its subcomponents, and all of its children. That is, the resources for these Components will be destroyed, any memory they consume will be released to the OS, and they will be marked as undisplayable.

Since:
3.0

stop

public void stop()
See Applet.stop() for suggestions on overriding this method. The default implementation for CanvasPlus does nothing. Because stop() is less crucial to successful operation of this CanvasPlus as an applet, it is not marked final, but in general extenders should override teardown().

Overrides:
stop in class java.applet.Applet
Since:
2.0
See Also:
Applet.stop()

draw

public void draw()
Opens a window and displays the current scene depicted by this CanvasPlus. Once this method has been called, the scene is said to be live. Note that this method will exit as soon as the window has been created, allowing the statements which succeed it to execute freely. In order to prevent further execution until this method has closed, use drawBlocking().

Since:
1.0
See Also:
drawBlocking()

draw

public void draw(int scaleMode)

drawBlocking

public void drawBlocking(int scaleMode)

drawBlocking

public void drawBlocking()
Opens a window and displays the current scene depicted by this CanvasPlus, blocking all further execution until the user closes the window. In order to allow execution to proceed after the window is opened and before it is closed, use draw().

Since:
2.0
See Also:
draw()

suspendUntilClosed

public void suspendUntilClosed()
Causes the calling thread to perform busy-waiting until the window opened by draw() is closed. This method will have no effect if the drawing window is not open.

Since:
2.0
See Also:
draw()

repaint

public void repaint()
Causes the Swing components of this CanvasPlus to repaint themselves. Callers can use this method to force the drawing space to set its preferred size correctly so the scroll bars are correctly sized. Because windowing is inherently multi-threaded, certain execution scheduling can cause a window with its scale mode set to scrollable to display scrollbars that are too small. CanvasPlus will handle this problem itself when displayed by its draw() methods, but extenders may encounter this issue when using CanvasPlus as an embedded applet, and thus this method is largely a convenience to extenders.

Overrides:
repaint in class java.awt.Component
Since:
2.0

lookAt

public void lookAt(int x,
                   int y)
Centers the visible portion of the scene depicted by this CanvasPlus around the given point. At a minimum, this method guarantees to bring the point (x,y) into view. If the point exists beyond the values returned by getScrollableRange(), it will not be possible to center the view around the given point because doing so would violate the bounds of the scrollbars. There is no harm in calling lookAt() on points that do not exist or wildly violate the bounds of this CanvasPlus; the method will make a best-effort attempt to scroll to that value.

If the current scale mode is set to SCALE_FIT or SCALE_FIXED_ASPECT, this method will have no effect since the entire scene is always visible under these scaling modes.

Parameters:
x - the X coordinate of the new center of focus
y - the y-croodinate of the new center of focus
Since:
2.0

lookAt

public void lookAt(float x,
                   float y)
Centers the visible portion of the scene depicted by this CanvasPlus around the point given in floating point precision. The specified parameters will be truncated to integers.

Parameters:
x - the X coordinate of the new center of focus
y - the y-croodinate of the new center of focus
Since:
2.0
See Also:
lookAt(int,int)

lookAt

public void lookAt(double x,
                   double y)
Centers the visible portion of the scene depicted by this CanvasPlus around the point given in double precision. The specified parameters will be truncated to integers.

Parameters:
x - the X coordinate of the new center of focus
y - the y-croodinate of the new center of focus
Since:
2.0
See Also:
lookAt(int,int)

lookAt

public void lookAt(java.awt.geom.Point2D.Float p)
Centers the visible portion of the scene depicted by this CanvasPlus around the specified point. The specified parameters' x- and y- values will be truncated to integers.

Parameters:
p - the new point at which focus will be centered
Since:
2.0
See Also:
lookAt(int,int)

lookAt

public void lookAt(java.awt.geom.Point2D.Double p)
Centers the visible portion of the scene depicted by this CanvasPlus around the specified point. The specified parameters' x- and y- values will be truncated to integers.

Parameters:
p - the new point at which focus will be centered
Since:
2.0
See Also:
lookAt(int,int)

getScrollableRange

public java.awt.Dimension getScrollableRange()
Returns the scrollable extent of this CanvasPlus. The value returned will hold the largest useful values specifiable via the lookAt(int,int) method. In general, a call to lookAt(0,0) will scroll to the upper-left corner of the visible area and a call to lookAt(d.width, d.height) where d is the value returned by this function will scroll to the lower-right corner of the visible area.

Note: this method will return unreliable values until the scene is live. In other words, before a call to draw() or drawBlocking() has been made, the value returned by this method is undefined. It will be non-null, but will most likely return a Dimension whose width and height values are one half of the current specified size for this CanvasPlus.

Returns:
an instance of Dimension containing the width and height of the scrollable range of this CanvasPlus
Since:
2.0

isLive

public boolean isLive()
Indicates whether or not the scene is currently live (i.e., the drawing window is open).

Returns:
true if this CanvasPlus is live, false otherwise.
Since:
2.0

getSize

public java.awt.Dimension getSize()
Returns the size of this CanvasPlus. This value is only used to define the size of the window when it is first opened and also as a way to define the aspect ratio of the desired image when using fixed aspect scaling mode. This method will not return the current size of the open window if this CanvasPlus is live. To get the current size, use getFrameSize() instead. The value returned is a copy and changing it will not change the size of this CanvasPlus; use setSize() instead.

Overrides:
getSize in class java.awt.Component
Returns:
an instance of Dimension containing the width and height of this CanvasPlus
Since:
1.0
See Also:
getFrameSize()

setSize

public void setSize(int width,
                    int height)
Sets the size of this CanvasPlus. This value is only used to define the size of the window when it is first opened and also as a way to define the aspect ratio of the desired image when using fixed aspect scaling mode. Calling this method on a live canvas will not cause the size of the open window to change. To change the size of the open window, use setFrameSize() instead.

Overrides:
setSize in class java.awt.Component
Parameters:
width - the new desired width of this CanvasPlus
height - the new desired height of this CanvasPlus
Since:
1.0
See Also:
setFrameSize(int,int)

setSize

public void setSize(java.awt.Dimension newSize)
Sets the size of this CanvasPlus. This value is only used to define the size of the window when it is first opened and also as a way to define the aspect ratio of the desired image when using fixed aspect scaling mode. Calling this method on a live canvas will not cause the size of the open window to change. To change the size of the open window, use setFrameSize() instead.

Overrides:
setSize in class java.awt.Component
Parameters:
newSize - the new desired dimensions of this CanvasPlus
Since:
1.0
See Also:
setFrameSize(int,int)

setBounds

public void setBounds(float xMin,
                      float yMin,
                      float xMax,
                      float yMax)

getFrameSize

public java.awt.Dimension getFrameSize()
Gets the current size of the visible window if this CanvasPlus is live. Otherwise, this method will return a size of [0,0]. This method returns a copy; changing the values of the returned Dimension will not affect the current window; use setFrameSize() instead.

Returns:
the current dimensions of the open window if the scene is live, a Dimension with width, height 0 otherwise
Since:
2.0

setFrameSize

public void setFrameSize(int width,
                         int height)
Sets the current size of the visible window if this CanvasPlus is live. This method will have no effect if called before or after the scene is live.

Parameters:
width - the new desired width of the visible window
height - the new desired height of the visible window
Since:
2.0

setFrameSize

public void setFrameSize(java.awt.Dimension newSize)
Sets the current size of the visible window if this CanvasPlus is live. This method will have no effect if called before or after the scene is live.

Parameters:
newSize - the new desired dimensions of the visible window
Since:
2.0

getMax

public java.awt.geom.Point2D.Float getMax()
Returns the point composed of the largest X-value and the largest Y-value so far added to this CanvasPlus. The X- and Y-values returned by this method will not necessarily belong to the same spatial point added to this CanvasPlus. As this value is maintained internally, it cannot be set; furthermore, this method returns a copy, therefore changing the return value's X- and Y- values will not affect this CanvasPlus.

Returns:
an instance of Point2D.Float containing the largest X- and Y-values present in this CanvasPlus
Since:
2.0

getMin

public java.awt.geom.Point2D.Float getMin()
Returns the point composed of the smallest X-value and the smallest Y-value so far added to this CanvasPlus. The X- and Y-values returned by this method will not necessarily belong to the same spatial point added to this CanvasPlus. As this value is maintained internally, it cannot be set; furthermore, this method returns a copy, therefore changing the return value's X- and Y- values will not affect this CanvasPlus.

Returns:
an instance of Point2D.Float containing the smallest X- and Y-values present in this CanvasPlus
Since:
2.0

getFont

public java.awt.Font getFont()
Returns the default font in which all future text added to this CanvasPlus will be rendered.

Specified by:
getFont in interface java.awt.MenuContainer
Overrides:
getFont in class java.awt.Component
Returns:
the default font associated with this CanvasPlus
Since:
2.0

setFont

public void setFont(java.awt.Font f)
Sets the default font in which all future text added to this CanvasPlus will be rendered.

Overrides:
setFont in class java.awt.Container
Parameters:
f - the new font to be associated with this CanvasPlus
Since:
2.0

setFont

public void setFont(java.lang.String face,
                    int style,
                    int size)
Sets the default font in which all future text added to this CanvasPlus will be rendered.

Parameters:
face - the font face
style - the style of the font (such as bold, italic, etc)
size - the size of the font
Since:
2.0

getBackgroundColor

public java.awt.Color getBackgroundColor()
Returns the current background color of this CanvasPlus.

Returns:
the background color of this CanvasPlus
Since:
2.0

setBackgroundColor

public void setBackgroundColor(java.awt.Color color)
Sets the background color of this CanvasPlus

Parameters:
color - the new background color
Since:
2.0

getScaleMode

public int getScaleMode()
Returns the current scale mode in use by this CanvasPlus.

Returns:
the scale mode of this CanvasPlus
Since:
2.0

setScaleMode

public void setScaleMode(int scaleMode)
Sets the scale mode for this CanvasPlus.

Parameters:
scaleMode - the scale mode to use for this CanvasPlus
Throws:
java.lang.IllegalArgumentException - if scaleMode is not one of SCALE_NONE, SCALE_SCROLL, SCALE_FIT, SCALE_FIXED_ASPECT
Since:
2.0

getShapeCount

public int getShapeCount()
Returns the number of graphics primitives added to this CanvasPlus.

Returns:
the size of this CanvasPlus's shape queue
Since:
2.0

add

public void add(Drawable2D obj)
Adds an implementor of Drawable2D into the scene depicted by this CanvasPlus

Parameters:
obj - the object to draw onto this CanvasPlus
Throws:
CircularMethodInvocationException - if obj.draw(this) invokes this method
Since:
2.0

addLine

public boolean addLine(float x1,
                       float y1,
                       float x2,
                       float y2,
                       java.awt.Color color)
Adds a line segment into the scene.

Parameters:
x1 - the X coordinate of the start point
y1 - the Y coordinate of the start point
x2 - the X coordinate of the end point
y2 - the Y coordinate of the end point
Returns:
true, as per contract with queue
Since:
3.0

addLine

public boolean addLine(double x1,
                       double y1,
                       double x2,
                       double y2,
                       java.awt.Color color)
Adds a line segment into the scene.

Parameters:
x1 - the X coordinate of the start point
y1 - the Y coordinate of the start point
x2 - the X coordinate of the end point
y2 - the Y coordinate of the end point
Returns:
true, as per contract with queue
Since:
3.0

removeLine

public boolean removeLine(float x1,
                          float y1,
                          float x2,
                          float y2,
                          java.awt.Color color)
Removes a line segment from the scene.

Parameters:
x1 - the X coordinate of the start point
y1 - the Y coordinate of the start point
x2 - the X coordinate of the end point
y2 - the Y coordinate of the end point
Returns:
true if the shape queue contained the shape
Since:
3.0

removeLine

public boolean removeLine(double x1,
                          double y1,
                          double x2,
                          double y2,
                          java.awt.Color color)
Removes a line segment from the scene.

Parameters:
x1 - the X coordinate of the start point
y1 - the Y coordinate of the start point
x2 - the X coordinate of the end point
y2 - the Y coordinate of the end point
Returns:
true if the shape queue contained the shape
Since:
3.0

addCircle

public boolean addCircle(float x,
                         float y,
                         float radius,
                         java.awt.Color color,
                         boolean filled)
Adds a circle into the scene.

Parameters:
x - the X coordinate of the circle's center
y - the Y coordinate of the circle's center
radius - the circle's radius
filled - true if the circle is solid (filled) or false if it is just an outline
Returns:
true, as per contract with queue
Since:
3.0

addCircle

public boolean addCircle(double x,
                         double y,
                         double radius,
                         java.awt.Color color,
                         boolean filled)
Adds a circle into the scene.

Parameters:
x - the X coordinate of the circle's center
y - the Y coordinate of the circle's center
radius - the circle's radius
filled - true if the circle is solid (filled) or false if it is just an outline
Returns:
true, as per contract with queue
Since:
3.0

removeCircle

public boolean removeCircle(float x,
                            float y,
                            float radius,
                            java.awt.Color color,
                            boolean filled)
Adds a circle into the scene.

Parameters:
x - the X coordinate of the circle's center
y - the Y coordinate of the circle's center
radius - the circle's radius
filled - true if the circle is solid (filled) or false if it is just an outline
Returns:
true if the shape queue contained the shape
Since:
3.0

removeCircle

public boolean removeCircle(double x,
                            double y,
                            double radius,
                            java.awt.Color color,
                            boolean filled)
Adds a circle into the scene.

Parameters:
x - the X coordinate of the circle's center
y - the Y coordinate of the circle's center
radius - the circle's radius
filled - true if the circle is solid (filled) or false if it is just an outline
Returns:
true if the shape queue contained the shape
Since:
3.0

addRectangle

public boolean addRectangle(float x,
                            float y,
                            float width,
                            float height,
                            java.awt.Color color,
                            boolean filled)
Adds a rectangle into the scene.

Parameters:
x - the X coordinate of the lower-left corner of the rectangle
y - the Y coordinate of the lower-left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle
filled - true if the rectangle is solid (filled) or false if it is just an outline
Returns:
true, as per contract with queue
Since:
3.0

addRectangle

public boolean addRectangle(double x,
                            double y,
                            double width,
                            double height,
                            java.awt.Color color,
                            boolean filled)
Adds a rectangle into the scene.

Parameters:
x - the X coordinate of the lower-left corner of the rectangle
y - the Y coordinate of the lower-left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle
filled - true if the rectangle is solid (filled) or false if it is just an outline
Returns:
true, as per contract with queue
Since:
3.0

removeRectangle

public boolean removeRectangle(float x,
                               float y,
                               float width,
                               float height,
                               java.awt.Color color,
                               boolean filled)
Removes a rectangle from the scene.

Parameters:
x - the X coordinate of the lower-left corner of the rectangle
y - the Y coordinate of the lower-left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle
filled - true if the rectangle is solid (filled) or false if it is just an outline
Returns:
true if the shape queue contained the shape
Since:
3.0

removeRectangle

public boolean removeRectangle(double x,
                               double y,
                               double width,
                               double height,
                               java.awt.Color color,
                               boolean filled)
Removes a rectangle from the scene.

Parameters:
x - the X coordinate of the lower-left corner of the rectangle
y - the Y coordinate of the lower-left corner of the rectangle
width - the width of the rectangle
height - the height of the rectangle
filled - true if the rectangle is solid (filled) or false if it is just an outline
Returns:
true if the shape queue contained the shape
Since:
3.0

addPoint

public boolean addPoint(java.lang.String caption,
                        float x,
                        float y,
                        java.awt.Color color)
Adds a labeled point into the scene.

Parameters:
caption - the point's label
x - the X coordinate of the point
y - the Y coordinate of the point
Returns:
true, as per contract with queue
Since:
3.0

addPoint

public boolean addPoint(java.lang.String caption,
                        double x,
                        double y,
                        java.awt.Color color)
Adds a labeled point into the scene.

Parameters:
caption - the point's label
x - the X coordinate of the point
y - the Y coordinate of the point
Returns:
true, as per contract with queue
Since:
3.0

removePoint

public boolean removePoint(java.lang.String caption,
                           float x,
                           float y,
                           java.awt.Color color)
Removes a labeled point from the scene.

Parameters:
caption - the point's label
x - the X coordinate of the point
y - the Y coordinate of the point
Returns:
true if the shape queue contained the shape
Since:
3.0

removePoint

public boolean removePoint(java.lang.String caption,
                           double x,
                           double y,
                           java.awt.Color color)
Removes a labeled point from the scene.

Parameters:
caption - the point's label
x - the X coordinate of the point
y - the Y coordinate of the point
Returns:
true if the shape queue contained the shape
Since:
3.0

addText

public boolean addText(java.lang.String text,
                       int x,
                       int y)
Adds a text label into the scene.

Parameters:
text - the text of the label
x - the X coordinate of the upper-left corner of the text
y - the Y coordinate of the upper-left corner of the text
Returns:
true, as per contract with queue
Since:
3.0

removeText

public boolean removeText(java.lang.String text,
                          int x,
                          int y)
Removes a text label from the scene.

Parameters:
text - the text of the label
x - the X coordinate of the upper-left corner of the text
y - the Y coordinate of the upper-left corner of the text
Returns:
true if the shape queue contained the shape
Since:
3.0

addCross

public boolean addCross(float x,
                        float y,
                        float radius,
                        java.awt.Color color)
Adds an axis-aligned orthogonal cross into the scene.

Parameters:
x - the X coordinate of the center of the cross
y - the Y coordinate of the center of the cross
radius - the radius of the cross (the distance from the center of the cross to each of its four endpoints)
Returns:
true, as per contract with queue
Since:
3.0

addCross

public boolean addCross(double x,
                        double y,
                        double radius,
                        java.awt.Color color)
Adds an axis-aligned orthogonal cross into the scene.

Parameters:
x - the X coordinate of the center of the cross
y - the Y coordinate of the center of the cross
radius - the radius of the cross (the distance from the center of the cross to each of its four endpoints)
Returns:
true, as per contract with queue
Since:
3.0

removeCross

public boolean removeCross(float x,
                           float y,
                           float radius,
                           java.awt.Color color)
Removes an axis-aligned orthogonal cross from the scene.

Parameters:
x - the X coordinate of the center of the cross
y - the Y coordinate of the center of the cross
radius - the radius of the cross (the distance from the center of the cross to each of its four endpoints)
Returns:
true if the shape queue contained the shape
Since:
3.0

removeCross

public boolean removeCross(double x,
                           double y,
                           double radius,
                           java.awt.Color color)
Removes an axis-aligned orthogonal cross from the scene.

Parameters:
x - the X coordinate of the center of the cross
y - the Y coordinate of the center of the cross
radius - the radius of the cross (the distance from the center of the cross to each of its four endpoints)
Returns:
true if the shape queue contained the shape
Since:
3.0