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
453
454 /**
455 * Creates a non rollover border for Toggle buttons in the toolbar.
456 */
457 private Border createNonRolloverToggleBorder() {
458 UIDefaults table = UIManager.getLookAndFeelDefaults();
459 return new CompoundBorder(new BasicBorders.RadioButtonBorder(
460 table.getColor("ToggleButton.shadow"),
461 table.getColor("ToggleButton.darkShadow"),
462 table.getColor("ToggleButton.light"),
463 table.getColor("ToggleButton.highlight")),
464 new BasicBorders.RolloverMarginBorder());
465 }
466
467 /**
468 * No longer used, use BasicToolBarUI.createFloatingWindow(JToolBar)
469 * @see #createFloatingWindow
470 */
471 protected JFrame createFloatingFrame(JToolBar toolbar) {
472 Window window = SwingUtilities.getWindowAncestor(toolbar);
473 JFrame frame = new JFrame(toolbar.getName(),
474 (window != null) ? window.getGraphicsConfiguration() : null) {
475 // Override createRootPane() to automatically resize
476 // the frame when contents change
477 protected JRootPane createRootPane() {
478 JRootPane rootPane = new JRootPane() {
479 private boolean packing = false;
480
481 public void validate() {
482 super.validate();
483 if (!packing) {
484 packing = true;
485 pack();
486 packing = false;
487 }
488 }
489 };
490 rootPane.setOpaque(true);
491 return rootPane;
492 }
493 };
494 frame.getRootPane().setName("ToolBar.FloatingFrame");
495 frame.setResizable(false);
496 WindowListener wl = createFrameListener();
497 frame.addWindowListener(wl);
498 return frame;
499 }
500
501 /**
502 * Creates a window which contains the toolbar after it has been
503 * dragged out from its container
504 * @return a <code>RootPaneContainer</code> object, containing the toolbar.
505 * @since 1.4
506 */
507 protected RootPaneContainer createFloatingWindow(JToolBar toolbar) {
508 class ToolBarDialog extends JDialog {
509 public ToolBarDialog(Frame owner, String title, boolean modal) {
510 super(owner, title, modal);
511 }
512
513 public ToolBarDialog(Dialog owner, String title, boolean modal) {
514 super(owner, title, modal);
515 }
516
517 // Override createRootPane() to automatically resize
518 // the frame when contents change
519 protected JRootPane createRootPane() {
520 JRootPane rootPane = new JRootPane() {
521 private boolean packing = false;
522
523 public void validate() {
524 super.validate();
525 if (!packing) {
526 packing = true;
527 pack();
528 packing = false;
529 }
530 }
531 };
532 rootPane.setOpaque(true);
533 return rootPane;
534 }
535 }
536
537 JDialog dialog;
538 Window window = SwingUtilities.getWindowAncestor(toolbar);
539 if (window instanceof Frame) {
1353 getHandler().mouseEntered(e);
1354 }
1355
1356 public void mouseExited(MouseEvent e) {
1357 getHandler().mouseExited(e);
1358 }
1359
1360 public void mouseDragged(MouseEvent e) {
1361 getHandler().tb = toolBar;
1362 getHandler().origin = origin;
1363 getHandler().mouseDragged(e);
1364 isDragging = getHandler().isDragging;
1365 origin = getHandler().origin;
1366 }
1367
1368 public void mouseMoved(MouseEvent e) {
1369 getHandler().mouseMoved(e);
1370 }
1371 }
1372
1373 protected class DragWindow extends Window
1374 {
1375 Color borderColor = Color.gray;
1376 int orientation = toolBar.getOrientation();
1377 Point offset; // offset of the mouse cursor inside the DragWindow
1378
1379 DragWindow(Window w) {
1380 super(w);
1381 }
1382
1383 /**
1384 * Returns the orientation of the toolbar window when the toolbar is
1385 * floating. The orientation is either one of <code>JToolBar.HORIZONTAL</code>
1386 * or <code>JToolBar.VERTICAL</code>.
1387 *
1388 * @return the orientation of the toolbar window
1389 * @since 1.6
1390 */
1391 public int getOrientation() {
1392 return orientation;
|
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
453
454 /**
455 * Creates a non rollover border for Toggle buttons in the toolbar.
456 */
457 private Border createNonRolloverToggleBorder() {
458 UIDefaults table = UIManager.getLookAndFeelDefaults();
459 return new CompoundBorder(new BasicBorders.RadioButtonBorder(
460 table.getColor("ToggleButton.shadow"),
461 table.getColor("ToggleButton.darkShadow"),
462 table.getColor("ToggleButton.light"),
463 table.getColor("ToggleButton.highlight")),
464 new BasicBorders.RolloverMarginBorder());
465 }
466
467 /**
468 * No longer used, use BasicToolBarUI.createFloatingWindow(JToolBar)
469 * @see #createFloatingWindow
470 */
471 protected JFrame createFloatingFrame(JToolBar toolbar) {
472 Window window = SwingUtilities.getWindowAncestor(toolbar);
473 @SuppressWarnings("serial") // anonymous class
474 JFrame frame = new JFrame(toolbar.getName(),
475 (window != null) ? window.getGraphicsConfiguration() : null) {
476 // Override createRootPane() to automatically resize
477 // the frame when contents change
478 protected JRootPane createRootPane() {
479 @SuppressWarnings("serial") // anonymous class
480 JRootPane rootPane = new JRootPane() {
481 private boolean packing = false;
482
483 public void validate() {
484 super.validate();
485 if (!packing) {
486 packing = true;
487 pack();
488 packing = false;
489 }
490 }
491 };
492 rootPane.setOpaque(true);
493 return rootPane;
494 }
495 };
496 frame.getRootPane().setName("ToolBar.FloatingFrame");
497 frame.setResizable(false);
498 WindowListener wl = createFrameListener();
499 frame.addWindowListener(wl);
500 return frame;
501 }
502
503 /**
504 * Creates a window which contains the toolbar after it has been
505 * dragged out from its container
506 * @return a <code>RootPaneContainer</code> object, containing the toolbar.
507 * @since 1.4
508 */
509 protected RootPaneContainer createFloatingWindow(JToolBar toolbar) {
510 @SuppressWarnings("serial") // Superclass is not serializable across versions
511 class ToolBarDialog extends JDialog {
512 public ToolBarDialog(Frame owner, String title, boolean modal) {
513 super(owner, title, modal);
514 }
515
516 public ToolBarDialog(Dialog owner, String title, boolean modal) {
517 super(owner, title, modal);
518 }
519
520 // Override createRootPane() to automatically resize
521 // the frame when contents change
522 protected JRootPane createRootPane() {
523 @SuppressWarnings("serial") // anonymous class
524 JRootPane rootPane = new JRootPane() {
525 private boolean packing = false;
526
527 public void validate() {
528 super.validate();
529 if (!packing) {
530 packing = true;
531 pack();
532 packing = false;
533 }
534 }
535 };
536 rootPane.setOpaque(true);
537 return rootPane;
538 }
539 }
540
541 JDialog dialog;
542 Window window = SwingUtilities.getWindowAncestor(toolbar);
543 if (window instanceof Frame) {
1357 getHandler().mouseEntered(e);
1358 }
1359
1360 public void mouseExited(MouseEvent e) {
1361 getHandler().mouseExited(e);
1362 }
1363
1364 public void mouseDragged(MouseEvent e) {
1365 getHandler().tb = toolBar;
1366 getHandler().origin = origin;
1367 getHandler().mouseDragged(e);
1368 isDragging = getHandler().isDragging;
1369 origin = getHandler().origin;
1370 }
1371
1372 public void mouseMoved(MouseEvent e) {
1373 getHandler().mouseMoved(e);
1374 }
1375 }
1376
1377 @SuppressWarnings("serial") // Same-version serialization only
1378 protected class DragWindow extends Window
1379 {
1380 Color borderColor = Color.gray;
1381 int orientation = toolBar.getOrientation();
1382 Point offset; // offset of the mouse cursor inside the DragWindow
1383
1384 DragWindow(Window w) {
1385 super(w);
1386 }
1387
1388 /**
1389 * Returns the orientation of the toolbar window when the toolbar is
1390 * floating. The orientation is either one of <code>JToolBar.HORIZONTAL</code>
1391 * or <code>JToolBar.VERTICAL</code>.
1392 *
1393 * @return the orientation of the toolbar window
1394 * @since 1.6
1395 */
1396 public int getOrientation() {
1397 return orientation;
|