0001 /*
0002 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
0003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004 *
0005 * This code is free software; you can redistribute it and/or modify it
0006 * under the terms of the GNU General Public License version 2 only, as
0007 * published by the Free Software Foundation. Sun designates this
0008 * particular file as subject to the "Classpath" exception as provided
0009 * by Sun in the LICENSE file that accompanied this code.
0010 *
0011 * This code is distributed in the hope that it will be useful, but WITHOUT
0012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014 * version 2 for more details (a copy is included in the LICENSE file that
0015 * accompanied this code).
0016 *
0017 * You should have received a copy of the GNU General Public License version
0018 * 2 along with this work; if not, write to the Free Software Foundation,
0019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020 *
0021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022 * CA 95054 USA or visit www.sun.com if you need additional information or
0023 * have any questions.
0024 */
0025
0026 package javax.swing.plaf.basic;
0027
0028 import java.awt.*;
0029 import java.awt.event.*;
0030 import java.awt.peer.LightweightPeer;
0031
0032 import javax.swing.*;
0033 import javax.swing.border.*;
0034 import javax.swing.plaf.*;
0035 import javax.swing.event.*;
0036
0037 import java.beans.*;
0038 import java.io.Serializable;
0039
0040 import sun.swing.DefaultLookup;
0041 import sun.swing.UIAction;
0042
0043 /**
0044 * A basic L&F implementation of JInternalFrame.
0045 *
0046 * @version 1.135 05/05/07
0047 * @author David Kloba
0048 * @author Rich Schiavi
0049 */
0050 public class BasicInternalFrameUI extends InternalFrameUI {
0051
0052 protected JInternalFrame frame;
0053
0054 private Handler handler;
0055 protected MouseInputAdapter borderListener;
0056 protected PropertyChangeListener propertyChangeListener;
0057 protected LayoutManager internalFrameLayout;
0058 protected ComponentListener componentListener;
0059 protected MouseInputListener glassPaneDispatcher;
0060 private InternalFrameListener internalFrameListener;
0061
0062 protected JComponent northPane;
0063 protected JComponent southPane;
0064 protected JComponent westPane;
0065 protected JComponent eastPane;
0066
0067 protected BasicInternalFrameTitlePane titlePane; // access needs this
0068
0069 private static DesktopManager sharedDesktopManager;
0070 private boolean componentListenerAdded = false;
0071
0072 private Rectangle parentBounds;
0073
0074 private boolean dragging = false;
0075 private boolean resizing = false;
0076
0077 /**
0078 * As of Java 2 platform v1.3 this previously undocumented field is no
0079 * longer used.
0080 * Key bindings are now defined by the LookAndFeel, please refer to
0081 * the key bindings specification for further details.
0082 *
0083 * @deprecated As of Java 2 platform v1.3.
0084 */
0085 @Deprecated
0086 protected KeyStroke openMenuKey;
0087
0088 private boolean keyBindingRegistered = false;
0089 private boolean keyBindingActive = false;
0090
0091 /////////////////////////////////////////////////////////////////////////////
0092 // ComponentUI Interface Implementation methods
0093 /////////////////////////////////////////////////////////////////////////////
0094 public static ComponentUI createUI(JComponent b) {
0095 return new BasicInternalFrameUI((JInternalFrame) b);
0096 }
0097
0098 public BasicInternalFrameUI(JInternalFrame b) {
0099 LookAndFeel laf = UIManager.getLookAndFeel();
0100 if (laf instanceof BasicLookAndFeel) {
0101 ((BasicLookAndFeel) laf).installAWTEventListener();
0102 }
0103 }
0104
0105 public void installUI(JComponent c) {
0106
0107 frame = (JInternalFrame) c;
0108
0109 installDefaults();
0110 installListeners();
0111 installComponents();
0112 installKeyboardActions();
0113
0114 LookAndFeel.installProperty(frame, "opaque", Boolean.TRUE);
0115 }
0116
0117 public void uninstallUI(JComponent c) {
0118 if (c != frame)
0119 throw new IllegalComponentStateException(this
0120 + " was asked to deinstall() " + c
0121 + " when it only knows about " + frame + ".");
0122
0123 uninstallKeyboardActions();
0124 uninstallComponents();
0125 uninstallListeners();
0126 uninstallDefaults();
0127 updateFrameCursor();
0128 handler = null;
0129 frame = null;
0130 }
0131
0132 protected void installDefaults() {
0133 Icon frameIcon = frame.getFrameIcon();
0134 if (frameIcon == null || frameIcon instanceof UIResource) {
0135 frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
0136 }
0137
0138 // Enable the content pane to inherit background color from its
0139 // parent by setting its background color to null.
0140 Container contentPane = frame.getContentPane();
0141 if (contentPane != null) {
0142 Color bg = contentPane.getBackground();
0143 if (bg instanceof UIResource)
0144 contentPane.setBackground(null);
0145 }
0146 frame.setLayout(internalFrameLayout = createLayoutManager());
0147 frame.setBackground(UIManager.getLookAndFeelDefaults()
0148 .getColor("control"));
0149
0150 LookAndFeel.installBorder(frame, "InternalFrame.border");
0151
0152 }
0153
0154 protected void installKeyboardActions() {
0155 createInternalFrameListener();
0156 if (internalFrameListener != null) {
0157 frame.addInternalFrameListener(internalFrameListener);
0158 }
0159
0160 LazyActionMap.installLazyActionMap(frame,
0161 BasicInternalFrameUI.class, "InternalFrame.actionMap");
0162 }
0163
0164 static void loadActionMap(LazyActionMap map) {
0165 map.put(new UIAction("showSystemMenu") {
0166 public void actionPerformed(ActionEvent evt) {
0167 JInternalFrame iFrame = (JInternalFrame) evt
0168 .getSource();
0169 if (iFrame.getUI() instanceof BasicInternalFrameUI) {
0170 JComponent comp = ((BasicInternalFrameUI) iFrame
0171 .getUI()).getNorthPane();
0172 if (comp instanceof BasicInternalFrameTitlePane) {
0173 ((BasicInternalFrameTitlePane) comp)
0174 .showSystemMenu();
0175 }
0176 }
0177 }
0178
0179 public boolean isEnabled(Object sender) {
0180 if (sender instanceof JInternalFrame) {
0181 JInternalFrame iFrame = (JInternalFrame) sender;
0182 if (iFrame.getUI() instanceof BasicInternalFrameUI) {
0183 return ((BasicInternalFrameUI) iFrame.getUI())
0184 .isKeyBindingActive();
0185 }
0186 }
0187 return false;
0188 }
0189 });
0190
0191 // Set the ActionMap's parent to the Auditory Feedback Action Map
0192 BasicLookAndFeel.installAudioActionMap(map);
0193 }
0194
0195 protected void installComponents() {
0196 setNorthPane(createNorthPane(frame));
0197 setSouthPane(createSouthPane(frame));
0198 setEastPane(createEastPane(frame));
0199 setWestPane(createWestPane(frame));
0200 }
0201
0202 /**
0203 * @since 1.3
0204 */
0205 protected void installListeners() {
0206 borderListener = createBorderListener(frame);
0207 propertyChangeListener = createPropertyChangeListener();
0208 frame.addPropertyChangeListener(propertyChangeListener);
0209 installMouseHandlers(frame);
0210 glassPaneDispatcher = createGlassPaneDispatcher();
0211 if (glassPaneDispatcher != null) {
0212 frame.getGlassPane().addMouseListener(glassPaneDispatcher);
0213 frame.getGlassPane().addMouseMotionListener(
0214 glassPaneDispatcher);
0215 }
0216 componentListener = createComponentListener();
0217 if (frame.getParent() != null) {
0218 parentBounds = frame.getParent().getBounds();
0219 }
0220 if ((frame.getParent() != null) && !componentListenerAdded) {
0221 frame.getParent().addComponentListener(componentListener);
0222 componentListenerAdded = true;
0223 }
0224 }
0225
0226 // Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event,
0227 // so that a resize can be cancelled if the focus is lost while resizing
0228 // when an Alt-Tab, modal dialog popup, iconify, dispose, or remove
0229 // of the internal frame occurs.
0230 private WindowFocusListener getWindowFocusListener() {
0231 return getHandler();
0232 }
0233
0234 // Cancel a resize in progress by calling finishMouseReleased().
0235 private void cancelResize() {
0236 if (resizing) {
0237 if (borderListener instanceof BorderListener) {
0238 ((BorderListener) borderListener).finishMouseReleased();
0239 }
0240 }
0241 }
0242
0243 private Handler getHandler() {
0244 if (handler == null) {
0245 handler = new Handler();
0246 }
0247 return handler;
0248 }
0249
0250 InputMap getInputMap(int condition) {
0251 if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
0252 return createInputMap(condition);
0253 }
0254 return null;
0255 }
0256
0257 InputMap createInputMap(int condition) {
0258 if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
0259 Object[] bindings = (Object[]) DefaultLookup.get(frame,
0260 this , "InternalFrame.windowBindings");
0261
0262 if (bindings != null) {
0263 return LookAndFeel.makeComponentInputMap(frame,
0264 bindings);
0265 }
0266 }
0267 return null;
0268 }
0269
0270 protected void uninstallDefaults() {
0271 Icon frameIcon = frame.getFrameIcon();
0272 if (frameIcon instanceof UIResource) {
0273 frame.setFrameIcon(null);
0274 }
0275 internalFrameLayout = null;
0276 frame.setLayout(null);
0277 LookAndFeel.uninstallBorder(frame);
0278 }
0279
0280 protected void uninstallComponents() {
0281 setNorthPane(null);
0282 setSouthPane(null);
0283 setEastPane(null);
0284 setWestPane(null);
0285 if (titlePane != null) {
0286 titlePane.uninstallDefaults();
0287 }
0288 titlePane = null;
0289 }
0290
0291 /**
0292 * @since 1.3
0293 */
0294 protected void uninstallListeners() {
0295 if ((frame.getParent() != null) && componentListenerAdded) {
0296 frame.getParent()
0297 .removeComponentListener(componentListener);
0298 componentListenerAdded = false;
0299 }
0300 componentListener = null;
0301 if (glassPaneDispatcher != null) {
0302 frame.getGlassPane().removeMouseListener(
0303 glassPaneDispatcher);
0304 frame.getGlassPane().removeMouseMotionListener(
0305 glassPaneDispatcher);
0306 glassPaneDispatcher = null;
0307 }
0308 deinstallMouseHandlers(frame);
0309 frame.removePropertyChangeListener(propertyChangeListener);
0310 propertyChangeListener = null;
0311 borderListener = null;
0312 }
0313
0314 protected void uninstallKeyboardActions() {
0315 if (internalFrameListener != null) {
0316 frame.removeInternalFrameListener(internalFrameListener);
0317 }
0318 internalFrameListener = null;
0319
0320 SwingUtilities.replaceUIInputMap(frame,
0321 JComponent.WHEN_IN_FOCUSED_WINDOW, null);
0322 SwingUtilities.replaceUIActionMap(frame, null);
0323
0324 }
0325
0326 void updateFrameCursor() {
0327 if (resizing) {
0328 return;
0329 }
0330 Cursor s = (Cursor) frame.getLastCursor();
0331 if (s == null) {
0332 s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
0333 }
0334 frame.setCursor(s);
0335 }
0336
0337 protected LayoutManager createLayoutManager() {
0338 return getHandler();
0339 }
0340
0341 protected PropertyChangeListener createPropertyChangeListener() {
0342 return getHandler();
0343 }
0344
0345 public Dimension getPreferredSize(JComponent x) {
0346 if ((JComponent) frame == x)
0347 return frame.getLayout().preferredLayoutSize(x);
0348 return new Dimension(100, 100);
0349 }
0350
0351 public Dimension getMinimumSize(JComponent x) {
0352 if ((JComponent) frame == x) {
0353 return frame.getLayout().minimumLayoutSize(x);
0354 }
0355 return new Dimension(0, 0);
0356 }
0357
0358 public Dimension getMaximumSize(JComponent x) {
0359 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
0360 }
0361
0362 /**
0363 * Installs necessary mouse handlers on <code>newPane</code>
0364 * and adds it to the frame.
0365 * Reverse process for the <code>currentPane</code>.
0366 */
0367 protected void replacePane(JComponent currentPane,
0368 JComponent newPane) {
0369 if (currentPane != null) {
0370 deinstallMouseHandlers(currentPane);
0371 frame.remove(currentPane);
0372 }
0373 if (newPane != null) {
0374 frame.add(newPane);
0375 installMouseHandlers(newPane);
0376 }
0377 }
0378
0379 protected void deinstallMouseHandlers(JComponent c) {
0380 c.removeMouseListener(borderListener);
0381 c.removeMouseMotionListener(borderListener);
0382 }
0383
0384 protected void installMouseHandlers(JComponent c) {
0385 c.addMouseListener(borderListener);
0386 c.addMouseMotionListener(borderListener);
0387 }
0388
0389 protected JComponent createNorthPane(JInternalFrame w) {
0390 titlePane = new BasicInternalFrameTitlePane(w);
0391 return titlePane;
0392 }
0393
0394 protected JComponent createSouthPane(JInternalFrame w) {
0395 return null;
0396 }
0397
0398 protected JComponent createWestPane(JInternalFrame w) {
0399 return null;
0400 }
0401
0402 protected JComponent createEastPane(JInternalFrame w) {
0403 return null;
0404 }
0405
0406 protected MouseInputAdapter createBorderListener(JInternalFrame w) {
0407 return new BorderListener();
0408 }
0409
0410 protected void createInternalFrameListener() {
0411 internalFrameListener = getHandler();
0412 }
0413
0414 protected final boolean isKeyBindingRegistered() {
0415 return keyBindingRegistered;
0416 }
0417
0418 protected final void setKeyBindingRegistered(boolean b) {
0419 keyBindingRegistered = b;
0420 }
0421
0422 public final boolean isKeyBindingActive() {
0423 return keyBindingActive;
0424 }
0425
0426 protected final void setKeyBindingActive(boolean b) {
0427 keyBindingActive = b;
0428 }
0429
0430 protected void setupMenuOpenKey() {
0431 // PENDING(hania): Why are these WHEN_IN_FOCUSED_WINDOWs? Shouldn't
0432 // they be WHEN_ANCESTOR_OF_FOCUSED_COMPONENT?
0433 // Also, no longer registering on the desktopicon, the previous
0434 // action did nothing.
0435 InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
0436 SwingUtilities.replaceUIInputMap(frame,
0437 JComponent.WHEN_IN_FOCUSED_WINDOW, map);
0438 //ActionMap actionMap = getActionMap();
0439 //SwingUtilities.replaceUIActionMap(frame, actionMap);
0440 }
0441
0442 protected void setupMenuCloseKey() {
0443 }
0444
0445 public JComponent getNorthPane() {
0446 return northPane;
0447 }
0448
0449 public void setNorthPane(JComponent c) {
0450 if (northPane != null
0451 && northPane instanceof BasicInternalFrameTitlePane) {
0452 ((BasicInternalFrameTitlePane) northPane)
0453 .uninstallListeners();
0454 }
0455 replacePane(northPane, c);
0456 northPane = c;
0457 if (c instanceof BasicInternalFrameTitlePane) {
0458 titlePane = (BasicInternalFrameTitlePane) c;
0459 }
0460 }
0461
0462 public JComponent getSouthPane() {
0463 return southPane;
0464 }
0465
0466 public void setSouthPane(JComponent c) {
0467 southPane = c;
0468 }
0469
0470 public JComponent getWestPane() {
0471 return westPane;
0472 }
0473
0474 public void setWestPane(JComponent c) {
0475 westPane = c;
0476 }
0477
0478 public JComponent getEastPane() {
0479 return eastPane;
0480 }
0481
0482 public void setEastPane(JComponent c) {
0483 eastPane = c;
0484 }
0485
0486 public class InternalFramePropertyChangeListener implements
0487 PropertyChangeListener {
0488 // NOTE: This class exists only for backward compatability. All
0489 // its functionality has been moved into Handler. If you need to add
0490 // new functionality add it to the Handler, but make sure this
0491 // class calls into the Handler.
0492 /**
0493 * Detects changes in state from the JInternalFrame and handles
0494 * actions.
0495 */
0496 public void propertyChange(PropertyChangeEvent evt) {
0497 getHandler().propertyChange(evt);
0498 }
0499 }
0500
0501 public class InternalFrameLayout implements LayoutManager {
0502 // NOTE: This class exists only for backward compatability. All
0503 // its functionality has been moved into Handler. If you need to add
0504 // new functionality add it to the Handler, but make sure this
0505 // class calls into the Handler.
0506 public void addLayoutComponent(String name, Component c) {
0507 getHandler().addLayoutComponent(name, c);
0508 }
0509
0510 public void removeLayoutComponent(Component c) {
0511 getHandler().removeLayoutComponent(c);
0512 }
0513
0514 public Dimension preferredLayoutSize(Container c) {
0515 return getHandler().preferredLayoutSize(c);
0516 }
0517
0518 public Dimension minimumLayoutSize(Container c) {
0519 return getHandler().minimumLayoutSize(c);
0520 }
0521
0522 public void layoutContainer(Container c) {
0523 getHandler().layoutContainer(c);
0524 }
0525 }
0526
0527 /// DesktopManager methods
0528 /** Returns the proper DesktopManager. Calls getDesktopPane() to
0529 * find the JDesktop component and returns the desktopManager from
0530 * it. If this fails, it will return a default DesktopManager that
0531 * should work in arbitrary parents.
0532 */
0533 protected DesktopManager getDesktopManager() {
0534 if (frame.getDesktopPane() != null
0535 && frame.getDesktopPane().getDesktopManager() != null)
0536 return frame.getDesktopPane().getDesktopManager();
0537 if (sharedDesktopManager == null)
0538 sharedDesktopManager = createDesktopManager();
0539 return sharedDesktopManager;
0540 }
0541
0542 protected DesktopManager createDesktopManager() {
0543 return new DefaultDesktopManager();
0544 }
0545
0546 /**
0547 * This method is called when the user wants to close the frame.
0548 * The <code>playCloseSound</code> Action is fired.
0549 * This action is delegated to the desktopManager.
0550 */
0551 protected void closeFrame(JInternalFrame f) {
0552 // Internal Frame Auditory Cue Activation
0553 BasicLookAndFeel.playSound(frame, "InternalFrame.closeSound");
0554 // delegate to desktop manager
0555 getDesktopManager().closeFrame(f);
0556 }
0557
0558 /**
0559 * This method is called when the user wants to maximize the frame.
0560 * The <code>playMaximizeSound</code> Action is fired.
0561 * This action is delegated to the desktopManager.
0562 */
0563 protected void maximizeFrame(JInternalFrame f) {
0564 // Internal Frame Auditory Cue Activation
0565 BasicLookAndFeel
0566 .playSound(frame, "InternalFrame.maximizeSound");
0567 // delegate to desktop manager
0568 getDesktopManager().maximizeFrame(f);
0569 }
0570
0571 /**
0572 * This method is called when the user wants to minimize the frame.
0573 * The <code>playRestoreDownSound</code> Action is fired.
0574 * This action is delegated to the desktopManager.
0575 */
0576 protected void minimizeFrame(JInternalFrame f) {
0577 // Internal Frame Auditory Cue Activation
0578 if (!f.isIcon()) {
0579 // This method seems to regularly get called after an
0580 // internal frame is iconified. Don't play this sound then.
0581 BasicLookAndFeel.playSound(frame,
0582 "InternalFrame.restoreDownSound");
0583 }
0584 // delegate to desktop manager
0585 getDesktopManager().minimizeFrame(f);
0586 }
0587
0588 /**
0589 * This method is called when the user wants to iconify the frame.
0590 * The <code>playMinimizeSound</code> Action is fired.
0591 * This action is delegated to the desktopManager.
0592 */
0593 protected void iconifyFrame(JInternalFrame f) {
0594 // Internal Frame Auditory Cue Activation
0595 BasicLookAndFeel
0596 .playSound(frame, "InternalFrame.minimizeSound");
0597 // delegate to desktop manager
0598 getDesktopManager().iconifyFrame(f);
0599 }
0600
0601 /**
0602 * This method is called when the user wants to deiconify the frame.
0603 * The <code>playRestoreUpSound</code> Action is fired.
0604 * This action is delegated to the desktopManager.
0605 */
0606 protected void deiconifyFrame(JInternalFrame f) {
0607 // Internal Frame Auditory Cue Activation
0608 if (!f.isMaximum()) {
0609 // This method seems to regularly get called after an
0610 // internal frame is maximized. Don't play this sound then.
0611 BasicLookAndFeel.playSound(frame,
0612 "InternalFrame.restoreUpSound");
0613 }
0614 // delegate to desktop manager
0615 getDesktopManager().deiconifyFrame(f);
0616 }
0617
0618 /** This method is called when the frame becomes selected.
0619 * This action is delegated to the desktopManager.
0620 */
0621 protected void activateFrame(JInternalFrame f) {
0622 getDesktopManager().activateFrame(f);
0623 }
0624
0625 /** This method is called when the frame is no longer selected.
0626 * This action is delegated to the desktopManager.
0627 */
0628 protected void deactivateFrame(JInternalFrame f) {
0629 getDesktopManager().deactivateFrame(f);
0630 }
0631
0632 /////////////////////////////////////////////////////////////////////////
0633 /// Border Listener Class
0634 /////////////////////////////////////////////////////////////////////////
0635 /**
0636 * Listens for border adjustments.
0637 */
0638 protected class BorderListener extends MouseInputAdapter implements
0639 SwingConstants {
0640 // _x & _y are the mousePressed location in absolute coordinate system
0641 int _x, _y;
0642 // __x & __y are the mousePressed location in source view's coordinate system
0643 int __x, __y;
0644 Rectangle startingBounds;
0645 int resizeDir;
0646
0647 protected final int RESIZE_NONE = 0;
0648 private boolean discardRelease = false;
0649
0650 int resizeCornerSize = 16;
0651
0652 public void mouseClicked(MouseEvent e) {
0653 if (e.getClickCount() > 1
0654 && e.getSource() == getNorthPane()) {
0655 if (frame.isIconifiable() && frame.isIcon()) {
0656 try {
0657 frame.setIcon(false);
0658 } catch (PropertyVetoException e2) {
0659 }
0660 } else if (frame.isMaximizable()) {
0661 if (!frame.isMaximum())
0662 try {
0663 frame.setMaximum(true);
0664 } catch (PropertyVetoException e2) {
0665 }
0666 else
0667 try {
0668 frame.setMaximum(false);
0669 } catch (PropertyVetoException e3) {
0670 }
0671 }
0672 }
0673 }
0674
0675 // Factor out finishMouseReleased() from mouseReleased(), so that
0676 // it can be called by cancelResize() without passing it a null
0677 // MouseEvent.
0678 void finishMouseReleased() {
0679 if (discardRelease) {
0680 discardRelease = false;
0681 return;
0682 }
0683 if (resizeDir == RESIZE_NONE) {
0684 getDesktopManager().endDraggingFrame(frame);
0685 dragging = false;
0686 } else {
0687 // Remove the WindowFocusListener for handling a
0688 // WINDOW_LOST_FOCUS event with a cancelResize().
0689 Window windowAncestor = SwingUtilities
0690 .getWindowAncestor(frame);
0691 if (windowAncestor != null) {
0692 windowAncestor
0693 .removeWindowFocusListener(getWindowFocusListener());
0694 }
0695 Container c = frame.getTopLevelAncestor();
0696 if (c instanceof RootPaneContainer) {
0697 Component glassPane = ((RootPaneContainer) c)
0698 .getGlassPane();
0699 glassPane
0700 .setCursor(Cursor
0701 .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
0702 glassPane.setVisible(false);
0703 }
0704 getDesktopManager().endResizingFrame(frame);
0705 resizing = false;
0706 }
0707 _x = 0;
0708 _y = 0;
0709 __x = 0;
0710 __y = 0;
0711 startingBounds = null;
0712 resizeDir = RESIZE_NONE;
0713 // Set discardRelease to true, so that only a mousePressed()
0714 // which sets it to false, will allow entry to the above code
0715 // for finishing a resize.
0716 discardRelease = true;
0717 }
0718
0719 public void mouseReleased(MouseEvent e) {
0720 finishMouseReleased();
0721 }
0722
0723 public void mousePressed(MouseEvent e) {
0724 Point p = SwingUtilities.convertPoint((Component) e
0725 .getSource(), e.getX(), e.getY(), null);
0726 __x = e.getX();
0727 __y = e.getY();
0728 _x = p.x;
0729 _y = p.y;
0730 startingBounds = frame.getBounds();
0731 resizeDir = RESIZE_NONE;
0732 discardRelease = false;
0733
0734 try {
0735 frame.setSelected(true);
0736 } catch (PropertyVetoException e1) {
0737 }
0738
0739 Insets i = frame.getInsets();
0740
0741 Point ep = new Point(__x, __y);
0742 if (e.getSource() == getNorthPane()) {
0743 Point np = getNorthPane().getLocation();
0744 ep.x += np.x;
0745 ep.y += np.y;
0746 }
0747
0748 if (e.getSource() == getNorthPane()) {
0749 if (ep.x > i.left && ep.y > i.top
0750 && ep.x < frame.getWidth() - i.right) {
0751 getDesktopManager().beginDraggingFrame(frame);
0752 dragging = true;
0753 return;
0754 }
0755 }
0756 if (!frame.isResizable()) {
0757 return;
0758 }
0759
0760 if (e.getSource() == frame
0761 || e.getSource() == getNorthPane()) {
0762 if (ep.x <= i.left) {
0763 if (ep.y < resizeCornerSize + i.top) {
0764 resizeDir = NORTH_WEST;
0765 } else if (ep.y > frame.getHeight()
0766 - resizeCornerSize - i.bottom) {
0767 resizeDir = SOUTH_WEST;
0768 } else {
0769 resizeDir = WEST;
0770 }
0771 } else if (ep.x >= frame.getWidth() - i.right) {
0772 if (ep.y < resizeCornerSize + i.top) {
0773 resizeDir = NORTH_EAST;
0774 } else if (ep.y > frame.getHeight()
0775 - resizeCornerSize - i.bottom) {
0776 resizeDir = SOUTH_EAST;
0777 } else {
0778 resizeDir = EAST;
0779 }
0780 } else if (ep.y <= i.top) {
0781 if (ep.x < resizeCornerSize + i.left) {
0782 resizeDir = NORTH_WEST;
0783 } else if (ep.x > frame.getWidth()
0784 - resizeCornerSize - i.right) {
0785 resizeDir = NORTH_EAST;
0786 } else {
0787 resizeDir = NORTH;
0788 }
0789 } else if (ep.y >= frame.getHeight() - i.bottom) {
0790 if (ep.x < resizeCornerSize + i.left) {
0791 resizeDir = SOUTH_WEST;
0792 } else if (ep.x > frame.getWidth()
0793 - resizeCornerSize - i.right) {
0794 resizeDir = SOUTH_EAST;
0795 } else {
0796 resizeDir = SOUTH;
0797 }
0798 } else {
0799 /* the mouse press happened inside the frame, not in the
0800 border */
0801 discardRelease = true;
0802 return;
0803 }
0804 Cursor s = Cursor
0805 .getPredefinedCursor(Cursor.DEFAULT_CURSOR);
0806 switch (resizeDir) {
0807 case SOUTH:
0808 s = Cursor
0809 .getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
0810 break;
0811 case NORTH:
0812 s = Cursor
0813 .getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
0814 break;
0815 case WEST:
0816 s = Cursor
0817 .getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
0818 break;
0819 case EAST:
0820 s = Cursor
0821 .getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
0822 break;
0823 case SOUTH_EAST:
0824 s = Cursor
0825 .getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
0826 break;
0827 case SOUTH_WEST:
0828 s = Cursor
0829 .getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
0830 break;
0831 case NORTH_WEST:
0832 s = Cursor
0833 .getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
0834 break;
0835 case NORTH_EAST:
0836 s = Cursor
0837 .getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
0838 break;
0839 }
0840 Container c = frame.getTopLevelAncestor();
0841 if (c instanceof RootPaneContainer) {
0842 Component glassPane = ((RootPaneContainer) c)
0843 .getGlassPane();
0844 glassPane.setVisible(true);
0845 glassPane.setCursor(s);
0846 }
0847 getDesktopManager()
0848 .beginResizingFrame(frame, resizeDir);
0849 resizing = true;
0850 // Add the WindowFocusListener for handling a
0851 // WINDOW_LOST_FOCUS event with a cancelResize().
0852 Window windowAncestor = SwingUtilities
0853 .getWindowAncestor(frame);
0854 if (windowAncestor != null) {
0855 windowAncestor
0856 .addWindowFocusListener(getWindowFocusListener());
0857 }
0858 return;
0859 }
0860 }
0861
0862 public void mouseDragged(MouseEvent e) {
0863
0864 if (startingBounds == null) {
0865 // (STEVE) Yucky work around for bug ID 4106552
0866 return;
0867 }
0868
0869 Point p = SwingUtilities.convertPoint((Component) e
0870 .getSource(), e.getX(), e.getY(), null);
0871 int deltaX = _x - p.x;
0872 int deltaY = _y - p.y;
0873 Dimension min = frame.getMinimumSize();
0874 Dimension max = frame.getMaximumSize();
0875 int newX, newY, newW, newH;
0876 Insets i = frame.getInsets();
0877
0878 // Handle a MOVE
0879 if (dragging) {
0880 if (frame.isMaximum()
0881 || ((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK)) {
0882 // don't allow moving of frames if maximixed or left mouse
0883 // button was not used.
0884 return;
0885 }
0886 int pWidth, pHeight;
0887 Dimension s = frame.getParent().getSize();
0888 pWidth = s.width;
0889 pHeight = s.height;
0890
0891 newX = startingBounds.x - deltaX;
0892 newY = startingBounds.y - deltaY;
0893
0894 // Make sure we stay in-bounds
0895 if (newX + i.left <= -__x)
0896 newX = -__x - i.left + 1;
0897 if (newY + i.top <= -__y)
0898 newY = -__y - i.top + 1;
0899 if (newX + __x + i.right >= pWidth)
0900 newX = pWidth - __x - i.right - 1;
0901 if (newY + __y + i.bottom >= pHeight)
0902 newY = pHeight - __y - i.bottom - 1;
0903
0904 getDesktopManager().dragFrame(frame, newX, newY);
0905 return;
0906 }
0907
0908 if (!frame.isResizable()) {
0909 return;
0910 }
0911
0912 newX = frame.getX();
0913 newY = frame.getY();
0914 newW = frame.getWidth();
0915 newH = frame.getHeight();
0916
0917 parentBounds = frame.getParent().getBounds();
0918
0919 switch (resizeDir) {
0920 case RESIZE_NONE:
0921 return;
0922 case NORTH:
0923 if (startingBounds.height + deltaY < min.height)
0924 deltaY = -(startingBounds.height - min.height);
0925 else if (startingBounds.height + deltaY > max.height)
0926 deltaY = max.height - startingBounds.height;
0927 if (startingBounds.y - deltaY < 0) {
0928 deltaY = startingBounds.y;
0929 }
0930
0931 newX = startingBounds.x;
0932 newY = startingBounds.y - deltaY;
0933 newW = startingBounds.width;
0934 newH = startingBounds.height + deltaY;
0935 break;
0936 case NORTH_EAST:
0937 if (startingBounds.height + deltaY < min.height)
0938 deltaY = -(startingBounds.height - min.height);
0939 else if (startingBounds.height + deltaY > max.height)
0940 deltaY = max.height - startingBounds.height;
0941 if (startingBounds.y - deltaY < 0) {
0942 deltaY = startingBounds.y;
0943 }
0944
0945 if (startingBounds.width - deltaX < min.width)
0946 deltaX = startingBounds.width - min.width;
0947 else if (startingBounds.width - deltaX > max.width)
0948 deltaX = -(max.width - startingBounds.width);
0949 if (startingBounds.x + startingBounds.width - deltaX > parentBounds.width) {
0950 deltaX = startingBounds.x + startingBounds.width
0951 - parentBounds.width;
0952 }
0953
0954 newX = startingBounds.x;
0955 newY = startingBounds.y - deltaY;
0956 newW = startingBounds.width - deltaX;
0957 newH = startingBounds.height + deltaY;
0958 break;
0959 case EAST:
0960 if (startingBounds.width - deltaX < min.width)
0961 deltaX = startingBounds.width - min.width;
0962 else if (startingBounds.width - deltaX > max.width)
0963 deltaX = -(max.width - startingBounds.width);
0964 if (startingBounds.x + startingBounds.width - deltaX > parentBounds.width) {
0965 deltaX = startingBounds.x + startingBounds.width
0966 - parentBounds.width;
0967 }
0968
0969 newW = startingBounds.width - deltaX;
0970 newH = startingBounds.height;
0971 break;
0972 case SOUTH_EAST:
0973 if (startingBounds.width - deltaX < min.width)
0974 deltaX = startingBounds.width - min.width;
0975 else if (startingBounds.width - deltaX > max.width)
0976 deltaX = -(max.width - startingBounds.width);
0977 if (startingBounds.x + startingBounds.width - deltaX > parentBounds.width) {
0978 deltaX = startingBounds.x + startingBounds.width
0979 - parentBounds.width;
0980 }
0981
0982 if (startingBounds.height - deltaY < min.height)
0983 deltaY = startingBounds.height - min.height;
0984 else if (startingBounds.height - deltaY > max.height)
0985 deltaY = -(max.height - startingBounds.height);
0986 if (startingBounds.y + startingBounds.height - deltaY > parentBounds.height) {
0987 deltaY = startingBounds.y + startingBounds.height
0988 - parentBounds.height;
0989 }
0990
0991 newW = startingBounds.width - deltaX;
0992 newH = startingBounds.height - deltaY;
0993 break;
0994 case SOUTH:
0995 if (startingBounds.height - deltaY < min.height)
0996 deltaY = startingBounds.height - min.height;
0997 else if (startingBounds.height - deltaY > max.height)
0998 deltaY = -(max.height - startingBounds.height);
0999 if (startingBounds.y + startingBounds.height - deltaY > parentBounds.height) {
1000 deltaY = startingBounds.y + startingBounds.height
1001 - parentBounds.height;
1002 }
1003
1004 newW = startingBounds.width;
1005 newH = startingBounds.height - deltaY;
1006 break;
1007 case SOUTH_WEST:
1008 if (startingBounds.height - deltaY < min.height)
1009 deltaY = startingBounds.height - min.height;
1010 else if (startingBounds.height - deltaY > max.height)
1011 deltaY = -(max.height - startingBounds.height);
1012 if (startingBounds.y + startingBounds.height - deltaY > parentBounds.height) {
1013 deltaY = startingBounds.y + startingBounds.height
1014 - parentBounds.height;
1015 }
1016
1017 if (startingBounds.width + deltaX < min.width)
1018 deltaX = -(startingBounds.width - min.width);
1019 else if (startingBounds.width + deltaX > max.width)
1020 deltaX = max.width - startingBounds.width;
1021 if (startingBounds.x - deltaX < 0) {
1022 deltaX = startingBounds.x;
1023 }
1024
1025 newX = startingBounds.x - deltaX;
1026 newY = startingBounds.y;
1027 newW = startingBounds.width + deltaX;
1028 newH = startingBounds.height - deltaY;
1029 break;
1030 case WEST:
1031 if (startingBounds.width + deltaX < min.width)
1032 deltaX = -(startingBounds.width - min.width);
1033 else if (startingBounds.width + deltaX > max.width)
1034 deltaX = max.width - startingBounds.width;
1035 if (startingBounds.x - deltaX < 0) {
1036 deltaX = startingBounds.x;
1037 }
1038
1039 newX = startingBounds.x - deltaX;
1040 newY = startingBounds.y;
1041 newW = startingBounds.width + deltaX;
1042 newH = startingBounds.height;
1043 break;
1044 case NORTH_WEST:
1045 if (startingBounds.width + deltaX < min.width)
1046 deltaX = -(startingBounds.width - min.width);
1047 else if (startingBounds.width + deltaX > max.width)
1048 deltaX = max.width - startingBounds.width;
1049 if (startingBounds.x - deltaX < 0) {
1050 deltaX = startingBounds.x;
1051 }
1052
1053 if (startingBounds.height + deltaY < min.height)
1054 deltaY = -(startingBounds.height - min.height);
1055 else if (startingBounds.height + deltaY > max.height)
1056 deltaY = max.height - startingBounds.height;
1057 if (startingBounds.y - deltaY < 0) {
1058 deltaY = startingBounds.y;
1059 }
1060
1061 newX = startingBounds.x - deltaX;
1062 newY = startingBounds.y - deltaY;
1063 newW = startingBounds.width + deltaX;
1064 newH = startingBounds.height + deltaY;
1065 break;
1066 default:
1067 return;
1068 }
1069 getDesktopManager().resizeFrame(frame, newX, newY, newW,
1070 newH);
1071 }
1072
1073 public void mouseMoved(MouseEvent e) {
1074
1075 if (!frame.isResizable())
1076 return;
1077
1078 if (e.getSource() == frame
1079 || e.getSource() == getNorthPane()) {
1080 Insets i = frame.getInsets();
1081 Point ep = new Point(e.getX(), e.getY());
1082 if (e.getSource() == getNorthPane()) {
1083 Point np = getNorthPane().getLocation();
1084 ep.x += np.x;
1085 ep.y += np.y;
1086 }
1087 if (ep.x <= i.left) {
1088 if (ep.y < resizeCornerSize + i.top)
1089 frame
1090 .setCursor(Cursor
1091 .getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
1092 else if (ep.y > frame.getHeight()
1093 - resizeCornerSize - i.bottom)
1094 frame
1095 .setCursor(Cursor
1096 .getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
1097 else
1098 frame
1099 .setCursor(Cursor
1100 .getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
1101 } else if (ep.x >= frame.getWidth() - i.right) {
1102 if (e.getY() < resizeCornerSize + i.top)
1103 frame
1104 .setCursor(Cursor
1105 .getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
1106 else if (ep.y > frame.getHeight()
1107 - resizeCornerSize - i.bottom)
1108 frame
1109 .setCursor(Cursor
1110 .getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
1111 else
1112 frame
1113 .setCursor(Cursor
1114 .getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
1115 } else if (ep.y <= i.top) {
1116 if (ep.x < resizeCornerSize + i.left)
1117 frame
1118 .setCursor(Cursor
1119 .getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
1120 else if (ep.x > frame.getWidth() - resizeCornerSize
1121 - i.right)
1122 frame
1123 .setCursor(Cursor
1124 .getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
1125 else
1126 frame
1127 .setCursor(Cursor
1128 .getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
1129 } else if (ep.y >= frame.getHeight() - i.bottom) {
1130 if (ep.x < resizeCornerSize + i.left)
1131 frame
1132 .setCursor(Cursor
1133 .getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
1134 else if (ep.x > frame.getWidth() - resizeCornerSize
1135 - i.right)
1136 frame
1137 .setCursor(Cursor
1138 .getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
1139 else
1140 frame
1141 .setCursor(Cursor
1142 .getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
1143 } else
1144 updateFrameCursor();
1145 return;
1146 }
1147
1148 updateFrameCursor();
1149 }
1150
1151 public void mouseEntered(MouseEvent e) {
1152 updateFrameCursor();
1153 }
1154
1155 public void mouseExited(MouseEvent e) {
1156 updateFrameCursor();
1157 }
1158
1159 }; /// End BorderListener Class
1160
1161 protected class ComponentHandler implements ComponentListener {
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 /** Invoked when a JInternalFrame's parent's size changes. */
1167 public void componentResized(ComponentEvent e) {
1168 getHandler().componentResized(e);
1169 }
1170
1171 public void componentMoved(ComponentEvent e) {
1172 getHandler().componentMoved(e);
1173 }
1174
1175 public void componentShown(ComponentEvent e) {
1176 getHandler().componentShown(e);
1177 }
1178
1179 public void componentHidden(ComponentEvent e) {
1180 getHandler().componentHidden(e);
1181 }
1182 }
1183
1184 protected ComponentListener createComponentListener() {
1185 return getHandler();
1186 }
1187
1188 protected class GlassPaneDispatcher implements MouseInputListener {
1189 // NOTE: This class exists only for backward compatability. All
1190 // its functionality has been moved into Handler. If you need to add
1191 // new functionality add it to the Handler, but make sure this
1192 // class calls into the Handler.
1193 public void mousePressed(MouseEvent e) {
1194 getHandler().mousePressed(e);
1195 }
1196
1197 public void mouseEntered(MouseEvent e) {
1198 getHandler().mouseEntered(e);
1199 }
1200
1201 public void mouseMoved(MouseEvent e) {
1202 getHandler().mouseMoved(e);
1203 }
1204
1205 public void mouseExited(MouseEvent e) {
1206 getHandler().mouseExited(e);
1207 }
1208
1209 public void mouseClicked(MouseEvent e) {
1210 getHandler().mouseClicked(e);
1211 }
1212
1213 public void mouseReleased(MouseEvent e) {
1214 getHandler().mouseReleased(e);
1215 }
1216
1217 public void mouseDragged(MouseEvent e) {
1218 getHandler().mouseDragged(e);
1219 }
1220 }
1221
1222 protected MouseInputListener createGlassPaneDispatcher() {
1223 return null;
1224 }
1225
1226 protected class BasicInternalFrameListener implements
1227 InternalFrameListener {
1228 // NOTE: This class exists only for backward compatability. All
1229 // its functionality has been moved into Handler. If you need to add
1230 // new functionality add it to the Handler, but make sure this
1231 // class calls into the Handler.
1232 public void internalFrameClosing(InternalFrameEvent e) {
1233 getHandler().internalFrameClosing(e);
1234 }
1235
1236 public void internalFrameClosed(InternalFrameEvent e) {
1237 getHandler().internalFrameClosed(e);
1238 }
1239
1240 public void internalFrameOpened(InternalFrameEvent e) {
1241 getHandler().internalFrameOpened(e);
1242 }
1243
1244 public void internalFrameIconified(InternalFrameEvent e) {
1245 getHandler().internalFrameIconified(e);
1246 }
1247
1248 public void internalFrameDeiconified(InternalFrameEvent e) {
1249 getHandler().internalFrameDeiconified(e);
1250 }
1251
1252 public void internalFrameActivated(InternalFrameEvent e) {
1253 getHandler().internalFrameActivated(e);
1254 }
1255
1256 public void internalFrameDeactivated(InternalFrameEvent e) {
1257 getHandler().internalFrameDeactivated(e);
1258 }
1259 }
1260
1261 private static boolean isDragging = false;
1262
1263 private class Handler implements ComponentListener,
1264 InternalFrameListener, LayoutManager, MouseInputListener,
1265 PropertyChangeListener, WindowFocusListener, SwingConstants {
1266
1267 public void windowGainedFocus(WindowEvent e) {
1268 }
1269
1270 public void windowLostFocus(WindowEvent e) {
1271 // Cancel a resize which may be in progress, when a
1272 // WINDOW_LOST_FOCUS event occurs, which may be
1273 // caused by an Alt-Tab or a modal dialog popup.
1274 cancelResize();
1275 }
1276
1277 // ComponentHandler methods
1278 /** Invoked when a JInternalFrame's parent's size changes. */
1279 public void componentResized(ComponentEvent e) {
1280 // Get the JInternalFrame's parent container size
1281 Rectangle parentNewBounds = ((Component) e.getSource())
1282 .getBounds();
1283 JInternalFrame.JDesktopIcon icon = null;
1284
1285 if (frame != null) {
1286 icon = frame.getDesktopIcon();
1287 // Resize the internal frame if it is maximized and relocate
1288 // the associated icon as well.
1289 if (frame.isMaximum()) {
1290 frame.setBounds(0, 0, parentNewBounds.width,
1291 parentNewBounds.height);
1292 }
1293 }
1294
1295 // Relocate the icon base on the new parent bounds.
1296 if (icon != null) {
1297 Rectangle iconBounds = icon.getBounds();
1298 int y = iconBounds.y
1299 + (parentNewBounds.height - parentBounds.height);
1300 icon.setBounds(iconBounds.x, y, iconBounds.width,
1301 iconBounds.height);
1302 }
1303
1304 // Update the new parent bounds for next resize.
1305 if (!parentBounds.equals(parentNewBounds)) {
1306 parentBounds = parentNewBounds;
1307 }
1308
1309 // Validate the component tree for this container.
1310 if (frame != null)
1311 frame.validate();
1312 }
1313
1314 public void componentMoved(ComponentEvent e) {
1315 }
1316
1317 public void componentShown(ComponentEvent e) {
1318 }
1319
1320 public void componentHidden(ComponentEvent e) {
1321 }
1322
1323 // InternalFrameListener
1324 public void internalFrameClosed(InternalFrameEvent e) {
1325 frame.removeInternalFrameListener(getHandler());
1326 }
1327
1328 public void internalFrameActivated(InternalFrameEvent e) {
1329 if (!isKeyBindingRegistered()) {
1330 setKeyBindingRegistered(true);
1331 setupMenuOpenKey();
1332 setupMenuCloseKey();
1333 }
1334 if (isKeyBindingRegistered())
1335 setKeyBindingActive(true);
1336 }
1337
1338 public void internalFrameDeactivated(InternalFrameEvent e) {
1339 setKeyBindingActive(false);
1340 }
1341
1342 public void internalFrameClosing(InternalFrameEvent e) {
1343 }
1344
1345 public void internalFrameOpened(InternalFrameEvent e) {
1346 }
1347
1348 public void internalFrameIconified(InternalFrameEvent e) {
1349 }
1350
1351 public void internalFrameDeiconified(InternalFrameEvent e) {
1352 }
1353
1354 // LayoutManager
1355 public void addLayoutComponent(String name, Component c) {
1356 }
1357
1358 public void removeLayoutComponent(Component c) {
1359 }
1360
1361 public Dimension preferredLayoutSize(Container c) {
1362 Dimension result;
1363 Insets i = frame.getInsets();
1364
1365 result = new Dimension(frame.getRootPane()
1366 .getPreferredSize());
1367 result.width += i.left + i.right;
1368 result.height += i.top + i.bottom;
1369
1370 if (getNorthPane() != null) {
1371 Dimension d = getNorthPane().getPreferredSize();
1372 result.width = Math.max(d.width, result.width);
1373 result.height += d.height;
1374 }
1375
1376 if (getSouthPane() != null) {
1377 Dimension d = getSouthPane().getPreferredSize();
1378 result.width = Math.max(d.width, result.width);
1379 result.height += d.height;
1380 }
1381
1382 if (getEastPane() != null) {
1383 Dimension d = getEastPane().getPreferredSize();
1384 result.width += d.width;
1385 result.height = Math.max(d.height, result.height);
1386 }
1387
1388 if (getWestPane() != null) {
1389 Dimension d = getWestPane().getPreferredSize();
1390 result.width += d.width;
1391 result.height = Math.max(d.height, result.height);
1392 }
1393 return result;
1394 }
1395
1396 public Dimension minimumLayoutSize(Container c) {
1397 // The minimum size of the internal frame only takes into
1398 // account the title pane since you are allowed to resize
1399 // the frames to the point where just the title pane is visible.
1400 Dimension result = new Dimension();
1401 if (getNorthPane() != null
1402 && getNorthPane() instanceof BasicInternalFrameTitlePane) {
1403 result = new Dimension(getNorthPane().getMinimumSize());
1404 }
1405 Insets i = frame.getInsets();
1406 result.width += i.left + i.right;
1407 result.height += i.top + i.bottom;
1408
1409 return result;
1410 }
1411
1412 public void layoutContainer(Container c) {
1413 Insets i = frame.getInsets();
1414 int cx, cy, cw, ch;
1415
1416 cx = i.left;
1417 cy = i.top;
1418 cw = frame.getWidth() - i.left - i.right;
1419 ch = frame.getHeight() - i.top - i.bottom;
1420
1421 if (getNorthPane() != null) {
1422 Dimension size = getNorthPane().getPreferredSize();
1423 if (DefaultLookup.getBoolean(frame,
1424 BasicInternalFrameUI.this ,
1425 "InternalFrame.layoutTitlePaneAtOrigin", false)) {
1426 cy = 0;
1427 ch += i.top;
1428 getNorthPane().setBounds(0, 0, frame.getWidth(),
1429 size.height);
1430 } else {
1431 getNorthPane().setBounds(cx, cy, cw, size.height);
1432 }
1433 cy += size.height;
1434 ch -= size.height;
1435 }
1436
1437 if (getSouthPane() != null) {
1438 Dimension size = getSouthPane().getPreferredSize();
1439 getSouthPane().setBounds(cx,
1440 frame.getHeight() - i.bottom - size.height, cw,
1441 size.height);
1442 ch -= size.height;
1443 }
1444
1445 if (getWestPane() != null) {
1446 Dimension size = getWestPane().getPreferredSize();
1447 getWestPane().setBounds(cx, cy, size.width, ch);
1448 cw -= size.width;
1449 cx += size.width;
1450 }
1451
1452 if (getEastPane() != null) {
1453 Dimension size = getEastPane().getPreferredSize();
1454 getEastPane().setBounds(cw - size.width, cy,
1455 size.width, ch);
1456 cw -= size.width;
1457 }
1458
1459 if (frame.getRootPane() != null) {
1460 frame.getRootPane().setBounds(cx, cy, cw, ch);
1461 }
1462 }
1463
1464 // MouseInputListener
1465 private Component mouseEventTarget = null;
1466 private Component dragSource = null;
1467
1468 public void mousePressed(MouseEvent e) {
1469 }
1470
1471 public void mouseEntered(MouseEvent e) {
1472 }
1473
1474 public void mouseMoved(MouseEvent e) {
1475 }
1476
1477 public void mouseExited(MouseEvent e) {
1478 }
1479
1480 public void mouseClicked(MouseEvent e) {
1481 }
1482
1483 public void mouseReleased(MouseEvent e) {
1484 }
1485
1486 public void mouseDragged(MouseEvent e) {
1487 }
1488
1489 // PropertyChangeListener
1490 public void propertyChange(PropertyChangeEvent evt) {
1491 String prop = (String) evt.getPropertyName();
1492 JInternalFrame f = (JInternalFrame) evt.getSource();
1493 Object newValue = evt.getNewValue();
1494 Object oldValue = evt.getOldValue();
1495
1496 if (JInternalFrame.IS_CLOSED_PROPERTY == prop) {
1497 if (newValue == Boolean.TRUE) {
1498 // Cancel a resize in progress if the internal frame
1499 // gets a setClosed(true) or dispose().
1500 cancelResize();
1501 if ((frame.getParent() != null)
1502 && componentListenerAdded) {
1503 frame.getParent().removeComponentListener(
1504 componentListener);
1505 }
1506 closeFrame(f);
1507 }
1508 } else if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) {
1509 if (newValue == Boolean.TRUE) {
1510 maximizeFrame(f);
1511 } else {
1512 minimizeFrame(f);
1513 }
1514 } else if (JInternalFrame.IS_ICON_PROPERTY == prop) {
1515 if (newValue == Boolean.TRUE) {
1516 iconifyFrame(f);
1517 } else {
1518 deiconifyFrame(f);
1519 }
1520 } else if (JInternalFrame.IS_SELECTED_PROPERTY == prop) {
1521 if (newValue == Boolean.TRUE
1522 && oldValue == Boolean.FALSE) {
1523 activateFrame(f);
1524 } else if (newValue == Boolean.FALSE
1525 && oldValue == Boolean.TRUE) {
1526 deactivateFrame(f);
1527 }
1528 } else if (prop == "ancestor") {
1529 if (newValue == null) {
1530 // Cancel a resize in progress, if the internal frame
1531 // gets a remove(), removeNotify() or setIcon(true).
1532 cancelResize();
1533 }
1534 if (frame.getParent() != null) {
1535 parentBounds = f.getParent().getBounds();
1536 } else {
1537 parentBounds = null;
1538 }
1539 if ((frame.getParent() != null)
1540 && !componentListenerAdded) {
1541 f.getParent().addComponentListener(
1542 componentListener);
1543 componentListenerAdded = true;
1544 } else if ((newValue == null) && componentListenerAdded) {
1545 if (f.getParent() != null) {
1546 f.getParent().removeComponentListener(
1547 componentListener);
1548 }
1549 componentListenerAdded = false;
1550 }
1551 } else if (JInternalFrame.TITLE_PROPERTY == prop
1552 || prop == "closable" || prop == "iconable"
1553 || prop == "maximizable") {
1554 Dimension dim = frame.getMinimumSize();
1555 Dimension frame_dim = frame.getSize();
1556 if (dim.width > frame_dim.width) {
1557 frame.setSize(dim.width, frame_dim.height);
1558 }
1559 }
1560 }
1561 }
1562 }
|