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.textlayout.attributes.AttributeMap;
\r
18 import com.ibm.richtext.textlayout.attributes.AttributeSet;
\r
19 import com.ibm.richtext.styledtext.StyleModifier;
\r
21 import com.ibm.richtext.textpanel.MTextPanel;
\r
22 import com.ibm.richtext.textpanel.TextPanelEvent;
\r
23 import com.ibm.richtext.uiimpl.resources.MenuData;
\r
25 public final class SubtractStyleMenuItem extends SingleCheckMenuItem {
\r
27 static final String COPYRIGHT =
\r
28 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
29 private final Object[] fKeys;
\r
31 private final boolean fCharacter;
\r
33 public SubtractStyleMenuItem(Object[] keys,
\r
35 boolean character) {
\r
39 fKeys = (Object[]) keys.clone();
\r
40 fCharacter = character;
\r
42 AttributeSet keySet = new AttributeSet(keys);
\r
43 final StyleModifier modifier = StyleModifier.createRemoveModifier(keySet);
\r
45 fItem.addListener(new EventListener() {
\r
46 public void eventOccurred(EventObject event) {
\r
47 MTextPanel panel = getTextPanel();
\r
48 if (panel == null) {
\r
49 throw new Error("Menu item is enabled when panel is null!");
\r
52 if (fCharacter == CHARACTER) {
\r
53 panel.modifyCharacterStyleOnSelection(modifier);
\r
56 panel.modifyParagraphStyleOnSelection(modifier);
\r
62 private static boolean objectsAreEqual(Object lhs, Object rhs) {
\r
68 return lhs.equals(rhs);
\r
72 protected void setChecked() {
\r
74 MTextPanel panel = getTextPanel();
\r
75 AttributeMap defaults = panel.getDefaultValues();
\r
77 for (int i=0; i < fKeys.length; i++) {
\r
78 Object defaultV = defaults.get(fKeys[i]);
\r
80 Object value = (fCharacter == CHARACTER)?
\r
81 panel.getCharacterStyleOverSelection(fKeys[i]) :
\r
82 panel.getParagraphStyleOverSelection(fKeys[i]);
\r
84 if (!objectsAreEqual(defaultV, value)) {
\r
85 fItem.setState(false);
\r
90 fItem.setState(true);
\r
93 public boolean respondsToEventType(int type) {
\r
95 return type == TextPanelEvent.SELECTION_STYLES_CHANGED;
\r
98 public final void textEventOccurred(TextPanelEvent event) {
\r