synthinternalframeui.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,486 行 · 第 1/4 页

JAVA
1,486
字号
        }        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 void update(Graphics g, JComponent c) {        SynthContext context = getContext(c);        SynthLookAndFeel.update(context, g);        paint(context, g);        context.dispose();    }    public void paint(Graphics g, JComponent c) {        SynthContext context = getContext(c);        paint(context, g);        context.dispose();    }    protected void paint(SynthContext context, Graphics g) {    }    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();            // ASSERT(frame == f) - This should always be true            if (SynthLookAndFeel.shouldUpdateStyle(evt)) {                fetchStyle((JInternalFrame)evt.getSource());            }            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.removeMouseListener(glassPaneDispatcher);                    // glassPane.removeMouseMotionListener(glassPaneDispatcher);                    glassPane.setVisible(false);                } else if (newValue == Boolean.FALSE &&                        oldValue == Boolean.TRUE) {                    deactivateFrame(f);                    // glassPane.addMouseListener(glassPaneDispatcher);                    // glassPane.addMouseMotionListener(glassPaneDispatcher);                    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);                }            }        }    }    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 SynthInternalFrameTitlePane) {                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 = 0;            cw = frame.getWidth() - i.left - i.right;            ch = frame.getHeight() - i.bottom;                    if (getNorthPane() != null) {                Dimension size = getNorthPane().getPreferredSize();		// Ignore insets when placing the title pane		getNorthPane().setBounds(0, 0, frame.getWidth(), 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        SynthLookAndFeel.playSound(f, "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        SynthLookAndFeel.playSound(f, "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.            SynthLookAndFeel.playSound(f, "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        SynthLookAndFeel.playSound(f, "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.            SynthLookAndFeel.playSound(f, "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) { }                    }                }             }        }        public void mouseReleased(MouseEvent e) {            if (discardRelease) {                discardRelease = false;                return;            }

⌨️ 快捷键说明

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