This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / libjava / javax / swing / JInternalFrame.java
blobead61f218fada2d305098b38b7ae635459ea3e98
1 /* JInternalFrame.java --
2 Copyright (C) 2002, 2004 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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 /**
80 * Creates a new AccessibleJInternalFrame object.
82 protected AccessibleJInternalFrame()
84 super();
87 /**
88 * DOCUMENT ME!
90 * @return DOCUMENT ME!
92 public String getAccessibleName()
94 return null;
97 /**
98 * DOCUMENT ME!
100 * @return DOCUMENT ME!
102 public AccessibleRole getAccessibleRole()
104 return null;
108 * DOCUMENT ME!
110 * @return DOCUMENT ME!
112 public AccessibleValue getAccessibleValue()
114 return null;
118 * DOCUMENT ME!
120 * @return DOCUMENT ME!
122 public Number getCurrentAccessibleValue()
124 return null;
128 * DOCUMENT ME!
130 * @return DOCUMENT ME!
132 public Number getMaximumAccessibleValue()
134 return null;
138 * DOCUMENT ME!
140 * @return DOCUMENT ME!
142 public Number getMinimumAccessibleValue()
144 return null;
148 * DOCUMENT ME!
150 * @param n DOCUMENT ME!
152 * @return DOCUMENT ME!
154 public boolean setCurrentAccessibleValue(Number n)
156 return false;
161 * This class represents the JInternalFrame while it is iconified.
163 public static class JDesktopIcon extends JComponent implements Accessible
166 * DOCUMENT ME!
168 protected class AccessibleJDesktopIcon extends AccessibleJComponent
169 implements AccessibleValue
172 * Creates a new AccessibleJDesktopIcon object.
174 protected AccessibleJDesktopIcon()
176 super();
180 * DOCUMENT ME!
182 * @return DOCUMENT ME!
184 public AccessibleRole getAccessibleRole()
186 return null;
190 * DOCUMENT ME!
192 * @return DOCUMENT ME!
194 public AccessibleValue getAccessibleValue()
196 return null;
200 * DOCUMENT ME!
202 * @return DOCUMENT ME!
204 public Number getCurrentAccessibleValue()
206 return null;
210 * DOCUMENT ME!
212 * @return DOCUMENT ME!
214 public Number getMaximumAccessibleValue()
216 return null;
220 * DOCUMENT ME!
222 * @return DOCUMENT ME!
224 public Number getMinimumAccessibleValue()
226 return null;
230 * DOCUMENT ME!
232 * @param n DOCUMENT ME!
234 * @return DOCUMENT ME!
236 public boolean setCurrentAccessibleValue(Number n)
238 return false;
242 /** The JInternalFrame this DesktopIcon represents. */
243 JInternalFrame frame;
246 * Creates a new JDesktopIcon object for representing the given frame.
248 * @param f The JInternalFrame to represent.
250 public JDesktopIcon(JInternalFrame f)
252 frame = f;
253 updateUI();
257 * DOCUMENT ME!
259 * @return DOCUMENT ME!
261 public AccessibleContext getAccessibleContext()
263 if (accessibleContext == null)
264 accessibleContext = new AccessibleJDesktopIcon();
265 return accessibleContext;
269 * This method returns the JDesktopPane this JDesktopIcon is in.
271 * @return The JDesktopPane this JDesktopIcon is in.
273 public JDesktopPane getDesktopPane()
275 JDesktopPane p = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
276 this);
277 return p;
281 * This method returns the JInternalFrame this JDesktopIcon represents.
283 * @return The JInternalFrame this JDesktopIcon represents.
285 public JInternalFrame getInternalFrame()
287 return frame;
291 * This method returns the UI that is responsible for the JDesktopIcon.
293 * @return The UI that is responsible for the JDesktopIcon.
295 public DesktopIconUI getUI()
297 return (DesktopIconUI) ui;
301 * This method returns the String identifier that is used to determine
302 * which class is used for JDesktopIcon's UI.
304 * @return A String identifier for the UI class.
306 public String getUIClassID()
308 return "DesktopIconUI";
312 * This method sets the JInternalFrame that this JDesktopIcon represents.
314 * @param f The JInternalFrame that this JDesktopIcon represents.
316 public void setInternalFrame(JInternalFrame f)
318 frame = f;
322 * This method sets the UI used for this JDesktopIcon.
324 * @param ui The UI to use.
326 public void setUI(DesktopIconUI ui)
328 super.setUI(ui);
332 * This method restores the UI property to the defaults.
334 public void updateUI()
336 setUI((DesktopIconUI) UIManager.getUI(this));
341 * The property fired in a PropertyChangeEvent when the contentPane property
342 * changes.
344 public static final String CONTENT_PANE_PROPERTY = "contentPane";
347 * The property fired in a PropertyChangeEvent when the frameIcon property
348 * changes.
350 public static final String FRAME_ICON_PROPERTY = "frameIcon";
353 * The property fired in a PropertyChangeEvent when the glassPane property
354 * changes.
356 public static final String GLASS_PANE_PROPERTY = "glassPane";
359 * The property fired in a PropertyChangeEvent when the closed property
360 * changes.
362 public static final String IS_CLOSED_PROPERTY = "closed";
365 * The property fired in a PropertyChangeEvent when the icon property
366 * changes.
368 public static final String IS_ICON_PROPERTY = "icon";
371 * The property fired in a PropertyChangeEvent when the maximum property
372 * changes.
374 public static final String IS_MAXIMUM_PROPERTY = "maximum";
377 * The property fired in a PropertyChangeEvent when the selected property
378 * changes.
380 public static final String IS_SELECTED_PROPERTY = "selected";
383 * The property fired in a PropertyChangeEvent when the layeredPane property
384 * changes.
386 public static final String LAYERED_PANE_PROPERTY = "layeredPane";
389 * The property fired in a PropertyChangeEvent when the jMenuBar property
390 * changes.
392 public static final String MENU_BAR_PROPERTY = "JMenuBar";
395 * The property fired in a PropertyChangeEvent when the rootPane property
396 * changes.
398 public static final String ROOT_PANE_PROPERTY = "rootPane";
401 * The property fired in a PropertyChangeEvent when the title property
402 * changes.
404 public static final String TITLE_PROPERTY = "title";
406 /** Whether the JInternalFrame is closable. */
407 protected boolean closable;
409 /** Whether the JInternalFrame can be iconified. */
410 protected boolean iconable;
412 /** Whether the JInternalFrame is closed. */
413 protected boolean isClosed;
415 /** Whether the JInternalFrame has been iconified. */
416 protected boolean isIcon;
418 /** Whether the JInternalFrame has been maximized. */
419 protected boolean isMaximum;
421 /** Whether the JInternalFrame is the active frame. */
422 protected boolean isSelected;
424 /** Whether the JInternalFrame can be maximized. */
425 protected boolean maximizable;
427 /** Whether the JInternalFrame has rootPaneChecking enabled. */
428 protected boolean rootPaneCheckingEnabled = true;
430 /** Whether the JInternalFrame is resizable. */
431 protected boolean resizable;
434 * The JDesktopIcon that represents the JInternalFrame while it is
435 * iconified.
437 protected JDesktopIcon desktopIcon;
439 /** The icon used in the JMenuBar in the TitlePane. */
440 protected Icon frameIcon;
442 /** The rootPane of the JInternalFrame. */
443 protected JRootPane rootPane;
445 /** The title on the TitlePane of the JInternalFrame. */
446 protected String title;
448 /** The bounds of the JInternalFrame before it was maximized. */
449 private transient Rectangle storedBounds;
451 /** The Component that receives focus by default. */
452 private transient Component defaultFocus;
454 /** The default close action taken, */
455 private transient int defaultCloseOperation = DISPOSE_ON_CLOSE;
457 /** Whether the JInternalFrame has become visible for the very first time. */
458 private transient boolean isFirstTimeVisible = true;
461 * Whether the JInternalFrame is in the transition from being a maximized
462 * frame back to a regular sized frame.
464 private transient boolean maxTransition = false;
466 /** DOCUMENT ME! */
467 private transient boolean wasIcon = false;
470 * Creates a new JInternalFrame object that has no title, and is
471 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
473 public JInternalFrame()
475 this(null, false, false, false, false);
479 * Creates a new JInternalFrame object with the given title and is
480 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
482 * @param title The title displayed in the JInternalFrame.
484 public JInternalFrame(String title)
486 this(title, false, false, false, false);
490 * Creates a new JInternalFrame object with the given title and resizable
491 * properties. The JInternalFrame is non-maximizable, non-iconifiable, and
492 * non-closable.
494 * @param title The title displayed in the JInternalFrame.
495 * @param resizable Whether the JInternalFrame is resizable.
497 public JInternalFrame(String title, boolean resizable)
499 this(title, resizable, false, false, false);
503 * Creates a new JInternalFrame object with the given title, resizable, and
504 * closable properties. The JInternalFrame is non-maximizable and
505 * non-iconifiable.
507 * @param title The title displayed in the JInternalFrame.
508 * @param resizable Whether the JInternalFrame is resizable.
509 * @param closable Whether the JInternalFrame is closable.
511 public JInternalFrame(String title, boolean resizable, boolean closable)
513 this(title, resizable, closable, false, false);
517 * Creates a new JInternalFrame object with the given title, resizable,
518 * closable and maximizable properties. The JInternalFrame is
519 * non-iconifiable.
521 * @param title The title displayed in the JInternalFrame.
522 * @param resizable Whether the JInternalFrame is resizable.
523 * @param closable Whether the JInternalFrame is closable.
524 * @param maximizable Whether the JInternalFrame is maximizable.
526 public JInternalFrame(String title, boolean resizable, boolean closable,
527 boolean maximizable)
529 this(title, resizable, closable, maximizable, false);
533 * Creates a new JInternalFrame object with the given title, resizable,
534 * closable, maximizable and iconifiable properties.
536 * @param title The title displayed in the JInternalFrame.
537 * @param resizable Whether the JInternalFrame is resizable.
538 * @param closable Whether the JInternalFrame is closable.
539 * @param maximizable Whether the JInternalFrame is maximizable.
540 * @param iconifiable Whether the JInternalFrame is iconifiable.
542 public JInternalFrame(String title, boolean resizable, boolean closable,
543 boolean maximizable, boolean iconifiable)
545 this.title = title;
546 this.resizable = resizable;
547 this.closable = closable;
548 this.maximizable = maximizable;
549 this.iconable = iconifiable;
550 storedBounds = new Rectangle();
552 setRootPaneCheckingEnabled(false);
553 setRootPane(createRootPane());
555 updateUI();
556 setRootPaneCheckingEnabled(true);
560 * This method adds Components to this Container. For JInternalFrames,
561 * instead of calling add directly on the JInternalFrame, it should be
562 * called with JInternalFrame.getContentPane().add. If root pane checking
563 * is enabled, calling this method will cause an exception to be thrown.
565 * @param comp The Component to add.
566 * @param constraints The constraints on the Component added.
567 * @param index The position to place the Component.
569 * @throws Error DOCUMENT ME!
571 protected void addImpl(Component comp, Object constraints, int index)
573 if (isRootPaneCheckingEnabled())
574 throw new Error("Do not use add() on JInternalPane directly. Use getContentPane().add() instead");
576 super.addImpl(comp, constraints, index);
580 * This method adds an InternalFrameListener to this JInternalFrame.
582 * @param l The listener to add.
584 public void addInternalFrameListener(InternalFrameListener l)
586 listenerList.add(InternalFrameListener.class, l);
590 * This method is used to create a root pane for the JInternalFrame. This
591 * method is called by the constructors.
593 * @return A root pane for the JInternalFrame to use.
595 protected JRootPane createRootPane()
597 return new JRootPane();
601 * This method makes this JInternalFrame invisible, unselected and closed.
602 * If this JInternalFrame is not closed already, it will fire an
603 * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
604 * doesn't give vetoable listeners a chance to veto and it will not fire an
605 * INTERNAL_FRAME_CLOSING event.
607 public void dispose()
609 hide();
610 JDesktopPane pane = getDesktopPane();
611 if (pane != null)
612 pane.setSelectedFrame(null);
613 else
617 setSelected(false);
619 catch (PropertyVetoException e)
621 // Do nothing if they don't want to be unselected.
624 isClosed = true;
625 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
626 removeNotify();
630 * This method is used for closing this JInternalFrame. It fires an
631 * INTERNAL_FRAME_CLOSING event and then performs the action specified by
632 * the default close operation.
634 public void doDefaultCloseAction()
636 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
637 switch (getDefaultCloseOperation())
639 case HIDE_ON_CLOSE:
640 hide();
641 break;
642 case DISPOSE_ON_CLOSE:
643 dispose();
644 break;
649 * This method fires an InternalFrameEvent to the listeners.
651 * @param id The type of event being fired. See InternalFrameEvent.
653 protected void fireInternalFrameEvent(int id)
655 Object[] ifListeners = listenerList.getListenerList();
656 InternalFrameEvent evt = new InternalFrameEvent(this, id);
657 switch (id)
659 case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
660 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
662 if (ifListeners[i] == InternalFrameListener.class)
663 ((InternalFrameListener) ifListeners[i + 1])
664 .internalFrameClosing(evt);
666 break;
667 case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
668 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
670 if (ifListeners[i] == InternalFrameListener.class)
671 ((InternalFrameListener) ifListeners[i + 1])
672 .internalFrameActivated(evt);
674 break;
675 case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
676 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
678 if (ifListeners[i] == InternalFrameListener.class)
679 ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt);
681 break;
682 case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
683 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
685 if (ifListeners[i] == InternalFrameListener.class)
686 ((InternalFrameListener) ifListeners[i + 1])
687 .internalFrameDeactivated(evt);
689 break;
690 case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
691 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
693 if (ifListeners[i] == InternalFrameListener.class)
694 ((InternalFrameListener) ifListeners[i + 1])
695 .internalFrameDeiconified(evt);
697 break;
698 case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
699 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
701 if (ifListeners[i] == InternalFrameListener.class)
702 ((InternalFrameListener) ifListeners[i + 1])
703 .internalFrameIconified(evt);
705 break;
706 case InternalFrameEvent.INTERNAL_FRAME_OPENED:
707 for (int i = ifListeners.length - 2; i >= 0; i -= 2)
709 if (ifListeners[i] == InternalFrameListener.class)
710 ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt);
712 break;
717 * DOCUMENT ME!
719 * @return DOCUMENT ME!
721 public AccessibleContext getAccessibleContext()
723 if (accessibleContext == null)
724 accessibleContext = new AccessibleJInternalFrame();
725 return accessibleContext;
729 * This method returns the Content Pane for this JInternalFrame.
731 * @return The Content Pane for this JInternalFrame.
733 public Container getContentPane()
735 return getRootPane().getContentPane();
739 * This method returns the default action taken when this JInternalFrame is
740 * closed.
742 * @return The default action taken when this JInternalFrame is closed.
744 public int getDefaultCloseOperation()
746 return defaultCloseOperation;
750 * This method returns the JDesktopIcon that represents this JInternalFrame
751 * while it is iconified.
753 * @return The JDesktopIcon that represents this JInternalFrame while it is
754 * iconified.
756 public JDesktopIcon getDesktopIcon()
758 if (desktopIcon == null)
759 desktopIcon = new JDesktopIcon(this);
760 return desktopIcon;
764 * This method searches this JInternalFrame ancestors for an instance of
765 * JDesktopPane. If one is found, it is returned. If none is found, then it
766 * will search the JDesktopIcon for a JDesktopPane.
768 * @return The JDesktopPane that this JInternalFrame belongs to.
770 public JDesktopPane getDesktopPane()
772 JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
773 this);
774 if (value == null && desktopIcon != null)
775 value = desktopIcon.getDesktopPane();
776 return value;
780 * This method returns null because this must always be the root of a focus
781 * traversal.
783 * @return null.
785 public Container getFocusCycleRootAncestor()
787 // as defined.
788 return null;
792 * This method returns the child Component that will receive focus if this
793 * JInternalFrame is selected.
795 * @return The child Component that will receive focus.
797 public Component getFocusOwner()
799 if (isSelected())
801 Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
802 if (SwingUtilities.isDescendingFrom(focus, this))
804 defaultFocus = focus;
805 return focus;
808 return null;
812 * This method returns the Frame Icon (the icon used in the JInternalFrame
813 * TitlePane and iconified frame).
815 * @return The Frame Icon.
817 public Icon getFrameIcon()
819 return frameIcon;
823 * This method returns the Glass Pane used with this JInternalFrame.
825 * @return The Glass Pane used with this JInternalFrame.
827 public Component getGlassPane()
829 return getRootPane().getGlassPane();
833 * This method returns an array of InternalFrameListeners that are listening
834 * to this JInternalFrame.
836 * @return An array of InternalFrameListeners that are listening to this
837 * JInternalFrame.
839 public InternalFrameListener[] getInternalFrameListeners()
841 return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class);
845 * This method returns the JMenuBar for this JInternalFrame.
847 * @return The JMenuBar for this JInternalFrame.
849 public JMenuBar getJMenuBar()
851 return getRootPane().getJMenuBar();
855 * This method returns the layer that this JInternalFrame resides in.
857 * @return The layer that this JInternalFrame resides in.
859 public int getLayer()
861 JDesktopPane pane = getDesktopPane();
862 if (pane != null)
863 return pane.getLayer(this).intValue();
864 return -1;
868 * This method returns the LayeredPane for this JInternalFrame.
870 * @return The LayeredPane for this JInternalFrame.
872 public JLayeredPane getLayeredPane()
874 return getRootPane().getLayeredPane();
878 * This method is deprecated. This method returns the JMenuBar for this
879 * JInternalFrame.
881 * @return The JMenuBar for this JInternalFrame.
883 * @deprecated 1.0.3
885 public JMenuBar getMenuBar()
887 return getJMenuBar();
891 * This method returns the child Component that will receive focus when the
892 * JInternalFrame is selected. If the JInternalFrame is selected, this
893 * method returns getFocusOwner(). Otherwise, it will return the child
894 * Component that most recently requested focus. If that is null, then the
895 * initial focus Component is returned. If that is null, then the default
896 * focus component is returned.
898 * @return The most recent focus owner.
900 public Component getMostRecentFocusOwner()
902 if (isSelected())
903 return getFocusOwner();
904 else
905 return defaultFocus;
909 * This method returns the bounds of the JInternalFrame if it is not
910 * maximized. If it is maximized, it returns the bounds of the
911 * JInternalFrame before it was maximized (the bounds that it will be
912 * restored to).
914 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
915 * just its bounds if it is not maximized).
917 public Rectangle getNormalBounds()
919 if (! isMaximum() && ! maxTransition)
920 return getBounds();
921 else
922 return storedBounds;
926 * This method returns the Root Pane for this JInternalFrame.
928 * @return The Root Pane for this JInternalFrame.
930 public JRootPane getRootPane()
932 return rootPane;
936 * This method sets the title of the JInternalFrame.
938 * @return The String displayed in the TitlePane of this JInternalFrame.
940 public String getTitle()
942 return title;
946 * This method returns the UI used to represent the JInternalFrame.
948 * @return The UI used to represent the JInternalFrame.
950 public InternalFrameUI getUI()
952 return (InternalFrameUI) ui;
956 * This method returns a String identifier that is used to determine which
957 * class acts as the JInternalFrame's UI.
959 * @return A String identifier to determine a UI class.
961 public String getUIClassID()
963 return "InternalFrameUI";
967 * This method returns null.
969 * @return null.
971 public String getWarningString()
973 // as defined.
974 return null;
978 * This method deselects this JInternalFrame and hides it.
980 public void hide()
982 JDesktopPane pane = getDesktopPane();
983 if (pane != null)
984 pane.setSelectedFrame(null);
985 else
989 setSelected(false);
991 catch (PropertyVetoException e)
993 // Do nothing.
996 super.hide();
1000 * This method returns whether this JInternalFrame is closable.
1002 * @return Whether this JInternalFrame is closable.
1004 public boolean isClosable()
1006 return closable;
1010 * This method returns whether this JInternalFrame has been closed.
1012 * @return Whether this JInternalFrame is closed.
1014 public boolean isClosed()
1016 return isClosed;
1020 * This must always return true.
1022 * @return True
1024 public boolean isFocusCycleRoot()
1026 return true;
1030 * This method returns whether this JInternalFrame is currently iconified.
1032 * @return Whether this JInternalFrame is currently iconified.
1034 public boolean isIcon()
1036 return isIcon;
1040 * This method returns whether the JInternalFrame can be iconified.
1042 * @return Whether the JInternalFrame can be iconified.
1044 public boolean isIconifiable()
1046 return iconable;
1050 * This method returns whether this JInternalFrame can be maximized.
1052 * @return Whether this JInternalFrame can be maximized.
1054 public boolean isMaximizable()
1056 return maximizable;
1060 * This method returns whether this JInternalFrame is currently maximized.
1062 * @return Whether this JInternalFrame is maximized.
1064 public boolean isMaximum()
1066 return isMaximum;
1070 * This method returns whether this JInternalFrame is resizable.
1072 * @return Whether this JInternalFrame is resizable.
1074 public boolean isResizable()
1076 return resizable;
1080 * This method returns whether root pane checking is enabled. If root pane
1081 * checking is enabled, then calls to addImpl and setLayout will throw
1082 * exceptions.
1084 * @return Whether root pane checking is enabled.
1086 protected boolean isRootPaneCheckingEnabled()
1088 return rootPaneCheckingEnabled;
1092 * This method returns whether this JInternalFrame is selected.
1094 * @return Whether this JInternalFrame is selected.
1096 public boolean isSelected()
1098 return isSelected;
1102 * A helper method that moves this JInternalFrame to the back if the parent
1103 * is a JLayeredPane.
1105 public void moveToBack()
1107 if (getParent() instanceof JLayeredPane)
1108 ((JLayeredPane) getParent()).moveToBack(this);
1112 * A helper method that moves this JInternalFrame to the front if the parent
1113 * is a JLayeredPane.
1115 public void moveToFront()
1117 if (getParent() instanceof JLayeredPane)
1118 ((JLayeredPane) getParent()).moveToFront(this);
1122 * This method causes the children of this JInternalFrame to be laid out.
1123 * Before it begins, if this JInternalFrame is an icon, then it will be
1124 * deiconified. If it is maximized, then it will be restored. If either
1125 * operation fails, then this method will return.
1127 public void pack()
1131 if (isIcon())
1132 setIcon(false);
1133 else if (isMaximum())
1134 setMaximum(false);
1136 catch (PropertyVetoException e)
1138 // Do nothing if they don't want to be restored first.
1140 doLayout();
1144 * This method is overridden to allow for speedier painting while this
1145 * JInternalFramme is being dragged.
1147 * @param g The Graphics object to paint with.
1149 protected void paintComponent(Graphics g)
1151 super.paintComponent(g);
1155 * This method returns a String describing this JInternalFrame.
1157 * @return A String describing this JInternalFrame.
1159 protected String paramString()
1161 return "JInternalFrame";
1165 * This method removes the given Component from the Container.
1167 * @param comp The Component to remove.
1169 public void remove(Component comp)
1171 super.remove(comp);
1175 * This method removes an InternalFrameListener from this JInternalFrame.
1177 * @param l The listener to remove.
1179 public void removeInternalFrameListener(InternalFrameListener l)
1181 listenerList.remove(InternalFrameListener.class, l);
1185 * This method resizes and positions this JInternalFrame. It also forces a
1186 * relayout of the Container.
1188 * @param x The x position of this JInternalFrame.
1189 * @param y The y position of this JInternalFrame.
1190 * @param width The width of this JInternalFrame.
1191 * @param height The height of this JInternalFrame.
1193 public void reshape(int x, int y, int width, int height)
1195 super.reshape(x, y, width, height);
1196 invalidate();
1197 doLayout();
1201 * This method gives focus to the last child Component that had focus. This
1202 * is used by the UI when this JInternalFrame is activated.
1204 public void restoreSubcomponentFocus()
1206 Component c = getMostRecentFocusOwner();
1207 if (c != null)
1208 c.requestFocus();
1212 * This method sets whether this JInternalFrame can be closed.
1214 * @param b Whether this JInternalFrame can be closed.
1216 public void setClosable(boolean b)
1218 closable = b;
1222 * This method closes the JInternalFrame if the given boolean is true. If it
1223 * is false, then the result of this method is unspecified. If the
1224 * JInternalFrame is closed, this method does nothing. This method will
1225 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1226 * listeners to cancel the close. If no listener vetoes the change, the
1227 * closed property is set to true and the JInternalFrame is hidden and
1228 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1229 * event.
1231 * @param b Whether the JInternalFrame will be closed.
1233 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1235 public void setClosed(boolean b) throws PropertyVetoException
1237 if (b && ! isClosed())
1239 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
1240 fireVetoableChange(IS_CLOSED_PROPERTY, false, true);
1242 isClosed = b;
1244 firePropertyChange(IS_CLOSED_PROPERTY, false, true);
1245 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
1250 * This method sets the Container to be used as a Content Pane for this
1251 * JInternalFrame.
1253 * @param c The Container to use as a Content Pane.
1255 public void setContentPane(Container c)
1257 if (c != getContentPane())
1259 Container old = getContentPane();
1260 getRootPane().setContentPane(c);
1261 firePropertyChange(CONTENT_PANE_PROPERTY, old, c);
1266 * This method sets the action taken when this JInternalFrame is closed.
1268 * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1269 * DISPOSE_ON_CLOSE.
1271 * @throws Error If the given operation is not one of the allowed modes.
1273 public void setDefaultCloseOperation(int operation)
1275 if (operation != DO_NOTHING_ON_CLOSE || operation != HIDE_ON_CLOSE
1276 || operation != DISPOSE_ON_CLOSE)
1277 throw new Error("Close operation must be one of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE");
1278 defaultCloseOperation = operation;
1282 * This method sets the JDesktopIcon that represents this JInternalFrame
1283 * while it is iconified.
1285 * @param d The JDesktopIcon that represents this JInternalFrame while it is
1286 * iconified.
1288 public void setDesktopIcon(JDesktopIcon d)
1290 d.setInternalFrame(this);
1291 desktopIcon = d;
1295 * This method does nothing because this must be the root of a focus
1296 * traversal cycle.
1298 * @param focusCycleRoot Not used.
1300 public final void setFocusCycleRoot(boolean focusCycleRoot)
1302 // Do nothing
1306 * This method sets the Icon to be used in two places. The first is icon
1307 * that is painted at the top left corner of the JInternalFrame when it is
1308 * not iconified (clicking on that icon will activate the TitlePane
1309 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1310 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1311 * will use a Look and Feel default.
1313 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1315 public void setFrameIcon(Icon icon)
1317 if (icon != frameIcon)
1319 Icon old = frameIcon;
1320 frameIcon = icon;
1321 firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon);
1326 * This method sets the Glass Pane used with this JInternalFrame.
1328 * @param glass The Glass Pane to use with this JInternalFrame.
1330 public void setGlassPane(Component glass)
1332 if (glass != getGlassPane())
1334 Component old = getGlassPane();
1335 getRootPane().setGlassPane(glass);
1336 firePropertyChange(GLASS_PANE_PROPERTY, old, glass);
1341 * This method iconifies or deiconifies this JInternalFrame given the
1342 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1343 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1344 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1346 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1348 * @throws PropertyVetoException DOCUMENT ME!
1350 public void setIcon(boolean b) throws PropertyVetoException
1352 if (b != isIcon())
1354 fireVetoableChange(IS_ICON_PROPERTY, b, isIcon);
1356 isIcon = b;
1358 firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon);
1359 if (b)
1360 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
1361 else
1362 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
1367 * This method sets whether the JInternalFrame can be iconified. (This means
1368 * that the JInternalFrame can be turned into an icon if minimized).
1370 * @param b Whether the JInternalFrame can be iconified.
1372 public void setIconifiable(boolean b)
1374 iconable = b;
1378 * This method sets the JMenuBar to be used with this JInternalFrame.
1380 * @param b The JMenuBar to be used with this JInternalFrame.
1382 public void setJMenuBar(JMenuBar b)
1384 getRootPane().setJMenuBar(b);
1388 * A helper method that set the layer that this JInternalFrame resides in.
1389 * Using this version of the method means that the user should not set it
1390 * to values that are already defined in JLayeredPane. If predefined values
1391 * are to be used, the user should use the setLayer(Integer) version.
1393 * @param layer The layer to place this JInternalFrame in.
1395 public void setLayer(int layer)
1397 setLayer(new Integer(layer));
1401 * A helper method that sets the layer that this JInternalFrame resides in.
1402 * Calling this version of the method should use layer values that are
1403 * already defined in JLayeredPane.
1405 * @param layer The layer to place this JInternalFrame in.
1407 public void setLayer(Integer layer)
1409 JDesktopPane p = getDesktopPane();
1410 if (p != null)
1412 int pos = p.getPosition(this);
1413 p.setLayer(this, layer.intValue(), pos);
1418 * This method sets the JLayeredPane to use with this JInternalFrame.
1420 * @param layered The JLayeredPane to use as a layeredPane.
1422 public void setLayeredPane(JLayeredPane layered)
1424 if (layered != getLayeredPane())
1426 JLayeredPane old = getLayeredPane();
1427 getRootPane().setLayeredPane(layered);
1428 firePropertyChange(LAYERED_PANE_PROPERTY, old, layered);
1433 * This method sets whether the JInternalFrame can be maximized.
1435 * @param b Whether this JInternalFrame can be maximized.
1437 public void setMaximizable(boolean b)
1439 maximizable = b;
1443 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1444 * should not be called on the JInternalFrame directly. Instead, it should
1445 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1446 * method with root pane checking enabled will cause exceptions to be
1447 * thrown.
1449 * @param manager The Layout Manager to be used with the JInternalFrame.
1451 * @throws Error If rootPaneChecking is enabled.
1453 public void setLayout(LayoutManager manager)
1455 if (isRootPaneCheckingEnabled())
1456 throw new Error("Cannot set layout. Use getContentPane().setLayout() instead.");
1457 super.setLayout(manager);
1461 * This method sets the JInternalFrame to maximized (if the given argument
1462 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1464 * @param b Whether this JInteralFrame will be maximized or restored.
1466 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1468 public void setMaximum(boolean b) throws PropertyVetoException
1470 if (b != isMaximum())
1472 fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum);
1473 isMaximum = b;
1474 if (b)
1475 setNormalBounds(getBounds());
1476 maxTransition = ! b;
1477 firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
1478 maxTransition = false;
1483 * This method is deprecated. This method sets the JMenuBar used with this
1484 * JInternalFrame.
1486 * @param m The JMenuBar to use with this JInternalFrame.
1488 * @deprecated 1.0.3
1490 public void setMenuBar(JMenuBar m)
1492 setJMenuBar(m);
1496 * This method sets the bounds that this JInternalFrame will be restored to.
1498 * @param r The bounds that this JInternalFrame will be restored to.
1500 public void setNormalBounds(Rectangle r)
1502 storedBounds.setBounds(r.x, r.y, r.width, r.height);
1506 * This method sets whether the JInternalFrame can be resized by a user
1507 * action (like dragging at the frame borders).
1509 * @param b Whether this JInternalFramer can be resized.
1511 public void setResizable(boolean b)
1513 resizable = b;
1517 * This method sets the Root Pane for this JInternalFrame.
1519 * @param root The Root Pane for this JInternalFrame.
1521 protected void setRootPane(JRootPane root)
1523 if (rootPane != null)
1524 remove(rootPane);
1526 rootPane = root;
1527 add(root);
1531 * This method sets whether root pane checking is enabled. If root pane
1532 * checking is enabled, then calls to addImpl and setLayout will throw
1533 * exceptions.
1535 * @param enabled Whether root pane checking is enabled.
1537 protected void setRootPaneCheckingEnabled(boolean enabled)
1539 rootPaneCheckingEnabled = enabled;
1543 * This method sets whether this JInternalFrame is the selected frame in the
1544 * JDesktopPane (or other container). When selected, a JInternalFrame will
1545 * have focus and paint its TitlePane differently (usually a different
1546 * colour). If this method selects the frame, this JInternalFrame will fire
1547 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1548 * fire an INTERNAL_FRAME_DEACTIVATED event.
1550 * @param selected Whether this JInternalFrame will become selected or
1551 * deselected.
1553 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1555 public void setSelected(boolean selected) throws PropertyVetoException
1557 if (selected != isSelected())
1559 fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected);
1561 if (! selected)
1562 defaultFocus = getMostRecentFocusOwner();
1564 isSelected = selected;
1566 if (selected)
1567 restoreSubcomponentFocus();
1569 firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
1571 if (isSelected)
1572 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
1573 else
1574 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
1579 * This method sets the title displayed in the TitlePane of this
1580 * JInternalFrame.
1582 * @param title The title displayed.
1584 public void setTitle(String title)
1586 if (title == null && this.title == null)
1587 return;
1588 if (title == null || this.title == null || ! this.title.equals(title))
1590 String old = title;
1591 this.title = title;
1592 firePropertyChange(TITLE_PROPERTY, old, this.title);
1597 * This method displays the JInternalFrame. If it is not visible, this
1598 * method will bring this JInternalFrame to the front, make it visible and
1599 * select it. If this is the first time this JInternalFrame is made
1600 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1602 public void show()
1604 if (! isVisible())
1606 moveToFront();
1607 super.show();
1609 JDesktopPane pane = getDesktopPane();
1610 if (pane != null)
1611 pane.setSelectedFrame(this);
1612 else
1616 setSelected(true);
1618 catch (PropertyVetoException e)
1620 // Do nothing. if they don't want to be selected.
1623 if (isFirstTimeVisible)
1625 isFirstTimeVisible = false;
1626 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
1632 * This method is used to set the UI responsible for the JInternalFrame.
1634 * @param ui The UI responsible for the JInternalFrame.
1636 public void setUI(InternalFrameUI ui)
1638 super.setUI(ui);
1642 * This method causes the JInternalFrame to be brough to back in the
1643 * z-order.
1645 public void toBack()
1647 moveToBack();
1651 * This method causes the JInternalFrame to be brought to front in the
1652 * z-order.
1654 public void toFront()
1656 moveToFront();
1660 * This method resets the UI to the Look and Feel defaults.
1662 public void updateUI()
1664 setUI((InternalFrameUI) UIManager.getUI(this));
1668 * This helper method allows JInternalFrames to signal that they were
1669 * iconned for the first time.
1671 * @param b Whether the JInternalFrame was iconned.
1672 * @param ID The identifier of the property change event to fire if the
1673 * JInternalFrame is iconned for the first time.
1675 void setWasIcon(boolean b, String ID)
1677 if (b && ! wasIcon)
1679 wasIcon = b;
1680 firePropertyChange(ID, ! b, b);
1685 * This helper method returns whether the JInternalFrame has been iconned
1686 * once already.
1688 * @return Whether the JInternalFrame has been iconned once already.
1690 boolean getWasIcon()
1692 return wasIcon;
1696 * This method is a convenience method to fire vetoable property changes.
1698 * @param name The identifier of the property change.
1699 * @param oldValue The old value.
1700 * @param newValue The new value.
1702 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1703 * the change.
1705 private void fireVetoableChange(String name, boolean oldValue,
1706 boolean newValue)
1707 throws PropertyVetoException
1709 super.fireVetoableChange(name, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));