Mercurial > octave-nkf
comparison scripts/java/org/octave/JDialogBox.java @ 15753:6e39fe7992d9
style fixes and copyright update for java files
* ClassHelper.java, DlgListener.java, JDialogBox.java,
Matrix.java, OctClassLoader.java, Octave.java, OctaveReference.java,
TeXcode.java, TeXtranslator.java:
Use Octave copyright text. Style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 08 Dec 2012 00:24:45 -0500 |
parents | acf0addfc610 |
children | d63878346099 |
comparison
equal
deleted
inserted
replaced
15752:f96faf028d90 | 15753:6e39fe7992d9 |
---|---|
1 /* | 1 /* |
2 ** Copyright (C) 2010 Martin Hepperle | 2 |
3 ** | 3 Copyright (C) 2010 Martin Hepperle |
4 ** This program is free software; you can redistribute it and/or modify | 4 |
5 ** it under the terms of the GNU General Public License as published by | 5 This file is part of Octave. |
6 ** the Free Software Foundation; either version 2 of the License, or | 6 |
7 ** (at your option) any later version. | 7 Octave is free software; you can redistribute it and/or modify it |
8 ** | 8 under the terms of the GNU General Public License as published by |
9 ** This program is distributed in the hope that it will be useful, | 9 the Free Software Foundation; either version 3 of the License, or (at |
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 your option) any later version. |
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 |
12 ** GNU General Public License for more details. | 12 Octave is distributed in the hope that it will be useful, but |
13 ** | 13 WITHOUT ANY WARRANTY; without even the implied warranty of |
14 ** You should have received a copy of the GNU General Public License | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 ** along with this program; If not, see <http://www.gnu.org/licenses/>. | 15 General Public License for more details. |
16 */ | 16 |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
17 | 22 |
18 package org.octave; | 23 package org.octave; |
19 | 24 |
20 import java.net.*; | 25 import java.net.*; |
21 import java.util.*; | 26 import java.util.*; |
39 * @author Martin Hepperle | 44 * @author Martin Hepperle |
40 * @version 1.0 | 45 * @version 1.0 |
41 */ | 46 */ |
42 public class JDialogBox | 47 public class JDialogBox |
43 { | 48 { |
44 public static final int CLOSE_OK = 1; | 49 public static final int CLOSE_OK = 1; |
45 public static final int CLOSE_NO = 2; | 50 public static final int CLOSE_NO = 2; |
46 public static final int CLOSE_CANCEL = 3; | 51 public static final int CLOSE_CANCEL = 3; |
47 | 52 |
48 // dialog type | 53 // dialog type |
49 public static int FLAG_LABEL = 1; | 54 public static int FLAG_LABEL = 1; |
50 public static int FLAG_TEXT = 2; | 55 public static int FLAG_TEXT = 2; |
51 public static int FLAG_INPUT = 4; | 56 public static int FLAG_INPUT = 4; |
52 public static int FLAG_LIST = 8; | 57 public static int FLAG_LIST = 8; |
53 // icon selection | 58 // icon selection |
54 public static int FLAG_QUESTION = 32; | 59 public static int FLAG_QUESTION = 32; |
55 public static int FLAG_ERROR = 64; | 60 public static int FLAG_ERROR = 64; |
56 public static int FLAG_WARNING = 128; | 61 public static int FLAG_WARNING = 128; |
57 public static int FLAG_INFORMATION = 256; | 62 public static int FLAG_INFORMATION = 256; |
58 | 63 |
59 public static int DLG_QUEST = FLAG_QUESTION | FLAG_TEXT; | 64 public static int DLG_QUEST = FLAG_QUESTION | FLAG_TEXT; |
60 public static int DLG_INPUT = FLAG_QUESTION | FLAG_INPUT; | 65 public static int DLG_INPUT = FLAG_QUESTION | FLAG_INPUT; |
61 public static int DLG_LIST = FLAG_QUESTION | FLAG_LIST; | 66 public static int DLG_LIST = FLAG_QUESTION | FLAG_LIST; |
62 | 67 |
63 private final static String m_OK = "OK"; | 68 private final static String m_OK = "OK"; |
64 private final static String m_Yes = "Yes"; | 69 private final static String m_Yes = "Yes"; |
65 private final static String m_No = "No"; | 70 private final static String m_No = "No"; |
66 private final static String m_Cancel = "Cancel"; | 71 private final static String m_Cancel = "Cancel"; |
67 | 72 |
68 private JButton m_ButtonNO; | 73 private JButton m_ButtonNO; |
69 private JButton m_ButtonOK; | 74 private JButton m_ButtonOK; |
70 private JButton m_ButtonCANCEL; | 75 private JButton m_ButtonCANCEL; |
71 private JButton m_Focus; | 76 private JButton m_Focus; |
72 private JTextArea m_TextField[]; | 77 private JTextArea m_TextField[]; |
73 private JList m_List; | 78 private JList m_List; |
74 private JFrame m_ParentFrame; | 79 private JFrame m_ParentFrame; |
75 private int m_CloseMethod; | 80 private int m_CloseMethod; |
76 | 81 |
77 // ------------------------------------ | 82 // ------------------------------------ |
78 // implementation of listdlg function | 83 // implementation of listdlg function |
79 // ------------------------------------ | 84 // ------------------------------------ |
80 | 85 |
81 /** | 86 /** |
82 * | 87 * |
83 * @param listcell String[] - a array of strings, one for each list entry | 88 * @param listcell String[] - a array of strings, one for each list entry |
84 * @param selmode String | 89 * @param selmode String |
85 * @param sizecell Object[] | 90 * @param sizecell Object[] |
86 * @param initialcell Object[] | 91 * @param initialcell Object[] |
87 * @param name String | 92 * @param name String |
88 * @param promptcell String[] | 93 * @param promptcell String[] |
89 * @param okstring String | 94 * @param okstring String |
90 * @param cancelstring String | 95 * @param cancelstring String |
91 * @return String[] | 96 * @return String[] |
92 */ | 97 */ |
93 public static int[] listdlg ( String[] listcell, | 98 public static int[] listdlg (String[] listcell, |
94 String selmode, | 99 String selmode, |
95 Object[] sizecell, | 100 Object[] sizecell, |
96 Object[] initialcell, | 101 Object[] initialcell, |
97 String name, | 102 String name, |
98 String[] promptcell, | 103 String[] promptcell, |
99 String okstring, | 104 String okstring, |
100 String cancelstring ) | 105 String cancelstring) |
101 { | 106 { |
102 JDialogBox d = new JDialogBox (); | 107 JDialogBox d = new JDialogBox (); |
103 d.genericdlg ( promptcell, listcell, name, selmode, | 108 d.genericdlg (promptcell, listcell, name, selmode, |
104 DLG_LIST, | 109 DLG_LIST, |
105 sizecell, initialcell, okstring, null, cancelstring ); | 110 sizecell, initialcell, okstring, null, cancelstring); |
106 return ( d.getSelectedIndices () ); | 111 return (d.getSelectedIndices ()); |
107 } | 112 } |
108 | 113 |
109 | 114 |
110 // ------------------------------------ | 115 // ------------------------------------ |
111 // implementation of inputdlg function | 116 // implementation of inputdlg function |
112 // ------------------------------------- | 117 // ------------------------------------- |
113 | 118 |
114 /** | 119 /** |
115 * Implements a variation of the inputdlg function. | 120 * Implements a variation of the inputdlg function. |
116 * | 121 * |
117 * @param prompt String[] - an array of text strings to be used as labels. | 122 * @param prompt String[] - an array of text strings to be used as labels. |
118 * @param title String - a text string to be used to label the dialog caption. | 123 * @param title String - a text string to be used to label the dialog caption. |
119 * @param RowsCols int - defines the width of the text fields in columns. | 124 * @param RowsCols int - defines the width of the text fields in columns. |
120 * @param defaults Object[] - an array of text strings or numbers to be | 125 * @param defaults Object[] - an array of text strings or numbers to be |
121 * placed into the text fields as default values. | 126 * placed into the text fields as default values. |
122 * @return String[] - an array of text strings containing the content of the | 127 * @return String[] - an array of text strings containing the content of the |
123 * text fields. | 128 * text fields. |
124 */ | 129 */ |
125 public static String[] inputdlg ( String[] prompt, | 130 public static String[] inputdlg (String[] prompt, |
126 String title, | 131 String title, |
127 Object[] RowsCols, | 132 Object[] RowsCols, |
128 Object[] defaults ) | 133 Object[] defaults) |
129 { | 134 { |
130 JDialogBox d = new JDialogBox (); | 135 JDialogBox d = new JDialogBox (); |
131 d.genericdlg ( prompt, null, title, "on", | 136 d.genericdlg (prompt, null, title, "on", |
132 FLAG_INPUT | FLAG_QUESTION, | 137 FLAG_INPUT | FLAG_QUESTION, |
133 RowsCols, defaults, m_OK, null, m_Cancel ); | 138 RowsCols, defaults, m_OK, null, m_Cancel); |
134 return ( d.getInput () ); | 139 return (d.getInput ()); |
135 } | 140 } |
136 | 141 |
137 | 142 |
138 /** | 143 /** |
139 * Extract the current content from the text fields of an inputdlg. | 144 * Extract the current content from the text fields of an inputdlg. |
140 * | 145 * |
141 * @return String[] - the text contained in the fields of an inputdlg. | 146 * @return String[] - the text contained in the fields of an inputdlg. |
142 * null if the dialog was cancelled. | 147 * null if the dialog was cancelled. |
143 */ | 148 */ |
144 private String[] getInput () | 149 private String[] getInput () |
145 { | 150 { |
146 String s[] = null; | 151 String s[] = null; |
147 | 152 |
148 if ( m_CloseMethod == CLOSE_OK ) | 153 if (m_CloseMethod == CLOSE_OK) |
149 { | 154 { |
150 s = new String[m_TextField.length]; | 155 s = new String[m_TextField.length]; |
151 | 156 |
152 for ( int i = 0; i < s.length; i++ ) | 157 for (int i = 0; i < s.length; i++) |
153 { | 158 { |
154 s[i] = new String ( m_TextField[i].getText () ); | 159 s[i] = new String (m_TextField[i].getText ()); |
155 } | 160 } |
156 } | 161 } |
157 | 162 |
158 return ( s ); | 163 return (s); |
159 } | 164 } |
160 | 165 |
161 | 166 |
162 private String getResult () | 167 private String getResult () |
163 { | 168 { |
164 String s = null; | 169 String s = null; |
165 | 170 |
166 if ( m_CloseMethod == CLOSE_OK ) | 171 if (m_CloseMethod == CLOSE_OK) |
167 { | 172 { |
168 s = m_ButtonOK.getText (); | 173 s = m_ButtonOK.getText (); |
169 } | 174 } |
170 else if ( m_CloseMethod == CLOSE_CANCEL ) | 175 else if (m_CloseMethod == CLOSE_CANCEL) |
171 { | 176 { |
172 s = m_ButtonCANCEL.getText (); | 177 s = m_ButtonCANCEL.getText (); |
173 } | 178 } |
174 else | 179 else |
175 { | 180 { |
176 s = m_ButtonNO.getText (); | 181 s = m_ButtonNO.getText (); |
177 } | 182 } |
178 | 183 |
179 return ( s ); | 184 return (s); |
180 } | 185 } |
181 | 186 |
182 | 187 |
183 /** | 188 /** |
184 * Extract the current content from the text fields of an inputdlg. | 189 * Extract the current content from the text fields of an inputdlg. |
185 * | 190 * |
186 * @return String[] - the text contained in the fields of an inputdlg. | 191 * @return String[] - the text contained in the fields of an inputdlg. |
187 * null if the dialog was cancelled. | 192 * null if the dialog was cancelled. |
188 */ | 193 */ |
189 private String[] getSelection () | 194 private String[] getSelection () |
190 { | 195 { |
191 String s[] = null; | 196 String s[] = null; |
192 | 197 |
193 if ( m_CloseMethod == CLOSE_OK ) | 198 if (m_CloseMethod == CLOSE_OK) |
194 { | 199 { |
195 int selection[] = m_List.getSelectedIndices (); | 200 int selection[] = m_List.getSelectedIndices (); |
196 | 201 |
197 s = new String[selection.length]; | 202 s = new String[selection.length]; |
198 | 203 |
199 for ( int i = 0; i < s.length; i++ ) | 204 for (int i = 0; i < s.length; i++) |
200 { | 205 { |
201 | 206 |
202 // s[i] = new String ( Integer.toString(selection[i]) ); | 207 // s[i] = new String (Integer.toString(selection[i])); |
203 s[i] = ( m_List.getSelectedValues ()[i] ).toString (); | 208 s[i] = (m_List.getSelectedValues ()[i]).toString (); |
204 } | 209 } |
205 } | 210 } |
206 | 211 |
207 return ( s ); | 212 return (s); |
208 } | 213 } |
209 | 214 |
210 | 215 |
211 private int[] getSelectedIndices () | 216 private int[] getSelectedIndices () |
212 { | 217 { |
213 int s[] = null; | 218 int s[] = null; |
214 | 219 |
215 if ( m_CloseMethod == CLOSE_OK ) | 220 if (m_CloseMethod == CLOSE_OK) |
216 { | 221 { |
217 s = m_List.getSelectedIndices (); | 222 s = m_List.getSelectedIndices (); |
218 for ( int i = 0; i < s.length; i++ ) | 223 for (int i = 0; i < s.length; i++) |
219 { | 224 { |
220 | 225 |
221 // translate to 1 based indices | 226 // translate to 1 based indices |
222 s[i] = s[i] + 1; | 227 s[i] = s[i] + 1; |
223 } | 228 } |
224 } | 229 } |
225 | 230 |
226 return ( s ); | 231 return (s); |
227 } | 232 } |
228 | 233 |
229 | 234 |
230 public void SelectAll () | 235 public void SelectAll () |
231 { | 236 { |
232 if ( null != m_List ) | 237 if (null != m_List) |
233 { | 238 { |
234 m_List.setSelectionInterval ( 0, m_List.getModel ().getSize () - 1 ); | 239 m_List.setSelectionInterval (0, m_List.getModel ().getSize () - 1); |
235 } | 240 } |
236 } | 241 } |
237 | 242 |
238 | 243 |
239 // ------------------------------------- | 244 // ------------------------------------- |
240 // implementation of helpdlg function | 245 // implementation of helpdlg function |
241 // ------------------------------------- | 246 // ------------------------------------- |
242 | 247 |
243 /** | 248 /** |
244 * Implements a simple helpdlg with default text and caption. Not very useful. | 249 * Implements a simple helpdlg with default text and caption. Not very useful. |
245 * | 250 * |
246 * Octave > helpdlg('helpstring','title') | 251 * Octave > helpdlg('helpstring','title') |
247 * | 252 * |
248 * Called via helpdlg.m. | 253 * Called via helpdlg.m. |
249 * | 254 * |
250 * @param helpstring String - a message string to be presented to the user. | 255 * @param helpstring String - a message string to be presented to the user. |
251 * The string can have embedded newline (\n) characters to break the message | 256 * The string can have embedded newline (\n) characters to break the message |
252 * into multiple lines. | 257 * into multiple lines. |
253 * @param title String - a text string to be used to label the dialog caption. | 258 * @param title String - a text string to be used to label the dialog caption. |
254 * @return int - always 1 | 259 * @return int - always 1 |
255 */ | 260 */ |
256 public static int helpdlg ( String helpstring, String title ) | 261 public static int helpdlg (String helpstring, String title) |
257 { | 262 { |
258 JDialogBox d = new JDialogBox (); | 263 JDialogBox d = new JDialogBox (); |
259 String s[] = new String[1]; | 264 String s[] = new String[1]; |
260 s[0] = helpstring; | 265 s[0] = helpstring; |
261 return ( d.genericdlg ( s, null, title, "on", | 266 return (d.genericdlg (s, null, title, "on", |
262 FLAG_TEXT | FLAG_INFORMATION, null, null, | 267 FLAG_TEXT | FLAG_INFORMATION, null, null, |
263 m_OK, null, m_Cancel ) ); | 268 m_OK, null, m_Cancel)); |
264 } | 269 } |
265 | 270 |
266 | 271 |
267 // ------------------------------------- | 272 // ------------------------------------- |
268 // implementation of emptydlg function | 273 // implementation of emptydlg function |
269 // ------------------------------------- | 274 // ------------------------------------- |
270 | 275 |
271 /** | 276 /** |
272 * Implements a simple helpdlg with default text and caption. Not very useful. | 277 * Implements a simple helpdlg with default text and caption. Not very useful. |
273 * | 278 * |
274 * Octave > emptydlg('messagestring','title') | 279 * Octave > emptydlg('messagestring','title') |
275 * | 280 * |
276 * Called via dlgbox.m. | 281 * Called via dlgbox.m. |
277 * | 282 * |
278 * @param messagestring String - a message string to be presented to the user. | 283 * @param messagestring String - a message string to be presented to the user. |
279 * The string can have embedded newline (\n) characters to break the message | 284 * The string can have embedded newline (\n) characters to break the message |
280 * into multiple lines. | 285 * into multiple lines. |
281 * @param title String - a text string to be used to label the dialog caption. | 286 * @param title String - a text string to be used to label the dialog caption. |
282 * @return int - always 1 | 287 * @return int - always 1 |
283 */ | 288 */ |
284 public static int emptydlg ( String helpstring, String title ) | 289 public static int emptydlg (String helpstring, String title) |
285 { | 290 { |
286 JDialogBox d = new JDialogBox (); | 291 JDialogBox d = new JDialogBox (); |
287 String s[] = new String[1]; | 292 String s[] = new String[1]; |
288 s[0] = helpstring; | 293 s[0] = helpstring; |
289 return ( d.genericdlg ( s, null, title, "on", | 294 return (d.genericdlg (s, null, title, "on", |
290 FLAG_TEXT, null, null, | 295 FLAG_TEXT, null, null, |
291 m_OK, null, m_Cancel ) ); | 296 m_OK, null, m_Cancel)); |
292 } | 297 } |
293 | 298 |
294 | 299 |
295 // ------------------------------------------- | 300 // ------------------------------------------- |
296 // implementation of questdlg related functions | 301 // implementation of questdlg related functions |
297 // ------------------------------------------- | 302 // ------------------------------------------- |
298 | 303 |
299 /** | 304 /** |
300 * Implements a simple questdlg with default text and caption. Not very useful. | 305 * Implements a simple questdlg with default text and caption. Not very useful. |
301 * | 306 * |
302 * @param question String - the question to be presented | 307 * @param question String - the question to be presented |
303 * @param title String - the caption | 308 * @param title String - the caption |
304 * @param options String[] - 'str1', 'str2', 'str3', 'default' | 309 * @param options String[] - 'str1', 'str2', 'str3', 'default' |
305 * @return String - the caption of the button pressed by the user | 310 * @return String - the caption of the button pressed by the user |
306 */ | 311 */ |
307 public static String questdlg ( String question, | 312 public static String questdlg (String question, |
308 String title, | 313 String title, |
309 String[] options ) | 314 String[] options) |
310 { | 315 { |
311 JDialogBox d = new JDialogBox (); | 316 JDialogBox d = new JDialogBox (); |
312 String s[] = new String[1]; | 317 String s[] = new String[1]; |
313 s[0] = question; | 318 s[0] = question; |
314 d.genericdlg ( s, options, title, "on", | 319 d.genericdlg (s, options, title, "on", |
315 DLG_QUEST, null, null, | 320 DLG_QUEST, null, null, |
316 options[0], options[1], options[2] ); | 321 options[0], options[1], options[2]); |
317 return ( d.getResult () ); | 322 return (d.getResult ()); |
318 } | 323 } |
319 | 324 |
320 | 325 |
321 // ------------------------------------- | 326 // ------------------------------------- |
322 // implementation of errordlg function | 327 // implementation of errordlg function |
323 // ------------------------------------- | 328 // ------------------------------------- |
324 | 329 |
325 /** | 330 /** |
326 * Implements a simple errordlg with default text and caption. Not very useful. | 331 * Implements a simple errordlg with default text and caption. Not very useful. |
327 * | 332 * |
328 * @param errorstring String - the error message to display. | 333 * @param errorstring String - the error message to display. |
329 * @param dlgname String - the caption of the dialog box. | 334 * @param dlgname String - the caption of the dialog box. |
330 * @return int - always 1 | 335 * @return int - always 1 |
331 */ | 336 */ |
332 public static int errordlg ( String errorstring, String dlgname ) | 337 public static int errordlg (String errorstring, String dlgname) |
333 { | 338 { |
334 JDialogBox d = new JDialogBox (); | 339 JDialogBox d = new JDialogBox (); |
335 String s[] = new String[1]; | 340 String s[] = new String[1]; |
336 s[0] = errorstring; | 341 s[0] = errorstring; |
337 return ( d.genericdlg ( s, null, dlgname, "on", FLAG_TEXT | FLAG_ERROR, | 342 return (d.genericdlg (s, null, dlgname, "on", FLAG_TEXT | FLAG_ERROR, |
338 null, null, | 343 null, null, |
339 m_OK, null, m_Cancel ) ); | 344 m_OK, null, m_Cancel)); |
340 } | 345 } |
341 | 346 |
342 | 347 |
343 // ------------------------------------------- | 348 // ------------------------------------------- |
344 // implementation of warndlg related functions | 349 // implementation of warndlg related functions |
345 // ------------------------------------------- | 350 // ------------------------------------------- |
346 | 351 |
347 /** | 352 /** |
348 * Implements a simple warndlg with default text and caption. Not very useful. | 353 * Implements a simple warndlg with default text and caption. Not very useful. |
349 * | 354 * |
350 * Called via warndlg.m. | 355 * Called via warndlg.m. |
351 * | 356 * |
352 * @param errorstring String - the message to be presented to the user. | 357 * @param errorstring String - the message to be presented to the user. |
353 * @param dlgname String - the caption of the dialog box. | 358 * @param dlgname String - the caption of the dialog box. |
354 * @return int - always 1 | 359 * @return int - always 1 |
355 */ | 360 */ |
356 public static int warndlg ( String errorstring, String dlgname ) | 361 public static int warndlg (String errorstring, String dlgname) |
357 { | 362 { |
358 JDialogBox d = new JDialogBox (); | 363 JDialogBox d = new JDialogBox (); |
359 String s[] = new String[1]; | 364 String s[] = new String[1]; |
360 s[0] = errorstring; | 365 s[0] = errorstring; |
361 return ( d.genericdlg ( s, null, dlgname, "on", FLAG_TEXT | FLAG_WARNING, | 366 return (d.genericdlg (s, null, dlgname, "on", FLAG_TEXT | FLAG_WARNING, |
362 null, null, | 367 null, null, |
363 m_OK, null, m_Cancel ) ); | 368 m_OK, null, m_Cancel)); |
364 } | 369 } |
365 | 370 |
366 | 371 |
367 // ------------------------------------- | 372 // ------------------------------------- |
368 // generic dlg function | 373 // generic dlg function |
369 // ------------------------------------- | 374 // ------------------------------------- |
370 /** | 375 /** |
371 * A generic dialog creation and display function. | 376 * A generic dialog creation and display function. |
372 * | 377 * |
373 * @param message String[] | 378 * @param message String[] |
374 * @param list String[] | 379 * @param list String[] |
375 * @param caption String | 380 * @param caption String |
376 * @param on String | 381 * @param on String |
377 * @param flag int | 382 * @param flag int |
378 * @param RowsCols Object[] | 383 * @param RowsCols Object[] |
379 * @param defaults Object[] | 384 * @param defaults Object[] |
380 * @param okstring String | 385 * @param okstring String |
381 * @param nostring String | 386 * @param nostring String |
382 * @param cancelstring String | 387 * @param cancelstring String |
383 * @return int | 388 * @return int |
384 */ | 389 */ |
385 public int genericdlg ( String message[], | 390 public int genericdlg (String message[], |
386 String list[], | 391 String list[], |
387 String caption, | 392 String caption, |
388 String on, | 393 String on, |
389 int flag, | 394 int flag, |
390 Object[] RowsCols, | 395 Object[] RowsCols, |
391 Object[] defaults, | 396 Object[] defaults, |
392 String okstring, | 397 String okstring, |
393 String nostring, | 398 String nostring, |
394 String cancelstring ) | 399 String cancelstring) |
395 { | 400 { |
396 TeXtranslator theTranslator = new TeXtranslator (); | 401 TeXtranslator theTranslator = new TeXtranslator (); |
397 setSystemLnF ( true ); | 402 setSystemLnF (true); |
398 | 403 |
399 caption = theTranslator.replace ( caption ); | 404 caption = theTranslator.replace (caption); |
400 | 405 |
401 m_ButtonNO = null; | 406 m_ButtonNO = null; |
402 m_ButtonOK = null; | 407 m_ButtonOK = null; |
403 m_ButtonCANCEL = null; | 408 m_ButtonCANCEL = null; |
404 | 409 |
405 // create a modal dialog with an empty frame as its parent | 410 // create a modal dialog with an empty frame as its parent |
406 m_ParentFrame = new JFrame (); | 411 m_ParentFrame = new JFrame (); |
407 | 412 |
408 // --- trick to bring dialog to the front | 413 // --- trick to bring dialog to the front |
409 // In Windows, the dialog is not brought to the foreground, but hidden | 414 // In Windows, the dialog is not brought to the foreground, but hidden |
410 // behind the Octave window as long as the parent frame is not visible. | 415 // behind the Octave window as long as the parent frame is not visible. |
411 // To avoid that the frame is visible, we move it outside of the screen. | 416 // To avoid that the frame is visible, we move it outside of the screen. |
412 m_ParentFrame.setBounds ( Toolkit.getDefaultToolkit ().getScreenSize (). | 417 m_ParentFrame.setBounds (Toolkit.getDefaultToolkit ().getScreenSize (). |
413 width + 100, | 418 width + 100, |
414 Toolkit.getDefaultToolkit ().getScreenSize (). | 419 Toolkit.getDefaultToolkit ().getScreenSize (). |
415 height + 100, 1, 1 ); | 420 height + 100, 1, 1); |
416 m_ParentFrame.setVisible ( true ); | 421 m_ParentFrame.setVisible (true); |
417 //-- end of trick | 422 //-- end of trick |
418 | 423 |
419 JDialog dlg; | 424 JDialog dlg; |
420 dlg = new JDialog ( m_ParentFrame ); | 425 dlg = new JDialog (m_ParentFrame); |
421 dlg.setTitle ( caption ); | 426 dlg.setTitle (caption); |
422 | 427 |
423 dlg.setModal ( true ); | 428 dlg.setModal (true); |
424 dlg.setDefaultCloseOperation ( JDialog.DISPOSE_ON_CLOSE ); | 429 dlg.setDefaultCloseOperation (JDialog.DISPOSE_ON_CLOSE); |
425 | 430 |
426 DlgListener theListener = new DlgListener ( this ); | 431 DlgListener theListener = new DlgListener (this); |
427 | 432 |
428 Container d = dlg.getContentPane (); | 433 Container d = dlg.getContentPane (); |
429 d.setLayout ( new BorderLayout ( 8, 8 ) ); | 434 d.setLayout (new BorderLayout (8, 8)); |
430 | 435 |
431 // spacer | 436 // spacer |
432 d.add ( new JLabel ( " " ), BorderLayout.NORTH ); | 437 d.add (new JLabel (" "), BorderLayout.NORTH); |
433 d.add ( new JLabel ( " " ), BorderLayout.EAST ); | 438 d.add (new JLabel (" "), BorderLayout.EAST); |
434 | 439 |
435 JPanel p = new JPanel (); | 440 JPanel p = new JPanel (); |
436 | 441 |
437 if ( FLAG_LABEL == ( FLAG_LABEL & flag ) ) | 442 if (FLAG_LABEL == (FLAG_LABEL & flag)) |
438 { | 443 { |
439 // a single line label | 444 // a single line label |
440 JLabel l = new JLabel ( theTranslator.replace ( message[0] ) ); | 445 JLabel l = new JLabel (theTranslator.replace (message[0])); |
441 p.add ( l ); | 446 p.add (l); |
442 } | 447 } |
443 else if ( FLAG_TEXT == ( FLAG_TEXT & flag ) ) | 448 else if (FLAG_TEXT == (FLAG_TEXT & flag)) |
444 { | 449 { |
445 String msg = theTranslator.replace ( message[0] ); | 450 String msg = theTranslator.replace (message[0]); |
446 // a multi-line text display for helpdlg | 451 // a multi-line text display for helpdlg |
447 StringTokenizer st = new StringTokenizer ( msg, "\n" ); | 452 StringTokenizer st = new StringTokenizer (msg, "\n"); |
448 | 453 |
449 int nRows = ( null == RowsCols ) ? 1 : | 454 int nRows = (null == RowsCols) ? 1 : |
450 Integer.parseInt ( RowsCols[0].toString () ); | 455 Integer.parseInt (RowsCols[0].toString ()); |
451 nRows = Math.max ( nRows, st.countTokens () ); | 456 nRows = Math.max (nRows, st.countTokens ()); |
452 int nCols = Math.max ( 1, msg.length () / nRows ); | 457 int nCols = Math.max (1, msg.length () / nRows); |
453 | 458 |
454 p.setLayout ( new GridLayout ( message.length, 1 ) ); | 459 p.setLayout (new GridLayout (message.length, 1)); |
455 JTextArea ta = new JTextArea ( msg, nRows, nCols ); | 460 JTextArea ta = new JTextArea (msg, nRows, nCols); |
456 ta.setEditable ( false ); | 461 ta.setEditable (false); |
457 ta.setFocusable ( false ); | 462 ta.setFocusable (false); |
458 ta.setOpaque ( false ); | 463 ta.setOpaque (false); |
459 // replace ugly monospaced font | 464 // replace ugly monospaced font |
460 ta.setFont ( p.getFont () ); | 465 ta.setFont (p.getFont ()); |
461 p.add ( ta ); | 466 p.add (ta); |
462 } | 467 } |
463 else if ( FLAG_INPUT == ( FLAG_INPUT & flag ) ) | 468 else if (FLAG_INPUT == (FLAG_INPUT & flag)) |
464 { | 469 { |
465 // a multi label/textfield entry dialog for inputdlg | 470 // a multi label/textfield entry dialog for inputdlg |
466 GridBagConstraints gbc = new GridBagConstraints (); | 471 GridBagConstraints gbc = new GridBagConstraints (); |
467 gbc.insets.top = 4; | 472 gbc.insets.top = 4; |
468 gbc.insets.left = 8; | 473 gbc.insets.left = 8; |
469 gbc.gridx = 0; | 474 gbc.gridx = 0; |
470 gbc.anchor = GridBagConstraints.NORTHWEST; | 475 gbc.anchor = GridBagConstraints.NORTHWEST; |
471 | 476 |
472 p.setLayout ( new GridBagLayout () ); | 477 p.setLayout (new GridBagLayout ()); |
473 m_TextField = new JTextArea[message.length]; | 478 m_TextField = new JTextArea[message.length]; |
474 | 479 |
475 // default values | 480 // default values |
476 int nRows = 1; | 481 int nRows = 1; |
477 int nCols = 10; | 482 int nCols = 10; |
478 | 483 |
479 for ( int i = 0; i < message.length; i++ ) | 484 for (int i = 0; i < message.length; i++) |
480 { | 485 { |
481 String msg = theTranslator.replace ( message[i] ); | 486 String msg = theTranslator.replace (message[i]); |
482 JLabel l = new JLabel ( msg ); | 487 JLabel l = new JLabel (msg); |
483 l.setHorizontalAlignment ( Label.LEFT ); | 488 l.setHorizontalAlignment (Label.LEFT); |
484 gbc.gridy = 2 * i; | 489 gbc.gridy = 2 * i; |
485 p.add ( l, gbc ); | 490 p.add (l, gbc); |
486 /** | 491 /** |
487 * @todo CHECK handling of RowsCols for inputdlg | 492 * @todo CHECK handling of RowsCols for inputdlg |
488 */ | 493 */ |
489 if ( RowsCols != null ) | 494 if (RowsCols != null) |
490 { | 495 { |
491 if ( RowsCols.length == 2 * message.length ) | 496 if (RowsCols.length == 2 * message.length) |
492 { | 497 { |
493 nRows = Integer.parseInt ( RowsCols[i].toString () ); | 498 nRows = Integer.parseInt (RowsCols[i].toString ()); |
494 nCols = Integer.parseInt ( RowsCols[RowsCols.length / 2 + | 499 nCols = Integer.parseInt (RowsCols[RowsCols.length / 2 + |
495 i].toString () ); | 500 i].toString ()); |
496 } | 501 } |
497 } | 502 } |
498 | 503 |
499 m_TextField[i] = new JTextArea ( "", Math.max ( nRows, 1 ), nCols ); | 504 m_TextField[i] = new JTextArea ("", Math.max (nRows, 1), nCols); |
500 // avoid resizing | 505 // avoid resizing |
501 m_TextField[i].setPreferredSize ( new Dimension ( Math.max ( nRows, | 506 m_TextField[i].setPreferredSize (new Dimension (Math.max (nRows, |
502 1 ), nCols ) ); | 507 1), nCols)); |
503 m_TextField[i].setAutoscrolls ( false ); | 508 m_TextField[i].setAutoscrolls (false); |
504 m_TextField[i].setFont ( p.getFont () ); | 509 m_TextField[i].setFont (p.getFont ()); |
505 m_TextField[i].setBorder ( new javax.swing.border.EtchedBorder () ); | 510 m_TextField[i].setBorder (new javax.swing.border.EtchedBorder ()); |
506 m_TextField[i].addKeyListener ( theListener ); | 511 m_TextField[i].addKeyListener (theListener); |
507 | 512 |
508 gbc.gridy = 2 * i + 1; | 513 gbc.gridy = 2 * i + 1; |
509 p.add ( m_TextField[i], gbc ); | 514 p.add (m_TextField[i], gbc); |
510 } | 515 } |
511 | 516 |
512 if ( defaults != null ) | 517 if (defaults != null) |
513 { | 518 { |
514 if ( defaults.length == message.length ) | 519 if (defaults.length == message.length) |
515 { | 520 { |
516 for ( int i = 0; i < message.length; i++ ) | 521 for (int i = 0; i < message.length; i++) |
517 { | 522 { |
518 String def = theTranslator.replace ( defaults[i].toString () ); | 523 String def = theTranslator.replace (defaults[i].toString ()); |
519 m_TextField[i].setText ( def ); | 524 m_TextField[i].setText (def); |
520 } | 525 } |
521 } | 526 } |
522 } | 527 } |
523 } | 528 } |
524 else if ( DLG_LIST == ( DLG_LIST & flag ) ) | 529 else if (DLG_LIST == (DLG_LIST & flag)) |
525 { | 530 { |
526 GridBagConstraints gbc = new GridBagConstraints (); | 531 GridBagConstraints gbc = new GridBagConstraints (); |
527 gbc.insets.top = 4; | 532 gbc.insets.top = 4; |
528 gbc.insets.left = 8; | 533 gbc.insets.left = 8; |
529 gbc.gridx = 0; | 534 gbc.gridx = 0; |
530 gbc.anchor = GridBagConstraints.NORTHWEST; | 535 gbc.anchor = GridBagConstraints.NORTHWEST; |
531 | 536 |
532 p.setLayout ( new GridBagLayout () ); | 537 p.setLayout (new GridBagLayout ()); |
533 | 538 |
534 for ( int i = 0; i < message.length; i++ ) | 539 for (int i = 0; i < message.length; i++) |
535 { | 540 { |
536 // a single line label | 541 // a single line label |
537 String msg = theTranslator.replace ( message[i] ); | 542 String msg = theTranslator.replace (message[i]); |
538 JLabel l = new JLabel ( msg ); | 543 JLabel l = new JLabel (msg); |
539 gbc.gridy = i; | 544 gbc.gridy = i; |
540 p.add ( l, gbc ); | 545 p.add (l, gbc); |
541 } | 546 } |
542 | 547 |
543 String lst[] = new String[list.length]; | 548 String lst[] = new String[list.length]; |
544 | 549 |
545 for ( int i = 0; i < list.length; i++ ) | 550 for (int i = 0; i < list.length; i++) |
546 { | 551 { |
547 lst[i] = theTranslator.replace ( list[i] ); | 552 lst[i] = theTranslator.replace (list[i]); |
548 } | 553 } |
549 m_List = new JList ( lst ); | 554 m_List = new JList (lst); |
550 | 555 |
551 // replace ugly monospaced font | 556 // replace ugly monospaced font |
552 m_List.setFont ( p.getFont () ); | 557 m_List.setFont (p.getFont ()); |
553 | 558 |
554 m_List.setMinimumSize ( new Dimension ( Math.max ( 1, | 559 m_List.setMinimumSize (new Dimension (Math.max (1, |
555 Integer.parseInt ( RowsCols[0].toString () ) ), | 560 Integer.parseInt (RowsCols[0].toString ())), |
556 Math.max ( 1, | 561 Math.max (1, |
557 Integer.parseInt ( RowsCols[1].toString () ) ) ) ); | 562 Integer.parseInt (RowsCols[1].toString ())))); |
558 m_List.setPreferredSize ( new Dimension ( Math.max ( 1, | 563 m_List.setPreferredSize (new Dimension (Math.max (1, |
559 Integer.parseInt ( RowsCols[1].toString () ) ), | 564 Integer.parseInt (RowsCols[1].toString ())), |
560 Math.max ( 1, | 565 Math.max (1, |
561 Integer.parseInt ( RowsCols[0].toString () ) ) ) ); | 566 Integer.parseInt (RowsCols[0].toString ())))); |
562 m_List.setBorder ( new javax.swing.border.EtchedBorder () ); | 567 m_List.setBorder (new javax.swing.border.EtchedBorder ()); |
563 | 568 |
564 gbc.gridy = message.length; | 569 gbc.gridy = message.length; |
565 gbc.fill = GridBagConstraints.HORIZONTAL; | 570 gbc.fill = GridBagConstraints.HORIZONTAL; |
566 p.add ( m_List, gbc ); | 571 p.add (m_List, gbc); |
567 | 572 |
568 if ( on.toLowerCase ().equals ( "single" ) ) | 573 if (on.toLowerCase ().equals ("single")) |
569 { | 574 { |
570 // single selection list | 575 // single selection list |
571 m_List.setSelectionMode ( ListSelectionModel.SINGLE_SELECTION ); | 576 m_List.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); |
572 | 577 |
573 m_List.setSelectedIndex ( Integer.parseInt ( | 578 m_List.setSelectedIndex (Integer.parseInt ( |
574 defaults[0].toString () ) - 1 ); | 579 defaults[0].toString ()) - 1); |
575 } | 580 } |
576 else | 581 else |
577 { | 582 { |
578 // multiple selection possible | 583 // multiple selection possible |
579 m_List.setSelectionMode ( ListSelectionModel. | 584 m_List.setSelectionMode (ListSelectionModel. |
580 MULTIPLE_INTERVAL_SELECTION ); | 585 MULTIPLE_INTERVAL_SELECTION); |
581 | 586 |
582 int selection[] = new int[defaults.length]; | 587 int selection[] = new int[defaults.length]; |
583 for ( int i = 0; i < defaults.length; i++ ) | 588 for (int i = 0; i < defaults.length; i++) |
584 { | 589 { |
585 selection[i] = Integer.parseInt ( defaults[i].toString () ) - 1; | 590 selection[i] = Integer.parseInt (defaults[i].toString ()) - 1; |
586 } | 591 } |
587 m_List.setSelectedIndices ( selection ); | 592 m_List.setSelectedIndices (selection); |
588 | 593 |
589 JButton b = new JButton ( "Select All" ); | 594 JButton b = new JButton ("Select All"); |
590 b.setActionCommand ( "SELALL" ); | 595 b.setActionCommand ("SELALL"); |
591 b.addActionListener ( theListener ); | 596 b.addActionListener (theListener); |
592 gbc.gridy = message.length + 1; | 597 gbc.gridy = message.length + 1; |
593 gbc.fill = GridBagConstraints.HORIZONTAL; | 598 gbc.fill = GridBagConstraints.HORIZONTAL; |
594 p.add ( b, gbc ); | 599 p.add (b, gbc); |
595 } | 600 } |
596 | 601 |
597 } | 602 } |
598 | 603 |
599 // prepare icon, if any | 604 // prepare icon, if any |
600 String sIconFile = null; | 605 String sIconFile = null; |
601 String sIconResource = null; | 606 String sIconResource = null; |
602 Icon theIcon = null; | 607 Icon theIcon = null; |
603 | 608 |
604 if ( FLAG_ERROR == ( FLAG_ERROR & flag ) ) | 609 if (FLAG_ERROR == (FLAG_ERROR & flag)) |
605 { | 610 { |
606 sIconFile = "images/error.png"; | 611 sIconFile = "images/error.png"; |
607 // Java for Windows | 612 // Java for Windows |
608 sIconResource = "OptionPane.errorIcon"; | 613 sIconResource = "OptionPane.errorIcon"; |
609 // Java for Linux does not offer these standard icons... | 614 // Java for Linux does not offer these standard icons... |
610 } | 615 } |
611 else if ( FLAG_WARNING == ( FLAG_WARNING & flag ) ) | 616 else if (FLAG_WARNING == (FLAG_WARNING & flag)) |
612 { | 617 { |
613 sIconFile = "images/warning.png"; | 618 sIconFile = "images/warning.png"; |
614 // Java for Windows | 619 // Java for Windows |
615 sIconResource = "OptionPane.warningIcon"; | 620 sIconResource = "OptionPane.warningIcon"; |
616 // Java for Linux does not offer these standard icons... | 621 // Java for Linux does not offer these standard icons... |
617 } | 622 } |
618 else if ( FLAG_QUESTION == ( FLAG_QUESTION & flag ) ) | 623 else if (FLAG_QUESTION == (FLAG_QUESTION & flag)) |
619 { | 624 { |
620 sIconFile = "images/question.png"; | 625 sIconFile = "images/question.png"; |
621 // Java for Windows | 626 // Java for Windows |
622 sIconResource = "OptionPane.questionIcon"; | 627 sIconResource = "OptionPane.questionIcon"; |
623 // Java for Linux does not offer these standard icons... | 628 // Java for Linux does not offer these standard icons... |
624 } | 629 } |
625 else if ( FLAG_INFORMATION == ( FLAG_INFORMATION & flag ) ) | 630 else if (FLAG_INFORMATION == (FLAG_INFORMATION & flag)) |
626 { | 631 { |
627 sIconFile = "images/information.png"; | 632 sIconFile = "images/information.png"; |
628 // Java for Windows | 633 // Java for Windows |
629 sIconResource = "OptionPane.informationIcon"; | 634 sIconResource = "OptionPane.informationIcon"; |
630 // Java for Linux does not offer these standard icons... | 635 // Java for Linux does not offer these standard icons... |
631 } | 636 } |
632 | 637 |
633 // first try to find the UIManager specific icon to fit look and feel | 638 // first try to find the UIManager specific icon to fit look and feel |
634 // Note: the Windows XP look and feel offers 50 icons. | 639 // Note: the Windows XP look and feel offers 50 icons. |
635 if ( sIconResource != null ) | 640 if (sIconResource != null) |
636 { | 641 { |
637 UIDefaults df = UIManager.getLookAndFeelDefaults (); | 642 UIDefaults df = UIManager.getLookAndFeelDefaults (); |
638 theIcon = df.getIcon ( sIconResource ); | 643 theIcon = df.getIcon (sIconResource); |
639 } | 644 } |
640 | 645 |
641 // fallback on bitmap image resource if icon was not found | 646 // fallback on bitmap image resource if icon was not found |
642 if ( theIcon == null && | 647 if (theIcon == null && |
643 sIconFile != null ) | 648 sIconFile != null) |
644 { | 649 { |
645 URL theResource = JDialogBox.class.getResource ( sIconFile ); | 650 URL theResource = JDialogBox.class.getResource (sIconFile); |
646 if ( theResource != null ) | 651 if (theResource != null) |
647 { | 652 { |
648 theIcon = new ImageIcon ( theResource ); | 653 theIcon = new ImageIcon (theResource); |
649 } | 654 } |
650 } | 655 } |
651 | 656 |
652 if ( theIcon != null ) | 657 if (theIcon != null) |
653 { | 658 { |
654 // dummy panel to provide space around icon | 659 // dummy panel to provide space around icon |
655 JPanel pi = new JPanel ( new GridLayout ( 1, 3 ) ); | 660 JPanel pi = new JPanel (new GridLayout (1, 3)); |
656 pi.add ( new JLabel () ); | 661 pi.add (new JLabel ()); |
657 pi.add ( new JLabel ( theIcon ) ); | 662 pi.add (new JLabel (theIcon)); |
658 pi.add ( new JLabel () ); | 663 pi.add (new JLabel ()); |
659 d.add ( pi, BorderLayout.WEST ); | 664 d.add (pi, BorderLayout.WEST); |
660 | 665 |
661 // use Octave icon if available. otherwise use dialog icon | 666 // use Octave icon if available. otherwise use dialog icon |
662 Icon theOctaveIcon = getOctaveIcon (); | 667 Icon theOctaveIcon = getOctaveIcon (); |
663 prepareFrameIcon ( m_ParentFrame, | 668 prepareFrameIcon (m_ParentFrame, |
664 theOctaveIcon == null ? theIcon : theOctaveIcon ); | 669 theOctaveIcon == null ? theIcon : theOctaveIcon); |
665 } | 670 } |
666 | 671 |
667 d.add ( p, BorderLayout.CENTER ); | 672 d.add (p, BorderLayout.CENTER); |
668 | 673 |
669 // button bar (2 rows of 3 columns each | 674 // button bar (2 rows of 3 columns each |
670 | 675 |
671 p = new JPanel (); | 676 p = new JPanel (); |
672 p.setLayout ( new java.awt.GridLayout ( 2, 3 ) ); | 677 p.setLayout (new java.awt.GridLayout (2, 3)); |
673 | 678 |
674 // spacer row | 679 // spacer row |
675 p.add ( new JLabel () ); | 680 p.add (new JLabel ()); |
676 p.add ( new JLabel () ); | 681 p.add (new JLabel ()); |
677 p.add ( new JLabel () ); | 682 p.add (new JLabel ()); |
678 | 683 |
679 if ( DLG_QUEST == ( DLG_QUEST & flag ) ) | 684 if (DLG_QUEST == (DLG_QUEST & flag)) |
680 { | 685 { |
681 // questdlg with empty option[2]: only two buttons | 686 // questdlg with empty option[2]: only two buttons |
682 if ( nostring.length () < 1 ) | 687 if (nostring.length () < 1) |
683 { | 688 { |
684 // spacer: left | 689 // spacer: left |
685 p.add ( new JLabel () ); | 690 p.add (new JLabel ()); |
686 } | 691 } |
687 } | 692 } |
688 else | 693 else |
689 { | 694 { |
690 // spacer: left | 695 // spacer: left |
691 p.add ( new JLabel () ); | 696 p.add (new JLabel ()); |
692 } | 697 } |
693 | 698 |
694 m_ButtonOK = new JButton ( theTranslator.replace ( okstring ) ); | 699 m_ButtonOK = new JButton (theTranslator.replace (okstring)); |
695 m_ButtonOK.setActionCommand ( "OK" ); | 700 m_ButtonOK.setActionCommand ("OK"); |
696 m_ButtonOK.addActionListener ( theListener ); | 701 m_ButtonOK.addActionListener (theListener); |
697 m_Focus = m_ButtonOK; | 702 m_Focus = m_ButtonOK; |
698 p.add ( m_ButtonOK ); | 703 p.add (m_ButtonOK); |
699 | 704 |
700 if ( DLG_QUEST == ( DLG_QUEST & flag ) ) | 705 if (DLG_QUEST == (DLG_QUEST & flag)) |
701 { | 706 { |
702 // questdlg with empty option[2]: only two buttons | 707 // questdlg with empty option[2]: only two buttons |
703 if ( nostring.length () > 01 ) | 708 if (nostring.length () > 01) |
704 { | 709 { |
705 // questdlg has three buttons | 710 // questdlg has three buttons |
706 m_ButtonNO = new JButton ( theTranslator.replace ( nostring ) ); | 711 m_ButtonNO = new JButton (theTranslator.replace (nostring)); |
707 m_ButtonNO.setActionCommand ( "NO" ); | 712 m_ButtonNO.setActionCommand ("NO"); |
708 m_ButtonNO.addActionListener ( theListener ); | 713 m_ButtonNO.addActionListener (theListener); |
709 p.add ( m_ButtonNO ); | 714 p.add (m_ButtonNO); |
710 if ( DLG_QUEST == ( DLG_QUEST & flag ) ) | 715 if (DLG_QUEST == (DLG_QUEST & flag)) |
711 { | 716 { |
712 // select default button | 717 // select default button |
713 if ( list[3].equals ( nostring ) ) | 718 if (list[3].equals (nostring)) |
714 { | 719 { |
715 m_Focus = m_ButtonNO; | 720 m_Focus = m_ButtonNO; |
716 } | 721 } |
717 } | 722 } |
718 } | 723 } |
719 } | 724 } |
720 | 725 |
721 if ( DLG_INPUT == ( DLG_INPUT & flag ) || | 726 if (DLG_INPUT == (DLG_INPUT & flag) || |
722 DLG_LIST == ( DLG_LIST & flag ) || | 727 DLG_LIST == (DLG_LIST & flag) || |
723 DLG_QUEST == ( DLG_QUEST & flag ) ) | 728 DLG_QUEST == (DLG_QUEST & flag)) |
724 { | 729 { |
725 m_ButtonCANCEL = new JButton ( theTranslator.replace ( cancelstring ) ); | 730 m_ButtonCANCEL = new JButton (theTranslator.replace (cancelstring)); |
726 m_ButtonCANCEL.setActionCommand ( "CANCEL" ); | 731 m_ButtonCANCEL.setActionCommand ("CANCEL"); |
727 m_ButtonCANCEL.addActionListener ( theListener ); | 732 m_ButtonCANCEL.addActionListener (theListener); |
728 p.add ( m_ButtonCANCEL ); | 733 p.add (m_ButtonCANCEL); |
729 if ( DLG_QUEST == ( DLG_QUEST & flag ) ) | 734 if (DLG_QUEST == (DLG_QUEST & flag)) |
730 { | 735 { |
731 // select default button | 736 // select default button |
732 if ( list[3].equals ( cancelstring ) ) | 737 if (list[3].equals (cancelstring)) |
733 { | 738 { |
734 m_Focus = m_ButtonCANCEL; | 739 m_Focus = m_ButtonCANCEL; |
735 } | 740 } |
736 } | 741 } |
737 } | 742 } |
738 else | 743 else |
739 { | 744 { |
740 // spacer: right | 745 // spacer: right |
741 p.add ( new JLabel () ); | 746 p.add (new JLabel ()); |
742 } | 747 } |
743 | 748 |
744 d.add ( p, BorderLayout.SOUTH ); | 749 d.add (p, BorderLayout.SOUTH); |
745 dlg.pack (); | 750 dlg.pack (); |
746 | 751 |
747 dlg.addWindowListener ( theListener ); | 752 dlg.addWindowListener (theListener); |
748 | 753 |
749 if ( on.equals ( "on" ) ) | 754 if (on.equals ("on")) |
750 { | 755 { |
751 m_ParentFrame.setAlwaysOnTop ( true ); | 756 m_ParentFrame.setAlwaysOnTop (true); |
752 } | 757 } |
753 | 758 |
754 // center dialog on screen | 759 // center dialog on screen |
755 Dimension dlgSize = dlg.getSize (); | 760 Dimension dlgSize = dlg.getSize (); |
756 Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize (); | 761 Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize (); |
757 | 762 |
758 dlg.setLocation ( ( screenSize.width - dlgSize.width ) / 2, | 763 dlg.setLocation ((screenSize.width - dlgSize.width) / 2, |
759 ( screenSize.height - dlgSize.height ) / 2 ); | 764 (screenSize.height - dlgSize.height) / 2); |
760 | 765 |
761 dlg.setVisible ( true ); | 766 dlg.setVisible (true); |
762 dlg.requestFocus (); | 767 dlg.requestFocus (); |
763 | 768 |
764 m_ParentFrame.setVisible ( false ); | 769 m_ParentFrame.setVisible (false); |
765 | 770 |
766 return ( 1 ); | 771 return (1); |
767 } | 772 } |
768 | 773 |
769 | 774 |
770 /** | 775 /** |
771 * | 776 * |
772 * @return Icon - null if icon was not found | 777 * @return Icon - null if icon was not found |
773 */ | 778 */ |
774 private Icon getOctaveIcon () | 779 private Icon getOctaveIcon () |
775 { | 780 { |
776 Icon theIcon = null; | 781 Icon theIcon = null; |
777 URL theResource = JDialogBox.class.getResource ( "images/octave.png" ); | 782 URL theResource = JDialogBox.class.getResource ("images/octave.png"); |
778 if ( theResource != null ) | 783 if (theResource != null) |
779 { | 784 { |
780 theIcon = new ImageIcon ( theResource ); | 785 theIcon = new ImageIcon (theResource); |
781 } | 786 } |
782 return theIcon; | 787 return theIcon; |
783 } | 788 } |
784 | 789 |
785 | 790 |
786 /** | 791 /** |
787 * Replace the standard Java frame icon with an Octave Icon. | 792 * Replace the standard Java frame icon with an Octave Icon. |
788 * | 793 * |
789 * @param theFrame Frame - the Frame to decorate | 794 * @param theFrame Frame - the Frame to decorate |
790 * @param theIcon Icon - the icon to use if octave icon is not found. | 795 * @param theIcon Icon - the icon to use if octave icon is not found. |
791 */ | 796 */ |
792 private void prepareFrameIcon ( Frame theFrame, Icon theIcon ) | 797 private void prepareFrameIcon (Frame theFrame, Icon theIcon) |
793 { | 798 { |
794 // prepare icon for upper left corner of Frame window | 799 // prepare icon for upper left corner of Frame window |
795 // maybe there is a simpler way to achieve this | 800 // maybe there is a simpler way to achieve this |
796 int w = theIcon.getIconWidth (); | 801 int w = theIcon.getIconWidth (); |
797 int h = theIcon.getIconHeight (); | 802 int h = theIcon.getIconHeight (); |
798 // Frame must be made displayable by packing it for createImage() to succeed | 803 // Frame must be made displayable by packing it for createImage() to succeed |
799 theFrame.pack (); | 804 theFrame.pack (); |
800 Image theImage = theFrame.createImage ( w, h ); | 805 Image theImage = theFrame.createImage (w, h); |
801 theIcon.paintIcon ( theFrame, theImage.getGraphics (), 0, 0 ); | 806 theIcon.paintIcon (theFrame, theImage.getGraphics (), 0, 0); |
802 theFrame.setIconImage ( theImage ); | 807 theFrame.setIconImage (theImage); |
803 } | 808 } |
804 | 809 |
805 | 810 |
806 /** | 811 /** |
807 * Select Look and Feel | 812 * Select Look and Feel |
808 * | 813 * |
809 * @param bSystemLnF boolean - if true, the current systesm Look&Feel is used, | 814 * @param bSystemLnF boolean - if true, the current systesm Look&Feel is used, |
810 * otherwise the Swing/Metal cross platform Look&Feel is used. | 815 * otherwise the Swing/Metal cross platform Look&Feel is used. |
811 */ | 816 */ |
812 private void setSystemLnF ( boolean bSystemLnF ) | 817 private void setSystemLnF (boolean bSystemLnF) |
813 { | 818 { |
814 try | 819 try |
815 { | 820 { |
816 if ( bSystemLnF ) | 821 if (bSystemLnF) |
817 { | 822 { |
818 // switch from Swing LnF to local system LnF | 823 // switch from Swing LnF to local system LnF |
819 UIManager.setLookAndFeel ( UIManager. | 824 UIManager.setLookAndFeel (UIManager. |
820 getSystemLookAndFeelClassName () ); | 825 getSystemLookAndFeelClassName ()); |
821 } | 826 } |
822 else | 827 else |
823 { | 828 { |
824 // use Swing LnF | 829 // use Swing LnF |
825 UIManager.setLookAndFeel ( UIManager. | 830 UIManager.setLookAndFeel (UIManager. |
826 getCrossPlatformLookAndFeelClassName () ); | 831 getCrossPlatformLookAndFeelClassName ()); |
827 } | 832 } |
828 } | 833 } |
829 catch ( Exception exception ) | 834 catch (Exception exception) |
830 { | 835 { |
831 exception.printStackTrace (); | 836 exception.printStackTrace (); |
832 } | 837 } |
833 } | 838 } |
834 | 839 |
835 | 840 |
836 /** | 841 /** |
837 * Called when the dialog is closed. Allows for specific cleanup actions. | 842 * Called when the dialog is closed. Allows for specific cleanup actions. |
838 * | 843 * |
839 * @param closeMethod int - OctaveDialog.CLOSE_OK, OctaveDialog.CLOSE_CANCEL | 844 * @param closeMethod int - OctaveDialog.CLOSE_OK, OctaveDialog.CLOSE_CANCEL |
840 */ | 845 */ |
841 public void closeDialog ( int closeMethod ) | 846 public void closeDialog (int closeMethod) |
842 { | 847 { |
843 m_CloseMethod = closeMethod; | 848 m_CloseMethod = closeMethod; |
844 m_ParentFrame.dispose (); | 849 m_ParentFrame.dispose (); |
845 } | 850 } |
846 | 851 |
847 | 852 |
848 public void setFocus () | 853 public void setFocus () |
849 { | 854 { |
850 if ( null != m_Focus ) | 855 if (null != m_Focus) |
851 { | 856 { |
852 m_Focus.requestFocus (); | 857 m_Focus.requestFocus (); |
853 m_ParentFrame.getRootPane ().setDefaultButton ( m_Focus ); | 858 m_ParentFrame.getRootPane ().setDefaultButton (m_Focus); |
854 m_ParentFrame.setAlwaysOnTop ( true ); | 859 m_ParentFrame.setAlwaysOnTop (true); |
855 } | 860 } |
856 } | 861 } |
857 | 862 |
858 | 863 |
859 /** | 864 /** |
860 * Tests the dialogs | 865 * Tests the dialogs |
861 * | 866 * |
862 * @param args String[] - not used. | 867 * @param args String[] - not used. |
863 */ | 868 */ |
864 public static void main ( String[] args ) | 869 public static void main (String[] args) |
865 { | 870 { |
866 TeXtranslator t = new TeXtranslator(); | 871 TeXtranslator t = new TeXtranslator(); |
867 | 872 |
868 if(false) | 873 if (false) |
869 { | 874 { |
870 // find out key names of icon UI resources | 875 // find out key names of icon UI resources |
871 UIDefaults df = UIManager.getLookAndFeelDefaults (); | 876 UIDefaults df = UIManager.getLookAndFeelDefaults (); |
872 | 877 |
873 for ( Enumeration e = df.keys (); e.hasMoreElements (); ) | 878 for (Enumeration e = df.keys (); e.hasMoreElements ();) |
874 { | 879 { |
875 String s = e.nextElement ().toString (); | 880 String s = e.nextElement ().toString (); |
876 | 881 |
877 if ( s.toLowerCase ().contains ( "icon" ) ) | 882 if (s.toLowerCase ().contains ("icon")) |
878 { | 883 { |
879 System.out.println ( s ); | 884 System.out.println (s); |
880 } | 885 } |
881 } | 886 } |
882 } | 887 } |
883 | 888 |
884 try | 889 try |
885 { | 890 { |
886 Class[] argTypes = new Class[1]; | 891 Class[] argTypes = new Class[1]; |
887 argTypes[0] = String.class; | 892 argTypes[0] = String.class; |
888 | 893 |
889 java.lang.reflect.Constructor c = ClassHelper.findConstructor ( java.lang.StringBuffer.class, | 894 java.lang.reflect.Constructor c = ClassHelper.findConstructor (java.lang.StringBuffer.class, |
890 argTypes ); | 895 argTypes); |
891 Object argValues[] = new Object[1]; | 896 Object argValues[] = new Object[1]; |
892 argValues[0] = new String("initial value"); | 897 argValues[0] = new String("initial value"); |
893 Object sb = c.newInstance(argValues); | 898 Object sb = c.newInstance(argValues); |
894 System.out.println(sb.toString()); | 899 System.out.println(sb.toString()); |
895 | 900 |
896 ClassHelper.invokeMethod(sb,"append",argValues,argTypes); | 901 ClassHelper.invokeMethod(sb,"append",argValues,argTypes); |
897 System.out.println(sb.toString()); | 902 System.out.println(sb.toString()); |
898 | 903 |
899 argValues = new Object[2]; | 904 argValues = new Object[2]; |
900 argTypes = new Class[2]; | 905 argTypes = new Class[2]; |
901 argTypes[0] = Integer.class; | 906 argTypes[0] = Integer.class; |
902 argTypes[1] = String.class; | 907 argTypes[1] = String.class; |
903 argValues[0] = new Integer(0); | 908 argValues[0] = new Integer(0); |
904 argValues[1] = new String("inserted"); | 909 argValues[1] = new String("inserted"); |
905 | 910 |
906 ClassHelper.invokeMethod(sb,"insert",argValues,argTypes); | 911 ClassHelper.invokeMethod(sb,"insert",argValues,argTypes); |
907 System.out.println(sb.toString()); | 912 System.out.println(sb.toString()); |
908 } | 913 } |
909 catch ( Throwable e ) | 914 catch (Throwable e) |
910 {} | 915 {} |
911 | 916 |
912 if ( true ) | 917 if (true) |
913 { | 918 { |
914 return; | 919 return; |
915 } | 920 } |
916 | 921 |
917 helpdlg ( "If you need help\nyou should ask for help\nif someone is around\notherwise you are on your own.", | 922 helpdlg ("If you need help\nyou should ask for help\nif someone is around\notherwise you are on your own.", |
918 "Information" ); | 923 "Information"); |
919 | 924 |
920 String[] options = new String[4]; | 925 String[] options = new String[4]; |
921 options[0] = "Yeah \\vartheta is too low"; | 926 options[0] = "Yeah \\vartheta is too low"; |
922 options[1] = "Maybe"; | 927 options[1] = "Maybe"; |
923 options[2] = "Nay \\vartheta is too high"; | 928 options[2] = "Nay \\vartheta is too high"; |
924 options[3] = "Maybe"; | 929 options[3] = "Maybe"; |
925 | 930 |
926 System.out.println ( questdlg ( "Is it too cold?", "Temperature", options ) ); | 931 System.out.println (questdlg ("Is it too cold?", "Temperature", options)); |
927 | 932 |
928 // test variants of errordlg | 933 // test variants of errordlg |
929 // does not affect layering of dialog | 934 // does not affect layering of dialog |
930 errordlg ( "Background error!", "Error" ); | 935 errordlg ("Background error!", "Error"); |
931 | 936 |
932 // test variants of helpdlg | 937 // test variants of helpdlg |
933 | 938 |
934 // test variants of inputdlg | 939 // test variants of inputdlg |
935 String prompt[] = new String[2]; | 940 String prompt[] = new String[2]; |
936 prompt[0] = "Question 1"; | 941 prompt[0] = "Question 1"; |
937 prompt[1] = "Question 2"; | 942 prompt[1] = "Question 2"; |
938 String defaults[] = new String[2]; | 943 String defaults[] = new String[2]; |
939 defaults[0] = "1.1"; | 944 defaults[0] = "1.1"; |
940 defaults[1] = "2.2"; | 945 defaults[1] = "2.2"; |
941 String title = "Enter values"; | 946 String title = "Enter values"; |
942 | 947 |
943 Integer rc[] = new Integer[2 * 2]; | 948 Integer rc[] = new Integer[2 * 2]; |
944 rc[0] = new Integer ( 1 ); | 949 rc[0] = new Integer (1); |
945 rc[1] = new Integer ( 2 ); | 950 rc[1] = new Integer (2); |
946 rc[2] = new Integer ( 10 ); | 951 rc[2] = new Integer (10); |
947 rc[3] = new Integer ( 20 ); | 952 rc[3] = new Integer (20); |
948 | 953 |
949 inputdlg ( prompt, title, rc, defaults ); | 954 inputdlg (prompt, title, rc, defaults); |
950 | 955 |
951 String listcell[] = new String[4]; | 956 String listcell[] = new String[4]; |
952 listcell[0] = "a \\alpha"; | 957 listcell[0] = "a \\alpha"; |
953 listcell[1] = "b \\beta"; | 958 listcell[1] = "b \\beta"; |
954 listcell[2] = "c \\gamma"; | 959 listcell[2] = "c \\gamma"; |
955 listcell[3] = "d \\delta"; | 960 listcell[3] = "d \\delta"; |
956 | 961 |
957 Integer size[] = new Integer[2]; | 962 Integer size[] = new Integer[2]; |
958 size[0] = new Integer ( 80 ); | 963 size[0] = new Integer (80); |
959 size[1] = new Integer ( 100 ); | 964 size[1] = new Integer (100); |
960 | 965 |
961 Integer initial[] = new Integer[2]; | 966 Integer initial[] = new Integer[2]; |
962 initial[0] = new Integer ( 4 ); | 967 initial[0] = new Integer (4); |
963 initial[1] = new Integer ( 2 ); | 968 initial[1] = new Integer (2); |
964 | 969 |
965 String promptcell[] = new String[2]; | 970 String promptcell[] = new String[2]; |
966 promptcell[0] = "Select something"; | 971 promptcell[0] = "Select something"; |
967 promptcell[1] = "(or even more than one thing)"; | 972 promptcell[1] = "(or even more than one thing)"; |
968 | 973 |
969 int idx[] = listdlg ( listcell, | 974 int idx[] = listdlg (listcell, |
970 "Multiple", | 975 "Multiple", |
971 size, | 976 size, |
972 initial, | 977 initial, |
973 "name", | 978 "name", |
974 promptcell, | 979 promptcell, |
975 "okstring", | 980 "okstring", |
976 "cancelstring" ); | 981 "cancelstring"); |
977 | 982 |
978 if ( idx != null ) | 983 if (idx != null) |
979 { | 984 { |
980 for ( int i = 0; i < idx.length; i++ ) | 985 for (int i = 0; i < idx.length; i++) |
981 { | 986 { |
982 System.out.println ( idx[i] ); | 987 System.out.println (idx[i]); |
983 } | 988 } |
984 } | 989 } |
985 } | 990 } |
986 } | 991 } |