2 * (C) Copyright IBM Corp. 1998-2007. 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.awtui;
\r
15 import java.util.Hashtable;
\r
17 import com.ibm.richtext.textlayout.attributes.AttributeSet;
\r
18 import com.ibm.richtext.styledtext.StyleModifier;
\r
19 import com.ibm.richtext.textpanel.MTextPanel;
\r
20 import com.ibm.richtext.uiimpl.MenuItemSet;
\r
22 import com.ibm.richtext.uiimpl.resources.FrameResources;
\r
23 import com.ibm.richtext.uiimpl.ResourceUtils;
\r
25 import java.awt.Dialog;
\r
26 import java.awt.Frame;
\r
27 import java.awt.Button;
\r
28 import java.awt.Choice;
\r
29 import java.awt.Label;
\r
30 import java.awt.FlowLayout;
\r
31 import java.awt.Panel;
\r
32 import java.awt.GridLayout;
\r
34 import java.awt.event.ActionEvent;
\r
35 import java.awt.event.ActionListener;
\r
36 import java.awt.event.WindowEvent;
\r
37 import java.awt.event.WindowAdapter;
\r
40 * Simple dialog which gets a color
\r
42 final class ObjectDialog extends Dialog implements ActionListener
\r
47 private static final long serialVersionUID = 8667616278985420231L;
\r
48 //static final String COPYRIGHT =
\r
49 // "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
51 private final MTextPanel fTextPanel;
\r
52 private final Object fKey;
\r
53 private boolean fCharacter;
\r
55 private final Button fOKButton;
\r
56 private final Button fCancelButton;
\r
57 private final Choice fItems;
\r
58 private final Hashtable fNameToValueMap;
\r
60 * Construct a new ColorDialog.
\r
61 * @param parent the dialog's parent frame
\r
62 * @param title the dialogs title
\r
63 * @param message the message displayed next to the input box
\r
65 ObjectDialog(Frame parent,
\r
68 MTextPanel textPanel,
\r
74 super(parent, title, false);
\r
75 fTextPanel = textPanel;
\r
77 fCharacter = character;
\r
79 setLayout(new GridLayout(2, 1));
\r
81 Panel panel = new Panel();
\r
82 panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
\r
83 fItems = new Choice();
\r
85 if (names.length != values.length) {
\r
86 throw new IllegalArgumentException("Must have same number of names and values.");
\r
89 fNameToValueMap = new Hashtable(names.length);
\r
91 for (int i=0; i < names.length; i++) {
\r
92 fItems.add(names[i]);
\r
93 if (values[i] != null) {
\r
94 fNameToValueMap.put(names[i], values[i]);
\r
98 panel.add(new Label(message));
\r
101 add("North", panel);
\r
103 fCancelButton = new Button(ResourceUtils.getResourceString(FrameResources.CANCEL));
\r
104 fOKButton = new Button(ResourceUtils.getResourceString(FrameResources.OK));
\r
105 Panel p = new Panel();
\r
106 p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
\r
107 p.add(fCancelButton);
\r
113 addWindowListener(new WindowAdapter() {
\r
114 public void windowClosing(WindowEvent e) {
\r
115 closeWindow(false);
\r
119 fOKButton.addActionListener(this);
\r
120 fCancelButton.addActionListener(this);
\r
123 private void closeWindow(boolean sendAction) {
\r
127 Object value = fNameToValueMap.get(fItems.getSelectedItem());
\r
133 public void actionPerformed(ActionEvent e) {
\r
135 Object source = e.getSource();
\r
137 if (source == fOKButton) {
\r
140 else if (source == fCancelButton) {
\r
141 closeWindow(false);
\r
144 throw new IllegalArgumentException("Invalid ActionEvent!");
\r
149 * Handle the user input
\r
150 * @param obj the value object
\r
152 private void sendAction(Object value) {
\r
154 StyleModifier modifier;
\r
155 if (value != null) {
\r
156 modifier = StyleModifier.createAddModifier(fKey, value);
\r
159 AttributeSet set = new AttributeSet(fKey);
\r
160 modifier = StyleModifier.createRemoveModifier(set);
\r
163 if (fCharacter == MenuItemSet.CHARACTER) {
\r
164 fTextPanel.modifyCharacterStyleOnSelection(modifier);
\r
167 fTextPanel.modifyParagraphStyleOnSelection(modifier);
\r