Fields Summary |
---|
private static ResourceBundle | resources |
private JTextComponent | editor |
private Hashtable | commands |
private Hashtable | menuItems |
private JMenuBar | menubar |
private JToolBar | toolbar |
private JComponent | status |
private JFrame | elementTreeFrame |
protected ElementTreePanel | elementTreePanel |
protected FileDialog | fileDialog |
protected UndoableEditListener | undoHandlerListener for the edits on the current document. |
protected UndoManager | undoUndoManager that we add edits to. |
public static final String | imageSuffixSuffix applied to the key used in resource file
lookups for an image. |
public static final String | labelSuffixSuffix applied to the key used in resource file
lookups for a label. |
public static final String | actionSuffixSuffix applied to the key used in resource file
lookups for an action. |
public static final String | tipSuffixSuffix applied to the key used in resource file
lookups for tooltip text. |
public static final String | openAction |
public static final String | newAction |
public static final String | saveAction |
public static final String | exitAction |
public static final String | showElementTreeAction |
private UndoAction | undoAction |
private RedoAction | redoAction |
private Action[] | defaultActionsActions defined by the Notepad class |
Methods Summary |
---|
protected java.beans.PropertyChangeListener | createActionChangeListener(javax.swing.JMenuItem b)
return new ActionChangedListener(b);
|
protected javax.swing.text.JTextComponent | createEditor()Create an editor to represent the given document.
JTextComponent c = new JTextArea();
c.setDragEnabled(true);
c.setFont(new Font("monospaced", Font.PLAIN, 12));
return c;
|
protected javax.swing.JMenu | createMenu(java.lang.String key)Create a menu for the app. By default this pulls the
definition of the menu from the associated resource file.
String[] itemKeys = tokenize(getResourceString(key));
JMenu menu = new JMenu(getResourceString(key + "Label"));
for (int i = 0; i < itemKeys.length; i++) {
if (itemKeys[i].equals("-")) {
menu.addSeparator();
} else {
JMenuItem mi = createMenuItem(itemKeys[i]);
menu.add(mi);
}
}
return menu;
|
protected javax.swing.JMenuItem | createMenuItem(java.lang.String cmd)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().
JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
URL url = getResource(cmd + imageSuffix);
if (url != null) {
mi.setHorizontalTextPosition(JButton.RIGHT);
mi.setIcon(new ImageIcon(url));
}
String astr = getResourceString(cmd + actionSuffix);
if (astr == null) {
astr = cmd;
}
mi.setActionCommand(astr);
Action a = getAction(astr);
if (a != null) {
mi.addActionListener(a);
a.addPropertyChangeListener(createActionChangeListener(mi));
mi.setEnabled(a.isEnabled());
} else {
mi.setEnabled(false);
}
menuItems.put(cmd, mi);
return mi;
|
protected javax.swing.JMenuBar | createMenubar()Create the menubar for the app. By default this pulls the
definition of the menu from the associated resource file.
JMenuItem mi;
JMenuBar mb = new JMenuBar();
String[] menuKeys = tokenize(getResourceString("menubar"));
for (int i = 0; i < menuKeys.length; i++) {
JMenu m = createMenu(menuKeys[i]);
if (m != null) {
mb.add(m);
}
}
return mb;
|
protected java.awt.Component | createStatusbar()Create a status bar
// need to do something reasonable here
status = new StatusBar();
return status;
|
protected java.awt.Component | createTool(java.lang.String key)Hook through which every toolbar item is created.
return createToolbarButton(key);
|
private java.awt.Component | createToolbar()Create the toolbar. By default this reads the
resource file for the definition of the toolbar.
toolbar = new JToolBar();
String[] toolKeys = tokenize(getResourceString("toolbar"));
for (int i = 0; i < toolKeys.length; i++) {
if (toolKeys[i].equals("-")) {
toolbar.add(Box.createHorizontalStrut(5));
} else {
toolbar.add(createTool(toolKeys[i]));
}
}
toolbar.add(Box.createHorizontalGlue());
return toolbar;
|
protected javax.swing.JButton | createToolbarButton(java.lang.String key)Create a button to go inside of the toolbar. 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.
URL url = getResource(key + imageSuffix);
JButton b = new JButton(new ImageIcon(url)) {
public float getAlignmentY() { return 0.5f; }
};
b.setRequestFocusEnabled(false);
b.setMargin(new Insets(1,1,1,1));
String astr = getResourceString(key + actionSuffix);
if (astr == null) {
astr = key;
}
Action a = getAction(astr);
if (a != null) {
b.setActionCommand(astr);
b.addActionListener(a);
} else {
b.setEnabled(false);
}
String tip = getResourceString(key + tipSuffix);
if (tip != null) {
b.setToolTipText(tip);
}
return b;
|
protected javax.swing.Action | getAction(java.lang.String cmd)
return (Action) commands.get(cmd);
|
public javax.swing.Action[] | getActions()Fetch the list of actions supported by this
editor. It is implemented to return the list
of actions supported by the embedded JTextComponent
augmented with the actions defined locally.
return TextAction.augmentList(editor.getActions(), defaultActions);
|
protected javax.swing.text.JTextComponent | getEditor()Fetch the editor contained in this panel
return editor;
|
protected java.awt.Frame | getFrame()Find the hosting frame, for the file-chooser dialog.
for (Container p = getParent(); p != null; p = p.getParent()) {
if (p instanceof Frame) {
return (Frame) p;
}
}
return null;
|
protected javax.swing.JMenuItem | getMenuItem(java.lang.String cmd)Fetch the menu item that was created for the given
command.
return (JMenuItem) menuItems.get(cmd);
|
protected javax.swing.JMenuBar | getMenubar()
return menubar;
|
protected java.net.URL | getResource(java.lang.String key)
String name = getResourceString(key);
if (name != null) {
URL url = this.getClass().getResource(name);
return url;
}
return null;
|
protected java.lang.String | getResourceString(java.lang.String nm)
String str;
try {
str = resources.getString(nm);
} catch (MissingResourceException mre) {
str = null;
}
return str;
|
protected java.awt.Container | getToolbar()
return toolbar;
|
public static void | main(java.lang.String[] args)
try {
String vers = System.getProperty("java.version");
if (vers.compareTo("1.1.2") < 0) {
System.out.println("!!!WARNING: Swing must be run with a " +
"1.1.2 or higher version VM!!!");
}
JFrame frame = new JFrame();
frame.setTitle(resources.getString("Title"));
frame.setBackground(Color.lightGray);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add("Center", new Notepad());
frame.addWindowListener(new AppCloser());
frame.pack();
frame.setSize(500, 600);
frame.show();
} catch (Throwable t) {
System.out.println("uncaught exception: " + t);
t.printStackTrace();
}
|
protected void | resetUndoManager()Resets the undo manager.
undo.discardAllEdits();
undoAction.update();
redoAction.update();
|
protected java.lang.String[] | tokenize(java.lang.String input)Take the given string and chop it up into a series
of strings on whitespace boundries. This is useful
for trying to get an array of strings out of the
resource file.
Vector v = new Vector();
StringTokenizer t = new StringTokenizer(input);
String cmd[];
while (t.hasMoreTokens())
v.addElement(t.nextToken());
cmd = new String[v.size()];
for (int i = 0; i < cmd.length; i++)
cmd[i] = (String) v.elementAt(i);
return cmd;
|