gtkpainter.java

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

JAVA
1,333
字号
/* * @(#)GTKPainter.java	1.55 03/05/05 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.plaf.*;/** * @version 1.55, 05/05/03 * @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);    public void paint(SynthContext context, Object paintKey, Graphics g,                      int x, int y, int w, int h) {        Region id = context.getRegion();        String name = (id.isSubregion()) ? null :                                           context.getComponent().getName();        GTKEngine engine = ((GTKStyle)context.getStyle()).getEngine(context);        if (paintKey == "background") {            if (!id.isSubregion()) {                // Offset by the insets, if necessary.                Border border = context.getComponent().getBorder();                if (border != null && !(border instanceof UIResource)) {                    Insets insets = context.getComponent().getInsets(                                            TEMP_INSETS);                    if (insets != null) {                        x += insets.left;                        y += insets.right;                        w -= (insets.left + insets.right);                        h -= (insets.top + insets.bottom);                    }                }            }            if (id == Region.ARROW_BUTTON) {                paintArrowButtonBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.BUTTON) {                if (name != null &&                        name.startsWith("InternalFrameTitlePane.")) {                    Metacity.INSTANCE.paintButtonBackground(context,                            g, x, y, w, h);                } else {                    paintButtonBackground(context, engine, g, x, y, w, h,                                          "button");                }            }            else if (id == Region.FORMATTED_TEXT_FIELD) {                paintTextFieldBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.LABEL) {                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);                }            }            else if (id == Region.LIST) {                paintListBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.MENU) {                paintMenuBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.MENU_BAR) {                paintMenuBarBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.MENU_ITEM) {                paintMenuItemBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.POPUP_MENU) {                paintPopupMenuBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.PROGRESS_BAR) {                paintProgressBarBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {                paintCheckButtonBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.CHECK_BOX_MENU_ITEM                    || id == Region.RADIO_BUTTON_MENU_ITEM) {                paintCheckButtonMenuItemBackground(context, engine, g,                        x, y, w, h);            }            else if (id == Region.ROOT_PANE) {                paintRootPaneBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.SCROLL_BAR) {                paintScrollBarBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.SCROLL_BAR_THUMB) {                paintScrollBarThumbBackground(context, engine, g, x, y, w, h);            }            /*            else if (id == Region.SCROLL_PANE) {                paintScrollPaneBackground(context, engine, g, x, y, w, h);            }            */            else if (id == Region.SEPARATOR) {                paintSeparatorBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.SLIDER_TRACK) {                paintSliderTrackBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.SLIDER_THUMB) {                paintSliderThumbBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.SPINNER) {                paintSpinnerBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.SPLIT_PANE_DIVIDER) {                paintSplitPaneDividerBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TABBED_PANE_CONTENT) {                paintTabbedPaneContentBackground(context,                    engine, g, x, y, w, h);            }            else if (id == Region.TABBED_PANE_TAB) {                paintTabbedPaneTabBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TEXT_AREA) {                paintTextAreaBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TEXT_FIELD) {                if (name == "Tree.cellEditor") {                    paintTreeCellEditorBackground(context, engine, g, x, y, w,                                                  h);                }                else {                    paintTextFieldBackground(context, engine, g, x, y, w, h);                }            }            else if (id == Region.TOGGLE_BUTTON) {                paintToggleButtonBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TOOL_BAR ||                     id == Region.TOOL_BAR_DRAG_WINDOW) {                paintToolBarBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TOOL_BAR_CONTENT) {                paintToolBarContentBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TOOL_TIP) {                paintToolTipBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TREE) {                paintTreeBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.TREE_CELL) {                paintTreeCellBackground(context, engine, g, x, y, w, h);            }            else if (id == Region.VIEWPORT) {                paintViewportBackground(context, engine, g, x, y, w, h);            }        } else if (paintKey == "border") {            if (id == Region.INTERNAL_FRAME) {                Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);            }            else if (id == Region.VIEWPORT) {                paintScrollPaneBackground(context, engine, g, x, y, w, h);            }        }        else if (paintKey == "foreground") {            if (id == Region.ARROW_BUTTON) {                paintArrowButtonForeground(context, engine, g, x, y, w, h);            }            else if (id == Region.PROGRESS_BAR) {                paintProgressBarForeground(context, engine, g, x, y, w, h);            }            else if (id == Region.SPLIT_PANE_DIVIDER) {                paintSplitPaneDividerDragBackground(context, engine, g, x, y,                                                    w,h);            }        }        else if (paintKey == "focus") {            if (id == Region.TREE_CELL) {                paintTreeCellFocus(context, engine, g, x, y, w, h);            }        }    }    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.MENU                 || id == Region.MENU_ITEM                || 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.FORMATTED_TEXT_FIELD) {            return getTextFieldInsets(state, insets);        }        else if (id == Region.INTERNAL_FRAME) {            insets = Metacity.INSTANCE.getBorderInsets(state, insets);        }        else if (id == Region.LABEL) {            if ("TableHeader.renderer" == name) {                return getButtonInsets(state, insets);            }            else if ("ComboBox.renderer" == 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) {            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;    }    //    // 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;    }

⌨️ 快捷键说明

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