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

📄 gtkpainter.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * @(#)GTKPainter.java	1.82 06/12/01 * * Copyright 2006 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 sun.awt.UNIXToolkit;import javax.swing.plaf.synth.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.plaf.*;import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType;import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;/** * @version 1.82, 12/01/06 * @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 {    private static final PositionType[] POSITIONS = {        PositionType.BOTTOM, PositionType.RIGHT,        PositionType.TOP, PositionType.LEFT    };        private static final ShadowType SHADOWS[] = {        ShadowType.NONE, ShadowType.IN, ShadowType.OUT,        ShadowType.ETCHED_IN, ShadowType.OUT    };        private final static GTKEngine ENGINE = GTKEngine.INSTANCE;    final static GTKPainter INSTANCE = new GTKPainter();    private GTKPainter() {    }    private String getName(SynthContext context) {        return (context.getRegion().isSubregion()) ? null :               context.getComponent().getName();    }    public void paintCheckBoxBackground(SynthContext context,            Graphics g, int x, int y, int w, int h) {        paintRadioButtonBackground(context, g, x, y, w, h);    }    public void paintCheckBoxMenuItemBackground(SynthContext context,            Graphics g, int x, int y, int w, int h) {        paintRadioButtonMenuItemBackground(context, g, x, y, w, h);    }    // FORMATTED_TEXT_FIELD    public void paintFormattedTextFieldBackground(SynthContext context,                                          Graphics g, int x, int y,                                          int w, int h) {        paintTextBackground(context, g, x, y, w, h);    }    //    // TOOL_BAR_DRAG_WINDOW    //    public void paintToolBarDragWindowBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintToolBarBackground(context, g, x, y, w, h);    }    //    // TOOL_BAR    //    public void paintToolBarBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        Region id = context.getRegion();        int state = context.getComponentState();        int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);        int orientation = ((JToolBar)context.getComponent()).getOrientation();        synchronized (UNIXToolkit.GTK_LOCK) {            if (! ENGINE.paintCachedImage(g, x, y, w, h, id,                                          state, orientation))            {                ENGINE.startPainting(g, x, y, w, h, id, state, orientation);                ENGINE.paintBox(g, context, id, gtkState, ShadowType.OUT,                                "handlebox_bin", x, y, w, h);                ENGINE.finishPainting();            }        }    }    public void paintToolBarContentBackground(SynthContext context,                                              Graphics g,                                              int x, int y, int w, int h) {        Region id = context.getRegion();        int orientation = ((JToolBar)context.getComponent()).getOrientation();        synchronized (UNIXToolkit.GTK_LOCK) {            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, orientation)) {                ENGINE.startPainting(g, x, y, w, h, id, orientation);                ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,                                ShadowType.OUT, "toolbar", x, y, w, h);                ENGINE.finishPainting();            }        }    }    //    // PASSWORD_FIELD    //    public void paintPasswordFieldBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        paintTextBackground(context, g, x, y, w, h);    }        //    // TEXT_FIELD    //    public void paintTextFieldBackground(SynthContext context, Graphics g,                                         int x, int y, int w, int h) {        if (getName(context) == "Tree.cellEditor") {            paintTreeCellEditorBackground(context, g, x, y, w, h);        } else {            paintTextBackground(context, g, x, y, w, h);        }    }    //    // RADIO_BUTTON    //    // NOTE: this is called for JCheckBox too    public void paintRadioButtonBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        Region id = context.getRegion();        int gtkState = GTKLookAndFeel.synthStateToGTKState(                id, context.getComponentState());        if (gtkState == SynthConstants.MOUSE_OVER) {            synchronized (UNIXToolkit.GTK_LOCK) {                if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {                    ENGINE.startPainting(g, x, y, w, h, id);                    ENGINE.paintFlatBox(g, context, id,                            SynthConstants.MOUSE_OVER, ShadowType.ETCHED_OUT,                            "checkbutton", x, y, w, h, ColorType.BACKGROUND);                    ENGINE.finishPainting();                }            }        }    }    //    // RADIO_BUTTON_MENU_ITEM    //    // NOTE: this is called for JCheckBoxMenuItem too    public void paintRadioButtonMenuItemBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        Region id = context.getRegion();        int gtkState = GTKLookAndFeel.synthStateToGTKState(                id, context.getComponentState());        if (gtkState == SynthConstants.MOUSE_OVER) {            synchronized (UNIXToolkit.GTK_LOCK) {                if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {                    ShadowType shadow = (GTKLookAndFeel.is2_2() ?                        ShadowType.NONE : ShadowType.OUT);                    ENGINE.startPainting(g, x, y, w, h, id);                    ENGINE.paintBox(g, context, id, gtkState,                            shadow, "menuitem", x, y, w, h);                    ENGINE.finishPainting();                }            }        }    }    //     // LABEL    //    public void paintLabelBackground(SynthContext context,                                     Graphics g, int x, int y,                                     int w, int h) {        String name = getName(context);        if (name == "TableHeader.renderer" ||            name == "GTKFileChooser.directoryListLabel" ||            name == "GTKFileChooser.fileListLabel") {                        paintButtonBackgroundImpl(context, g, Region.BUTTON, "button",                    x, y, w, h, true, false, false, false);        } else if (name == "ComboBox.renderer") {            paintTextBackground(context, 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) {        // Does not call into ENGINE for better performance        fillArea(context, g, x, y, w, h, ColorType.BACKGROUND);    }    //    // 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);    }    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 {            AbstractButton button = (AbstractButton)context.getComponent();            boolean paintBG = button.isContentAreaFilled() &&                              button.isBorderPainted();            boolean paintFocus = button.isFocusPainted();            boolean defaultCapable = (button instanceof JButton) &&                    ((JButton)button).isDefaultCapable();            boolean toolButton = (button.getParent() instanceof JToolBar);            paintButtonBackgroundImpl(context, g, Region.BUTTON, "button",                    x, y, w, h, paintBG, paintFocus, defaultCapable, toolButton);        }    }    private void paintButtonBackgroundImpl(SynthContext context, Graphics g,            Region id, String detail, int x, int y, int w, int h,            boolean paintBackground, boolean paintFocus,            boolean defaultCapable, boolean toolButton) {        int state = context.getComponentState();        synchronized (UNIXToolkit.GTK_LOCK) {            if (ENGINE.paintCachedImage(g, x, y, w, h, id, state, detail,                    paintBackground, paintFocus, defaultCapable, toolButton)) {                return;            }            ENGINE.startPainting(g, x, y, w, h, id, state, detail,                paintBackground, paintFocus, defaultCapable, toolButton);            // Paint the default indicator            GTKStyle style = (GTKStyle)context.getStyle();            if (defaultCapable && !toolButton) {                Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(                        context, "default-border",                        GTKStyle.BUTTON_DEFAULT_BORDER_INSETS);                            if (paintBackground && (state & SynthConstants.DEFAULT) != 0) {                    ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,                            ShadowType.IN, "buttondefault", x, y, w, h);                }                x += defaultInsets.left;                y += defaultInsets.top;                w -= (defaultInsets.left + defaultInsets.right);                h -= (defaultInsets.top + defaultInsets.bottom);            }            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();            // Render the box.            if (!interiorFocus &&                    (state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {                x += totalFocusSize;                y += totalFocusSize;                w -= 2 * totalFocusSize;                h -= 2 * totalFocusSize;            }                    int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);            boolean paintBg;            if (toolButton) {                // Toolbar buttons should only have their background painted                // in the PRESSED, SELECTED, or MOUSE_OVER states.                paintBg =                    (gtkState != SynthConstants.ENABLED) &&                    (gtkState != SynthConstants.DISABLED);            } else {                // Otherwise, always paint the button's background, unless                // the user has overridden it and we're in the ENABLED state.                paintBg =                    paintBackground ||                    (gtkState != SynthConstants.ENABLED);            }            if (paintBg) {                ShadowType shadowType = ShadowType.OUT;                if ((state & (SynthConstants.PRESSED |                              SynthConstants.SELECTED)) != 0) {                    shadowType = ShadowType.IN;                }                ENGINE.paintBox(g, context, id, gtkState,                        shadowType, detail, x, y, w, h);            }                        // focus            if (paintFocus && (state & SynthConstants.FOCUSED) != 0) {                if (interiorFocus) {                    x += xThickness + focusPad;                    y += yThickness + focusPad;                    w -= 2 * (xThickness + focusPad);                    h -= 2 * (yThickness + focusPad);                } else {                    x -= totalFocusSize;

⌨️ 快捷键说明

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