Methods Summary |
---|
protected javax.swing.JMenuBar | createMenuBar()
JMenuBar menubar = new JMenuBar();
JMenu file = new JMenu("File");
JMenu edit = new JMenu("Edit");
menubar.add(file);
menubar.add(edit);
file.add(getOpenAction());
file.add(getSaveAction());
file.add(new ExitAction());
edit.add(getHashedAction(DefaultEditorKit.cutAction));
edit.add(getHashedAction(DefaultEditorKit.copyAction));
edit.add(getHashedAction(DefaultEditorKit.pasteAction));
edit.add(getHashedAction(DefaultEditorKit.selectAllAction));
return menubar;
|
protected javax.swing.text.JTextComponent | createTextComponent()
JTextArea ta = new JTextArea();
ta.setLineWrap(true);
return ta;
|
protected javax.swing.JToolBar | createToolBar()
JToolBar bar = new JToolBar();
// Add simple actions for opening & saving
bar.add(getOpenAction()).setText("");
bar.add(getSaveAction()).setText("");
bar.addSeparator();
// Add cut/copy/paste buttons
bar.add(getHashedAction(DefaultEditorKit.cutAction)).setText("");
bar.add(getHashedAction(DefaultEditorKit.copyAction)).setText("");
bar.add(getHashedAction(DefaultEditorKit.pasteAction)).setText("");
return bar;
|
protected javax.swing.Action | getHashedAction(java.lang.String name)
return (Action)actionHash.get(name);
|
protected javax.swing.Action | getOpenAction() return openAction;
|
protected javax.swing.Action | getSaveAction() return saveAction;
|
protected javax.swing.text.JTextComponent | getTextComponent() return textComp;
|
protected void | hashDefaultActions()
Action[] actions = textComp.getActions();
for (int i=0; i<actions.length; i++) {
String name = (String)actions[i].getValue(Action.NAME);
actionHash.put(name, actions[i]);
}
|
public static void | main(java.lang.String[] args)
SimpleEditor editor = new SimpleEditor();
editor.addWindowListener(new BasicWindowMonitor());
editor.setVisible(true);
|
protected void | makeActionsPretty()
Action a;
a = getHashedAction(DefaultEditorKit.cutAction);
a.putValue(Action.SMALL_ICON, new ImageIcon("icons/cut.gif"));
a.putValue(Action.NAME, "Cut");
a = getHashedAction(DefaultEditorKit.copyAction);
a.putValue(Action.SMALL_ICON, new ImageIcon("icons/copy.gif"));
a.putValue(Action.NAME, "Copy");
a = getHashedAction(DefaultEditorKit.pasteAction);
a.putValue(Action.SMALL_ICON, new ImageIcon("icons/paste.gif"));
a.putValue(Action.NAME, "Paste");
a = getHashedAction(DefaultEditorKit.selectAllAction);
a.putValue(Action.NAME, "Select All");
|
protected void | updateKeymap()
// Create a new child Keymap
Keymap map = JTextComponent.addKeymap("NextPrevMap",
textComp.getKeymap());
// Define the keystrokes to be added
KeyStroke next = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
InputEvent.CTRL_MASK, false);
KeyStroke prev = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
InputEvent.CTRL_MASK, false);
KeyStroke selNext = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK, false);
KeyStroke selPrev = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK, false);
// Add the new mappings used DefaultEditorKit actions
map.addActionForKeyStroke(next, getHashedAction(
DefaultEditorKit.nextWordAction));
map.addActionForKeyStroke(prev, getHashedAction(
DefaultEditorKit.previousWordAction));
map.addActionForKeyStroke(selNext, getHashedAction(
DefaultEditorKit.selectionNextWordAction));
map.addActionForKeyStroke(selPrev, getHashedAction(
DefaultEditorKit.selectionPreviousWordAction));
// Set the Keymap for the text component
textComp.setKeymap(map);
|