Class Workspace

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--Workspace

class Workspace
extends java.awt.Panel

The workspace class is the panel where all of the gates are drawn, this is basically what the user sees, adding gates, moving gates etc.

See Also:
Serialized Form

Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
(package private)  java.awt.Image buffer
           
(package private)  boolean calculate
           
(package private)  java.awt.Graphics g
           
(package private)  java.util.Vector gates
           
(package private)  int height
           
(package private)  java.util.Vector macros
           
(package private)  boolean stateChange
           
(package private)  int width
           
 
Fields inherited from class java.awt.Container
component, containerListener, layoutMgr, ncomponents
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
(package private) Workspace(int _width, int _height)
          Workspace constructor - calls the awt.Panel constructor, and sets the szie of the workspace
 
Method Summary
 java.lang.Object addObject(int id, int tool, int x, int y, java.lang.Object macroGroup_, int attr)
          Adds an object to the workspace (gate, input, or macro), by giving the location the object should be placed at, what kind of object it is, and that objects id
 void buffer()
          Creates the image buffer - must be called before Workspace can be used.
(package private)  void clear()
           
 boolean connect(java.lang.Object source_, java.lang.Object destination_, boolean loading)
          Connects two gates - First makes sure both objects are gates.
 boolean disconnect(java.lang.Object source_, java.lang.Object destination_)
          Takes two gates, and makes sure there is a connection between them, if so removes that connection.
(package private)  void drawCalculate()
          draws the output value of each gate
(package private)  void drawConnection(GraphicGate source, GraphicGate destination, int inputLocation)
          draws the connection between two gates
(package private)  void drawMacroBox(Macro currentMacro)
          draws a box around all the gates in a macro
 java.util.Vector getGates()
          returns the Vector used to store all gates on workspace
 java.util.Vector getMacros()
          returns the Vector used to store all macros on workspace
 java.awt.Dimension getMaximumSize()
          Gets the maximum panel height and width
 java.awt.Dimension getMinimumSize()
          Gets the minimum panel height and width
 java.lang.Object getObjectAtLoc(int x, int y)
          Takes in a location (x, y coordinates) and returns an object if an object was clicked on.
 java.awt.Dimension getPreferredSize()
          Gets the preferred panel height and width
 void moveGate(java.lang.Object target_, int x, int y)
          Moves the gate to the new location
 void moveObject(java.lang.Object target_, int x, int y)
          Check that the target is of type gate first - then move it to the new location.
 void paint(java.awt.Graphics graphics)
          Handles the buffered version of the paint method
(package private)  void redrawWorkspace()
          redraws the entire workspace, to update all graphics objects locations
 void reinitialize()
          Remove everything from the workspace
 void removeGate(java.lang.Object target_)
          Checks that target is of type gate first - then removes it, by setting pointers from other gates to it to null, and then removing it
 void removeObject(java.lang.Object target_, CircuitDiagram cd)
          Checks first to see if the object to be removed is a gate and then sees if it is in a macro or not.
(package private)  void toggleInput(java.lang.Object target_)
          Toggles the input value of an input object
 void update(java.awt.Graphics graphics)
          Handles the buffered version of the update method
 
Methods inherited from class java.awt.Panel
, addNotify, constructComponentName
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyOrientation, countComponents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getCursorTarget, getInsets, getLayout, getMouseEventTarget, getWindow, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, nextFocus, paintComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, removeNotify, setCursor, setFocusOwner, setFont, setLayout, transferFocus, updateCursor, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getIntrinsicCursor, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, 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, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, 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, wait, wait, wait
 

Field Detail

buffer

java.awt.Image buffer

g

java.awt.Graphics g

width

int width

height

int height

gates

java.util.Vector gates

macros

java.util.Vector macros

stateChange

boolean stateChange

calculate

boolean calculate
Constructor Detail

Workspace

Workspace(int _width,
          int _height)
Workspace constructor - calls the awt.Panel constructor, and sets the szie of the workspace
Parameters:
_width - width of workspace
_height - height of workspace
Method Detail

reinitialize

public void reinitialize()
Remove everything from the workspace

getObjectAtLoc

public java.lang.Object getObjectAtLoc(int x,
                                       int y)
Takes in a location (x, y coordinates) and returns an object if an object was clicked on. If gates are stacked, it returns the top (visable) gate.
Parameters:
x - x coordinate
y - y coordinate
Returns:
Object gate at the location, or null if no gate exists there

addObject

public java.lang.Object addObject(int id,
                                  int tool,
                                  int x,
                                  int y,
                                  java.lang.Object macroGroup_,
                                  int attr)
Adds an object to the workspace (gate, input, or macro), by giving the location the object should be placed at, what kind of object it is, and that objects id
Parameters:
id - object id
tool - type of gate being passed in
x - x coordinate
y - y coordinate
macroGroup - macro group being passed in
int - optional attribute int
Returns:
Object returns the object that was added

moveObject

public void moveObject(java.lang.Object target_,
                       int x,
                       int y)
Check that the target is of type gate first - then move it to the new location.
Parameters:
target_ - gate to be moved
x - x coordinate of new location
y - y coordinate of new location

moveGate

public void moveGate(java.lang.Object target_,
                     int x,
                     int y)
Moves the gate to the new location
Parameters:
target_ - gate to be moved
x - x coordinate of new location
y - y coordinate of new location

removeObject

public void removeObject(java.lang.Object target_,
                         CircuitDiagram cd)
Checks first to see if the object to be removed is a gate and then sees if it is in a macro or not. If not just call removeGate on the gate, if so then calls removeGate on every gate in the macro, and then removes the macro from the macroVector
Parameters:
target_ - gate to be removed
cd - parent CircuitDiagram

removeGate

public void removeGate(java.lang.Object target_)
Checks that target is of type gate first - then removes it, by setting pointers from other gates to it to null, and then removing it
Parameters:
target_ - gate to be removed

connect

public boolean connect(java.lang.Object source_,
                       java.lang.Object destination_,
                       boolean loading)
Connects two gates - First makes sure both objects are gates. Then connects the output of the first to the input of the second, making sure that there are available inputs on the second gate. If not, nothing happens.
Parameters:
source_ - gate giving output
destination_ - gate taking in input
loading - is this connection being made from a

disconnect

public boolean disconnect(java.lang.Object source_,
                          java.lang.Object destination_)
Takes two gates, and makes sure there is a connection between them, if so removes that connection.
Parameters:
source_ - source gate
destination_ - destination gate

toggleInput

void toggleInput(java.lang.Object target_)
Toggles the input value of an input object
Parameters:
target_ - input object to be toggled

drawCalculate

void drawCalculate()
draws the output value of each gate

getGates

public java.util.Vector getGates()
returns the Vector used to store all gates on workspace
Returns:
vector of gates on workspace

getMacros

public java.util.Vector getMacros()
returns the Vector used to store all macros on workspace
Returns:
vector of macros on workspace

drawConnection

void drawConnection(GraphicGate source,
                    GraphicGate destination,
                    int inputLocation)
draws the connection between two gates
Parameters:
source - source gate
destination - destination gate
inputLocation - location on image of input link is

drawMacroBox

void drawMacroBox(Macro currentMacro)
draws a box around all the gates in a macro

redrawWorkspace

void redrawWorkspace()
redraws the entire workspace, to update all graphics objects locations

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred panel height and width
Overrides:
getPreferredSize in class java.awt.Container
Returns:
a Dimension corresponding to the size of the buffer

getMinimumSize

public java.awt.Dimension getMinimumSize()
Gets the minimum panel height and width
Overrides:
getMinimumSize in class java.awt.Container
Returns:
a Dimension corresponding to the size of the buffer

getMaximumSize

public java.awt.Dimension getMaximumSize()
Gets the maximum panel height and width
Overrides:
getMaximumSize in class java.awt.Container
Returns:
a Dimension corresponding to the size of the buffer

buffer

public void buffer()
Creates the image buffer - must be called before Workspace can be used.

clear

void clear()

update

public void update(java.awt.Graphics graphics)
Handles the buffered version of the update method
Overrides:
update in class java.awt.Container
Parameters:
graphics - the graphics object to draw the buffer to

paint

public void paint(java.awt.Graphics graphics)
Handles the buffered version of the paint method
Overrides:
paint in class java.awt.Container
Parameters:
graphics - the graphics object to draw the buffer to