2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.uiimpl;
\r
15 import java.util.EventObject;
\r
17 import com.ibm.richtext.textpanel.MTextPanel;
\r
18 import com.ibm.richtext.textpanel.TextPanelEvent;
\r
19 import com.ibm.richtext.uiimpl.resources.MenuData;
\r
21 public abstract class CommandMenuItem extends MenuItemSet {
\r
23 static final String COPYRIGHT =
\r
24 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
25 private /*final*/ MItem fItem;
\r
27 protected abstract boolean isEnabled();
\r
28 protected abstract void performAction();
\r
30 protected CommandMenuItem(MenuData data) {
\r
35 protected CommandMenuItem(MenuData data, boolean enableByDefault) {
\r
37 fItem = MItem.createItem(data);
\r
38 fItem.addListener(new EventListener() {
\r
39 public void eventOccurred(EventObject event) {
\r
43 fItem.setEnabled(enableByDefault);
\r
46 protected void textPanelChanged() {
\r
48 MTextPanel textPanel = getTextPanel();
\r
49 if (textPanel == null) {
\r
50 fItem.setEnabled(false);
\r
53 fItem.setEnabled(isEnabled());
\r
57 public final void textEventOccurred(TextPanelEvent event) {
\r
59 fItem.setEnabled(isEnabled());
\r
62 public static final class CutCopyClear extends CommandMenuItem {
\r
64 public static final int CUT = 0;
\r
65 public static final int COPY = 1;
\r
66 public static final int CLEAR = 2;
\r
68 private final int fKind;
\r
70 public CutCopyClear(MenuData menuData, int kind) {
\r
73 if (kind != CUT && kind != COPY && kind != CLEAR) {
\r
74 throw new IllegalArgumentException("Invalid menu kind");
\r
79 protected boolean isEnabled() {
\r
81 MTextPanel panel = getTextPanel();
\r
82 return panel.getSelectionStart() != panel.getSelectionEnd();
\r
85 public boolean respondsToEventType(int type) {
\r
87 return type == TextPanelEvent.SELECTION_EMPTY_CHANGED;
\r
90 protected void performAction() {
\r
92 MTextPanel panel = getTextPanel();
\r
107 public static final class UndoRedo extends CommandMenuItem {
\r
109 public static final boolean UNDO = true;
\r
110 public static final boolean REDO = false;
\r
112 private boolean fKind;
\r
114 public UndoRedo(MenuData menuData, boolean kind) {
\r
120 protected boolean isEnabled() {
\r
122 MTextPanel panel = getTextPanel();
\r
123 if (fKind == UNDO) {
\r
124 return panel.canUndo();
\r
127 return panel.canRedo();
\r
131 public boolean respondsToEventType(int type) {
\r
133 return type == TextPanelEvent.UNDO_STATE_CHANGED;
\r
136 protected void performAction() {
\r
138 MTextPanel panel = getTextPanel();
\r
139 if (fKind == UNDO) {
\r
148 public static final class Paste extends CommandMenuItem {
\r
150 public Paste(MenuData menuData) {
\r
155 protected boolean isEnabled() {
\r
157 return getTextPanel().clipboardNotEmpty();
\r
160 public boolean respondsToEventType(int type) {
\r
162 return type == TextPanelEvent.CLIPBOARD_CHANGED;
\r
165 protected void performAction() {
\r
167 getTextPanel().paste();
\r
171 public static final class SelectAll extends CommandMenuItem {
\r
173 public SelectAll(MenuData menuData) {
\r
178 protected boolean isEnabled() {
\r
183 public boolean respondsToEventType(int type) {
\r
188 protected void performAction() {
\r
190 getTextPanel().selectAll();
\r