edu.northwestern.at.utils.swing.notepad
Class Notepad

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 edu.northwestern.at.utils.swing.WindowsMenuManager
                          extended by edu.northwestern.at.utils.swing.XFrame
                              extended by edu.northwestern.at.utils.swing.notepad.Notepad
All Implemented Interfaces:
CutCopyPaste, EditBatch, PrintableContainer, SelectAll, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants
Direct Known Subclasses:
WordHoardCalcSimpleEditor

public class Notepad
extends XFrame
implements EditBatch, CutCopyPaste, SelectAll

Simple text editor.

Modified from Sun's Notepad sample, the usage license for which follows. The author of Sun's version is Timothy Prinzing. Modifications by Philip R. Burns.

Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-Redistribution in binary form must reproduct the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.

This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility.

See Also:
Serialized Form

Nested Class Summary
protected  class Notepad.ActionChangedListener
           
(package private)  class Notepad.ClipboardObserver
          Clipboard observer.
protected  class Notepad.CopyAction
          Copy to clipboard action.
protected  class Notepad.CutAction
          Cut to clipboard action.
protected  class Notepad.ExitAction
          Exit command.
protected  class Notepad.FileLoader
          Thread to load a file into the text storage model
protected  class Notepad.FileSaver
          Thread to save document to a text file.
protected  class Notepad.FindAction
          Create find action.
protected  class Notepad.MyDocumentListener
          Listens for changes to document being edited.
protected  class Notepad.NewAction
          New action.
protected  class Notepad.OpenAction
          Open file action.
protected  class Notepad.PageSetupAction
          Create page setup action.
protected  class Notepad.PasteAction
          Paste from clipboard action.
protected  class Notepad.PrintAction
          Create print action.
protected  class Notepad.RedoAction
          Handles Redo action.
protected  class Notepad.ReplaceAction
          Create replace action.
protected  class Notepad.RunAction
          Run action.
protected  class Notepad.SaveAction
          Save file action.
protected  class Notepad.SaveAsAction
          Save as action.
protected  class Notepad.SelectAllAction
          Handles "select all" action.
protected  class Notepad.StatusBar
          Create status bar for displaying row/column and progress.
protected  class Notepad.UndoAction
          Handles Undo action.
protected  class Notepad.UndoHandler
           
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String acceleratorSuffix
          Suffix applied to the key word in resource file lookups for getting accelerator key name.
static java.lang.String actionSuffix
          Suffix applied to the key used in resource file lookups for an action.
protected  java.util.Hashtable commands
          Hash table of menu actions.
protected  javax.swing.JPanel contentPanel
          Content pane for editor.
protected  Notepad.CopyAction copyAction
           
protected  java.io.File currentFile
          Current file being edited.
protected  Notepad.CutAction cutAction
           
protected  javax.swing.Action[] defaultActions
          Actions defined by the Notepad class.
protected  java.awt.datatransfer.ClipboardOwner defaultClipboardOwner
          Clipboard.
protected  Notepad.MyDocumentListener documentListener
          The document listener.
protected  boolean documentModified
          True if the document text has been modified.
protected  boolean doingEditBatch
          True if in the midst of creating a compound edit batch.
protected  javax.swing.JTextArea editor
          The text component holding the text being edited.
protected  Notepad.ExitAction exitAction
           
protected  Notepad.FindAction findAction
           
static java.awt.Font font
          The font.
static int fontCharWidth
          Width of a single character in the font.
static java.lang.String imageSuffix
          Suffix applied to the key used in resource file lookups for an image.
static java.lang.String labelSuffix
          Suffix applied to the key used in resource file lookups for a label.
protected  java.util.Hashtable menuItems
          Hash table containing menu items.
protected  java.util.Hashtable menus
          Hash table containing menus.
protected  Notepad.NewAction newAction
           
protected  java.lang.String newTitle
          Default title for new file.
protected  Notepad.OpenAction openAction
           
protected  Notepad.PageSetupAction pageSetupAction
           
protected  Notepad.PasteAction pasteAction
           
protected  Notepad.PrintAction printAction
           
protected  boolean readOnly
          True if editor is readonly (e.g., acting as a viewer only).
protected  Notepad.RedoAction redoAction
           
protected  Notepad.ReplaceAction replaceAction
           
protected static java.util.ResourceBundle resources
          The editor resource strings.
protected  Notepad.RunAction runAction
           
protected  Notepad.SaveAction saveAction
           
protected  Notepad.SaveAsAction saveAsAction
           
protected  Notepad.SelectAllAction selectAllAction
           
static int tabSize
          Tab size in columns.
static java.lang.String tipSuffix
          Suffix applied to the key used in resource file lookups for tooltip text.
protected  java.lang.String title
          Current title for editor.
protected  java.util.Hashtable toolbarButtons
          Hash table containing toolbar buttons.
protected  javax.swing.undo.UndoManager undo
          UndoManager to which we add edits.
protected  javax.swing.undo.CompoundEdit undoableEditBatch
          The compound undo edit batch manager.
protected  Notepad.UndoAction undoAction
           
protected  javax.swing.event.UndoableEditListener undoHandler
          Listener for the undoable edits to the current document.
static java.lang.String visibleSuffix
          Suffix applied to the key word in resource file lookups for setting item visible (=1) or invisible(=0).
 
Fields inherited from class edu.northwestern.at.utils.swing.XFrame
aboutBox, prefsWindow
 
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
Notepad()
          Create Notepad editor.
Notepad(boolean readOnly)
          Create Notepad editor.
 
Method Summary
 boolean clipboardHasPasteableData()
          Check if clipboard has pasteable data.
 void copy()
          Copy to clipboard.
protected  java.beans.PropertyChangeListener createActionChangeListener(javax.swing.JMenuItem b)
           
protected  void createCaretListener()
          Create caret listener to track cursor movements.
protected  void createDocumentListener()
          Create a document listener.
protected  javax.swing.JTextArea createEditor()
          Create an XTextArea to hold the document text.
protected  javax.swing.JMenu createMenu(java.lang.String key)
          Create an editor menu.
protected  javax.swing.JMenuBar createMenubar()
          Create the menubar for the app.
protected  javax.swing.JMenuItem createMenuItem(java.lang.String cmd)
          Create a menu item.
protected  Notepad.StatusBar createStatusBar()
          Create a status bar.
protected  java.awt.Component createTool(java.lang.String key)
          Create a toolbar item by name.
protected  javax.swing.JToolBar createToolbar()
          Create the toolbar.
protected  javax.swing.JButton createToolbarButton(java.lang.String key)
          Create a button for the toolbar.
 void cut()
          Cut to clipboard.
protected  void doCopy(java.awt.event.ActionEvent e)
          Handle Copy action.
protected  void doCut(java.awt.event.ActionEvent e)
          Handle Cut action.
protected  void doExit(java.awt.event.ActionEvent e)
          Handle exit request.
protected  void doFind(java.awt.event.ActionEvent e)
          Do find.
protected  void doNew(java.awt.event.ActionEvent e)
          Performs new action.
protected  void doOpen(java.awt.event.ActionEvent e)
          Performs open file action.
protected  void doPageSetup(java.awt.event.ActionEvent e)
          Printer page setup.
protected  void doPaste(java.awt.event.ActionEvent e)
          Handle Paste action.
protected  void doPrint(java.awt.event.ActionEvent e)
          Print the text.
protected  void doReplace(java.awt.event.ActionEvent e)
          Do replace.
protected  void doRunAction(java.awt.event.ActionEvent e)
          Run script, etc.
protected  void doSave(java.awt.event.ActionEvent e)
          Performs save file action.
protected  void doSaveAs(java.awt.event.ActionEvent e)
          Performs save as action.
protected  void doSelectAll(java.awt.event.ActionEvent e)
          Performs "select all" action.
protected  void enableEditMenuItems(boolean textSelected)
          Enables/disables edit menu items depending upon whether text is selected.
protected  void enableMenuItems(boolean docHasText)
          Enables/disables menu items depending upon document contents.
 void endEditBatch()
          End undoable edit batch.
protected  javax.swing.Action getAction(java.lang.String cmd)
          Return action for a specified command.
 javax.swing.Action[] getActions()
          Fetch the list of actions supported by this editor.
protected  javax.swing.JTextArea getEditor()
          Return the editor contained in this panel.
protected  java.lang.String getEditorText()
          Return the editor text as a string.
protected  java.awt.Frame getFrame()
          Find the parent frame for displaying a file-chooser dialog.
protected  javax.swing.JMenuItem getMenu(java.lang.String menuName)
          Return top-level menu.
protected  javax.swing.JMenuBar getMenubar()
          Return the menu bar.
protected  javax.swing.JMenuItem getMenuItem(java.lang.String cmd)
          Return menu item for a specified command.
protected  java.net.URL getResource(java.lang.String key)
          Return resource URL by name.
protected  java.lang.String getResourceString(java.lang.String nm)
          Return resource string by name.
 java.lang.String getTitle()
          Get title.
protected  java.awt.Container getToolbar()
          Return the toolbar.
protected  java.awt.Component getToolbarItem(java.lang.String key)
          Get a toolbar item by name.
protected  void handleCaretEvent(javax.swing.event.CaretEvent event)
          Handles caret change events.
 void initializeClipboard()
          Initialize clipboard.
 boolean isCopyEnabled()
          Is copy enabled?
 boolean isCutEnabled()
          Is cut enabled?
 boolean isPasteEnabled()
          Is paste enabled?
 boolean isSelectAllEnabled()
          Checks if "select all" enabled.
 boolean isTextSelected()
          Is anything selected which can be cut/copied?
 boolean isUnselectEnabled()
          Is unselect enabled?
 void paste()
          Paste from clipboard.
protected  void reallyExit(java.awt.event.ActionEvent e)
          Exit editor.
protected  void reportUnexpectedError(java.lang.Exception e)
          Report an unexpected error.
protected  void resetUndoManager()
          Reset undo manager.
 void selectAll()
          Selects all text.
protected  void setActionState(java.lang.String actionName, boolean enabled)
          Enable or disable an action.
protected  int showNotSavedDialog(java.lang.String title)
          Confirm closing with unsaved changes.
 void startEditBatch()
          Start undoable edit batch.
 void unselect()
          Unselect selection.
 
Methods inherited from class edu.northwestern.at.utils.swing.XFrame
about, common, doPageSetup, doPrint, doPrint, doPrint, doPrintPreview, doPrintPreview, doPrintPreview, pack, pack, prefs, quit, setAboutBox, setDefaultImage, setPrefsWindow
 
Methods inherited from class edu.northwestern.at.utils.swing.WindowsMenuManager
dispose, getActiveWindow, getAllOpenWindows, getWindowsMenu, handleLastWindowClosed, setJMenuBar, setTitle, setVisible, setWindowsMenu
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, 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, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, 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, 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, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

readOnly

protected boolean readOnly
True if editor is readonly (e.g., acting as a viewer only).


documentModified

protected boolean documentModified
True if the document text has been modified.


currentFile

protected java.io.File currentFile
Current file being edited.


newTitle

protected java.lang.String newTitle
Default title for new file.


title

protected java.lang.String title
Current title for editor.


documentListener

protected Notepad.MyDocumentListener documentListener
The document listener.


undoableEditBatch

protected javax.swing.undo.CompoundEdit undoableEditBatch
The compound undo edit batch manager.


doingEditBatch

protected boolean doingEditBatch
True if in the midst of creating a compound edit batch.


contentPanel

protected javax.swing.JPanel contentPanel
Content pane for editor.


editor

protected javax.swing.JTextArea editor
The text component holding the text being edited.


commands

protected java.util.Hashtable commands
Hash table of menu actions.


menuItems

protected java.util.Hashtable menuItems
Hash table containing menu items.


menus

protected java.util.Hashtable menus
Hash table containing menus.


toolbarButtons

protected java.util.Hashtable toolbarButtons
Hash table containing toolbar buttons.


undoHandler

protected javax.swing.event.UndoableEditListener undoHandler
Listener for the undoable edits to the current document.


undo

protected javax.swing.undo.UndoManager undo
UndoManager to which we add edits.


defaultClipboardOwner

protected java.awt.datatransfer.ClipboardOwner defaultClipboardOwner
Clipboard.


imageSuffix

public static final java.lang.String imageSuffix
Suffix applied to the key used in resource file lookups for an image.

See Also:
Constant Field Values

labelSuffix

public static final java.lang.String labelSuffix
Suffix applied to the key used in resource file lookups for a label.

See Also:
Constant Field Values

actionSuffix

public static final java.lang.String actionSuffix
Suffix applied to the key used in resource file lookups for an action.

See Also:
Constant Field Values

tipSuffix

public static final java.lang.String tipSuffix
Suffix applied to the key used in resource file lookups for tooltip text.

See Also:
Constant Field Values

visibleSuffix

public static final java.lang.String visibleSuffix
Suffix applied to the key word in resource file lookups for setting item visible (=1) or invisible(=0).

See Also:
Constant Field Values

acceleratorSuffix

public static final java.lang.String acceleratorSuffix
Suffix applied to the key word in resource file lookups for getting accelerator key name.

See Also:
Constant Field Values

tabSize

public static final int tabSize
Tab size in columns.

See Also:
Constant Field Values

font

public static final java.awt.Font font
The font.


fontCharWidth

public static int fontCharWidth
Width of a single character in the font.


resources

protected static java.util.ResourceBundle resources
The editor resource strings.


newAction

protected Notepad.NewAction newAction

openAction

protected Notepad.OpenAction openAction

saveAction

protected Notepad.SaveAction saveAction

saveAsAction

protected Notepad.SaveAsAction saveAsAction

pageSetupAction

protected Notepad.PageSetupAction pageSetupAction

printAction

protected Notepad.PrintAction printAction

exitAction

protected Notepad.ExitAction exitAction

copyAction

protected Notepad.CopyAction copyAction

cutAction

protected Notepad.CutAction cutAction

pasteAction

protected Notepad.PasteAction pasteAction

selectAllAction

protected Notepad.SelectAllAction selectAllAction

undoAction

protected Notepad.UndoAction undoAction

redoAction

protected Notepad.RedoAction redoAction

findAction

protected Notepad.FindAction findAction

replaceAction

protected Notepad.ReplaceAction replaceAction

runAction

protected Notepad.RunAction runAction

defaultActions

protected javax.swing.Action[] defaultActions
Actions defined by the Notepad class.

Constructor Detail

Notepad

public Notepad(boolean readOnly)
Create Notepad editor.

Parameters:
readOnly - True if editor is read-only, e.g., acting as a viewer.

Notepad

public Notepad()
Create Notepad editor.

Method Detail

getActions

public javax.swing.Action[] getActions()
Fetch the list of actions supported by this editor.

Returns:
Array of editor actions.

It is implemented to return the list of actions supported by the embedded JTextComponent augmented with the actions defined locally.


getTitle

public java.lang.String getTitle()
Get title.

Overrides:
getTitle in class java.awt.Frame
Returns:
The title.

createDocumentListener

protected void createDocumentListener()
Create a document listener.


createEditor

protected javax.swing.JTextArea createEditor()
Create an XTextArea to hold the document text.


getEditor

protected javax.swing.JTextArea getEditor()
Return the editor contained in this panel.


getEditorText

protected java.lang.String getEditorText()
Return the editor text as a string.


getFrame

protected java.awt.Frame getFrame()
Find the parent frame for displaying a file-chooser dialog.


createMenuItem

protected javax.swing.JMenuItem createMenuItem(java.lang.String cmd)
Create a menu item.

Parameters:
cmd - The name of the menu command.

This is the hook through which all menu items are created. It registers the result with the menuitem hashtable so that it can be fetched with getMenuItem().


getMenuItem

protected javax.swing.JMenuItem getMenuItem(java.lang.String cmd)
Return menu item for a specified command.

Parameters:
cmd - Name of the action.
Returns:
Menu item created for the given command or null if not created.

getMenu

protected javax.swing.JMenuItem getMenu(java.lang.String menuName)
Return top-level menu.

Parameters:
menuName - Name of the menu.
Returns:
Menu for given name or null if not created.

getAction

protected javax.swing.Action getAction(java.lang.String cmd)
Return action for a specified command.

Parameters:
cmd - Name of the action.
Returns:
Action created for the given command or null if not created.

getResourceString

protected java.lang.String getResourceString(java.lang.String nm)
Return resource string by name.

Parameters:
nm - Name of resource string.
Returns:
The resource string identified by "nm", or null if none.

getResource

protected java.net.URL getResource(java.lang.String key)
Return resource URL by name.

Parameters:
key - Key for resource.
Returns:
The resource URL identified by "key", or null if none.

getToolbar

protected java.awt.Container getToolbar()
Return the toolbar.

Returns:
The toolbar.

getMenubar

protected javax.swing.JMenuBar getMenubar()
Return the menu bar.

Returns:
The menu bar.

createStatusBar

protected Notepad.StatusBar createStatusBar()
Create a status bar.

Returns:
The status bar.

resetUndoManager

protected void resetUndoManager()
Reset undo manager.


createToolbar

protected javax.swing.JToolBar createToolbar()
Create the toolbar.

Returns:
The toolbar.

By default this reads the resource file for the definition of the toolbar.


createTool

protected java.awt.Component createTool(java.lang.String key)
Create a toolbar item by name.

Parameters:
key - The name of the toolbar item to create.
Returns:
The created toolbar item component.

getToolbarItem

protected java.awt.Component getToolbarItem(java.lang.String key)
Get a toolbar item by name.

Parameters:
key - The name of the toolbar item to retrieve.
Returns:
The toolbar item component, or null if not found.

createToolbarButton

protected javax.swing.JButton createToolbarButton(java.lang.String key)
Create a button for the toolbar.

Parameters:
key - The name of the button to create.
Returns:
The created button.

By default this will load an image resource. The image filename is relative to the classpath (including the '.' directory if its a part of the classpath), and may either be in a JAR file or a separate file.


createMenubar

protected javax.swing.JMenuBar createMenubar()
Create the menubar for the app.

Returns:
The toolbar.

By default this pulls the definition of the menu from the associated resource file.


createMenu

protected javax.swing.JMenu createMenu(java.lang.String key)
Create an editor menu.

Returns:
The menu.

By default this pulls the definition of the menu from the associated resource file.


createActionChangeListener

protected java.beans.PropertyChangeListener createActionChangeListener(javax.swing.JMenuItem b)

doCopy

protected void doCopy(java.awt.event.ActionEvent e)
Handle Copy action.


doCut

protected void doCut(java.awt.event.ActionEvent e)
Handle Cut action.


doPaste

protected void doPaste(java.awt.event.ActionEvent e)
Handle Paste action.


doSelectAll

protected void doSelectAll(java.awt.event.ActionEvent e)
Performs "select all" action.


selectAll

public void selectAll()
Selects all text.

Specified by:
selectAll in interface SelectAll

isSelectAllEnabled

public boolean isSelectAllEnabled()
Checks if "select all" enabled.

Specified by:
isSelectAllEnabled in interface SelectAll
Returns:
returns true if select all enabled.

doOpen

protected void doOpen(java.awt.event.ActionEvent e)
Performs open file action.


doNew

protected void doNew(java.awt.event.ActionEvent e)
Performs new action.


doSave

protected void doSave(java.awt.event.ActionEvent e)
Performs save file action.


doSaveAs

protected void doSaveAs(java.awt.event.ActionEvent e)
Performs save as action.


doRunAction

protected void doRunAction(java.awt.event.ActionEvent e)
Run script, etc.

Override this to implement script execution, etc. Default here is to do nothing.


doExit

protected void doExit(java.awt.event.ActionEvent e)
Handle exit request.

Override this to add extra end-of-editing checks.


showNotSavedDialog

protected int showNotSavedDialog(java.lang.String title)
Confirm closing with unsaved changes.


reallyExit

protected void reallyExit(java.awt.event.ActionEvent e)
Exit editor.

Override this to change end-of-editing behavior. Called at the end of doExit() .


doFind

protected void doFind(java.awt.event.ActionEvent e)
Do find.


doReplace

protected void doReplace(java.awt.event.ActionEvent e)
Do replace.


doPageSetup

protected void doPageSetup(java.awt.event.ActionEvent e)
Printer page setup.


doPrint

protected void doPrint(java.awt.event.ActionEvent e)
Print the text.


startEditBatch

public void startEditBatch()
Start undoable edit batch. Implements EditBatch interface.

Specified by:
startEditBatch in interface EditBatch

endEditBatch

public void endEditBatch()
End undoable edit batch. Implements EditBatch interface.

Specified by:
endEditBatch in interface EditBatch

setActionState

protected void setActionState(java.lang.String actionName,
                              boolean enabled)
Enable or disable an action.

Parameters:
actionName - Name of the action to enable or disable.
enabled - True to enable action, false otherwise.

Menu items and toolbar buttons associated with this action are also enabled or disabled.


enableMenuItems

protected void enableMenuItems(boolean docHasText)
Enables/disables menu items depending upon document contents.

Parameters:
docHasText - True if document being edited has text.

enableEditMenuItems

protected void enableEditMenuItems(boolean textSelected)
Enables/disables edit menu items depending upon whether text is selected.

Parameters:
textSelected - True if there is a selection in effect.

createCaretListener

protected void createCaretListener()
Create caret listener to track cursor movements.


handleCaretEvent

protected void handleCaretEvent(javax.swing.event.CaretEvent event)
Handles caret change events.

Parameters:
event - The caret event.

reportUnexpectedError

protected void reportUnexpectedError(java.lang.Exception e)
Report an unexpected error.

Parameters:
e - The exception.

Does nothing by default. Override in subclasses as needed.


clipboardHasPasteableData

public boolean clipboardHasPasteableData()
Check if clipboard has pasteable data.

Returns:
true if clipboard has pasteable text.

initializeClipboard

public void initializeClipboard()
Initialize clipboard.


cut

public void cut()
Cut to clipboard.

Specified by:
cut in interface CutCopyPaste

copy

public void copy()
Copy to clipboard.

Specified by:
copy in interface CutCopyPaste

paste

public void paste()
Paste from clipboard.

Specified by:
paste in interface CutCopyPaste

isCutEnabled

public boolean isCutEnabled()
Is cut enabled?

Specified by:
isCutEnabled in interface CutCopyPaste

isCopyEnabled

public boolean isCopyEnabled()
Is copy enabled?

Specified by:
isCopyEnabled in interface CutCopyPaste

isPasteEnabled

public boolean isPasteEnabled()
Is paste enabled?

Specified by:
isPasteEnabled in interface CutCopyPaste

isTextSelected

public boolean isTextSelected()
Is anything selected which can be cut/copied?

Specified by:
isTextSelected in interface CutCopyPaste

unselect

public void unselect()
Unselect selection.

Specified by:
unselect in interface SelectAll

isUnselectEnabled

public boolean isUnselectEnabled()
Is unselect enabled?

Specified by:
isUnselectEnabled in interface SelectAll