198 private void installListeners() {
199 if (window != null) {
200 windowListener = createWindowListener();
201 window.addWindowListener(windowListener);
202 propertyChangeListener = createWindowPropertyChangeListener();
203 window.addPropertyChangeListener(propertyChangeListener);
204 }
205 }
206
207 /**
208 * Uninstalls the necessary listeners.
209 */
210 private void uninstallListeners() {
211 if (window != null) {
212 window.removeWindowListener(windowListener);
213 window.removePropertyChangeListener(propertyChangeListener);
214 }
215 }
216
217 /**
218 * Returns the <code>WindowListener</code> to add to the
219 * <code>Window</code>.
220 */
221 private WindowListener createWindowListener() {
222 return new WindowHandler();
223 }
224
225 /**
226 * Returns the <code>PropertyChangeListener</code> to install on
227 * the <code>Window</code>.
228 */
229 private PropertyChangeListener createWindowPropertyChangeListener() {
230 return new PropertyChangeHandler();
231 }
232
233 /**
234 * Returns the <code>JRootPane</code> this was created for.
235 */
236 public JRootPane getRootPane() {
237 return rootPane;
238 }
239
240 /**
241 * Returns the decoration style of the <code>JRootPane</code>.
242 */
243 private int getWindowDecorationStyle() {
244 return getRootPane().getWindowDecorationStyle();
245 }
246
247 public void addNotify() {
248 super.addNotify();
249
250 uninstallListeners();
251
252 window = SwingUtilities.getWindowAncestor(this);
253 if (window != null) {
254 if (window instanceof Frame) {
255 setState(((Frame)window).getExtendedState());
256 }
257 else {
258 setState(0);
259 }
260 setActive(window.isActive());
261 installListeners();
262 updateSystemIcon();
263 }
264 }
265
266 public void removeNotify() {
267 super.removeNotify();
268
269 uninstallListeners();
270 window = null;
271 }
272
273 /**
274 * Adds any sub-Components contained in the <code>MetalTitlePane</code>.
275 */
276 private void installSubcomponents() {
277 int decorationStyle = getWindowDecorationStyle();
278 if (decorationStyle == JRootPane.FRAME) {
279 createActions();
280 menuBar = createMenuBar();
281 add(menuBar);
282 createButtons();
283 add(iconifyButton);
284 add(toggleButton);
285 add(closeButton);
286 } else if (decorationStyle == JRootPane.PLAIN_DIALOG ||
287 decorationStyle == JRootPane.INFORMATION_DIALOG ||
288 decorationStyle == JRootPane.ERROR_DIALOG ||
289 decorationStyle == JRootPane.COLOR_CHOOSER_DIALOG ||
290 decorationStyle == JRootPane.FILE_CHOOSER_DIALOG ||
291 decorationStyle == JRootPane.QUESTION_DIALOG ||
292 decorationStyle == JRootPane.WARNING_DIALOG) {
293 createActions();
294 createButtons();
341 break;
342 }
343 activeBumps.setBumpColors(activeBumpsHighlight, activeBumpsShadow,
344 activeBackground);
345 }
346
347 /**
348 * Installs the fonts and necessary properties on the MetalTitlePane.
349 */
350 private void installDefaults() {
351 setFont(UIManager.getFont("InternalFrame.titleFont", getLocale()));
352 }
353
354 /**
355 * Uninstalls any previously installed UI values.
356 */
357 private void uninstallDefaults() {
358 }
359
360 /**
361 * Returns the <code>JMenuBar</code> displaying the appropriate
362 * system menu items.
363 */
364 protected JMenuBar createMenuBar() {
365 menuBar = new SystemMenuBar();
366 menuBar.setFocusable(false);
367 menuBar.setBorderPainted(true);
368 menuBar.add(createMenu());
369 return menuBar;
370 }
371
372 /**
373 * Closes the Window.
374 */
375 private void close() {
376 Window window = getWindow();
377
378 if (window != null) {
379 window.dispatchEvent(new WindowEvent(
380 window, WindowEvent.WINDOW_CLOSING));
381 }
402 }
403
404 /**
405 * Restores the Frame size.
406 */
407 private void restore() {
408 Frame frame = getFrame();
409
410 if (frame == null) {
411 return;
412 }
413
414 if ((state & Frame.ICONIFIED) != 0) {
415 frame.setExtendedState(state & ~Frame.ICONIFIED);
416 } else {
417 frame.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
418 }
419 }
420
421 /**
422 * Create the <code>Action</code>s that get associated with the
423 * buttons and menu items.
424 */
425 private void createActions() {
426 closeAction = new CloseAction();
427 if (getWindowDecorationStyle() == JRootPane.FRAME) {
428 iconifyAction = new IconifyAction();
429 restoreAction = new RestoreAction();
430 maximizeAction = new MaximizeAction();
431 }
432 }
433
434 /**
435 * Returns the <code>JMenu</code> displaying the appropriate menu items
436 * for manipulating the Frame.
437 */
438 private JMenu createMenu() {
439 JMenu menu = new JMenu("");
440 if (getWindowDecorationStyle() == JRootPane.FRAME) {
441 addMenuItems(menu);
442 }
443 return menu;
444 }
445
446 /**
447 * Adds the necessary <code>JMenuItem</code>s to the passed in menu.
448 */
449 private void addMenuItems(JMenu menu) {
450 Locale locale = getRootPane().getLocale();
451 JMenuItem mi = menu.add(restoreAction);
452 int mnemonic = MetalUtils.getInt("MetalTitlePane.restoreMnemonic", -1);
453
454 if (mnemonic != -1) {
455 mi.setMnemonic(mnemonic);
456 }
457
458 mi = menu.add(iconifyAction);
459 mnemonic = MetalUtils.getInt("MetalTitlePane.iconifyMnemonic", -1);
460 if (mnemonic != -1) {
461 mi.setMnemonic(mnemonic);
462 }
463
464 if (Toolkit.getDefaultToolkit().isFrameStateSupported(
465 Frame.MAXIMIZED_BOTH)) {
466 mi = menu.add(maximizeAction);
467 mnemonic =
468 MetalUtils.getInt("MetalTitlePane.maximizeMnemonic", -1);
469 if (mnemonic != -1) {
470 mi.setMnemonic(mnemonic);
471 }
472 }
473
474 menu.add(new JSeparator());
475
476 mi = menu.add(closeAction);
477 mnemonic = MetalUtils.getInt("MetalTitlePane.closeMnemonic", -1);
478 if (mnemonic != -1) {
479 mi.setMnemonic(mnemonic);
480 }
481 }
482
483 /**
484 * Returns a <code>JButton</code> appropriate for placement on the
485 * TitlePane.
486 */
487 private JButton createTitleButton() {
488 JButton button = new JButton();
489
490 button.setFocusPainted(false);
491 button.setFocusable(false);
492 button.setOpaque(true);
493 return button;
494 }
495
496 /**
497 * Creates the Buttons that will be placed on the TitlePane.
498 */
499 private void createButtons() {
500 closeButton = createTitleButton();
501 closeButton.setAction(closeAction);
502 closeButton.setText(null);
503 closeButton.putClientProperty("paintActive", Boolean.TRUE);
504 closeButton.setBorder(handyEmptyBorder);
513 iconifyButton = createTitleButton();
514 iconifyButton.setAction(iconifyAction);
515 iconifyButton.setText(null);
516 iconifyButton.putClientProperty("paintActive", Boolean.TRUE);
517 iconifyButton.setBorder(handyEmptyBorder);
518 iconifyButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
519 "Iconify");
520 iconifyButton.setIcon(UIManager.getIcon("InternalFrame.iconifyIcon"));
521
522 toggleButton = createTitleButton();
523 toggleButton.setAction(restoreAction);
524 toggleButton.putClientProperty("paintActive", Boolean.TRUE);
525 toggleButton.setBorder(handyEmptyBorder);
526 toggleButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
527 "Maximize");
528 toggleButton.setIcon(maximizeIcon);
529 }
530 }
531
532 /**
533 * Returns the <code>LayoutManager</code> that should be installed on
534 * the <code>MetalTitlePane</code>.
535 */
536 private LayoutManager createLayout() {
537 return new TitlePaneLayout();
538 }
539
540 /**
541 * Updates state dependant upon the Window's active state.
542 */
543 private void setActive(boolean isActive) {
544 Boolean activeB = isActive ? Boolean.TRUE : Boolean.FALSE;
545
546 closeButton.putClientProperty("paintActive", activeB);
547 if (getWindowDecorationStyle() == JRootPane.FRAME) {
548 iconifyButton.putClientProperty("paintActive", activeB);
549 toggleButton.putClientProperty("paintActive", activeB);
550 }
551 // Repaint the whole thing as the Borders that are used have
552 // different colors for active vs inactive
553 getRootPane().repaint();
554 }
555
556 /**
557 * Sets the state of the Window.
558 */
559 private void setState(int state) {
560 setState(state, false);
561 }
562
563 /**
564 * Sets the state of the window. If <code>updateRegardless</code> is
565 * true and the state has not changed, this will update anyway.
566 */
567 private void setState(int state, boolean updateRegardless) {
568 Window w = getWindow();
569
570 if (w != null && getWindowDecorationStyle() == JRootPane.FRAME) {
571 if (this.state == state && !updateRegardless) {
572 return;
573 }
574 Frame frame = getFrame();
575
576 if (frame != null) {
577 JRootPane rootPane = getRootPane();
578
579 if (((state & Frame.MAXIMIZED_BOTH) != 0) &&
580 (rootPane.getBorder() == null ||
581 (rootPane.getBorder() instanceof UIResource)) &&
582 frame.isShowing()) {
583 rootPane.setBorder(null);
584 }
616 repaint();
617 }
618 }
619 }
620 else {
621 // Not contained in a Frame
622 maximizeAction.setEnabled(false);
623 restoreAction.setEnabled(false);
624 iconifyAction.setEnabled(false);
625 remove(toggleButton);
626 remove(iconifyButton);
627 revalidate();
628 repaint();
629 }
630 closeAction.setEnabled(true);
631 this.state = state;
632 }
633 }
634
635 /**
636 * Updates the toggle button to contain the Icon <code>icon</code>, and
637 * Action <code>action</code>.
638 */
639 private void updateToggleButton(Action action, Icon icon) {
640 toggleButton.setAction(action);
641 toggleButton.setIcon(icon);
642 toggleButton.setText(null);
643 }
644
645 /**
646 * Returns the Frame rendering in. This will return null if the
647 * <code>JRootPane</code> is not contained in a <code>Frame</code>.
648 */
649 private Frame getFrame() {
650 Window window = getWindow();
651
652 if (window instanceof Frame) {
653 return (Frame)window;
654 }
655 return null;
656 }
657
658 /**
659 * Returns the <code>Window</code> the <code>JRootPane</code> is
660 * contained in. This will return null if there is no parent ancestor
661 * of the <code>JRootPane</code>.
662 */
663 private Window getWindow() {
664 return window;
665 }
666
667 /**
668 * Returns the String to display as the title.
669 */
670 private String getTitle() {
671 Window w = getWindow();
672
673 if (w instanceof Frame) {
674 return ((Frame)w).getTitle();
675 }
676 else if (w instanceof Dialog) {
677 return ((Dialog)w).getTitle();
678 }
679 return null;
680 }
681
763 yOffset );
764 xOffset += leftToRight ? titleLength + 5 : -5;
765 }
766
767 int bumpXOffset;
768 int bumpLength;
769 if( leftToRight ) {
770 bumpLength = width - buttonsWidth - xOffset - 5;
771 bumpXOffset = xOffset;
772 } else {
773 bumpLength = xOffset - buttonsWidth - 5;
774 bumpXOffset = buttonsWidth + 5;
775 }
776 int bumpYOffset = 3;
777 int bumpHeight = getHeight() - (2 * bumpYOffset);
778 bumps.setBumpArea( bumpLength, bumpHeight );
779 bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
780 }
781
782 /**
783 * Actions used to <code>close</code> the <code>Window</code>.
784 */
785 @SuppressWarnings("serial") // Superclass is not serializable across versions
786 private class CloseAction extends AbstractAction {
787 public CloseAction() {
788 super(UIManager.getString("MetalTitlePane.closeTitle",
789 getLocale()));
790 }
791
792 public void actionPerformed(ActionEvent e) {
793 close();
794 }
795 }
796
797
798 /**
799 * Actions used to <code>iconfiy</code> the <code>Frame</code>.
800 */
801 @SuppressWarnings("serial") // Superclass is not serializable across versions
802 private class IconifyAction extends AbstractAction {
803 public IconifyAction() {
804 super(UIManager.getString("MetalTitlePane.iconifyTitle",
805 getLocale()));
806 }
807
808 public void actionPerformed(ActionEvent e) {
809 iconify();
810 }
811 }
812
813
814 /**
815 * Actions used to <code>restore</code> the <code>Frame</code>.
816 */
817 @SuppressWarnings("serial") // Superclass is not serializable across versions
818 private class RestoreAction extends AbstractAction {
819 public RestoreAction() {
820 super(UIManager.getString
821 ("MetalTitlePane.restoreTitle", getLocale()));
822 }
823
824 public void actionPerformed(ActionEvent e) {
825 restore();
826 }
827 }
828
829
830 /**
831 * Actions used to <code>restore</code> the <code>Frame</code>.
832 */
833 @SuppressWarnings("serial") // Superclass is not serializable across versions
834 private class MaximizeAction extends AbstractAction {
835 public MaximizeAction() {
836 super(UIManager.getString("MetalTitlePane.maximizeTitle",
837 getLocale()));
838 }
839
840 public void actionPerformed(ActionEvent e) {
841 maximize();
842 }
843 }
844
845
846 /**
847 * Class responsible for drawing the system menu. Looks up the
848 * image to draw from the Frame associated with the
849 * <code>JRootPane</code>.
850 */
851 @SuppressWarnings("serial") // Superclass is not serializable across versions
852 private class SystemMenuBar extends JMenuBar {
853 public void paint(Graphics g) {
854 if (isOpaque()) {
855 g.setColor(getBackground());
856 g.fillRect(0, 0, getWidth(), getHeight());
857 }
858
859 if (systemIcon != null) {
860 g.drawImage(systemIcon, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
861 } else {
862 Icon icon = UIManager.getIcon("InternalFrame.icon");
863
864 if (icon != null) {
865 icon.paintIcon(this, g, 0, 0);
866 }
867 }
868 }
869 public Dimension getMinimumSize() {
|
198 private void installListeners() {
199 if (window != null) {
200 windowListener = createWindowListener();
201 window.addWindowListener(windowListener);
202 propertyChangeListener = createWindowPropertyChangeListener();
203 window.addPropertyChangeListener(propertyChangeListener);
204 }
205 }
206
207 /**
208 * Uninstalls the necessary listeners.
209 */
210 private void uninstallListeners() {
211 if (window != null) {
212 window.removeWindowListener(windowListener);
213 window.removePropertyChangeListener(propertyChangeListener);
214 }
215 }
216
217 /**
218 * Returns the {@code WindowListener} to add to the
219 * {@code Window}.
220 */
221 private WindowListener createWindowListener() {
222 return new WindowHandler();
223 }
224
225 /**
226 * Returns the {@code PropertyChangeListener} to install on
227 * the {@code Window}.
228 */
229 private PropertyChangeListener createWindowPropertyChangeListener() {
230 return new PropertyChangeHandler();
231 }
232
233 /**
234 * Returns the {@code JRootPane} this was created for.
235 */
236 public JRootPane getRootPane() {
237 return rootPane;
238 }
239
240 /**
241 * Returns the decoration style of the {@code JRootPane}.
242 */
243 private int getWindowDecorationStyle() {
244 return getRootPane().getWindowDecorationStyle();
245 }
246
247 public void addNotify() {
248 super.addNotify();
249
250 uninstallListeners();
251
252 window = SwingUtilities.getWindowAncestor(this);
253 if (window != null) {
254 if (window instanceof Frame) {
255 setState(((Frame)window).getExtendedState());
256 }
257 else {
258 setState(0);
259 }
260 setActive(window.isActive());
261 installListeners();
262 updateSystemIcon();
263 }
264 }
265
266 public void removeNotify() {
267 super.removeNotify();
268
269 uninstallListeners();
270 window = null;
271 }
272
273 /**
274 * Adds any sub-Components contained in the {@code MetalTitlePane}.
275 */
276 private void installSubcomponents() {
277 int decorationStyle = getWindowDecorationStyle();
278 if (decorationStyle == JRootPane.FRAME) {
279 createActions();
280 menuBar = createMenuBar();
281 add(menuBar);
282 createButtons();
283 add(iconifyButton);
284 add(toggleButton);
285 add(closeButton);
286 } else if (decorationStyle == JRootPane.PLAIN_DIALOG ||
287 decorationStyle == JRootPane.INFORMATION_DIALOG ||
288 decorationStyle == JRootPane.ERROR_DIALOG ||
289 decorationStyle == JRootPane.COLOR_CHOOSER_DIALOG ||
290 decorationStyle == JRootPane.FILE_CHOOSER_DIALOG ||
291 decorationStyle == JRootPane.QUESTION_DIALOG ||
292 decorationStyle == JRootPane.WARNING_DIALOG) {
293 createActions();
294 createButtons();
341 break;
342 }
343 activeBumps.setBumpColors(activeBumpsHighlight, activeBumpsShadow,
344 activeBackground);
345 }
346
347 /**
348 * Installs the fonts and necessary properties on the MetalTitlePane.
349 */
350 private void installDefaults() {
351 setFont(UIManager.getFont("InternalFrame.titleFont", getLocale()));
352 }
353
354 /**
355 * Uninstalls any previously installed UI values.
356 */
357 private void uninstallDefaults() {
358 }
359
360 /**
361 * Returns the {@code JMenuBar} displaying the appropriate
362 * system menu items.
363 */
364 protected JMenuBar createMenuBar() {
365 menuBar = new SystemMenuBar();
366 menuBar.setFocusable(false);
367 menuBar.setBorderPainted(true);
368 menuBar.add(createMenu());
369 return menuBar;
370 }
371
372 /**
373 * Closes the Window.
374 */
375 private void close() {
376 Window window = getWindow();
377
378 if (window != null) {
379 window.dispatchEvent(new WindowEvent(
380 window, WindowEvent.WINDOW_CLOSING));
381 }
402 }
403
404 /**
405 * Restores the Frame size.
406 */
407 private void restore() {
408 Frame frame = getFrame();
409
410 if (frame == null) {
411 return;
412 }
413
414 if ((state & Frame.ICONIFIED) != 0) {
415 frame.setExtendedState(state & ~Frame.ICONIFIED);
416 } else {
417 frame.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
418 }
419 }
420
421 /**
422 * Create the {@code Action}s that get associated with the
423 * buttons and menu items.
424 */
425 private void createActions() {
426 closeAction = new CloseAction();
427 if (getWindowDecorationStyle() == JRootPane.FRAME) {
428 iconifyAction = new IconifyAction();
429 restoreAction = new RestoreAction();
430 maximizeAction = new MaximizeAction();
431 }
432 }
433
434 /**
435 * Returns the {@code JMenu} displaying the appropriate menu items
436 * for manipulating the Frame.
437 */
438 private JMenu createMenu() {
439 JMenu menu = new JMenu("");
440 if (getWindowDecorationStyle() == JRootPane.FRAME) {
441 addMenuItems(menu);
442 }
443 return menu;
444 }
445
446 /**
447 * Adds the necessary {@code JMenuItem}s to the passed in menu.
448 */
449 private void addMenuItems(JMenu menu) {
450 Locale locale = getRootPane().getLocale();
451 JMenuItem mi = menu.add(restoreAction);
452 int mnemonic = MetalUtils.getInt("MetalTitlePane.restoreMnemonic", -1);
453
454 if (mnemonic != -1) {
455 mi.setMnemonic(mnemonic);
456 }
457
458 mi = menu.add(iconifyAction);
459 mnemonic = MetalUtils.getInt("MetalTitlePane.iconifyMnemonic", -1);
460 if (mnemonic != -1) {
461 mi.setMnemonic(mnemonic);
462 }
463
464 if (Toolkit.getDefaultToolkit().isFrameStateSupported(
465 Frame.MAXIMIZED_BOTH)) {
466 mi = menu.add(maximizeAction);
467 mnemonic =
468 MetalUtils.getInt("MetalTitlePane.maximizeMnemonic", -1);
469 if (mnemonic != -1) {
470 mi.setMnemonic(mnemonic);
471 }
472 }
473
474 menu.add(new JSeparator());
475
476 mi = menu.add(closeAction);
477 mnemonic = MetalUtils.getInt("MetalTitlePane.closeMnemonic", -1);
478 if (mnemonic != -1) {
479 mi.setMnemonic(mnemonic);
480 }
481 }
482
483 /**
484 * Returns a {@code JButton} appropriate for placement on the
485 * TitlePane.
486 */
487 private JButton createTitleButton() {
488 JButton button = new JButton();
489
490 button.setFocusPainted(false);
491 button.setFocusable(false);
492 button.setOpaque(true);
493 return button;
494 }
495
496 /**
497 * Creates the Buttons that will be placed on the TitlePane.
498 */
499 private void createButtons() {
500 closeButton = createTitleButton();
501 closeButton.setAction(closeAction);
502 closeButton.setText(null);
503 closeButton.putClientProperty("paintActive", Boolean.TRUE);
504 closeButton.setBorder(handyEmptyBorder);
513 iconifyButton = createTitleButton();
514 iconifyButton.setAction(iconifyAction);
515 iconifyButton.setText(null);
516 iconifyButton.putClientProperty("paintActive", Boolean.TRUE);
517 iconifyButton.setBorder(handyEmptyBorder);
518 iconifyButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
519 "Iconify");
520 iconifyButton.setIcon(UIManager.getIcon("InternalFrame.iconifyIcon"));
521
522 toggleButton = createTitleButton();
523 toggleButton.setAction(restoreAction);
524 toggleButton.putClientProperty("paintActive", Boolean.TRUE);
525 toggleButton.setBorder(handyEmptyBorder);
526 toggleButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
527 "Maximize");
528 toggleButton.setIcon(maximizeIcon);
529 }
530 }
531
532 /**
533 * Returns the {@code LayoutManager} that should be installed on
534 * the {@code MetalTitlePane}.
535 */
536 private LayoutManager createLayout() {
537 return new TitlePaneLayout();
538 }
539
540 /**
541 * Updates state dependant upon the Window's active state.
542 */
543 private void setActive(boolean isActive) {
544 Boolean activeB = isActive ? Boolean.TRUE : Boolean.FALSE;
545
546 closeButton.putClientProperty("paintActive", activeB);
547 if (getWindowDecorationStyle() == JRootPane.FRAME) {
548 iconifyButton.putClientProperty("paintActive", activeB);
549 toggleButton.putClientProperty("paintActive", activeB);
550 }
551 // Repaint the whole thing as the Borders that are used have
552 // different colors for active vs inactive
553 getRootPane().repaint();
554 }
555
556 /**
557 * Sets the state of the Window.
558 */
559 private void setState(int state) {
560 setState(state, false);
561 }
562
563 /**
564 * Sets the state of the window. If {@code updateRegardless} is
565 * true and the state has not changed, this will update anyway.
566 */
567 private void setState(int state, boolean updateRegardless) {
568 Window w = getWindow();
569
570 if (w != null && getWindowDecorationStyle() == JRootPane.FRAME) {
571 if (this.state == state && !updateRegardless) {
572 return;
573 }
574 Frame frame = getFrame();
575
576 if (frame != null) {
577 JRootPane rootPane = getRootPane();
578
579 if (((state & Frame.MAXIMIZED_BOTH) != 0) &&
580 (rootPane.getBorder() == null ||
581 (rootPane.getBorder() instanceof UIResource)) &&
582 frame.isShowing()) {
583 rootPane.setBorder(null);
584 }
616 repaint();
617 }
618 }
619 }
620 else {
621 // Not contained in a Frame
622 maximizeAction.setEnabled(false);
623 restoreAction.setEnabled(false);
624 iconifyAction.setEnabled(false);
625 remove(toggleButton);
626 remove(iconifyButton);
627 revalidate();
628 repaint();
629 }
630 closeAction.setEnabled(true);
631 this.state = state;
632 }
633 }
634
635 /**
636 * Updates the toggle button to contain the Icon {@code icon}, and
637 * Action {@code action}.
638 */
639 private void updateToggleButton(Action action, Icon icon) {
640 toggleButton.setAction(action);
641 toggleButton.setIcon(icon);
642 toggleButton.setText(null);
643 }
644
645 /**
646 * Returns the Frame rendering in. This will return null if the
647 * {@code JRootPane} is not contained in a {@code Frame}.
648 */
649 private Frame getFrame() {
650 Window window = getWindow();
651
652 if (window instanceof Frame) {
653 return (Frame)window;
654 }
655 return null;
656 }
657
658 /**
659 * Returns the {@code Window} the {@code JRootPane} is
660 * contained in. This will return null if there is no parent ancestor
661 * of the {@code JRootPane}.
662 */
663 private Window getWindow() {
664 return window;
665 }
666
667 /**
668 * Returns the String to display as the title.
669 */
670 private String getTitle() {
671 Window w = getWindow();
672
673 if (w instanceof Frame) {
674 return ((Frame)w).getTitle();
675 }
676 else if (w instanceof Dialog) {
677 return ((Dialog)w).getTitle();
678 }
679 return null;
680 }
681
763 yOffset );
764 xOffset += leftToRight ? titleLength + 5 : -5;
765 }
766
767 int bumpXOffset;
768 int bumpLength;
769 if( leftToRight ) {
770 bumpLength = width - buttonsWidth - xOffset - 5;
771 bumpXOffset = xOffset;
772 } else {
773 bumpLength = xOffset - buttonsWidth - 5;
774 bumpXOffset = buttonsWidth + 5;
775 }
776 int bumpYOffset = 3;
777 int bumpHeight = getHeight() - (2 * bumpYOffset);
778 bumps.setBumpArea( bumpLength, bumpHeight );
779 bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
780 }
781
782 /**
783 * Actions used to {@code close} the {@code Window}.
784 */
785 @SuppressWarnings("serial") // Superclass is not serializable across versions
786 private class CloseAction extends AbstractAction {
787 public CloseAction() {
788 super(UIManager.getString("MetalTitlePane.closeTitle",
789 getLocale()));
790 }
791
792 public void actionPerformed(ActionEvent e) {
793 close();
794 }
795 }
796
797
798 /**
799 * Actions used to {@code iconfiy} the {@code Frame}.
800 */
801 @SuppressWarnings("serial") // Superclass is not serializable across versions
802 private class IconifyAction extends AbstractAction {
803 public IconifyAction() {
804 super(UIManager.getString("MetalTitlePane.iconifyTitle",
805 getLocale()));
806 }
807
808 public void actionPerformed(ActionEvent e) {
809 iconify();
810 }
811 }
812
813
814 /**
815 * Actions used to {@code restore} the {@code Frame}.
816 */
817 @SuppressWarnings("serial") // Superclass is not serializable across versions
818 private class RestoreAction extends AbstractAction {
819 public RestoreAction() {
820 super(UIManager.getString
821 ("MetalTitlePane.restoreTitle", getLocale()));
822 }
823
824 public void actionPerformed(ActionEvent e) {
825 restore();
826 }
827 }
828
829
830 /**
831 * Actions used to {@code restore} the {@code Frame}.
832 */
833 @SuppressWarnings("serial") // Superclass is not serializable across versions
834 private class MaximizeAction extends AbstractAction {
835 public MaximizeAction() {
836 super(UIManager.getString("MetalTitlePane.maximizeTitle",
837 getLocale()));
838 }
839
840 public void actionPerformed(ActionEvent e) {
841 maximize();
842 }
843 }
844
845
846 /**
847 * Class responsible for drawing the system menu. Looks up the
848 * image to draw from the Frame associated with the
849 * {@code JRootPane}.
850 */
851 @SuppressWarnings("serial") // Superclass is not serializable across versions
852 private class SystemMenuBar extends JMenuBar {
853 public void paint(Graphics g) {
854 if (isOpaque()) {
855 g.setColor(getBackground());
856 g.fillRect(0, 0, getWidth(), getHeight());
857 }
858
859 if (systemIcon != null) {
860 g.drawImage(systemIcon, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
861 } else {
862 Icon icon = UIManager.getIcon("InternalFrame.icon");
863
864 if (icon != null) {
865 icon.paintIcon(this, g, 0, 0);
866 }
867 }
868 }
869 public Dimension getMinimumSize() {
|