Class DrawPadView

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--DrawPadView
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class DrawPadView
extends java.applet.Applet
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener

CLASS: DrawPadView
PURPOSE: This class handle all the GUI action and this is also the main class for the applet
IMPORT: java.awt.Color, java.applet.Applet, java.awt.Graphics, java.awt.Image, java.awt.event.MouseEvent, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener, java.awt.event.KeyEvent, Ellipse, Rectangle, Line, Polygon, DrawableShape, DrawPadDoc, Point
EXPORT: New Class|DrawPadView
New Method| init, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, paint, setSelectedColor, update, drawBorder, drawColorBar, drawCurrentColor, drawOptionBar

See Also:
Serialized Form

Inner classes inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
private  java.awt.Graphics backBufferGraphics
          Graphic context associate with the back image buffer
private  java.awt.Image backBufferImage
          Back Image buffer for drawing
private  boolean bChangingColor
          A flag to indicate whether we are changing the shape's color
private  boolean bDrawingShape
          A flag to indicate whether a shape is being draw
private  int BORDER_WIDTH
          Constant for the border width
private  boolean bSelectedPointBox
          A flag to indicate whether a point box for a shape has been selected
private  boolean bSelectedShape
          A flag to indicate whether a shape is selected in the list
private  java.awt.Color[] colorList
          An Array of color that is available
private  DrawableShape currentShape
          Current shape object for before adding to DrawPadDoc
private  byte DOUBLE_IMAGE_SIZE
          Constant for 2 * image size in pixel.
private  int drawHeight
          Drawing area height.
private  DrawPadDoc drawPadDoc
          Keep track of all the shape and for the editing methods
private  int drawWidth
          Drawing area width.
private  Point endPoint
          keep track of the last point
private  byte HALF_IMAGE_SIZE
          Constant for half image size in pixel.
private  byte IMAGE_DOWN
          Constant to indicate the image is in down-state
private  byte IMAGE_SIZE
          Constant for the image size in pixel.
private  byte IMAGE_UP
          Constant to indicate the image is in up-state
private  java.lang.String imageDirectory
          Constant for the path that the image files is in
private  java.lang.String[][] imageNames
          Name of the option image files (upstate and downstate)
private  byte OPT_ELLIPSE
          Constant for Ellipseect Option
private  byte OPT_FILLED_ELLIPSE
          Constant for Filled Ellipse Option
private  byte OPT_FILLED_POLYGON
          Constant for Filled Polygon Option
private  byte OPT_FILLED_RECTANGLE
          Constant for Filled Rectangle Option
private  byte OPT_LINE
          Constant for Line Option
private  byte OPT_POLYGON
          Constant for Polygon Option
private  byte OPT_RECTANGLE
          Constant for Rectangle Option
private  byte OPT_SELECT
          Constant for Select Option
private  java.awt.Image[][] optionImages
          array to contain the images for options
private  int selectedColor
          Color that has been selected
private  int selectedOption
          Option that has been selected
 
Fields inherited from class java.applet.Applet
accessibleContext, serialVersionUID, stub
 
Fields inherited from class java.awt.Panel
base, nameCounter
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawPadView()
           
 
Method Summary
private  void drawBorder(java.awt.Graphics g)
          
PRE: Valid Graphic object.
POST: Draw the border for the drawing area
private  void drawColorBar(java.awt.Graphics g)
          
PRE: Valid Graphic object.
POST: Draw the color bar to the given Graphics object
private  void drawCurrentColor(java.awt.Graphics g)
          
PRE: Valid Graphic object.
POST: Draw the color that we are using right now
private  void drawOptionBar(java.awt.Graphics g)
          
PRE: Valid Graphic object.
POST: Draw the option bar to the given Graphics object
 void init()
          
PRE: None
POST: Initialize all the variables and GUI for the applet
 void keyPressed(java.awt.event.KeyEvent e)
          
PRE: A valid KeyEvent Object
POST: Perform editing functionality.
 void keyReleased(java.awt.event.KeyEvent e)
          
PRE: A valid KeyEvent Object
POST: This method was override from the interface KeyListener.
 void keyTyped(java.awt.event.KeyEvent e)
          
PRE: A valid KeyEvent Object
POST: This method was override from the interface KeyListener.
 void mouseClicked(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent Object
POST: This method was override from the interface MouseListener.
 void mouseDragged(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent Object
POST: Show rubber band effect and perform editing functionality.
 void mouseEntered(java.awt.event.MouseEvent e)
          
PRE: A valid KeyEvent Object
POST: This method was override from the interface MouseMotionListener.
 void mouseExited(java.awt.event.MouseEvent e)
          
PRE: A valid KeyEvent Object
POST: This method was override from the interface MouseMotionListener.
 void mouseMoved(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent Object
POST: For rubber band effect when drawing object.
 void mousePressed(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent Object
POST: Set all the flags needed.
 void mouseReleased(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent Object
POST: Set all the flags needed.
 void paint(java.awt.Graphics g)
          
PRE: A valid Graphics Object
POST: Will have drawPadDoc draw all its shape and also draw the current shape if we are doing Add shape.
 void setSelectedColor(java.awt.Color c)
          
PRE: A valid Color Object
POST: set and update the color bar to the input color
 void update(java.awt.Graphics g)
          
PRE: A valid Graphics Object
POST: Will have drawPadDoc draw all its shape and also draw the current shape if we are doing Add shape.
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
, addNotify, constructComponentName
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, readObject, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusOwner, setFont, setLayout, transferFocus, validate, validateTree, writeObject
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, resetGC, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

endPoint

private Point endPoint
keep track of the last point

drawPadDoc

private DrawPadDoc drawPadDoc
Keep track of all the shape and for the editing methods

currentShape

private DrawableShape currentShape
Current shape object for before adding to DrawPadDoc

bSelectedShape

private boolean bSelectedShape
A flag to indicate whether a shape is selected in the list

bDrawingShape

private boolean bDrawingShape
A flag to indicate whether a shape is being draw

bSelectedPointBox

private boolean bSelectedPointBox
A flag to indicate whether a point box for a shape has been selected

bChangingColor

private boolean bChangingColor
A flag to indicate whether we are changing the shape's color

imageNames

private java.lang.String[][] imageNames
Name of the option image files (upstate and downstate)

optionImages

private java.awt.Image[][] optionImages
array to contain the images for options

IMAGE_UP

private final byte IMAGE_UP
Constant to indicate the image is in up-state

IMAGE_DOWN

private final byte IMAGE_DOWN
Constant to indicate the image is in down-state

IMAGE_SIZE

private final byte IMAGE_SIZE
Constant for the image size in pixel. Image size is alway in Square

HALF_IMAGE_SIZE

private final byte HALF_IMAGE_SIZE
Constant for half image size in pixel. For faster calculation

DOUBLE_IMAGE_SIZE

private final byte DOUBLE_IMAGE_SIZE
Constant for 2 * image size in pixel. For faster calculation

OPT_SELECT

private final byte OPT_SELECT
Constant for Select Option

OPT_LINE

private final byte OPT_LINE
Constant for Line Option

OPT_RECTANGLE

private final byte OPT_RECTANGLE
Constant for Rectangle Option

OPT_FILLED_RECTANGLE

private final byte OPT_FILLED_RECTANGLE
Constant for Filled Rectangle Option

OPT_ELLIPSE

private final byte OPT_ELLIPSE
Constant for Ellipseect Option

OPT_FILLED_ELLIPSE

private final byte OPT_FILLED_ELLIPSE
Constant for Filled Ellipse Option

OPT_POLYGON

private final byte OPT_POLYGON
Constant for Polygon Option

OPT_FILLED_POLYGON

private final byte OPT_FILLED_POLYGON
Constant for Filled Polygon Option

imageDirectory

private final java.lang.String imageDirectory
Constant for the path that the image files is in

BORDER_WIDTH

private final int BORDER_WIDTH
Constant for the border width

selectedOption

private int selectedOption
Option that has been selected

selectedColor

private int selectedColor
Color that has been selected

backBufferImage

private java.awt.Image backBufferImage
Back Image buffer for drawing

backBufferGraphics

private java.awt.Graphics backBufferGraphics
Graphic context associate with the back image buffer

drawWidth

private int drawWidth
Drawing area width. Default is 500, can be pass in from the html

drawHeight

private int drawHeight
Drawing area height. Default is 400, can be pass in from the html

colorList

private final java.awt.Color[] colorList
An Array of color that is available
Constructor Detail

DrawPadView

public DrawPadView()
Method Detail

init

public void init()

PRE: None
POST: Initialize all the variables and GUI for the applet
Overrides:
init in class java.applet.Applet

drawCurrentColor

private void drawCurrentColor(java.awt.Graphics g)

PRE: Valid Graphic object.
POST: Draw the color that we are using right now

drawColorBar

private void drawColorBar(java.awt.Graphics g)

PRE: Valid Graphic object.
POST: Draw the color bar to the given Graphics object

drawBorder

private void drawBorder(java.awt.Graphics g)

PRE: Valid Graphic object.
POST: Draw the border for the drawing area

drawOptionBar

private void drawOptionBar(java.awt.Graphics g)

PRE: Valid Graphic object.
POST: Draw the option bar to the given Graphics object

paint

public void paint(java.awt.Graphics g)

PRE: A valid Graphics Object
POST: Will have drawPadDoc draw all its shape and also draw the current shape if we are doing Add shape. Also will draw color bar and option bar
Overrides:
paint in class java.awt.Container

update

public void update(java.awt.Graphics g)

PRE: A valid Graphics Object
POST: Will have drawPadDoc draw all its shape and also draw the current shape if we are doing Add shape. Also will draw color bar and option bar. This method is override for double buffering technique.
Overrides:
update in class java.awt.Container

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent Object
POST: Set all the flags needed. Also add shape to the list in some cases. This method was override from the interface MouseListener.
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent Object
POST: Set all the flags needed. Also add shape to the list in some cases. This will also keep track of last mouse point clicked. Perform actions result from clicking at the option/color bar. Also perform editing methods. This method was override from the interface MouseListener.
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseMoved

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

PRE: A valid MouseEvent Object
POST: For rubber band effect when drawing object. This method was override from the interface MouseMotionListener.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent Object
POST: Show rubber band effect and perform editing functionality. This method was override from the interface MouseMotionListener.
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)

PRE: A valid KeyEvent Object
POST: Perform editing functionality. This method was override from the interface KeyListener.
Specified by:
keyPressed in interface java.awt.event.KeyListener

setSelectedColor

public void setSelectedColor(java.awt.Color c)

PRE: A valid Color Object
POST: set and update the color bar to the input color

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)

PRE: A valid KeyEvent Object
POST: This method was override from the interface KeyListener.
Specified by:
keyTyped in interface java.awt.event.KeyListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)

PRE: A valid KeyEvent Object
POST: This method was override from the interface MouseMotionListener.
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseClicked

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

PRE: A valid MouseEvent Object
POST: This method was override from the interface MouseListener.
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)

PRE: A valid KeyEvent Object
POST: This method was override from the interface MouseMotionListener.
Specified by:
mouseExited in interface java.awt.event.MouseListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)

PRE: A valid KeyEvent Object
POST: This method was override from the interface KeyListener.
Specified by:
keyReleased in interface java.awt.event.KeyListener