]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/uiimpl/StyleMenuItemSet.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / uiimpl / StyleMenuItemSet.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.\r
3  *\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
12  */\r
13 package com.ibm.richtext.uiimpl;\r
14 \r
15 import com.ibm.richtext.textlayout.attributes.AttributeSet;\r
16 import com.ibm.richtext.styledtext.StyleModifier;\r
17 \r
18 import com.ibm.richtext.textpanel.MTextPanel;\r
19 import com.ibm.richtext.textpanel.TextPanelEvent;\r
20 import com.ibm.richtext.uiimpl.resources.MenuData;\r
21 \r
22 public final class StyleMenuItemSet extends ChoiceMenuItemSet {\r
23     \r
24     static final String COPYRIGHT =\r
25                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
26 \r
27     private Object fKey;\r
28     private boolean fCharacter;\r
29 \r
30     public StyleMenuItemSet(Object style,\r
31                             Object[] values,\r
32                             MenuData[] menuData,\r
33                             boolean character) {\r
34         \r
35         super(values, menuData);\r
36         fKey = style;\r
37         fCharacter = character;\r
38     }\r
39     \r
40     protected void handleValueSelected(Object value) {\r
41         \r
42         MTextPanel textPanel = getTextPanel();\r
43         if (textPanel == null) {\r
44             throw new Error("Menu item is enabled when panel is null!");\r
45         }\r
46         \r
47         StyleModifier modifier;\r
48         if (value == null) {\r
49             AttributeSet set = new AttributeSet(fKey);\r
50             modifier = StyleModifier.createRemoveModifier(set);\r
51         }\r
52         else {\r
53             modifier = StyleModifier.createAddModifier(fKey, value);\r
54         }\r
55                     \r
56         if (fCharacter == CHARACTER) {\r
57             textPanel.modifyCharacterStyleOnSelection(modifier);\r
58         }\r
59         else {\r
60             textPanel.modifyParagraphStyleOnSelection(modifier);\r
61         }\r
62     }\r
63     \r
64     protected Object getCurrentValue() {\r
65         \r
66         MTextPanel textPanel = getTextPanel();\r
67         if (textPanel == null) {\r
68             throw new Error("Shouldn't call this without a text panel!");\r
69         }\r
70         \r
71         if (fCharacter == CHARACTER) {\r
72             return textPanel.getCharacterStyleOverSelection(fKey);\r
73         }\r
74         else {\r
75             return textPanel.getParagraphStyleOverSelection(fKey);\r
76         }\r
77     }\r
78 \r
79     public void textEventOccurred(TextPanelEvent event) {\r
80         \r
81         setChecked();\r
82     }\r
83     \r
84     public boolean respondsToEventType(int type) {\r
85         \r
86         return type == TextPanelEvent.SELECTION_STYLES_CHANGED;\r
87     }\r
88 }