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.awt.FlowLayout;
\r
16 import java.awt.Dialog;
\r
17 import java.awt.TextField;
\r
18 import java.awt.Button;
\r
19 import java.awt.Frame;
\r
20 import java.awt.Panel;
\r
21 import java.awt.Label;
\r
23 import java.text.NumberFormat;
\r
24 import java.text.ParseException;
\r
26 import java.awt.event.ActionEvent;
\r
27 import java.awt.event.ActionListener;
\r
28 import java.awt.event.WindowEvent;
\r
29 import java.awt.event.WindowAdapter;
\r
31 import com.ibm.richtext.uiimpl.resources.FrameResources;
\r
32 import com.ibm.richtext.uiimpl.MenuItemSet;
\r
33 import com.ibm.richtext.uiimpl.ResourceUtils;
\r
35 import com.ibm.richtext.styledtext.StyleModifier;
\r
36 import com.ibm.richtext.textpanel.MTextPanel;
\r
39 * Simple dialog which gets a number, and sends an appropriate command
\r
41 final class NumberDialog extends Dialog implements ActionListener
\r
46 private static final long serialVersionUID = -2181405364377952745L;
\r
47 //static final String COPYRIGHT =
\r
48 // "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
49 private MTextPanel fTextPanel;
\r
50 private TextField fInput = null;
\r
51 private Button fOKButton = null;
\r
52 private Button fCancelButton = null;
\r
53 private boolean fCharacter;
\r
54 private Object fKey;
\r
55 private float fMultiplier;
\r
58 * @param multiplier the factor by which to multiply the user's
\r
59 * selection before creating the attribute value. This
\r
60 * is useful for subscripting.
\r
62 NumberDialog(Frame parent,
\r
65 MTextPanel textPanel,
\r
70 super(parent, title, false);
\r
71 fTextPanel = textPanel;
\r
73 fCharacter = character;
\r
74 fMultiplier = multiplier;
\r
75 setLayout(new java.awt.GridLayout(2,1));
\r
77 Panel panel = new Panel();
\r
78 panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
\r
79 fInput = new TextField(5);
\r
80 panel.add(new Label(message));
\r
82 add("Center", panel);
\r
84 fCancelButton = new Button(ResourceUtils.getResourceString(FrameResources.CANCEL));
\r
85 fOKButton = new Button(ResourceUtils.getResourceString(FrameResources.OK));
\r
86 Panel p = new Panel();
\r
87 p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
\r
88 p.add(fCancelButton);
\r
94 addWindowListener(new WindowAdapter() {
\r
95 public void windowClosing(WindowEvent e) {
\r
100 fOKButton.addActionListener(this);
\r
101 fCancelButton.addActionListener(this);
\r
104 private void closeWindow(boolean sendAction) {
\r
111 String text = fInput.getText();
\r
112 num = NumberFormat.getInstance().parse(text).intValue();
\r
114 catch (ParseException exception) {
\r
115 sendAction = false;
\r
126 public void actionPerformed(ActionEvent e) {
\r
128 Object source = e.getSource();
\r
130 if (source == fOKButton) {
\r
133 else if (source == fCancelButton) {
\r
134 closeWindow(false);
\r
137 throw new IllegalArgumentException("Invalid ActionEvent!");
\r
142 * Handle the user input
\r
143 * @param the number the user typed in
\r
145 private void sendAction(int number) {
\r
146 float num = number * fMultiplier;
\r
147 StyleModifier modifier = StyleModifier.createAddModifier(
\r
150 if (fCharacter == MenuItemSet.CHARACTER) {
\r
151 fTextPanel.modifyCharacterStyleOnSelection(modifier);
\r
154 fTextPanel.modifyParagraphStyleOnSelection(modifier);
\r