jdk/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java
changeset 3345 e095f8b1c3e8
parent 3104 cce457efb5d8
child 5506 202f599c92aa
equal deleted inserted replaced
3344:e2acdc658d52 3345:e095f8b1c3e8
    25 
    25 
    26 package javax.swing.plaf.basic;
    26 package javax.swing.plaf.basic;
    27 
    27 
    28 import java.awt.*;
    28 import java.awt.*;
    29 import java.awt.event.*;
    29 import java.awt.event.*;
    30 import java.awt.peer.LightweightPeer;
       
    31 
       
    32 import javax.swing.*;
    30 import javax.swing.*;
    33 import javax.swing.border.*;
       
    34 import javax.swing.plaf.*;
    31 import javax.swing.plaf.*;
    35 import javax.swing.event.*;
    32 import javax.swing.event.*;
    36 
       
    37 import java.beans.*;
    33 import java.beans.*;
    38 import java.io.Serializable;
       
    39 
       
    40 import sun.swing.DefaultLookup;
    34 import sun.swing.DefaultLookup;
    41 import sun.swing.UIAction;
    35 import sun.swing.UIAction;
    42 
    36 
    43 /**
    37 /**
    44  * A basic L&F implementation of JInternalFrame.
    38  * A basic L&F implementation of JInternalFrame.
    53 
    47 
    54     private Handler handler;
    48     private Handler handler;
    55     protected MouseInputAdapter          borderListener;
    49     protected MouseInputAdapter          borderListener;
    56     protected PropertyChangeListener     propertyChangeListener;
    50     protected PropertyChangeListener     propertyChangeListener;
    57     protected LayoutManager              internalFrameLayout;
    51     protected LayoutManager              internalFrameLayout;
       
    52     protected ComponentListener          componentListener;
    58     protected MouseInputListener         glassPaneDispatcher;
    53     protected MouseInputListener         glassPaneDispatcher;
    59     private InternalFrameListener        internalFrameListener;
    54     private InternalFrameListener        internalFrameListener;
    60 
    55 
    61     protected JComponent northPane;
    56     protected JComponent northPane;
    62     protected JComponent southPane;
    57     protected JComponent southPane;
    64     protected JComponent eastPane;
    59     protected JComponent eastPane;
    65 
    60 
    66     protected BasicInternalFrameTitlePane titlePane; // access needs this
    61     protected BasicInternalFrameTitlePane titlePane; // access needs this
    67 
    62 
    68     private static DesktopManager sharedDesktopManager;
    63     private static DesktopManager sharedDesktopManager;
       
    64     private boolean componentListenerAdded = false;
    69 
    65 
    70     private Rectangle parentBounds;
    66     private Rectangle parentBounds;
    71     private DesktopIconMover desktopIconMover;
       
    72 
    67 
    73     private boolean dragging = false;
    68     private boolean dragging = false;
    74     private boolean resizing = false;
    69     private boolean resizing = false;
    75 
    70 
    76     /**
    71     /**
   207         glassPaneDispatcher = createGlassPaneDispatcher();
   202         glassPaneDispatcher = createGlassPaneDispatcher();
   208         if (glassPaneDispatcher != null) {
   203         if (glassPaneDispatcher != null) {
   209             frame.getGlassPane().addMouseListener(glassPaneDispatcher);
   204             frame.getGlassPane().addMouseListener(glassPaneDispatcher);
   210             frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher);
   205             frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher);
   211         }
   206         }
       
   207         componentListener =  createComponentListener();
   212         if (frame.getParent() != null) {
   208         if (frame.getParent() != null) {
   213           parentBounds = frame.getParent().getBounds();
   209           parentBounds = frame.getParent().getBounds();
   214         }
   210         }
   215         getDesktopIconMover().installListeners();
   211         if ((frame.getParent() != null) && !componentListenerAdded) {
   216     }
   212             frame.getParent().addComponentListener(componentListener);
   217 
   213             componentListenerAdded = true;
   218     private DesktopIconMover getDesktopIconMover() {
   214         }
   219         if (desktopIconMover == null) {
       
   220             desktopIconMover = new DesktopIconMover(frame);
       
   221         }
       
   222         return desktopIconMover;
       
   223     }
   215     }
   224 
   216 
   225     // Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event,
   217     // Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event,
   226     // so that a resize can be cancelled if the focus is lost while resizing
   218     // so that a resize can be cancelled if the focus is lost while resizing
   227     // when an Alt-Tab, modal dialog popup, iconify, dispose, or remove
   219     // when an Alt-Tab, modal dialog popup, iconify, dispose, or remove
   288 
   280 
   289     /**
   281     /**
   290      * @since 1.3
   282      * @since 1.3
   291      */
   283      */
   292     protected void uninstallListeners() {
   284     protected void uninstallListeners() {
   293       getDesktopIconMover().uninstallListeners();
   285         if ((frame.getParent() != null) && componentListenerAdded) {
       
   286             frame.getParent().removeComponentListener(componentListener);
       
   287             componentListenerAdded = false;
       
   288         }
       
   289         componentListener = null;
   294       if (glassPaneDispatcher != null) {
   290       if (glassPaneDispatcher != null) {
   295           frame.getGlassPane().removeMouseListener(glassPaneDispatcher);
   291           frame.getGlassPane().removeMouseListener(glassPaneDispatcher);
   296           frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
   292           frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
   297           glassPaneDispatcher = null;
   293           glassPaneDispatcher = null;
   298       }
   294       }
  1226                     frame.setBounds(0, 0, parentNewBounds.width,
  1222                     frame.setBounds(0, 0, parentNewBounds.width,
  1227                         parentNewBounds.height);
  1223                         parentNewBounds.height);
  1228                 }
  1224                 }
  1229             }
  1225             }
  1230 
  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 
  1231             // Update the new parent bounds for next resize.
  1236             // Update the new parent bounds for next resize.
  1232             if (!parentBounds.equals(parentNewBounds)) {
  1237             if (!parentBounds.equals(parentNewBounds)) {
  1233                 parentBounds = parentNewBounds;
  1238                 parentBounds = parentNewBounds;
  1234             }
  1239             }
  1235 
  1240 
  1397             if (JInternalFrame.IS_CLOSED_PROPERTY == prop) {
  1402             if (JInternalFrame.IS_CLOSED_PROPERTY == prop) {
  1398                 if (newValue == Boolean.TRUE) {
  1403                 if (newValue == Boolean.TRUE) {
  1399                     // Cancel a resize in progress if the internal frame
  1404                     // Cancel a resize in progress if the internal frame
  1400                     // gets a setClosed(true) or dispose().
  1405                     // gets a setClosed(true) or dispose().
  1401                     cancelResize();
  1406                     cancelResize();
       
  1407                     if ((frame.getParent() != null) && componentListenerAdded) {
       
  1408                         frame.getParent().removeComponentListener(componentListener);
       
  1409                     }
  1402                     closeFrame(f);
  1410                     closeFrame(f);
  1403                 }
  1411                 }
  1404             } else if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) {
  1412             } else if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) {
  1405                 if(newValue == Boolean.TRUE) {
  1413                 if(newValue == Boolean.TRUE) {
  1406                     maximizeFrame(f);
  1414                     maximizeFrame(f);
  1428                 }
  1436                 }
  1429                 if (frame.getParent() != null) {
  1437                 if (frame.getParent() != null) {
  1430                     parentBounds = f.getParent().getBounds();
  1438                     parentBounds = f.getParent().getBounds();
  1431                 } else {
  1439                 } else {
  1432                     parentBounds = null;
  1440                     parentBounds = null;
       
  1441                 }
       
  1442                 if ((frame.getParent() != null) && !componentListenerAdded) {
       
  1443                     f.getParent().addComponentListener(componentListener);
       
  1444                     componentListenerAdded = true;
  1433                 }
  1445                 }
  1434             } else if (JInternalFrame.TITLE_PROPERTY == prop ||
  1446             } else if (JInternalFrame.TITLE_PROPERTY == prop ||
  1435                     prop == "closable" || prop == "iconable" ||
  1447                     prop == "closable" || prop == "iconable" ||
  1436                     prop == "maximizable") {
  1448                     prop == "maximizable") {
  1437                 Dimension dim = frame.getMinimumSize();
  1449                 Dimension dim = frame.getMinimumSize();