gtkpainter.java

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

JAVA
1,426
字号
                                            Graphics g,                                            int x, int y, int w, int h) {        GTKEngine engine = getEngine(context);        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();        JToggleButton toggleButton = (JToggleButton)context.getComponent();        if (!interiorFocus && (state & SynthConstants.FOCUSED) ==                              SynthConstants.FOCUSED) {            x += totalFocusSize;            y += totalFocusSize;            w -= 2 * totalFocusSize;            h -= 2 * totalFocusSize;        }        int shadow = GTKConstants.SHADOW_OUT;        if (toggleButton.isSelected() ||                ((state & SynthConstants.PRESSED) != 0)) {            shadow = GTKConstants.SHADOW_IN;        }        if (toggleButton.isContentAreaFilled() &&                         toggleButton.isBorderPainted()) {            engine.paintBox(context, g, gtkState, shadow, "button", x, y, w,h);        }        // focus        if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED &&                     toggleButton.isFocusPainted()) {            if (interiorFocus) {                x += xThickness + focusPad;                y += yThickness + focusPad;                w -= 2 * (xThickness + focusPad);                h -= 2 * (yThickness + focusPad);            }            else {                x -= totalFocusSize;                y -= totalFocusSize;                w += 2 * totalFocusSize;                h += 2 * totalFocusSize;            }            engine.paintFocus(context, g, gtkState, "button", x, y, w, h);        }    }    //    // ROOT_PANE    //    public void paintRootPaneBackground(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);    }    //    // SCROLL_BAR    //    public void paintScrollBarBackground(SynthContext context,                                          Graphics g,                                          int x, int y, int w,int h) {        GTKEngine engine = getEngine(context);        GTKStyle style = (GTKStyle)context.getStyle();        int state = context.getComponentState();        int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),                                                           state);        int focusSize = style.getClassSpecificIntValue(context,                                                        "focus-line-width",1);        int focusPad = style.getClassSpecificIntValue(context,                                                      "focus-padding", 1);        int totalFocus = focusSize + focusPad;        engine.paintBox(context, g, SynthConstants.PRESSED,                            GTKConstants.SHADOW_IN, "trough", x + totalFocus,                            y + totalFocus, w - 2 * totalFocus,                            h - 2 * totalFocus);        if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {            engine.paintFocus(context, g, SynthConstants.ENABLED,                              "trough", x, y, w, h);        }    }    private Insets getScrollBarInsets(SynthContext context, Insets insets) {        GTKStyle style = (GTKStyle)context.getStyle();        if (context.getComponent().isFocusable()) {            int focusSize = style.getClassSpecificIntValue(context,                                                        "focus-line-width",1);            int focusPad = style.getClassSpecificIntValue(context,                                                      "focus-padding", 1);            int w = focusSize + focusPad;            int h = focusSize + focusPad;            insets.left = insets.right = w;            insets.top = insets.bottom = h;        }        int troughBorder = style.getClassSpecificIntValue(context,                                                          "trough-border", 1);        insets.left += troughBorder;        insets.right += troughBorder;        insets.top += troughBorder;        insets.bottom += troughBorder;        return insets;    }    //    // SCROLL_BAR_THUMB    //    public void paintScrollBarThumbBackground(SynthContext context,                    Graphics g, int x, int y, int w, int h, int orientation) {        GTKEngine engine = getEngine(context);        if (orientation == JScrollBar.VERTICAL) {            orientation = GTKConstants.VERTICAL;        }        else {            orientation = GTKConstants.HORIZONTAL;        }        engine.paintSlider(context, g, GTKLookAndFeel.synthStateToGTKState(               context.getRegion(), context.getComponentState()),               GTKConstants.SHADOW_OUT, "slider", x, y, w, h, orientation);    }    //    // TOOL_BAR    //    private void paintToolBarBackground(SynthContext context, GTKEngine engine,                                        Graphics g, int x, int y,                                        int w, int h) {        int state = context.getComponentState();        int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),                state);        GTKStyle style = (GTKStyle)context.getStyle();        g.setColor(style.getGTKColor(context.getComponent(),                context.getRegion(), state, GTKColorType.BACKGROUND));        engine.paintFlatBox(context, g, gtkState, "handlebox_bin", x, y, w, h);    }    private Insets getToolBarInsets(SynthContext context, Insets insets) {        GTKStyle style = (GTKStyle)context.getStyle();        int xThickness = style.getXThickness();        int yThickness = style.getYThickness();        insets.top = insets.bottom = yThickness;        insets.right = insets.left = xThickness;        return insets;    }    public void paintToolBarContentBackground(SynthContext context,            Graphics g, int x, int y, int w, int h) {        int state = context.getComponentState();        int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),                                                           state);        getEngine(context).paintShadow(context, g, SynthConstants.ENABLED,            GTKConstants.SHADOW_OUT, "handlebox_bin", x, y, w, h);    }    //    // TOOL_TIP    //    public void paintToolTipBackground(SynthContext context, Graphics g,                                        int x, int y, int w,int h) {        getEngine(context).paintFlatBoxNormal(context, g,                                              SynthConstants.ENABLED,"tooltip",                                              x, y, w, h);    }    private Insets getToolTipInsets(SynthContext context, Insets insets) {        GTKStyle style = (GTKStyle)context.getStyle();        insets.left = insets.right = style.getXThickness();        insets.top = insets.bottom = style.getYThickness();        return insets;    }    //    // TREE_CELL    //    public void paintTreeCellBackground(SynthContext context, Graphics g,                                        int x, int y, int w,int h) {        int gtkState = GTKLookAndFeel.synthStateToGTKState(                          context.getRegion(), context.getComponentState());        // the string arg should alternate based on row being painted, but        // we currently don't pass that in.        getEngine(context).paintFlatBoxText(context, g, gtkState, "cell_odd",                                            x, y, w, h);    }    public void paintTreeCellFocus(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.paintFocus(context, g, gtkState, "treeview", x, y, w, h);    }    //    // TREE_CELL_RENDERER    //    private Insets getTreeCellRendererInsets(SynthContext context,                                             Insets insets) {        insets.left = insets.right = insets.top = insets.bottom = 1;        return insets;    }    //    // TREE_CELL_EDITOR    //    private Insets getTreeCellEditorInsets(SynthContext context,                                             Insets insets) {        insets.left = insets.right = insets.top = insets.bottom = 1;        return insets;    }    private void paintTreeCellEditorBackground(SynthContext context,                                     GTKEngine engine, Graphics g,                                     int x, int y, int w,int h) {        int gtkState = GTKLookAndFeel.synthStateToGTKState(                          context.getRegion(), context.getComponentState());        engine.paintFlatBoxText(context, g, gtkState, "entry_bg", x, y, w, h);    }    //    // TREE    //    public void paintTreeBackground(SynthContext context, Graphics g,                                    int x, int y, int w,int h) {        // As far as I can tell, these don't call into the engine.        int gtkState = GTKLookAndFeel.synthStateToGTKState(                          context.getRegion(), context.getComponentState());        g.setColor(((GTKStyle)context.getStyle()).getGTKColor(                context.getComponent(), context.getRegion(), gtkState,                GTKColorType.TEXT_BACKGROUND));        g.fillRect(x, y, w, h);    }    //    // VIEWPORT    //    public void paintViewportBackground(SynthContext context, Graphics g,                                        int x, int y, int w,int h) {        // As far as I can tell, these don't call into the engine.        // Also note that you don't want this to call into the engine        // as if it where to paint a background JViewport wouldn't scroll        // correctly.        int gtkState = GTKLookAndFeel.synthStateToGTKState(                          context.getRegion(), context.getComponentState());        g.setColor(((GTKStyle)context.getStyle()).getGTKColor(                context.getComponent(), context.getRegion(), gtkState,                GTKColorType.TEXT_BACKGROUND));        g.fillRect(x, y, w, h);    }    // Refer to GTKLookAndFeel for details on this.    static class ListTableFocusBorder extends AbstractBorder implements                          UIResource {        private boolean selectedCell;        public static ListTableFocusBorder getSelectedCellBorder() {            return new ListTableFocusBorder(true);         }                public static ListTableFocusBorder getUnselectedCellBorder() {            return new ListTableFocusBorder(false);         }                public ListTableFocusBorder(boolean selectedCell) {            this.selectedCell = selectedCell;        }        private SynthContext getContext(Component c) {            SynthContext context = null;                        Component parent = c;            while(parent != null &&                     !(parent instanceof JTable) &&                     !(parent instanceof JList)) {                parent = parent.getParent();            }                         ComponentUI ui = null;            if (parent instanceof JTable) {                ui = ((JTable)parent).getUI();            } else if (parent instanceof JList) {                ui = ((JList)parent).getUI();            }                        if (ui instanceof SynthUI) {                context = ((SynthUI)ui).getContext((JComponent)parent);            }                        return context;        }                public void paintBorder(Component c, Graphics g, int x, int y,                                int w, int h) {            SynthContext context = getContext(c);            int state = (selectedCell? SynthConstants.SELECTED:                         SynthConstants.FOCUSED | SynthConstants.ENABLED);            if (context != null) {                ((GTKStyle)context.getStyle()).getEngine(context).                    paintFocus(context, g, state, "", x, y, w, h);            } else {                g.setColor(Color.BLACK);                GTKEngine.INSTANCE._paintFocus(                        g, x, y, w, h, GTKEngine.DEFAULT_FOCUS_PATTERN, 1);            }        }        public Insets getBorderInsets(Component c) {            int size = 1;            SynthContext context = getContext(c);            if (context != null) {                size = ((GTKStyle)context.getStyle()).getClassSpecificIntValue(                    context, "focus-line-width", 1);               }            return new Insets(size, size, size, size);        }        public Insets getBorderInsets(Component c, Insets i) {            Insets ins = getBorderInsets(c);            if (i == null) {                return ins;             }            i.left = ins.left;            i.right = ins.right;            i.top = ins.top;            i.bottom = ins.bottom;            return i;        }        public boolean isBorderOpaque() {            return true;        }    }}

⌨️ 快捷键说明

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