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

📄 gtkengine.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    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,                    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.getComponent(), ss.getRegion(),                state, GTKColorType.FOREGROUND);        Color background = style.getGTKColor(ss.getComponent(), ss.getRegion(),                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(SynthContext context, Graphics g, int state,                           int shadowType, String info,                           int x, int y, int w, int h, int orientation) {        paintBox(context, g, state, shadowType, info, x, y, w, h);        if (context.getRegion() == Region.SLIDER_THUMB) {            if (orientation == GTKConstants.HORIZONTAL) {                paintVline(context, g, state, info, x + w / 2 - 1, y + 2, 2,                           h - 4);            } else {                paintHline(context, g, state, info, x + 2, y + h / 2 - 1,                           w - 4, 2);            }        }    }    public void paintHline(SynthContext context, Graphics g, 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;        g.setColor(style.getGTKColor(context.getComponent(),                                     context.getRegion(), state,                                     GTKColorType.DARK));        g.drawLine(0, centerY, w - 2, centerY);        g.setColor(style.getGTKColor(context.getComponent(),                                     context.getRegion(), 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(SynthContext context, Graphics g, 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.getComponent(),                                     context.getRegion(),                                     state, GTKColorType.DARK));        g.drawLine(centerX, 0, centerX, h - 2);        g.drawLine(centerX, 0, centerX + 1, 0);        g.setColor(style.getGTKColor(context.getComponent(),                                     context.getRegion(),                                     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.     */    void paintBackground(SynthContext context, Graphics g, 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.getClipRect();                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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -