e-Mohr v. 1.00

wc
Class CanvasWC

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bywc.CanvasWC
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable
Direct Known Subclasses:
MohrCircleCanvas, MohrPrincipalStrsCanvas, MohrStateStrsCanvas, MohrThetaStrsCanvas

public abstract class CanvasWC
extends javax.swing.JPanel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

This CanvasWC class extends the JPanel class to provide control over displaying using a device-independent coordinate system called World Coordinates (WC), which is used by applications. Displaying is buffered to a BufferedImage object (offscreen image) to emulate double buffering rendering. The BufferedImage object contains a Graphics2D object as part of its rendering state. The Graphics2D object contains an AffineTransform object that defines how to convert coordinates from client space (world coordinates) to device-dependent (raster) coordinates in device space.

Clients need to extend this class, by creating subclasses, in order to use it.

The vertical Y axis of the CanvasWC object is set by default in downward direction, but clients may specify it in upward direction when the canvas is created.

===================

Version:
1.1 02/08/2000
Author:
Luiz Fernando Martha
See Also:
JPanel, Graphics2D, BufferedImage, MouseListener, MouseMotionListener, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int BASE_CENTER
          Field constant used to define text alignment.
static int BASE_LEFT
          Field constant used to define text alignment.
static int BASE_RIGHT
          Field constant used to define text alignment.
static int CENTER
          Field constant used to define text alignment.
static int DOWNWARD_Y
          Field constant used to define the vertical Y axis of the canvas in downward direction.
static int EAST
          Field constant used to define text alignment.
private  java.awt.Point ept_raster
          Private field that holds a mouse event point in raster (device) coordinates.
private  java.awt.geom.Point2D.Double ept_world
          Private field that holds a mouse event point in world coordinates.
private  java.awt.Font fnt
          Private field that holds current font that is used to display text.
private  java.awt.font.FontRenderContext frc
          Font renderer context: private field that is a container for the information needed to measure text that is displayed.
private  java.awt.Graphics2D g2off
          Graphics context object (Graphics2D) that contains an AffineTransform object that defines how to convert coordinates from client space (world coordinates) to device-dependent (raster) coordinates in device space.
private  java.awt.Graphics goff
          Graphics context object (Graphics) of the offscreen image used privately for double buffering.
(package private)  java.awt.geom.AffineTransform identity
          Private field that holds an auxiliary identity affine transformation matrix.
private  java.awt.image.BufferedImage ioff
          BufferedImage object that is used to implement double buffering rendering.
static int NORTH
          Field constant used to define text alignment.
static int NORTH_EAST
          Field constant used to define text alignment.
static int NORTH_WEST
          Field constant used to define text alignment.
static int OPAQUE
          Field constant used to define opaque text background opacity.
private  java.awt.Point pt_raster
          Private field that holds a auxiliary point in raster (device) coordinates.
private  java.awt.geom.Point2D.Double pt_world
          Private field that holds a auxiliary point in world coordinates.
protected  java.awt.Dimension raster_area
          Defines the canvas raster area.
static int SOUTH
          Field constant used to define text alignment.
static int SOUTH_EAST
          Field constant used to define text alignment.
static int SOUTH_WEST
          Field constant used to define text alignment.
private  int text_alignment
          Private field that holds current text alignment parameter.
private  java.awt.Rectangle text_box
          Private field that holds text box for opaque displaying.
private  int text_opacity
          Private field that holds current text alignment parameter.
static int TRANSPARENT
          Field constant used to define transparent text background opacity.
static int UPWARD_Y
          Field constant used to define the vertical Y axis of the canvas in upward direction.
protected  double vdistortion
          Keeps the WC window vertical distortion factor.
static int WEST
          Field constant used to define text alignment.
protected  java.awt.geom.Rectangle2D.Double world_area
          Defines the canvas world coordinate area.
protected  java.awt.geom.Rectangle2D.Double world_raw
          Defines the original canvas world coordinate area.
protected  int y_dir
          Keeps the vertical Y axis direction state.
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
CanvasWC()
          Default constructor.
CanvasWC(int y_dir)
          Constructor that sets up WC canvas according to a given orientation.
 
Method Summary
private  void adjustWorld()
          Adjusts the window in world coordinates (world_area) to have the same aspect ratio between height and width of the canvas (in its current state).
private  void buildOffscreen()
          Creates the BufferedImage object that is used to implement double buffering rendering.
 void drawString(java.lang.String text, double x, double y)
          Draw a given string on a given position.
 double getVDistortion()
          Gets the WC window vertical distortion factor.
 void mouseClicked(java.awt.event.MouseEvent e)
          Dummy method for the event of mouse clicked in canvas.
 void mouseDragged(java.awt.event.MouseEvent e)
          Handles the event of the user dragging the mouse while holding down the mouse button.
abstract  void mouseDraggedWC(java.awt.event.MouseEvent e, java.awt.geom.Point2D.Double pt)
          Mouse button dragged abstract method.
 void mouseEntered(java.awt.event.MouseEvent e)
          Dummy method for the event of mouse entered in canvas.
 void mouseExited(java.awt.event.MouseEvent e)
          Dummy method for the event of mouse exited from canvas.
 void mouseMoved(java.awt.event.MouseEvent e)
          Dummy method for the event of mouse motion in canvas.
 void mousePressed(java.awt.event.MouseEvent e)
          Handles the event of the user pressing down the mouse button.
abstract  void mousePressedWC(java.awt.event.MouseEvent e, java.awt.geom.Point2D.Double pt)
          Mouse button pressed abstract method.
 void mouseReleased(java.awt.event.MouseEvent e)
          Handles the event of the user releasing the mouse button.
abstract  void mouseReleasedWC(java.awt.event.MouseEvent e, java.awt.geom.Point2D.Double pt)
          Mouse button released abstract method.
 void paintComponent(java.awt.Graphics g)
          Update method of canvas.
 void panWorldX(double fac)
          Translates the world coordinate window of the target canvas in the horizontal direction based on a given pan factor.
 void panWorldY(double fac)
          Translates the world coordinate window of the target canvas in the vertical direction based on a given pan factor.
 java.awt.geom.Point2D.Double raster2world(int raster_x, int raster_y)
          Transforms the coordinates of a point given in device space (raster) to client space (world coordinates).
abstract  void redraw(java.awt.Graphics2D g)
          Redisplay abstract method.
 void scaleWorld(double fac)
          Scales the world coordinate window of the target canvas based on the given scaling factor.
 void setFont(java.awt.Font fnt)
          Set font to be used to display texts.
 void setTextAlignment(int text_alignment)
          Set alignment to be used to display texts.
 void setTextOpacity(int text_opacity)
          Set opacity to be used to display texts.
 void setVDistortion(double vdistortion)
          Sets the WC window vertical distortion factor.
 void setWorld(double xmin, double xmax, double ymin, double ymax)
          Sets the limits of the world coordinate window for the target canvas.
 java.awt.Point world2raster(double world_x, double world_y)
          Transforms the coordinates of a point given in client space (WC) to device-dependent (raster) coordinates.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, 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

raster_area

protected java.awt.Dimension raster_area
Defines the canvas raster area. This area corresponds to the sizes of the canvas in pixels.

See Also:
Dimension

world_area

protected java.awt.geom.Rectangle2D.Double world_area
Defines the canvas world coordinate area. This area corresponds to the window in client space which is visible in the canvas. This window is adjusted to have the same aspect ratio between height and width of the canvas (in its current state). When the client specifies the windows, the adjustment maintains the center of given (raw) window in the same position. This adjustment may be affected by the canvas vertical distortion factor.

See Also:
Rectangle2D.Double, vdistortion, setWorld(double, double, double, double)

world_raw

protected java.awt.geom.Rectangle2D.Double world_raw
Defines the original canvas world coordinate area. This area corresponds to the window in world coordinates which was set by the client. That is, it corresponds to the world area prior to adjustment with respect to the canvas aspect ratio between height and width.

See Also:
setWorld(double, double, double, double), world_area

DOWNWARD_Y

public static final int DOWNWARD_Y
Field constant used to define the vertical Y axis of the canvas in downward direction.

See Also:
Constant Field Values

UPWARD_Y

public static final int UPWARD_Y
Field constant used to define the vertical Y axis of the canvas in upward direction.

See Also:
Constant Field Values

y_dir

protected int y_dir
Keeps the vertical Y axis direction state. The possible values are DOWNWARD_Y (default) or UPWARD_Y. The Y axis direction is specified during creation, when the CanvasWC constructor is called.


ioff

private java.awt.image.BufferedImage ioff
BufferedImage object that is used to implement double buffering rendering. This object defines a Graphics2D graphics context object used to convert from world coordinates to raster coordinates.


goff

private java.awt.Graphics goff
Graphics context object (Graphics) of the offscreen image used privately for double buffering.


g2off

private java.awt.Graphics2D g2off
Graphics context object (Graphics2D) that contains an AffineTransform object that defines how to convert coordinates from client space (world coordinates) to device-dependent (raster) coordinates in device space.


vdistortion

protected double vdistortion
Keeps the WC window vertical distortion factor. This factor specifies the amount of distortion between the height and width of the world coordinate area. It is essentially a factor between the vertical and horizontal scales in client world coordinate space. A factor with value greater than one will cause a vertical stretching of the image.

See Also:
setVDistortion(double), world_area

pt_world

private java.awt.geom.Point2D.Double pt_world
Private field that holds a auxiliary point in world coordinates.


pt_raster

private java.awt.Point pt_raster
Private field that holds a auxiliary point in raster (device) coordinates.


ept_world

private java.awt.geom.Point2D.Double ept_world
Private field that holds a mouse event point in world coordinates.


ept_raster

private java.awt.Point ept_raster
Private field that holds a mouse event point in raster (device) coordinates.


TRANSPARENT

public static final int TRANSPARENT
Field constant used to define transparent text background opacity.

See Also:
Constant Field Values

OPAQUE

public static final int OPAQUE
Field constant used to define opaque text background opacity.

See Also:
Constant Field Values

text_opacity

private int text_opacity
Private field that holds current text alignment parameter.


text_box

private java.awt.Rectangle text_box
Private field that holds text box for opaque displaying.


NORTH_WEST

public static final int NORTH_WEST
Field constant used to define text alignment.

See Also:
Constant Field Values

NORTH

public static final int NORTH
Field constant used to define text alignment.

See Also:
Constant Field Values

NORTH_EAST

public static final int NORTH_EAST
Field constant used to define text alignment.

See Also:
Constant Field Values

SOUTH_WEST

public static final int SOUTH_WEST
Field constant used to define text alignment.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
Field constant used to define text alignment.

See Also:
Constant Field Values

SOUTH_EAST

public static final int SOUTH_EAST
Field constant used to define text alignment.

See Also:
Constant Field Values

WEST

public static final int WEST
Field constant used to define text alignment.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Field constant used to define text alignment.

See Also:
Constant Field Values

EAST

public static final int EAST
Field constant used to define text alignment.

See Also:
Constant Field Values

BASE_LEFT

public static final int BASE_LEFT
Field constant used to define text alignment.

See Also:
Constant Field Values

BASE_CENTER

public static final int BASE_CENTER
Field constant used to define text alignment.

See Also:
Constant Field Values

BASE_RIGHT

public static final int BASE_RIGHT
Field constant used to define text alignment.

See Also:
Constant Field Values

text_alignment

private int text_alignment
Private field that holds current text alignment parameter.


fnt

private java.awt.Font fnt
Private field that holds current font that is used to display text.


frc

private java.awt.font.FontRenderContext frc
Font renderer context: private field that is a container for the information needed to measure text that is displayed.


identity

java.awt.geom.AffineTransform identity
Private field that holds an auxiliary identity affine transformation matrix.

Constructor Detail

CanvasWC

public CanvasWC()
Default constructor. Sets up vertical Y axis in downward direction.


CanvasWC

public CanvasWC(int y_dir)
Constructor that sets up WC canvas according to a given orientation.

Parameters:
y_dir - can either be DOWNWARD_Y or UPWARD_Y
See Also:
DOWNWARD_Y, UPWARD_Y
Method Detail

redraw

public abstract void redraw(java.awt.Graphics2D g)
Redisplay abstract method. Client's concrete class must implement it. This method is called every time the canvas is updated.

Parameters:
g - is the 2D graphics context that the client uses to display

mousePressedWC

public abstract void mousePressedWC(java.awt.event.MouseEvent e,
                                    java.awt.geom.Point2D.Double pt)
Mouse button pressed abstract method. Client's concrete class must implement it. This method is called when the user presses a mouse button in the canvas.

Parameters:
e - is mouse event object
pt - is the mouse position in client's floating point world coordinates

mouseDraggedWC

public abstract void mouseDraggedWC(java.awt.event.MouseEvent e,
                                    java.awt.geom.Point2D.Double pt)
Mouse button dragged abstract method. Client's concrete class must implement it. This method is called when user drags the mouse in the canvas with a button pressed.

Parameters:
e - is mouse event object
pt - is the mouse position in client's floating point world coordinates

mouseReleasedWC

public abstract void mouseReleasedWC(java.awt.event.MouseEvent e,
                                     java.awt.geom.Point2D.Double pt)
Mouse button released abstract method. Client's concrete class must implement it. This method is called when user the mouse button at the end of a mouse pressed-dragged-released interaction.

Parameters:
e - is mouse event object
pt - is the mouse position in client's floating point world coordinates

buildOffscreen

private void buildOffscreen()
Creates the BufferedImage object that is used to implement double buffering rendering. This object defines a Graphics2D graphics context object used to convert from world coordinates to raster coordinates.


adjustWorld

private void adjustWorld()
Adjusts the window in world coordinates (world_area) to have the same aspect ratio between height and width of the canvas (in its current state). The adjustment maintains the center of given (raw) window in the same position. This adjustment may be affected by the canvas vertical distortion factor (vdistortion).


setWorld

public void setWorld(double xmin,
                     double xmax,
                     double ymin,
                     double ymax)
Sets the limits of the world coordinate window for the target canvas. The limits are adjusted to be consistent with the canvas viewport aspect ratio and with the canvas vertical distortion factor. The adjustment is such that the center of the given window is maintained.

The canvas is not automatically repainted by this method.

Parameters:
xmin - is the left limit of target window
xmax - is the right limit of target window
ymin - is the bottom limit of target window if vertical Y axis is upward, otherwise it is the top limit
ymax - is the top limit of target window if vertical Y axis is upward, otherwise it is the bottom limit
See Also:
world_area, setVDistortion(double)

panWorldX

public void panWorldX(double fac)
Translates the world coordinate window of the target canvas in the horizontal direction based on a given pan factor. This factor is a percentage of the current window horizontal size. A negative factor indicates a window translation to the right (the client model will move left), and a positive factor indicates a window translation to the left (the client model will move right).

The canvas is not automatically repainted by this method.

Parameters:
fac - is the pan factor
See Also:
world_area, setWorld(double, double, double, double)

panWorldY

public void panWorldY(double fac)
Translates the world coordinate window of the target canvas in the vertical direction based on a given pan factor. This factor is a percentage of the current window horizontal size. If the vertical Y axis is upward, a negative factor indicates a upward window translation (the client model will move downward), and a positive factor indicates a downward window translation (the client model will move upward). If the vertical Y axis is downward, the reverse will occur.

The canvas is not automatically repainted by this method.

Parameters:
fac - is the pan factor
See Also:
world_area, setWorld(double, double, double, double)

scaleWorld

public void scaleWorld(double fac)
Scales the world coordinate window of the target canvas based on the given scaling factor. This factor is a percentage of decrease (positive factor) or increase (negative factor) of the window sizes. The result of this inversion (positive ==> decrease, negative ==> increase) is that the size of the client's enviroment decreases with a negative factor and increases with a positive factor.

The canvas is not automatically repainted by this method.

Parameters:
fac - is the scaling factor
See Also:
world_area, setWorld(double, double, double, double)

setVDistortion

public void setVDistortion(double vdistortion)
Sets the WC window vertical distortion factor. This factor specifies the amount of distortion between the height and width of the world coordinate area. It is essentially a factor between the vertical and horizontal scales in client world coordinate space. A factor with value greater than one will cause a vertical stretching of the image.

The canvas is not automatically repainted by this method.

Parameters:
vdistortion - is the vertical distortion factor
See Also:
vdistortion, setWorld(double, double, double, double)

getVDistortion

public double getVDistortion()
Gets the WC window vertical distortion factor.

Returns:
vertical distortion factor
See Also:
vdistortion, setVDistortion(double)

world2raster

public java.awt.Point world2raster(double world_x,
                                   double world_y)
Transforms the coordinates of a point given in client space (WC) to device-dependent (raster) coordinates. The canvas device space has its origin in the upper-left corner of the canvas. The CanvasWC object contains an AffineTransform object that defines how to convert coordinates from client space (world coordinates) to device-dependent (raster) coordinates in device space. Note that, to avoid creating new point objects, the method returns a reference to a private object and not a copy of a new point. If needed, clients must clone the returned object.

Parameters:
world_x - is the x coordinate of given point in client space
world_y - is the y coordinate of given point in client space
Returns:
point in raster (device) coordinates
See Also:
setWorld(double, double, double, double), raster2world(int, int)

raster2world

public java.awt.geom.Point2D.Double raster2world(int raster_x,
                                                 int raster_y)
Transforms the coordinates of a point given in device space (raster) to client space (world coordinates). The canvas device space has its origin in the upper-left corner of the canvas. The CanvasWC object contains an AffineTransform object that defines how to convert coordinates from device-dependent (raster) coordinates in device space to client space (world coordinates). Note that, to avoid creating new point objects, the method returns a reference to a private object and not a copy of a new point. If needed, clients must clone the returned object.

Parameters:
raster_x - is the x coordinate of the given point in device space
raster_y - is the y coordinate of the given point in device space
Returns:
point in world (client) coordinates
See Also:
setWorld(double, double, double, double), world2raster(double, double)

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Handles the event of the user pressing down the mouse button. Calls client method mousePressedWC

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - is mouse event object
See Also:
mousePressedWC(java.awt.event.MouseEvent, java.awt.geom.Point2D.Double)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Handles the event of the user dragging the mouse while holding down the mouse button. Calls client method mouseDraggedWC

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - is mouse event object
See Also:
mouseDraggedWC(java.awt.event.MouseEvent, java.awt.geom.Point2D.Double)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Handles the event of the user releasing the mouse button. Calls client method mouseReleasedWC

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - is mouse event object
See Also:
mouseReleasedWC(java.awt.event.MouseEvent, java.awt.geom.Point2D.Double)

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Dummy method for the event of mouse motion in canvas.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - is mouse event object

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Dummy method for the event of mouse clicked in canvas.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - is mouse event object

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Dummy method for the event of mouse exited from canvas.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - is mouse event object

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Dummy method for the event of mouse entered in canvas.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - is mouse event object

paintComponent

public void paintComponent(java.awt.Graphics g)
Update method of canvas.
In case the sizes of the canvas have changed, it (re)builds a BufferedImage object (offscreen image) to implement double buffering rendering. In this case, the world coordinate window defined by the client (if defined) is adjusted according to the new canvas sizes.
Then, it clears the canvas using the currently defined background color and calls the client's redraw method, passing the Graphics2D graphics context object of the offscreen image, so that the client may display on it.
Finally, it fills the canvas with the image that was displayed by the canvas on the offscreen image.

Parameters:
g - is the target graphics context
See Also:
setWorld(double, double, double, double), redraw(java.awt.Graphics2D)

setFont

public void setFont(java.awt.Font fnt)
Set font to be used to display texts.


setTextOpacity

public void setTextOpacity(int text_opacity)
Set opacity to be used to display texts.


setTextAlignment

public void setTextAlignment(int text_alignment)
Set alignment to be used to display texts.


drawString

public void drawString(java.lang.String text,
                       double x,
                       double y)
Draw a given string on a given position. (Parts of this method were stolen from TWFText.java)


e-Mohr v. 1.00