gtkengine.java

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

JAVA
1,225
字号
                    int y2 = h - (offset - max3);                    int temp = Math.min(next - offset, max4 - offset);                    g.fillRect(0, y2 - temp, size, temp);                    offset += temp;                }            }            else {                offset = next;            }            index = (index + 1) % pattern.length;        }        g.translate(-x, -y);    }    Color getFocusColor(SynthContext context, int state) {        return ((GTKStyle)context.getStyle()).getGTKColor(               context.getComponent(), context.getRegion(), state,               ColorType.FOREGROUND);    }    public void paintHandle(SynthContext context, Graphics g, int paintState,                            int shadowType, String info, int x, int y,                            int w, int h, int orientation) {        paintBox(context, g, paintState, shadowType, info, x, y, w, h);        g.translate(x, y);        Region region = context.getRegion();        GTKStyle style = (GTKStyle)context.getStyle();        JComponent component = context.getComponent();        Color lightColor = style.getGTKColor(component, region, paintState,                                          GTKColorType.LIGHT);        Color darkColor = style.getGTKColor(component, region, paintState,                                          GTKColorType.DARK);        Color blackColor = style.getGTKColor(component, region, paintState,                                          GTKColorType.BLACK);        int startX;        int startY;        if (info == "paned") {            JSplitPane splitPane = (JSplitPane)component;            int markerLength = 7 * 3 + 6 * 2;  // 7 markers width of 3                                               // + 6 spacers width of 2.            if (orientation == GTKConstants.HORIZONTAL) {                // Components are above/below.                startX = w / 2 - markerLength / 2;                startY = splitPane.getDividerSize() / 2 - 1;            } else {                // Components are left/right                startX = splitPane.getDividerSize() / 2 - 1;                startY = h / 2 - markerLength / 2;            }            for (int i = 0; i < 7; i++) {                // Add length of one marker and spacing.                if (orientation == GTKConstants.HORIZONTAL) {                    startX += 5;                } else {                    startY += 5;                }                g.setColor(lightColor);                g.fillRect(startX, startY, 2, 2);                g.setColor(blackColor);                g.fillRect(startX + 1, startY + 1, 2, 2);                g.setColor(darkColor);                g.fillRect(startX + 1, startY + 1, 1, 1);            }        } else if (info == "handlebox") {            JToolBar tb = (JToolBar)component;            startX = 2;            startY = 2;            if (tb.getOrientation() == JToolBar.HORIZONTAL) {                while (startY < h) {                    g.setColor(darkColor);                    g.fillRect(startX + 1, startY + 1, 2, 2);                    g.fillRect(startX + 4, startY + 2, 2, 2);                    g.setColor(lightColor);                    g.fillRect(startX, startY, 2, 2);                    g.fillRect(startX + 3, startY + 1, 2, 2);                    startY += 3;                }            } else {                boolean toggle = true;                while (startX < w) {                    g.setColor(darkColor);                    g.fillRect(startX + 1, startY + 1, 2, 2);                    g.fillRect(startX + 1, startY + 4, 2, 2);                    g.setColor(lightColor);                    g.fillRect(startX, startY, 2, 2);                    g.fillRect(startX, startY + 3, 2, 2);                    startX += 3;                    if (toggle) {                        startY++;                        toggle = false;                    } else {                        startY--;                        toggle = true;                    }                }            }            // Fix up the shadow.            paintShadow(context, g, paintState, shadowType, info, 0, 0, w, h);        }        g.translate(-x, -y);    }    public void paintOption(SynthContext context, Graphics g, int paintState,                            int shadowType, String info, int x, int y,                            int w, int h) {        g.translate(x, y);        int componentState = context.getComponentState();        int centerY = h / 2 - 1;        JComponent component = context.getComponent();        Region region = context.getRegion();        GTKStyle style = (GTKStyle)context.getStyle();        // We need to use the state from the context since the state passed in may have been modified.        int optionState = ((componentState & SynthConstants.PRESSED) == 0) ?                SynthConstants.ENABLED : SynthConstants.PRESSED;         g.setColor(style.getGTKColor(component, region, optionState, GTKColorType.TEXT_BACKGROUND));               if (region != Region.RADIO_BUTTON_MENU_ITEM) {            // Paint center portion.            g.fillRect(3, centerY - 3, 9, 9);            g.fillRect(13, centerY - 1, 1, 4);            g.fillRect(12, centerY + 3, 1, 2);            g.fillRect(9, centerY + 6, 2, 1);            g.fillRect(5, centerY + 7, 4, 1);                // Paint dark shadow.            g.setColor(style.getGTKColor(component, region, SynthConstants.ENABLED,                                         GTKColorType.DARK));            g.fillRect(5, centerY - 5, 4, 1);            g.fillRect(3, centerY - 4, 3, 1);            g.fillRect(2, centerY - 3, 1, 2);            g.fillRect(1, centerY - 1, 1, 4);            g.fillRect(2, centerY + 4, 1, 1);            g.fillRect(3, centerY + 5, 2, 1);            g.fillRect(5, centerY + 6, 4, 1);            g.fillRect(9, centerY + 5, 2, 1);            g.fillRect(11, centerY + 3, 1, 2);            g.fillRect(12, centerY - 1, 1, 4);            g.fillRect(11, centerY - 3, 1, 2);            g.fillRect(10, centerY - 4, 1, 1);                        // Paint black shadow.            g.setColor(style.getGTKColor(component, region, paintState,                                         GTKColorType.BLACK));            g.fillRect(5, centerY - 4, 5, 1);            g.fillRect(10, centerY - 3, 1, 1);            g.fillRect(3, centerY - 3, 2, 1);            g.fillRect(3, centerY - 2, 1, 1);            g.fillRect(2, centerY - 1, 1, 5);            g.fillRect(3, centerY + 4, 1, 1);        }        // Fill in center if selected.        if ((componentState & SynthConstants.SELECTED) != 0) {            g.setColor(style.getGTKColor(component, region, SynthConstants.ENABLED,                                         GTKColorType.FOREGROUND));            g.fillRect(5, centerY, 5, 3);            g.fillRect(6, centerY - 1, 3, 1);            g.fillRect(6, centerY + 3, 3, 1);        }        g.translate(-x, -y);    }    public void paintShadow(SynthContext context, Graphics g, int state,                            int shadowType, String info, int x, int y,                            int w, int h) {        if (info == "buttondefault") {            // YES, this appears to be special cased.            g.setColor(((GTKStyle)context.getStyle()).getGTKColor(                           context.getComponent(), context.getRegion(),                           state, GTKColorType.BLACK));            g.drawRect(x, y, w - 1, h - 1);            return;        }        GTKStyle style = (GTKStyle)context.getStyle();        JComponent c = context.getComponent();        Region region = context.getRegion();        int xThickness = style.getXThickness();        int yThickness = style.getYThickness();        if (info == "trough" ||                (info == "spinbutton" && c instanceof JButton)) {            // YES, this appears to be special cased.            xThickness = yThickness = 1;        }        if (xThickness < 0 && yThickness < 0) {            // nothing to paint.            return;        }        Color upperLeft = null, innerLeft = null, bottomRight = null,              innerRight = null;        switch (shadowType) {        case GTKConstants.SHADOW_IN:            if (info == "spinbutton" && c instanceof JButton) {                upperLeft = style.getGTKColor(c, region, state,                        GTKColorType.DARK);                innerRight = upperLeft;                bottomRight = style.getGTKColor(c, region, state,                        GTKColorType.BLACK);            } else {                upperLeft = style.getGTKColor(c, region, state,                        GTKColorType.DARK);                innerLeft = style.getGTKColor(c, region, state,                        GTKColorType.BLACK);                bottomRight = style.getGTKColor(c, region, state,                        GTKColorType.LIGHT);                innerRight = style.getGTKColor(c, region, state,                        GTKColorType.BACKGROUND);            }            break;        case GTKConstants.SHADOW_OUT:            upperLeft = style.getGTKColor(c, region, state,GTKColorType.LIGHT);            innerLeft = style.getGTKColor(c, region, state,                                          GTKColorType.BACKGROUND);            bottomRight = style.getGTKColor(c, region, state,                                            GTKColorType.BLACK);            innerRight = style.getGTKColor(c, region, state,GTKColorType.DARK);            break;        default:            assert true : "Unknown shadow type!";        }        if (info == "spinbutton" && c instanceof JButton) {            _paintSpinButtonShadow(g, x, y, w, h, xThickness, yThickness,                    upperLeft, innerLeft, bottomRight, innerRight);        } else {            _paintShadow(g,  x, y, w, h, xThickness, yThickness,                    upperLeft, innerLeft, bottomRight, innerRight);        }    }    void _paintShadow(Graphics g, int x, int y, int w, int h,                 int xThickness, int yThickness, Color upperLeft,                 Color innerLeft, Color bottomRight, Color innerRight) {        g.translate(x, y);        // left/top        g.setColor(upperLeft);        if (xThickness > 0) {            g.drawLine(0, 0, 0, h - 1);        }        if (yThickness > 0) {            g.drawLine(1, 0, w - 1, 0);        }        // Inner left/top        if (xThickness > 1 || yThickness > 1) {            g.setColor(innerLeft);            if (xThickness > 1) {                g.drawLine(1, 1, 1, h - 2);            }            if (yThickness > 1) {                g.drawLine(2, 1, w - 2, 1);            }        }        // Bottom/right        g.setColor(bottomRight);        if (xThickness > 0) {            g.drawLine(w - 1, 1, w - 1, h - 1);        }        if (yThickness > 0) {            g.drawLine(1, h - 1, w - 2, h - 1);        }        // Inner bottom/right        if (xThickness > 1 || yThickness > 1) {            g.setColor(innerRight);            if (xThickness > 1) {                g.drawLine(w - 2, 2, w - 2, h - 2);            }            if (yThickness > 1) {                g.drawLine(2, h - 2, w - 3, h - 2);            }        }        g.translate(-x, -y);    }    void _paintSpinButtonShadow(Graphics g, int x, int y,                 int w, int h, int xThickness, int yThickness, Color upperLeft,                 Color innerLeft, Color bottomRight, Color innerRight) {        g.translate(x, y);        // top        g.setColor(upperLeft);        g.drawLine(0, 0, w - 1, 0);        // bottom        g.setColor(innerRight);        g.drawLine(0, h - 1, w - 1, h - 1);        // left/right        g.setColor(bottomRight);        g.drawLine(0, 0, 0, h - 1);        g.drawLine(w - 1, 0, w - 1, h - 1);        g.translate(-x, -y);    }    public void paintExpander(SynthContext context, Graphics g, int state,                              int expanderStyle, String info, int x,                              int y, int w, int h) {        if (expanderStyle == GTKConstants.EXPANDER_COLLAPSED) {            if (state != SynthConstants.MOUSE_OVER) {                paintHollowTriangle(context, g, state,

⌨️ 快捷键说明

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