gtkpainter.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,426 行 · 第 1/4 页

JAVA
1,426
字号
/* * @(#)GTKPainter.java	1.69 05/05/27 * * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import sun.swing.plaf.synth.SynthUI;import javax.swing.plaf.synth.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.plaf.*;/** * @version 1.69, 05/27/05 * @author Joshua Outwater * @author Scott Violet */// Need to support:// default_outside_border: Insets when default.// interior_focus: Indicates if focus should appear inside border, or//                       outside border.// focus-line-width: Integer giving size of focus border// focus-padding: Integer giving padding between border and focus//        indicator.// focus-line-pattern: //class GTKPainter extends SynthPainter {    static final GTKPainter INSTANCE = new GTKPainter();    static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);    private static final Insets TEMP_INSETS = new Insets(0, 0, 0, 0);    /**     * Space for the default border.     */    private static final Insets BUTTON_DEFAULT_BORDER_INSETS =                                       new Insets(1, 1, 1, 1);    private GTKEngine getEngine(SynthContext context) {        return ((GTKStyle)context.getStyle()).getEngine(context);    }    private String getName(SynthContext context) {        return (context.getRegion().isSubregion()) ? null :               context.getComponent().getName();    }    Insets getInsets(SynthContext state, Insets insets) {        Region id = state.getRegion();        String name = (id.isSubregion()) ? null :                                           state.getComponent().getName();        if (insets == null) {            insets = new Insets(0, 0, 0, 0);        }        else {            insets.top = insets.bottom = insets.left = insets.right = 0;        }        if (id == Region.BUTTON || id == Region.TOGGLE_BUTTON                || id == Region.CHECK_BOX || id == Region.RADIO_BUTTON                || id == Region.ARROW_BUTTON || id == Region.TOGGLE_BUTTON                || id == Region.RADIO_BUTTON_MENU_ITEM                || id == Region.CHECK_BOX_MENU_ITEM) {            if ("Spinner.previousButton" == name ||                    "Spinner.nextButton" == name) {                return getSpinnerButtonInsets(state, insets);            } else {                return getButtonInsets(state, insets);            }        }        else if (id == Region.MENU               || id == Region.MENU_ITEM) {            return getMenuItemInsets(state, insets);        }        else if (id == Region.FORMATTED_TEXT_FIELD) {            return getTextFieldInsets(state, insets);        }        else if (id == Region.INTERNAL_FRAME) {            insets = Metacity.INSTANCE.getBorderInsets(state, insets);        }        else if (id == Region.DESKTOP_ICON) {	    // Use default 0, 0, 0, 0        }        else if (id == Region.LABEL) {            if ("TableHeader.renderer" == name) {                return getButtonInsets(state, insets);            }            else if ("ComboBox.renderer" == name ||                     "ComboBox.listRenderer" == name) {                return getTextFieldInsets(state, insets);            }            else if ("Tree.cellRenderer" == name) {                return getTreeCellRendererInsets(state, insets);            }        }        else if (id == Region.MENU_BAR) {            return getMenuBarInsets(state, insets);        }        else if (id == Region.OPTION_PANE) {            return getOptionPaneInsets(state, insets);        }        else if (id == Region.POPUP_MENU) {            return getPopupMenuInsets(state, insets);        }        else if (id == Region.PROGRESS_BAR) {            return getProgressBarInsets(state, insets);        }        else if (id == Region.SCROLL_BAR) {            return getScrollBarInsets(state, insets);        }        else if (id == Region.SEPARATOR) {            return getSeparatorInsets(state, insets);        }        else if (id == Region.SLIDER) {            return getSliderInsets(state, insets);        }        else if (id == Region.SLIDER_TRACK) {            return getSliderTrackInsets(state, insets);        }        else if (id == Region.SPINNER) {            return getSpinnerInsets(state, insets);        }        else if (id == Region.TABBED_PANE) {            return getTabbedPaneInsets(state, insets);        }        else if (id == Region.TABBED_PANE_CONTENT) {            return getTabbedPaneContentInsets(state, insets);        }        else if (id == Region.TABBED_PANE_TAB) {            return getTabbedPaneTabInsets(state, insets);        }        else if (id == Region.TEXT_FIELD ||                  id == Region.PASSWORD_FIELD) {            if (name == "Tree.cellEditor") {                return getTreeCellEditorInsets(state, insets);            }            return getTextFieldInsets(state, insets);        }        else if (id == Region.TOOL_BAR) {            return getToolBarInsets(state, insets);        }        else if (id == Region.TOOL_TIP) {            return getToolTipInsets(state, insets);        }        return insets;    }    public void paintCheckBoxBackground(SynthContext context,                                        Graphics g, int x, int y,                                        int w, int h) {        paintRadioButtonCheckBoxBackground(context, getEngine(context),                                           g, x, y, w, h);    }    // FORMATTED_TEXT_FIELD    public void paintFormattedTextFieldBackground(SynthContext context,                                          Graphics g, int x, int y,                                          int w, int h) {        paintTextFieldBackground(context, getEngine(context), g, x, y, w, h);    }    //    // TOOL_DRAG_WINDOW    //    public void paintToolBarDragWindowBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintToolBarBackground(context, getEngine(context), g, x, y, w, h);    }    //    // TOOL_BAR    //    public void paintToolBarBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintToolBarBackground(context, getEngine(context), g, x, y, w, h);    }    //    // PASSWORD_FIELD    //    public void paintPasswordFieldBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintTextFieldBackground(context, g, x, y, w, h);      }        //    // TEXT_FIELD    //    public void paintTextFieldBackground(SynthContext context,                                          Graphics g, int x, int y,                                          int w, int h) {        GTKEngine engine = getEngine(context);        if (getName(context) == "Tree.cellEditor") {            paintTreeCellEditorBackground(context, engine, g, x, y, w, h);        }        else {            paintTextFieldBackground(context, engine, g, x, y, w, h);        }    }    //    // RADIO_BUTTON    //    public void paintRadioButtonBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintRadioButtonCheckBoxBackground(context, getEngine(context),                                           g, x, y, w, h);    }    //    // RADIO_BUTTON_MENU_ITEM    //    public void paintRadioButtonMenuItemBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintRadioButtonCheckBoxMenuItemBackground(context, getEngine(context),                                                   g, x, y, w, h);    }    //     // LABEL    //    public void paintLabelBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        GTKEngine engine = getEngine(context);        String name = getName(context);        if ("TableHeader.renderer" == name ||              name == "GTKFileChooser.directoryListLabel" ||              name == "GTKFileChooser.fileListLabel") {            paintButtonBackground(context, engine, g, x, y, w, h, "button");        }        else if (name == "ComboBox.renderer") {            paintTextFieldBackground(context, engine, g, x, y, w, h);        }    }    //    // INTERNAL_FRAME    //     public void paintInternalFrameBorder(SynthContext context,                                      Graphics g, int x, int y,                                      int w, int h) {        Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);    }    //    // DESKTOP_PANE    //    public void paintDesktopPaneBackground(SynthContext context,                                           Graphics g, int x, int y,                                           int w, int h) {        GTKEngine engine = getEngine(context);        int gtkState = GTKLookAndFeel.synthStateToGTKState(                          context.getRegion(), context.getComponentState());        engine.paintFlatBoxNormal(context, g, gtkState, "base", x, y, w, h);    }    //    // DESKTOP_ICON    //    public void paintDesktopIconBorder(SynthContext context,                                           Graphics g, int x, int y,                                           int w, int h) {        Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);    }    //     // CHECK_BOX_MENU_ITEM    //    public void paintCheckBoxMenuItemBackground(SynthContext context,                                                Graphics g, int x, int y,                                                int w, int h) {        paintRadioButtonCheckBoxMenuItemBackground(context, getEngine(context),                                                   g, x, y, w, h);    }    //    // BUTTON    //    private Insets getButtonInsets(SynthContext context, Insets insets) {        GTKStyle style = (GTKStyle)context.getStyle();        int focusSize = style.getClassSpecificIntValue(context,                                                       "focus-line-width",1);        int focusPad = style.getClassSpecificIntValue(context,                                                      "focus-padding", 1);        int xThickness = style.getXThickness();        int yThickness = style.getYThickness();        int w = focusSize + focusPad + xThickness;        int h = focusSize + focusPad + yThickness;        Component component = context.getComponent();        insets.left = insets.right = w;        insets.top = insets.bottom = h;        if ((component instanceof JButton) &&                       ((JButton)component).isDefaultCapable()) {            Insets defaultInsets = style.getClassSpecificInsetsValue(context,                          "default-border", BUTTON_DEFAULT_BORDER_INSETS);            insets.left += defaultInsets.left;            insets.right += defaultInsets.right;            insets.top += defaultInsets.top;            insets.bottom += defaultInsets.bottom;        }        return insets;    }    public void paintButtonBackground(SynthContext context,                                      Graphics g, int x, int y,                                      int w, int h) {        String name = getName(context);        if (name != null && name.startsWith("InternalFrameTitlePane.")) {            Metacity.INSTANCE.paintButtonBackground(context, g, x, y, w, h);        } else {            paintButtonBackground(context, getEngine(context), g, x, y, w, h,                                  "button");        }    }    private void paintButtonBackground(SynthContext context, GTKEngine engine,                                       Graphics g, int x, int y, int w, int h,                                       String detail) {        // paint the default shadow        int state = context.getComponentState();        int gtkState = GTKLookAndFeel.synthStateToGTKState(                                      context.getRegion(), state);        GTKStyle style = (GTKStyle)context.getStyle();        boolean interiorFocus = style.getClassSpecificBoolValue(context,                                                 "interior-focus", true);        int focusSize = style.getClassSpecificIntValue(context,                                                       "focus-line-width",1);        int focusPad = style.getClassSpecificIntValue(context, "focus-padding",                                                      1);        int totalFocusSize = focusSize + focusPad;        int xThickness = style.getXThickness();        int yThickness = style.getYThickness();        Component component = context.getComponent();        AbstractButton button = (component instanceof AbstractButton) ?                                (AbstractButton)component : null;        boolean paintBG = (button == null || (button.isContentAreaFilled() &&                                              button.isBorderPainted()));        // Paint the default indicator        if ((component instanceof JButton) &&                       ((JButton)component).isDefaultCapable()) {            Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(                      context, "default-border", BUTTON_DEFAULT_BORDER_INSETS);            if (paintBG && (state & SynthConstants.DEFAULT) ==

⌨️ 快捷键说明

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