7fd59977 |
1 | |
2 | //Title: AISDisplayMode sample |
3 | //Version: |
4 | //Copyright: Copyright (c) 1999 |
5 | //Author: |
6 | //Company: Matra Datavision |
7 | //Description: |
8 | |
9 | import java.awt.*; |
10 | import java.awt.event.*; |
11 | import java.util.*; |
12 | import java.math.*; |
13 | import javax.swing.*; |
14 | import javax.swing.event.*; |
15 | import util.*; |
16 | |
17 | |
18 | public class IsosDlg extends StandardDlg |
19 | implements InputMethodListener, |
20 | KeyListener |
21 | { |
22 | //-----------------------------------------------------------// |
23 | // GUI components |
24 | //-----------------------------------------------------------// |
25 | JTextField txtU; |
26 | JTextField txtV; |
27 | |
28 | private boolean consume = false; |
29 | private String strU = new String(""); |
30 | private String strV = new String(""); |
31 | |
32 | private int myUValue = 1; |
33 | private int myVValue = 1; |
34 | private boolean isOK = false; |
35 | |
36 | //=======================================================================// |
37 | // Construction |
38 | //=======================================================================// |
39 | public IsosDlg(Frame parent, int u, int v) |
40 | { |
41 | super(parent, "Isos", true, true, false, true); |
42 | myUValue = u; |
43 | myVValue = v; |
44 | |
45 | InitDlg(); |
46 | |
47 | strU = String.valueOf(myUValue); |
48 | strV = String.valueOf(myVValue); |
49 | txtU.setText(strU); |
50 | txtV.setText(strV); |
51 | |
52 | pack(); |
53 | } |
54 | |
55 | //-----------------------------------------------------------------------// |
56 | private void InitDlg() |
57 | { |
58 | JPanel aPane = new JPanel(new GridLayout(2, 2, 4, 4)); |
59 | |
60 | aPane.add(new JLabel("U Isos Number")); |
61 | |
62 | txtU = new JTextField(6); |
63 | txtU.addInputMethodListener(this); |
64 | txtU.addKeyListener(this); |
65 | txtU.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
66 | aPane.add(txtU); |
67 | |
68 | aPane.add(new JLabel("V Isos Number")); |
69 | |
70 | txtV = new JTextField(6); |
71 | txtV.addInputMethodListener(this); |
72 | txtV.addKeyListener(this); |
73 | txtV.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
74 | aPane.add(txtV); |
75 | |
76 | aPane.setBorder(BorderFactory.createEmptyBorder(5, 7, 5, 7)); |
77 | ControlsPanel.setLayout(new BorderLayout()); |
78 | ControlsPanel.add(aPane, BorderLayout.CENTER); |
79 | pack(); |
80 | setResizable(false); |
81 | } |
82 | |
83 | //=======================================================================// |
84 | public void OkAction() |
85 | { |
86 | Integer value; |
87 | String newValue; |
88 | |
89 | newValue = txtU.getText(); |
90 | value = new Integer(newValue.equals("")? "0" : newValue); |
91 | myUValue = value.intValue(); |
92 | |
93 | newValue = txtV.getText(); |
94 | value = new Integer(newValue.equals("")? "0" : newValue); |
95 | myVValue = value.intValue(); |
96 | |
97 | isOK = true; |
98 | dispose(); |
99 | } |
100 | |
101 | //-----------------------------------------------------------------------// |
102 | public void CancelAction() |
103 | { |
104 | isOK = false; |
105 | dispose(); |
106 | } |
107 | |
108 | |
109 | //=======================================================================// |
110 | public int getUValue() |
111 | { |
112 | return myUValue; |
113 | } |
114 | |
115 | //-----------------------------------------------------------------------// |
116 | public int getVValue() |
117 | { |
118 | return myVValue; |
119 | } |
120 | |
121 | //-----------------------------------------------------------------------// |
122 | public boolean isOK() |
123 | { |
124 | return isOK; |
125 | } |
126 | |
127 | |
128 | //=======================================================================// |
129 | // Key listener interface |
130 | //=======================================================================// |
131 | public void keyTyped(KeyEvent event) |
132 | { |
133 | } |
134 | |
135 | //=======================================================================// |
136 | public void keyPressed(KeyEvent event) |
137 | { |
138 | JTextField field = (JTextField) event.getSource(); |
139 | |
140 | int aKod = event.getKeyCode(); |
141 | if (!event.isActionKey() && aKod != event.VK_BACK_SPACE && |
142 | aKod != event.VK_DELETE) |
143 | { |
144 | if (!Character.isDigit(event.getKeyChar())) |
145 | consume = true; |
146 | } |
147 | } |
148 | |
149 | //=======================================================================// |
150 | public void keyReleased(KeyEvent event) |
151 | { |
152 | JTextField field = (JTextField) event.getSource(); |
153 | String newValue = field.getText(); |
154 | |
155 | if (field.equals(txtU)) |
156 | { |
157 | if (!newValue.equals(strU)) |
158 | { |
159 | if (consume) |
160 | { |
161 | txtU.setText(strU); |
162 | consume = false; |
163 | } |
164 | else |
165 | { |
166 | strU = newValue; |
167 | Integer value = new Integer(newValue.equals("")? "0" : newValue); |
168 | if (!(value.intValue()>0)) |
169 | { |
170 | txtU.selectAll(); |
171 | JOptionPane.showMessageDialog(this, "Please enter a positive value", |
172 | "Warning!!!", JOptionPane.WARNING_MESSAGE); |
173 | requestFocus(); |
174 | } |
175 | } |
176 | } |
177 | } |
178 | else if (field.equals(txtV)) |
179 | { |
180 | if (!newValue.equals(strV)) |
181 | { |
182 | if (consume) |
183 | { |
184 | txtV.setText(strV); |
185 | consume = false; |
186 | } |
187 | else |
188 | { |
189 | strV = newValue; |
190 | Integer value = new Integer(newValue.equals("")? "0" : newValue); |
191 | if (!(value.intValue()>0)) |
192 | { |
193 | txtV.selectAll(); |
194 | JOptionPane.showMessageDialog(this, "Please enter a positive value", |
195 | "Warning!!!", JOptionPane.WARNING_MESSAGE); |
196 | requestFocus(); |
197 | } |
198 | } |
199 | } |
200 | } |
201 | } |
202 | |
203 | //=======================================================================// |
204 | // InputMethod listener interface |
205 | //=======================================================================// |
206 | public void inputMethodTextChanged(InputMethodEvent event) |
207 | { |
208 | if (consume) |
209 | { |
210 | event.consume(); |
211 | consume = false; |
212 | } |
213 | } |
214 | |
215 | public void caretPositionChanged(InputMethodEvent event) |
216 | { |
217 | } |
218 | |
219 | } |