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.swingui;
\r
15 import java.awt.Container;
\r
16 import java.awt.FlowLayout;
\r
17 import java.awt.Frame;
\r
19 import java.text.NumberFormat;
\r
20 import java.text.ParseException;
\r
22 import javax.swing.JDialog;
\r
23 import javax.swing.JPanel;
\r
24 import javax.swing.JTextField;
\r
25 import javax.swing.JButton;
\r
26 import javax.swing.JLabel;
\r
28 import java.awt.event.ActionEvent;
\r
29 import java.awt.event.ActionListener;
\r
30 import java.awt.event.WindowEvent;
\r
31 import java.awt.event.WindowAdapter;
\r
33 import com.ibm.richtext.uiimpl.resources.FrameResources;
\r
34 import com.ibm.richtext.uiimpl.MenuItemSet;
\r
35 import com.ibm.richtext.uiimpl.ResourceUtils;
\r
37 import com.ibm.richtext.styledtext.StyleModifier;
\r
38 import com.ibm.richtext.textpanel.MTextPanel;
\r
41 * Simple dialog which gets a number, and sends an appropriate command
\r
43 final class JNumberDialog extends JDialog implements ActionListener
\r
48 private static final long serialVersionUID = 8948601172508147011L;
\r
49 //static final String COPYRIGHT =
\r
50 // "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
51 private MTextPanel fTextPanel;
\r
52 private JTextField fInput = null;
\r
54 private JButton fOKButton = null;
\r
55 private JButton fCancelButton = null;
\r
56 private boolean fCharacter;
\r
57 private Object fKey;
\r
58 private float fMultiplier;
\r
61 * @param multiplier the factor by which to multiply the user's
\r
62 * selection before creating the attribute value. This
\r
63 * is useful for subscripting.
\r
65 JNumberDialog(Frame parent,
\r
68 MTextPanel textPanel,
\r
73 super(parent, title, false);
\r
74 fTextPanel = textPanel;
\r
76 fCharacter = character;
\r
77 fMultiplier = multiplier;
\r
79 Container content = getContentPane();
\r
81 content.setLayout(new java.awt.GridLayout(2,1));
\r
83 JPanel panel = new JPanel();
\r
84 panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
\r
85 fInput = new JTextField(5);
\r
87 panel.add(new JLabel(message));
\r
89 content.add("Center", panel);
\r
91 fCancelButton = new JButton(ResourceUtils.getResourceString(FrameResources.CANCEL));
\r
92 fOKButton = new JButton(ResourceUtils.getResourceString(FrameResources.OK));
\r
93 JPanel p = new JPanel();
\r
94 p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
\r
95 p.add(fCancelButton);
\r
97 content.add("South", p);
\r
101 addWindowListener(new WindowAdapter() {
\r
102 public void windowClosing(WindowEvent e) {
\r
103 closeWindow(false);
\r
107 fOKButton.addActionListener(this);
\r
108 fCancelButton.addActionListener(this);
\r
111 private void closeWindow(boolean sendAction) {
\r
118 String text = fInput.getText();
\r
119 num = NumberFormat.getInstance().parse(text).intValue();
\r
121 catch (ParseException exception) {
\r
122 sendAction = false;
\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 number The number the user typed in
\r
152 private void sendAction(int number) {
\r
153 float num = number * fMultiplier;
\r
154 StyleModifier modifier = StyleModifier.createAddModifier(
\r
157 if (fCharacter == MenuItemSet.CHARACTER) {
\r
158 fTextPanel.modifyCharacterStyleOnSelection(modifier);
\r
161 fTextPanel.modifyParagraphStyleOnSelection(modifier);
\r