tnt.gui
Class TnTImp

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by tnt.gui.TnTFrame
                          extended by tnt.gui.TnTImp
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ListSelectionListener, javax.swing.event.MouseInputListener, javax.swing.RootPaneContainer, javax.swing.WindowConstants

 class TnTImp
extends TnTFrame
implements javax.swing.event.ListSelectionListener, javax.swing.event.MouseInputListener, java.awt.event.WindowListener

This class defines the majority of the business logic related to the TnToolkit's GUI.

Version:
1.0 - 01/2006
Author:
Steven J. Castellucci

Nested Class Summary
(package private)  class TnTImp.ColorEdit
          This class encapsulates an undoable change in color.
(package private)  class TnTImp.DeleteKeyEdit
          This class encapsulates an undoable key deletion.
(package private)  class TnTImp.EditMappingEdit
          This class encapsulates an undoable key-letter mapping.
(package private)  class TnTImp.MoveResizeKeyEdit
          This class encapsulates an undoable key relocation or resize.
(package private)  class TnTImp.NewKeyEdit
          This class encapsulates an undoable key creation.
 
Nested classes/interfaces inherited from class tnt.gui.TnTFrame
TnTFrame.InfoPanel
 
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Color color
          The current color used to display key-button outlines on the canvas.
protected  boolean fileModified
          A flag to indicate modifications since the last save.
protected  java.lang.String imageFileName
          The path to the image file used in the current workspace.
protected  KeyLetterDialog mapping
          The dialog used for key-letter mapping.
protected  ModelDefinition modelDef
          The ModelDefinition object used to store model data.
protected  javax.swing.JFileChooser openFileChooser
          The file chooser used for opening.
protected  ParametersDialog parameters
          The dialog used setting metric parameters.
protected  javax.swing.JFileChooser saveFileChooser
          The file chooser used for saving.
protected  KeyButton selected
          The currently selected key-button, null if none.
protected  javax.swing.undo.UndoManager undoManager
          The undo manager.
protected  Workspace workspace
          The Workspace object used to store state data.
protected  java.io.File workspaceFile
          A reference to the workspace file on disk.
 
Fields inherited from class tnt.gui.TnTFrame
aboutMenuItem, blackLineMenuItem, blueLineMenuItem, calculateMenuItem, canvas, canvasScrollPane, customLineMenuItem, cxValueLabel, cyValueLabel, dataModel, deleteKeyButton, dimension, editKeyButton, exitMenuItem, exportMenuItem, greenLineMenuItem, hValueLabel, magentaLineMenuItem, mouseLocation, newMenuItem, openMenuItem, parametersMenuItem, pointLocation, redLineMenuItem, redoMenuItem, saveAsMenuItem, saveMenuItem, shapesList, SPACE, STATUS_LABEL_WIDTH, statusHelp, twValueLabel, undoMenuItem, userManualMenuItem, VIEWPORT_DIMENSIONS, wValueLabel, xValueLabel, yellowLineMenuItem, yValueLabel
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TnTImp()
           
 
Method Summary
protected  void aboutAction()
          Defines action(s) to take upon selection of the "About" menu item.
protected  void addKeyAction(java.awt.geom.Rectangle2D.Double keyBounds)
          Presents the user with a key-letter mapping dialog and creates a new KeyButton object with the selected letters and the passed rectangular bounds.
protected  void calculateAction()
          Displays a message dialog if any letters are not mapped.
protected  void clearWorkspace()
          Reinitializes the workspace to a blank one.
protected  void deleteKeyAction()
          Defines action(s) to take upon pressing the delete button.
protected  void editKeyAction()
          Defines action(s) to take upon pressing the edit button.
protected  void exitAction()
          Dispatches a "window closing" event.
protected  void exportAction()
          Displays an instance of ExportDialog.
protected  void loadImage(javax.swing.ImageIcon i)
          Sets the passed image as the canvas background image.
protected  void loadWorkspace(Workspace ws)
          Notifies the user if the image file and/or word-frequency file are readable, calls clearWorkspace(), then recreates the state stored in the passed Workspace object.
 void mouseClicked(java.awt.event.MouseEvent me)
           
 void mouseDragged(java.awt.event.MouseEvent me)
           
 void mouseEntered(java.awt.event.MouseEvent me)
           
 void mouseExited(java.awt.event.MouseEvent me)
           
 void mouseMoved(java.awt.event.MouseEvent me)
           
 void mousePressed(java.awt.event.MouseEvent me)
           
 void mouseReleased(java.awt.event.MouseEvent me)
           
protected  boolean newAction()
          Prompts to save unsaved work and then clears the workspace.
protected  boolean openAction()
          Clears the current workspace by calling newAction(), then allows the user to open an image file or a previously-stored workspace file.
protected  void parameterAction()
          Displays an instance of ParametersDialog.
protected  void redoAction()
          Redoes the last action on the canvas.
protected  boolean saveAction()
          Checks that the workspace file on disk exists and is writable.
protected  boolean saveAsAction()
          Creates a writable file on disk and saves a reference to that file to workspaceFile.
protected  void setColorAction(java.awt.Color c)
          Sets the outline color of the canvas.
protected  void setCustomColorAction()
          Displays a color chooser dialog and then sets the canvas' color appropriately.
protected  void setSelected(int index)
          Sets the selected KeyButton object to be that which resides at the passed index in the data model.
Pass -1 to deselect all.
 void setTitle(java.lang.String filename)
           
protected  void undoAction()
          Undoes the last action on the canvas.
protected  void updateState()
          Saves parameters and data to and modelDef workspace appropriately.
protected  void userManualAction()
          Defines action(s) to take upon selection of the "User Manual" menu item.
 void valueChanged(javax.swing.event.ListSelectionEvent lse)
           
 void windowActivated(java.awt.event.WindowEvent we)
           
 void windowClosed(java.awt.event.WindowEvent we)
           
 void windowClosing(java.awt.event.WindowEvent we)
           
 void windowDeactivated(java.awt.event.WindowEvent we)
           
 void windowDeiconified(java.awt.event.WindowEvent we)
           
 void windowIconified(java.awt.event.WindowEvent we)
           
 void windowOpened(java.awt.event.WindowEvent we)
           
 
Methods inherited from class tnt.gui.TnTFrame
actionPerformed, createCanvasScrollPane, createColorMenu, createEditMenu, createFileMenu, createHelpMenu, createInfoPanel, createMetricsMenu, createStatusPanel
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

fileModified

protected boolean fileModified
A flag to indicate modifications since the last save.


color

protected java.awt.Color color
The current color used to display key-button outlines on the canvas.


openFileChooser

protected javax.swing.JFileChooser openFileChooser
The file chooser used for opening.


saveFileChooser

protected javax.swing.JFileChooser saveFileChooser
The file chooser used for saving.


selected

protected KeyButton selected
The currently selected key-button, null if none.


mapping

protected KeyLetterDialog mapping
The dialog used for key-letter mapping.


modelDef

protected ModelDefinition modelDef
The ModelDefinition object used to store model data.

See Also:
ModelDefinition

parameters

protected ParametersDialog parameters
The dialog used setting metric parameters.


imageFileName

protected java.lang.String imageFileName
The path to the image file used in the current workspace.


workspaceFile

protected java.io.File workspaceFile
A reference to the workspace file on disk.


undoManager

protected javax.swing.undo.UndoManager undoManager
The undo manager.


workspace

protected Workspace workspace
The Workspace object used to store state data.

See Also:
Workspace
Constructor Detail

TnTImp

public TnTImp()
Method Detail

newAction

protected boolean newAction()
Prompts to save unsaved work and then clears the workspace.

Specified by:
newAction in class TnTFrame
Returns:
true if successful, false otherwise.
See Also:
clearWorkspace()

openAction

protected boolean openAction()
Clears the current workspace by calling newAction(), then allows the user to open an image file or a previously-stored workspace file.

Specified by:
openAction in class TnTFrame
Returns:
true if successful, false otherwise.
See Also:
newAction(), loadImage(ImageIcon i), loadWorkspace(Workspace ws)

saveAction

protected boolean saveAction()
Checks that the workspace file on disk exists and is writable. If so, writes the data to the file. If not, calls saveAsAction().

Specified by:
saveAction in class TnTFrame
Returns:
true if successful, false otherwise.
See Also:
saveAsAction()

saveAsAction

protected boolean saveAsAction()
Creates a writable file on disk and saves a reference to that file to workspaceFile.

Specified by:
saveAsAction in class TnTFrame
Returns:
true if successful, false otherwise.
See Also:
workspaceFile

exportAction

protected void exportAction()
Displays an instance of ExportDialog.

Specified by:
exportAction in class TnTFrame
See Also:
ExportDialog

exitAction

protected void exitAction()
Dispatches a "window closing" event.

Specified by:
exitAction in class TnTFrame
See Also:
windowClosing(WindowEvent we)

undoAction

protected void undoAction()
Undoes the last action on the canvas.

Specified by:
undoAction in class TnTFrame

redoAction

protected void redoAction()
Redoes the last action on the canvas.

Specified by:
redoAction in class TnTFrame

setColorAction

protected void setColorAction(java.awt.Color c)
Sets the outline color of the canvas.

Specified by:
setColorAction in class TnTFrame

setCustomColorAction

protected void setCustomColorAction()
Displays a color chooser dialog and then sets the canvas' color appropriately.

Specified by:
setCustomColorAction in class TnTFrame
See Also:
setColorAction(Color c)

parameterAction

protected void parameterAction()
Displays an instance of ParametersDialog.

Specified by:
parameterAction in class TnTFrame
See Also:
parameters

calculateAction

protected void calculateAction()
Displays a message dialog if any letters are not mapped. Otherwise, creates and runs an instance of CalculateMetricsThread.

Specified by:
calculateAction in class TnTFrame
See Also:
CalculateMetrics

userManualAction

protected void userManualAction()
Description copied from class: TnTFrame
Defines action(s) to take upon selection of the "User Manual" menu item.

Specified by:
userManualAction in class TnTFrame

aboutAction

protected void aboutAction()
Description copied from class: TnTFrame
Defines action(s) to take upon selection of the "About" menu item.

Specified by:
aboutAction in class TnTFrame

editKeyAction

protected void editKeyAction()
Description copied from class: TnTFrame
Defines action(s) to take upon pressing the edit button.

Specified by:
editKeyAction in class TnTFrame

deleteKeyAction

protected void deleteKeyAction()
Description copied from class: TnTFrame
Defines action(s) to take upon pressing the delete button.

Specified by:
deleteKeyAction in class TnTFrame

addKeyAction

protected void addKeyAction(java.awt.geom.Rectangle2D.Double keyBounds)
Presents the user with a key-letter mapping dialog and creates a new KeyButton object with the selected letters and the passed rectangular bounds.

Parameters:
keyBounds - the rectangular bounds outlining the new key.

setSelected

protected void setSelected(int index)
Sets the selected KeyButton object to be that which resides at the passed index in the data model.
Pass -1 to deselect all.

Parameters:
index - the index of the object to select.

updateState

protected void updateState()
Saves parameters and data to and modelDef workspace appropriately.

See Also:
modelDef, workspace

clearWorkspace

protected void clearWorkspace()
Reinitializes the workspace to a blank one.


loadImage

protected void loadImage(javax.swing.ImageIcon i)
Sets the passed image as the canvas background image.

Parameters:
i - the background image to use.

loadWorkspace

protected void loadWorkspace(Workspace ws)
Notifies the user if the image file and/or word-frequency file are readable, calls clearWorkspace(), then recreates the state stored in the passed Workspace object.

Parameters:
ws - the Workspace object with the state to recreate.

setTitle

public void setTitle(java.lang.String filename)
Overrides:
setTitle in class java.awt.Frame

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent lse)
Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseDragged

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

mouseEntered

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

mouseExited

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

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent me)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mousePressed

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

mouseReleased

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

windowActivated

public void windowActivated(java.awt.event.WindowEvent we)
Specified by:
windowActivated in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent we)
Specified by:
windowClosed in interface java.awt.event.WindowListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent we)
Specified by:
windowClosing in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent we)
Specified by:
windowDeactivated in interface java.awt.event.WindowListener

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent we)
Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent we)
Specified by:
windowIconified in interface java.awt.event.WindowListener

windowOpened

public void windowOpened(java.awt.event.WindowEvent we)
Specified by:
windowOpened in interface java.awt.event.WindowListener