1 /*
2 * Copyright (c) 1997, 2008, 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
377
378 } else {
379 String s = msg.toString();
380 int len = s.length();
381 if (len <= 0) {
382 return;
383 }
384 int nl;
385 int nll = 0;
386
387 if ((nl = s.indexOf(newline)) >= 0) {
388 nll = newline.length();
389 } else if ((nl = s.indexOf("\r\n")) >= 0) {
390 nll = 2;
391 } else if ((nl = s.indexOf('\n')) >= 0) {
392 nll = 1;
393 }
394 if (nl >= 0) {
395 // break up newlines
396 if (nl == 0) {
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 private static class MultiplexingTextField extends JTextField {
1343 private KeyStroke[] strokes;
1344
1345 MultiplexingTextField(int cols) {
1346 super(cols);
1347 }
1348
1349 /**
1350 * Sets the KeyStrokes that will be additional processed for
1351 * ancestor bindings.
1352 */
1353 void setKeyStrokes(KeyStroke[] strokes) {
1354 this.strokes = strokes;
1355 }
1356
1357 protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
1358 int condition, boolean pressed) {
1359 boolean processed = super.processKeyBinding(ks, e, condition,
1360 pressed);
1361
1415 this.minimumWidth = minimumWidth;
1416 }
1417
1418 JButton createButton() {
1419 JButton button;
1420
1421 if (minimumWidth > 0) {
1422 button = new ConstrainedButton(text, minimumWidth);
1423 } else {
1424 button = new JButton(text);
1425 }
1426 if (icon != null) {
1427 button.setIcon(icon);
1428 }
1429 if (mnemonic != 0) {
1430 button.setMnemonic(mnemonic);
1431 }
1432 return button;
1433 }
1434
1435 private static class ConstrainedButton extends JButton {
1436 int minimumWidth;
1437
1438 ConstrainedButton(String text, int minimumWidth) {
1439 super(text);
1440 this.minimumWidth = minimumWidth;
1441 }
1442
1443 public Dimension getMinimumSize() {
1444 Dimension min = super.getMinimumSize();
1445 min.width = Math.max(min.width, minimumWidth);
1446 return min;
1447 }
1448
1449 public Dimension getPreferredSize() {
1450 Dimension pref = super.getPreferredSize();
1451 pref.width = Math.max(pref.width, minimumWidth);
1452 return pref;
1453 }
1454 }
|
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
377
378 } else {
379 String s = msg.toString();
380 int len = s.length();
381 if (len <= 0) {
382 return;
383 }
384 int nl;
385 int nll = 0;
386
387 if ((nl = s.indexOf(newline)) >= 0) {
388 nll = newline.length();
389 } else if ((nl = s.indexOf("\r\n")) >= 0) {
390 nll = 2;
391 } else if ((nl = s.indexOf('\n')) >= 0) {
392 nll = 1;
393 }
394 if (nl >= 0) {
395 // break up newlines
396 if (nl == 0) {
397 @SuppressWarnings("serial") // anonymous class
398 JPanel breakPanel = new JPanel() {
399 public Dimension getPreferredSize() {
400 Font f = getFont();
401
402 if (f != null) {
403 return new Dimension(1, f.getSize() + 2);
404 }
405 return new Dimension(0, 0);
406 }
407 };
408 breakPanel.setName("OptionPane.break");
409 addMessageComponents(container, cons, breakPanel, maxll,
410 true);
411 } else {
412 addMessageComponents(container, cons, s.substring(0, nl),
413 maxll, false);
414 }
415 addMessageComponents(container, cons, s.substring(nl + nll), maxll,
416 false);
417
1323 op.applyComponentOrientation(o);
1324 }
1325 }
1326 }
1327 }
1328 }
1329
1330
1331 //
1332 // Classes used when optionPane.getWantsInput returns true.
1333 //
1334
1335 /**
1336 * A JTextField that allows you to specify an array of KeyStrokes that
1337 * that will have their bindings processed regardless of whether or
1338 * not they are registered on the JTextField. This is used as we really
1339 * want the ActionListener to be notified so that we can push the
1340 * change to the JOptionPane, but we also want additional bindings
1341 * (those of the JRootPane) to be processed as well.
1342 */
1343 @SuppressWarnings("serial") // Superclass is not serializable across versions
1344 private static class MultiplexingTextField extends JTextField {
1345 private KeyStroke[] strokes;
1346
1347 MultiplexingTextField(int cols) {
1348 super(cols);
1349 }
1350
1351 /**
1352 * Sets the KeyStrokes that will be additional processed for
1353 * ancestor bindings.
1354 */
1355 void setKeyStrokes(KeyStroke[] strokes) {
1356 this.strokes = strokes;
1357 }
1358
1359 protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
1360 int condition, boolean pressed) {
1361 boolean processed = super.processKeyBinding(ks, e, condition,
1362 pressed);
1363
1417 this.minimumWidth = minimumWidth;
1418 }
1419
1420 JButton createButton() {
1421 JButton button;
1422
1423 if (minimumWidth > 0) {
1424 button = new ConstrainedButton(text, minimumWidth);
1425 } else {
1426 button = new JButton(text);
1427 }
1428 if (icon != null) {
1429 button.setIcon(icon);
1430 }
1431 if (mnemonic != 0) {
1432 button.setMnemonic(mnemonic);
1433 }
1434 return button;
1435 }
1436
1437 @SuppressWarnings("serial") // Superclass is not serializable across versions
1438 private static class ConstrainedButton extends JButton {
1439 int minimumWidth;
1440
1441 ConstrainedButton(String text, int minimumWidth) {
1442 super(text);
1443 this.minimumWidth = minimumWidth;
1444 }
1445
1446 public Dimension getMinimumSize() {
1447 Dimension min = super.getMinimumSize();
1448 min.width = Math.max(min.width, minimumWidth);
1449 return min;
1450 }
1451
1452 public Dimension getPreferredSize() {
1453 Dimension pref = super.getPreferredSize();
1454 pref.width = Math.max(pref.width, minimumWidth);
1455 return pref;
1456 }
1457 }
|