History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/javax/swing/plaf/basic/BasicInternalFrameUI.java (1 of 18352 files). Show all

Unified · Split

java/pkg/javax/swing/plaf/basic/BasicInternalFrameUI.java+1457−0
@@ -0,0 +1,1457 @@
1+/*
2+ * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package javax.swing.plaf.basic;
27+
28+import java.awt.*;
29+import java.awt.event.*;
30+import javax.swing.*;
31+import javax.swing.plaf.*;
32+import javax.swing.event.*;
33+import java.beans.*;
34+import sun.swing.DefaultLookup;
35+import sun.swing.UIAction;
36+
37+/**
38+ * A basic L&F implementation of JInternalFrame.
39+ *
40+ * @author David Kloba
41+ * @author Rich Schiavi
42+ */
43+public class BasicInternalFrameUI extends InternalFrameUI
44+{
45+
46+ protected JInternalFrame frame;
47+
48+ private Handler handler;
49+ protected MouseInputAdapter borderListener;
50+ protected PropertyChangeListener propertyChangeListener;
51+ protected LayoutManager internalFrameLayout;
52+ protected ComponentListener componentListener;
53+ protected MouseInputListener glassPaneDispatcher;
54+ private InternalFrameListener internalFrameListener;
55+
56+ protected JComponent northPane;
57+ protected JComponent southPane;
58+ protected JComponent westPane;
59+ protected JComponent eastPane;
60+
61+ protected BasicInternalFrameTitlePane titlePane; // access needs this
62+
63+ private static DesktopManager sharedDesktopManager;
64+ private boolean componentListenerAdded = false;
65+
66+ private Rectangle parentBounds;
67+
68+ private boolean dragging = false;
69+ private boolean resizing = false;
70+
71+ /**
72+ * As of Java 2 platform v1.3 this previously undocumented field is no
73+ * longer used.
74+ * Key bindings are now defined by the LookAndFeel, please refer to
75+ * the key bindings specification for further details.
76+ *
77+ * @deprecated As of Java 2 platform v1.3.
78+ */
79+ @Deprecated
80+ protected KeyStroke openMenuKey;
81+
82+ private boolean keyBindingRegistered = false;
83+ private boolean keyBindingActive = false;
84+
85+/////////////////////////////////////////////////////////////////////////////
86+// ComponentUI Interface Implementation methods
87+/////////////////////////////////////////////////////////////////////////////
88+ public static ComponentUI createUI(JComponent b) {
89+ return new BasicInternalFrameUI((JInternalFrame)b);
90+ }
91+
92+ public BasicInternalFrameUI(JInternalFrame b) {
93+ LookAndFeel laf = UIManager.getLookAndFeel();
94+ if (laf instanceof BasicLookAndFeel) {
95+ ((BasicLookAndFeel)laf).installAWTEventListener();
96+ }
97+ }
98+
99+ public void installUI(JComponent c) {
100+
101+ frame = (JInternalFrame)c;
102+
103+ installDefaults();
104+ installListeners();
105+ installComponents();
106+ installKeyboardActions();
107+
108+ LookAndFeel.installProperty(frame, "opaque", Boolean.TRUE);
109+ }
110+
111+ public void uninstallUI(JComponent c) {
112+ if(c != frame)
113+ throw new IllegalComponentStateException(
114+ this + " was asked to deinstall() "
115+ + c + " when it only knows about "
116+ + frame + ".");
117+
118+ uninstallKeyboardActions();
119+ uninstallComponents();
120+ uninstallListeners();
121+ uninstallDefaults();
122+ updateFrameCursor();
123+ handler = null;
124+ frame = null;
125+ }
126+
127+ protected void installDefaults(){
128+ Icon frameIcon = frame.getFrameIcon();
129+ if (frameIcon == null || frameIcon instanceof UIResource) {
130+ frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
131+ }
132+
133+ // Enable the content pane to inherit background color from its
134+ // parent by setting its background color to null.
135+ Container contentPane = frame.getContentPane();
136+ if (contentPane != null) {
137+ Color bg = contentPane.getBackground();
138+ if (bg instanceof UIResource)
139+ contentPane.setBackground(null);
140+ }
141+ frame.setLayout(internalFrameLayout = createLayoutManager());
142+ frame.setBackground(UIManager.getLookAndFeelDefaults().getColor("control"));
143+
144+ LookAndFeel.installBorder(frame, "InternalFrame.border");
145+
146+ }
147+ protected void installKeyboardActions(){
148+ createInternalFrameListener();
149+ if (internalFrameListener != null) {
150+ frame.addInternalFrameListener(internalFrameListener);
151+ }
152+
153+ LazyActionMap.installLazyActionMap(frame, BasicInternalFrameUI.class,
154+ "InternalFrame.actionMap");
155+ }
156+
157+ static void loadActionMap(LazyActionMap map) {
158+ map.put(new UIAction("showSystemMenu") {
159+ public void actionPerformed(ActionEvent evt) {
160+ JInternalFrame iFrame = (JInternalFrame)evt.getSource();
161+ if (iFrame.getUI() instanceof BasicInternalFrameUI) {
162+ JComponent comp = ((BasicInternalFrameUI)
163+ iFrame.getUI()).getNorthPane();
164+ if (comp instanceof BasicInternalFrameTitlePane) {
165+ ((BasicInternalFrameTitlePane)comp).
166+ showSystemMenu();
167+ }
168+ }
169+ }
170+
171+ public boolean isEnabled(Object sender){
172+ if (sender instanceof JInternalFrame) {
173+ JInternalFrame iFrame = (JInternalFrame)sender;
174+ if (iFrame.getUI() instanceof BasicInternalFrameUI) {
175+ return ((BasicInternalFrameUI)iFrame.getUI()).
176+ isKeyBindingActive();
177+ }
178+ }
179+ return false;
180+ }
181+ });
182+
183+ // Set the ActionMap's parent to the Auditory Feedback Action Map
184+ BasicLookAndFeel.installAudioActionMap(map);
185+ }
186+
187+ protected void installComponents(){
188+ setNorthPane(createNorthPane(frame));
189+ setSouthPane(createSouthPane(frame));
190+ setEastPane(createEastPane(frame));
191+ setWestPane(createWestPane(frame));
192+ }
193+
194+ /**
195+ * @since 1.3
196+ */
197+ protected void installListeners() {
198+ borderListener = createBorderListener(frame);
199+ propertyChangeListener = createPropertyChangeListener();
200+ frame.addPropertyChangeListener(propertyChangeListener);
201+ installMouseHandlers(frame);
202+ glassPaneDispatcher = createGlassPaneDispatcher();
203+ if (glassPaneDispatcher != null) {
204+ frame.getGlassPane().addMouseListener(glassPaneDispatcher);
205+ frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher);
206+ }
207+ componentListener = createComponentListener();
208+ if (frame.getParent() != null) {
209+ parentBounds = frame.getParent().getBounds();
210+ }
211+ if ((frame.getParent() != null) && !componentListenerAdded) {
212+ frame.getParent().addComponentListener(componentListener);
213+ componentListenerAdded = true;
214+ }
215+ }
216+
217+ // Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event,
218+ // so that a resize can be cancelled if the focus is lost while resizing
219+ // when an Alt-Tab, modal dialog popup, iconify, dispose, or remove
220+ // of the internal frame occurs.
221+ private WindowFocusListener getWindowFocusListener(){
222+ return getHandler();
223+ }
224+
225+ // Cancel a resize in progress by calling finishMouseReleased().
226+ private void cancelResize() {
227+ if (resizing) {
228+ if (borderListener instanceof BorderListener) {
229+ ((BorderListener)borderListener).finishMouseReleased();
230+ }
231+ }
232+ }
233+
234+ private Handler getHandler() {
235+ if (handler == null) {
236+ handler = new Handler();
237+ }
238+ return handler;
239+ }
240+
241+ InputMap getInputMap(int condition) {
242+ if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
243+ return createInputMap(condition);
244+ }
245+ return null;
246+ }
247+
248+ InputMap createInputMap(int condition) {
249+ if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
250+ Object[] bindings = (Object[])DefaultLookup.get(
251+ frame, this, "InternalFrame.windowBindings");
252+
253+ if (bindings != null) {
254+ return LookAndFeel.makeComponentInputMap(frame, bindings);
255+ }
256+ }
257+ return null;
258+ }
259+
260+ protected void uninstallDefaults() {
261+ Icon frameIcon = frame.getFrameIcon();
262+ if (frameIcon instanceof UIResource) {
263+ frame.setFrameIcon(null);
264+ }
265+ internalFrameLayout = null;
266+ frame.setLayout(null);
267+ LookAndFeel.uninstallBorder(frame);
268+ }
269+
270+ protected void uninstallComponents(){
271+ setNorthPane(null);
272+ setSouthPane(null);
273+ setEastPane(null);
274+ setWestPane(null);
275+ if(titlePane != null) {
276+ titlePane.uninstallDefaults();
277+ }
278+ titlePane = null;
279+ }
280+
281+ /**
282+ * @since 1.3
283+ */
284+ protected void uninstallListeners() {
285+ if ((frame.getParent() != null) && componentListenerAdded) {
286+ frame.getParent().removeComponentListener(componentListener);
287+ componentListenerAdded = false;
288+ }
289+ componentListener = null;
290+ if (glassPaneDispatcher != null) {
291+ frame.getGlassPane().removeMouseListener(glassPaneDispatcher);
292+ frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
293+ glassPaneDispatcher = null;
294+ }
295+ deinstallMouseHandlers(frame);
296+ frame.removePropertyChangeListener(propertyChangeListener);
297+ propertyChangeListener = null;
298+ borderListener = null;
299+ }
300+
301+ protected void uninstallKeyboardActions(){
302+ if (internalFrameListener != null) {
303+ frame.removeInternalFrameListener(internalFrameListener);
304+ }
305+ internalFrameListener = null;
306+
307+ SwingUtilities.replaceUIInputMap(frame, JComponent.
308+ WHEN_IN_FOCUSED_WINDOW, null);
309+ SwingUtilities.replaceUIActionMap(frame, null);
310+
311+ }
312+
313+ void updateFrameCursor() {
314+ if (resizing) {
315+ return;
316+ }
317+ Cursor s = frame.getLastCursor();
318+ if (s == null) {
319+ s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
320+ }
321+ frame.setCursor(s);
322+ }
323+
324+ protected LayoutManager createLayoutManager(){
325+ return getHandler();
326+ }
327+
328+ protected PropertyChangeListener createPropertyChangeListener(){
329+ return getHandler();
330+ }
331+
332+
333+
334+ public Dimension getPreferredSize(JComponent x) {
335+ if(frame == x)
336+ return frame.getLayout().preferredLayoutSize(x);
337+ return new Dimension(100, 100);
338+ }
339+
340+ public Dimension getMinimumSize(JComponent x) {
341+ if(frame == x) {
342+ return frame.getLayout().minimumLayoutSize(x);
343+ }
344+ return new Dimension(0, 0);
345+ }
346+
347+ public Dimension getMaximumSize(JComponent x) {
348+ return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
349+ }
350+
351+
352+
353+ /**
354+ * Installs necessary mouse handlers on <code>newPane</code>
355+ * and adds it to the frame.
356+ * Reverse process for the <code>currentPane</code>.
357+ */
358+ protected void replacePane(JComponent currentPane, JComponent newPane) {
359+ if(currentPane != null) {
360+ deinstallMouseHandlers(currentPane);
361+ frame.remove(currentPane);
362+ }
363+ if(newPane != null) {
364+ frame.add(newPane);
365+ installMouseHandlers(newPane);
366+ }
367+ }
368+
369+ protected void deinstallMouseHandlers(JComponent c) {
370+ c.removeMouseListener(borderListener);
371+ c.removeMouseMotionListener(borderListener);
372+ }
373+
374+ protected void installMouseHandlers(JComponent c) {
375+ c.addMouseListener(borderListener);
376+ c.addMouseMotionListener(borderListener);
377+ }
378+
379+ protected JComponent createNorthPane(JInternalFrame w) {
380+ titlePane = new BasicInternalFrameTitlePane(w);
381+ return titlePane;
382+ }
383+
384+
385+ protected JComponent createSouthPane(JInternalFrame w) {
386+ return null;
387+ }
388+
389+ protected JComponent createWestPane(JInternalFrame w) {
390+ return null;
391+ }
392+
393+ protected JComponent createEastPane(JInternalFrame w) {
394+ return null;
395+ }
396+
397+
398+ protected MouseInputAdapter createBorderListener(JInternalFrame w) {
399+ return new BorderListener();
400+ }
401+
402+ protected void createInternalFrameListener(){
403+ internalFrameListener = getHandler();
404+ }
405+
406+ protected final boolean isKeyBindingRegistered(){
407+ return keyBindingRegistered;
408+ }
409+
410+ protected final void setKeyBindingRegistered(boolean b){
411+ keyBindingRegistered = b;
412+ }
413+
414+ public final boolean isKeyBindingActive(){
415+ return keyBindingActive;
416+ }
417+
418+ protected final void setKeyBindingActive(boolean b){
419+ keyBindingActive = b;
420+ }
421+
422+
423+ protected void setupMenuOpenKey(){
424+ // PENDING(hania): Why are these WHEN_IN_FOCUSED_WINDOWs? Shouldn't
425+ // they be WHEN_ANCESTOR_OF_FOCUSED_COMPONENT?
426+ // Also, no longer registering on the desktopicon, the previous
427+ // action did nothing.
428+ InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
429+ SwingUtilities.replaceUIInputMap(frame,
430+ JComponent.WHEN_IN_FOCUSED_WINDOW, map);
431+ //ActionMap actionMap = getActionMap();
432+ //SwingUtilities.replaceUIActionMap(frame, actionMap);
433+ }
434+
435+ protected void setupMenuCloseKey(){
436+ }
437+
438+ public JComponent getNorthPane() {
439+ return northPane;
440+ }
441+
442+ public void setNorthPane(JComponent c) {
443+ if (northPane != null &&
444+ northPane instanceof BasicInternalFrameTitlePane) {
445+ ((BasicInternalFrameTitlePane)northPane).uninstallListeners();
446+ }
447+ replacePane(northPane, c);
448+ northPane = c;
449+ if (c instanceof BasicInternalFrameTitlePane) {
450+ titlePane = (BasicInternalFrameTitlePane)c;
451+ }
452+ }
453+
454+ public JComponent getSouthPane() {
455+ return southPane;
456+ }
457+
458+ public void setSouthPane(JComponent c) {
459+ southPane = c;
460+ }
461+
462+ public JComponent getWestPane() {
463+ return westPane;
464+ }
465+
466+ public void setWestPane(JComponent c) {
467+ westPane = c;
468+ }
469+
470+ public JComponent getEastPane() {
471+ return eastPane;
472+ }
473+
474+ public void setEastPane(JComponent c) {
475+ eastPane = c;
476+ }
477+
478+ public class InternalFramePropertyChangeListener implements
479+ PropertyChangeListener {
480+ // NOTE: This class exists only for backward compatability. All
481+ // its functionality has been moved into Handler. If you need to add
482+ // new functionality add it to the Handler, but make sure this
483+ // class calls into the Handler.
484+ /**
485+ * Detects changes in state from the JInternalFrame and handles
486+ * actions.
487+ */
488+ public void propertyChange(PropertyChangeEvent evt) {
489+ getHandler().propertyChange(evt);
490+ }
491+ }
492+
493+ public class InternalFrameLayout implements LayoutManager {
494+ // NOTE: This class exists only for backward compatability. All
495+ // its functionality has been moved into Handler. If you need to add
496+ // new functionality add it to the Handler, but make sure this
497+ // class calls into the Handler.
498+ public void addLayoutComponent(String name, Component c) {
499+ getHandler().addLayoutComponent(name, c);
500+ }
501+
502+ public void removeLayoutComponent(Component c) {
503+ getHandler().removeLayoutComponent(c);
504+ }
505+
506+ public Dimension preferredLayoutSize(Container c) {
507+ return getHandler().preferredLayoutSize(c);
508+ }
509+
510+ public Dimension minimumLayoutSize(Container c) {
511+ return getHandler().minimumLayoutSize(c);
512+ }
513+
514+ public void layoutContainer(Container c) {
515+ getHandler().layoutContainer(c);
516+ }
517+ }
518+
519+/// DesktopManager methods
520+ /** Returns the proper DesktopManager. Calls getDesktopPane() to
521+ * find the JDesktop component and returns the desktopManager from
522+ * it. If this fails, it will return a default DesktopManager that
523+ * should work in arbitrary parents.
524+ */
525+ protected DesktopManager getDesktopManager() {
526+ if(frame.getDesktopPane() != null
527+ && frame.getDesktopPane().getDesktopManager() != null)
528+ return frame.getDesktopPane().getDesktopManager();
529+ if(sharedDesktopManager == null)
530+ sharedDesktopManager = createDesktopManager();
531+ return sharedDesktopManager;
532+ }
533+
534+ protected DesktopManager createDesktopManager(){
535+ return new DefaultDesktopManager();
536+ }
537+
538+ /**
539+ * This method is called when the user wants to close the frame.
540+ * The <code>playCloseSound</code> Action is fired.
541+ * This action is delegated to the desktopManager.
542+ */
543+ protected void closeFrame(JInternalFrame f) {
544+ // Internal Frame Auditory Cue Activation
545+ BasicLookAndFeel.playSound(frame,"InternalFrame.closeSound");
546+ // delegate to desktop manager
547+ getDesktopManager().closeFrame(f);
548+ }
549+
550+ /**
551+ * This method is called when the user wants to maximize the frame.
552+ * The <code>playMaximizeSound</code> Action is fired.
553+ * This action is delegated to the desktopManager.
554+ */
555+ protected void maximizeFrame(JInternalFrame f) {
556+ // Internal Frame Auditory Cue Activation
557+ BasicLookAndFeel.playSound(frame,"InternalFrame.maximizeSound");
558+ // delegate to desktop manager
559+ getDesktopManager().maximizeFrame(f);
560+ }
561+
562+ /**
563+ * This method is called when the user wants to minimize the frame.
564+ * The <code>playRestoreDownSound</code> Action is fired.
565+ * This action is delegated to the desktopManager.
566+ */
567+ protected void minimizeFrame(JInternalFrame f) {
568+ // Internal Frame Auditory Cue Activation
569+ if ( ! f.isIcon() ) {
570+ // This method seems to regularly get called after an
571+ // internal frame is iconified. Don't play this sound then.
572+ BasicLookAndFeel.playSound(frame,"InternalFrame.restoreDownSound");
573+ }
574+ // delegate to desktop manager
575+ getDesktopManager().minimizeFrame(f);
576+ }
577+
578+ /**
579+ * This method is called when the user wants to iconify the frame.
580+ * The <code>playMinimizeSound</code> Action is fired.
581+ * This action is delegated to the desktopManager.
582+ */
583+ protected void iconifyFrame(JInternalFrame f) {
584+ // Internal Frame Auditory Cue Activation
585+ BasicLookAndFeel.playSound(frame, "InternalFrame.minimizeSound");
586+ // delegate to desktop manager
587+ getDesktopManager().iconifyFrame(f);
588+ }
589+
590+ /**
591+ * This method is called when the user wants to deiconify the frame.
592+ * The <code>playRestoreUpSound</code> Action is fired.
593+ * This action is delegated to the desktopManager.
594+ */
595+ protected void deiconifyFrame(JInternalFrame f) {
596+ // Internal Frame Auditory Cue Activation
597+ if ( ! f.isMaximum() ) {
598+ // This method seems to regularly get called after an
599+ // internal frame is maximized. Don't play this sound then.
600+ BasicLookAndFeel.playSound(frame, "InternalFrame.restoreUpSound");
601+ }
602+ // delegate to desktop manager
603+ getDesktopManager().deiconifyFrame(f);
604+ }
605+
606+ /** This method is called when the frame becomes selected.
607+ * This action is delegated to the desktopManager.
608+ */
609+ protected void activateFrame(JInternalFrame f) {
610+ getDesktopManager().activateFrame(f);
611+ }
612+ /** This method is called when the frame is no longer selected.
613+ * This action is delegated to the desktopManager.
614+ */
615+ protected void deactivateFrame(JInternalFrame f) {
616+ getDesktopManager().deactivateFrame(f);
617+ }
618+
619+ /////////////////////////////////////////////////////////////////////////
620+ /// Border Listener Class
621+ /////////////////////////////////////////////////////////////////////////
622+ /**
623+ * Listens for border adjustments.
624+ */
625+ protected class BorderListener extends MouseInputAdapter implements SwingConstants
626+ {
627+ // _x & _y are the mousePressed location in absolute coordinate system
628+ int _x, _y;
629+ // __x & __y are the mousePressed location in source view's coordinate system
630+ int __x, __y;
631+ Rectangle startingBounds;
632+ int resizeDir;
633+
634+
635+ protected final int RESIZE_NONE = 0;
636+ private boolean discardRelease = false;
637+
638+ int resizeCornerSize = 16;
639+
640+ public void mouseClicked(MouseEvent e) {
641+ if(e.getClickCount() > 1 && e.getSource() == getNorthPane()) {
642+ if(frame.isIconifiable() && frame.isIcon()) {
643+ try { frame.setIcon(false); } catch (PropertyVetoException e2) { }
644+ } else if(frame.isMaximizable()) {
645+ if(!frame.isMaximum())
646+ try { frame.setMaximum(true); } catch (PropertyVetoException e2) { }
647+ else
648+ try { frame.setMaximum(false); } catch (PropertyVetoException e3) { }
649+ }
650+ }
651+ }
652+
653+ // Factor out finishMouseReleased() from mouseReleased(), so that
654+ // it can be called by cancelResize() without passing it a null
655+ // MouseEvent.
656+ void finishMouseReleased() {
657+ if (discardRelease) {
658+ discardRelease = false;
659+ return;
660+ }
661+ if (resizeDir == RESIZE_NONE) {
662+ getDesktopManager().endDraggingFrame(frame);
663+ dragging = false;
664+ } else {
665+ // Remove the WindowFocusListener for handling a
666+ // WINDOW_LOST_FOCUS event with a cancelResize().
667+ Window windowAncestor =
668+ SwingUtilities.getWindowAncestor(frame);
669+ if (windowAncestor != null) {
670+ windowAncestor.removeWindowFocusListener(
671+ getWindowFocusListener());
672+ }
673+ Container c = frame.getTopLevelAncestor();
674+ if (c instanceof RootPaneContainer) {
675+ Component glassPane = ((RootPaneContainer)c).getGlassPane();
676+ glassPane.setCursor(Cursor.getPredefinedCursor(
677+ Cursor.DEFAULT_CURSOR));
678+ glassPane.setVisible(false);
679+ }
680+ getDesktopManager().endResizingFrame(frame);
681+ resizing = false;
682+ updateFrameCursor();
683+ }
684+ _x = 0;
685+ _y = 0;
686+ __x = 0;
687+ __y = 0;
688+ startingBounds = null;
689+ resizeDir = RESIZE_NONE;
690+ // Set discardRelease to true, so that only a mousePressed()
691+ // which sets it to false, will allow entry to the above code
692+ // for finishing a resize.
693+ discardRelease = true;
694+ }
695+
696+ public void mouseReleased(MouseEvent e) {
697+ finishMouseReleased();
698+ }
699+
700+ public void mousePressed(MouseEvent e) {
701+ Point p = SwingUtilities.convertPoint((Component)e.getSource(),
702+ e.getX(), e.getY(), null);
703+ __x = e.getX();
704+ __y = e.getY();
705+ _x = p.x;
706+ _y = p.y;
707+ startingBounds = frame.getBounds();
708+ resizeDir = RESIZE_NONE;
709+ discardRelease = false;
710+
711+ try { frame.setSelected(true); }
712+ catch (PropertyVetoException e1) { }
713+
714+ Insets i = frame.getInsets();
715+
716+ Point ep = new Point(__x, __y);
717+ if (e.getSource() == getNorthPane()) {
718+ Point np = getNorthPane().getLocation();
719+ ep.x += np.x;
720+ ep.y += np.y;
721+ }
722+
723+ if (e.getSource() == getNorthPane()) {
724+ if (ep.x > i.left && ep.y > i.top && ep.x < frame.getWidth() - i.right) {
725+ getDesktopManager().beginDraggingFrame(frame);
726+ dragging = true;
727+ return;
728+ }
729+ }
730+ if (!frame.isResizable()) {
731+ return;
732+ }
733+
734+ if (e.getSource() == frame || e.getSource() == getNorthPane()) {
735+ if (ep.x <= i.left) {
736+ if (ep.y < resizeCornerSize + i.top) {
737+ resizeDir = NORTH_WEST;
738+ } else if (ep.y > frame.getHeight()
739+ - resizeCornerSize - i.bottom) {
740+ resizeDir = SOUTH_WEST;
741+ } else {
742+ resizeDir = WEST;
743+}
744+ } else if (ep.x >= frame.getWidth() - i.right) {
745+ if (ep.y < resizeCornerSize + i.top) {
746+ resizeDir = NORTH_EAST;
747+ } else if (ep.y > frame.getHeight()
748+ - resizeCornerSize - i.bottom) {
749+ resizeDir = SOUTH_EAST;
750+ } else {
751+ resizeDir = EAST;
752+ }
753+ } else if (ep.y <= i.top) {
754+ if (ep.x < resizeCornerSize + i.left) {
755+ resizeDir = NORTH_WEST;
756+ } else if (ep.x > frame.getWidth()
757+ - resizeCornerSize - i.right) {
758+ resizeDir = NORTH_EAST;
759+ } else {
760+ resizeDir = NORTH;
761+ }
762+ } else if (ep.y >= frame.getHeight() - i.bottom) {
763+ if (ep.x < resizeCornerSize + i.left) {
764+ resizeDir = SOUTH_WEST;
765+ } else if (ep.x > frame.getWidth()
766+ - resizeCornerSize - i.right) {
767+ resizeDir = SOUTH_EAST;
768+ } else {
769+ resizeDir = SOUTH;
770+ }
771+ } else {
772+ /* the mouse press happened inside the frame, not in the
773+ border */
774+ discardRelease = true;
775+ return;
776+ }
777+ Cursor s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
778+ switch (resizeDir) {
779+ case SOUTH:
780+ s = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
781+ break;
782+ case NORTH:
783+ s = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
784+ break;
785+ case WEST:
786+ s = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
787+ break;
788+ case EAST:
789+ s = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
790+ break;
791+ case SOUTH_EAST:
792+ s = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
793+ break;
794+ case SOUTH_WEST:
795+ s = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
796+ break;
797+ case NORTH_WEST:
798+ s = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
799+ break;
800+ case NORTH_EAST:
801+ s = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
802+ break;
803+ }
804+ Container c = frame.getTopLevelAncestor();
805+ if (c instanceof RootPaneContainer) {
806+ Component glassPane = ((RootPaneContainer)c).getGlassPane();
807+ glassPane.setVisible(true);
808+ glassPane.setCursor(s);
809+ }
810+ getDesktopManager().beginResizingFrame(frame, resizeDir);
811+ resizing = true;
812+ // Add the WindowFocusListener for handling a
813+ // WINDOW_LOST_FOCUS event with a cancelResize().
814+ Window windowAncestor = SwingUtilities.getWindowAncestor(frame);
815+ if (windowAncestor != null) {
816+ windowAncestor.addWindowFocusListener(
817+ getWindowFocusListener());
818+ }
819+ return;
820+ }
821+ }
822+
823+ public void mouseDragged(MouseEvent e) {
824+
825+ if ( startingBounds == null ) {
826+ // (STEVE) Yucky work around for bug ID 4106552
827+ return;
828+ }
829+
830+ Point p = SwingUtilities.convertPoint((Component)e.getSource(),
831+ e.getX(), e.getY(), null);
832+ int deltaX = _x - p.x;
833+ int deltaY = _y - p.y;
834+ Dimension min = frame.getMinimumSize();
835+ Dimension max = frame.getMaximumSize();
836+ int newX, newY, newW, newH;
837+ Insets i = frame.getInsets();
838+
839+ // Handle a MOVE
840+ if (dragging) {
841+ if (frame.isMaximum() || ((e.getModifiers() &
842+ InputEvent.BUTTON1_MASK) !=
843+ InputEvent.BUTTON1_MASK)) {
844+ // don't allow moving of frames if maximixed or left mouse
845+ // button was not used.
846+ return;
847+ }
848+ int pWidth, pHeight;
849+ Dimension s = frame.getParent().getSize();
850+ pWidth = s.width;
851+ pHeight = s.height;
852+
853+
854+ newX = startingBounds.x - deltaX;
855+ newY = startingBounds.y - deltaY;
856+
857+ // Make sure we stay in-bounds
858+ if(newX + i.left <= -__x)
859+ newX = -__x - i.left + 1;
860+ if(newY + i.top <= -__y)
861+ newY = -__y - i.top + 1;
862+ if(newX + __x + i.right >= pWidth)
863+ newX = pWidth - __x - i.right - 1;
864+ if(newY + __y + i.bottom >= pHeight)
865+ newY = pHeight - __y - i.bottom - 1;
866+
867+ getDesktopManager().dragFrame(frame, newX, newY);
868+ return;
869+ }
870+
871+ if(!frame.isResizable()) {
872+ return;
873+ }
874+
875+ newX = frame.getX();
876+ newY = frame.getY();
877+ newW = frame.getWidth();
878+ newH = frame.getHeight();
879+
880+ parentBounds = frame.getParent().getBounds();
881+
882+ switch(resizeDir) {
883+ case RESIZE_NONE:
884+ return;
885+ case NORTH:
886+ if(startingBounds.height + deltaY < min.height)
887+ deltaY = -(startingBounds.height - min.height);
888+ else if(startingBounds.height + deltaY > max.height)
889+ deltaY = max.height - startingBounds.height;
890+ if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
891+
892+ newX = startingBounds.x;
893+ newY = startingBounds.y - deltaY;
894+ newW = startingBounds.width;
895+ newH = startingBounds.height + deltaY;
896+ break;
897+ case NORTH_EAST:
898+ if(startingBounds.height + deltaY < min.height)
899+ deltaY = -(startingBounds.height - min.height);
900+ else if(startingBounds.height + deltaY > max.height)
901+ deltaY = max.height - startingBounds.height;
902+ if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
903+
904+ if(startingBounds.width - deltaX < min.width)
905+ deltaX = startingBounds.width - min.width;
906+ else if(startingBounds.width - deltaX > max.width)
907+ deltaX = -(max.width - startingBounds.width);
908+ if (startingBounds.x + startingBounds.width - deltaX >
909+ parentBounds.width) {
910+ deltaX = startingBounds.x + startingBounds.width -
911+ parentBounds.width;
912+ }
913+
914+ newX = startingBounds.x;
915+ newY = startingBounds.y - deltaY;
916+ newW = startingBounds.width - deltaX;
917+ newH = startingBounds.height + deltaY;
918+ break;
919+ case EAST:
920+ if(startingBounds.width - deltaX < min.width)
921+ deltaX = startingBounds.width - min.width;
922+ else if(startingBounds.width - deltaX > max.width)
923+ deltaX = -(max.width - startingBounds.width);
924+ if (startingBounds.x + startingBounds.width - deltaX >
925+ parentBounds.width) {
926+ deltaX = startingBounds.x + startingBounds.width -
927+ parentBounds.width;
928+ }
929+
930+ newW = startingBounds.width - deltaX;
931+ newH = startingBounds.height;
932+ break;
933+ case SOUTH_EAST:
934+ if(startingBounds.width - deltaX < min.width)
935+ deltaX = startingBounds.width - min.width;
936+ else if(startingBounds.width - deltaX > max.width)
937+ deltaX = -(max.width - startingBounds.width);
938+ if (startingBounds.x + startingBounds.width - deltaX >
939+ parentBounds.width) {
940+ deltaX = startingBounds.x + startingBounds.width -
941+ parentBounds.width;
942+ }
943+
944+ if(startingBounds.height - deltaY < min.height)
945+ deltaY = startingBounds.height - min.height;
946+ else if(startingBounds.height - deltaY > max.height)
947+ deltaY = -(max.height - startingBounds.height);
948+ if (startingBounds.y + startingBounds.height - deltaY >
949+ parentBounds.height) {
950+ deltaY = startingBounds.y + startingBounds.height -
951+ parentBounds.height ;
952+ }
953+
954+ newW = startingBounds.width - deltaX;
955+ newH = startingBounds.height - deltaY;
956+ break;
957+ case SOUTH:
958+ if(startingBounds.height - deltaY < min.height)
959+ deltaY = startingBounds.height - min.height;
960+ else if(startingBounds.height - deltaY > max.height)
961+ deltaY = -(max.height - startingBounds.height);
962+ if (startingBounds.y + startingBounds.height - deltaY >
963+ parentBounds.height) {
964+ deltaY = startingBounds.y + startingBounds.height -
965+ parentBounds.height ;
966+ }
967+
968+ newW = startingBounds.width;
969+ newH = startingBounds.height - deltaY;
970+ break;
971+ case SOUTH_WEST:
972+ if(startingBounds.height - deltaY < min.height)
973+ deltaY = startingBounds.height - min.height;
974+ else if(startingBounds.height - deltaY > max.height)
975+ deltaY = -(max.height - startingBounds.height);
976+ if (startingBounds.y + startingBounds.height - deltaY >
977+ parentBounds.height) {
978+ deltaY = startingBounds.y + startingBounds.height -
979+ parentBounds.height ;
980+ }
981+
982+ if(startingBounds.width + deltaX < min.width)
983+ deltaX = -(startingBounds.width - min.width);
984+ else if(startingBounds.width + deltaX > max.width)
985+ deltaX = max.width - startingBounds.width;
986+ if (startingBounds.x - deltaX < 0) {
987+ deltaX = startingBounds.x;
988+ }
989+
990+ newX = startingBounds.x - deltaX;
991+ newY = startingBounds.y;
992+ newW = startingBounds.width + deltaX;
993+ newH = startingBounds.height - deltaY;
994+ break;
995+ case WEST:
996+ if(startingBounds.width + deltaX < min.width)
997+ deltaX = -(startingBounds.width - min.width);
998+ else if(startingBounds.width + deltaX > max.width)
999+ deltaX = max.width - startingBounds.width;
1000+ if (startingBounds.x - deltaX < 0) {
1001+ deltaX = startingBounds.x;
1002+ }
1003+
1004+ newX = startingBounds.x - deltaX;
1005+ newY = startingBounds.y;
1006+ newW = startingBounds.width + deltaX;
1007+ newH = startingBounds.height;
1008+ break;
1009+ case NORTH_WEST:
1010+ if(startingBounds.width + deltaX < min.width)
1011+ deltaX = -(startingBounds.width - min.width);
1012+ else if(startingBounds.width + deltaX > max.width)
1013+ deltaX = max.width - startingBounds.width;
1014+ if (startingBounds.x - deltaX < 0) {
1015+ deltaX = startingBounds.x;
1016+ }
1017+
1018+ if(startingBounds.height + deltaY < min.height)
1019+ deltaY = -(startingBounds.height - min.height);
1020+ else if(startingBounds.height + deltaY > max.height)
1021+ deltaY = max.height - startingBounds.height;
1022+ if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
1023+
1024+ newX = startingBounds.x - deltaX;
1025+ newY = startingBounds.y - deltaY;
1026+ newW = startingBounds.width + deltaX;
1027+ newH = startingBounds.height + deltaY;
1028+ break;
1029+ default:
1030+ return;
1031+ }
1032+ getDesktopManager().resizeFrame(frame, newX, newY, newW, newH);
1033+ }
1034+
1035+ public void mouseMoved(MouseEvent e) {
1036+
1037+ if(!frame.isResizable())
1038+ return;
1039+
1040+ if (e.getSource() == frame || e.getSource() == getNorthPane()) {
1041+ Insets i = frame.getInsets();
1042+ Point ep = new Point(e.getX(), e.getY());
1043+ if (e.getSource() == getNorthPane()) {
1044+ Point np = getNorthPane().getLocation();
1045+ ep.x += np.x;
1046+ ep.y += np.y;
1047+ }
1048+ if(ep.x <= i.left) {
1049+ if(ep.y < resizeCornerSize + i.top)
1050+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
1051+ else if(ep.y > frame.getHeight() - resizeCornerSize - i.bottom)
1052+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
1053+ else
1054+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
1055+ } else if(ep.x >= frame.getWidth() - i.right) {
1056+ if(e.getY() < resizeCornerSize + i.top)
1057+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
1058+ else if(ep.y > frame.getHeight() - resizeCornerSize - i.bottom)
1059+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
1060+ else
1061+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
1062+ } else if(ep.y <= i.top) {
1063+ if(ep.x < resizeCornerSize + i.left)
1064+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
1065+ else if(ep.x > frame.getWidth() - resizeCornerSize - i.right)
1066+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
1067+ else
1068+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
1069+ } else if(ep.y >= frame.getHeight() - i.bottom) {
1070+ if(ep.x < resizeCornerSize + i.left)
1071+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
1072+ else if(ep.x > frame.getWidth() - resizeCornerSize - i.right)
1073+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
1074+ else
1075+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
1076+ }
1077+ else
1078+ updateFrameCursor();
1079+ return;
1080+ }
1081+
1082+ updateFrameCursor();
1083+ }
1084+
1085+ public void mouseEntered(MouseEvent e) {
1086+ updateFrameCursor();
1087+ }
1088+
1089+ public void mouseExited(MouseEvent e) {
1090+ updateFrameCursor();
1091+ }
1092+
1093+ } /// End BorderListener Class
1094+
1095+ protected class ComponentHandler implements ComponentListener {
1096+ // NOTE: This class exists only for backward compatability. All
1097+ // its functionality has been moved into Handler. If you need to add
1098+ // new functionality add it to the Handler, but make sure this
1099+ // class calls into the Handler.
1100+ /** Invoked when a JInternalFrame's parent's size changes. */
1101+ public void componentResized(ComponentEvent e) {
1102+ getHandler().componentResized(e);
1103+ }
1104+
1105+ public void componentMoved(ComponentEvent e) {
1106+ getHandler().componentMoved(e);
1107+ }
1108+ public void componentShown(ComponentEvent e) {
1109+ getHandler().componentShown(e);
1110+ }
1111+ public void componentHidden(ComponentEvent e) {
1112+ getHandler().componentHidden(e);
1113+ }
1114+ }
1115+
1116+ protected ComponentListener createComponentListener() {
1117+ return getHandler();
1118+ }
1119+
1120+
1121+ protected class GlassPaneDispatcher implements MouseInputListener {
1122+ // NOTE: This class exists only for backward compatability. All
1123+ // its functionality has been moved into Handler. If you need to add
1124+ // new functionality add it to the Handler, but make sure this
1125+ // class calls into the Handler.
1126+ public void mousePressed(MouseEvent e) {
1127+ getHandler().mousePressed(e);
1128+ }
1129+
1130+ public void mouseEntered(MouseEvent e) {
1131+ getHandler().mouseEntered(e);
1132+ }
1133+
1134+ public void mouseMoved(MouseEvent e) {
1135+ getHandler().mouseMoved(e);
1136+ }
1137+
1138+ public void mouseExited(MouseEvent e) {
1139+ getHandler().mouseExited(e);
1140+ }
1141+
1142+ public void mouseClicked(MouseEvent e) {
1143+ getHandler().mouseClicked(e);
1144+ }
1145+
1146+ public void mouseReleased(MouseEvent e) {
1147+ getHandler().mouseReleased(e);
1148+ }
1149+
1150+ public void mouseDragged(MouseEvent e) {
1151+ getHandler().mouseDragged(e);
1152+ }
1153+ }
1154+
1155+ protected MouseInputListener createGlassPaneDispatcher() {
1156+ return null;
1157+ }
1158+
1159+
1160+ protected class BasicInternalFrameListener implements InternalFrameListener
1161+ {
1162+ // NOTE: This class exists only for backward compatability. All
1163+ // its functionality has been moved into Handler. If you need to add
1164+ // new functionality add it to the Handler, but make sure this
1165+ // class calls into the Handler.
1166+ public void internalFrameClosing(InternalFrameEvent e) {
1167+ getHandler().internalFrameClosing(e);
1168+ }
1169+
1170+ public void internalFrameClosed(InternalFrameEvent e) {
1171+ getHandler().internalFrameClosed(e);
1172+ }
1173+
1174+ public void internalFrameOpened(InternalFrameEvent e) {
1175+ getHandler().internalFrameOpened(e);
1176+ }
1177+
1178+ public void internalFrameIconified(InternalFrameEvent e) {
1179+ getHandler().internalFrameIconified(e);
1180+ }
1181+
1182+ public void internalFrameDeiconified(InternalFrameEvent e) {
1183+ getHandler().internalFrameDeiconified(e);
1184+ }
1185+
1186+ public void internalFrameActivated(InternalFrameEvent e) {
1187+ getHandler().internalFrameActivated(e);
1188+ }
1189+
1190+
1191+ public void internalFrameDeactivated(InternalFrameEvent e) {
1192+ getHandler().internalFrameDeactivated(e);
1193+ }
1194+ }
1195+
1196+ private class Handler implements ComponentListener, InternalFrameListener,
1197+ LayoutManager, MouseInputListener, PropertyChangeListener,
1198+ WindowFocusListener, SwingConstants {
1199+
1200+ public void windowGainedFocus(WindowEvent e) {
1201+ }
1202+
1203+ public void windowLostFocus(WindowEvent e) {
1204+ // Cancel a resize which may be in progress, when a
1205+ // WINDOW_LOST_FOCUS event occurs, which may be
1206+ // caused by an Alt-Tab or a modal dialog popup.
1207+ cancelResize();
1208+ }
1209+
1210+ // ComponentHandler methods
1211+ /** Invoked when a JInternalFrame's parent's size changes. */
1212+ public void componentResized(ComponentEvent e) {
1213+ // Get the JInternalFrame's parent container size
1214+ Rectangle parentNewBounds = ((Component) e.getSource()).getBounds();
1215+ JInternalFrame.JDesktopIcon icon = null;
1216+
1217+ if (frame != null) {
1218+ icon = frame.getDesktopIcon();
1219+ // Resize the internal frame if it is maximized and relocate
1220+ // the associated icon as well.
1221+ if (frame.isMaximum()) {
1222+ frame.setBounds(0, 0, parentNewBounds.width,
1223+ parentNewBounds.height);
1224+ }
1225+ }
1226+
1227+ // Relocate the icon base on the new parent bounds.
1228+ if (icon != null) {
1229+ Rectangle iconBounds = icon.getBounds();
1230+ int y = iconBounds.y +
1231+ (parentNewBounds.height - parentBounds.height);
1232+ icon.setBounds(iconBounds.x, y,
1233+ iconBounds.width, iconBounds.height);
1234+ }
1235+
1236+ // Update the new parent bounds for next resize.
1237+ if (!parentBounds.equals(parentNewBounds)) {
1238+ parentBounds = parentNewBounds;
1239+ }
1240+
1241+ // Validate the component tree for this container.
1242+ if (frame != null) frame.validate();
1243+ }
1244+
1245+ public void componentMoved(ComponentEvent e) {}
1246+ public void componentShown(ComponentEvent e) {}
1247+ public void componentHidden(ComponentEvent e) {}
1248+
1249+
1250+ // InternalFrameListener
1251+ public void internalFrameClosed(InternalFrameEvent e) {
1252+ frame.removeInternalFrameListener(getHandler());
1253+ }
1254+
1255+ public void internalFrameActivated(InternalFrameEvent e) {
1256+ if (!isKeyBindingRegistered()){
1257+ setKeyBindingRegistered(true);
1258+ setupMenuOpenKey();
1259+ setupMenuCloseKey();
1260+ }
1261+ if (isKeyBindingRegistered())
1262+ setKeyBindingActive(true);
1263+ }
1264+
1265+ public void internalFrameDeactivated(InternalFrameEvent e) {
1266+ setKeyBindingActive(false);
1267+ }
1268+
1269+ public void internalFrameClosing(InternalFrameEvent e) { }
1270+ public void internalFrameOpened(InternalFrameEvent e) { }
1271+ public void internalFrameIconified(InternalFrameEvent e) { }
1272+ public void internalFrameDeiconified(InternalFrameEvent e) { }
1273+
1274+
1275+ // LayoutManager
1276+ public void addLayoutComponent(String name, Component c) {}
1277+ public void removeLayoutComponent(Component c) {}
1278+ public Dimension preferredLayoutSize(Container c) {
1279+ Dimension result;
1280+ Insets i = frame.getInsets();
1281+
1282+ result = new Dimension(frame.getRootPane().getPreferredSize());
1283+ result.width += i.left + i.right;
1284+ result.height += i.top + i.bottom;
1285+
1286+ if(getNorthPane() != null) {
1287+ Dimension d = getNorthPane().getPreferredSize();
1288+ result.width = Math.max(d.width, result.width);
1289+ result.height += d.height;
1290+ }
1291+
1292+ if(getSouthPane() != null) {
1293+ Dimension d = getSouthPane().getPreferredSize();
1294+ result.width = Math.max(d.width, result.width);
1295+ result.height += d.height;
1296+ }
1297+
1298+ if(getEastPane() != null) {
1299+ Dimension d = getEastPane().getPreferredSize();
1300+ result.width += d.width;
1301+ result.height = Math.max(d.height, result.height);
1302+ }
1303+
1304+ if(getWestPane() != null) {
1305+ Dimension d = getWestPane().getPreferredSize();
1306+ result.width += d.width;
1307+ result.height = Math.max(d.height, result.height);
1308+ }
1309+ return result;
1310+ }
1311+
1312+ public Dimension minimumLayoutSize(Container c) {
1313+ // The minimum size of the internal frame only takes into
1314+ // account the title pane since you are allowed to resize
1315+ // the frames to the point where just the title pane is visible.
1316+ Dimension result = new Dimension();
1317+ if (getNorthPane() != null &&
1318+ getNorthPane() instanceof BasicInternalFrameTitlePane) {
1319+ result = new Dimension(getNorthPane().getMinimumSize());
1320+ }
1321+ Insets i = frame.getInsets();
1322+ result.width += i.left + i.right;
1323+ result.height += i.top + i.bottom;
1324+
1325+ return result;
1326+ }
1327+
1328+ public void layoutContainer(Container c) {
1329+ Insets i = frame.getInsets();
1330+ int cx, cy, cw, ch;
1331+
1332+ cx = i.left;
1333+ cy = i.top;
1334+ cw = frame.getWidth() - i.left - i.right;
1335+ ch = frame.getHeight() - i.top - i.bottom;
1336+
1337+ if(getNorthPane() != null) {
1338+ Dimension size = getNorthPane().getPreferredSize();
1339+ if (DefaultLookup.getBoolean(frame, BasicInternalFrameUI.this,
1340+ "InternalFrame.layoutTitlePaneAtOrigin", false)) {
1341+ cy = 0;
1342+ ch += i.top;
1343+ getNorthPane().setBounds(0, 0, frame.getWidth(),
1344+ size.height);
1345+ }
1346+ else {
1347+ getNorthPane().setBounds(cx, cy, cw, size.height);
1348+ }
1349+ cy += size.height;
1350+ ch -= size.height;
1351+ }
1352+
1353+ if(getSouthPane() != null) {
1354+ Dimension size = getSouthPane().getPreferredSize();
1355+ getSouthPane().setBounds(cx, frame.getHeight()
1356+ - i.bottom - size.height,
1357+ cw, size.height);
1358+ ch -= size.height;
1359+ }
1360+
1361+ if(getWestPane() != null) {
1362+ Dimension size = getWestPane().getPreferredSize();
1363+ getWestPane().setBounds(cx, cy, size.width, ch);
1364+ cw -= size.width;
1365+ cx += size.width;
1366+ }
1367+
1368+ if(getEastPane() != null) {
1369+ Dimension size = getEastPane().getPreferredSize();
1370+ getEastPane().setBounds(cw - size.width, cy, size.width, ch);
1371+ cw -= size.width;
1372+ }
1373+
1374+ if(frame.getRootPane() != null) {
1375+ frame.getRootPane().setBounds(cx, cy, cw, ch);
1376+ }
1377+ }
1378+
1379+
1380+ // MouseInputListener
1381+ public void mousePressed(MouseEvent e) { }
1382+
1383+ public void mouseEntered(MouseEvent e) { }
1384+
1385+ public void mouseMoved(MouseEvent e) { }
1386+
1387+ public void mouseExited(MouseEvent e) { }
1388+
1389+ public void mouseClicked(MouseEvent e) { }
1390+
1391+ public void mouseReleased(MouseEvent e) { }
1392+
1393+ public void mouseDragged(MouseEvent e) { }
1394+
1395+ // PropertyChangeListener
1396+ public void propertyChange(PropertyChangeEvent evt) {
1397+ String prop = evt.getPropertyName();
1398+ JInternalFrame f = (JInternalFrame)evt.getSource();
1399+ Object newValue = evt.getNewValue();
1400+ Object oldValue = evt.getOldValue();
1401+
1402+ if (JInternalFrame.IS_CLOSED_PROPERTY == prop) {
1403+ if (newValue == Boolean.TRUE) {
1404+ // Cancel a resize in progress if the internal frame
1405+ // gets a setClosed(true) or dispose().
1406+ cancelResize();
1407+ if ((frame.getParent() != null) && componentListenerAdded) {
1408+ frame.getParent().removeComponentListener(componentListener);
1409+ }
1410+ closeFrame(f);
1411+ }
1412+ } else if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) {
1413+ if(newValue == Boolean.TRUE) {
1414+ maximizeFrame(f);
1415+ } else {
1416+ minimizeFrame(f);
1417+ }
1418+ } else if(JInternalFrame.IS_ICON_PROPERTY == prop) {
1419+ if (newValue == Boolean.TRUE) {
1420+ iconifyFrame(f);
1421+ } else {
1422+ deiconifyFrame(f);
1423+ }
1424+ } else if (JInternalFrame.IS_SELECTED_PROPERTY == prop) {
1425+ if (newValue == Boolean.TRUE && oldValue == Boolean.FALSE) {
1426+ activateFrame(f);
1427+ } else if (newValue == Boolean.FALSE &&
1428+ oldValue == Boolean.TRUE) {
1429+ deactivateFrame(f);
1430+ }
1431+ } else if (prop == "ancestor") {
1432+ if (newValue == null) {
1433+ // Cancel a resize in progress, if the internal frame
1434+ // gets a remove(), removeNotify() or setIcon(true).
1435+ cancelResize();
1436+ }
1437+ if (frame.getParent() != null) {
1438+ parentBounds = f.getParent().getBounds();
1439+ } else {
1440+ parentBounds = null;
1441+ }
1442+ if ((frame.getParent() != null) && !componentListenerAdded) {
1443+ f.getParent().addComponentListener(componentListener);
1444+ componentListenerAdded = true;
1445+ }
1446+ } else if (JInternalFrame.TITLE_PROPERTY == prop ||
1447+ prop == "closable" || prop == "iconable" ||
1448+ prop == "maximizable") {
1449+ Dimension dim = frame.getMinimumSize();
1450+ Dimension frame_dim = frame.getSize();
1451+ if (dim.width > frame_dim.width) {
1452+ frame.setSize(dim.width, frame_dim.height);
1453+ }
1454+ }
1455+ }
1456+ }
1457+}