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

📄 synthinternalframetitlepane.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            else if (frame.isClosable()) {                lastButton = closeButton;            }            int maxX;            int minX;            boolean ltr = SynthLookAndFeel.isLeftToRight(frame);            int titleAlignment = this.titleAlignment;            if (ltr) {                if (lastButton != null) {                    maxX = lastButton.getX() - titleSpacing;                }                else {                    maxX = frame.getWidth() - frame.getInsets().right -                           titleSpacing;                }                minX = menuButton.getX() + menuButton.getWidth() +                       titleSpacing;            }            else {                if (lastButton != null) {                    minX = lastButton.getX() + lastButton.getWidth() +                           titleSpacing;                }                else {                    minX = frame.getInsets().left + titleSpacing;                }                maxX = menuButton.getX() - titleSpacing;                if (titleAlignment == SwingConstants.LEADING) {                    titleAlignment = SwingConstants.TRAILING;                }                else if (titleAlignment == SwingConstants.TRAILING) {                    titleAlignment = SwingConstants.LEADING;                }            }            String clippedTitle = getTitle(title, fm, maxX - minX);            if (clippedTitle == title) {                // String fit, align as necessary.                if (titleAlignment == SwingConstants.TRAILING) {                    minX = maxX - style.getGraphicsUtils(context).                        computeStringWidth(context, g.getFont(), fm, title);                }                else if (titleAlignment == SwingConstants.CENTER) {                    int width = style.getGraphicsUtils(context).                           computeStringWidth(context, g.getFont(), fm, title);                    minX = Math.max(minX, (getWidth() - width) / 2);                    minX = Math.min(maxX - width, minX);                }            }            style.getGraphicsUtils(context).paintText(                context, g, clippedTitle, minX, baseline - fm.getAscent(), -1);	}    }    public void paintBorder(SynthContext context, Graphics g, int x,                            int y, int w, int h) {        context.getPainter().paintInternalFrameTitlePaneBorder(context,                                                            g, x, y, w, h);    }    protected LayoutManager createLayout() {        SynthContext context = getContext(this);	LayoutManager lm =	    (LayoutManager)style.get(context, "InternalFrameTitlePane.titlePaneLayout");	context.dispose();        return (lm != null) ? lm : new SynthTitlePaneLayout();    }    public void propertyChange(PropertyChangeEvent evt) {        if (evt.getSource() == this) {            if (SynthLookAndFeel.shouldUpdateStyle(evt)) {                updateStyle(this);            }        }        else {            // Changes for the internal frame            if (evt.getPropertyName() == JInternalFrame.FRAME_ICON_PROPERTY) {                updateMenuIcon();            }        }    }    /**     * Resets the menuButton icon to match that of the frame.     */    private void updateMenuIcon() {        Icon frameIcon = frame.getFrameIcon();        SynthContext context = getContext(this);        if (frameIcon != null) {            Dimension maxSize = (Dimension)context.getStyle().get(context,                                "InternalFrameTitlePane.maxFrameIconSize");            int maxWidth = 16;            int maxHeight = 16;            if (maxSize != null) {                maxWidth = maxSize.width;                maxHeight = maxSize.height;            }            if ((frameIcon.getIconWidth() > maxWidth ||                     frameIcon.getIconHeight() > maxHeight) &&                     (frameIcon instanceof ImageIcon)) {                frameIcon = new ImageIcon(((ImageIcon)frameIcon).                             getImage().getScaledInstance(maxWidth, maxHeight,                             Image.SCALE_SMOOTH));            }        }        context.dispose();        menuButton.setIcon(frameIcon);    }    class SynthTitlePaneLayout implements LayoutManager {        public void addLayoutComponent(String name, Component c) {}        public void removeLayoutComponent(Component c) {}            public Dimension preferredLayoutSize(Container c)  {	    return minimumLayoutSize(c);	}            public Dimension minimumLayoutSize(Container c) {            SynthContext context = getContext(                             SynthInternalFrameTitlePane.this);            int width = 0;            int height = 0;             int buttonCount = 0;            Dimension pref;            if (frame.isClosable()) {                pref = closeButton.getPreferredSize();                width += pref.width;                height = Math.max(pref.height, height);                buttonCount++;            }            if (frame.isMaximizable()) {                pref = maxButton.getPreferredSize();                width += pref.width;                height = Math.max(pref.height, height);                buttonCount++;            }            if (frame.isIconifiable()) {                pref = iconButton.getPreferredSize();                width += pref.width;                height = Math.max(pref.height, height);                buttonCount++;            }            pref = menuButton.getPreferredSize();            width += pref.width;            height = Math.max(pref.height, height);            width += Math.max(0, (buttonCount - 1) * buttonSpacing);            FontMetrics fm = SynthInternalFrameTitlePane.this.getFontMetrics(                                          getFont());            SynthGraphicsUtils graphicsUtils = context.getStyle().                                       getGraphicsUtils(context);            String frameTitle = frame.getTitle();            int title_w = frameTitle != null ? graphicsUtils.                               computeStringWidth(context, fm.getFont(),                               fm, frameTitle) : 0;            int title_length = frameTitle != null ? frameTitle.length() : 0;            // Leave room for three characters in the title.            if (title_length > 3) {                int subtitle_w = graphicsUtils.computeStringWidth(context,                    fm.getFont(), fm, frameTitle.substring(0, 3) + "...");                width += (title_w < subtitle_w) ? title_w : subtitle_w;            } else {                width += title_w;            }            height = Math.max(fm.getHeight() + 2, height);            width += titleSpacing + titleSpacing;            Insets insets = getInsets();            height += insets.top + insets.bottom;            width += insets.left + insets.right;            context.dispose();            return new Dimension(width, height);	}            private int center(Component c, Insets insets, int x,                           boolean trailing) {            Dimension pref = c.getPreferredSize();            if (trailing) {                x -= pref.width;            }            c.setBounds(x, insets.top +                        (getHeight() - insets.top - insets.bottom -                         pref.height) / 2, pref.width, pref.height);            if (pref.width > 0) {                if (trailing) {                    return x - buttonSpacing;                }                return x + pref.width + buttonSpacing;            }            return x;        }        public void layoutContainer(Container c) {            Insets insets = c.getInsets();            Dimension pref;            if (SynthLookAndFeel.isLeftToRight(frame)) {                center(menuButton, insets, insets.left, false);                int x = getWidth() - insets.right;                if (frame.isClosable()) {                    x = center(closeButton, insets, x, true);                }                if (frame.isMaximizable()) {                    x = center(maxButton, insets, x, true);                }                if (frame.isIconifiable()) {                    x = center(iconButton, insets, x, true);                }            }            else {                center(menuButton, insets, getWidth() - insets.right,                       true);                int x = insets.left;                if (frame.isClosable()) {                    x = center(closeButton, insets, x, false);                }                if (frame.isMaximizable()) {                    x = center(maxButton, insets, x, false);                }                if (frame.isIconifiable()) {                    x = center(iconButton, insets, x, false);                }            }        }    }    private JButton createNoFocusButton() {        JButton button = new JButton();        button.setFocusable(false);        button.setMargin(new Insets(0,0,0,0));        return button;    }}

⌨️ 快捷键说明

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