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 com.ibm.richtext.textlayout.attributes.AttributeSet;
\r
16 import com.ibm.richtext.styledtext.StyleModifier;
\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
22 public final class StyleMenuItemSet extends ChoiceMenuItemSet {
\r
24 static final String COPYRIGHT =
\r
25 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
27 private Object fKey;
\r
28 private boolean fCharacter;
\r
30 public StyleMenuItemSet(Object style,
\r
32 MenuData[] menuData,
\r
33 boolean character) {
\r
35 super(values, menuData);
\r
37 fCharacter = character;
\r
40 protected void handleValueSelected(Object value) {
\r
42 MTextPanel textPanel = getTextPanel();
\r
43 if (textPanel == null) {
\r
44 throw new Error("Menu item is enabled when panel is null!");
\r
47 StyleModifier modifier;
\r
48 if (value == null) {
\r
49 AttributeSet set = new AttributeSet(fKey);
\r
50 modifier = StyleModifier.createRemoveModifier(set);
\r
53 modifier = StyleModifier.createAddModifier(fKey, value);
\r
56 if (fCharacter == CHARACTER) {
\r
57 textPanel.modifyCharacterStyleOnSelection(modifier);
\r
60 textPanel.modifyParagraphStyleOnSelection(modifier);
\r
64 protected Object getCurrentValue() {
\r
66 MTextPanel textPanel = getTextPanel();
\r
67 if (textPanel == null) {
\r
68 throw new Error("Shouldn't call this without a text panel!");
\r
71 if (fCharacter == CHARACTER) {
\r
72 return textPanel.getCharacterStyleOverSelection(fKey);
\r
75 return textPanel.getParagraphStyleOverSelection(fKey);
\r
79 public void textEventOccurred(TextPanelEvent event) {
\r
84 public boolean respondsToEventType(int type) {
\r
86 return type == TextPanelEvent.SELECTION_STYLES_CHANGED;
\r