Merge from mainline
[official-gcc.git] / libjava / classpath / javax / swing / JInternalFrame.java
blob948988c24a7ad410180db424c7b163f81ec32121
1 /* JInternalFrame.java --
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import java.awt.Component;
42 import java.awt.Container;
43 import java.awt.Graphics;
44 import java.awt.KeyboardFocusManager;
45 import java.awt.LayoutManager;
46 import java.awt.Rectangle;
47 import java.beans.PropertyVetoException;
49 import javax.accessibility.Accessible;
50 import javax.accessibility.AccessibleContext;
51 import javax.accessibility.AccessibleRole;
52 import javax.accessibility.AccessibleValue;
53 import javax.swing.event.InternalFrameEvent;
54 import javax.swing.event.InternalFrameListener;
55 import javax.swing.plaf.DesktopIconUI;
56 import javax.swing.plaf.InternalFrameUI;
58 /**
59 * This class implements a Swing widget that looks and acts like a native
60 * frame. The frame can be dragged, resized, closed, etc. Typically,
61 * JInternalFrames are placed in JDesktopPanes. The actions that the
62 * JInternalFrame performs (maximizing, minimizing, etc.) are performed by a
63 * DesktopManager. As with regular frames, components are added by calling
64 * frame.getContentPane().add.
66 public class JInternalFrame extends JComponent implements Accessible,
67 WindowConstants,
68 RootPaneContainer
70 /** DOCUMENT ME! */
71 private static final long serialVersionUID = -5425177187760785402L;
73 /**
74 * DOCUMENT ME!
76 protected class AccessibleJInternalFrame extends AccessibleJComponent
77 implements AccessibleValue
79 private static final long serialVersionUID = 5931936924175476797L;
81 /**
82 * Creates a new AccessibleJInternalFrame object.
84 protected AccessibleJInternalFrame()
86 super();
89 /**
90 * DOCUMENT ME!
92 * @return DOCUMENT ME!
94 public String getAccessibleName()
96 return null;
99 /**
100 * DOCUMENT ME!
102 * @return DOCUMENT ME!
104 public AccessibleRole getAccessibleRole()
106 return null;
110 * DOCUMENT ME!
112 * @return DOCUMENT ME!
114 public AccessibleValue getAccessibleValue()
116 return null;
120 * DOCUMENT ME!
122 * @return DOCUMENT ME!
124 public Number getCurrentAccessibleValue()
126 return null;
130 * DOCUMENT ME!
132 * @return DOCUMENT ME!
134 public Number getMaximumAccessibleValue()
136 return null;
140 * DOCUMENT ME!
142 * @return DOCUMENT ME!
144 public Number getMinimumAccessibleValue()
146 return null;
150 * DOCUMENT ME!
152 * @param n DOCUMENT ME!
154 * @return DOCUMENT ME!
156 public boolean setCurrentAccessibleValue(Number n)
158 return false;
163 * This class represents the JInternalFrame while it is iconified.
165 public static class JDesktopIcon extends JComponent implements Accessible
168 * DOCUMENT ME!
170 protected class AccessibleJDesktopIcon extends AccessibleJComponent
171 implements AccessibleValue
173 private static final long serialVersionUID = 5035560458941637802L;
176 * Creates a new AccessibleJDesktopIcon object.
178 protected AccessibleJDesktopIcon()
180 super();
184 * DOCUMENT ME!
186 * @return DOCUMENT ME!
188 public AccessibleRole getAccessibleRole()
190 return null;
194 * DOCUMENT ME!
196 * @return DOCUMENT ME!
198 public AccessibleValue getAccessibleValue()
200 return null;
204 * DOCUMENT ME!
206 * @return DOCUMENT ME!
208 public Number getCurrentAccessibleValue()
210 return null;
214 * DOCUMENT ME!
216 * @return DOCUMENT ME!
218 public Number getMaximumAccessibleValue()
220 return null;
224 * DOCUMENT ME!
226 * @return DOCUMENT ME!
228 public Number getMinimumAccessibleValue()
230 return null;
234 * DOCUMENT ME!
236 * @param n DOCUMENT ME!
238 * @return DOCUMENT ME!
240 public boolean setCurrentAccessibleValue(Number n)
242 return false;
246 private static final long serialVersionUID = 4672973344731387687L;
248 /** The JInternalFrame this DesktopIcon represents. */
249 JInternalFrame frame;
252 * Creates a new JDesktopIcon object for representing the given frame.
254 * @param f The JInternalFrame to represent.
256 public JDesktopIcon(JInternalFrame f)
258 frame = f;
259 updateUI();
263 * DOCUMENT ME!
265 * @return DOCUMENT ME!
267 public AccessibleContext getAccessibleContext()
269 if (accessibleContext == null)
270 accessibleContext = new AccessibleJDesktopIcon();
271 return accessibleContext;
275 * This method returns the JDesktopPane this JDesktopIcon is in.
277 * @return The JDesktopPane this JDesktopIcon is in.
279 public JDesktopPane getDesktopPane()
281 JDesktopPane p = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
282 this);
283 return p;
287 * This method returns the JInternalFrame this JDesktopIcon represents.
289 * @return The JInternalFrame this JDesktopIcon represents.
291 public JInternalFrame getInternalFrame()
293 return frame;
297 * This method returns the UI that is responsible for the JDesktopIcon.
299 * @return The UI that is responsible for the JDesktopIcon.
301 public DesktopIconUI getUI()
303 return (DesktopIconUI) ui;
307 * This method returns the String identifier that is used to determine
308 * which class is used for JDesktopIcon's UI.
310 * @return A String identifier for the UI class.
312 public String getUIClassID()
314 return "DesktopIconUI";
318 * This method sets the JInternalFrame that this JDesktopIcon represents.
320 * @param f The JInternalFrame that this JDesktopIcon represents.
322 public void setInternalFrame(JInternalFrame f)
324 frame = f;
328 * This method sets the UI used for this JDesktopIcon.
330 * @param ui The UI to use.
332 public void setUI(DesktopIconUI ui)
334 super.setUI(ui);
338 * This method restores the UI property to the defaults.
340 public void updateUI()
342 setUI((DesktopIconUI) UIManager.getUI(this));
347 * The property fired in a PropertyChangeEvent when the contentPane property
348 * changes.
350 public static final String CONTENT_PANE_PROPERTY = "contentPane";
353 * The property fired in a PropertyChangeEvent when the frameIcon property
354 * changes.
356 public static final String FRAME_ICON_PROPERTY = "frameIcon";
359 * The property fired in a PropertyChangeEvent when the glassPane property
360 * changes.
362 public static final String GLASS_PANE_PROPERTY = "glassPane";
365 * The property fired in a PropertyChangeEvent when the closed property
366 * changes.
368 public static final String IS_CLOSED_PROPERTY = "closed";
371 * The property fired in a PropertyChangeEvent when the icon property
372 * changes.
374 public static final String IS_ICON_PROPERTY = "icon";
377 * The property fired in a PropertyChangeEvent when the maximum property
378 * changes.
380 public static final String IS_MAXIMUM_PROPERTY = "maximum";
383 * The property fired in a PropertyChangeEvent when the selected property
384 * changes.
386 public static final String IS_SELECTED_PROPERTY = "selected";
389 * The property fired in a PropertyChangeEvent when the layeredPane property
390 * changes.
392 public static final String LAYERED_PANE_PROPERTY = "layeredPane";
395 * The property fired in a PropertyChangeEvent when the jMenuBar property
396 * changes.
398 public static final String MENU_BAR_PROPERTY = "JMenuBar";
401 * The property fired in a PropertyChangeEvent when the rootPane property
402 * changes.
404 public static final String ROOT_PANE_PROPERTY = "rootPane";
407 * The property fired in a PropertyChangeEvent when the title property
408 * changes.
410 public static final String TITLE_PROPERTY = "title";
412 /** Whether the JInternalFrame is closable. */
413 protected boolean closable;
415 /** Whether the JInternalFrame can be iconified. */
416 protected boolean iconable;
418 /** Whether the JInternalFrame is closed. */
419 protected boolean isClosed;
421 /** Whether the JInternalFrame has been iconified. */
422 protected boolean isIcon;
424 /** Whether the JInternalFrame has been maximized. */
425 protected boolean isMaximum;
427 /** Whether the JInternalFrame is the active frame. */
428 protected boolean isSelected;
430 /** Whether the JInternalFrame can be maximized. */
431 protected boolean maximizable;
434 * Whether the JInternalFrame has rootPaneChecking enabled.
436 * @specnote Should be false to comply with J2SE 5.0
438 protected boolean rootPaneCheckingEnabled = false;
440 /** Whether the JInternalFrame is resizable. */
441 protected boolean resizable;
444 * The JDesktopIcon that represents the JInternalFrame while it is
445 * iconified.
447 protected JDesktopIcon desktopIcon;
449 /** The icon used in the JMenuBar in the TitlePane. */
450 protected Icon frameIcon;
452 /** The rootPane of the JInternalFrame. */
453 protected JRootPane rootPane;
455 /** The title on the TitlePane of the JInternalFrame. */
456 protected String title;
458 /** The bounds of the JInternalFrame before it was maximized. */
459 private transient Rectangle storedBounds;
461 /** The Component that receives focus by default. */
462 private transient Component defaultFocus;
464 /** The default close action taken, */
465 private transient int defaultCloseOperation = DISPOSE_ON_CLOSE;
467 /** Whether the JInternalFrame has become visible for the very first time. */
468 private transient boolean isFirstTimeVisible = true;
471 * Whether the JInternalFrame is in the transition from being a maximized
472 * frame back to a regular sized frame.
474 private transient boolean maxTransition = false;
476 /** DOCUMENT ME! */
477 private transient boolean wasIcon = false;
480 * Creates a new JInternalFrame object that has no title, and is
481 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
483 public JInternalFrame()
485 this(null, false, false, false, false);
489 * Creates a new JInternalFrame object with the given title and is
490 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
492 * @param title The title displayed in the JInternalFrame.
494 public JInternalFrame(String title)
496 this(title, false, false, false, false);
500 * Creates a new JInternalFrame object with the given title and resizable
501 * properties. The JInternalFrame is non-maximizable, non-iconifiable, and
502 * non-closable.
504 * @param title The title displayed in the JInternalFrame.
505 * @param resizable Whether the JInternalFrame is resizable.
507 public JInternalFrame(String title, boolean resizable)
509 this(title, resizable, false, false, false);
513 * Creates a new JInternalFrame object with the given title, resizable, and
514 * closable properties. The JInternalFrame is non-maximizable and
515 * non-iconifiable.
517 * @param title The title displayed in the JInternalFrame.
518 * @param resizable Whether the JInternalFrame is resizable.
519 * @param closable Whether the JInternalFrame is closable.
521 public JInternalFrame(String title, boolean resizable, boolean closable)
523 this(title, resizable, closable, false, false);
527 * Creates a new JInternalFrame object with the given title, resizable,
528 * closable and maximizable properties. The JInternalFrame is
529 * non-iconifiable.
531 * @param title The title displayed in the JInternalFrame.
532 * @param resizable Whether the JInternalFrame is resizable.
533 * @param closable Whether the JInternalFrame is closable.
534 * @param maximizable Whether the JInternalFrame is maximizable.
536 public JInternalFrame(String title, boolean resizable, boolean closable,
537 boolean maximizable)
539 this(title, resizable, closable, maximizable, false);
543 * Creates a new JInternalFrame object with the given title, resizable,
544 * closable, maximizable and iconifiable properties.
546 * @param title The title displayed in the JInternalFrame.
547 * @param resizable Whether the JInternalFrame is resizable.
548 * @param closable Whether the JInternalFrame is closable.
549 * @param maximizable Whether the JInternalFrame is maximizable.
550 * @param iconifiable Whether the JInternalFrame is iconifiable.
552 public JInternalFrame(String title, boolean resizable, boolean closable,
553 boolean maximizable, boolean iconifiable)
555 this.title = title;
556 this.resizable = resizable;
557 this.closable = closable;
558 this.maximizable = maximizable;
559 this.iconable = iconifiable;
560 storedBounds = new Rectangle();
561 setRootPane(createRootPane());
562 updateUI();
563 setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
567 * This method adds Components to this Container. For JInternalFrames,
568 * instead of calling add directly on the JInternalFrame, it should be
569 * called with JInternalFrame.getContentPane().add. If root pane checking
570 * is enabled, calling this method will cause an exception to be thrown.
572 * @param comp The Component to add.
573 * @param constraints The constraints on the Component added.
574 * @param index The position to place the Component.
576 * @throws Error DOCUMENT ME!
578 protected void addImpl(Component comp, Object constraints, int index)
580 // If we're in the initialization stage use super.add. Here we add the
581 // rootPane as well as the title bar and other stuff.
582 // Otherwise pass the add onto the content pane.
583 if (isRootPaneCheckingEnabled())
584 getContentPane().add(comp, constraints, index);
585 else
586 super.addImpl(comp,constraints, index);
590 * This method adds an InternalFrameListener to this JInternalFrame.
592 * @param l The listener to add.
594 public void addInternalFrameListener(InternalFrameListener l)
596 listenerList.add(InternalFrameListener.class, l);
600 * This method is used to create a root pane for the JInternalFrame. This
601 * method is called by the constructors.
603 * @return A root pane for the JInternalFrame to use.
605 protected JRootPane createRootPane()
607 return new JRootPane();
611 * This method makes this JInternalFrame invisible, unselected and closed.
612 * If this JInternalFrame is not closed already, it will fire an
613 * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
614 * doesn't give vetoable listeners a chance to veto and it will not fire an
615 * INTERNAL_FRAME_CLOSING event.
617 public void dispose()
619 hide();
620 JDesktopPane pane = getDesktopPane();
621 if (pane != null)
622 pane.setSelectedFrame(null);
623 else
627 setSelected(false);
629 catch (PropertyVetoException e)
631 // Do nothing if they don't want to be unselected.
634 isClosed = true;
635 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
636 removeNotify();
640 * This method is used for closing this JInternalFrame. It fires an
641 * INTERNAL_FRAME_CLOSING event and then performs the action specified by
642 * the default close operation.
644 public void doDefaultCloseAction()
646 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
647 switch (getDefaultCloseOperation())
649 case HIDE_ON_CLOSE:
650 hide();
651 break;
652 case DISPOSE_ON_CLOSE:
653 dispose();
654 break;
659 * This method fires an InternalFrameEvent to the listeners.
661 * @param id The type of event being fired. See InternalFrameEvent.
663 protected void fireInternalFrameEvent(int id)
665 Object[] ifListeners = listenerList.getListenerList();
666 InternalFrameEvent evt = new InternalFrameEvent(this, id);
667 switch (id)
669 case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
670 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
672 if (ifListeners[i] == InternalFrameListener.class)
673 ((InternalFrameListener) ifListeners[i + 1])
674 .internalFrameClosing(evt);
676 break;
677 case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
678 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
680 if (ifListeners[i] == InternalFrameListener.class)
681 ((InternalFrameListener) ifListeners[i + 1])
682 .internalFrameActivated(evt);
684 break;
685 case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
686 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
688 if (ifListeners[i] == InternalFrameListener.class)
689 ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt);
691 break;
692 case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
693 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
695 if (ifListeners[i] == InternalFrameListener.class)
696 ((InternalFrameListener) ifListeners[i + 1])
697 .internalFrameDeactivated(evt);
699 break;
700 case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
701 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
703 if (ifListeners[i] == InternalFrameListener.class)
704 ((InternalFrameListener) ifListeners[i + 1])
705 .internalFrameDeiconified(evt);
707 break;
708 case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
709 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
711 if (ifListeners[i] == InternalFrameListener.class)
712 ((InternalFrameListener) ifListeners[i + 1])
713 .internalFrameIconified(evt);
715 break;
716 case InternalFrameEvent.INTERNAL_FRAME_OPENED:
717 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
719 if (ifListeners[i] == InternalFrameListener.class)
720 ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt);
722 break;
727 * DOCUMENT ME!
729 * @return DOCUMENT ME!
731 public AccessibleContext getAccessibleContext()
733 if (accessibleContext == null)
734 accessibleContext = new AccessibleJInternalFrame();
735 return accessibleContext;
739 * This method returns the Content Pane for this JInternalFrame.
741 * @return The Content Pane for this JInternalFrame.
743 public Container getContentPane()
745 return getRootPane().getContentPane();
749 * This method returns the default action taken when this JInternalFrame is
750 * closed.
752 * @return The default action taken when this JInternalFrame is closed.
754 public int getDefaultCloseOperation()
756 return defaultCloseOperation;
760 * This method returns the JDesktopIcon that represents this JInternalFrame
761 * while it is iconified.
763 * @return The JDesktopIcon that represents this JInternalFrame while it is
764 * iconified.
766 public JDesktopIcon getDesktopIcon()
768 if (desktopIcon == null)
769 desktopIcon = new JDesktopIcon(this);
770 return desktopIcon;
774 * This method searches this JInternalFrame ancestors for an instance of
775 * JDesktopPane. If one is found, it is returned. If none is found, then it
776 * will search the JDesktopIcon for a JDesktopPane.
778 * @return The JDesktopPane that this JInternalFrame belongs to.
780 public JDesktopPane getDesktopPane()
782 JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
783 this);
784 if (value == null && desktopIcon != null)
785 value = desktopIcon.getDesktopPane();
786 return value;
790 * This method returns null because this must always be the root of a focus
791 * traversal.
793 * @return always null
795 * @since 1.4
797 public final Container getFocusCycleRootAncestor()
799 // as defined.
800 return null;
804 * This method returns the child Component that will receive focus if this
805 * JInternalFrame is selected.
807 * @return The child Component that will receive focus.
809 public Component getFocusOwner()
811 if (isSelected())
813 Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
814 if (SwingUtilities.isDescendingFrom(focus, this))
816 defaultFocus = focus;
817 return focus;
820 return null;
824 * This method returns the Frame Icon (the icon used in the JInternalFrame
825 * TitlePane and iconified frame).
827 * @return The Frame Icon.
829 public Icon getFrameIcon()
831 return frameIcon;
835 * This method returns the Glass Pane used with this JInternalFrame.
837 * @return The Glass Pane used with this JInternalFrame.
839 public Component getGlassPane()
841 return getRootPane().getGlassPane();
845 * This method returns an array of InternalFrameListeners that are listening
846 * to this JInternalFrame.
848 * @return An array of InternalFrameListeners that are listening to this
849 * JInternalFrame.
851 public InternalFrameListener[] getInternalFrameListeners()
853 return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class);
857 * This method returns the JMenuBar for this JInternalFrame.
859 * @return The JMenuBar for this JInternalFrame.
861 public JMenuBar getJMenuBar()
863 return getRootPane().getJMenuBar();
867 * This method returns the layer that this JInternalFrame resides in.
869 * @return The layer that this JInternalFrame resides in.
871 public int getLayer()
873 JDesktopPane pane = getDesktopPane();
874 if (pane != null)
875 // The cast here forces the call to the instance method getLayer()
876 // instead of the static method (this would lead to infinite
877 // recursion).
878 return pane.getLayer((Component) this);
879 return -1;
883 * This method returns the LayeredPane for this JInternalFrame.
885 * @return The LayeredPane for this JInternalFrame.
887 public JLayeredPane getLayeredPane()
889 return getRootPane().getLayeredPane();
893 * This method is deprecated. This method returns the JMenuBar for this
894 * JInternalFrame.
896 * @return The JMenuBar for this JInternalFrame.
898 * @deprecated 1.0.3
900 public JMenuBar getMenuBar()
902 return getJMenuBar();
906 * This method returns the child Component that will receive focus when the
907 * JInternalFrame is selected. If the JInternalFrame is selected, this
908 * method returns getFocusOwner(). Otherwise, it will return the child
909 * Component that most recently requested focus. If that is null, then the
910 * initial focus Component is returned. If that is null, then the default
911 * focus component is returned.
913 * @return The most recent focus owner.
915 public Component getMostRecentFocusOwner()
917 if (isSelected())
918 return getFocusOwner();
919 else
920 return defaultFocus;
924 * This method returns the bounds of the JInternalFrame if it is not
925 * maximized. If it is maximized, it returns the bounds of the
926 * JInternalFrame before it was maximized (the bounds that it will be
927 * restored to).
929 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
930 * just its bounds if it is not maximized).
932 public Rectangle getNormalBounds()
934 if (! isMaximum() && ! maxTransition)
935 return getBounds();
936 else
937 return storedBounds;
941 * This method returns the Root Pane for this JInternalFrame.
943 * @return The Root Pane for this JInternalFrame.
945 public JRootPane getRootPane()
947 return rootPane;
951 * This method sets the title of the JInternalFrame.
953 * @return The String displayed in the TitlePane of this JInternalFrame.
955 public String getTitle()
957 return title;
961 * This method returns the UI used to represent the JInternalFrame.
963 * @return The UI used to represent the JInternalFrame.
965 public InternalFrameUI getUI()
967 return (InternalFrameUI) ui;
971 * This method returns a String identifier that is used to determine which
972 * class acts as the JInternalFrame's UI.
974 * @return A String identifier to determine a UI class.
976 public String getUIClassID()
978 return "InternalFrameUI";
982 * This method returns null.
984 * @return null.
986 public final String getWarningString()
988 // as defined.
989 return null;
993 * This method deselects this JInternalFrame and hides it.
995 public void hide()
997 JDesktopPane pane = getDesktopPane();
998 if (pane != null)
999 pane.setSelectedFrame(null);
1000 else
1004 setSelected(false);
1006 catch (PropertyVetoException e)
1008 // Do nothing.
1011 super.hide();
1015 * This method returns whether this JInternalFrame is closable.
1017 * @return Whether this JInternalFrame is closable.
1019 public boolean isClosable()
1021 return closable;
1025 * This method returns whether this JInternalFrame has been closed.
1027 * @return Whether this JInternalFrame is closed.
1029 public boolean isClosed()
1031 return isClosed;
1035 * This must always return true.
1037 * @return always true
1039 * @since 1.4
1041 public final boolean isFocusCycleRoot()
1043 return true;
1047 * This method returns whether this JInternalFrame is currently iconified.
1049 * @return Whether this JInternalFrame is currently iconified.
1051 public boolean isIcon()
1053 return isIcon;
1057 * This method returns whether the JInternalFrame can be iconified.
1059 * @return Whether the JInternalFrame can be iconified.
1061 public boolean isIconifiable()
1063 return iconable;
1067 * This method returns whether this JInternalFrame can be maximized.
1069 * @return Whether this JInternalFrame can be maximized.
1071 public boolean isMaximizable()
1073 return maximizable;
1077 * This method returns whether this JInternalFrame is currently maximized.
1079 * @return Whether this JInternalFrame is maximized.
1081 public boolean isMaximum()
1083 return isMaximum;
1087 * This method returns whether this JInternalFrame is resizable.
1089 * @return Whether this JInternalFrame is resizable.
1091 public boolean isResizable()
1093 return resizable;
1097 * This method returns whether root pane checking is enabled. If root pane
1098 * checking is enabled, then calls to addImpl and setLayout will throw
1099 * exceptions.
1101 * @return Whether root pane checking is enabled.
1103 protected boolean isRootPaneCheckingEnabled()
1105 return rootPaneCheckingEnabled;
1109 * This method returns whether this JInternalFrame is selected.
1111 * @return Whether this JInternalFrame is selected.
1113 public boolean isSelected()
1115 return isSelected;
1119 * A helper method that moves this JInternalFrame to the back if the parent
1120 * is a JLayeredPane.
1122 public void moveToBack()
1124 if (getParent() instanceof JLayeredPane)
1125 ((JLayeredPane) getParent()).moveToBack(this);
1129 * A helper method that moves this JInternalFrame to the front if the parent
1130 * is a JLayeredPane.
1132 public void moveToFront()
1134 if (getParent() instanceof JLayeredPane)
1135 ((JLayeredPane) getParent()).moveToFront(this);
1139 * This method causes the children of this JInternalFrame to be laid out.
1140 * Before it begins, if this JInternalFrame is an icon, then it will be
1141 * deiconified. If it is maximized, then it will be restored. If either
1142 * operation fails, then this method will return.
1144 public void pack()
1148 if (isIcon())
1149 setIcon(false);
1150 else if (isMaximum())
1151 setMaximum(false);
1153 catch (PropertyVetoException e)
1155 // Do nothing if they don't want to be restored first.
1157 setSize(getPreferredSize());
1161 * This method is overridden to allow for speedier painting while this
1162 * JInternalFramme is being dragged.
1164 * @param g The Graphics object to paint with.
1166 protected void paintComponent(Graphics g)
1168 super.paintComponent(g);
1172 * This method returns a String describing this JInternalFrame.
1174 * @return A String describing this JInternalFrame.
1176 protected String paramString()
1178 return super.paramString();
1182 * This method removes the given Component from the Container.
1184 * @param comp The Component to remove.
1186 public void remove(Component comp)
1188 // If we're removing the root pane, use super.remove. Otherwise
1189 // pass it on to the content pane instead.
1190 if (comp==rootPane)
1191 super.remove(comp);
1192 else
1193 getContentPane().remove(comp);
1197 * This method removes an InternalFrameListener from this JInternalFrame.
1199 * @param l The listener to remove.
1201 public void removeInternalFrameListener(InternalFrameListener l)
1203 listenerList.remove(InternalFrameListener.class, l);
1207 * This method resizes and positions this JInternalFrame. It also forces a
1208 * relayout of the Container.
1210 * @param x The x position of this JInternalFrame.
1211 * @param y The y position of this JInternalFrame.
1212 * @param width The width of this JInternalFrame.
1213 * @param height The height of this JInternalFrame.
1215 public void reshape(int x, int y, int width, int height)
1217 super.reshape(x, y, width, height);
1218 revalidate();
1222 * This method gives focus to the last child Component that had focus. This
1223 * is used by the UI when this JInternalFrame is activated.
1225 public void restoreSubcomponentFocus()
1227 Component c = getMostRecentFocusOwner();
1228 if (c != null)
1229 c.requestFocus();
1233 * This method sets whether this JInternalFrame can be closed.
1235 * @param b Whether this JInternalFrame can be closed.
1237 public void setClosable(boolean b)
1239 closable = b;
1243 * This method closes the JInternalFrame if the given boolean is true. If it
1244 * is false, then the result of this method is unspecified. If the
1245 * JInternalFrame is closed, this method does nothing. This method will
1246 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1247 * listeners to cancel the close. If no listener vetoes the change, the
1248 * closed property is set to true and the JInternalFrame is hidden and
1249 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1250 * event.
1252 * @param b Whether the JInternalFrame will be closed.
1254 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1256 public void setClosed(boolean b) throws PropertyVetoException
1258 if (b && ! isClosed())
1260 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
1261 fireVetoableChange(IS_CLOSED_PROPERTY, false, true);
1263 isClosed = b;
1265 firePropertyChange(IS_CLOSED_PROPERTY, false, true);
1266 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
1271 * This method sets the Container to be used as a Content Pane for this
1272 * JInternalFrame.
1274 * @param c The Container to use as a Content Pane.
1276 public void setContentPane(Container c)
1278 if (c != getContentPane())
1280 Container old = getContentPane();
1281 getRootPane().setContentPane(c);
1282 firePropertyChange(CONTENT_PANE_PROPERTY, old, c);
1287 * This method sets the action taken when this JInternalFrame is closed.
1289 * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1290 * DISPOSE_ON_CLOSE.
1292 * @throws Error If the given operation is not one of the allowed modes.
1294 public void setDefaultCloseOperation(int operation)
1296 /* Reference implementation allows invalid operations to be specified.
1297 In that case, behaviour defaults to DO_NOTHING_ON_CLOSE.
1298 processWindowEvent handles the behaviour. getDefaultCloseOperation
1299 must return the invalid operator code. */
1300 defaultCloseOperation = operation;
1304 * This method sets the JDesktopIcon that represents this JInternalFrame
1305 * while it is iconified.
1307 * @param d The JDesktopIcon that represents this JInternalFrame while it is
1308 * iconified.
1310 public void setDesktopIcon(JDesktopIcon d)
1312 d.setInternalFrame(this);
1313 desktopIcon = d;
1317 * This method does nothing because this must be the root of a focus
1318 * traversal cycle.
1320 * @param focusCycleRoot Not used.
1322 public final void setFocusCycleRoot(boolean focusCycleRoot)
1324 // Do nothing
1328 * This method sets the Icon to be used in two places. The first is icon
1329 * that is painted at the top left corner of the JInternalFrame when it is
1330 * not iconified (clicking on that icon will activate the TitlePane
1331 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1332 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1333 * will use a Look and Feel default.
1335 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1337 public void setFrameIcon(Icon icon)
1339 if (icon != frameIcon)
1341 Icon old = frameIcon;
1342 frameIcon = icon;
1343 firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon);
1348 * This method sets the Glass Pane used with this JInternalFrame.
1350 * @param glass The Glass Pane to use with this JInternalFrame.
1352 public void setGlassPane(Component glass)
1354 if (glass != getGlassPane())
1356 Component old = getGlassPane();
1357 getRootPane().setGlassPane(glass);
1358 firePropertyChange(GLASS_PANE_PROPERTY, old, glass);
1363 * This method iconifies or deiconifies this JInternalFrame given the
1364 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1365 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1366 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1368 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1370 * @throws PropertyVetoException DOCUMENT ME!
1372 public void setIcon(boolean b) throws PropertyVetoException
1374 if (b != isIcon())
1376 fireVetoableChange(IS_ICON_PROPERTY, b, isIcon);
1378 isIcon = b;
1380 firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon);
1381 if (b)
1382 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
1383 else
1384 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
1389 * This method sets whether the JInternalFrame can be iconified. (This means
1390 * that the JInternalFrame can be turned into an icon if minimized).
1392 * @param b Whether the JInternalFrame can be iconified.
1394 public void setIconifiable(boolean b)
1396 iconable = b;
1400 * This method sets the JMenuBar to be used with this JInternalFrame.
1402 * @param b The JMenuBar to be used with this JInternalFrame.
1404 public void setJMenuBar(JMenuBar b)
1406 getRootPane().setJMenuBar(b);
1410 * A helper method that set the layer that this JInternalFrame resides in.
1411 * Using this version of the method means that the user should not set it
1412 * to values that are already defined in JLayeredPane. If predefined values
1413 * are to be used, the user should use the setLayer(Integer) version.
1415 * @param layer The layer to place this JInternalFrame in.
1417 public void setLayer(int layer)
1419 setLayer(new Integer(layer));
1423 * A helper method that sets the layer that this JInternalFrame resides in.
1424 * Calling this version of the method should use layer values that are
1425 * already defined in JLayeredPane.
1427 * @param layer The layer to place this JInternalFrame in.
1429 public void setLayer(Integer layer)
1431 JDesktopPane p = getDesktopPane();
1432 if (p != null)
1434 int pos = p.getPosition(this);
1435 p.setLayer(this, layer.intValue(), pos);
1440 * This method sets the JLayeredPane to use with this JInternalFrame.
1442 * @param layered The JLayeredPane to use as a layeredPane.
1444 public void setLayeredPane(JLayeredPane layered)
1446 if (layered != getLayeredPane())
1448 JLayeredPane old = getLayeredPane();
1449 getRootPane().setLayeredPane(layered);
1450 firePropertyChange(LAYERED_PANE_PROPERTY, old, layered);
1455 * This method sets whether the JInternalFrame can be maximized.
1457 * @param b Whether this JInternalFrame can be maximized.
1459 public void setMaximizable(boolean b)
1461 maximizable = b;
1465 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1466 * should not be called on the JInternalFrame directly. Instead, it should
1467 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1468 * method with root pane checking enabled will cause exceptions to be
1469 * thrown.
1471 * @param manager The Layout Manager to be used with the JInternalFrame.
1473 * @throws Error If rootPaneChecking is enabled.
1475 public void setLayout(LayoutManager manager)
1477 // Check if we're in initialization stage. If so, call super.setLayout
1478 // otherwise, valid calls go to the content pane.
1479 if (isRootPaneCheckingEnabled())
1480 getContentPane().setLayout(manager);
1481 else
1482 super.setLayout(manager);
1486 * This method sets the JInternalFrame to maximized (if the given argument
1487 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1489 * @param b Whether this JInteralFrame will be maximized or restored.
1491 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1493 public void setMaximum(boolean b) throws PropertyVetoException
1495 if (b != isMaximum())
1497 fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum);
1498 isMaximum = b;
1499 if (b)
1500 setNormalBounds(getBounds());
1501 maxTransition = ! b;
1502 firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
1503 maxTransition = false;
1508 * This method is deprecated. This method sets the JMenuBar used with this
1509 * JInternalFrame.
1511 * @param m The JMenuBar to use with this JInternalFrame.
1513 * @deprecated 1.0.3
1515 public void setMenuBar(JMenuBar m)
1517 setJMenuBar(m);
1521 * This method sets the bounds that this JInternalFrame will be restored to.
1523 * @param r The bounds that this JInternalFrame will be restored to.
1525 public void setNormalBounds(Rectangle r)
1527 storedBounds.setBounds(r.x, r.y, r.width, r.height);
1531 * This method sets whether the JInternalFrame can be resized by a user
1532 * action (like dragging at the frame borders).
1534 * @param b Whether this JInternalFramer can be resized.
1536 public void setResizable(boolean b)
1538 resizable = b;
1542 * This method sets the Root Pane for this JInternalFrame.
1544 * @param root The Root Pane for this JInternalFrame.
1546 protected void setRootPane(JRootPane root)
1548 if (rootPane != null)
1549 remove(rootPane);
1551 rootPane = root;
1552 add(root);
1556 * This method sets whether root pane checking is enabled. If root pane
1557 * checking is enabled, then calls to addImpl and setLayout will throw
1558 * exceptions.
1560 * @param enabled Whether root pane checking is enabled.
1562 protected void setRootPaneCheckingEnabled(boolean enabled)
1564 rootPaneCheckingEnabled = enabled;
1568 * This method sets whether this JInternalFrame is the selected frame in the
1569 * JDesktopPane (or other container). When selected, a JInternalFrame will
1570 * have focus and paint its TitlePane differently (usually a different
1571 * colour). If this method selects the frame, this JInternalFrame will fire
1572 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1573 * fire an INTERNAL_FRAME_DEACTIVATED event.
1575 * @param selected Whether this JInternalFrame will become selected or
1576 * deselected.
1578 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1580 public void setSelected(boolean selected) throws PropertyVetoException
1582 if (selected != isSelected())
1584 fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected);
1586 if (! selected)
1587 defaultFocus = getMostRecentFocusOwner();
1589 isSelected = selected;
1591 if (selected)
1592 restoreSubcomponentFocus();
1594 firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
1596 if (isSelected)
1597 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
1598 else
1599 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
1604 * This method sets the title displayed in the TitlePane of this
1605 * JInternalFrame.
1607 * @param title The title displayed.
1609 public void setTitle(String title)
1611 if (title == null && this.title == null)
1612 return;
1613 if (title == null || this.title == null || ! this.title.equals(title))
1615 String old = title;
1616 this.title = title;
1617 firePropertyChange(TITLE_PROPERTY, old, this.title);
1622 * This method displays the JInternalFrame. If it is not visible, this
1623 * method will bring this JInternalFrame to the front, make it visible and
1624 * select it. If this is the first time this JInternalFrame is made
1625 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1627 public void show()
1629 if (! isVisible())
1631 super.show();
1633 JDesktopPane pane = getDesktopPane();
1634 if (pane != null)
1635 pane.setSelectedFrame(this);
1636 else
1640 setSelected(true);
1642 catch (PropertyVetoException e)
1644 // Do nothing. if they don't want to be selected.
1647 if (isFirstTimeVisible)
1649 isFirstTimeVisible = false;
1650 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
1656 * This method is used to set the UI responsible for the JInternalFrame.
1658 * @param ui The UI responsible for the JInternalFrame.
1660 public void setUI(InternalFrameUI ui)
1662 // We must temporarily go into init mode so that the UI can directly
1663 // manipulate the JInternalFrame.
1664 boolean old = isRootPaneCheckingEnabled();
1665 setRootPaneCheckingEnabled(false);
1666 super.setUI(ui);
1667 setRootPaneCheckingEnabled(old);
1671 * This method causes the JInternalFrame to be brough to back in the
1672 * z-order.
1674 public void toBack()
1676 moveToBack();
1680 * This method causes the JInternalFrame to be brought to front in the
1681 * z-order.
1683 public void toFront()
1685 moveToFront();
1689 * This method resets the UI to the Look and Feel defaults.
1691 public void updateUI()
1693 // We must go into the init stage when updating the UI, so the UI can
1694 // set layout and components directly on the internal frame, not its
1695 // content pane.
1696 boolean old = isRootPaneCheckingEnabled();
1697 setRootPaneCheckingEnabled(false);
1698 setUI((InternalFrameUI) UIManager.getUI(this));
1699 setRootPaneCheckingEnabled(old);
1703 * This helper method allows JInternalFrames to signal that they were
1704 * iconned for the first time.
1706 * @param b Whether the JInternalFrame was iconned.
1707 * @param ID The identifier of the property change event to fire if the
1708 * JInternalFrame is iconned for the first time.
1710 void setWasIcon(boolean b, String ID)
1712 if (b && ! wasIcon)
1714 wasIcon = b;
1715 firePropertyChange(ID, ! b, b);
1720 * This helper method returns whether the JInternalFrame has been iconned
1721 * once already.
1723 * @return Whether the JInternalFrame has been iconned once already.
1725 boolean getWasIcon()
1727 return wasIcon;
1731 * This method is a convenience method to fire vetoable property changes.
1733 * @param name The identifier of the property change.
1734 * @param oldValue The old value.
1735 * @param newValue The new value.
1737 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1738 * the change.
1740 private void fireVetoableChange(String name, boolean oldValue,
1741 boolean newValue)
1742 throws PropertyVetoException
1744 super.fireVetoableChange(name, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));