1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
376
377 } else {
378 String s = msg.toString();
379 int len = s.length();
380 if (len <= 0) {
381 return;
382 }
383 int nl;
384 int nll = 0;
385
386 if ((nl = s.indexOf(newline)) >= 0) {
387 nll = newline.length();
388 } else if ((nl = s.indexOf("\r\n")) >= 0) {
389 nll = 2;
390 } else if ((nl = s.indexOf('\n')) >= 0) {
391 nll = 1;
392 }
393 if (nl >= 0) {
394 // break up newlines
395 if (nl == 0) {
396 JPanel breakPanel = new JPanel() {
397 public Dimension getPreferredSize() {
398 Font f = getFont();
399
400 if (f != null) {
401 return new Dimension(1, f.getSize() + 2);
402 }
403 return new Dimension(0, 0);
404 }
405 };
406 breakPanel.setName("OptionPane.break");
407 addMessageComponents(container, cons, breakPanel, maxll,
408 true);
409 } else {
410 addMessageComponents(container, cons, s.substring(0, nl),
411 maxll, false);
412 }
413 addMessageComponents(container, cons, s.substring(nl + nll), maxll,
414 false);
415
1321 op.applyComponentOrientation(o);
1322 }
1323 }
1324 }
1325 }
1326 }
1327
1328
1329 //
1330 // Classes used when optionPane.getWantsInput returns true.
1331 //
1332
1333 /**
1334 * A JTextField that allows you to specify an array of KeyStrokes that
1335 * that will have their bindings processed regardless of whether or
1336 * not they are registered on the JTextField. This is used as we really
1337 * want the ActionListener to be notified so that we can push the
1338 * change to the JOptionPane, but we also want additional bindings
1339 * (those of the JRootPane) to be processed as well.
1340 */
1341 private static class MultiplexingTextField extends JTextField {
1342 private KeyStroke[] strokes;
1343
1344 MultiplexingTextField(int cols) {
1345 super(cols);
1346 }
1347
1348 /**
1349 * Sets the KeyStrokes that will be additional processed for
1350 * ancestor bindings.
1351 */
1352 void setKeyStrokes(KeyStroke[] strokes) {
1353 this.strokes = strokes;
1354 }
1355
1356 protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
1357 int condition, boolean pressed) {
1358 boolean processed = super.processKeyBinding(ks, e, condition,
1359 pressed);
1360
1414 this.minimumWidth = minimumWidth;
1415 }
1416
1417 JButton createButton() {
1418 JButton button;
1419
1420 if (minimumWidth > 0) {
1421 button = new ConstrainedButton(text, minimumWidth);
1422 } else {
1423 button = new JButton(text);
1424 }
1425 if (icon != null) {
1426 button.setIcon(icon);
1427 }
1428 if (mnemonic != 0) {
1429 button.setMnemonic(mnemonic);
1430 }
1431 return button;
1432 }
1433
1434 private static class ConstrainedButton extends JButton {
1435 int minimumWidth;
1436
1437 ConstrainedButton(String text, int minimumWidth) {
1438 super(text);
1439 this.minimumWidth = minimumWidth;
1440 }
1441
1442 public Dimension getMinimumSize() {
1443 Dimension min = super.getMinimumSize();
1444 min.width = Math.max(min.width, minimumWidth);
1445 return min;
1446 }
1447
1448 public Dimension getPreferredSize() {
1449 Dimension pref = super.getPreferredSize();
1450 pref.width = Math.max(pref.width, minimumWidth);
1451 return pref;
1452 }
1453 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
376
377 } else {
378 String s = msg.toString();
379 int len = s.length();
380 if (len <= 0) {
381 return;
382 }
383 int nl;
384 int nll = 0;
385
386 if ((nl = s.indexOf(newline)) >= 0) {
387 nll = newline.length();
388 } else if ((nl = s.indexOf("\r\n")) >= 0) {
389 nll = 2;
390 } else if ((nl = s.indexOf('\n')) >= 0) {
391 nll = 1;
392 }
393 if (nl >= 0) {
394 // break up newlines
395 if (nl == 0) {
396 @SuppressWarnings("serial") // anonymous class
397 JPanel breakPanel = new JPanel() {
398 public Dimension getPreferredSize() {
399 Font f = getFont();
400
401 if (f != null) {
402 return new Dimension(1, f.getSize() + 2);
403 }
404 return new Dimension(0, 0);
405 }
406 };
407 breakPanel.setName("OptionPane.break");
408 addMessageComponents(container, cons, breakPanel, maxll,
409 true);
410 } else {
411 addMessageComponents(container, cons, s.substring(0, nl),
412 maxll, false);
413 }
414 addMessageComponents(container, cons, s.substring(nl + nll), maxll,
415 false);
416
1322 op.applyComponentOrientation(o);
1323 }
1324 }
1325 }
1326 }
1327 }
1328
1329
1330 //
1331 // Classes used when optionPane.getWantsInput returns true.
1332 //
1333
1334 /**
1335 * A JTextField that allows you to specify an array of KeyStrokes that
1336 * that will have their bindings processed regardless of whether or
1337 * not they are registered on the JTextField. This is used as we really
1338 * want the ActionListener to be notified so that we can push the
1339 * change to the JOptionPane, but we also want additional bindings
1340 * (those of the JRootPane) to be processed as well.
1341 */
1342 @SuppressWarnings("serial") // Superclass is not serializable across versions
1343 private static class MultiplexingTextField extends JTextField {
1344 private KeyStroke[] strokes;
1345
1346 MultiplexingTextField(int cols) {
1347 super(cols);
1348 }
1349
1350 /**
1351 * Sets the KeyStrokes that will be additional processed for
1352 * ancestor bindings.
1353 */
1354 void setKeyStrokes(KeyStroke[] strokes) {
1355 this.strokes = strokes;
1356 }
1357
1358 protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
1359 int condition, boolean pressed) {
1360 boolean processed = super.processKeyBinding(ks, e, condition,
1361 pressed);
1362
1416 this.minimumWidth = minimumWidth;
1417 }
1418
1419 JButton createButton() {
1420 JButton button;
1421
1422 if (minimumWidth > 0) {
1423 button = new ConstrainedButton(text, minimumWidth);
1424 } else {
1425 button = new JButton(text);
1426 }
1427 if (icon != null) {
1428 button.setIcon(icon);
1429 }
1430 if (mnemonic != 0) {
1431 button.setMnemonic(mnemonic);
1432 }
1433 return button;
1434 }
1435
1436 @SuppressWarnings("serial") // Superclass is not serializable across versions
1437 private static class ConstrainedButton extends JButton {
1438 int minimumWidth;
1439
1440 ConstrainedButton(String text, int minimumWidth) {
1441 super(text);
1442 this.minimumWidth = minimumWidth;
1443 }
1444
1445 public Dimension getMinimumSize() {
1446 Dimension min = super.getMinimumSize();
1447 min.width = Math.max(min.width, minimumWidth);
1448 return min;
1449 }
1450
1451 public Dimension getPreferredSize() {
1452 Dimension pref = super.getPreferredSize();
1453 pref.width = Math.max(pref.width, minimumWidth);
1454 return pref;
1455 }
1456 }
|