1 /* JInternalFrame.java --
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
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
.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
;
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
,
71 private static final long serialVersionUID
= -5425177187760785402L;
76 protected class AccessibleJInternalFrame
extends AccessibleJComponent
77 implements AccessibleValue
79 private static final long serialVersionUID
= 5931936924175476797L;
82 * Creates a new AccessibleJInternalFrame object.
84 protected AccessibleJInternalFrame()
92 * @return DOCUMENT ME!
94 public String
getAccessibleName()
102 * @return DOCUMENT ME!
104 public AccessibleRole
getAccessibleRole()
112 * @return DOCUMENT ME!
114 public AccessibleValue
getAccessibleValue()
122 * @return DOCUMENT ME!
124 public Number
getCurrentAccessibleValue()
132 * @return DOCUMENT ME!
134 public Number
getMaximumAccessibleValue()
142 * @return DOCUMENT ME!
144 public Number
getMinimumAccessibleValue()
152 * @param n DOCUMENT ME!
154 * @return DOCUMENT ME!
156 public boolean setCurrentAccessibleValue(Number n
)
163 * This class represents the JInternalFrame while it is iconified.
165 public static class JDesktopIcon
extends JComponent
implements Accessible
170 protected class AccessibleJDesktopIcon
extends AccessibleJComponent
171 implements AccessibleValue
173 private static final long serialVersionUID
= 5035560458941637802L;
176 * Creates a new AccessibleJDesktopIcon object.
178 protected AccessibleJDesktopIcon()
186 * @return DOCUMENT ME!
188 public AccessibleRole
getAccessibleRole()
196 * @return DOCUMENT ME!
198 public AccessibleValue
getAccessibleValue()
206 * @return DOCUMENT ME!
208 public Number
getCurrentAccessibleValue()
216 * @return DOCUMENT ME!
218 public Number
getMaximumAccessibleValue()
226 * @return DOCUMENT ME!
228 public Number
getMinimumAccessibleValue()
236 * @param n DOCUMENT ME!
238 * @return DOCUMENT ME!
240 public boolean setCurrentAccessibleValue(Number n
)
246 private static final long serialVersionUID
= 4672973344731387687L;
248 /** The JInternalFrame this DesktopIcon represents. */
249 JInternalFrame frame
;
252 * Creates a new JDesktopIcon object for representing the given frame.
254 * @param f The JInternalFrame to represent.
256 public JDesktopIcon(JInternalFrame f
)
265 * @return DOCUMENT ME!
267 public AccessibleContext
getAccessibleContext()
269 if (accessibleContext
== null)
270 accessibleContext
= new AccessibleJDesktopIcon();
271 return accessibleContext
;
275 * This method returns the JDesktopPane this JDesktopIcon is in.
277 * @return The JDesktopPane this JDesktopIcon is in.
279 public JDesktopPane
getDesktopPane()
281 JDesktopPane p
= (JDesktopPane
) SwingUtilities
.getAncestorOfClass(JDesktopPane
.class,
287 * This method returns the JInternalFrame this JDesktopIcon represents.
289 * @return The JInternalFrame this JDesktopIcon represents.
291 public JInternalFrame
getInternalFrame()
297 * This method returns the UI that is responsible for the JDesktopIcon.
299 * @return The UI that is responsible for the JDesktopIcon.
301 public DesktopIconUI
getUI()
303 return (DesktopIconUI
) ui
;
307 * This method returns the String identifier that is used to determine
308 * which class is used for JDesktopIcon's UI.
310 * @return A String identifier for the UI class.
312 public String
getUIClassID()
314 return "DesktopIconUI";
318 * This method sets the JInternalFrame that this JDesktopIcon represents.
320 * @param f The JInternalFrame that this JDesktopIcon represents.
322 public void setInternalFrame(JInternalFrame f
)
328 * This method sets the UI used for this JDesktopIcon.
330 * @param ui The UI to use.
332 public void setUI(DesktopIconUI ui
)
338 * This method restores the UI property to the defaults.
340 public void updateUI()
342 setUI((DesktopIconUI
) UIManager
.getUI(this));
347 * The property fired in a PropertyChangeEvent when the contentPane property
350 public static final String CONTENT_PANE_PROPERTY
= "contentPane";
353 * The property fired in a PropertyChangeEvent when the frameIcon property
356 public static final String FRAME_ICON_PROPERTY
= "frameIcon";
359 * The property fired in a PropertyChangeEvent when the glassPane property
362 public static final String GLASS_PANE_PROPERTY
= "glassPane";
365 * The property fired in a PropertyChangeEvent when the closed property
368 public static final String IS_CLOSED_PROPERTY
= "closed";
371 * The property fired in a PropertyChangeEvent when the icon property
374 public static final String IS_ICON_PROPERTY
= "icon";
377 * The property fired in a PropertyChangeEvent when the maximum property
380 public static final String IS_MAXIMUM_PROPERTY
= "maximum";
383 * The property fired in a PropertyChangeEvent when the selected property
386 public static final String IS_SELECTED_PROPERTY
= "selected";
389 * The property fired in a PropertyChangeEvent when the layeredPane property
392 public static final String LAYERED_PANE_PROPERTY
= "layeredPane";
395 * The property fired in a PropertyChangeEvent when the jMenuBar property
398 public static final String MENU_BAR_PROPERTY
= "JMenuBar";
401 * The property fired in a PropertyChangeEvent when the rootPane property
404 public static final String ROOT_PANE_PROPERTY
= "rootPane";
407 * The property fired in a PropertyChangeEvent when the title property
410 public static final String TITLE_PROPERTY
= "title";
412 /** Whether the JInternalFrame is closable. */
413 protected boolean closable
;
415 /** Whether the JInternalFrame can be iconified. */
416 protected boolean iconable
;
418 /** Whether the JInternalFrame is closed. */
419 protected boolean isClosed
;
421 /** Whether the JInternalFrame has been iconified. */
422 protected boolean isIcon
;
424 /** Whether the JInternalFrame has been maximized. */
425 protected boolean isMaximum
;
427 /** Whether the JInternalFrame is the active frame. */
428 protected boolean isSelected
;
430 /** Whether the JInternalFrame can be maximized. */
431 protected boolean maximizable
;
434 * Whether the JInternalFrame has rootPaneChecking enabled.
436 * @specnote Should be false to comply with J2SE 5.0
438 protected boolean rootPaneCheckingEnabled
= false;
440 /** Whether the JInternalFrame is resizable. */
441 protected boolean resizable
;
444 * The JDesktopIcon that represents the JInternalFrame while it is
447 protected JDesktopIcon desktopIcon
;
449 /** The icon used in the JMenuBar in the TitlePane. */
450 protected Icon frameIcon
;
452 /** The rootPane of the JInternalFrame. */
453 protected JRootPane rootPane
;
455 /** The title on the TitlePane of the JInternalFrame. */
456 protected String title
;
458 /** The bounds of the JInternalFrame before it was maximized. */
459 private transient Rectangle storedBounds
;
461 /** The Component that receives focus by default. */
462 private transient Component defaultFocus
;
464 /** The default close action taken, */
465 private transient int defaultCloseOperation
= DISPOSE_ON_CLOSE
;
467 /** Whether the JInternalFrame has become visible for the very first time. */
468 private transient boolean isFirstTimeVisible
= true;
471 * Whether the JInternalFrame is in the transition from being a maximized
472 * frame back to a regular sized frame.
474 private transient boolean maxTransition
= false;
477 private transient boolean wasIcon
= false;
480 * Creates a new JInternalFrame object that has no title, and is
481 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
483 public JInternalFrame()
485 this(null, false, false, false, false);
489 * Creates a new JInternalFrame object with the given title and is
490 * non-resizable, non-maximizable, non-iconifiable, and non-closable.
492 * @param title The title displayed in the JInternalFrame.
494 public JInternalFrame(String title
)
496 this(title
, false, false, false, false);
500 * Creates a new JInternalFrame object with the given title and resizable
501 * properties. The JInternalFrame is non-maximizable, non-iconifiable, and
504 * @param title The title displayed in the JInternalFrame.
505 * @param resizable Whether the JInternalFrame is resizable.
507 public JInternalFrame(String title
, boolean resizable
)
509 this(title
, resizable
, false, false, false);
513 * Creates a new JInternalFrame object with the given title, resizable, and
514 * closable properties. The JInternalFrame is non-maximizable and
517 * @param title The title displayed in the JInternalFrame.
518 * @param resizable Whether the JInternalFrame is resizable.
519 * @param closable Whether the JInternalFrame is closable.
521 public JInternalFrame(String title
, boolean resizable
, boolean closable
)
523 this(title
, resizable
, closable
, false, false);
527 * Creates a new JInternalFrame object with the given title, resizable,
528 * closable and maximizable properties. The JInternalFrame is
531 * @param title The title displayed in the JInternalFrame.
532 * @param resizable Whether the JInternalFrame is resizable.
533 * @param closable Whether the JInternalFrame is closable.
534 * @param maximizable Whether the JInternalFrame is maximizable.
536 public JInternalFrame(String title
, boolean resizable
, boolean closable
,
539 this(title
, resizable
, closable
, maximizable
, false);
543 * Creates a new JInternalFrame object with the given title, resizable,
544 * closable, maximizable and iconifiable properties.
546 * @param title The title displayed in the JInternalFrame.
547 * @param resizable Whether the JInternalFrame is resizable.
548 * @param closable Whether the JInternalFrame is closable.
549 * @param maximizable Whether the JInternalFrame is maximizable.
550 * @param iconifiable Whether the JInternalFrame is iconifiable.
552 public JInternalFrame(String title
, boolean resizable
, boolean closable
,
553 boolean maximizable
, boolean iconifiable
)
556 this.resizable
= resizable
;
557 this.closable
= closable
;
558 this.maximizable
= maximizable
;
559 this.iconable
= iconifiable
;
560 storedBounds
= new Rectangle();
561 setRootPane(createRootPane());
562 // JInternalFrames are invisible by default.
565 setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
569 * This method adds Components to this Container. For JInternalFrames,
570 * instead of calling add directly on the JInternalFrame, it should be
571 * called with JInternalFrame.getContentPane().add. If root pane checking
572 * is enabled, calling this method will cause an exception to be thrown.
574 * @param comp The Component to add.
575 * @param constraints The constraints on the Component added.
576 * @param index The position to place the Component.
578 * @throws Error DOCUMENT ME!
580 protected void addImpl(Component comp
, Object constraints
, int index
)
582 // If we're in the initialization stage use super.add. Here we add the
583 // rootPane as well as the title bar and other stuff.
584 // Otherwise pass the add onto the content pane.
585 if (isRootPaneCheckingEnabled())
586 getContentPane().add(comp
, constraints
, index
);
588 super.addImpl(comp
,constraints
, index
);
592 * This method adds an InternalFrameListener to this JInternalFrame.
594 * @param l The listener to add.
596 public void addInternalFrameListener(InternalFrameListener l
)
598 listenerList
.add(InternalFrameListener
.class, l
);
602 * This method is used to create a root pane for the JInternalFrame. This
603 * method is called by the constructors.
605 * @return A root pane for the JInternalFrame to use.
607 protected JRootPane
createRootPane()
609 return new JRootPane();
613 * This method makes this JInternalFrame invisible, unselected and closed.
614 * If this JInternalFrame is not closed already, it will fire an
615 * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
616 * doesn't give vetoable listeners a chance to veto and it will not fire an
617 * INTERNAL_FRAME_CLOSING event.
619 public void dispose()
622 JDesktopPane pane
= getDesktopPane();
624 pane
.setSelectedFrame(null);
631 catch (PropertyVetoException e
)
633 // Do nothing if they don't want to be unselected.
637 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSED
);
642 * This method is used for closing this JInternalFrame. It fires an
643 * INTERNAL_FRAME_CLOSING event and then performs the action specified by
644 * the default close operation.
646 public void doDefaultCloseAction()
648 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSING
);
649 switch (getDefaultCloseOperation())
654 case DISPOSE_ON_CLOSE
:
661 * This method fires an InternalFrameEvent to the listeners.
663 * @param id The type of event being fired. See InternalFrameEvent.
665 protected void fireInternalFrameEvent(int id
)
667 Object
[] ifListeners
= listenerList
.getListenerList();
668 InternalFrameEvent evt
= new InternalFrameEvent(this, id
);
671 case InternalFrameEvent
.INTERNAL_FRAME_CLOSING
:
672 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
674 if (ifListeners
[i
] == InternalFrameListener
.class)
675 ((InternalFrameListener
) ifListeners
[i
+ 1])
676 .internalFrameClosing(evt
);
679 case InternalFrameEvent
.INTERNAL_FRAME_ACTIVATED
:
680 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
682 if (ifListeners
[i
] == InternalFrameListener
.class)
683 ((InternalFrameListener
) ifListeners
[i
+ 1])
684 .internalFrameActivated(evt
);
687 case InternalFrameEvent
.INTERNAL_FRAME_CLOSED
:
688 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
690 if (ifListeners
[i
] == InternalFrameListener
.class)
691 ((InternalFrameListener
) ifListeners
[i
+ 1]).internalFrameClosed(evt
);
694 case InternalFrameEvent
.INTERNAL_FRAME_DEACTIVATED
:
695 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
697 if (ifListeners
[i
] == InternalFrameListener
.class)
698 ((InternalFrameListener
) ifListeners
[i
+ 1])
699 .internalFrameDeactivated(evt
);
702 case InternalFrameEvent
.INTERNAL_FRAME_DEICONIFIED
:
703 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
705 if (ifListeners
[i
] == InternalFrameListener
.class)
706 ((InternalFrameListener
) ifListeners
[i
+ 1])
707 .internalFrameDeiconified(evt
);
710 case InternalFrameEvent
.INTERNAL_FRAME_ICONIFIED
:
711 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
713 if (ifListeners
[i
] == InternalFrameListener
.class)
714 ((InternalFrameListener
) ifListeners
[i
+ 1])
715 .internalFrameIconified(evt
);
718 case InternalFrameEvent
.INTERNAL_FRAME_OPENED
:
719 for (int i
= ifListeners
.length
- 2; i
>= 0; i
-= 2)
721 if (ifListeners
[i
] == InternalFrameListener
.class)
722 ((InternalFrameListener
) ifListeners
[i
+ 1]).internalFrameOpened(evt
);
731 * @return DOCUMENT ME!
733 public AccessibleContext
getAccessibleContext()
735 if (accessibleContext
== null)
736 accessibleContext
= new AccessibleJInternalFrame();
737 return accessibleContext
;
741 * This method returns the Content Pane for this JInternalFrame.
743 * @return The Content Pane for this JInternalFrame.
745 public Container
getContentPane()
747 return getRootPane().getContentPane();
751 * This method returns the default action taken when this JInternalFrame is
754 * @return The default action taken when this JInternalFrame is closed.
756 public int getDefaultCloseOperation()
758 return defaultCloseOperation
;
762 * This method returns the JDesktopIcon that represents this JInternalFrame
763 * while it is iconified.
765 * @return The JDesktopIcon that represents this JInternalFrame while it is
768 public JDesktopIcon
getDesktopIcon()
770 if (desktopIcon
== null)
771 desktopIcon
= new JDesktopIcon(this);
776 * This method searches this JInternalFrame ancestors for an instance of
777 * JDesktopPane. If one is found, it is returned. If none is found, then it
778 * will search the JDesktopIcon for a JDesktopPane.
780 * @return The JDesktopPane that this JInternalFrame belongs to.
782 public JDesktopPane
getDesktopPane()
784 JDesktopPane value
= (JDesktopPane
) SwingUtilities
.getAncestorOfClass(JDesktopPane
.class,
786 if (value
== null && desktopIcon
!= null)
787 value
= desktopIcon
.getDesktopPane();
792 * This method returns null because this must always be the root of a focus
795 * @return always null
799 public final Container
getFocusCycleRootAncestor()
806 * This method returns the child Component that will receive focus if this
807 * JInternalFrame is selected.
809 * @return The child Component that will receive focus.
811 public Component
getFocusOwner()
815 Component focus
= KeyboardFocusManager
.getCurrentKeyboardFocusManager().getFocusOwner();
816 if (SwingUtilities
.isDescendingFrom(focus
, this))
818 defaultFocus
= focus
;
826 * This method returns the Frame Icon (the icon used in the JInternalFrame
827 * TitlePane and iconified frame).
829 * @return The Frame Icon.
831 public Icon
getFrameIcon()
837 * This method returns the Glass Pane used with this JInternalFrame.
839 * @return The Glass Pane used with this JInternalFrame.
841 public Component
getGlassPane()
843 return getRootPane().getGlassPane();
847 * This method returns an array of InternalFrameListeners that are listening
848 * to this JInternalFrame.
850 * @return An array of InternalFrameListeners that are listening to this
853 public InternalFrameListener
[] getInternalFrameListeners()
855 return (InternalFrameListener
[]) listenerList
.getListeners(InternalFrameListener
.class);
859 * This method returns the JMenuBar for this JInternalFrame.
861 * @return The JMenuBar for this JInternalFrame.
863 public JMenuBar
getJMenuBar()
865 return getRootPane().getJMenuBar();
869 * This method returns the layer that this JInternalFrame resides in.
871 * @return The layer that this JInternalFrame resides in.
873 public int getLayer()
875 JDesktopPane pane
= getDesktopPane();
877 // The cast here forces the call to the instance method getLayer()
878 // instead of the static method (this would lead to infinite
880 return pane
.getLayer((Component
) this);
885 * This method returns the LayeredPane for this JInternalFrame.
887 * @return The LayeredPane for this JInternalFrame.
889 public JLayeredPane
getLayeredPane()
891 return getRootPane().getLayeredPane();
895 * This method is deprecated. This method returns the JMenuBar for this
898 * @return The JMenuBar for this JInternalFrame.
902 public JMenuBar
getMenuBar()
904 return getJMenuBar();
908 * This method returns the child Component that will receive focus when the
909 * JInternalFrame is selected. If the JInternalFrame is selected, this
910 * method returns getFocusOwner(). Otherwise, it will return the child
911 * Component that most recently requested focus. If that is null, then the
912 * initial focus Component is returned. If that is null, then the default
913 * focus component is returned.
915 * @return The most recent focus owner.
917 public Component
getMostRecentFocusOwner()
920 return getFocusOwner();
926 * This method returns the bounds of the JInternalFrame if it is not
927 * maximized. If it is maximized, it returns the bounds of the
928 * JInternalFrame before it was maximized (the bounds that it will be
931 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
932 * just its bounds if it is not maximized).
934 public Rectangle
getNormalBounds()
936 if (! isMaximum() && ! maxTransition
)
943 * This method returns the Root Pane for this JInternalFrame.
945 * @return The Root Pane for this JInternalFrame.
947 public JRootPane
getRootPane()
953 * This method sets the title of the JInternalFrame.
955 * @return The String displayed in the TitlePane of this JInternalFrame.
957 public String
getTitle()
963 * This method returns the UI used to represent the JInternalFrame.
965 * @return The UI used to represent the JInternalFrame.
967 public InternalFrameUI
getUI()
969 return (InternalFrameUI
) ui
;
973 * This method returns a String identifier that is used to determine which
974 * class acts as the JInternalFrame's UI.
976 * @return A String identifier to determine a UI class.
978 public String
getUIClassID()
980 return "InternalFrameUI";
984 * This method returns null.
988 public final String
getWarningString()
995 * This method deselects this JInternalFrame and hides it.
999 JDesktopPane pane
= getDesktopPane();
1001 pane
.setSelectedFrame(null);
1008 catch (PropertyVetoException e
)
1017 * This method returns whether this JInternalFrame is closable.
1019 * @return Whether this JInternalFrame is closable.
1021 public boolean isClosable()
1027 * This method returns whether this JInternalFrame has been closed.
1029 * @return Whether this JInternalFrame is closed.
1031 public boolean isClosed()
1037 * This must always return true.
1039 * @return always true
1043 public final boolean isFocusCycleRoot()
1049 * This method returns whether this JInternalFrame is currently iconified.
1051 * @return Whether this JInternalFrame is currently iconified.
1053 public boolean isIcon()
1059 * This method returns whether the JInternalFrame can be iconified.
1061 * @return Whether the JInternalFrame can be iconified.
1063 public boolean isIconifiable()
1069 * This method returns whether this JInternalFrame can be maximized.
1071 * @return Whether this JInternalFrame can be maximized.
1073 public boolean isMaximizable()
1079 * This method returns whether this JInternalFrame is currently maximized.
1081 * @return Whether this JInternalFrame is maximized.
1083 public boolean isMaximum()
1089 * This method returns whether this JInternalFrame is resizable.
1091 * @return Whether this JInternalFrame is resizable.
1093 public boolean isResizable()
1099 * This method returns whether root pane checking is enabled. If root pane
1100 * checking is enabled, then calls to addImpl and setLayout will throw
1103 * @return Whether root pane checking is enabled.
1105 protected boolean isRootPaneCheckingEnabled()
1107 return rootPaneCheckingEnabled
;
1111 * This method returns whether this JInternalFrame is selected.
1113 * @return Whether this JInternalFrame is selected.
1115 public boolean isSelected()
1121 * A helper method that moves this JInternalFrame to the back if the parent
1122 * is a JLayeredPane.
1124 public void moveToBack()
1126 if (getParent() instanceof JLayeredPane
)
1127 ((JLayeredPane
) getParent()).moveToBack(this);
1131 * A helper method that moves this JInternalFrame to the front if the parent
1132 * is a JLayeredPane.
1134 public void moveToFront()
1136 if (getParent() instanceof JLayeredPane
)
1137 ((JLayeredPane
) getParent()).moveToFront(this);
1141 * This method causes the children of this JInternalFrame to be laid out.
1142 * Before it begins, if this JInternalFrame is an icon, then it will be
1143 * deiconified. If it is maximized, then it will be restored. If either
1144 * operation fails, then this method will return.
1152 else if (isMaximum())
1155 catch (PropertyVetoException e
)
1157 // Do nothing if they don't want to be restored first.
1159 setSize(getPreferredSize());
1163 * This method is overridden to allow for speedier painting while this
1164 * JInternalFramme is being dragged.
1166 * @param g The Graphics object to paint with.
1168 protected void paintComponent(Graphics g
)
1170 super.paintComponent(g
);
1174 * This method returns a String describing this JInternalFrame.
1176 * @return A String describing this JInternalFrame.
1178 protected String
paramString()
1180 return super.paramString();
1184 * This method removes the given Component from the Container.
1186 * @param comp The Component to remove.
1188 public void remove(Component comp
)
1190 // If we're removing the root pane, use super.remove. Otherwise
1191 // pass it on to the content pane instead.
1195 getContentPane().remove(comp
);
1199 * This method removes an InternalFrameListener from this JInternalFrame.
1201 * @param l The listener to remove.
1203 public void removeInternalFrameListener(InternalFrameListener l
)
1205 listenerList
.remove(InternalFrameListener
.class, l
);
1209 * This method resizes and positions this JInternalFrame. It also forces a
1210 * relayout of the Container.
1212 * @param x The x position of this JInternalFrame.
1213 * @param y The y position of this JInternalFrame.
1214 * @param width The width of this JInternalFrame.
1215 * @param height The height of this JInternalFrame.
1217 public void reshape(int x
, int y
, int width
, int height
)
1219 super.reshape(x
, y
, width
, height
);
1224 * This method gives focus to the last child Component that had focus. This
1225 * is used by the UI when this JInternalFrame is activated.
1227 public void restoreSubcomponentFocus()
1229 Component c
= getMostRecentFocusOwner();
1235 * This method sets whether this JInternalFrame can be closed.
1237 * @param b Whether this JInternalFrame can be closed.
1239 public void setClosable(boolean b
)
1245 * This method closes the JInternalFrame if the given boolean is true. If it
1246 * is false, then the result of this method is unspecified. If the
1247 * JInternalFrame is closed, this method does nothing. This method will
1248 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1249 * listeners to cancel the close. If no listener vetoes the change, the
1250 * closed property is set to true and the JInternalFrame is hidden and
1251 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1254 * @param b Whether the JInternalFrame will be closed.
1256 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1258 public void setClosed(boolean b
) throws PropertyVetoException
1260 if (b
&& ! isClosed())
1262 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSING
);
1263 fireVetoableChange(IS_CLOSED_PROPERTY
, false, true);
1268 firePropertyChange(IS_CLOSED_PROPERTY
, false, true);
1269 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSED
);
1274 * This method sets the Container to be used as a Content Pane for this
1277 * @param c The Container to use as a Content Pane.
1279 public void setContentPane(Container c
)
1281 if (c
!= getContentPane())
1283 Container old
= getContentPane();
1284 getRootPane().setContentPane(c
);
1285 firePropertyChange(CONTENT_PANE_PROPERTY
, old
, c
);
1290 * This method sets the action taken when this JInternalFrame is closed.
1292 * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1295 * @throws Error If the given operation is not one of the allowed modes.
1297 public void setDefaultCloseOperation(int operation
)
1299 /* Reference implementation allows invalid operations to be specified.
1300 In that case, behaviour defaults to DO_NOTHING_ON_CLOSE.
1301 processWindowEvent handles the behaviour. getDefaultCloseOperation
1302 must return the invalid operator code. */
1303 defaultCloseOperation
= operation
;
1307 * This method sets the JDesktopIcon that represents this JInternalFrame
1308 * while it is iconified.
1310 * @param d The JDesktopIcon that represents this JInternalFrame while it is
1313 public void setDesktopIcon(JDesktopIcon d
)
1315 d
.setInternalFrame(this);
1320 * This method does nothing because this must be the root of a focus
1323 * @param focusCycleRoot Not used.
1325 public final void setFocusCycleRoot(boolean focusCycleRoot
)
1331 * This method sets the Icon to be used in two places. The first is icon
1332 * that is painted at the top left corner of the JInternalFrame when it is
1333 * not iconified (clicking on that icon will activate the TitlePane
1334 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1335 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1336 * will use a Look and Feel default.
1338 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1340 public void setFrameIcon(Icon icon
)
1342 if (icon
!= frameIcon
)
1344 Icon old
= frameIcon
;
1346 firePropertyChange(FRAME_ICON_PROPERTY
, old
, frameIcon
);
1351 * This method sets the Glass Pane used with this JInternalFrame.
1353 * @param glass The Glass Pane to use with this JInternalFrame.
1355 public void setGlassPane(Component glass
)
1357 if (glass
!= getGlassPane())
1359 Component old
= getGlassPane();
1360 getRootPane().setGlassPane(glass
);
1361 firePropertyChange(GLASS_PANE_PROPERTY
, old
, glass
);
1366 * This method iconifies or deiconifies this JInternalFrame given the
1367 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1368 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1369 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1371 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1373 * @throws PropertyVetoException DOCUMENT ME!
1375 public void setIcon(boolean b
) throws PropertyVetoException
1379 fireVetoableChange(IS_ICON_PROPERTY
, b
, isIcon
);
1383 firePropertyChange(IS_ICON_PROPERTY
, ! isIcon
, isIcon
);
1385 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_ICONIFIED
);
1387 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_DEICONIFIED
);
1392 * This method sets whether the JInternalFrame can be iconified. (This means
1393 * that the JInternalFrame can be turned into an icon if minimized).
1395 * @param b Whether the JInternalFrame can be iconified.
1397 public void setIconifiable(boolean b
)
1403 * This method sets the JMenuBar to be used with this JInternalFrame.
1405 * @param b The JMenuBar to be used with this JInternalFrame.
1407 public void setJMenuBar(JMenuBar b
)
1409 getRootPane().setJMenuBar(b
);
1413 * A helper method that set the layer that this JInternalFrame resides in.
1414 * Using this version of the method means that the user should not set it
1415 * to values that are already defined in JLayeredPane. If predefined values
1416 * are to be used, the user should use the setLayer(Integer) version.
1418 * @param layer The layer to place this JInternalFrame in.
1420 public void setLayer(int layer
)
1422 setLayer(new Integer(layer
));
1426 * A helper method that sets the layer that this JInternalFrame resides in.
1427 * Calling this version of the method should use layer values that are
1428 * already defined in JLayeredPane.
1430 * @param layer The layer to place this JInternalFrame in.
1432 public void setLayer(Integer layer
)
1434 JDesktopPane p
= getDesktopPane();
1437 int pos
= p
.getPosition(this);
1438 p
.setLayer(this, layer
.intValue(), pos
);
1443 * This method sets the JLayeredPane to use with this JInternalFrame.
1445 * @param layered The JLayeredPane to use as a layeredPane.
1447 public void setLayeredPane(JLayeredPane layered
)
1449 if (layered
!= getLayeredPane())
1451 JLayeredPane old
= getLayeredPane();
1452 getRootPane().setLayeredPane(layered
);
1453 firePropertyChange(LAYERED_PANE_PROPERTY
, old
, layered
);
1458 * This method sets whether the JInternalFrame can be maximized.
1460 * @param b Whether this JInternalFrame can be maximized.
1462 public void setMaximizable(boolean b
)
1468 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1469 * should not be called on the JInternalFrame directly. Instead, it should
1470 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1471 * method with root pane checking enabled will cause exceptions to be
1474 * @param manager The Layout Manager to be used with the JInternalFrame.
1476 * @throws Error If rootPaneChecking is enabled.
1478 public void setLayout(LayoutManager manager
)
1480 // Check if we're in initialization stage. If so, call super.setLayout
1481 // otherwise, valid calls go to the content pane.
1482 if (isRootPaneCheckingEnabled())
1483 getContentPane().setLayout(manager
);
1485 super.setLayout(manager
);
1489 * This method sets the JInternalFrame to maximized (if the given argument
1490 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1492 * @param b Whether this JInteralFrame will be maximized or restored.
1494 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1496 public void setMaximum(boolean b
) throws PropertyVetoException
1498 if (b
!= isMaximum())
1500 fireVetoableChange(IS_MAXIMUM_PROPERTY
, b
, isMaximum
);
1503 setNormalBounds(getBounds());
1504 maxTransition
= ! b
;
1505 firePropertyChange(IS_MAXIMUM_PROPERTY
, ! isMaximum
, isMaximum
);
1506 maxTransition
= false;
1511 * This method is deprecated. This method sets the JMenuBar used with this
1514 * @param m The JMenuBar to use with this JInternalFrame.
1518 public void setMenuBar(JMenuBar m
)
1524 * This method sets the bounds that this JInternalFrame will be restored to.
1526 * @param r The bounds that this JInternalFrame will be restored to.
1528 public void setNormalBounds(Rectangle r
)
1530 storedBounds
.setBounds(r
.x
, r
.y
, r
.width
, r
.height
);
1534 * This method sets whether the JInternalFrame can be resized by a user
1535 * action (like dragging at the frame borders).
1537 * @param b Whether this JInternalFramer can be resized.
1539 public void setResizable(boolean b
)
1545 * This method sets the Root Pane for this JInternalFrame.
1547 * @param root The Root Pane for this JInternalFrame.
1549 protected void setRootPane(JRootPane root
)
1551 if (rootPane
!= null)
1559 * This method sets whether root pane checking is enabled. If root pane
1560 * checking is enabled, then calls to addImpl and setLayout will throw
1563 * @param enabled Whether root pane checking is enabled.
1565 protected void setRootPaneCheckingEnabled(boolean enabled
)
1567 rootPaneCheckingEnabled
= enabled
;
1571 * This method sets whether this JInternalFrame is the selected frame in the
1572 * JDesktopPane (or other container). When selected, a JInternalFrame will
1573 * have focus and paint its TitlePane differently (usually a different
1574 * colour). If this method selects the frame, this JInternalFrame will fire
1575 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1576 * fire an INTERNAL_FRAME_DEACTIVATED event.
1578 * @param selected Whether this JInternalFrame will become selected or
1581 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1583 public void setSelected(boolean selected
) throws PropertyVetoException
1585 if (selected
!= isSelected())
1587 fireVetoableChange(IS_SELECTED_PROPERTY
, selected
, isSelected
);
1590 defaultFocus
= getMostRecentFocusOwner();
1592 isSelected
= selected
;
1595 restoreSubcomponentFocus();
1597 firePropertyChange(IS_SELECTED_PROPERTY
, ! isSelected
, isSelected
);
1600 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_ACTIVATED
);
1602 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_DEACTIVATED
);
1607 * This method sets the title displayed in the TitlePane of this
1610 * @param title The title displayed.
1612 public void setTitle(String title
)
1614 if (title
== null && this.title
== null)
1616 if (title
== null || this.title
== null || ! this.title
.equals(title
))
1620 firePropertyChange(TITLE_PROPERTY
, old
, this.title
);
1625 * This method displays the JInternalFrame. If it is not visible, this
1626 * method will bring this JInternalFrame to the front, make it visible and
1627 * select it. If this is the first time this JInternalFrame is made
1628 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1636 JDesktopPane pane
= getDesktopPane();
1638 pane
.setSelectedFrame(this);
1645 catch (PropertyVetoException e
)
1647 // Do nothing. if they don't want to be selected.
1650 if (isFirstTimeVisible
)
1652 isFirstTimeVisible
= false;
1653 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_OPENED
);
1659 * This method is used to set the UI responsible for the JInternalFrame.
1661 * @param ui The UI responsible for the JInternalFrame.
1663 public void setUI(InternalFrameUI ui
)
1665 // We must temporarily go into init mode so that the UI can directly
1666 // manipulate the JInternalFrame.
1667 boolean old
= isRootPaneCheckingEnabled();
1668 setRootPaneCheckingEnabled(false);
1670 setRootPaneCheckingEnabled(old
);
1674 * This method causes the JInternalFrame to be brough to back in the
1677 public void toBack()
1683 * This method causes the JInternalFrame to be brought to front in the
1686 public void toFront()
1692 * This method resets the UI to the Look and Feel defaults.
1694 public void updateUI()
1696 // We must go into the init stage when updating the UI, so the UI can
1697 // set layout and components directly on the internal frame, not its
1699 boolean old
= isRootPaneCheckingEnabled();
1700 setRootPaneCheckingEnabled(false);
1701 setUI((InternalFrameUI
) UIManager
.getUI(this));
1702 setRootPaneCheckingEnabled(old
);
1706 * This helper method allows JInternalFrames to signal that they were
1707 * iconned for the first time.
1709 * @param b Whether the JInternalFrame was iconned.
1710 * @param ID The identifier of the property change event to fire if the
1711 * JInternalFrame is iconned for the first time.
1713 void setWasIcon(boolean b
, String ID
)
1718 firePropertyChange(ID
, ! b
, b
);
1723 * This helper method returns whether the JInternalFrame has been iconned
1726 * @return Whether the JInternalFrame has been iconned once already.
1728 boolean getWasIcon()
1734 * This method is a convenience method to fire vetoable property changes.
1736 * @param name The identifier of the property change.
1737 * @param oldValue The old value.
1738 * @param newValue The new value.
1740 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1743 private void fireVetoableChange(String name
, boolean oldValue
,
1745 throws PropertyVetoException
1747 super.fireVetoableChange(name
, Boolean
.valueOf(oldValue
), Boolean
.valueOf(newValue
));