01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.uiimpl;
14:
15: import com.ibm.richtext.textlayout.attributes.AttributeSet;
16: import com.ibm.richtext.styledtext.StyleModifier;
17:
18: import com.ibm.richtext.textpanel.MTextPanel;
19: import com.ibm.richtext.textpanel.TextPanelEvent;
20: import com.ibm.richtext.uiimpl.resources.MenuData;
21:
22: public final class StyleMenuItemSet extends ChoiceMenuItemSet {
23:
24: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
25:
26: private Object fKey;
27: private boolean fCharacter;
28:
29: public StyleMenuItemSet(Object style, Object[] values,
30: MenuData[] menuData, boolean character) {
31:
32: super (values, menuData);
33: fKey = style;
34: fCharacter = character;
35: }
36:
37: protected void handleValueSelected(Object value) {
38:
39: MTextPanel textPanel = getTextPanel();
40: if (textPanel == null) {
41: throw new Error("Menu item is enabled when panel is null!");
42: }
43:
44: StyleModifier modifier;
45: if (value == null) {
46: AttributeSet set = new AttributeSet(fKey);
47: modifier = StyleModifier.createRemoveModifier(set);
48: } else {
49: modifier = StyleModifier.createAddModifier(fKey, value);
50: }
51:
52: if (fCharacter == CHARACTER) {
53: textPanel.modifyCharacterStyleOnSelection(modifier);
54: } else {
55: textPanel.modifyParagraphStyleOnSelection(modifier);
56: }
57: }
58:
59: protected Object getCurrentValue() {
60:
61: MTextPanel textPanel = getTextPanel();
62: if (textPanel == null) {
63: throw new Error("Shouldn't call this without a text panel!");
64: }
65:
66: if (fCharacter == CHARACTER) {
67: return textPanel.getCharacterStyleOverSelection(fKey);
68: } else {
69: return textPanel.getParagraphStyleOverSelection(fKey);
70: }
71: }
72:
73: public void textEventOccurred(TextPanelEvent event) {
74:
75: setChecked();
76: }
77:
78: public boolean respondsToEventType(int type) {
79:
80: return type == TextPanelEvent.SELECTION_STYLES_CHANGED;
81: }
82: }
|