GridView
Class DrawingCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by GridView.DrawingCanvas
All Implemented Interfaces:
DrawingCanvasInterface, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.MouseInputListener

public class DrawingCanvas
extends javax.swing.JPanel
implements javax.swing.event.MouseInputListener, DrawingCanvasInterface

Class for drawing stuff onto a canvas (widget). This class is responsible for drawing stuff onto the screen. It uses mouse motion for several kinds of visual input, eg angle of viewing etc. The drawing area represented by this class is shown within the main viewer window.

This class draws over a buffered image, and just copies over the buffer to the screen at the time of rendering. This buffering makes the rendering more efficient (no redraw necessary for actions that do not change the picture). For platforms that support hardware acceleration, image rendering makes use of that feature.

Since:
1.0
See Also:
DrawingCanvasInterface, Viewer, Serialized Form

Nested Class Summary
static class DrawingCanvas.DrawType
          WIREFRAME: wireframe model SURFACE: surface model with edges SURFACE_ONLY: Only surface, no edges CRINKLE_CUT: Cut the object.
static class DrawingCanvas.ViewType
           
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  boolean bDrawingCutLine
           
private  boolean bDrawingROIRect
           
private  boolean bDrawingRuler
           
private  float[] dPlane
          dPlane[0], dPlane[1], dPlane[2], dPlane[4] are used to define the cut plane as follows: dPlane[0]*x + dPlane[1]*y + dPlane[2]*z + dPlane[3] = 0;.
static int INSETS
          Insets for actual drawing area within the canvas.
private  float[] mAxisCosine
           
private  java.awt.Color mBgColor
          Background color.
private  java.awt.image.BufferedImage mBufImg
          Buffered image
private  Controller mController
           
private  float[] mCuttingPlane
          Cutting plane.
(package private)  DrawingCanvas.DrawType mDrawType
           
protected  int mMouseX
          X coordinate (in screen coordinates of mouse pressed event.
private  int mMouseY
          Y coordinate (in screen coordinates of mouse pressed event.
private  int mNewMouseX
           
private  int mNewMouseY
           
private  OutputPanel mOutPanel
          Output panel for logging messages / errors.
private  java.awt.Color mRulerColor
          Ruler color.
private  Viewer mViewer
          Instance of the containing viewer.
(package private)  DrawingCanvas.ViewType mViewType
           
 
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
DrawingCanvas(Viewer vw, int width, int height, Controller cont)
          Class constructor.
 
Method Summary
private  void Draw(java.awt.Graphics g)
          Draw the scene on provided graphics instance.
private  void DrawAxonometricView(java.awt.Graphics g)
          Draw Axonometric view taking into account the current parameter settings.
private  void DrawCameraImage(DrawingCanvas canvas, java.awt.Graphics g, float[] camera_coor, float[] center_proj, boolean onlySurface, boolean onlyWireframe)
           
private  void DrawOnePtPerspectiveView(java.awt.Graphics g)
           
private  void DrawPerspectiveView(java.awt.Graphics g, float[] camera_coor, float[] center_proj)
          Modifies the transformation matrix to account for one point perspective projection.
private  void DrawROIRectangle(java.awt.Graphics g)
          Draw a rectangular region of interest (ROI) on supplied graphics instance.
private  void DrawRuler(java.awt.Graphics g)
          Draw the final ruler with measurement and arrowhead.
private  void DrawRulerOutline(java.awt.Graphics g)
          Draw the ruler outline over supplied graphics instance.
private  void DrawThreePtPerspectiveView(java.awt.Graphics g)
           
private  void DrawTwoPtPerspectiveView(java.awt.Graphics g)
           
 java.awt.Color GetBackgroundColor()
          Find the current background color.
 Controller GetController()
           
 float[] GetCutPlane()
           
 DrawingCanvas.DrawType GetDrawType()
           
 java.awt.Graphics GetImageGraphics()
          Get the Graphics2d instance associated with buffered image.
 int GetMinOfWidthHeight()
          Get minimum of screen width and height.
 int GetMouseX()
           
 int GetMouseY()
           
 int GetNewMouseX()
           
 int GetNewMouseY()
           
 java.awt.Dimension getPreferredSize()
           
 java.awt.Color GetRulerColor()
           
 Viewer GetViewer()
           
 DrawingCanvas.ViewType GetViewType()
           
 boolean IsSpecularShading()
           
 float LightIntensity()
           
 void mouseClicked(java.awt.event.MouseEvent e)
          Handler for mouseClicked event..
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          Handler for mouseMoved event.
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
protected  void paintComponent(java.awt.Graphics g)
          Method called by Java for repainting.
 void RegenerateImage()
          Paint the buffered image again, after possibly resizing it.
private  void ResizeBufferedImage()
          Resize the buffered image to drawing canvas size.
 void SaveScreenShot(java.io.File file, java.lang.String extension)
           
 void SetBackgroundColor(java.awt.Color newColor)
          Set the color to specified color.
 void SetCuttingPlane(float[] plane)
          Set the cutting plane.
 void SetDrawType(DrawingCanvas.DrawType dtyp)
          Sets the type of drawing (e.g wireframe, surface, crinkle cut).
Redraws the image if new selection differs from the old one.
 void SetOutputPanel(OutputPanel outPanel)
          Record the output panel instance, so that error info etc can be dumped onto the panel.
 void SetRulerColor(java.awt.Color col)
           
 void SetViewType(DrawingCanvas.ViewType vtyp)
          Sets the type of view.
 int SpecularExponent()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, 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
 
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, firePropertyChange, getBackground, 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, 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

INSETS

public static final int INSETS
Insets for actual drawing area within the canvas.

See Also:
Constant Field Values

mViewer

private Viewer mViewer
Instance of the containing viewer.


mController

private Controller mController

mOutPanel

private OutputPanel mOutPanel
Output panel for logging messages / errors.


mViewType

DrawingCanvas.ViewType mViewType

mDrawType

DrawingCanvas.DrawType mDrawType

dPlane

private float[] dPlane
dPlane[0], dPlane[1], dPlane[2], dPlane[4] are used to define the cut plane as follows: dPlane[0]*x + dPlane[1]*y + dPlane[2]*z + dPlane[3] = 0;.


mMouseX

protected int mMouseX
X coordinate (in screen coordinates of mouse pressed event.


mMouseY

private int mMouseY
Y coordinate (in screen coordinates of mouse pressed event.


mNewMouseX

private int mNewMouseX

mNewMouseY

private int mNewMouseY

mBufImg

private java.awt.image.BufferedImage mBufImg
Buffered image


mBgColor

private java.awt.Color mBgColor
Background color.


mRulerColor

private java.awt.Color mRulerColor
Ruler color.


mCuttingPlane

private float[] mCuttingPlane
Cutting plane. An array with four elements defining the plane as: mCuttingPlane[0]*X + mCuttingPlane[1]*Y + mCuttingPlane[2]*Z + mCuttingPlane[3] = 0


mAxisCosine

private float[] mAxisCosine

bDrawingROIRect

private boolean bDrawingROIRect

bDrawingRuler

private boolean bDrawingRuler

bDrawingCutLine

private boolean bDrawingCutLine
Constructor Detail

DrawingCanvas

public DrawingCanvas(Viewer vw,
                     int width,
                     int height,
                     Controller cont)
Class constructor.

Parameters:
vw - Viewer instance that displays the drawing canvas.
width - Canvas width (in pixels). This is the initial width, it can change later in response to resizing window, etc.
height - Canvas height (in pixels).
cont - Controller instance.
Method Detail

LightIntensity

public float LightIntensity()
Specified by:
LightIntensity in interface DrawingCanvasInterface

SpecularExponent

public int SpecularExponent()
Specified by:
SpecularExponent in interface DrawingCanvasInterface

IsSpecularShading

public boolean IsSpecularShading()
Specified by:
IsSpecularShading in interface DrawingCanvasInterface

SetBackgroundColor

public void SetBackgroundColor(java.awt.Color newColor)
Set the color to specified color. Sends a repaint request if the new background color differs from the last background color.

Parameters:
newColor - New background color.
See Also:
mBgColor

GetBackgroundColor

public java.awt.Color GetBackgroundColor()
Find the current background color.

Returns:
Current background color.

SetRulerColor

public void SetRulerColor(java.awt.Color col)

GetRulerColor

public java.awt.Color GetRulerColor()

SetOutputPanel

public void SetOutputPanel(OutputPanel outPanel)
Record the output panel instance, so that error info etc can be dumped onto the panel.

Parameters:
outPanel - Instance of OutputPanel used on the main viewer.
See Also:
OutputPanel

DrawROIRectangle

private void DrawROIRectangle(java.awt.Graphics g)
Draw a rectangular region of interest (ROI) on supplied graphics instance.

Parameters:
g - Graphics instance.

DrawRulerOutline

private void DrawRulerOutline(java.awt.Graphics g)
Draw the ruler outline over supplied graphics instance.

Parameters:
g - Graphics instance

DrawRuler

private void DrawRuler(java.awt.Graphics g)
Draw the final ruler with measurement and arrowhead.

Parameters:
g - Graphics instance

paintComponent

protected void paintComponent(java.awt.Graphics g)
Method called by Java for repainting. This method should take the current view settings and call the appropriate methods for doing the drawing.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - Graphics instance (passed by Java framework).

SetCuttingPlane

public void SetCuttingPlane(float[] plane)
Set the cutting plane.

Parameters:
plane - An array with four elements defining the plane as: plane[0]*X + plane[1]*Y + plane[2]*Z + plane[3] = 0

SetViewType

public void SetViewType(DrawingCanvas.ViewType vtyp)
Sets the type of view. Redraws the image if new selection differs from the old one.

Parameters:
vtyp - View type (Select from one of perspective views or axonometric view, for the perspective view option, there are one-point, two-point and three-point based perspective options).
See Also:
DrawingCanvas.ViewType

GetViewType

public DrawingCanvas.ViewType GetViewType()

SetDrawType

public void SetDrawType(DrawingCanvas.DrawType dtyp)
Sets the type of drawing (e.g wireframe, surface, crinkle cut).
Redraws the image if new selection differs from the old one.

Parameters:
dtyp - Draw type (Select from one of wireframe, surface drawing, or crinkle cut).
See Also:
DrawingCanvas.DrawType

GetDrawType

public DrawingCanvas.DrawType GetDrawType()

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Handler for mouseClicked event..

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent corresponding to mouse movement

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Handler for mouseMoved event.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent corresponding to mouse movement

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

GetMinOfWidthHeight

public int GetMinOfWidthHeight()
Get minimum of screen width and height. This function is used in computing the scaling factors for zooming onto a newly loaded object (to make the new object fit smugly on the screen).


getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

ResizeBufferedImage

private void ResizeBufferedImage()
Resize the buffered image to drawing canvas size.


GetImageGraphics

public java.awt.Graphics GetImageGraphics()
Get the Graphics2d instance associated with buffered image.

Returns:
Graphics instance

RegenerateImage

public void RegenerateImage()
Paint the buffered image again, after possibly resizing it.


Draw

private void Draw(java.awt.Graphics g)
Draw the scene on provided graphics instance.

Parameters:
g - Graphics instance where painting needs to be done.

DrawOnePtPerspectiveView

private void DrawOnePtPerspectiveView(java.awt.Graphics g)

DrawTwoPtPerspectiveView

private void DrawTwoPtPerspectiveView(java.awt.Graphics g)

DrawThreePtPerspectiveView

private void DrawThreePtPerspectiveView(java.awt.Graphics g)

DrawAxonometricView

private void DrawAxonometricView(java.awt.Graphics g)
Draw Axonometric view taking into account the current parameter settings.

Parameters:
g - Graphics instance.

DrawPerspectiveView

private void DrawPerspectiveView(java.awt.Graphics g,
                                 float[] camera_coor,
                                 float[] center_proj)
Modifies the transformation matrix to account for one point perspective projection.

Parameters:
g - Grpahics instance.
See Also:
GeomDataManager.mTransMatrix

DrawCameraImage

private void DrawCameraImage(DrawingCanvas canvas,
                             java.awt.Graphics g,
                             float[] camera_coor,
                             float[] center_proj,
                             boolean onlySurface,
                             boolean onlyWireframe)

SaveScreenShot

public void SaveScreenShot(java.io.File file,
                           java.lang.String extension)

GetViewer

public Viewer GetViewer()

GetController

public Controller GetController()

GetCutPlane

public float[] GetCutPlane()

GetMouseX

public int GetMouseX()

GetMouseY

public int GetMouseY()

GetNewMouseX

public int GetNewMouseX()

GetNewMouseY

public int GetNewMouseY()