Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / javax / swing / JInternalFrame.java
blob5bd6f781cd0eaf1da273112fb651e453f90b1af1
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 // JInternalFrames are invisible by default.
563 setVisible(false);
564 updateUI();
565 setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
569 * This method adds Components to this Container. For JInternalFrames,
570 * instead of calling add directly on the JInternalFrame, it should be
571 * called with JInternalFrame.getContentPane().add. If root pane checking
572 * is enabled, calling this method will cause an exception to be thrown.
574 * @param comp The Component to add.
575 * @param constraints The constraints on the Component added.
576 * @param index The position to place the Component.
578 * @throws Error DOCUMENT ME!
580 protected void addImpl(Component comp, Object constraints, int index)
582 // If we're in the initialization stage use super.add. Here we add the
583 // rootPane as well as the title bar and other stuff.
584 // Otherwise pass the add onto the content pane.
585 if (isRootPaneCheckingEnabled())
586 getContentPane().add(comp, constraints, index);
587 else
588 super.addImpl(comp,constraints, index);
592 * This method adds an InternalFrameListener to this JInternalFrame.
594 * @param l The listener to add.
596 public void addInternalFrameListener(InternalFrameListener l)
598 listenerList.add(InternalFrameListener.class, l);
602 * This method is used to create a root pane for the JInternalFrame. This
603 * method is called by the constructors.
605 * @return A root pane for the JInternalFrame to use.
607 protected JRootPane createRootPane()
609 return new JRootPane();
613 * This method makes this JInternalFrame invisible, unselected and closed.
614 * If this JInternalFrame is not closed already, it will fire an
615 * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
616 * doesn't give vetoable listeners a chance to veto and it will not fire an
617 * INTERNAL_FRAME_CLOSING event.
619 public void dispose()
621 setVisible(false);
622 JDesktopPane pane = getDesktopPane();
623 if (pane != null)
624 pane.setSelectedFrame(null);
625 else
629 setSelected(false);
631 catch (PropertyVetoException e)
633 // Do nothing if they don't want to be unselected.
636 isClosed = true;
637 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
638 removeNotify();
642 * This method is used for closing this JInternalFrame. It fires an
643 * INTERNAL_FRAME_CLOSING event and then performs the action specified by
644 * the default close operation.
646 public void doDefaultCloseAction()
648 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
649 switch (getDefaultCloseOperation())
651 case HIDE_ON_CLOSE:
652 setVisible(false);
653 break;
654 case DISPOSE_ON_CLOSE:
655 dispose();
656 break;
661 * This method fires an InternalFrameEvent to the listeners.
663 * @param id The type of event being fired. See InternalFrameEvent.
665 protected void fireInternalFrameEvent(int id)
667 Object[] ifListeners = listenerList.getListenerList();
668 InternalFrameEvent evt = new InternalFrameEvent(this, id);
669 switch (id)
671 case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
672 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
674 if (ifListeners[i] == InternalFrameListener.class)
675 ((InternalFrameListener) ifListeners[i + 1])
676 .internalFrameClosing(evt);
678 break;
679 case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
680 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
682 if (ifListeners[i] == InternalFrameListener.class)
683 ((InternalFrameListener) ifListeners[i + 1])
684 .internalFrameActivated(evt);
686 break;
687 case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
688 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
690 if (ifListeners[i] == InternalFrameListener.class)
691 ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt);
693 break;
694 case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
695 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
697 if (ifListeners[i] == InternalFrameListener.class)
698 ((InternalFrameListener) ifListeners[i + 1])
699 .internalFrameDeactivated(evt);
701 break;
702 case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
703 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
705 if (ifListeners[i] == InternalFrameListener.class)
706 ((InternalFrameListener) ifListeners[i + 1])
707 .internalFrameDeiconified(evt);
709 break;
710 case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
711 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
713 if (ifListeners[i] == InternalFrameListener.class)
714 ((InternalFrameListener) ifListeners[i + 1])
715 .internalFrameIconified(evt);
717 break;
718 case InternalFrameEvent.INTERNAL_FRAME_OPENED:
719 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
721 if (ifListeners[i] == InternalFrameListener.class)
722 ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt);
724 break;
729 * DOCUMENT ME!
731 * @return DOCUMENT ME!
733 public AccessibleContext getAccessibleContext()
735 if (accessibleContext == null)
736 accessibleContext = new AccessibleJInternalFrame();
737 return accessibleContext;
741 * This method returns the Content Pane for this JInternalFrame.
743 * @return The Content Pane for this JInternalFrame.
745 public Container getContentPane()
747 return getRootPane().getContentPane();
751 * This method returns the default action taken when this JInternalFrame is
752 * closed.
754 * @return The default action taken when this JInternalFrame is closed.
756 public int getDefaultCloseOperation()
758 return defaultCloseOperation;
762 * This method returns the JDesktopIcon that represents this JInternalFrame
763 * while it is iconified.
765 * @return The JDesktopIcon that represents this JInternalFrame while it is
766 * iconified.
768 public JDesktopIcon getDesktopIcon()
770 if (desktopIcon == null)
771 desktopIcon = new JDesktopIcon(this);
772 return desktopIcon;
776 * This method searches this JInternalFrame ancestors for an instance of
777 * JDesktopPane. If one is found, it is returned. If none is found, then it
778 * will search the JDesktopIcon for a JDesktopPane.
780 * @return The JDesktopPane that this JInternalFrame belongs to.
782 public JDesktopPane getDesktopPane()
784 JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
785 this);
786 if (value == null && desktopIcon != null)
787 value = desktopIcon.getDesktopPane();
788 return value;
792 * This method returns null because this must always be the root of a focus
793 * traversal.
795 * @return always null
797 * @since 1.4
799 public final Container getFocusCycleRootAncestor()
801 // as defined.
802 return null;
806 * This method returns the child Component that will receive focus if this
807 * JInternalFrame is selected.
809 * @return The child Component that will receive focus.
811 public Component getFocusOwner()
813 if (isSelected())
815 Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
816 if (SwingUtilities.isDescendingFrom(focus, this))
818 defaultFocus = focus;
819 return focus;
822 return null;
826 * This method returns the Frame Icon (the icon used in the JInternalFrame
827 * TitlePane and iconified frame).
829 * @return The Frame Icon.
831 public Icon getFrameIcon()
833 return frameIcon;
837 * This method returns the Glass Pane used with this JInternalFrame.
839 * @return The Glass Pane used with this JInternalFrame.
841 public Component getGlassPane()
843 return getRootPane().getGlassPane();
847 * This method returns an array of InternalFrameListeners that are listening
848 * to this JInternalFrame.
850 * @return An array of InternalFrameListeners that are listening to this
851 * JInternalFrame.
853 public InternalFrameListener[] getInternalFrameListeners()
855 return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class);
859 * This method returns the JMenuBar for this JInternalFrame.
861 * @return The JMenuBar for this JInternalFrame.
863 public JMenuBar getJMenuBar()
865 return getRootPane().getJMenuBar();
869 * This method returns the layer that this JInternalFrame resides in.
871 * @return The layer that this JInternalFrame resides in.
873 public int getLayer()
875 JDesktopPane pane = getDesktopPane();
876 if (pane != null)
877 // The cast here forces the call to the instance method getLayer()
878 // instead of the static method (this would lead to infinite
879 // recursion).
880 return pane.getLayer((Component) this);
881 return -1;
885 * This method returns the LayeredPane for this JInternalFrame.
887 * @return The LayeredPane for this JInternalFrame.
889 public JLayeredPane getLayeredPane()
891 return getRootPane().getLayeredPane();
895 * This method is deprecated. This method returns the JMenuBar for this
896 * JInternalFrame.
898 * @return The JMenuBar for this JInternalFrame.
900 * @deprecated 1.0.3
902 public JMenuBar getMenuBar()
904 return getJMenuBar();
908 * This method returns the child Component that will receive focus when the
909 * JInternalFrame is selected. If the JInternalFrame is selected, this
910 * method returns getFocusOwner(). Otherwise, it will return the child
911 * Component that most recently requested focus. If that is null, then the
912 * initial focus Component is returned. If that is null, then the default
913 * focus component is returned.
915 * @return The most recent focus owner.
917 public Component getMostRecentFocusOwner()
919 if (isSelected())
920 return getFocusOwner();
921 else
922 return defaultFocus;
926 * This method returns the bounds of the JInternalFrame if it is not
927 * maximized. If it is maximized, it returns the bounds of the
928 * JInternalFrame before it was maximized (the bounds that it will be
929 * restored to).
931 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
932 * just its bounds if it is not maximized).
934 public Rectangle getNormalBounds()
936 if (! isMaximum() && ! maxTransition)
937 return getBounds();
938 else
939 return storedBounds;
943 * This method returns the Root Pane for this JInternalFrame.
945 * @return The Root Pane for this JInternalFrame.
947 public JRootPane getRootPane()
949 return rootPane;
953 * This method sets the title of the JInternalFrame.
955 * @return The String displayed in the TitlePane of this JInternalFrame.
957 public String getTitle()
959 return title;
963 * This method returns the UI used to represent the JInternalFrame.
965 * @return The UI used to represent the JInternalFrame.
967 public InternalFrameUI getUI()
969 return (InternalFrameUI) ui;
973 * This method returns a String identifier that is used to determine which
974 * class acts as the JInternalFrame's UI.
976 * @return A String identifier to determine a UI class.
978 public String getUIClassID()
980 return "InternalFrameUI";
984 * This method returns null.
986 * @return null.
988 public final String getWarningString()
990 // as defined.
991 return null;
995 * This method deselects this JInternalFrame and hides it.
997 public void hide()
999 JDesktopPane pane = getDesktopPane();
1000 if (pane != null)
1001 pane.setSelectedFrame(null);
1002 else
1006 setSelected(false);
1008 catch (PropertyVetoException e)
1010 // Do nothing.
1013 super.hide();
1017 * This method returns whether this JInternalFrame is closable.
1019 * @return Whether this JInternalFrame is closable.
1021 public boolean isClosable()
1023 return closable;
1027 * This method returns whether this JInternalFrame has been closed.
1029 * @return Whether this JInternalFrame is closed.
1031 public boolean isClosed()
1033 return isClosed;
1037 * This must always return true.
1039 * @return always true
1041 * @since 1.4
1043 public final boolean isFocusCycleRoot()
1045 return true;
1049 * This method returns whether this JInternalFrame is currently iconified.
1051 * @return Whether this JInternalFrame is currently iconified.
1053 public boolean isIcon()
1055 return isIcon;
1059 * This method returns whether the JInternalFrame can be iconified.
1061 * @return Whether the JInternalFrame can be iconified.
1063 public boolean isIconifiable()
1065 return iconable;
1069 * This method returns whether this JInternalFrame can be maximized.
1071 * @return Whether this JInternalFrame can be maximized.
1073 public boolean isMaximizable()
1075 return maximizable;
1079 * This method returns whether this JInternalFrame is currently maximized.
1081 * @return Whether this JInternalFrame is maximized.
1083 public boolean isMaximum()
1085 return isMaximum;
1089 * This method returns whether this JInternalFrame is resizable.
1091 * @return Whether this JInternalFrame is resizable.
1093 public boolean isResizable()
1095 return resizable;
1099 * This method returns whether root pane checking is enabled. If root pane
1100 * checking is enabled, then calls to addImpl and setLayout will throw
1101 * exceptions.
1103 * @return Whether root pane checking is enabled.
1105 protected boolean isRootPaneCheckingEnabled()
1107 return rootPaneCheckingEnabled;
1111 * This method returns whether this JInternalFrame is selected.
1113 * @return Whether this JInternalFrame is selected.
1115 public boolean isSelected()
1117 return isSelected;
1121 * A helper method that moves this JInternalFrame to the back if the parent
1122 * is a JLayeredPane.
1124 public void moveToBack()
1126 if (getParent() instanceof JLayeredPane)
1127 ((JLayeredPane) getParent()).moveToBack(this);
1131 * A helper method that moves this JInternalFrame to the front if the parent
1132 * is a JLayeredPane.
1134 public void moveToFront()
1136 if (getParent() instanceof JLayeredPane)
1137 ((JLayeredPane) getParent()).moveToFront(this);
1141 * This method causes the children of this JInternalFrame to be laid out.
1142 * Before it begins, if this JInternalFrame is an icon, then it will be
1143 * deiconified. If it is maximized, then it will be restored. If either
1144 * operation fails, then this method will return.
1146 public void pack()
1150 if (isIcon())
1151 setIcon(false);
1152 else if (isMaximum())
1153 setMaximum(false);
1155 catch (PropertyVetoException e)
1157 // Do nothing if they don't want to be restored first.
1159 setSize(getPreferredSize());
1163 * This method is overridden to allow for speedier painting while this
1164 * JInternalFramme is being dragged.
1166 * @param g The Graphics object to paint with.
1168 protected void paintComponent(Graphics g)
1170 super.paintComponent(g);
1174 * This method returns a String describing this JInternalFrame.
1176 * @return A String describing this JInternalFrame.
1178 protected String paramString()
1180 return super.paramString();
1184 * This method removes the given Component from the Container.
1186 * @param comp The Component to remove.
1188 public void remove(Component comp)
1190 // If we're removing the root pane, use super.remove. Otherwise
1191 // pass it on to the content pane instead.
1192 if (comp==rootPane)
1193 super.remove(comp);
1194 else
1195 getContentPane().remove(comp);
1199 * This method removes an InternalFrameListener from this JInternalFrame.
1201 * @param l The listener to remove.
1203 public void removeInternalFrameListener(InternalFrameListener l)
1205 listenerList.remove(InternalFrameListener.class, l);
1209 * This method resizes and positions this JInternalFrame. It also forces a
1210 * relayout of the Container.
1212 * @param x The x position of this JInternalFrame.
1213 * @param y The y position of this JInternalFrame.
1214 * @param width The width of this JInternalFrame.
1215 * @param height The height of this JInternalFrame.
1217 public void reshape(int x, int y, int width, int height)
1219 super.reshape(x, y, width, height);
1220 revalidate();
1224 * This method gives focus to the last child Component that had focus. This
1225 * is used by the UI when this JInternalFrame is activated.
1227 public void restoreSubcomponentFocus()
1229 Component c = getMostRecentFocusOwner();
1230 if (c != null)
1231 c.requestFocus();
1235 * This method sets whether this JInternalFrame can be closed.
1237 * @param b Whether this JInternalFrame can be closed.
1239 public void setClosable(boolean b)
1241 closable = b;
1245 * This method closes the JInternalFrame if the given boolean is true. If it
1246 * is false, then the result of this method is unspecified. If the
1247 * JInternalFrame is closed, this method does nothing. This method will
1248 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1249 * listeners to cancel the close. If no listener vetoes the change, the
1250 * closed property is set to true and the JInternalFrame is hidden and
1251 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1252 * event.
1254 * @param b Whether the JInternalFrame will be closed.
1256 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1258 public void setClosed(boolean b) throws PropertyVetoException
1260 if (b && ! isClosed())
1262 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
1263 fireVetoableChange(IS_CLOSED_PROPERTY, false, true);
1265 isClosed = b;
1266 dispose();
1268 firePropertyChange(IS_CLOSED_PROPERTY, false, true);
1269 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
1274 * This method sets the Container to be used as a Content Pane for this
1275 * JInternalFrame.
1277 * @param c The Container to use as a Content Pane.
1279 public void setContentPane(Container c)
1281 if (c != getContentPane())
1283 Container old = getContentPane();
1284 getRootPane().setContentPane(c);
1285 firePropertyChange(CONTENT_PANE_PROPERTY, old, c);
1290 * This method sets the action taken when this JInternalFrame is closed.
1292 * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1293 * DISPOSE_ON_CLOSE.
1295 * @throws Error If the given operation is not one of the allowed modes.
1297 public void setDefaultCloseOperation(int operation)
1299 /* Reference implementation allows invalid operations to be specified.
1300 In that case, behaviour defaults to DO_NOTHING_ON_CLOSE.
1301 processWindowEvent handles the behaviour. getDefaultCloseOperation
1302 must return the invalid operator code. */
1303 defaultCloseOperation = operation;
1307 * This method sets the JDesktopIcon that represents this JInternalFrame
1308 * while it is iconified.
1310 * @param d The JDesktopIcon that represents this JInternalFrame while it is
1311 * iconified.
1313 public void setDesktopIcon(JDesktopIcon d)
1315 d.setInternalFrame(this);
1316 desktopIcon = d;
1320 * This method does nothing because this must be the root of a focus
1321 * traversal cycle.
1323 * @param focusCycleRoot Not used.
1325 public final void setFocusCycleRoot(boolean focusCycleRoot)
1327 // Do nothing
1331 * This method sets the Icon to be used in two places. The first is icon
1332 * that is painted at the top left corner of the JInternalFrame when it is
1333 * not iconified (clicking on that icon will activate the TitlePane
1334 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1335 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1336 * will use a Look and Feel default.
1338 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1340 public void setFrameIcon(Icon icon)
1342 if (icon != frameIcon)
1344 Icon old = frameIcon;
1345 frameIcon = icon;
1346 firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon);
1351 * This method sets the Glass Pane used with this JInternalFrame.
1353 * @param glass The Glass Pane to use with this JInternalFrame.
1355 public void setGlassPane(Component glass)
1357 if (glass != getGlassPane())
1359 Component old = getGlassPane();
1360 getRootPane().setGlassPane(glass);
1361 firePropertyChange(GLASS_PANE_PROPERTY, old, glass);
1366 * This method iconifies or deiconifies this JInternalFrame given the
1367 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1368 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1369 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1371 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1373 * @throws PropertyVetoException DOCUMENT ME!
1375 public void setIcon(boolean b) throws PropertyVetoException
1377 if (b != isIcon())
1379 fireVetoableChange(IS_ICON_PROPERTY, b, isIcon);
1381 isIcon = b;
1383 firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon);
1384 if (b)
1385 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
1386 else
1387 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
1392 * This method sets whether the JInternalFrame can be iconified. (This means
1393 * that the JInternalFrame can be turned into an icon if minimized).
1395 * @param b Whether the JInternalFrame can be iconified.
1397 public void setIconifiable(boolean b)
1399 iconable = b;
1403 * This method sets the JMenuBar to be used with this JInternalFrame.
1405 * @param b The JMenuBar to be used with this JInternalFrame.
1407 public void setJMenuBar(JMenuBar b)
1409 getRootPane().setJMenuBar(b);
1413 * A helper method that set the layer that this JInternalFrame resides in.
1414 * Using this version of the method means that the user should not set it
1415 * to values that are already defined in JLayeredPane. If predefined values
1416 * are to be used, the user should use the setLayer(Integer) version.
1418 * @param layer The layer to place this JInternalFrame in.
1420 public void setLayer(int layer)
1422 setLayer(new Integer(layer));
1426 * A helper method that sets the layer that this JInternalFrame resides in.
1427 * Calling this version of the method should use layer values that are
1428 * already defined in JLayeredPane.
1430 * @param layer The layer to place this JInternalFrame in.
1432 public void setLayer(Integer layer)
1434 JDesktopPane p = getDesktopPane();
1435 if (p != null)
1437 int pos = p.getPosition(this);
1438 p.setLayer(this, layer.intValue(), pos);
1443 * This method sets the JLayeredPane to use with this JInternalFrame.
1445 * @param layered The JLayeredPane to use as a layeredPane.
1447 public void setLayeredPane(JLayeredPane layered)
1449 if (layered != getLayeredPane())
1451 JLayeredPane old = getLayeredPane();
1452 getRootPane().setLayeredPane(layered);
1453 firePropertyChange(LAYERED_PANE_PROPERTY, old, layered);
1458 * This method sets whether the JInternalFrame can be maximized.
1460 * @param b Whether this JInternalFrame can be maximized.
1462 public void setMaximizable(boolean b)
1464 maximizable = b;
1468 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1469 * should not be called on the JInternalFrame directly. Instead, it should
1470 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1471 * method with root pane checking enabled will cause exceptions to be
1472 * thrown.
1474 * @param manager The Layout Manager to be used with the JInternalFrame.
1476 * @throws Error If rootPaneChecking is enabled.
1478 public void setLayout(LayoutManager manager)
1480 // Check if we're in initialization stage. If so, call super.setLayout
1481 // otherwise, valid calls go to the content pane.
1482 if (isRootPaneCheckingEnabled())
1483 getContentPane().setLayout(manager);
1484 else
1485 super.setLayout(manager);
1489 * This method sets the JInternalFrame to maximized (if the given argument
1490 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1492 * @param b Whether this JInteralFrame will be maximized or restored.
1494 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1496 public void setMaximum(boolean b) throws PropertyVetoException
1498 if (b != isMaximum())
1500 fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum);
1501 isMaximum = b;
1502 if (b)
1503 setNormalBounds(getBounds());
1504 maxTransition = ! b;
1505 firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
1506 maxTransition = false;
1511 * This method is deprecated. This method sets the JMenuBar used with this
1512 * JInternalFrame.
1514 * @param m The JMenuBar to use with this JInternalFrame.
1516 * @deprecated 1.0.3
1518 public void setMenuBar(JMenuBar m)
1520 setJMenuBar(m);
1524 * This method sets the bounds that this JInternalFrame will be restored to.
1526 * @param r The bounds that this JInternalFrame will be restored to.
1528 public void setNormalBounds(Rectangle r)
1530 storedBounds.setBounds(r.x, r.y, r.width, r.height);
1534 * This method sets whether the JInternalFrame can be resized by a user
1535 * action (like dragging at the frame borders).
1537 * @param b Whether this JInternalFramer can be resized.
1539 public void setResizable(boolean b)
1541 resizable = b;
1545 * This method sets the Root Pane for this JInternalFrame.
1547 * @param root The Root Pane for this JInternalFrame.
1549 protected void setRootPane(JRootPane root)
1551 if (rootPane != null)
1552 remove(rootPane);
1554 rootPane = root;
1555 add(root);
1559 * This method sets whether root pane checking is enabled. If root pane
1560 * checking is enabled, then calls to addImpl and setLayout will throw
1561 * exceptions.
1563 * @param enabled Whether root pane checking is enabled.
1565 protected void setRootPaneCheckingEnabled(boolean enabled)
1567 rootPaneCheckingEnabled = enabled;
1571 * This method sets whether this JInternalFrame is the selected frame in the
1572 * JDesktopPane (or other container). When selected, a JInternalFrame will
1573 * have focus and paint its TitlePane differently (usually a different
1574 * colour). If this method selects the frame, this JInternalFrame will fire
1575 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1576 * fire an INTERNAL_FRAME_DEACTIVATED event.
1578 * @param selected Whether this JInternalFrame will become selected or
1579 * deselected.
1581 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1583 public void setSelected(boolean selected) throws PropertyVetoException
1585 if (selected != isSelected())
1587 fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected);
1589 if (! selected)
1590 defaultFocus = getMostRecentFocusOwner();
1592 isSelected = selected;
1594 if (selected)
1595 restoreSubcomponentFocus();
1597 firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
1599 if (isSelected)
1600 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
1601 else
1602 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
1607 * This method sets the title displayed in the TitlePane of this
1608 * JInternalFrame.
1610 * @param title The title displayed.
1612 public void setTitle(String title)
1614 if (title == null && this.title == null)
1615 return;
1616 if (title == null || this.title == null || ! this.title.equals(title))
1618 String old = title;
1619 this.title = title;
1620 firePropertyChange(TITLE_PROPERTY, old, this.title);
1625 * This method displays the JInternalFrame. If it is not visible, this
1626 * method will bring this JInternalFrame to the front, make it visible and
1627 * select it. If this is the first time this JInternalFrame is made
1628 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1630 public void show()
1632 if (! isVisible())
1634 super.show();
1636 JDesktopPane pane = getDesktopPane();
1637 if (pane != null)
1638 pane.setSelectedFrame(this);
1639 else
1643 setSelected(true);
1645 catch (PropertyVetoException e)
1647 // Do nothing. if they don't want to be selected.
1650 if (isFirstTimeVisible)
1652 isFirstTimeVisible = false;
1653 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
1659 * This method is used to set the UI responsible for the JInternalFrame.
1661 * @param ui The UI responsible for the JInternalFrame.
1663 public void setUI(InternalFrameUI ui)
1665 // We must temporarily go into init mode so that the UI can directly
1666 // manipulate the JInternalFrame.
1667 boolean old = isRootPaneCheckingEnabled();
1668 setRootPaneCheckingEnabled(false);
1669 super.setUI(ui);
1670 setRootPaneCheckingEnabled(old);
1674 * This method causes the JInternalFrame to be brough to back in the
1675 * z-order.
1677 public void toBack()
1679 moveToBack();
1683 * This method causes the JInternalFrame to be brought to front in the
1684 * z-order.
1686 public void toFront()
1688 moveToFront();
1692 * This method resets the UI to the Look and Feel defaults.
1694 public void updateUI()
1696 // We must go into the init stage when updating the UI, so the UI can
1697 // set layout and components directly on the internal frame, not its
1698 // content pane.
1699 boolean old = isRootPaneCheckingEnabled();
1700 setRootPaneCheckingEnabled(false);
1701 setUI((InternalFrameUI) UIManager.getUI(this));
1702 setRootPaneCheckingEnabled(old);
1706 * This helper method allows JInternalFrames to signal that they were
1707 * iconned for the first time.
1709 * @param b Whether the JInternalFrame was iconned.
1710 * @param ID The identifier of the property change event to fire if the
1711 * JInternalFrame is iconned for the first time.
1713 void setWasIcon(boolean b, String ID)
1715 if (b && ! wasIcon)
1717 wasIcon = b;
1718 firePropertyChange(ID, ! b, b);
1723 * This helper method returns whether the JInternalFrame has been iconned
1724 * once already.
1726 * @return Whether the JInternalFrame has been iconned once already.
1728 boolean getWasIcon()
1730 return wasIcon;
1734 * This method is a convenience method to fire vetoable property changes.
1736 * @param name The identifier of the property change.
1737 * @param oldValue The old value.
1738 * @param newValue The new value.
1740 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1741 * the change.
1743 private void fireVetoableChange(String name, boolean oldValue,
1744 boolean newValue)
1745 throws PropertyVetoException
1747 super.fireVetoableChange(name, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));