gtkdefaultengine.java

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

JAVA
1,177
字号
                        GTKColorType.DARK);                innerLeft = style.getGTKColor(context, state,                        GTKColorType.BLACK);                bottomRight = style.getGTKColor(context, state,                        GTKColorType.LIGHT);                innerRight = style.getGTKColor(context, state,                        GTKColorType.BACKGROUND);            }            break;        case OUT:            upperLeft = style.getGTKColor(context, state,GTKColorType.LIGHT);            innerLeft = style.getGTKColor(context, state, GTKColorType.BACKGROUND);            bottomRight = style.getGTKColor(context, state, GTKColorType.BLACK);            innerRight = style.getGTKColor(context, 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(Graphics g, SynthContext context, Region id,            int state, ExpanderStyle expanderStyle, String info,            int x, int y, int w, int h) {        if (expanderStyle == ExpanderStyle.COLLAPSED) {            if (state != SynthConstants.MOUSE_OVER) {                paintHollowTriangle(context, g, state,                    x, y, Math.min(w,h),                    adjustAxisForComponentOrientation(                    context.getComponent(), SwingConstants.EAST));            } else {            }        }        else {            if (state != SynthConstants.MOUSE_OVER) {                paintHollowTriangle(context, g, state,                    x, y, Math.min(w,h), SwingConstants.SOUTH);            } else {            }        }    }    private void paintHollowTriangle(SynthContext ss, Graphics g, int state,            int x, int y, int size, int direction) {        GTKStyle style = (GTKStyle)ss.getStyle();        int mid, height, thick, i, j, up, down;        mid = (size / 2);        height = size / 2 + 1;        thick = Math.max(1, size / 7);        g.translate(x, y);        Color foreground = style.getGTKColor(ss, state, GTKColorType.FOREGROUND);        Color background = style.getGTKColor(ss, state, GTKColorType.BACKGROUND);        switch(direction) {        case SwingConstants.NORTH:            j = size / 2 + height / 2 - 1;            // Fill in the background of the expander icon.            g.setColor(background);            for(i = height - 1; i > 0; i--) {                g.drawLine(mid - i + 1, j, mid + i - 1, j);                j--;            }            g.setColor(foreground);            j = size / 2 + height / 2 - 1;            down = thick - 1;            // Draw the base of the triangle.            for (up = 0; up < thick; up++) {                g.drawLine(0 - down, j - up, size + down, j - up);                down--;            }            j--;            // Paint sides of triangle.            for(i = height - 1; i > 0; i--) {                for (up = 0; up < thick; up++ ) {                    g.drawLine(mid - i + 1 - up, j, mid - i + 1 - up, j);                    g.drawLine(mid + i - 1 + up, j, mid + i - 1 + up, j);                }                j--;            }            // Paint remainder of tip if necessary.            if (thick > 1) {                for (up = thick - 2; up >= 0; up--) {                    g.drawLine(mid - up, j, mid + up, j);                    j--;                }            }            break;        case SwingConstants.SOUTH:            j = size / 2 - height / 2 - 1;            // Fill in the background of the expander icon.            g.setColor(background);            for (i = height - 1; i > 0; i--) {                g.drawLine(mid - i + 1, j, mid + i - 1, j);                j++;            }            g.setColor(foreground);            j = size / 2 - height / 2 - 1;            down = thick - 1;            // Draw the base of the triangle.            for (up = 0; up < thick; up++) {                g.drawLine(0 - down, j + up, size + down, j + up);                down--;            }            j++;            // Paint sides of triangle.            for (i = height - 1; i > 0; i--) {                for (up = 0; up < thick; up++ ) {                    g.drawLine(mid - i + 1 - up, j, mid - i + 1 - up, j);                    g.drawLine(mid + i - 1 + up, j, mid + i - 1 + up, j);                }                j++;            }            // Paint remainder of tip if necessary.            if (thick > 1) {                for (up = thick - 2; up >= 0; up--) {                    g.drawLine(mid - up, j, mid + up, j);                    j++;                }            }            break;        case SwingConstants.WEST:            i = size / 2 + height / 2 - 1;            // Fill in the background of the expander icon.            g.setColor(background);            for (j = height - 1; j > 0; j--) {                g.drawLine(i, mid - j + 1, i, mid + j - 1);                i--;            }            g.setColor(foreground);            i = size / 2 + height / 2 - 1;            down = thick - 1;            // Draw the base of the triangle.            for (up = 0; up < thick; up++) {                g.drawLine(i - up, 0 - down, i - up, size + down);                down--;            }            i--;            // Paint sides of triangle.            for (j = height - 1; j > 0; j--) {                for (up = 0; up < thick; up++) {                    g.drawLine(i, mid - j + 1 - up, i, mid - j + 1 - up);                    g.drawLine(i, mid + j - 1 + up, i, mid + j - 1 + up);                }                i--;            }            // Paint remainder of tip if necessary.            if (thick > 1) {                for (up = thick - 2; up >= 0; up--) {                    g.drawLine(i, mid - up, i, mid + up);                    i--;                }            }            break;        case SwingConstants.EAST:            i = size / 2 - height / 2 - 1;            // Fill in the background of the expander icon.            g.setColor(background);            for (j = height - 1; j > 0; j--) {                g.drawLine(i, mid - j + 1, i, mid + j - 1);                i++;            }            g.setColor(foreground);            i = size / 2 - height / 2 - 1;            down = thick - 1;            // Draw the base of the triangle.            for (up = 0; up < thick; up++) {                g.drawLine(i + up, 0 - down, i + up, size + down);                down--;            }            i++;            // Paint sides of triangle.            for (j = height - 1; j > 0; j--) {                for (up = 0; up < thick; up++) {                    g.drawLine(i, mid - j + 1 - up, i, mid - j + 1 - up);                    g.drawLine(i, mid + j - 1 + up, i, mid + j - 1 + up);                }                i++;            }            // Paint remainder of tip if necessary.            if (thick > 1) {                for (up = thick - 2; up >= 0; up--) {                    g.drawLine(i, mid - up, i, mid + up);                    i++;                }            }            break;        }        g.translate(-x, -y);	    }    public void paintSlider(Graphics g, SynthContext context, Region id,            int state, ShadowType shadowType, String info,            int x, int y, int w, int h, Orientation orientation) {        paintBox(g, context, id, state, shadowType, info, x, y, w, h);        if (context.getRegion() == Region.SLIDER_THUMB) {            if (orientation == Orientation.HORIZONTAL) {                paintVline(g, context, id, state, info,                        x + w / 2 - 1, y + 2, 2, h - 4);            } else {                paintHline(g, context, id, state, info,                        x + 2, y + h / 2 - 1, w - 4, 2);            }        }    }    public void paintHline(Graphics g, SynthContext context, Region id,            int state, String info, int x, int y, int w, int h) {        g.translate(x, y);        GTKStyle style = (GTKStyle)context.getStyle();        int centerY = h / 2;        if (h == 2) {            centerY = 0;        }        g.setColor(style.getGTKColor(context, state, GTKColorType.DARK));        g.drawLine(0, centerY, w - 2, centerY);        g.setColor(style.getGTKColor(context, state, GTKColorType.LIGHT));        g.drawLine(0, centerY + 1, w - 1, centerY + 1);        g.drawLine(w - 1, centerY, w - 1, centerY + 1);        g.translate(-x, -y);    }    public void paintVline(Graphics g, SynthContext context, Region id,            int state, String info, int x, int y, int w, int h) {        g.translate(x, y);        GTKStyle style = (GTKStyle)context.getStyle();        int centerX = w / 2;        g.setColor(style.getGTKColor(context, state, GTKColorType.DARK));        g.drawLine(centerX, 0, centerX, h - 2);        g.drawLine(centerX, 0, centerX + 1, 0);        g.setColor(style.getGTKColor(context, state, GTKColorType.LIGHT));        g.drawLine(centerX + 1, 1, centerX + 1, h - 1);        g.drawLine(centerX, h - 1, centerX + 1, h - 1);        g.translate(-x, -y);    }    /**     * If necessary paints the background.     */    public void paintBackground(Graphics g, SynthContext context,            Region id, int state, Color color, int x, int y, int w, int h) {        GTKStyle style = (GTKStyle)context.getStyle();        if (style.fillBackground(context, state)) {            g.setColor(color);            g.fillRect(x, y, w, h);        }        else {            Image image = style.getBackgroundImage(context, state);            int iW;            int iH;             if (image != null && (iW = image.getWidth(null)) > 0 &&                                 (iH = image.getHeight(null)) > 0) {                // Map the x/y location to originate from the origin of the                // window                int x2 = x;                int y2 = y;                Component parent = context.getComponent().getParent();                while (parent != null && !(parent instanceof Window) &&                       !(parent instanceof java.applet.Applet)) {                    Component nextParent = parent.getParent();                    if (parent instanceof JRootPane &&                                !(nextParent instanceof Window) &&                               !(nextParent instanceof java.applet.Applet)) {                        x2 += parent.getX();                        y2 += parent.getY();                    }                    parent = nextParent;                }                x2 = x2 % iW;                y2 = y2 % iH;                Rectangle clip = g.getClipBounds();                 int cx1 = clip.x;                 int cy1 = clip.y;                 int cx2 = cx1 + clip.width;                 int cy2 = cy1 + clip.height;                 int lastIY = y2;                for (int yCounter = y, maxY = y + h; yCounter < maxY;                         yCounter += (iH - lastIY), lastIY = 0) {                    int lastIX = x2;                    for (int xCounter = x, maxX = x + w; xCounter < maxX;                             xCounter += (iW - lastIX), lastIX = 0) {                        int dx2 = Math.min(maxX, xCounter + iW - lastIX);                        int dy2 = Math.min(maxY, yCounter + iH - lastIY);                        if (dx2 > cx1 && dy2 > cy1 && cx2 > xCounter &&                                         cy2 > yCounter) {                            g.drawImage(image, xCounter, yCounter, dx2, dy2,                                    lastIX, lastIY, lastIX + dx2 - xCounter,                                    lastIY + dy2 - yCounter, null);                        }                    }                }            }        }    }}

⌨️ 快捷键说明

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