jimmc.swing
Class JsFrame

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--jimmc.swing.JsFrame
All Implemented Interfaces:
javax.accessibility.Accessible, ExceptionHandler, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants
Direct Known Subclasses:
PrintPreviewer

public class JsFrame
extends javax.swing.JFrame
implements ExceptionHandler

A general Frame with utility methods.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Inner classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Inner classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  ResourceSource res
          Our resource source.
 
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, 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
JsFrame()
          Create a frame without a name.
JsFrame(java.lang.String name)
          Create a frame with a name.
 
Method Summary
protected  void addAboutMenuItem(javax.swing.JMenu menu)
          Add the About entry to the menu.
protected  void addCloseMenuItem(javax.swing.JMenu m)
          Add the File->Close menu item.
protected  void addWindowListener()
          Add a window listener to close our window.
 void afterAction(java.lang.Object source)
          Called after an action when no exception was thrown.
 void beforeAction(java.lang.Object source)
          Called before an action which may generate an exception.
 boolean confirmDialog(java.lang.String prompt)
           
protected  boolean confirmExit()
          Ask if he really wants to exit from the program.
protected  javax.swing.JMenu createFileMenu()
          Create the File menu.
protected  javax.swing.JMenu createHelpMenu()
          Create the Help menu.
protected  javax.swing.JMenu createHelpMenuOnly()
          Create the Help menu without any entries.
protected  javax.swing.JMenuBar createMenuBar()
          Create a default menu bar with a File menu.
 void errorDialog(java.lang.String errmsg)
          Put up an error dialog.
 void exceptionDialog(java.lang.Throwable ex)
          A dialog to display an exception.
 java.io.File fileOpenDialog(java.lang.String prompt)
          Put up a file open dialog.
 java.io.File fileOpenDialog(java.lang.String prompt, java.io.File dflt)
          Put up a file open dialog.
 java.io.File fileOpenDialog(java.lang.String prompt, java.lang.String dflt)
          Put up a file open dialog.
 java.io.File fileSaveDialog(java.lang.String prompt)
          Put up a file save dialog.
 java.io.File fileSaveDialog(java.lang.String prompt, java.io.File dflt)
          Put up a file save dialog.
 java.io.File fileSaveDialog(java.lang.String prompt, java.lang.String dflt)
          Put up a file save dialog.
protected  java.lang.Object getMessageDisplay(java.lang.String msg)
          Get an object to display a message.
 java.io.PrintWriter getPrintWriterFor(java.lang.String filename)
          Get a PrintWriter for the specified file.
 ResourceSource getResourceSource()
          Get our resource source.
 void handleException(java.lang.Object source, java.lang.Throwable ex)
          Deal with an exception.
 void infoDialog(java.lang.String infomsg)
          Put up an info dialog.
 int multiButtonDialog(java.lang.String prompt, java.lang.String title, java.lang.String[] labels)
          Put up a dialog with multiple buttons.
protected  void processClose()
          Close this window.
protected  void processFileExit()
          Process the File->Exit menu command.
protected  void processHelpAbout()
          Process the Help->About menu command.
 boolean saveTextToFile(java.lang.String text, java.lang.String filename)
          Save the specified text string to the specified file.
 void setResourceSource(ResourceSource resourceSource)
          Set our resource source.
 java.lang.String stringDialog(java.lang.String prompt)
          Put up a string dialog.
 int yncDialog(java.lang.String prompt, java.lang.String yes, java.lang.String no, java.lang.String cancel)
          Put up a three-button Yes/No/Cancel dialog.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, processKeyEvent, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, isResizable, remove, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle
 
Methods inherited from class java.awt.Window
addWindowListener, applyResourceBundle, applyResourceBundle, dispose, getFocusOwner, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isShowing, pack, postEvent, processEvent, removeWindowListener, setCursor, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFont, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, 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, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, 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, size, toString, transferFocus
 
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

res

protected ResourceSource res
Our resource source.
Constructor Detail

JsFrame

public JsFrame()
Create a frame without a name.

JsFrame

public JsFrame(java.lang.String name)
Create a frame with a name.
Method Detail

setResourceSource

public void setResourceSource(ResourceSource resourceSource)
Set our resource source.

getResourceSource

public ResourceSource getResourceSource()
Get our resource source.

addWindowListener

protected void addWindowListener()
Add a window listener to close our window.

createMenuBar

protected javax.swing.JMenuBar createMenuBar()
Create a default menu bar with a File menu.

createFileMenu

protected javax.swing.JMenu createFileMenu()
Create the File menu.

addCloseMenuItem

protected void addCloseMenuItem(javax.swing.JMenu m)
Add the File->Close menu item.

createHelpMenu

protected javax.swing.JMenu createHelpMenu()
Create the Help menu.

createHelpMenuOnly

protected javax.swing.JMenu createHelpMenuOnly()
Create the Help menu without any entries.

addAboutMenuItem

protected void addAboutMenuItem(javax.swing.JMenu menu)
Add the About entry to the menu.

processHelpAbout

protected void processHelpAbout()
Process the Help->About menu command.

processClose

protected void processClose()
Close this window.

processFileExit

protected void processFileExit()
Process the File->Exit menu command.

confirmExit

protected boolean confirmExit()
Ask if he really wants to exit from the program.

confirmDialog

public boolean confirmDialog(java.lang.String prompt)

errorDialog

public void errorDialog(java.lang.String errmsg)
Put up an error dialog.

infoDialog

public void infoDialog(java.lang.String infomsg)
Put up an info dialog.

getMessageDisplay

protected java.lang.Object getMessageDisplay(java.lang.String msg)
Get an object to display a message. For short messages, the object is the message itself. For long messages, the object is a JTextArea inside s JScrollPane.

stringDialog

public java.lang.String stringDialog(java.lang.String prompt)
Put up a string dialog.

fileOpenDialog

public java.io.File fileOpenDialog(java.lang.String prompt)
Put up a file open dialog.

fileOpenDialog

public java.io.File fileOpenDialog(java.lang.String prompt,
                                   java.lang.String dflt)
Put up a file open dialog.
Returns:
null if cancelled.

fileOpenDialog

public java.io.File fileOpenDialog(java.lang.String prompt,
                                   java.io.File dflt)
Put up a file open dialog.
Returns:
null if cancelled.

fileSaveDialog

public java.io.File fileSaveDialog(java.lang.String prompt)
Put up a file save dialog.

fileSaveDialog

public java.io.File fileSaveDialog(java.lang.String prompt,
                                   java.lang.String dflt)
Put up a file save dialog.
Returns:
null if cancelled

fileSaveDialog

public java.io.File fileSaveDialog(java.lang.String prompt,
                                   java.io.File dflt)
Put up a file save dialog.
Returns:
null if cancelled

yncDialog

public int yncDialog(java.lang.String prompt,
                     java.lang.String yes,
                     java.lang.String no,
                     java.lang.String cancel)
Put up a three-button Yes/No/Cancel dialog.
Returns:
The index of the selected button: 0 for yes, 1 for no, 2 for cancel.

multiButtonDialog

public int multiButtonDialog(java.lang.String prompt,
                             java.lang.String title,
                             java.lang.String[] labels)
Put up a dialog with multiple buttons.
Parameters:
prompt - The prompt string.
title - The title string.
labels - The labels to use on the buttons.
Returns:
The index number of the selected button.

exceptionDialog

public void exceptionDialog(java.lang.Throwable ex)
A dialog to display an exception.

getPrintWriterFor

public java.io.PrintWriter getPrintWriterFor(java.lang.String filename)
Get a PrintWriter for the specified file. If the file aready exists, ask the user for confirmation before overwriting the file.
Returns:
The opened PrintWriter, or null if the user declined to open the file.

saveTextToFile

public boolean saveTextToFile(java.lang.String text,
                              java.lang.String filename)
Save the specified text string to the specified file.
Parameters:
text - The text to write to the file.
filename - The output file.
Returns:
True if the data was written to the file, false if the file already existed and the user declined to overwrite it (i.e. cancelled), or on error.

beforeAction

public void beforeAction(java.lang.Object source)
Description copied from interface: ExceptionHandler
Called before an action which may generate an exception.
Specified by:
beforeAction in interface ExceptionHandler
Following copied from interface: jimmc.util.ExceptionHandler
Parameters:
source - The source of the action.

afterAction

public void afterAction(java.lang.Object source)
Description copied from interface: ExceptionHandler
Called after an action when no exception was thrown.
Specified by:
afterAction in interface ExceptionHandler
Following copied from interface: jimmc.util.ExceptionHandler
Parameters:
source - The source of the action.

handleException

public void handleException(java.lang.Object source,
                            java.lang.Throwable ex)
Description copied from interface: ExceptionHandler
Deal with an exception.
Specified by:
handleException in interface ExceptionHandler
Following copied from interface: jimmc.util.ExceptionHandler
Parameters:
exception - The exception or other throwable to handle.