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., 59 Temple Place, Suite 330, 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
80 * Creates a new AccessibleJInternalFrame object.
82 protected AccessibleJInternalFrame()
90 * @return DOCUMENT ME!
92 public String
getAccessibleName()
100 * @return DOCUMENT ME!
102 public AccessibleRole
getAccessibleRole()
110 * @return DOCUMENT ME!
112 public AccessibleValue
getAccessibleValue()
120 * @return DOCUMENT ME!
122 public Number
getCurrentAccessibleValue()
130 * @return DOCUMENT ME!
132 public Number
getMaximumAccessibleValue()
140 * @return DOCUMENT ME!
142 public Number
getMinimumAccessibleValue()
150 * @param n DOCUMENT ME!
152 * @return DOCUMENT ME!
154 public boolean setCurrentAccessibleValue(Number n
)
161 * This class represents the JInternalFrame while it is iconified.
163 public static class JDesktopIcon
extends JComponent
implements Accessible
168 protected class AccessibleJDesktopIcon
extends AccessibleJComponent
169 implements AccessibleValue
172 * Creates a new AccessibleJDesktopIcon object.
174 protected AccessibleJDesktopIcon()
182 * @return DOCUMENT ME!
184 public AccessibleRole
getAccessibleRole()
192 * @return DOCUMENT ME!
194 public AccessibleValue
getAccessibleValue()
202 * @return DOCUMENT ME!
204 public Number
getCurrentAccessibleValue()
212 * @return DOCUMENT ME!
214 public Number
getMaximumAccessibleValue()
222 * @return DOCUMENT ME!
224 public Number
getMinimumAccessibleValue()
232 * @param n DOCUMENT ME!
234 * @return DOCUMENT ME!
236 public boolean setCurrentAccessibleValue(Number n
)
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
)
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,
281 * This method returns the JInternalFrame this JDesktopIcon represents.
283 * @return The JInternalFrame this JDesktopIcon represents.
285 public JInternalFrame
getInternalFrame()
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
)
322 * This method sets the UI used for this JDesktopIcon.
324 * @param ui The UI to use.
326 public void setUI(DesktopIconUI 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
344 public static final String CONTENT_PANE_PROPERTY
= "contentPane";
347 * The property fired in a PropertyChangeEvent when the frameIcon property
350 public static final String FRAME_ICON_PROPERTY
= "frameIcon";
353 * The property fired in a PropertyChangeEvent when the glassPane property
356 public static final String GLASS_PANE_PROPERTY
= "glassPane";
359 * The property fired in a PropertyChangeEvent when the closed property
362 public static final String IS_CLOSED_PROPERTY
= "closed";
365 * The property fired in a PropertyChangeEvent when the icon property
368 public static final String IS_ICON_PROPERTY
= "icon";
371 * The property fired in a PropertyChangeEvent when the maximum property
374 public static final String IS_MAXIMUM_PROPERTY
= "maximum";
377 * The property fired in a PropertyChangeEvent when the selected property
380 public static final String IS_SELECTED_PROPERTY
= "selected";
383 * The property fired in a PropertyChangeEvent when the layeredPane property
386 public static final String LAYERED_PANE_PROPERTY
= "layeredPane";
389 * The property fired in a PropertyChangeEvent when the jMenuBar property
392 public static final String MENU_BAR_PROPERTY
= "JMenuBar";
395 * The property fired in a PropertyChangeEvent when the rootPane property
398 public static final String ROOT_PANE_PROPERTY
= "rootPane";
401 * The property fired in a PropertyChangeEvent when the title property
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
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;
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
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
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
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
,
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
)
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());
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()
610 JDesktopPane pane
= getDesktopPane();
612 pane
.setSelectedFrame(null);
619 catch (PropertyVetoException e
)
621 // Do nothing if they don't want to be unselected.
625 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSED
);
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())
642 case DISPOSE_ON_CLOSE
:
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
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
756 public JDesktopIcon
getDesktopIcon()
758 if (desktopIcon
== null)
759 desktopIcon
= new JDesktopIcon(this);
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,
774 if (value
== null && desktopIcon
!= null)
775 value
= desktopIcon
.getDesktopPane();
780 * This method returns null because this must always be the root of a focus
783 * @return always null
787 public final Container
getFocusCycleRootAncestor()
794 * This method returns the child Component that will receive focus if this
795 * JInternalFrame is selected.
797 * @return The child Component that will receive focus.
799 public Component
getFocusOwner()
803 Component focus
= KeyboardFocusManager
.getCurrentKeyboardFocusManager().getFocusOwner();
804 if (SwingUtilities
.isDescendingFrom(focus
, this))
806 defaultFocus
= focus
;
814 * This method returns the Frame Icon (the icon used in the JInternalFrame
815 * TitlePane and iconified frame).
817 * @return The Frame Icon.
819 public Icon
getFrameIcon()
825 * This method returns the Glass Pane used with this JInternalFrame.
827 * @return The Glass Pane used with this JInternalFrame.
829 public Component
getGlassPane()
831 return getRootPane().getGlassPane();
835 * This method returns an array of InternalFrameListeners that are listening
836 * to this JInternalFrame.
838 * @return An array of InternalFrameListeners that are listening to this
841 public InternalFrameListener
[] getInternalFrameListeners()
843 return (InternalFrameListener
[]) listenerList
.getListeners(InternalFrameListener
.class);
847 * This method returns the JMenuBar for this JInternalFrame.
849 * @return The JMenuBar for this JInternalFrame.
851 public JMenuBar
getJMenuBar()
853 return getRootPane().getJMenuBar();
857 * This method returns the layer that this JInternalFrame resides in.
859 * @return The layer that this JInternalFrame resides in.
861 public int getLayer()
863 JDesktopPane pane
= getDesktopPane();
865 return pane
.getLayer(this);
870 * This method returns the LayeredPane for this JInternalFrame.
872 * @return The LayeredPane for this JInternalFrame.
874 public JLayeredPane
getLayeredPane()
876 return getRootPane().getLayeredPane();
880 * This method is deprecated. This method returns the JMenuBar for this
883 * @return The JMenuBar for this JInternalFrame.
887 public JMenuBar
getMenuBar()
889 return getJMenuBar();
893 * This method returns the child Component that will receive focus when the
894 * JInternalFrame is selected. If the JInternalFrame is selected, this
895 * method returns getFocusOwner(). Otherwise, it will return the child
896 * Component that most recently requested focus. If that is null, then the
897 * initial focus Component is returned. If that is null, then the default
898 * focus component is returned.
900 * @return The most recent focus owner.
902 public Component
getMostRecentFocusOwner()
905 return getFocusOwner();
911 * This method returns the bounds of the JInternalFrame if it is not
912 * maximized. If it is maximized, it returns the bounds of the
913 * JInternalFrame before it was maximized (the bounds that it will be
916 * @return A Rectangle that contains this JInternalFrame's normal bounds (or
917 * just its bounds if it is not maximized).
919 public Rectangle
getNormalBounds()
921 if (! isMaximum() && ! maxTransition
)
928 * This method returns the Root Pane for this JInternalFrame.
930 * @return The Root Pane for this JInternalFrame.
932 public JRootPane
getRootPane()
938 * This method sets the title of the JInternalFrame.
940 * @return The String displayed in the TitlePane of this JInternalFrame.
942 public String
getTitle()
948 * This method returns the UI used to represent the JInternalFrame.
950 * @return The UI used to represent the JInternalFrame.
952 public InternalFrameUI
getUI()
954 return (InternalFrameUI
) ui
;
958 * This method returns a String identifier that is used to determine which
959 * class acts as the JInternalFrame's UI.
961 * @return A String identifier to determine a UI class.
963 public String
getUIClassID()
965 return "InternalFrameUI";
969 * This method returns null.
973 public final String
getWarningString()
980 * This method deselects this JInternalFrame and hides it.
984 JDesktopPane pane
= getDesktopPane();
986 pane
.setSelectedFrame(null);
993 catch (PropertyVetoException e
)
1002 * This method returns whether this JInternalFrame is closable.
1004 * @return Whether this JInternalFrame is closable.
1006 public boolean isClosable()
1012 * This method returns whether this JInternalFrame has been closed.
1014 * @return Whether this JInternalFrame is closed.
1016 public boolean isClosed()
1022 * This must always return true.
1024 * @return always true
1028 public final boolean isFocusCycleRoot()
1034 * This method returns whether this JInternalFrame is currently iconified.
1036 * @return Whether this JInternalFrame is currently iconified.
1038 public boolean isIcon()
1044 * This method returns whether the JInternalFrame can be iconified.
1046 * @return Whether the JInternalFrame can be iconified.
1048 public boolean isIconifiable()
1054 * This method returns whether this JInternalFrame can be maximized.
1056 * @return Whether this JInternalFrame can be maximized.
1058 public boolean isMaximizable()
1064 * This method returns whether this JInternalFrame is currently maximized.
1066 * @return Whether this JInternalFrame is maximized.
1068 public boolean isMaximum()
1074 * This method returns whether this JInternalFrame is resizable.
1076 * @return Whether this JInternalFrame is resizable.
1078 public boolean isResizable()
1084 * This method returns whether root pane checking is enabled. If root pane
1085 * checking is enabled, then calls to addImpl and setLayout will throw
1088 * @return Whether root pane checking is enabled.
1090 protected boolean isRootPaneCheckingEnabled()
1092 return rootPaneCheckingEnabled
;
1096 * This method returns whether this JInternalFrame is selected.
1098 * @return Whether this JInternalFrame is selected.
1100 public boolean isSelected()
1106 * A helper method that moves this JInternalFrame to the back if the parent
1107 * is a JLayeredPane.
1109 public void moveToBack()
1111 if (getParent() instanceof JLayeredPane
)
1112 ((JLayeredPane
) getParent()).moveToBack(this);
1116 * A helper method that moves this JInternalFrame to the front if the parent
1117 * is a JLayeredPane.
1119 public void moveToFront()
1121 if (getParent() instanceof JLayeredPane
)
1122 ((JLayeredPane
) getParent()).moveToFront(this);
1126 * This method causes the children of this JInternalFrame to be laid out.
1127 * Before it begins, if this JInternalFrame is an icon, then it will be
1128 * deiconified. If it is maximized, then it will be restored. If either
1129 * operation fails, then this method will return.
1137 else if (isMaximum())
1140 catch (PropertyVetoException e
)
1142 // Do nothing if they don't want to be restored first.
1148 * This method is overridden to allow for speedier painting while this
1149 * JInternalFramme is being dragged.
1151 * @param g The Graphics object to paint with.
1153 protected void paintComponent(Graphics g
)
1155 super.paintComponent(g
);
1159 * This method returns a String describing this JInternalFrame.
1161 * @return A String describing this JInternalFrame.
1163 protected String
paramString()
1165 return "JInternalFrame";
1169 * This method removes the given Component from the Container.
1171 * @param comp The Component to remove.
1173 public void remove(Component comp
)
1179 * This method removes an InternalFrameListener from this JInternalFrame.
1181 * @param l The listener to remove.
1183 public void removeInternalFrameListener(InternalFrameListener l
)
1185 listenerList
.remove(InternalFrameListener
.class, l
);
1189 * This method resizes and positions this JInternalFrame. It also forces a
1190 * relayout of the Container.
1192 * @param x The x position of this JInternalFrame.
1193 * @param y The y position of this JInternalFrame.
1194 * @param width The width of this JInternalFrame.
1195 * @param height The height of this JInternalFrame.
1197 public void reshape(int x
, int y
, int width
, int height
)
1199 super.reshape(x
, y
, width
, height
);
1205 * This method gives focus to the last child Component that had focus. This
1206 * is used by the UI when this JInternalFrame is activated.
1208 public void restoreSubcomponentFocus()
1210 Component c
= getMostRecentFocusOwner();
1216 * This method sets whether this JInternalFrame can be closed.
1218 * @param b Whether this JInternalFrame can be closed.
1220 public void setClosable(boolean b
)
1226 * This method closes the JInternalFrame if the given boolean is true. If it
1227 * is false, then the result of this method is unspecified. If the
1228 * JInternalFrame is closed, this method does nothing. This method will
1229 * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1230 * listeners to cancel the close. If no listener vetoes the change, the
1231 * closed property is set to true and the JInternalFrame is hidden and
1232 * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1235 * @param b Whether the JInternalFrame will be closed.
1237 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1239 public void setClosed(boolean b
) throws PropertyVetoException
1241 if (b
&& ! isClosed())
1243 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSING
);
1244 fireVetoableChange(IS_CLOSED_PROPERTY
, false, true);
1248 firePropertyChange(IS_CLOSED_PROPERTY
, false, true);
1249 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_CLOSED
);
1254 * This method sets the Container to be used as a Content Pane for this
1257 * @param c The Container to use as a Content Pane.
1259 public void setContentPane(Container c
)
1261 if (c
!= getContentPane())
1263 Container old
= getContentPane();
1264 getRootPane().setContentPane(c
);
1265 firePropertyChange(CONTENT_PANE_PROPERTY
, old
, c
);
1270 * This method sets the action taken when this JInternalFrame is closed.
1272 * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1275 * @throws Error If the given operation is not one of the allowed modes.
1277 public void setDefaultCloseOperation(int operation
)
1279 if (operation
!= DO_NOTHING_ON_CLOSE
1280 && operation
!= HIDE_ON_CLOSE
1281 && operation
!= DISPOSE_ON_CLOSE
)
1282 throw new Error("Close operation must be one of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE");
1283 defaultCloseOperation
= operation
;
1287 * This method sets the JDesktopIcon that represents this JInternalFrame
1288 * while it is iconified.
1290 * @param d The JDesktopIcon that represents this JInternalFrame while it is
1293 public void setDesktopIcon(JDesktopIcon d
)
1295 d
.setInternalFrame(this);
1300 * This method does nothing because this must be the root of a focus
1303 * @param focusCycleRoot Not used.
1305 public final void setFocusCycleRoot(boolean focusCycleRoot
)
1311 * This method sets the Icon to be used in two places. The first is icon
1312 * that is painted at the top left corner of the JInternalFrame when it is
1313 * not iconified (clicking on that icon will activate the TitlePane
1314 * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1315 * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1316 * will use a Look and Feel default.
1318 * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1320 public void setFrameIcon(Icon icon
)
1322 if (icon
!= frameIcon
)
1324 Icon old
= frameIcon
;
1326 firePropertyChange(FRAME_ICON_PROPERTY
, old
, frameIcon
);
1331 * This method sets the Glass Pane used with this JInternalFrame.
1333 * @param glass The Glass Pane to use with this JInternalFrame.
1335 public void setGlassPane(Component glass
)
1337 if (glass
!= getGlassPane())
1339 Component old
= getGlassPane();
1340 getRootPane().setGlassPane(glass
);
1341 firePropertyChange(GLASS_PANE_PROPERTY
, old
, glass
);
1346 * This method iconifies or deiconifies this JInternalFrame given the
1347 * boolean argument. If the JInternalFrame becomes iconified, it will fire
1348 * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1349 * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1351 * @param b Whether this JInternalFrame is to be iconified or deiconified.
1353 * @throws PropertyVetoException DOCUMENT ME!
1355 public void setIcon(boolean b
) throws PropertyVetoException
1359 fireVetoableChange(IS_ICON_PROPERTY
, b
, isIcon
);
1363 firePropertyChange(IS_ICON_PROPERTY
, ! isIcon
, isIcon
);
1365 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_ICONIFIED
);
1367 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_DEICONIFIED
);
1372 * This method sets whether the JInternalFrame can be iconified. (This means
1373 * that the JInternalFrame can be turned into an icon if minimized).
1375 * @param b Whether the JInternalFrame can be iconified.
1377 public void setIconifiable(boolean b
)
1383 * This method sets the JMenuBar to be used with this JInternalFrame.
1385 * @param b The JMenuBar to be used with this JInternalFrame.
1387 public void setJMenuBar(JMenuBar b
)
1389 getRootPane().setJMenuBar(b
);
1393 * A helper method that set the layer that this JInternalFrame resides in.
1394 * Using this version of the method means that the user should not set it
1395 * to values that are already defined in JLayeredPane. If predefined values
1396 * are to be used, the user should use the setLayer(Integer) version.
1398 * @param layer The layer to place this JInternalFrame in.
1400 public void setLayer(int layer
)
1402 setLayer(new Integer(layer
));
1406 * A helper method that sets the layer that this JInternalFrame resides in.
1407 * Calling this version of the method should use layer values that are
1408 * already defined in JLayeredPane.
1410 * @param layer The layer to place this JInternalFrame in.
1412 public void setLayer(Integer layer
)
1414 JDesktopPane p
= getDesktopPane();
1417 int pos
= p
.getPosition(this);
1418 p
.setLayer(this, layer
.intValue(), pos
);
1423 * This method sets the JLayeredPane to use with this JInternalFrame.
1425 * @param layered The JLayeredPane to use as a layeredPane.
1427 public void setLayeredPane(JLayeredPane layered
)
1429 if (layered
!= getLayeredPane())
1431 JLayeredPane old
= getLayeredPane();
1432 getRootPane().setLayeredPane(layered
);
1433 firePropertyChange(LAYERED_PANE_PROPERTY
, old
, layered
);
1438 * This method sets whether the JInternalFrame can be maximized.
1440 * @param b Whether this JInternalFrame can be maximized.
1442 public void setMaximizable(boolean b
)
1448 * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1449 * should not be called on the JInternalFrame directly. Instead, it should
1450 * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1451 * method with root pane checking enabled will cause exceptions to be
1454 * @param manager The Layout Manager to be used with the JInternalFrame.
1456 * @throws Error If rootPaneChecking is enabled.
1458 public void setLayout(LayoutManager manager
)
1460 if (isRootPaneCheckingEnabled())
1461 throw new Error("Cannot set layout. Use getContentPane().setLayout() instead.");
1462 super.setLayout(manager
);
1466 * This method sets the JInternalFrame to maximized (if the given argument
1467 * is true) or restores the JInternalFrame to its normal bounds otherwise.
1469 * @param b Whether this JInteralFrame will be maximized or restored.
1471 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1473 public void setMaximum(boolean b
) throws PropertyVetoException
1475 if (b
!= isMaximum())
1477 fireVetoableChange(IS_MAXIMUM_PROPERTY
, b
, isMaximum
);
1480 setNormalBounds(getBounds());
1481 maxTransition
= ! b
;
1482 firePropertyChange(IS_MAXIMUM_PROPERTY
, ! isMaximum
, isMaximum
);
1483 maxTransition
= false;
1488 * This method is deprecated. This method sets the JMenuBar used with this
1491 * @param m The JMenuBar to use with this JInternalFrame.
1495 public void setMenuBar(JMenuBar m
)
1501 * This method sets the bounds that this JInternalFrame will be restored to.
1503 * @param r The bounds that this JInternalFrame will be restored to.
1505 public void setNormalBounds(Rectangle r
)
1507 storedBounds
.setBounds(r
.x
, r
.y
, r
.width
, r
.height
);
1511 * This method sets whether the JInternalFrame can be resized by a user
1512 * action (like dragging at the frame borders).
1514 * @param b Whether this JInternalFramer can be resized.
1516 public void setResizable(boolean b
)
1522 * This method sets the Root Pane for this JInternalFrame.
1524 * @param root The Root Pane for this JInternalFrame.
1526 protected void setRootPane(JRootPane root
)
1528 if (rootPane
!= null)
1536 * This method sets whether root pane checking is enabled. If root pane
1537 * checking is enabled, then calls to addImpl and setLayout will throw
1540 * @param enabled Whether root pane checking is enabled.
1542 protected void setRootPaneCheckingEnabled(boolean enabled
)
1544 rootPaneCheckingEnabled
= enabled
;
1548 * This method sets whether this JInternalFrame is the selected frame in the
1549 * JDesktopPane (or other container). When selected, a JInternalFrame will
1550 * have focus and paint its TitlePane differently (usually a different
1551 * colour). If this method selects the frame, this JInternalFrame will fire
1552 * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1553 * fire an INTERNAL_FRAME_DEACTIVATED event.
1555 * @param selected Whether this JInternalFrame will become selected or
1558 * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1560 public void setSelected(boolean selected
) throws PropertyVetoException
1562 if (selected
!= isSelected())
1564 fireVetoableChange(IS_SELECTED_PROPERTY
, selected
, isSelected
);
1567 defaultFocus
= getMostRecentFocusOwner();
1569 isSelected
= selected
;
1572 restoreSubcomponentFocus();
1574 firePropertyChange(IS_SELECTED_PROPERTY
, ! isSelected
, isSelected
);
1577 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_ACTIVATED
);
1579 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_DEACTIVATED
);
1584 * This method sets the title displayed in the TitlePane of this
1587 * @param title The title displayed.
1589 public void setTitle(String title
)
1591 if (title
== null && this.title
== null)
1593 if (title
== null || this.title
== null || ! this.title
.equals(title
))
1597 firePropertyChange(TITLE_PROPERTY
, old
, this.title
);
1602 * This method displays the JInternalFrame. If it is not visible, this
1603 * method will bring this JInternalFrame to the front, make it visible and
1604 * select it. If this is the first time this JInternalFrame is made
1605 * visible, an INTERNAL_FRAME_OPENED event will be fired.
1614 JDesktopPane pane
= getDesktopPane();
1616 pane
.setSelectedFrame(this);
1623 catch (PropertyVetoException e
)
1625 // Do nothing. if they don't want to be selected.
1628 if (isFirstTimeVisible
)
1630 isFirstTimeVisible
= false;
1631 fireInternalFrameEvent(InternalFrameEvent
.INTERNAL_FRAME_OPENED
);
1637 * This method is used to set the UI responsible for the JInternalFrame.
1639 * @param ui The UI responsible for the JInternalFrame.
1641 public void setUI(InternalFrameUI ui
)
1647 * This method causes the JInternalFrame to be brough to back in the
1650 public void toBack()
1656 * This method causes the JInternalFrame to be brought to front in the
1659 public void toFront()
1665 * This method resets the UI to the Look and Feel defaults.
1667 public void updateUI()
1669 setUI((InternalFrameUI
) UIManager
.getUI(this));
1673 * This helper method allows JInternalFrames to signal that they were
1674 * iconned for the first time.
1676 * @param b Whether the JInternalFrame was iconned.
1677 * @param ID The identifier of the property change event to fire if the
1678 * JInternalFrame is iconned for the first time.
1680 void setWasIcon(boolean b
, String ID
)
1685 firePropertyChange(ID
, ! b
, b
);
1690 * This helper method returns whether the JInternalFrame has been iconned
1693 * @return Whether the JInternalFrame has been iconned once already.
1695 boolean getWasIcon()
1701 * This method is a convenience method to fire vetoable property changes.
1703 * @param name The identifier of the property change.
1704 * @param oldValue The old value.
1705 * @param newValue The new value.
1707 * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1710 private void fireVetoableChange(String name
, boolean oldValue
,
1712 throws PropertyVetoException
1714 super.fireVetoableChange(name
, Boolean
.valueOf(oldValue
), Boolean
.valueOf(newValue
));