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

📄 smoothgradienttitlepane.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        boolean isSelected = (window == null) ? true : window.isActive();        int width = getWidth();        int height = getHeight();        Color background;        Color foreground;        Color darkShadow;        if (isSelected) {            background = activeBackground;            foreground = activeForeground;            darkShadow = activeShadow;        } else {            background = inactiveBackground;            foreground = inactiveForeground;            darkShadow = inactiveShadow;        }        g.setColor(background);        g.fillRect(0, 0, width, height);        g.setColor( darkShadow );        g.drawLine ( 0, height - 1, width, height -1);        g.drawLine ( 0, 0, 0 ,0);            g.drawLine ( width - 1, 0 , width -1, 0);        int xOffset = leftToRight ? 5 : width - 5;        if (getWindowDecorationStyle() == JRootPane.FRAME) {            xOffset += leftToRight ? IMAGE_WIDTH + 5 : - IMAGE_WIDTH - 5;        }                String theTitle = getTitle();        if (theTitle != null) {            Font f = getFont();            FontMetrics fm = g.getFontMetrics();            g.setColor(foreground);            int yOffset = ( (height - fm.getHeight() ) / 2 ) + fm.getAscent();            Rectangle rect = new Rectangle(0, 0, 0, 0);            if (iconifyButton != null && iconifyButton.getParent() != null) {                rect = iconifyButton.getBounds();            }            int titleW;            if( leftToRight ) {                if (rect.x == 0) {                    rect.x = window.getWidth() - window.getInsets().right-2;                }                titleW = rect.x - xOffset - 4;                theTitle = clippedText(theTitle, fm, titleW);            } else {                titleW = xOffset - rect.x - rect.width - 4;                theTitle = clippedText(theTitle, fm, titleW);                xOffset -= SwingUtilities.computeStringWidth(fm, theTitle);            }            int titleLength = SwingUtilities.computeStringWidth(fm, theTitle);            g.drawString( theTitle, xOffset, yOffset );            xOffset += leftToRight ? titleLength + 5  : -5;        }        Rectangle r = new Rectangle(1,0,width,height);        SmoothGradientUtils.addLight3DEffekt(g, r, true);    }    /**     * Convenience method to clip the passed in text to the specified     * size.     */    private String clippedText(String text, FontMetrics fm,                                 int availTextWidth) {        if ((text == null) || (text.equals("")))  {            return "";        }        int textWidth = SwingUtilities.computeStringWidth(fm, text);        String clipString = "...";        if (textWidth > availTextWidth) {            int totalWidth = SwingUtilities.computeStringWidth(fm, clipString);            int nChars;            for(nChars = 0; nChars < text.length(); nChars++) {                totalWidth += fm.charWidth(text.charAt(nChars));                if (totalWidth > availTextWidth) {                    break;                }            }            text = text.substring(0, nChars) + clipString;        }        return text;    }    /**     * Actions used to <code>close</code> the <code>Window</code>.     */    private class CloseAction extends AbstractAction {        public CloseAction() {            super(UIManager.getString("MetalTitlePane.closeTitle",                                      getLocale()));        }        public void actionPerformed(ActionEvent e) {            close();        }          }    /**     * Actions used to <code>iconfiy</code> the <code>Frame</code>.     */    private class IconifyAction extends AbstractAction {        public IconifyAction() {            super(UIManager.getString("MetalTitlePane.iconifyTitle",                                      getLocale()));        }        public void actionPerformed(ActionEvent e) {            iconify();        }    }     /**     * Actions used to <code>restore</code> the <code>Frame</code>.     */    private class RestoreAction extends AbstractAction {        public RestoreAction() {            super(UIManager.getString                  ("MetalTitlePane.restoreTitle", getLocale()));        }        public void actionPerformed(ActionEvent e) {            restore();        }    }    /**     * Actions used to <code>restore</code> the <code>Frame</code>.     */    private class MaximizeAction extends AbstractAction {        public MaximizeAction() {            super(UIManager.getString("MetalTitlePane.maximizeTitle",                                      getLocale()));        }        public void actionPerformed(ActionEvent e) {            maximize();        }    }    /**     * Class responsible for drawing the system menu. Looks up the     * image to draw from the Frame associated with the     * <code>JRootPane</code>.     */    private class SystemMenuBar extends JMenuBar {        public void paint(Graphics g) {            Frame frame = getFrame();            if (isOpaque()) {                g.setColor(getBackground());                g.fillRect(0, 0, getWidth(), getHeight());            }            Image image = (frame != null) ? frame.getIconImage() : null;            if (image != null) {                g.drawImage(image, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);            } else {                Icon icon = UIManager.getIcon("InternalFrame.icon");                if (icon != null) {                    icon.paintIcon(this, g, 0, 0);                }            }        }        public Dimension getMinimumSize() {            return getPreferredSize();        }        public Dimension getPreferredSize() {            Dimension size = super.getPreferredSize();            return new Dimension(Math.max(IMAGE_WIDTH, size.width),                                 Math.max(size.height, IMAGE_HEIGHT));        }    }    /**     * This inner class is marked &quot;public&quot; due to a compiler bug.     * This class should be treated as a &quot;protected&quot; inner class.     * Instantiate it only within subclasses of <Foo>.     */    private class TitlePaneLayout implements LayoutManager {          public void addLayoutComponent(String name, Component c) {}        public void removeLayoutComponent(Component c) {}           public Dimension preferredLayoutSize(Container c)  {            int height = computeHeight();            return new Dimension(height, height);        }                public Dimension minimumLayoutSize(Container c) {            return preferredLayoutSize(c);        }             private int computeHeight() {                  FontMetrics fm = getFontMetrics(getFont());//                = Toolkit.getDefaultToolkit().getFontMetrics(getFont());            int fontHeight = fm.getHeight();            fontHeight += 7;            int iconHeight = 0;            if (getWindowDecorationStyle() == JRootPane.FRAME) {                iconHeight = IMAGE_HEIGHT;            }            int finalHeight = Math.max( fontHeight, iconHeight );            return finalHeight;        }                                public void layoutContainer(Container c) {            if (getWindowDecorationStyle() != JRootPane.FRAME) {                buttonsWidth = 0;                return;            }            boolean leftToRight = (window == null) ?                               getRootPane().getComponentOrientation().isLeftToRight() :                               window.getComponentOrientation().isLeftToRight();            int w = getWidth();            int x;             int y = 3;            int spacing;            int buttonHeight;             int buttonWidth;                        if (closeButton != null && closeButton.getIcon() != null) {                buttonHeight = closeButton.getIcon().getIconHeight();                 buttonWidth = closeButton.getIcon().getIconWidth();            }            else {                buttonHeight = IMAGE_HEIGHT;                buttonWidth = IMAGE_WIDTH;            }                        // assumes all buttons have the same dimensions            // these dimensions include the borders            x = leftToRight ? w : 0;            spacing = 5;            x = leftToRight ? spacing : w - buttonWidth - spacing;            menuBar.setBounds(x, y, buttonWidth, buttonHeight);            x = leftToRight ? w : 0;            spacing = 4;            x += leftToRight ? -spacing -buttonWidth : spacing;            if (closeButton != null) {                closeButton.setBounds(x, y, buttonWidth, buttonHeight);            }            if( !leftToRight ) x += buttonWidth;            if (Toolkit.getDefaultToolkit().isFrameStateSupported(                    Frame.MAXIMIZED_BOTH)) {                if (toggleButton.getParent() != null) {                    spacing = 1;//10                    x += leftToRight ? -spacing -buttonWidth : spacing;                    toggleButton.setBounds(x, y, buttonWidth, buttonHeight);                    if (!leftToRight) {                        x += buttonWidth;                    }                }            }            if (iconifyButton != null && iconifyButton.getParent() != null) {                spacing = 1;                x += leftToRight ? -spacing -buttonWidth : spacing;                iconifyButton.setBounds(x, y, buttonWidth, buttonHeight);                if (!leftToRight) {                    x += buttonWidth;                }            }            buttonsWidth = leftToRight ? w - x : x;        }    }    /**     * PropertyChangeListener installed on the Window. Updates the necessary     * state as the state of the Window changes.     */    private class PropertyChangeHandler implements PropertyChangeListener {        public void propertyChange(PropertyChangeEvent pce) {            String name = pce.getPropertyName();            // Frame.state isn't currently bound.            if ("resizable".equals(name) || "state".equals(name)) {                Frame frame = getFrame();                if (frame != null) {                    setState(frame.getExtendedState(), true);                }                if ("resizable".equals(name)) {                    getRootPane().repaint();                }            }            else if ("title".equals(name)) {                repaint();            }            else if ("componentOrientation".equals(name)) {                revalidate();                repaint();            }        }    }    /**     * WindowListener installed on the Window, updates the state as necessary.     */    private class WindowHandler extends WindowAdapter {        public void windowActivated(WindowEvent ev) {            setActive(true);        }        public void windowDeactivated(WindowEvent ev) {            setActive(false);        }    }}

⌨️ 快捷键说明

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