⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicinternalframeui.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	// Also, no longer registering on the desktopicon, the previous	// action did nothing.	InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);	SwingUtilities.replaceUIInputMap(frame,				      JComponent.WHEN_IN_FOCUSED_WINDOW, map);	//ActionMap actionMap = getActionMap();	//SwingUtilities.replaceUIActionMap(frame, actionMap);    }    protected void setupMenuCloseKey(){    }          public JComponent getNorthPane() {        return northPane;    }    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 {        /**         * Detects changes in state from the JInternalFrame and handles         * actions.         */        public void propertyChange(PropertyChangeEvent evt) {            String prop = (String)evt.getPropertyName();            JInternalFrame f = (JInternalFrame)evt.getSource();            Object newValue = evt.getNewValue();            Object oldValue = evt.getOldValue();            if (JInternalFrame.IS_CLOSED_PROPERTY.equals(prop)) {                if (newValue == Boolean.TRUE) {                    if ((frame.getParent() != null) && componentListenerAdded) {                        frame.getParent().removeComponentListener(                                componentListener);                    }                    closeFrame(f);                }            } else if (JInternalFrame.IS_MAXIMUM_PROPERTY.equals(prop)) {                if(newValue == Boolean.TRUE) {                    maximizeFrame(f);                } else {                    minimizeFrame(f);                }            } else if(JInternalFrame.IS_ICON_PROPERTY.equals(prop)) {                if (newValue == Boolean.TRUE) {                    iconifyFrame(f);                } else {                    deiconifyFrame(f);                }            } else if (JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) {                Component glassPane = f.getGlassPane();                if (newValue == Boolean.TRUE && oldValue == Boolean.FALSE) {                    activateFrame(f);                    glassPane.setVisible(false);                } else if (newValue == Boolean.FALSE &&                           oldValue == Boolean.TRUE) {                    deactivateFrame(f);                    glassPane.setVisible(true);                }            } else if (prop.equals("ancestor")) {                if (frame.getParent() != null) {                    parentBounds = f.getParent().getBounds();                } else {                    parentBounds = null;                }                if ((frame.getParent() != null) && !componentListenerAdded) {                    f.getParent().addComponentListener(componentListener);                    componentListenerAdded = true;                } else if ((newValue == null) && componentListenerAdded) {                    if (f.getParent() != null) {                        f.getParent().removeComponentListener(                                componentListener);                    }                    componentListenerAdded = false;                }            } else if (JInternalFrame.TITLE_PROPERTY.equals(prop) ||                    prop.equals("closable") || prop.equals("iconable") ||                    prop.equals("maximizable")) {                Dimension dim = frame.getMinimumSize();                Dimension frame_dim = frame.getSize();                if (dim.width > frame_dim.width) {                    frame.setSize(dim.width, frame_dim.height);                }            }        }    }  public class InternalFrameLayout implements LayoutManager {    public void addLayoutComponent(String name, Component c) {}    public void removeLayoutComponent(Component c) {}        public Dimension preferredLayoutSize(Container c)  {	Dimension result;	Insets i = frame.getInsets();		result = new Dimension(frame.getRootPane().getPreferredSize());	result.width += i.left + i.right;	result.height += i.top + i.bottom;        if(getNorthPane() != null) {	    Dimension d = getNorthPane().getPreferredSize();	    result.width = Math.max(d.width, result.width);            result.height += d.height;	}        if(getSouthPane() != null) {	    Dimension d = getSouthPane().getPreferredSize();	    result.width = Math.max(d.width, result.width);            result.height += d.height;	}        if(getEastPane() != null) {	    Dimension d = getEastPane().getPreferredSize();            result.width += d.width;	    result.height = Math.max(d.height, result.height);	}        if(getWestPane() != null) {	    Dimension d = getWestPane().getPreferredSize();            result.width += d.width;	    result.height = Math.max(d.height, result.height);	}	return result;    }        public Dimension minimumLayoutSize(Container c) {        // The minimum size of the internal frame only takes into account the        // title pane since you are allowed to resize the frames to the point        // where just the title pane is visible.        Dimension result = new Dimension();        if (getNorthPane() != null &&            getNorthPane() instanceof BasicInternalFrameTitlePane) {              result = new Dimension(getNorthPane().getMinimumSize());        }	Insets i = frame.getInsets();        result.width += i.left + i.right;	result.height += i.top + i.bottom;		return result;    }        public void layoutContainer(Container c) {        Insets i = frame.getInsets();        int cx, cy, cw, ch;                cx = i.left;        cy = i.top;        cw = frame.getWidth() - i.left - i.right;        ch = frame.getHeight() - i.top - i.bottom;                if(getNorthPane() != null) {            Dimension size = getNorthPane().getPreferredSize();            getNorthPane().setBounds(cx, cy, cw, size.height);            cy += size.height;            ch -= size.height;        }        if(getSouthPane() != null) {            Dimension size = getSouthPane().getPreferredSize();            getSouthPane().setBounds(cx, frame.getHeight()                                                 - i.bottom - size.height,                                                 cw, size.height);            ch -= size.height;        }        if(getWestPane() != null) {            Dimension size = getWestPane().getPreferredSize();            getWestPane().setBounds(cx, cy, size.width, ch);            cw -= size.width;            cx += size.width;                   }        if(getEastPane() != null) {            Dimension size = getEastPane().getPreferredSize();            getEastPane().setBounds(cw - size.width, cy, size.width, ch);            cw -= size.width;                   }                if(frame.getRootPane() != null) {            frame.getRootPane().setBounds(cx, cy, cw, ch);        }    }  }/// 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	fireAudioAction("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	fireAudioAction("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.	    fireAudioAction("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	fireAudioAction("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.	    fireAudioAction("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);    }    /**     * Convenience method for firing off the auditory cue actions.     *     * @since 1.4     */    private void fireAudioAction (String actionName) {	ActionMap map = frame.getActionMap();	if (map != null) {	    Action audioAction = map.get(actionName);	    if (audioAction != null) {		// pass off firing the Action to a utility method		BasicLookAndFeel lf = (BasicLookAndFeel)		                       UIManager.getLookAndFeel();		lf.playSound(audioAction);	    }	}    }    /////////////////////////////////////////////////////////////////////////    /// 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) { }		}             }

⌨️ 快捷键说明

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