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

📄 smoothgradienttitlepane.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * Installs the fonts and necessary properties on the MetalTitlePane.     */    private void installDefaults() {        setFont(UIManager.getFont("InternalFrame.titleFont", getLocale()));    }        /**     * Uninstalls any previously installed UI values.     */    private void uninstallDefaults() {    }    /**     * Returns the <code>JMenuBar</code> displaying the appropriate      * system menu items.     */    protected JMenuBar createMenuBar() {        menuBar = new SystemMenuBar();        menuBar.setFocusable(false);        menuBar.setBorderPainted(true);        menuBar.add(createMenu());        return menuBar;    }    /**     * Closes the Window.     */    private void close() {        Window window = getWindow();        if (window != null) {            window.dispatchEvent(new WindowEvent(                                 window, WindowEvent.WINDOW_CLOSING));        }    }    /**     * Iconifies the Frame.     */    private void iconify() {        Frame frame = getFrame();        if (frame != null) {            frame.setExtendedState(state | Frame.ICONIFIED);        }    }    /**     * Maximizes the Frame.     */    private void maximize() {        Frame frame = getFrame();        if (frame != null) {            frame.setExtendedState(state | Frame.MAXIMIZED_BOTH);        }    }    /**     * Restores the Frame size.     */    private void restore() {        Frame frame = getFrame();        if (frame == null) {            return;        }        if ((state & Frame.ICONIFIED) != 0) {            frame.setExtendedState(state & ~Frame.ICONIFIED);        } else {            frame.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);        }    }    /**     * Create the <code>Action</code>s that get associated with the     * buttons and menu items.     */    private void createActions() {        closeAction = new CloseAction();        iconifyAction = new IconifyAction();        restoreAction = new RestoreAction();        maximizeAction = new MaximizeAction();    }    /**     * Returns the <code>JMenu</code> displaying the appropriate menu items     * for manipulating the Frame.     */    private JMenu createMenu() {        JMenu menu = new JMenu("");        if (getWindowDecorationStyle() == JRootPane.FRAME) {            addMenuItems(menu);        }        return menu;    }    /**     * Adds the necessary <code>JMenuItem</code>s to the passed in menu.     */    private void addMenuItems(JMenu menu) {        Locale locale = getRootPane().getLocale();        JMenuItem mi = menu.add(restoreAction);        int mnemonic = SmoothGradientUtils.getInt("MetalTitlePane.restoreMnemonic", -1);        if (mnemonic != -1) {            mi.setMnemonic(mnemonic);        }        mi = menu.add(iconifyAction);        mnemonic = SmoothGradientUtils.getInt("MetalTitlePane.iconifyMnemonic", -1);        if (mnemonic != -1) {            mi.setMnemonic(mnemonic);        }        if (Toolkit.getDefaultToolkit().isFrameStateSupported(                Frame.MAXIMIZED_BOTH)) {            mi = menu.add(maximizeAction);            mnemonic =                SmoothGradientUtils.getInt("MetalTitlePane.maximizeMnemonic", -1);            if (mnemonic != -1) {                mi.setMnemonic(mnemonic);            }        }        menu.add(new JSeparator());        mi = menu.add(closeAction);        mnemonic = SmoothGradientUtils.getInt("MetalTitlePane.closeMnemonic", -1);        if (mnemonic != -1) {            mi.setMnemonic(mnemonic);        }    }    /**     * Returns a <code>JButton</code> appropriate for placement on the     * TitlePane.     */    private JButton createTitleButton() {        JButton button = new JButton();        button.setFocusPainted(false);        button.setFocusable(false);        button.setOpaque(true);        return button;    }    /**     * Creates the Buttons that will be placed on the TitlePane.     */    private void createButtons() {        maximizeIcon = UIManager.getIcon("InternalFrame.maximizeIcon");        minimizeIcon = UIManager.getIcon("InternalFrame.minimizeIcon");        closeButton = createTitleButton();        closeButton.setAction(closeAction);        closeButton.setText(null);        closeButton.putClientProperty("paintActive", Boolean.TRUE);        closeButton.setBorder(handyEmptyBorder);        closeButton.getAccessibleContext().setAccessibleName("Close");        closeButton.setIcon(UIManager.getIcon("InternalFrame.closeIcon"));        iconifyButton = createTitleButton();        iconifyButton.setAction(iconifyAction);        iconifyButton.setText(null);        iconifyButton.putClientProperty("paintActive", Boolean.TRUE);        iconifyButton.setBorder(handyEmptyBorder);        iconifyButton.getAccessibleContext().setAccessibleName("Iconify");        iconifyButton.setIcon(UIManager.getIcon("InternalFrame.iconifyIcon"));        toggleButton = createTitleButton();        toggleButton.setAction(restoreAction);        toggleButton.putClientProperty("paintActive", Boolean.TRUE);        toggleButton.setBorder(handyEmptyBorder);        toggleButton.getAccessibleContext().setAccessibleName("Maximize");        toggleButton.setIcon(maximizeIcon);    }    /**     * Returns the <code>LayoutManager</code> that should be installed on     * the <code>MetalTitlePane</code>.     */    private LayoutManager createLayout() {        return new TitlePaneLayout();    }    /**     * Updates state dependant upon the Window's active state.     */    private void setActive(boolean isActive) {        if (getWindowDecorationStyle() == JRootPane.FRAME) {            Boolean activeB = isActive ? Boolean.TRUE : Boolean.FALSE;            iconifyButton.putClientProperty("paintActive", activeB);            closeButton.putClientProperty("paintActive", activeB);            toggleButton.putClientProperty("paintActive", activeB);        }        // Repaint the whole thing as the Borders that are used have        // different colors for active vs inactive        getRootPane().repaint();    }    /**     * Sets the state of the Window.     */    private void setState(int state) {        setState(state, false);    }    /**     * Sets the state of the window. If <code>updateRegardless</code> is     * true and the state has not changed, this will update anyway.     */    private void setState(int state, boolean updateRegardless) {        Window w = getWindow();        if (w != null && getWindowDecorationStyle() == JRootPane.FRAME) {            if (this.state == state && !updateRegardless) {                return;            }            Frame frame = getFrame();            if (frame != null) {                JRootPane rootPane = getRootPane();                if (((state & Frame.MAXIMIZED_BOTH) != 0) &&                        (rootPane.getBorder() == null ||                        (rootPane.getBorder() instanceof UIResource)) &&                            frame.isShowing()) {                    rootPane.setBorder(null);                }                else if ((state & Frame.MAXIMIZED_BOTH) == 0) {                    // This is a croak, if state becomes bound, this can                    // be nuked.//                    rootPaneUI.installBorder(rootPane);                }                if (frame.isResizable()) {                    if ((state & Frame.MAXIMIZED_BOTH) != 0) {                        updateToggleButton(restoreAction, minimizeIcon);                        maximizeAction.setEnabled(false);                        restoreAction.setEnabled(true);                    }                    else {                        updateToggleButton(maximizeAction, maximizeIcon);                        maximizeAction.setEnabled(true);                        restoreAction.setEnabled(false);                    }                    if (toggleButton.getParent() == null ||                        iconifyButton.getParent() == null) {                        add(toggleButton);                        add(iconifyButton);                        revalidate();                        repaint();                    }                    toggleButton.setText(null);                }                else {                    maximizeAction.setEnabled(false);                    restoreAction.setEnabled(false);                    if (toggleButton.getParent() != null) {                        remove(toggleButton);                        revalidate();                        repaint();                    }                }            }            else {                // Not contained in a Frame                maximizeAction.setEnabled(false);                restoreAction.setEnabled(false);                iconifyAction.setEnabled(false);                remove(toggleButton);                remove(iconifyButton);                revalidate();                repaint();            }            closeAction.setEnabled(true);            this.state = state;        }    }    /**     * Updates the toggle button to contain the Icon <code>icon</code>, and     * Action <code>action</code>.     */    private void updateToggleButton(Action action, Icon icon) {        toggleButton.setAction(action);        toggleButton.setIcon(icon);        toggleButton.setText(null);    }    /**     * Returns the Frame rendering in. This will return null if the     * <code>JRootPane</code> is not contained in a <code>Frame</code>.     */    private Frame getFrame() {        Window window = getWindow();        if (window instanceof Frame) {            return (Frame)window;        }        return null;    }    /**     * Returns the <code>Window</code> the <code>JRootPane</code> is     * contained in. This will return null if there is no parent ancestor     * of the <code>JRootPane</code>.     */    private Window getWindow() {        return window;    }    /**     * Returns the String to display as the title.     */    private String getTitle() {        Window w = getWindow();        if (w instanceof Frame) {            return ((Frame)w).getTitle();        }        else if (w instanceof Dialog) {            return ((Dialog)w).getTitle();        }        return null;    }    /**     * Renders the TitlePane.     */    public void paintComponent(Graphics g)  {        // As state isn't bound, we need a convenience place to check        // if it has changed. Changing the state typically changes the        if (getFrame() != null) {            setState(getFrame().getExtendedState());        }        Window window = getWindow();        boolean leftToRight = (window == null) ?                               getRootPane().getComponentOrientation().isLeftToRight() :                               window.getComponentOrientation().isLeftToRight();

⌨️ 快捷键说明

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