gtkdefaultengine.java

来自「JAVA 所有包」· Java 代码 · 共 1,177 行 · 第 1/3 页

JAVA
1,177
字号
/* * @(#)GTKDefaultEngine.java	1.7 06/06/07 * * 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 javax.swing.plaf.synth.*;import java.awt.*;import javax.swing.*;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;/** * GTKDefaultEngine mirrors that of a a GtkStyleClass. * * @version 1.7, 06/07/06 * @author Josh Outwater * @author Scott Violet */public class GTKDefaultEngine extends GTKEngine {    static final int[] DEFAULT_FOCUS_PATTERN = new int[] {1, 1};    static int adjustAxisForComponentOrientation(JComponent c,                                                 int axis) {        if (c.getComponentOrientation().isLeftToRight()) {            return axis;        }        switch (axis) {        case SwingConstants.EAST:            return SwingConstants.WEST;        case SwingConstants.WEST:            return SwingConstants.EAST;        }        return axis;    }    public void paintArrow(Graphics g, SynthContext context, Region id,            int state, ShadowType shadowType, ArrowType direction,            String info, int x, int y, int w, int h) {        int sizeW = w / 4 + 1;        int sizeH = h / 4 + 1;        int size = Math.max(2, Math.min(sizeW, sizeH));        switch (direction) {        case UP:        case DOWN:            x += (w - size * 2 + 1) / 2;            y += (h - size) / 2;            break;        case LEFT:        case RIGHT:            x += (w - size) / 2;            y += (h - size * 2 + 1) / 2;            break;        }        GTKStyle style = (GTKStyle)context.getStyle();        int i;        int arW = size * 2 - 2;        g.translate(x, y);        if (state == SynthConstants.DISABLED) {            g.setColor(style.getGTKColor(context, state, GTKColorType.WHITE));        }        else {            g.setColor(style.getGTKColor(context, state, GTKColorType.FOREGROUND));        }        switch(direction) {        case UP:            for(i = 0; i < size; i++) {                g.drawLine(i, size - i - 1, arW - i, size - i - 1);            }            break;        case DOWN:            for (i = 0; i < size; i++) {                g.drawLine(i, i, arW - i, i);            }            break;        case LEFT:            int j;            for (j = 0, i = size - 1; i >= 0; i--, j++) {                g.drawLine(i, j, i, arW - j);            }            break;        case RIGHT:            for (i = 0; i < size; i++)   {                g.drawLine(i, i, i, arW - i);            }            break;        }        g.translate(-x, -y);	    }    public void paintBox(Graphics g, SynthContext context, Region id,            int state, ShadowType shadowType, String info,            int x, int y, int w, int h) {        GTKStyle style = (GTKStyle)context.getStyle();        // This should really happen after the shadow is drawn.        if (info == "menuitem" && state == SynthConstants.MOUSE_OVER &&                                  GTKLookAndFeel.is2_2()) {            paintBackground(g, context, id, state,                    style.getGTKColor(context, SynthConstants.MOUSE_OVER,                         GTKColorType.BACKGROUND),                    x, y, w, h);        }        else {            paintBackground(g, context, id, state,                    style.getGTKColor(context, state,                        GTKColorType.BACKGROUND), x, y, w, h);        }        paintShadow(g, context, id, state, shadowType, info, x, y, w, h);    }    public void paintBoxGap(Graphics g, SynthContext context, Region id,            int state, ShadowType shadowType, String info,            int x, int y, int w, int h, PositionType boxGapType, int tabBegin,            int size) {        _paintBoxGap(context, g, state, shadowType, x, y, w, h, boxGapType,                tabBegin, size, GTKColorType.BACKGROUND, GTKColorType.LIGHT,                GTKColorType.BLACK, GTKColorType.DARK, false);    }    void _paintBoxGap(SynthContext context, Graphics g, int state,            ShadowType shadowType, int x, int y, int w, int h,            PositionType boxGapType, int tabBegin, int size,            ColorType backgroundType, ColorType upperLeftType,            ColorType bottomRightType, ColorType innerRightType,            boolean paintWhite) {        GTKStyle style = (GTKStyle)context.getStyle();        paintBackground(g, context, context.getRegion(), state,                style.getGTKColor(context, state, backgroundType),                x, y, w, h);        int tabEnd = tabBegin + size;        Color upperLeft = style.getGTKColor(context, state, upperLeftType);        Color bottomRight = style.getGTKColor(context, state, bottomRightType);        Color innerRight = style.getGTKColor(context, state, innerRightType);        Color white = style.getGTKColor(context, state, GTKColorType.WHITE);        g.translate(x, y);        if (boxGapType == PositionType.TOP) {            // Paint bottom.            g.setColor(bottomRight);            g.drawLine(0, h - 1, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(1, h - 2, w - 2, h - 2);            // Paint left side.            g.setColor(upperLeft);            g.drawLine(0, 0, 0, h - 2);            if (paintWhite) {                g.setColor(white);                g.drawLine(1, 0, 1, h - 3);            }            // Paint right side.            g.setColor(bottomRight);            g.drawLine(w - 1, 0, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(w - 2, 0, w - 2, h - 2);            // Paint top.            if (tabBegin > 1) {                g.setColor(upperLeft);                g.drawLine(0, 0, tabBegin - 2, 0);            }            g.setColor(upperLeft);            g.drawLine(tabEnd - 1, 0, w - 2, 0);            if (paintWhite) {                g.setColor(white);                if (tabBegin > 0) {                    g.drawLine(0, 1, tabBegin, 1);                }                g.drawLine(tabEnd, 1, w - 2, 1);            }        }        else if (boxGapType == PositionType.BOTTOM) {            // Paint top.            g.setColor(upperLeft);            g.drawLine(0, 0, w - 1, 0);            if (paintWhite) {                g.setColor(white);                g.drawLine(0, 1, w - 1, 1);            }            // Paint left side.            g.setColor(upperLeft);            g.drawLine(0, 0, 0, h - 1);            if (paintWhite) {                g.setColor(white);                g.drawLine(1, 1, 1, h - 2);            }            // Paint right side.            g.setColor(bottomRight);            g.drawLine(w - 1, 0, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(w - 2, 1, w - 2, h - 2);            // Paint bottom.            if (tabBegin > 1) {                g.setColor(bottomRight);                g.drawLine(0, h - 1, tabBegin - 2, h - 1);                g.setColor(innerRight);                g.drawLine(tabBegin - 1, h - 1, tabBegin - 1, h - 1);                g.drawLine(1, h - 2, tabBegin - 2, h - 2);            }            g.setColor(bottomRight);            g.drawLine(tabEnd - 1, h - 1, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(tabEnd - 2, h - 1, tabEnd - 2, h - 1);            g.drawLine(tabEnd - 1, h - 2, w - 2, h - 2);        }        else if (boxGapType == PositionType.RIGHT) {            // Paint top.            g.setColor(upperLeft);            g.drawLine(0, 0, w - 1, 0);            if (paintWhite) {                g.setColor(white);                g.drawLine(0, 1, w - 1, 1);            }            // Paint bottom.            g.setColor(bottomRight);            g.drawLine(0, h - 1, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(1, h - 2, w - 2, h - 2);            // Paint left side.            g.setColor(upperLeft);            g.drawLine(0, 0, 0, h - 2);            if (paintWhite) {                g.setColor(white);                g.drawLine(1, 1, 1, h - 3);            }            if (tabBegin > 1) {                g.setColor(bottomRight);                g.drawLine(w - 1, 0, w - 1, tabBegin - 2);                g.setColor(innerRight);                g.drawLine(w - 1, tabBegin - 1, w - 1, tabBegin - 1);                g.drawLine(w - 2, 1, w - 2, tabBegin - 2);            }            g.setColor(bottomRight);            g.drawLine(w - 1, tabEnd - 1, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(w - 1, tabEnd - 2, w - 1, tabEnd - 2);            g.drawLine(w - 2, tabEnd - 1, w - 2, h - 2);        }        else if (boxGapType == PositionType.LEFT) {            // Paint top.            g.setColor(upperLeft);            g.drawLine(0, 0, w - 2, 0);            if (paintWhite) {                g.setColor(white);                g.drawLine(0, 1, w - 2, 1);            }            // Paint bottom.            g.setColor(bottomRight);            g.drawLine(0, h - 1, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(1, h - 2, w - 2, h - 2);            // Paint right side.            g.setColor(bottomRight);            g.drawLine(w - 1, 1, w - 1, h - 1);            g.setColor(innerRight);            g.drawLine(w - 2, 0, w - 2, h - 2);            // Paint left side.            if (tabBegin > 1) {                g.setColor(upperLeft);                g.drawLine(0, 0, 0, tabBegin - 2);            }            g.setColor(upperLeft);            g.drawLine(0, tabEnd - 1, 0, h - 2);            if (paintWhite) {                g.setColor(white);                if (tabBegin > 1) {                    g.drawLine(1, 0, 1, tabBegin - 1);                }                g.drawLine(1, tabEnd - 1, 1, h - 3);            }        }        g.translate(-x, -y);    }    public void paintCheck(Graphics g, SynthContext context, Region id,            int state, ShadowType shadowType, String info,            int x, int y, int w, int h) {        int componentState = context.getComponentState();        GTKStyle style = (GTKStyle)context.getStyle();        if ("checkbutton" == info) {            int checkState = ((componentState & SynthConstants.PRESSED) == 0) ?                     SynthConstants.ENABLED : SynthConstants.PRESSED;            paintFlatBox(g, context, id, checkState, ShadowType.ETCHED_OUT,                    info, x, y, w, h, ColorType.TEXT_BACKGROUND);            paintShadow(g, context, id, checkState,                    ShadowType.IN, info, x, y, w, h);        }        g.translate(x, y);        int centerY = h / 2 - 1;        // Paint check mark in center if selected.        if ((componentState & SynthConstants.SELECTED) != 0) {            g.setColor(style.getGTKColor(context, state,                    GTKColorType.FOREGROUND));            g.drawLine(3, centerY + 2, 4, centerY + 2);            g.drawLine(5, centerY + 3, 6, centerY + 3);            g.drawLine(6, centerY + 2, 6, centerY + 4);            g.drawLine(7, centerY + 1, 7, centerY);            g.drawLine(7, centerY, 8, centerY);            g.drawLine(8, centerY, 8, centerY - 1);            g.drawLine(8, centerY - 1, 9, centerY - 1);            g.drawLine(9, centerY - 1, 9, centerY - 2);            if (!GTKLookAndFeel.is2_2()) {                if ((componentState & SynthConstants.PRESSED) != 0) {                    g.setColor(style.getGTKColor(context,                            SynthConstants.PRESSED, GTKColorType.DARK));                } else {                    g.setColor(style.getGTKColor(context,                             SynthConstants.ENABLED, GTKColorType.DARK));                }            }            g.drawLine(3, centerY + 1, 4, centerY + 1);            g.drawLine(4, centerY + 3, 4, centerY + 3);            g.drawLine(5, centerY + 2, 5, centerY + 2);            g.drawLine(6, centerY + 1, 6, centerY + 1);            g.drawLine(7, centerY + 2, 7, centerY + 2);            g.drawLine(10, centerY - 2, 10, centerY - 2);        }        g.translate(-x, -y);    }    public void paintExtension(Graphics g, SynthContext context, Region id,            int state, ShadowType shadowType, String info,            int x, int y, int w, int h, PositionType placement, int tabIndex) {        _paintExtension(context, g, state, shadowType, x, y, w, h, placement,                        GTKColorType.LIGHT, GTKColorType.BACKGROUND,                        GTKColorType.BLACK, GTKColorType.DARK, false,tabIndex);    }    void _paintExtension(SynthContext context, Graphics g, int state,            ShadowType shadowType, int x, int y, int w, int h,            PositionType placement, ColorType upperLeftType,            ColorType backgroundType, ColorType bottomRightType,            ColorType innerRightType, boolean paintWhite, int tabIndex) {        GTKStyle style = (GTKStyle)context.getStyle();        Region region = context.getRegion();        int xThickness = style.getXThickness();        int yThickness = style.getYThickness();        if (xThickness < 0 && yThickness < 0) {            // nothing to paint.            return;        }        Color upperLeft = style.getGTKColor(context, state, upperLeftType);        Color background = style.getGTKColor(context, state, backgroundType);        Color bottomRight = style.getGTKColor(context, state, bottomRightType);        Color innerRight = style.getGTKColor(context, state, innerRightType);        Color white = style.getGTKColor(context, state, GTKColorType.WHITE);                int selectedIndex = ((JTabbedPane)context.getComponent()).getSelectedIndex();        g.translate(x, y);        // NOTE: placement refers to the size of the extension, so that        // BOTTOM corresponds to a TabbedPane with the tabs placed at the top.        if (placement == PositionType.BOTTOM) {            // Fill the background.            paintBackground(g, context, region, state, background, 0, 1, w, h);            if (tabIndex == selectedIndex || tabIndex == 0) {                g.setColor(upperLeft);                g.drawLine(0, 1, 0, h - 1);                g.drawLine(1, 0, w - 2, 0);                if (paintWhite) {                    g.setColor(white);

⌨️ 快捷键说明

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