gtkpainter.java

来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 1,409 行 · 第 1/4 页

JAVA
1,409
字号
    //    public void paintArrowButtonForeground(SynthContext context, Graphics g,                                           int x, int y, int w, int h,                                           int direction) {        Region id = context.getRegion();        Component c = context.getComponent();        String name = c.getName();        ArrowType arrowType = null;        switch (direction) {            case SwingConstants.NORTH:                arrowType = ArrowType.UP; break;            case SwingConstants.SOUTH:                arrowType = ArrowType.DOWN; break;            case SwingConstants.EAST:                arrowType = ArrowType.RIGHT; break;            case SwingConstants.WEST:                arrowType = ArrowType.LEFT; break;        }        String detail = "arrow";        if (name == "ScrollBar.button") {            if (arrowType == ArrowType.UP || arrowType == ArrowType.DOWN) {                detail = "vscrollbar";            } else {                detail = "hscrollbar";            }        } else if (name == "Spinner.nextButton" ||                   name == "Spinner.previousButton") {            detail = "spinbutton";        } else if (name != "ComboBox.arrowButton") {            assert false;        }                int gtkState = GTKLookAndFeel.synthStateToGTKState(                id, context.getComponentState());        ShadowType shadowType = (gtkState == SynthConstants.PRESSED ?            ShadowType.IN : ShadowType.OUT);        synchronized (UNIXToolkit.GTK_LOCK) {            if (ENGINE.paintCachedImage(g, x, y, w, h,                    gtkState, name, direction)) {                return;            }            ENGINE.startPainting(g, x, y, w, h, gtkState, name, direction);            ENGINE.paintArrow(g, context, id, gtkState,                    shadowType, arrowType, detail, x, y, w, h);            ENGINE.finishPainting();        }    }    public void paintArrowButtonBackground(SynthContext context,            Graphics g, int x, int y, int w, int h) {        Region id = context.getRegion();        AbstractButton button = (AbstractButton)context.getComponent();        String name = button.getName();        String detail = "button";        int direction = SwingConstants.CENTER;        if (name == "ScrollBar.button") {            Integer prop = (Integer)                 button.getClientProperty("__arrow_direction__");             direction = (prop != null) ?                 prop.intValue() : SwingConstants.WEST;             switch (direction) {             default:             case SwingConstants.EAST:             case SwingConstants.WEST:                 detail = "hscrollbar";                 break;             case SwingConstants.NORTH:             case SwingConstants.SOUTH:                 detail = "vscrollbar";                 break;             }        } else if (name == "Spinner.previousButton") {            detail = "spinbutton_down";        } else if (name == "Spinner.nextButton") {            detail = "spinbutton_up";        } else if (name != "ComboBox.arrowButton") {             assert false;        }        int state = context.getComponentState();         synchronized (UNIXToolkit.GTK_LOCK) {             if (ENGINE.paintCachedImage(g, x, y, w, h, id,                                         state, detail, direction))             {                 return;             }             ENGINE.startPainting(g, x, y, w, h, id,                                  state, detail, direction);             if (detail.startsWith("spin")) {                /*                 * The ubuntulooks engine (and presumably others) expect us to                 * first draw the full "spinbutton" background, and then draw                 * the individual "spinbutton_up/down" buttons on top of that.                 * Note that it is the state of the JSpinner (not its arrow                 * button) that determines how we draw this background.                 */                int spinState = button.getParent().isEnabled() ?                    SynthConstants.ENABLED : SynthConstants.DISABLED;                int mody = (detail == "spinbutton_up") ? y : y-h;                int modh = h*2;                ENGINE.paintBox(g, context, id, spinState,                                ShadowType.IN, "spinbutton",                                x, mody, w, modh);            }            int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);             ShadowType shadowType = ShadowType.OUT;             if ((gtkState & (SynthConstants.PRESSED |                              SynthConstants.SELECTED)) != 0)             {                 shadowType = ShadowType.IN;             }             ENGINE.paintBox(g, context, id, gtkState,                             shadowType, detail, x, y, w, h);              ENGINE.finishPainting();         }    }    //    // LIST    //    public void paintListBackground(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, GTKColorType.TEXT_BACKGROUND);    }        public void paintMenuBarBackground(SynthContext context, Graphics g,                                       int x, int y, int w, int h) {        Region id = context.getRegion();        synchronized (UNIXToolkit.GTK_LOCK) {            if (ENGINE.paintCachedImage(g, x, y, w, h, id)) {                return;            }            GTKStyle style = (GTKStyle)context.getStyle();            int shadow = style.getClassSpecificIntValue(                    context, "shadow-type", 2);            ShadowType shadowType = SHADOWS[shadow];            int gtkState = GTKLookAndFeel.synthStateToGTKState(                    id, context.getComponentState());            ENGINE.startPainting(g, x, y, w, h, id);            ENGINE.paintBox(g, context, id, gtkState,                shadowType, "menubar", x, y, w, h);            ENGINE.finishPainting();        }    }    //    // MENU    //    public void paintMenuBackground(SynthContext context,                                     Graphics g,                                     int x, int y, int w, int h) {        paintMenuItemBackground(context, g, x, y, w, h);    }    // This is called for both MENU and MENU_ITEM    public void paintMenuItemBackground(SynthContext context,                                     Graphics g,                                     int x, int y, int w, int h) {        int gtkState = GTKLookAndFeel.synthStateToGTKState(                context.getRegion(), context.getComponentState());        if (gtkState == SynthConstants.MOUSE_OVER) {            Region id = Region.MENU_ITEM;            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();                }            }        }    }    public void paintPopupMenuBackground(SynthContext context, Graphics g,                                        int x, int y, int w, int h) {        Region id = context.getRegion();        int gtkState = GTKLookAndFeel.synthStateToGTKState(                id, context.getComponentState());        synchronized (UNIXToolkit.GTK_LOCK) {            if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {                return;            }            ENGINE.startPainting(g, x, y, w, h, id, gtkState);            ENGINE.paintBox(g, context, id, gtkState,                    ShadowType.OUT, "menu", x, y, w, h);            GTKStyle style = (GTKStyle)context.getStyle();            int xThickness = style.getXThickness();            int yThickness = style.getYThickness();            ENGINE.paintBackground(g, context, id, gtkState,                    style.getGTKColor(context, gtkState, GTKColorType.BACKGROUND),                    x + xThickness, y + yThickness,                    w - xThickness - xThickness, h - yThickness - yThickness);            ENGINE.finishPainting();        }    }    public void paintProgressBarBackground(SynthContext context,                                            Graphics g,                                            int x, int y, int w, int h) {        Region id = context.getRegion();        synchronized (UNIXToolkit.GTK_LOCK) {            if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {                ENGINE.startPainting(g, x, y, w, h, id);                ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,                        ShadowType.IN, "trough", x, y, w, h);                ENGINE.finishPainting();            }        }    }    public void paintProgressBarForeground(SynthContext context, Graphics g,                                            int x, int y, int w, int h,                                            int orientation) {        Region id = context.getRegion();        synchronized (UNIXToolkit.GTK_LOCK) {            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, "fg")) {                ENGINE.startPainting(g, x, y, w, h, id, "fg");                ENGINE.paintBox(g, context, id, SynthConstants.MOUSE_OVER,                        ShadowType.OUT, "bar", x, y, w, h);                ENGINE.finishPainting();            }        }    }    public void paintViewportBorder(SynthContext context, Graphics g,                                           int x, int y, int w, int h) {        Region id = context.getRegion();        synchronized (UNIXToolkit.GTK_LOCK) {            if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {                ENGINE.startPainting(g, x, y, w, h, id);                ENGINE.paintShadow(g, context, id, SynthConstants.ENABLED,                        ShadowType.IN, "scrolled_window", x, y, w, h);                ENGINE.finishPainting();            }        }    }    public void paintScrollPaneBorder(SynthContext context, Graphics g,                                           int x, int y, int w, int h) {        paintViewportBorder(context, g, x, y, w, h);    }    public void paintSeparatorBackground(SynthContext context,                                          Graphics g,                                          int x, int y, int w, int h,                                         int orientation) {        Region id = context.getRegion();        int state = context.getComponentState();        JComponent c = context.getComponent();        /*         * Note: In theory, the style's x/y thickness values would determine         * the width of the separator content.  In practice, however, some         * engines will render a line that is wider than the corresponding         * thickness value.  For example, ubuntulooks reports x/y thickness         * values of 1 for separators, but always renders a 2-pixel wide line.         * As a result of all this, we need to be careful not to restrict         * the w/h values below too much, so that the full thickness of the         * rendered line will be captured by our image caching code.         */        String detail;        if (c instanceof JToolBar.Separator) {            /*             * GTK renders toolbar separators differently in that an             * artificial padding is added to each end of the separator.             * The value of 0.2f below is derived from the source code of             * gtktoolbar.c in the current version of GTK+ (2.8.20 at the             * time of this writing).  Specifically, the relevant values are:             *     SPACE_LINE_DIVISION 10.0             *     SPACE_LINE_START     2.0             *     SPACE_LINE_END       8.0             * These are used to determine the distance from the top (or left)             * edge of the toolbar to the other edge.  So for example, the             * starting/top point of a vertical separator is 2/10 of the             * height of a horizontal toolbar away from the top edge, which             * is how we arrive at 0.2f below.  Likewise, the ending/bottom             * point is 8/10 of the height away from the top edge, or in other             * words, it is 2/10 away from the bottom edge, which is again             * how we arrive at the 0.2f value below.             *             * The separator is also centered horizontally or vertically,             * depending on its orientation.  This was determined empirically             * and by examining the code referenced above.             */            detail = "toolbar";            float pct = 0.2f;            JToolBar.Separator sep = (JToolBar.Separator)c;            Dimension size = sep.getSeparatorSize();            GTKStyle style = (GTKStyle)context.getStyle();            if (orientation == JSeparator.HORIZONTAL) {                x += (int)(w * pct);                w -= (int)(w * pct * 2);                y += (size.height - style.getYThickness()) / 2;            } else {                y += (int)(h * pct);                h -= (int)(h * pct * 2);                x += (size.width - style.getXThickness()) / 2;            }        } else {            // For regular/menu separators, we simply subtract out the insets.            detail = "separator";            Insets insets = c.getInsets();            x += insets.left;            y += insets.top;            if (orientation == JSeparator.HORIZONTAL) {                w -= (insets.left + insets.right);            } else {                h -= (insets.top + insets.bottom);            }        }        synchronized (UNIXToolkit.GTK_LOCK) {            if (! ENGINE.paintCachedImage(g, x, y, w, h, id,                                          state, detail, orientation)) {                ENGINE.startPainting(g, x, y, w, h, id,                                     state, detail, orientation);                if (orientation == JSeparator.HORIZONTAL) {                    ENGINE.paintHline(g, context, id, state,                                      detail, x, y, w, h);                } else {                    ENGINE.paintVline(g, context, id, state,                                      detail, x, y, w, h);                }                ENGINE.finishPainting();            }        }    }    public void paintSliderTrackBackground(SynthContext context,                                       Graphics g,                                       int x, int y, int w,int h) {        Region id = context.getRegion();        int state = context.getComponentState();        // For focused sliders, we paint focus rect outside the bounds passed.        // Need to adjust for that.        boolean focused = ((state & SynthConstants.FOCUSED) != 0);        int focusSize = 0;        if (focused) {            GTKStyle style = (GTKStyle)context.getStyle();            focusSize = style.getClassSpecificIntValue(                                context, "focus-line-width", 1) +

⌨️ 快捷键说明

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