2004-08-12 Janis Johnson <janis187@us.ibm.com>
[official-gcc.git] / libjava / javax / swing / JInternalFrame.java
blob12c9d139db2538d5439ae3a228572994eb36c9fc
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. */
38 package javax.swing;
40 import java.awt.Color;
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;
48 import javax.accessibility.Accessible;
49 import javax.accessibility.AccessibleContext;
50 import javax.accessibility.AccessibleRole;
51 import javax.accessibility.AccessibleValue;
52 import javax.swing.event.InternalFrameEvent;
53 import javax.swing.event.InternalFrameListener;
54 import javax.swing.plaf.DesktopIconUI;
55 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 String CONTENT_PANE_PROPERTY = "contentPane";
347 * The property fired in a PropertyChangeEvent when the frameIcon property
348 * changes.
350 public static String FRAME_ICON_PROPERTY = "frameIcon";
353 * The property fired in a PropertyChangeEvent when the glassPane property
354 * changes.
356 public static String GLASS_PANE_PROPERTY = "glassPane";
359 * The property fired in a PropertyChangeEvent when the closed property
360 * changes.
362 public static String IS_CLOSED_PROPERTY = "closed";
365 * The property fired in a PropertyChangeEvent when the icon property
366 * changes.
368 public static String IS_ICON_PROPERTY = "icon";
371 * The property fired in a PropertyChangeEvent when the maximum property
372 * changes.
374 public static String IS_MAXIMUM_PROPERTY = "maximum";
377 * The property fired in a PropertyChangeEvent when the selected property
378 * changes.
380 public static String IS_SELECTED_PROPERTY = "selected";
383 * The property fired in a PropertyChangeEvent when the layeredPane property
384 * changes.
386 public static String LAYERED_PANE_PROPERTY = "layeredPane";
389 * The property fired in a PropertyChangeEvent when the jMenuBar property
390 * changes.
392 public static String MENU_BAR_PROPERTY = "jMenuBar";
395 * The property fired in a PropertyChangeEvent when the rootPane property
396 * changes.
398 public static String ROOT_PANE_PROPERTY = "rootPane";
401 * The property fired in a PropertyChangeEvent when the title property
402 * changes.
404 public static 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 public JMenuBar getMenuBar()
885 return getJMenuBar();
889 * This method returns the child Component that will receive focus when the
890 * JInternalFrame is selected. If the JInternalFrame is selected, this
891 * method returns getFocusOwner(). Otherwise, it will return the child
892 * Component that most recently requested focus. If that is null, then the
893 * initial focus Component is returned. If that is null, then the default
894 * focus component is returned.
896 * @return The most recent focus owner.
898 public Component getMostRecentFocusOwner()
900 if (isSelected())
901 return getFocusOwner();
902 else
903 return defaultFocus;
907 * This method returns the bounds of the JInternalFrame if it is not
908 * maximized. If it is maximized, it returns the bounds of the
909 * JInternalFrame before it was maximized (the bounds that it will be
910 * restored to).
912 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
913 * just its bounds if it is not maximized).
915 public Rectangle getNormalBounds()
917 if (! isMaximum() && ! maxTransition)
918 return getBounds();
919 else
920 return storedBounds;
924 * This method returns the Root Pane for this JInternalFrame.
926 * @return The Root Pane for this JInternalFrame.
928 public JRootPane getRootPane()
930 return rootPane;
934 * This method sets the title of the JInternalFrame.
936 * @return The String displayed in the TitlePane of this JInternalFrame.
938 public String getTitle()
940 return title;
944 * This method returns the UI used to represent the JInternalFrame.
946 * @return The UI used to represent the JInternalFrame.
948 public InternalFrameUI getUI()
950 return (InternalFrameUI) ui;
954 * This method returns a String identifier that is used to determine which
955 * class acts as the JInternalFrame's UI.
957 * @return A String identifier to determine a UI class.
959 public String getUIClassID()
961 return "InternalFrameUI";
965 * This method returns null.
967 * @return null.
969 public String getWarningString()
971 // as defined.
972 return null;
976 * This method deselects this JInternalFrame and hides it.
978 public void hide()
980 JDesktopPane pane = getDesktopPane();
981 if (pane != null)
982 pane.setSelectedFrame(null);
983 else
987 setSelected(false);
989 catch (PropertyVetoException e)
991 // Do nothing.
994 super.hide();
998 * This method returns whether this JInternalFrame is closable.
1000 * @return Whether this JInternalFrame is closable.
1002 public boolean isClosable()
1004 return closable;
1008 * This method returns whether this JInternalFrame has been closed.
1010 * @return Whether this JInternalFrame is closed.
1012 public boolean isClosed()
1014 return isClosed;
1018 * This must always return true.
1020 * @return True
1022 public boolean isFocusCycleRoot()
1024 return true;
1028 * This method returns whether this JInternalFrame is currently iconified.
1030 * @return Whether this JInternalFrame is currently iconified.
1032 public boolean isIcon()
1034 return isIcon;
1038 * This method returns whether the JInternalFrame can be iconified.
1040 * @return Whether the JInternalFrame can be iconified.
1042 public boolean isIconifiable()
1044 return iconable;
1048 * This method returns whether this JInternalFrame can be maximized.
1050 * @return Whether this JInternalFrame can be maximized.
1052 public boolean isMaximizable()
1054 return maximizable;
1058 * This method returns whether this JInternalFrame is currently maximized.
1060 * @return Whether this JInternalFrame is maximized.
1062 public boolean isMaximum()
1064 return isMaximum;
1068 * This method returns whether this JInternalFrame is resizable.
1070 * @return Whether this JInternalFrame is resizable.
1072 public boolean isResizable()
1074 return resizable;
1078 * This method returns whether root pane checking is enabled. If root pane
1079 * checking is enabled, then calls to addImpl and setLayout will throw
1080 * exceptions.
1082 * @return Whether root pane checking is enabled.
1084 protected boolean isRootPaneCheckingEnabled()
1086 return rootPaneCheckingEnabled;
1090 * This method returns whether this JInternalFrame is selected.
1092 * @return Whether this JInternalFrame is selected.
1094 public boolean isSelected()
1096 return isSelected;
1100 * A helper method that moves this JInternalFrame to the back if the parent
1101 * is a JLayeredPane.
1103 public void moveToBack()
1105 if (getParent() instanceof JLayeredPane)
1106 ((JLayeredPane) getParent()).moveToBack(this);
1110 * A helper method that moves this JInternalFrame to the front if the parent
1111 * is a JLayeredPane.
1113 public void moveToFront()
1115 if (getParent() instanceof JLayeredPane)
1116 ((JLayeredPane) getParent()).moveToFront(this);
1120 * This method causes the children of this JInternalFrame to be laid out.
1121 * Before it begins, if this JInternalFrame is an icon, then it will be
1122 * deiconified. If it is maximized, then it will be restored. If either
1123 * operation fails, then this method will return.
1125 public void pack()
1129 if (isIcon())
1130 setIcon(false);
1131 else if (isMaximum())
1132 setMaximum(false);
1134 catch (PropertyVetoException e)
1136 // Do nothing if they don't want to be restored first.
1138 doLayout();
1142 * This method is overridden to allow for speedier painting while this
1143 * JInternalFramme is being dragged.
1145 * @param g The Graphics object to paint with.
1147 protected void paintComponent(Graphics g)
1149 super.paintComponent(g);
1153 * This method returns a String describing this JInternalFrame.
1155 * @return A String describing this JInternalFrame.
1157 protected String paramString()
1159 return "JInternalFrame";
1163 * This method removes the given Component from the Container.
1165 * @param comp The Component to remove.
1167 public void remove(Component comp)
1169 super.remove(comp);
1173 * This method removes an InternalFrameListener from this JInternalFrame.
1175 * @param l The listener to remove.
1177 public void removeInternalFrameListener(InternalFrameListener l)
1179 listenerList.remove(InternalFrameListener.class, l);
1183 * This method resizes and positions this JInternalFrame. It also forces a
1184 * relayout of the Container.
1186 * @param x The x position of this JInternalFrame.
1187 * @param y The y position of this JInternalFrame.
1188 * @param width The width of this JInternalFrame.
1189 * @param height The height of this JInternalFrame.
1191 public void reshape(int x, int y, int width, int height)
1193 super.reshape(x, y, width, height);
1194 invalidate();
1195 doLayout();
1199 * This method gives focus to the last child Component that had focus. This
1200 * is used by the UI when this JInternalFrame is activated.
1202 public void restoreSubcomponentFocus()
1204 Component c = getMostRecentFocusOwner();
1205 if (c != null)
1206 c.requestFocus();
1210 * This method sets whether this JInternalFrame can be closed.
1212 * @param b Whether this JInternalFrame can be closed.
1214 public void setClosable(boolean b)
1216 closable = b;
1220 * This method closes the JInternalFrame if the given boolean is true. If it
1221 * is false, then the result of this method is unspecified. If the
1222 * JInternalFrame is closed, this method does nothing. This method will
1223 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1224 * listeners to cancel the close. If no listener vetoes the change, the
1225 * closed property is set to true and the JInternalFrame is hidden and
1226 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1227 * event.
1229 * @param b Whether the JInternalFrame will be closed.
1231 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1233 public void setClosed(boolean b) throws PropertyVetoException
1235 if (b && ! isClosed())
1237 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
1238 fireVetoableChange(IS_CLOSED_PROPERTY, false, true);
1240 isClosed = b;
1242 firePropertyChange(IS_CLOSED_PROPERTY, false, true);
1243 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
1248 * This method sets the Container to be used as a Content Pane for this
1249 * JInternalFrame.
1251 * @param c The Container to use as a Content Pane.
1253 public void setContentPane(Container c)
1255 if (c != getContentPane())
1257 Container old = getContentPane();
1258 getRootPane().setContentPane(c);
1259 firePropertyChange(CONTENT_PANE_PROPERTY, old, c);
1264 * This method sets the action taken when this JInternalFrame is closed.
1266 * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1267 * DISPOSE_ON_CLOSE.
1269 * @throws Error If the given operation is not one of the allowed modes.
1271 public void setDefaultCloseOperation(int operation)
1273 if (operation != DO_NOTHING_ON_CLOSE || operation != HIDE_ON_CLOSE
1274 || operation != DISPOSE_ON_CLOSE)
1275 throw new Error("Close operation must be one of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE");
1276 defaultCloseOperation = operation;
1280 * This method sets the JDesktopIcon that represents this JInternalFrame
1281 * while it is iconified.
1283 * @param d The JDesktopIcon that represents this JInternalFrame while it is
1284 * iconified.
1286 public void setDesktopIcon(JDesktopIcon d)
1288 d.setInternalFrame(this);
1289 desktopIcon = d;
1293 * This method does nothing because this must be the root of a focus
1294 * traversal cycle.
1296 * @param focusCycleRoot Not used.
1298 public final void setFocusCycleRoot(boolean focusCycleRoot)
1300 // Do nothing
1304 * This method sets the Icon to be used in two places. The first is icon
1305 * that is painted at the top left corner of the JInternalFrame when it is
1306 * not iconified (clicking on that icon will activate the TitlePane
1307 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1308 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1309 * will use a Look and Feel default.
1311 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1313 public void setFrameIcon(Icon icon)
1315 if (icon != frameIcon)
1317 Icon old = frameIcon;
1318 frameIcon = icon;
1319 firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon);
1324 * This method sets the Glass Pane used with this JInternalFrame.
1326 * @param glass The Glass Pane to use with this JInternalFrame.
1328 public void setGlassPane(Component glass)
1330 if (glass != getGlassPane())
1332 Component old = getGlassPane();
1333 getRootPane().setGlassPane(glass);
1334 firePropertyChange(GLASS_PANE_PROPERTY, old, glass);
1339 * This method iconifies or deiconifies this JInternalFrame given the
1340 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1341 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1342 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1344 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1346 * @throws PropertyVetoException DOCUMENT ME!
1348 public void setIcon(boolean b) throws PropertyVetoException
1350 if (b != isIcon())
1352 fireVetoableChange(IS_ICON_PROPERTY, b, isIcon);
1354 isIcon = b;
1356 firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon);
1357 if (b)
1358 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
1359 else
1360 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
1365 * This method sets whether the JInternalFrame can be iconified. (This means
1366 * that the JInternalFrame can be turned into an icon if minimized).
1368 * @param b Whether the JInternalFrame can be iconified.
1370 public void setIconifiable(boolean b)
1372 iconable = b;
1376 * This method sets the JMenuBar to be used with this JInternalFrame.
1378 * @param b The JMenuBar to be used with this JInternalFrame.
1380 public void setJMenuBar(JMenuBar b)
1382 getRootPane().setJMenuBar(b);
1386 * A helper method that set the layer that this JInternalFrame resides in.
1387 * Using this version of the method means that the user should not set it
1388 * to values that are already defined in JLayeredPane. If predefined values
1389 * are to be used, the user should use the setLayer(Integer) version.
1391 * @param layer The layer to place this JInternalFrame in.
1393 public void setLayer(int layer)
1395 setLayer(new Integer(layer));
1399 * A helper method that sets the layer that this JInternalFrame resides in.
1400 * Calling this version of the method should use layer values that are
1401 * already defined in JLayeredPane.
1403 * @param layer The layer to place this JInternalFrame in.
1405 public void setLayer(Integer layer)
1407 JDesktopPane p = getDesktopPane();
1408 if (p != null)
1410 int pos = p.getPosition(this);
1411 p.setLayer(this, layer.intValue(), pos);
1416 * This method sets the JLayeredPane to use with this JInternalFrame.
1418 * @param layered The JLayeredPane to use as a layeredPane.
1420 public void setLayeredPane(JLayeredPane layered)
1422 if (layered != getLayeredPane())
1424 JLayeredPane old = getLayeredPane();
1425 getRootPane().setLayeredPane(layered);
1426 firePropertyChange(LAYERED_PANE_PROPERTY, old, layered);
1431 * This method sets whether the JInternalFrame can be maximized.
1433 * @param b Whether this JInternalFrame can be maximized.
1435 public void setMaximizable(boolean b)
1437 maximizable = b;
1441 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1442 * should not be called on the JInternalFrame directly. Instead, it should
1443 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1444 * method with root pane checking enabled will cause exceptions to be
1445 * thrown.
1447 * @param manager The Layout Manager to be used with the JInternalFrame.
1449 * @throws Error If rootPaneChecking is enabled.
1451 public void setLayout(LayoutManager manager)
1453 if (isRootPaneCheckingEnabled())
1454 throw new Error("Cannot set layout. Use getContentPane().setLayout() instead.");
1455 super.setLayout(manager);
1459 * This method sets the JInternalFrame to maximized (if the given argument
1460 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1462 * @param b Whether this JInteralFrame will be maximized or restored.
1464 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1466 public void setMaximum(boolean b) throws PropertyVetoException
1468 if (b != isMaximum())
1470 fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum);
1471 isMaximum = b;
1472 if (b)
1473 setNormalBounds(getBounds());
1474 maxTransition = ! b;
1475 firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
1476 maxTransition = false;
1481 * This method is deprecated. This method sets the JMenuBar used with this
1482 * JInternalFrame.
1484 * @param m The JMenuBar to use with this JInternalFrame.
1486 public void setMenuBar(JMenuBar m)
1488 setJMenuBar(m);
1492 * This method sets the bounds that this JInternalFrame will be restored to.
1494 * @param r The bounds that this JInternalFrame will be restored to.
1496 public void setNormalBounds(Rectangle r)
1498 storedBounds.setBounds(r.x, r.y, r.width, r.height);
1502 * This method sets whether the JInternalFrame can be resized by a user
1503 * action (like dragging at the frame borders).
1505 * @param b Whether this JInternalFramer can be resized.
1507 public void setResizable(boolean b)
1509 resizable = b;
1513 * This method sets the Root Pane for this JInternalFrame.
1515 * @param root The Root Pane for this JInternalFrame.
1517 protected void setRootPane(JRootPane root)
1519 if (rootPane != null)
1520 remove(rootPane);
1522 rootPane = root;
1523 add(root);
1527 * This method sets whether root pane checking is enabled. If root pane
1528 * checking is enabled, then calls to addImpl and setLayout will throw
1529 * exceptions.
1531 * @param enabled Whether root pane checking is enabled.
1533 protected void setRootPaneCheckingEnabled(boolean enabled)
1535 rootPaneCheckingEnabled = enabled;
1539 * This method sets whether this JInternalFrame is the selected frame in the
1540 * JDesktopPane (or other container). When selected, a JInternalFrame will
1541 * have focus and paint its TitlePane differently (usually a different
1542 * colour). If this method selects the frame, this JInternalFrame will fire
1543 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1544 * fire an INTERNAL_FRAME_DEACTIVATED event.
1546 * @param selected Whether this JInternalFrame will become selected or
1547 * deselected.
1549 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1551 public void setSelected(boolean selected) throws PropertyVetoException
1553 if (selected != isSelected())
1555 fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected);
1557 if (! selected)
1558 defaultFocus = getMostRecentFocusOwner();
1560 isSelected = selected;
1562 if (selected)
1563 restoreSubcomponentFocus();
1565 firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
1567 if (isSelected)
1568 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
1569 else
1570 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
1575 * This method sets the title displayed in the TitlePane of this
1576 * JInternalFrame.
1578 * @param title The title displayed.
1580 public void setTitle(String title)
1582 if (title == null && this.title == null)
1583 return;
1584 if (title == null || this.title == null || ! this.title.equals(title))
1586 String old = title;
1587 this.title = title;
1588 firePropertyChange(TITLE_PROPERTY, old, this.title);
1593 * This method displays the JInternalFrame. If it is not visible, this
1594 * method will bring this JInternalFrame to the front, make it visible and
1595 * select it. If this is the first time this JInternalFrame is made
1596 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1598 public void show()
1600 if (! isVisible())
1602 moveToFront();
1603 super.show();
1605 JDesktopPane pane = getDesktopPane();
1606 if (pane != null)
1607 pane.setSelectedFrame(this);
1608 else
1612 setSelected(true);
1614 catch (PropertyVetoException e)
1616 // Do nothing. if they don't want to be selected.
1619 if (isFirstTimeVisible)
1621 isFirstTimeVisible = false;
1622 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
1628 * This method is used to set the UI responsible for the JInternalFrame.
1630 * @param ui The UI responsible for the JInternalFrame.
1632 public void setUI(InternalFrameUI ui)
1634 super.setUI(ui);
1638 * This method causes the JInternalFrame to be brough to back in the
1639 * z-order.
1641 public void toBack()
1643 moveToBack();
1647 * This method causes the JInternalFrame to be brought to front in the
1648 * z-order.
1650 public void toFront()
1652 moveToFront();
1656 * This method resets the UI to the Look and Feel defaults.
1658 public void updateUI()
1660 setUI((InternalFrameUI) UIManager.getUI(this));
1664 * This helper method allows JInternalFrames to signal that they were
1665 * iconned for the first time.
1667 * @param b Whether the JInternalFrame was iconned.
1668 * @param ID The identifier of the property change event to fire if the
1669 * JInternalFrame is iconned for the first time.
1671 void setWasIcon(boolean b, String ID)
1673 if (b && ! wasIcon)
1675 wasIcon = b;
1676 firePropertyChange(ID, ! b, b);
1681 * This helper method returns whether the JInternalFrame has been iconned
1682 * once already.
1684 * @return Whether the JInternalFrame has been iconned once already.
1686 boolean getWasIcon()
1688 return wasIcon;
1692 * This method is a convenience method to fire vetoable property changes.
1694 * @param name The identifier of the property change.
1695 * @param oldValue The old value.
1696 * @param newValue The new value.
1698 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1699 * the change.
1701 private void fireVetoableChange(String name, boolean oldValue,
1702 boolean newValue)
1703 throws PropertyVetoException
1705 super.fireVetoableChange(name, new Boolean(oldValue), new Boolean(newValue));
1707 } // class JInternalFrame