Class CircuitDiagram

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--CircuitDiagram

class CircuitDiagram
extends java.awt.Frame
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.FocusListener

This class implements the window for each circuit diagram that's open. It contains the frame, menu, and workspace, logic and fileio objects that make up the circuit diagram. All of the mouse event handling is done here, passing calls to the workspace, logic and fileio objects as necessary.

See Also:
Serialized Form

Inner Class Summary
(package private)  class CircuitDiagram.CDCloser
          This class handles closing the CircuitDiagram window when it's done manually, instead of through a menu command
(package private)  class CircuitDiagram.MenuListener
          This class handles the actions sent to the various CircuitDiagram menu commands.
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
(package private)  FileIO fileio
          The associated fileio
(package private)  java.lang.String filename
          This CircuitDiagram's default title
(package private)  int id
          This CircuitDiagram's id
(package private)  Logic logic
          The associated logic
(package private)  GateBuilder parent
          The parent GateBuilder to make global calls on
(package private)  Workspace workspace
          The associated workspace
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, icon, ICONIFIED, mbManagement, menuBar, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, ownedWindows, resizable, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, title, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Window
inputContext, OPENED, ownedWindowList, state, warningString, windowListener
 
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) CircuitDiagram(GateBuilder _parent, int _id, java.awt.Point _offset, boolean _show)
          This constructor creates a circuit diagram window and all the associated objects - workspace, logic, and fileio.
 
Method Summary
 java.lang.Object addObject(int type, int x, int y, Macro macro, int attr)
          Top-level call for adding an object to the CircuitDiagram.
 void calculate()
          Executed when calculate is selected from the macros menu
 void close()
          Executed when close is selected from the file menu
 boolean connectObjects(java.lang.Object target1, java.lang.Object target2, boolean force)
          Top-level call for connecting two objects in the CircuitDiagram
 boolean disconnectObjects(java.lang.Object target1, java.lang.Object target2)
          Top-level call for disconnecting two objects in the CircuitDiagram
 void exportMacro()
          Executed when exportmacro is selected from the macros menu
 void focusGained(java.awt.event.FocusEvent e)
          Executed on focusGained.
 void focusLost(java.awt.event.FocusEvent e)
          Executed on focusLost.
 void generalHelp()
          Executed when General is selected from the help menu
 java.util.Vector getMacros()
          Returns the macro vector
 java.awt.Dimension getMaximumSize()
          Returns the max size of the CircuitDiagram.
 int getNextGateID()
          An accessor for the nextGateID variable
 java.util.Vector getObjects()
          Returns the object vector
 java.awt.Dimension getPreferredSize()
          Returns the preferred size of the CircuitDiagram.
 void importMacro()
          Executed when importmacro is selected from the macros menu
 void importMacro(java.lang.String loaded)
          Executed when a builtin macro is loaded.
 void incNextGateID()
          An accessor which increments nextGateID
 void macrosHelp()
          Executed when Macros is selected from the help menu
 void mouseClicked(java.awt.event.MouseEvent e)
          Executed on a mouseClick.
 void mouseDragged(java.awt.event.MouseEvent e)
          Executed on a mouseDragged.
 void mouseEntered(java.awt.event.MouseEvent e)
          Executed on a mouseEntered.
 void mouseExited(java.awt.event.MouseEvent e)
          Executed on a mouseExited.
 void mouseMoved(java.awt.event.MouseEvent e)
          Executed on a mouseMoved.
 void mousePressed(java.awt.event.MouseEvent e)
          Executed on a mousePressed.
 void mouseReleased(java.awt.event.MouseEvent e)
          Executed on a mouseReleased.
 void moveObject(java.lang.Object target, int x, int y)
          Top-level call for moving an object in the Workspace
 void newFile()
          Executed when new is selected from the file menu
 void open()
          Executed when open is selected from the file menu
 void openUrl()
          Executed when open url is selected from the file menu
 void print()
          Executed when print is selected from the file menu
 void quit()
          Executed when quit is selected from the file menu
 void removeObject(java.lang.Object target)
          Top-level call for removing an object from the CircuitDiagram
 void repaint()
          Calls update as soon as possible.
 void save()
          Executed when save is selected from the file menu
 void saveAs()
          Executed when saveas is selected from the file menu
 void saveChanges()
          Helper function that only saves if changes have been made
 void setFilename(java.lang.String _filename)
          Sets the filename for the current circuit diagram, and makes the title bar read the new name.
 void toggleInput(java.lang.Object target)
          Top-level call for toggling the value of an input object
 void toolsHelp()
          Executed when Tools is selected from the help menu
 void updateMacros(java.lang.String path)
          Takes a path to a macro file and puts it in the macros menu if it's not already there, and adds it to the macro cache
 
Methods inherited from class java.awt.Frame
, addNotify, addToFrameList, constructComponentName, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, isResizable, paramString, postProcessKeyEvent, remove, removeFromFrameList, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle
 
Methods inherited from class java.awt.Window
addOwnedWindow, addWindowListener, applyResourceBundle, applyResourceBundle, connectOwnedWindow, dispatchEventImpl, dispose, eventEnabled, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isActive, isShowing, nextFocus, pack, postEvent, postWindowEvent, preProcessKeyEvent, processEvent, processWindowEvent, removeOwnedWindow, removeWindowListener, setCursor, setFocusOwner, show, toBack, toFront, transferFocus
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyOrientation, countComponents, deliverEvent, dispatchEventToSelf, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getCursorTarget, getInsets, getLayout, getMinimumSize, getMouseEventTarget, getWindow, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, paint, paintComponents, postsOldMouseEvents, preferredSize, print, printComponents, processContainerEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFont, setLayout, update, 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, getInputMethodRequests, getIntrinsicCursor, getLocation, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkitImpl, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

GateBuilder parent
The parent GateBuilder to make global calls on

id

int id
This CircuitDiagram's id

workspace

Workspace workspace
The associated workspace

logic

Logic logic
The associated logic

fileio

FileIO fileio
The associated fileio

filename

java.lang.String filename
This CircuitDiagram's default title
Constructor Detail

CircuitDiagram

CircuitDiagram(GateBuilder _parent,
               int _id,
               java.awt.Point _offset,
               boolean _show)
This constructor creates a circuit diagram window and all the associated objects - workspace, logic, and fileio. It initializes everything and sets up to receive input events.
Parameters:
_parent - the GateBuilder that created this CircuitDiagram
_id - the CircuitDiagram's id number
_offset - the window location from the upperleft corner
_show - true to display the window, false to not.
Method Detail

updateMacros

public void updateMacros(java.lang.String path)
Takes a path to a macro file and puts it in the macros menu if it's not already there, and adds it to the macro cache
Parameters:
path - the path to the macro to add

repaint

public void repaint()
Calls update as soon as possible. Overloaded from Frame's version to also call repaint on the Workspace within the CircuitDiagram.
Overrides:
repaint in class java.awt.Component

getMaximumSize

public java.awt.Dimension getMaximumSize()
Returns the max size of the CircuitDiagram.
Overrides:
getMaximumSize in class java.awt.Container

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size of the CircuitDiagram.
Overrides:
getPreferredSize in class java.awt.Container

getNextGateID

public int getNextGateID()
An accessor for the nextGateID variable

incNextGateID

public void incNextGateID()
An accessor which increments nextGateID

getObjects

public java.util.Vector getObjects()
Returns the object vector

getMacros

public java.util.Vector getMacros()
Returns the macro vector

setFilename

public void setFilename(java.lang.String _filename)
Sets the filename for the current circuit diagram, and makes the title bar read the new name.
Parameters:
_filename - the new filename

addObject

public java.lang.Object addObject(int type,
                                  int x,
                                  int y,
                                  Macro macro,
                                  int attr)
Top-level call for adding an object to the CircuitDiagram.
Parameters:
type - an integer type from the Tool class
x - the x coordinate of the new object
y - the y coordinate of the new object
macroGroup - the macro to associate the new object with
attr - optional attribute int

removeObject

public void removeObject(java.lang.Object target)
Top-level call for removing an object from the CircuitDiagram
Parameters:
target - the object to remove

connectObjects

public boolean connectObjects(java.lang.Object target1,
                              java.lang.Object target2,
                              boolean force)
Top-level call for connecting two objects in the CircuitDiagram
Parameters:
target1 - the source object
target2 - the destination object
force - force making the connection or not

disconnectObjects

public boolean disconnectObjects(java.lang.Object target1,
                                 java.lang.Object target2)
Top-level call for disconnecting two objects in the CircuitDiagram
Parameters:
target1 - the source object
target2 - the destination object

moveObject

public void moveObject(java.lang.Object target,
                       int x,
                       int y)
Top-level call for moving an object in the Workspace
Parameters:
target - the object to move
x - the destination x coordinate
y - the destination y coordinate

toggleInput

public void toggleInput(java.lang.Object target)
Top-level call for toggling the value of an input object
Parameters:
target - the input object

newFile

public void newFile()
Executed when new is selected from the file menu

open

public void open()
Executed when open is selected from the file menu

openUrl

public void openUrl()
Executed when open url is selected from the file menu

close

public void close()
Executed when close is selected from the file menu

saveChanges

public void saveChanges()
Helper function that only saves if changes have been made

save

public void save()
Executed when save is selected from the file menu

saveAs

public void saveAs()
Executed when saveas is selected from the file menu

print

public void print()
Executed when print is selected from the file menu

quit

public void quit()
Executed when quit is selected from the file menu

importMacro

public void importMacro()
Executed when importmacro is selected from the macros menu

importMacro

public void importMacro(java.lang.String loaded)
Executed when a builtin macro is loaded.
Parameters:
loaded - the name of the cached macro to load

exportMacro

public void exportMacro()
Executed when exportmacro is selected from the macros menu

calculate

public void calculate()
Executed when calculate is selected from the macros menu

generalHelp

public void generalHelp()
Executed when General is selected from the help menu

toolsHelp

public void toolsHelp()
Executed when Tools is selected from the help menu

macrosHelp

public void macrosHelp()
Executed when Macros is selected from the help menu

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Executed on a mouseClick. Toggles input gate
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Executed on a mouseEntered. Does nothing
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Executed on a mouseExited. Does nothing
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Executed on a mousePressed. Starts connectin or moving objects, or adds object
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Executed on a mouseReleased. Finishes connecting gates, resets status
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the mouseEvent

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Executed on a mouseDragged. Moves objects or otherwise does nothing
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouseEvent

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Executed on a mouseMoved. Does nothing
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouseEvent

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Executed on focusGained. Registers the circuitdiagram as the current window with gatebuilder
Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
e - the focusEvent

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Executed on focusLost. Does nothing.
Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
e - the focusEvent