1 /* JInternalFrame.java --
2 Copyright (C) 2002, 2004, 2005, 2006, 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)
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
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
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. */
41 import java.awt.BorderLayout;
42 import java.awt.Component;
43 import java.awt.Container;
44 import java.awt.Graphics;
45 import java.awt.IllegalComponentStateException;
46 import java.awt.KeyboardFocusManager;
47 import java.awt.LayoutManager;
48 import java.awt.Rectangle;
49 import java.beans.PropertyChangeEvent;
50 import java.beans.PropertyVetoException;
52 import javax.accessibility.Accessible;
53 import javax.accessibility.AccessibleContext;
54 import javax.accessibility.AccessibleRole;
55 import javax.accessibility.AccessibleValue;
56 import javax.swing.event.InternalFrameEvent;
57 import javax.swing.event.InternalFrameListener;
58 import javax.swing.plaf.DesktopIconUI;
59 import javax.swing.plaf.InternalFrameUI;
62 * This class implements a Swing widget that looks and acts like a native
63 * frame. The frame can be dragged, resized, closed, etc. Typically,
64 * JInternalFrames are placed in JDesktopPanes. The actions that the
65 * JInternalFrame performs (maximizing, minimizing, etc.) are performed by a
66 * DesktopManager. As with regular frames, components are added by calling
67 * frame.getContentPane().add.
69 public class JInternalFrame extends JComponent implements Accessible,
74 private static final long serialVersionUID = -5425177187760785402L;
77 * Provides the accessibility features for the <code>JInternalFrame</code>
80 protected class AccessibleJInternalFrame extends AccessibleJComponent
81 implements AccessibleValue
83 private static final long serialVersionUID = 5931936924175476797L;
86 * Creates a new <code>AccessibleJInternalFrame</code> instance.
88 protected AccessibleJInternalFrame()
94 * Returns the frame title.
96 * @return The frame title.
98 public String getAccessibleName()
104 * Returns the accessible role for the <code>JInternalFrame</code>
107 * @return {@link AccessibleRole#INTERNAL_FRAME}.
109 public AccessibleRole getAccessibleRole()
111 return AccessibleRole.INTERNAL_FRAME;
115 * Returns an object that provides access to the current, minimum and
116 * maximum values for the {@link JInternalFrame}. Since this class
117 * implements {@link AccessibleValue}, it returns itself.
119 * @return The accessible value.
121 public AccessibleValue getAccessibleValue()
127 * Returns the current layer for the {@link JInternalFrame} component,
128 * as an {@link Integer}.
130 * @return The layer for the {@link JInternalFrame} component.
132 public Number getCurrentAccessibleValue()
134 return new Integer(getLayer());
138 * Returns the maximum permitted accessible value.
140 * @return <code>Integer(Integer.MAX_VALUE)</code>.
142 public Number getMaximumAccessibleValue()
144 return new Integer(Integer.MAX_VALUE);
148 * Returns the minimum permitted accessible value.
150 * @return <code>Integer(Integer.MIN_VALUE)</code>.
152 public Number getMinimumAccessibleValue()
154 return new Integer(Integer.MIN_VALUE);
158 * Sets the layer for the internal frame.
160 * @param n the layer (see the constants defined in {@link JLayeredPane}).
162 * @return <code>true</code> if the value is set, and <code>false</code>
165 public boolean setCurrentAccessibleValue(Number n)
169 setLayer(n.intValue());
175 * This class represents the JInternalFrame while it is iconified.
177 public static class JDesktopIcon extends JComponent implements Accessible
180 * Provides the accessibility features for the <code>JDesktopIcon</code>
183 protected class AccessibleJDesktopIcon extends AccessibleJComponent
184 implements AccessibleValue
186 private static final long serialVersionUID = 5035560458941637802L;
189 * Creates a new <code>AccessibleJDesktopIcon</code> instance.
191 protected AccessibleJDesktopIcon()
197 * Returns the accessible role for the <code>JDesktopIcon</code>
200 * @return {@link AccessibleRole#DESKTOP_ICON}.
202 public AccessibleRole getAccessibleRole()
204 return AccessibleRole.DESKTOP_ICON;
208 * Returns an object that provides access to the current, minimum and
209 * maximum values for the {@link JDesktopIcon}. Since this class
210 * implements {@link AccessibleValue}, it returns itself.
212 * @return The accessible value.
214 public AccessibleValue getAccessibleValue()
220 * Returns the current layer for the {@link JInternalFrame} component
221 * represented by this <code>JDesktopIcon</code>, as an {@link Integer}.
225 public Number getCurrentAccessibleValue()
227 return new Integer(frame.getLayer());
231 * Returns the maximum permitted accessible value.
233 * @return <code>Integer(Integer.MAX_VALUE)</code>.
235 public Number getMaximumAccessibleValue()
237 return new Integer(Integer.MAX_VALUE);
241 * Returns the minimum permitted accessible value.
243 * @return <code>Integer(Integer.MIN_VALUE)</code>.
245 public Number getMinimumAccessibleValue()
247 return new Integer(Integer.MIN_VALUE);
251 * Sets the layer for the internal frame represented by this
252 * <code>JDesktopIcon</code> component.
254 * @param n the layer (see the constants defined in
255 * {@link JLayeredPane}).
257 * @return <code>true</code> if the value is set, and <code>false</code>
260 public boolean setCurrentAccessibleValue(Number n)
264 frame.setLayer(n.intValue());
269 private static final long serialVersionUID = 4672973344731387687L;
271 /** The JInternalFrame this DesktopIcon represents. */
272 JInternalFrame frame;
275 * Creates a new JDesktopIcon object for representing the given frame.
277 * @param f The JInternalFrame to represent.
279 public JDesktopIcon(JInternalFrame f)
286 * Returns the object that provides accessibility features for this
287 * <code>JDesktopIcon</code> component.
289 * @return The accessible context (an instance of
290 * {@link AccessibleJDesktopIcon}).
292 public AccessibleContext getAccessibleContext()
294 if (accessibleContext == null)
295 accessibleContext = new AccessibleJDesktopIcon();
296 return accessibleContext;
300 * This method returns the JDesktopPane this JDesktopIcon is in.
302 * @return The JDesktopPane this JDesktopIcon is in.
304 public JDesktopPane getDesktopPane()
306 JDesktopPane p = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
312 * This method returns the JInternalFrame this JDesktopIcon represents.
314 * @return The JInternalFrame this JDesktopIcon represents.
316 public JInternalFrame getInternalFrame()
322 * This method returns the UI that is responsible for the JDesktopIcon.
324 * @return The UI that is responsible for the JDesktopIcon.
326 public DesktopIconUI getUI()
328 return (DesktopIconUI) ui;
332 * This method returns the String identifier that is used to determine
333 * which class is used for JDesktopIcon's UI.
335 * @return A String identifier for the UI class.
337 public String getUIClassID()
339 return "DesktopIconUI";
343 * This method sets the JInternalFrame that this JDesktopIcon represents.
345 * @param f The JInternalFrame that this JDesktopIcon represents.
347 public void setInternalFrame(JInternalFrame f)
353 * This method sets the UI used for this JDesktopIcon.
355 * @param ui The UI to use.
357 public void setUI(DesktopIconUI ui)
363 * This method restores the UI property to the defaults.
365 public void updateUI()
367 setUI((DesktopIconUI) UIManager.getUI(this));
372 * The property fired in a PropertyChangeEvent when the contentPane property
375 public static final String CONTENT_PANE_PROPERTY = "contentPane";
378 * The property fired in a PropertyChangeEvent when the frameIcon property
381 public static final String FRAME_ICON_PROPERTY = "frameIcon";
384 * The property fired in a PropertyChangeEvent when the glassPane property
387 public static final String GLASS_PANE_PROPERTY = "glassPane";
390 * The property fired in a PropertyChangeEvent when the closed property
393 public static final String IS_CLOSED_PROPERTY = "closed";
396 * The property fired in a PropertyChangeEvent when the icon property
399 public static final String IS_ICON_PROPERTY = "icon";
402 * The property fired in a PropertyChangeEvent when the maximum property
405 public static final String IS_MAXIMUM_PROPERTY = "maximum";
408 * The property fired in a PropertyChangeEvent when the selected property
411 public static final String IS_SELECTED_PROPERTY = "selected";
414 * The property fired in a PropertyChangeEvent when the layeredPane property
417 public static final String LAYERED_PANE_PROPERTY = "layeredPane";
420 * The property fired in a PropertyChangeEvent when the jMenuBar property
423 public static final String MENU_BAR_PROPERTY = "JMenuBar";
426 * The property fired in a PropertyChangeEvent when the rootPane property
429 public static final String ROOT_PANE_PROPERTY = "rootPane";
432 * The property fired in a PropertyChangeEvent when the title property
435 public static final String TITLE_PROPERTY = "title";
437 /** Whether the JInternalFrame is closable. */
438 protected boolean closable;
440 /** Whether the JInternalFrame can be iconified. */
441 protected boolean iconable;
443 /** Whether the JInternalFrame is closed. */
444 protected boolean isClosed;
446 /** Whether the JInternalFrame has been iconified. */
447 protected boolean isIcon;
449 /** Whether the JInternalFrame has been maximized. */
450 protected boolean isMaximum;
452 /** Whether the JInternalFrame is the active frame. */
453 protected boolean isSelected;
455 /** Whether the JInternalFrame can be maximized. */
456 protected boolean maximizable;
459 * Whether the JInternalFrame has rootPaneChecking enabled.
461 * @specnote Should be false to comply with J2SE 5.0
463 protected boolean rootPaneCheckingEnabled = false;
465 /** Whether the JInternalFrame is resizable. */
466 protected boolean resizable;
469 * The JDesktopIcon that represents the JInternalFrame while it is
472 protected JDesktopIcon desktopIcon;
474 /** The icon used in the JMenuBar in the TitlePane. */
475 protected Icon frameIcon;
477 /** The rootPane of the JInternalFrame. */
478 protected JRootPane rootPane;
480 /** The title on the TitlePane of the JInternalFrame. */
481 protected String title;
483 /** The bounds of the JInternalFrame before it was maximized. */
484 private transient Rectangle storedBounds;
486 /** The Component that receives focus by default. */
487 private transient Component defaultFocus;
489 /** The default close action taken, */
490 private transient int defaultCloseOperation = DISPOSE_ON_CLOSE;
492 /** Whether the JInternalFrame has become visible for the very first time. */
493 private transient boolean isFirstTimeVisible = true;
496 private transient boolean wasIcon = false;
499 * Creates a new JInternalFrame object that has an empty string for its
500 * title, and is non-resizable, non-maximizable, non-iconifiable, and
503 public JInternalFrame()
505 this("", false, false, false, false);
509 * Creates a new JInternalFrame object with the given title and is
510 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
512 * @param title The title displayed in the JInternalFrame.
514 public JInternalFrame(String title)
516 this(title, false, false, false, false);
520 * Creates a new JInternalFrame object with the given title and resizable
521 * properties. The JInternalFrame is non-maximizable, non-iconifiable, and
524 * @param title The title displayed in the JInternalFrame.
525 * @param resizable Whether the JInternalFrame is resizable.
527 public JInternalFrame(String title, boolean resizable)
529 this(title, resizable, false, false, false);
533 * Creates a new JInternalFrame object with the given title, resizable, and
534 * closable properties. The JInternalFrame is non-maximizable and
537 * @param title The title displayed in the JInternalFrame.
538 * @param resizable Whether the JInternalFrame is resizable.
539 * @param closable Whether the JInternalFrame is closable.
541 public JInternalFrame(String title, boolean resizable, boolean closable)
543 this(title, resizable, closable, false, false);
547 * Creates a new JInternalFrame object with the given title, resizable,
548 * closable and maximizable properties. The JInternalFrame is
551 * @param title The title displayed in the JInternalFrame.
552 * @param resizable Whether the JInternalFrame is resizable.
553 * @param closable Whether the JInternalFrame is closable.
554 * @param maximizable Whether the JInternalFrame is maximizable.
556 public JInternalFrame(String title, boolean resizable, boolean closable,
559 this(title, resizable, closable, maximizable, false);
563 * Creates a new JInternalFrame object with the given title, resizable,
564 * closable, maximizable and iconifiable properties.
566 * @param title The title displayed in the JInternalFrame.
567 * @param resizable Whether the JInternalFrame is resizable.
568 * @param closable Whether the JInternalFrame is closable.
569 * @param maximizable Whether the JInternalFrame is maximizable.
570 * @param iconifiable Whether the JInternalFrame is iconifiable.
572 public JInternalFrame(String title, boolean resizable, boolean closable,
573 boolean maximizable, boolean iconifiable)
576 this.resizable = resizable;
577 this.closable = closable;
578 this.maximizable = maximizable;
579 this.iconable = iconifiable;
581 setRootPane(createRootPane());
582 // JInternalFrames are invisible and opaque by default.
585 desktopIcon = new JDesktopIcon(this);
587 setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
591 * This method adds Components to this Container. For JInternalFrames,
592 * instead of calling add directly on the JInternalFrame, it should be
593 * called with JInternalFrame.getContentPane().add. If root pane checking
594 * is enabled, calling this method will cause an exception to be thrown.
596 * @param comp The Component to add.
597 * @param constraints The constraints on the Component added.
598 * @param index The position to place the Component.
600 * @throws Error DOCUMENT ME!
602 protected void addImpl(Component comp, Object constraints, int index)
604 // If we're in the initialization stage use super.add. Here we add the
605 // rootPane as well as the title bar and other stuff.
606 // Otherwise pass the add onto the content pane.
607 if (isRootPaneCheckingEnabled())
608 getContentPane().add(comp, constraints, index);
610 super.addImpl(comp,constraints, index);
614 * This method adds an InternalFrameListener to this JInternalFrame.
616 * @param l The listener to add.
618 public void addInternalFrameListener(InternalFrameListener l)
620 listenerList.add(InternalFrameListener.class, l);
624 * This method is used to create a root pane for the JInternalFrame. This
625 * method is called by the constructors.
627 * @return A root pane for the JInternalFrame to use.
629 protected JRootPane createRootPane()
631 return new JRootPane();
635 * This method makes this JInternalFrame invisible, unselected and closed.
636 * If this JInternalFrame is not closed already, it will fire an
637 * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
638 * doesn't give vetoable listeners a chance to veto and it will not fire an
639 * INTERNAL_FRAME_CLOSING event.
641 public void dispose()
651 catch (PropertyVetoException e)
653 // Do nothing if they don't want to be unselected.
658 firePropertyChange(IS_CLOSED_PROPERTY, Boolean.FALSE, Boolean.TRUE);
661 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
665 * This method is used for closing this JInternalFrame. It fires an
666 * INTERNAL_FRAME_CLOSING event and then performs the action specified by
667 * the default close operation.
669 public void doDefaultCloseAction()
671 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
672 switch (getDefaultCloseOperation())
677 case DISPOSE_ON_CLOSE:
684 * This method fires an InternalFrameEvent to the listeners.
686 * @param id The type of event being fired. See InternalFrameEvent.
688 protected void fireInternalFrameEvent(int id)
690 Object[] ifListeners = listenerList.getListenerList();
691 InternalFrameEvent evt = new InternalFrameEvent(this, id);
694 case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
695 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
697 if (ifListeners[i] == InternalFrameListener.class)
698 ((InternalFrameListener) ifListeners[i + 1])
699 .internalFrameClosing(evt);
702 case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
703 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
705 if (ifListeners[i] == InternalFrameListener.class)
706 ((InternalFrameListener) ifListeners[i + 1])
707 .internalFrameActivated(evt);
710 case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
711 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
713 if (ifListeners[i] == InternalFrameListener.class)
714 ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt);
717 case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
718 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
720 if (ifListeners[i] == InternalFrameListener.class)
721 ((InternalFrameListener) ifListeners[i + 1])
722 .internalFrameDeactivated(evt);
725 case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
726 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
728 if (ifListeners[i] == InternalFrameListener.class)
729 ((InternalFrameListener) ifListeners[i + 1])
730 .internalFrameDeiconified(evt);
733 case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
734 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
736 if (ifListeners[i] == InternalFrameListener.class)
737 ((InternalFrameListener) ifListeners[i + 1])
738 .internalFrameIconified(evt);
741 case InternalFrameEvent.INTERNAL_FRAME_OPENED:
742 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
744 if (ifListeners[i] == InternalFrameListener.class)
745 ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt);
752 * Returns the object that provides accessibility features for this
753 * <code>JInternalFrame</code> component.
755 * @return The accessible context (an instance of
756 * {@link AccessibleJInternalFrame}).
758 public AccessibleContext getAccessibleContext()
760 if (accessibleContext == null)
761 accessibleContext = new AccessibleJInternalFrame();
762 return accessibleContext;
766 * This method returns the Content Pane for this JInternalFrame.
768 * @return The Content Pane for this JInternalFrame.
770 public Container getContentPane()
772 return getRootPane().getContentPane();
776 * Returns a code for the default action taken when this
777 * <code>JInternalFrame</code> is closed.
779 * @return The action code (usually one of
780 * {@link WindowConstants#DO_NOTHING_ON_CLOSE},
781 * {@link WindowConstants#HIDE_ON_CLOSE}, or
782 * {@link WindowConstants#DISPOSE_ON_CLOSE}).
784 * @see #setDefaultCloseOperation(int)
785 * @see #doDefaultCloseAction()
787 public int getDefaultCloseOperation()
789 return defaultCloseOperation;
793 * Returns the <code>JDesktopIcon</code> that represents this
794 * <code>JInternalFrame</code> while it is iconified.
796 * @return The desktop icon component.
798 public JDesktopIcon getDesktopIcon()
804 * This method searches this JInternalFrame ancestors for an instance of
805 * JDesktopPane. If one is found, it is returned. If none is found, then it
806 * will search the JDesktopIcon for a JDesktopPane.
808 * @return The JDesktopPane that this JInternalFrame belongs to.
810 public JDesktopPane getDesktopPane()
812 JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
814 if (value == null && desktopIcon != null)
815 value = desktopIcon.getDesktopPane();
820 * This method returns null because this must always be the root of a focus
823 * @return always null
827 public final Container getFocusCycleRootAncestor()
834 * This method returns the child Component that will receive focus if this
835 * JInternalFrame is selected.
837 * @return The child Component that will receive focus.
839 public Component getFocusOwner()
843 Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
844 if (SwingUtilities.isDescendingFrom(focus, this))
846 defaultFocus = focus;
854 * This method returns the Frame Icon (the icon used in the JInternalFrame
855 * TitlePane and iconified frame).
857 * @return The Frame Icon.
859 public Icon getFrameIcon()
865 * This method returns the Glass Pane used with this JInternalFrame.
867 * @return The Glass Pane used with this JInternalFrame.
869 public Component getGlassPane()
871 return getRootPane().getGlassPane();
875 * This method returns an array of InternalFrameListeners that are listening
876 * to this JInternalFrame.
878 * @return An array of InternalFrameListeners that are listening to this
881 public InternalFrameListener[] getInternalFrameListeners()
883 return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class);
887 * This method returns the JMenuBar for this JInternalFrame.
889 * @return The JMenuBar for this JInternalFrame.
891 public JMenuBar getJMenuBar()
893 return getRootPane().getJMenuBar();
897 * This method returns the layer that this JInternalFrame resides in.
899 * @return The layer that this JInternalFrame resides in.
901 public int getLayer()
903 return JLayeredPane.getLayer(this);
907 * This method returns the LayeredPane for this JInternalFrame.
909 * @return The LayeredPane for this JInternalFrame.
911 public JLayeredPane getLayeredPane()
913 return getRootPane().getLayeredPane();
917 * This method is deprecated. This method returns the JMenuBar for this
920 * @return The JMenuBar for this JInternalFrame.
924 public JMenuBar getMenuBar()
926 return getJMenuBar();
930 * This method returns the child Component that will receive focus when the
931 * JInternalFrame is selected. If the JInternalFrame is selected, this
932 * method returns getFocusOwner(). Otherwise, it will return the child
933 * Component that most recently requested focus. If that is null, then the
934 * initial focus Component is returned. If that is null, then the default
935 * focus component is returned.
937 * @return The most recent focus owner.
939 public Component getMostRecentFocusOwner()
942 return getFocusOwner();
948 * This method returns the bounds of the JInternalFrame if it is not
949 * maximized. If it is maximized, it returns the bounds of the
950 * JInternalFrame before it was maximized (the bounds that it will be
953 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
954 * just its bounds if it is not maximized).
956 public Rectangle getNormalBounds()
958 if (storedBounds == null)
965 * This method returns the Root Pane for this JInternalFrame.
967 * @return The Root Pane for this JInternalFrame.
969 public JRootPane getRootPane()
975 * Returns the frame's title.
977 * @return The frame's title (can be <code>null</code>).
979 * @see #setTitle(String)
981 public String getTitle()
987 * This method returns the UI used to represent the JInternalFrame.
989 * @return The UI used to represent the JInternalFrame.
991 public InternalFrameUI getUI()
993 return (InternalFrameUI) ui;
997 * This method returns a String identifier that is used to determine which
998 * class acts as the JInternalFrame's UI.
1000 * @return A String identifier to determine a UI class.
1002 public String getUIClassID()
1004 return "InternalFrameUI";
1008 * This method returns null.
1012 public final String getWarningString()
1019 * This method deselects this JInternalFrame and hides it.
1024 getDesktopIcon().hide();
1029 * This method returns whether this JInternalFrame is closable.
1031 * @return Whether this JInternalFrame is closable.
1033 public boolean isClosable()
1039 * This method returns whether this JInternalFrame has been closed.
1041 * @return Whether this JInternalFrame is closed.
1043 public boolean isClosed()
1049 * This must always return true.
1051 * @return always true
1055 public final boolean isFocusCycleRoot()
1061 * This method returns whether this JInternalFrame is currently iconified.
1063 * @return Whether this JInternalFrame is currently iconified.
1065 public boolean isIcon()
1071 * This method returns whether the JInternalFrame can be iconified.
1073 * @return Whether the JInternalFrame can be iconified.
1075 public boolean isIconifiable()
1081 * This method returns whether this JInternalFrame can be maximized.
1083 * @return Whether this JInternalFrame can be maximized.
1085 public boolean isMaximizable()
1091 * This method returns whether this JInternalFrame is currently maximized.
1093 * @return Whether this JInternalFrame is maximized.
1095 public boolean isMaximum()
1101 * This method returns whether this JInternalFrame is resizable.
1103 * @return Whether this JInternalFrame is resizable.
1105 public boolean isResizable()
1111 * This method returns whether root pane checking is enabled. If root pane
1112 * checking is enabled, then calls to addImpl and setLayout will throw
1115 * @return Whether root pane checking is enabled.
1117 protected boolean isRootPaneCheckingEnabled()
1119 return rootPaneCheckingEnabled;
1123 * This method returns whether this JInternalFrame is selected.
1125 * @return Whether this JInternalFrame is selected.
1127 public boolean isSelected()
1133 * A helper method that moves this JInternalFrame to the back if the parent
1134 * is a JLayeredPane.
1136 public void moveToBack()
1138 Container p = getParent();
1139 if (p instanceof JLayeredPane)
1140 ((JLayeredPane) p).moveToBack(this);
1144 * A helper method that moves this JInternalFrame to the front if the parent
1145 * is a JLayeredPane.
1147 public void moveToFront()
1149 Container p = getParent();
1150 if (p != null && p instanceof JLayeredPane)
1151 ((JLayeredPane) p).moveToFront(this);
1155 * This method causes the children of this JInternalFrame to be laid out.
1156 * Before it begins, if this JInternalFrame is an icon, then it will be
1157 * deiconified. If it is maximized, then it will be restored. If either
1158 * operation fails, then this method will return.
1166 else if (isMaximum())
1169 catch (PropertyVetoException e)
1171 // Do nothing if they don't want to be restored first.
1173 setSize(getPreferredSize());
1178 * This method is overridden to allow for speedier painting while this
1179 * JInternalFramme is being dragged.
1181 * @param g The Graphics object to paint with.
1183 protected void paintComponent(Graphics g)
1185 super.paintComponent(g);
1189 * An implementation dependent string describing the current state of this
1190 * <code>JInternalFrame</code> instance.
1192 * @return A string describing the current state of this
1193 * <code>JInternalFrame</code> instance.
1195 protected String paramString()
1197 return super.paramString() + ",title=" + getTitle();
1201 * This method removes the given Component from the Container.
1203 * @param comp The Component to remove.
1205 public void remove(Component comp)
1207 // If we're removing the root pane, use super.remove. Otherwise
1208 // pass it on to the content pane instead.
1209 if (comp==rootPane || ! isRootPaneCheckingEnabled())
1212 getContentPane().remove(comp);
1216 * This method removes an InternalFrameListener from this JInternalFrame.
1218 * @param l The listener to remove.
1220 public void removeInternalFrameListener(InternalFrameListener l)
1222 listenerList.remove(InternalFrameListener.class, l);
1226 * This method resizes and positions this JInternalFrame. It also forces a
1227 * relayout of the Container.
1229 * @param x The x position of this JInternalFrame.
1230 * @param y The y position of this JInternalFrame.
1231 * @param width The width of this JInternalFrame.
1232 * @param height The height of this JInternalFrame.
1234 public void reshape(int x, int y, int width, int height)
1236 super.reshape(x, y, width, height);
1241 * This method gives focus to the last child Component that had focus. This
1242 * is used by the UI when this JInternalFrame is activated.
1244 public void restoreSubcomponentFocus()
1246 Component c = getMostRecentFocusOwner();
1252 * This method sets whether this JInternalFrame can be closed.
1254 * @param b Whether this JInternalFrame can be closed.
1256 public void setClosable(boolean b)
1261 firePropertyChange("closable", ! closable, closable);
1266 * This method closes the JInternalFrame if the given boolean is true. If it
1267 * is false, then the result of this method is unspecified. If the
1268 * JInternalFrame is closed, this method does nothing. This method will
1269 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1270 * listeners to cancel the close. If no listener vetoes the change, the
1271 * closed property is set to true and the JInternalFrame is hidden and
1272 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1275 * @param b Whether the JInternalFrame will be closed.
1277 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1279 public void setClosed(boolean b) throws PropertyVetoException
1281 if (b && ! isClosed())
1283 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
1284 fireVetoableChange(IS_CLOSED_PROPERTY, false, true);
1289 firePropertyChange(IS_CLOSED_PROPERTY, false, true);
1294 * This method sets the Container to be used as a Content Pane for this
1297 * @param c The Container to use as a Content Pane.
1299 public void setContentPane(Container c)
1301 if (c != getContentPane())
1303 Container old = getContentPane();
1304 getRootPane().setContentPane(c);
1305 firePropertyChange(CONTENT_PANE_PROPERTY, old, c);
1310 * Sets a code for the action to be taken when this
1311 * <code>JInternalFrame</code> is closed. Note that no validation is
1312 * performed on the <code>operation</code> code, any integer will be
1313 * accepted (nevertheless, you should pass in one of the listed values).
1315 * @param operation one of {@link WindowConstants#DO_NOTHING_ON_CLOSE},
1316 * {@link WindowConstants#HIDE_ON_CLOSE} or
1317 * {@link WindowConstants#DISPOSE_ON_CLOSE}.
1319 * @see #getDefaultCloseOperation()
1320 * @see #doDefaultCloseAction()
1322 public void setDefaultCloseOperation(int operation)
1324 /* Reference implementation allows invalid operations to be specified.
1325 In that case, behaviour defaults to DO_NOTHING_ON_CLOSE.
1326 processWindowEvent handles the behaviour. getDefaultCloseOperation
1327 must return the invalid operator code. */
1328 defaultCloseOperation = operation;
1332 * Sets the <code>JDesktopIcon</code> instance that represents this
1333 * <code>JInternalFrame</code> while it is iconified and, if the new icon is
1334 * not the same instance as the existing icon, sends a
1335 * {@link PropertyChangeEvent} (with the property name
1336 * <code>"desktopIcon"</code>) to all registered listeners..
1338 * @param d the icon.
1340 * @see #getDesktopIcon()
1342 public void setDesktopIcon(JDesktopIcon d)
1344 if (desktopIcon != d)
1346 JDesktopIcon oldIcon = desktopIcon;
1348 firePropertyChange("desktopIcon", oldIcon, d);
1353 * This method does nothing because this must be the root of a focus
1356 * @param focusCycleRoot Not used.
1358 public final void setFocusCycleRoot(boolean focusCycleRoot)
1364 * This method sets the Icon to be used in two places. The first is icon
1365 * that is painted at the top left corner of the JInternalFrame when it is
1366 * not iconified (clicking on that icon will activate the TitlePane
1367 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1368 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1369 * will use a Look and Feel default.
1371 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1373 public void setFrameIcon(Icon icon)
1375 if (icon != frameIcon)
1377 Icon old = frameIcon;
1379 firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon);
1384 * This method sets the Glass Pane used with this JInternalFrame.
1386 * @param glass The Glass Pane to use with this JInternalFrame.
1388 public void setGlassPane(Component glass)
1390 if (glass != getGlassPane())
1392 Component old = getGlassPane();
1393 getRootPane().setGlassPane(glass);
1394 firePropertyChange(GLASS_PANE_PROPERTY, old, glass);
1399 * This method iconifies or deiconifies this JInternalFrame given the
1400 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1401 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1402 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1404 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1406 * @throws PropertyVetoException DOCUMENT ME!
1408 public void setIcon(boolean b) throws PropertyVetoException
1412 fireVetoableChange(IS_ICON_PROPERTY, b, isIcon);
1416 firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon);
1418 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
1420 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
1425 * This method sets whether the JInternalFrame can be iconified. (This means
1426 * that the JInternalFrame can be turned into an icon if minimized).
1428 * @param b Whether the JInternalFrame can be iconified.
1430 public void setIconifiable(boolean b)
1435 firePropertyChange("iconable", ! iconable, iconable);
1440 * This method sets the JMenuBar to be used with this JInternalFrame.
1442 * @param b The JMenuBar to be used with this JInternalFrame.
1444 public void setJMenuBar(JMenuBar b)
1446 JMenuBar old = getJMenuBar();
1447 getRootPane().setJMenuBar(b);
1448 firePropertyChange(MENU_BAR_PROPERTY, old, b);
1452 * A helper method that set the layer that this JInternalFrame resides in.
1453 * Using this version of the method means that the user should not set it
1454 * to values that are already defined in JLayeredPane. If predefined values
1455 * are to be used, the user should use the setLayer(Integer) version.
1457 * @param layer The layer to place this JInternalFrame in.
1459 public void setLayer(int layer)
1461 setLayer(new Integer(layer));
1465 * A helper method that sets the layer that this JInternalFrame resides in.
1466 * Calling this version of the method should use layer values that are
1467 * already defined in JLayeredPane.
1469 * @param layer The layer to place this JInternalFrame in.
1471 public void setLayer(Integer layer)
1473 Container p = getParent();
1474 if (p instanceof JLayeredPane)
1476 JLayeredPane lp = (JLayeredPane) p;
1477 lp.setLayer(this, layer.intValue(), lp.getPosition(this));
1481 JLayeredPane.putLayer(this, layer.intValue());
1483 p.repaint(getX(), getY(), getWidth(), getHeight());
1488 * This method sets the JLayeredPane to use with this JInternalFrame.
1490 * @param layered The JLayeredPane to use as a layeredPane.
1492 public void setLayeredPane(JLayeredPane layered)
1494 if (layered == null)
1495 throw new IllegalComponentStateException("LayeredPane must not be null");
1497 if (layered != getLayeredPane())
1499 JLayeredPane old = getLayeredPane();
1500 getRootPane().setLayeredPane(layered);
1501 firePropertyChange(LAYERED_PANE_PROPERTY, old, layered);
1506 * This method sets whether the JInternalFrame can be maximized.
1508 * @param b Whether this JInternalFrame can be maximized.
1510 public void setMaximizable(boolean b)
1512 if (maximizable != b)
1515 firePropertyChange("maximizable", ! maximizable, maximizable);
1520 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1521 * should not be called on the JInternalFrame directly. Instead, it should
1522 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1523 * method with root pane checking enabled will cause exceptions to be
1526 * @param manager The Layout Manager to be used with the JInternalFrame.
1528 * @throws Error If rootPaneChecking is enabled.
1530 public void setLayout(LayoutManager manager)
1532 // Check if we're in initialization stage. If so, call super.setLayout
1533 // otherwise, valid calls go to the content pane.
1534 if (isRootPaneCheckingEnabled())
1535 getContentPane().setLayout(manager);
1537 super.setLayout(manager);
1541 * This method sets the JInternalFrame to maximized (if the given argument
1542 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1544 * @param b Whether this JInteralFrame will be maximized or restored.
1546 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1548 public void setMaximum(boolean b) throws PropertyVetoException
1552 fireVetoableChange(IS_MAXIMUM_PROPERTY, isMaximum, b);
1554 firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
1559 * This method is deprecated. This method sets the JMenuBar used with this
1562 * @param m The JMenuBar to use with this JInternalFrame.
1566 public void setMenuBar(JMenuBar m)
1572 * This method sets the bounds that this JInternalFrame will be restored to.
1574 * @param r The bounds that this JInternalFrame will be restored to.
1576 public void setNormalBounds(Rectangle r)
1582 * This method sets whether the JInternalFrame can be resized by a user
1583 * action (like dragging at the frame borders).
1585 * @param b Whether this JInternalFramer can be resized.
1587 public void setResizable(boolean b)
1592 firePropertyChange("resizable", ! resizable, resizable);
1597 * This method sets the Root Pane for this JInternalFrame.
1599 * @param root The Root Pane for this JInternalFrame.
1601 protected void setRootPane(JRootPane root)
1603 if (rootPane != null)
1606 JRootPane old = rootPane;
1609 if (rootPane != null)
1611 boolean checkingEnabled = isRootPaneCheckingEnabled();
1614 setRootPaneCheckingEnabled(false);
1615 add(rootPane, BorderLayout.CENTER);
1619 setRootPaneCheckingEnabled(checkingEnabled);
1622 firePropertyChange(ROOT_PANE_PROPERTY, old, rootPane);
1626 * This method sets whether root pane checking is enabled. If root pane
1627 * checking is enabled, then calls to addImpl and setLayout will throw
1630 * @param enabled Whether root pane checking is enabled.
1632 protected void setRootPaneCheckingEnabled(boolean enabled)
1634 rootPaneCheckingEnabled = enabled;
1638 * This method sets whether this JInternalFrame is the selected frame in the
1639 * JDesktopPane (or other container). When selected, a JInternalFrame will
1640 * have focus and paint its TitlePane differently (usually a different
1641 * colour). If this method selects the frame, this JInternalFrame will fire
1642 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1643 * fire an INTERNAL_FRAME_DEACTIVATED event.
1645 * @param selected Whether this JInternalFrame will become selected or
1648 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1650 public void setSelected(boolean selected) throws PropertyVetoException
1652 if (selected != isSelected
1653 && (! selected || (isIcon ? desktopIcon.isShowing() : isShowing())))
1655 fireVetoableChange(IS_SELECTED_PROPERTY, isSelected, selected);
1658 defaultFocus = getMostRecentFocusOwner();
1660 isSelected = selected;
1661 firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
1664 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
1666 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
1669 restoreSubcomponentFocus();
1676 * Sets the title for the <code>JInternalFrame</code> and sends a
1677 * {@link PropertyChangeEvent} (with the property name
1678 * {@link #TITLE_PROPERTY}) to all registered listeners.
1680 * @param title the new title (<code>null</code> permitted).
1684 public void setTitle(String title)
1686 String old = this.title;
1688 firePropertyChange(TITLE_PROPERTY, old, this.title);
1692 * This method displays the JInternalFrame. If it is not visible, this
1693 * method will bring this JInternalFrame to the front, make it visible and
1694 * select it. If this is the first time this JInternalFrame is made
1695 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1701 if (isFirstTimeVisible)
1703 isFirstTimeVisible = false;
1704 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
1707 getDesktopIcon().setVisible(true);
1721 catch (PropertyVetoException e)
1723 // Do nothing. if they don't want to be selected.
1730 * This method is used to set the UI responsible for the JInternalFrame.
1732 * @param ui The UI responsible for the JInternalFrame.
1734 public void setUI(InternalFrameUI ui)
1736 // We must temporarily go into init mode so that the UI can directly
1737 // manipulate the JInternalFrame.
1738 boolean old = isRootPaneCheckingEnabled();
1739 setRootPaneCheckingEnabled(false);
1741 setRootPaneCheckingEnabled(old);
1745 * This method causes the JInternalFrame to be brough to back in the
1748 public void toBack()
1754 * This method causes the JInternalFrame to be brought to front in the
1757 public void toFront()
1763 * This method resets the UI to the Look and Feel defaults.
1765 public void updateUI()
1767 // We must go into the init stage when updating the UI, so the UI can
1768 // set layout and components directly on the internal frame, not its
1770 boolean old = isRootPaneCheckingEnabled();
1771 setRootPaneCheckingEnabled(false);
1772 setUI((InternalFrameUI) UIManager.getUI(this));
1773 setRootPaneCheckingEnabled(old);
1777 * This helper method allows JInternalFrames to signal that they were
1778 * iconned for the first time.
1780 * @param b Whether the JInternalFrame was iconned.
1781 * @param ID The identifier of the property change event to fire if the
1782 * JInternalFrame is iconned for the first time.
1784 void setWasIcon(boolean b, String ID)
1789 firePropertyChange(ID, ! b, b);
1794 * This helper method returns whether the JInternalFrame has been iconned
1797 * @return Whether the JInternalFrame has been iconned once already.
1799 boolean getWasIcon()
1805 * This method is a convenience method to fire vetoable property changes.
1807 * @param name The identifier of the property change.
1808 * @param oldValue The old value.
1809 * @param newValue The new value.
1811 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1814 private void fireVetoableChange(String name, boolean oldValue,
1816 throws PropertyVetoException
1818 super.fireVetoableChange(name, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));