basicinternalframeui.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,620 行 · 第 1/4 页

JAVA
1,620
字号
    public void setNorthPane(JComponent c) {        if (northPane != null &&                northPane instanceof BasicInternalFrameTitlePane) {            ((BasicInternalFrameTitlePane)northPane).uninstallListeners();        }        replacePane(northPane, c);        northPane = c;    }    public JComponent getSouthPane() {        return southPane;    }    public void setSouthPane(JComponent c) {        southPane = c;    }    public JComponent getWestPane() {        return westPane;    }    public void setWestPane(JComponent c) {        westPane = c;    }    public JComponent getEastPane() {        return eastPane;    }    public void setEastPane(JComponent c) {        eastPane = c;    }    public class InternalFramePropertyChangeListener implements        PropertyChangeListener {        // NOTE: This class exists only for backward compatability. All        // its functionality has been moved into Handler. If you need to add        // new functionality add it to the Handler, but make sure this              // class calls into the Handler.        /**         * Detects changes in state from the JInternalFrame and handles         * actions.         */        public void propertyChange(PropertyChangeEvent evt) {            getHandler().propertyChange(evt);        }    }  public class InternalFrameLayout implements LayoutManager {    // NOTE: This class exists only for backward compatability. All    // its functionality has been moved into Handler. If you need to add    // new functionality add it to the Handler, but make sure this          // class calls into the Handler.    public void addLayoutComponent(String name, Component c) {        getHandler().addLayoutComponent(name, c);    }    public void removeLayoutComponent(Component c) {        getHandler().removeLayoutComponent(c);    }       public Dimension preferredLayoutSize(Container c)  {        return getHandler().preferredLayoutSize(c);    }        public Dimension minimumLayoutSize(Container c) {        return getHandler().minimumLayoutSize(c);    }        public void layoutContainer(Container c) {        getHandler().layoutContainer(c);    }  }/// DesktopManager methods    /** Returns the proper DesktopManager. Calls getDesktopPane() to       * find the JDesktop component and returns the desktopManager from      * it. If this fails, it will return a default DesktopManager that       * should work in arbitrary parents.      */    protected DesktopManager getDesktopManager() {	if(frame.getDesktopPane() != null 	   && frame.getDesktopPane().getDesktopManager() != null)	    return frame.getDesktopPane().getDesktopManager();	if(sharedDesktopManager == null)	  sharedDesktopManager = createDesktopManager();	return sharedDesktopManager;	    }      protected DesktopManager createDesktopManager(){      return new DefaultDesktopManager();    }        /**     * This method is called when the user wants to close the frame.     * The <code>playCloseSound</code> Action is fired.     * This action is delegated to the desktopManager.     */    protected void closeFrame(JInternalFrame f) {	// Internal Frame Auditory Cue Activation        BasicLookAndFeel.playSound(frame,"InternalFrame.closeSound");	// delegate to desktop manager	getDesktopManager().closeFrame(f);    }    /**     * This method is called when the user wants to maximize the frame.     * The <code>playMaximizeSound</code> Action is fired.     * This action is delegated to the desktopManager.     */    protected void maximizeFrame(JInternalFrame f) {	// Internal Frame Auditory Cue Activation        BasicLookAndFeel.playSound(frame,"InternalFrame.maximizeSound");	// delegate to desktop manager	getDesktopManager().maximizeFrame(f);    }    /**     * This method is called when the user wants to minimize the frame.     * The <code>playRestoreDownSound</code> Action is fired.     * This action is delegated to the desktopManager.     */    protected void minimizeFrame(JInternalFrame f) {	// Internal Frame Auditory Cue Activation	if ( ! f.isIcon() ) {	    // This method seems to regularly get called after an	    // internal frame is iconified. Don't play this sound then.            BasicLookAndFeel.playSound(frame,"InternalFrame.restoreDownSound");	}	// delegate to desktop manager	getDesktopManager().minimizeFrame(f);    }    /**     * This method is called when the user wants to iconify the frame.     * The <code>playMinimizeSound</code> Action is fired.     * This action is delegated to the desktopManager.     */    protected void iconifyFrame(JInternalFrame f) {	// Internal Frame Auditory Cue Activation        BasicLookAndFeel.playSound(frame, "InternalFrame.minimizeSound");	// delegate to desktop manager	getDesktopManager().iconifyFrame(f);    }    /**     * This method is called when the user wants to deiconify the frame.     * The <code>playRestoreUpSound</code> Action is fired.     * This action is delegated to the desktopManager.     */    protected void deiconifyFrame(JInternalFrame f) {	// Internal Frame Auditory Cue Activation	if ( ! f.isMaximum() ) {	    // This method seems to regularly get called after an	    // internal frame is maximized. Don't play this sound then.            BasicLookAndFeel.playSound(frame, "InternalFrame.restoreUpSound");	}	// delegate to desktop manager	getDesktopManager().deiconifyFrame(f);    }    /** This method is called when the frame becomes selected.      * This action is delegated to the desktopManager.      */    protected void activateFrame(JInternalFrame f) {	getDesktopManager().activateFrame(f);    }    /** This method is called when the frame is no longer selected.      * This action is delegated to the desktopManager.      */    protected void deactivateFrame(JInternalFrame f) {	getDesktopManager().deactivateFrame(f);    }    /////////////////////////////////////////////////////////////////////////    /// Border Listener Class    /////////////////////////////////////////////////////////////////////////            /**     * Listens for border adjustments.     */    protected class BorderListener extends MouseInputAdapter implements SwingConstants    {	// _x & _y are the mousePressed location in absolute coordinate system        int _x, _y;	// __x & __y are the mousePressed location in source view's coordinate system	int __x, __y;        Rectangle startingBounds;        int resizeDir;                        protected final int RESIZE_NONE  = 0;        private boolean discardRelease = false;                        int resizeCornerSize = 16;        	public void mouseClicked(MouseEvent e) {            if(e.getClickCount() > 1 && e.getSource() == getNorthPane()) {		if(frame.isIconifiable() && frame.isIcon()) {                    try { frame.setIcon(false); } catch (PropertyVetoException e2) { }		} else if(frame.isMaximizable()) {                    if(!frame.isMaximum())                        try { frame.setMaximum(true); } catch (PropertyVetoException e2) { }                    else                        try { frame.setMaximum(false); } catch (PropertyVetoException e3) { }		}             }	}        void finishMouseReleased() {           if (discardRelease) {	     discardRelease = false;	     return;	  }	    if (resizeDir == RESIZE_NONE) {	        getDesktopManager().endDraggingFrame(frame);			dragging = false;	    } else {              Window windowAncestor =                   SwingUtilities.getWindowAncestor(frame);              if (windowAncestor != null) {                  windowAncestor.removeWindowFocusListener(                      getWindowFocusListener());              }	      Container c = frame.getTopLevelAncestor();	      if (c instanceof JFrame) {		((JFrame)frame.getTopLevelAncestor()).getGlassPane().setCursor(                  Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));            	        ((JFrame)frame.getTopLevelAncestor()).getGlassPane(                  ).setVisible(false);	      } else if (c instanceof JApplet) {		((JApplet)c).getGlassPane().setCursor(		  Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));		((JApplet)c).getGlassPane().setVisible(false);	      } else if (c instanceof JWindow) {		((JWindow)c).getGlassPane().setCursor(                  Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));		((JWindow)c).getGlassPane().setVisible(false);	      } else if (c instanceof JDialog) {		((JDialog)c).getGlassPane().setCursor(                  Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));		((JDialog)c).getGlassPane().setVisible(false);	      }	      getDesktopManager().endResizingFrame(frame);              resizing = false;	    }            _x = 0;            _y = 0;            __x = 0;            __y = 0;            startingBounds = null;            resizeDir = RESIZE_NONE;            discardRelease = true;        }                        public void mouseReleased(MouseEvent e) {            finishMouseReleased();        }        public void mousePressed(MouseEvent e) {            Point p = SwingUtilities.convertPoint((Component)e.getSource(),                         e.getX(), e.getY(), null);            __x = e.getX();            __y = e.getY();            _x = p.x;            _y = p.y;            startingBounds = frame.getBounds();	    resizeDir = RESIZE_NONE;            discardRelease = false;            if(!frame.isSelected()) {                try { frame.setSelected(true); }		catch (PropertyVetoException e1) { }            }	    Insets i = frame.getInsets();	    Point ep = new Point(__x, __y);            if (e.getSource() == getNorthPane()) {		Point np = getNorthPane().getLocation();		ep.x += np.x;		ep.y += np.y;	    }            if (e.getSource() == getNorthPane()) {		if (ep.x > i.left && ep.y > i.top && ep.x < frame.getWidth() - i.right) {		    getDesktopManager().beginDraggingFrame(frame);		    dragging = true;		    return;		}            }	    if (!frame.isResizable()) {	      return;	    }	    if (e.getSource() == frame || e.getSource() == getNorthPane()) {                if (ep.x <= i.left) {		    if (ep.y < resizeCornerSize + i.top) {                        resizeDir = NORTH_WEST;                    } else if (ep.y > frame.getHeight()                              - resizeCornerSize - i.bottom) {                        resizeDir = SOUTH_WEST;		    } else {                          resizeDir = WEST;}                } else if (ep.x >= frame.getWidth() - i.right) {		    if (ep.y < resizeCornerSize + i.top) {                        resizeDir = NORTH_EAST;                    } else if (ep.y > frame.getHeight()                               - resizeCornerSize - i.bottom) {                        resizeDir = SOUTH_EAST;		    } else {                                       resizeDir = EAST;		    }                } else if (ep.y <= i.top) {		    if (ep.x < resizeCornerSize + i.left) {                        resizeDir = NORTH_WEST;                    } else if (ep.x > frame.getWidth()                               - resizeCornerSize - i.right) {                        resizeDir = NORTH_EAST;                    } else {                                     resizeDir = NORTH;		    }                } else if (ep.y >= frame.getHeight() - i.bottom) {		    if (ep.x < resizeCornerSize + i.left) {                        resizeDir = SOUTH_WEST;                    } else if (ep.x > frame.getWidth()                              - resizeCornerSize - i.right) {                        resizeDir = SOUTH_EAST;                    } else {                                      resizeDir = SOUTH;		    }                } else {		  /* the mouse press happened inside the frame, not in the		     border */		  discardRelease = true;		  return;		}		Cursor s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);                switch (resizeDir) {		case SOUTH:		  s = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);		  break; 		case NORTH:		  s = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);		  break; 		case WEST:		  s = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);		  break; 		case EAST:		  s = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);		  break; 		case SOUTH_EAST:		  s = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);		  break; 		case SOUTH_WEST:		  s = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);		  break; 		case NORTH_WEST:		  s = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);		  break; 		case NORTH_EAST:		  s = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);		  break;		} 		Container c = frame.getTopLevelAncestor();		if (c instanceof JFrame){		  ((JFrame)c).getGlassPane().setVisible(true);		  ((JFrame)c).getGlassPane().setCursor(s);		} else if (c instanceof JApplet){		  ((JApplet)c).getGlassPane().setVisible(true);		  ((JApplet)c).getGlassPane().setCursor(s);		} else if (c instanceof JWindow){		  ((JWindow)c).getGlassPane().setVisible(true);		  ((JWindow)c).getGlassPane().setCursor(s);		} else if (c instanceof JDialog){		  ((JDialog)c).getGlassPane().setVisible(true);		  ((JDialog)c).getGlassPane().setCursor(s);		}		getDesktopManager().beginResizingFrame(frame, resizeDir);                resizing = true;                Window windowAncestor = SwingUtilities.getWindowAncestor(frame);                if (windowAncestor != null) {                    windowAncestor.addWindowFocusListener(                        getWindowFocusListener());                }		return;            }        }        public void mouseDragged(MouseEvent e) {   	    if ( startingBounds == null ) {	      // (STEVE) Yucky work around for bug ID 4106552		 return;	    }                                                 Point p = SwingUtilities.convertPoint((Component)e.getSource(),                     e.getX(), e.getY(), null);            int deltaX = _x - p.x;            int deltaY = _y - p.y;	    Dimension min = frame.getMinimumSize();	    Dimension max = frame.getMaximumSize();	    int newX, newY, newW, newH;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?