Java Code Examples for sun.swing.SwingUtilities2#isScaledGraphics()

The following examples show how to use sun.swing.SwingUtilities2#isScaledGraphics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowsIconFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
    JCheckBox cb = (JCheckBox) c;
    ButtonModel model = cb.getModel();
    XPStyle xp = XPStyle.getXP();

    if (xp != null) {
        State state;
        if (model.isSelected()) {
            state = State.CHECKEDNORMAL;
            if (!model.isEnabled()) {
                state = State.CHECKEDDISABLED;
            } else if (model.isPressed() && model.isArmed()) {
                state = State.CHECKEDPRESSED;
            } else if (model.isRollover()) {
                state = State.CHECKEDHOT;
            }
        } else {
            state = State.UNCHECKEDNORMAL;
            if (!model.isEnabled()) {
                state = State.UNCHECKEDDISABLED;
            } else if (model.isPressed() && model.isArmed()) {
                state = State.UNCHECKEDPRESSED;
            } else if (model.isRollover()) {
                state = State.UNCHECKEDHOT;
            }
        }
        Part part = Part.BP_CHECKBOX;
        xp.getSkin(c, part).paintSkin(g, x, y, state);
    } else {
        // outer bevel
        if(!cb.isBorderPaintedFlat()) {
            // Outer top/left
            g.setColor(UIManager.getColor("CheckBox.shadow"));
            g.drawLine(x, y, x+11, y);
            g.drawLine(x, y+1, x, y+11);

            // Outer bottom/right
            g.setColor(UIManager.getColor("CheckBox.highlight"));
            g.drawLine(x+12, y, x+12, y+12);
            g.drawLine(x, y+12, x+11, y+12);

            // Inner top.left
            g.setColor(UIManager.getColor("CheckBox.darkShadow"));
            g.drawLine(x+1, y+1, x+10, y+1);
            g.drawLine(x+1, y+2, x+1, y+10);

            // Inner bottom/right
            g.setColor(UIManager.getColor("CheckBox.light"));
            g.drawLine(x+1, y+11, x+11, y+11);
            g.drawLine(x+11, y+1, x+11, y+10);

            // inside box
            if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
                g.setColor(UIManager.getColor("CheckBox.background"));
            } else {
                g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
            }
            g.fillRect(x+2, y+2, csize-4, csize-4);
        } else {
            g.setColor(UIManager.getColor("CheckBox.shadow"));
            g.drawRect(x+1, y+1, csize-3, csize-3);

            if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
                g.setColor(UIManager.getColor("CheckBox.background"));
            } else {
                g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
            }
            g.fillRect(x+2, y+2, csize-4, csize-4);
        }

        if(model.isEnabled()) {
            g.setColor(UIManager.getColor("CheckBox.foreground"));
        } else {
            g.setColor(UIManager.getColor("CheckBox.shadow"));
        }

        // paint check
        if (model.isSelected()) {
            if (SwingUtilities2.isScaledGraphics(g)) {
                int[] xPoints = {3, 5, 9, 9, 5, 3};
                int[] yPoints = {5, 7, 3, 5, 9, 7};
                g.translate(x, y);
                g.fillPolygon(xPoints, yPoints, 6);
                g.drawPolygon(xPoints, yPoints, 6);
                g.translate(-x, -y);
            } else {
                g.drawLine(x + 9, y + 3, x + 9, y + 3);
                g.drawLine(x + 8, y + 4, x + 9, y + 4);
                g.drawLine(x + 7, y + 5, x + 9, y + 5);
                g.drawLine(x + 6, y + 6, x + 8, y + 6);
                g.drawLine(x + 3, y + 7, x + 7, y + 7);
                g.drawLine(x + 4, y + 8, x + 6, y + 8);
                g.drawLine(x + 5, y + 9, x + 5, y + 9);
                g.drawLine(x + 3, y + 5, x + 3, y + 5);
                g.drawLine(x + 3, y + 6, x + 4, y + 6);
            }
        }
    }
}
 
Example 2
Source File: WindowsIconFactory.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
    JCheckBox cb = (JCheckBox) c;
    ButtonModel model = cb.getModel();
    XPStyle xp = XPStyle.getXP();

    if (xp != null) {
        State state;
        if (model.isSelected()) {
            state = State.CHECKEDNORMAL;
            if (!model.isEnabled()) {
                state = State.CHECKEDDISABLED;
            } else if (model.isPressed() && model.isArmed()) {
                state = State.CHECKEDPRESSED;
            } else if (model.isRollover()) {
                state = State.CHECKEDHOT;
            }
        } else {
            state = State.UNCHECKEDNORMAL;
            if (!model.isEnabled()) {
                state = State.UNCHECKEDDISABLED;
            } else if (model.isPressed() && model.isArmed()) {
                state = State.UNCHECKEDPRESSED;
            } else if (model.isRollover()) {
                state = State.UNCHECKEDHOT;
            }
        }
        Part part = Part.BP_CHECKBOX;
        xp.getSkin(c, part).paintSkin(g, x, y, state);
    } else {
        // outer bevel
        if(!cb.isBorderPaintedFlat()) {
            // Outer top/left
            g.setColor(UIManager.getColor("CheckBox.shadow"));
            g.drawLine(x, y, x+11, y);
            g.drawLine(x, y+1, x, y+11);

            // Outer bottom/right
            g.setColor(UIManager.getColor("CheckBox.highlight"));
            g.drawLine(x+12, y, x+12, y+12);
            g.drawLine(x, y+12, x+11, y+12);

            // Inner top.left
            g.setColor(UIManager.getColor("CheckBox.darkShadow"));
            g.drawLine(x+1, y+1, x+10, y+1);
            g.drawLine(x+1, y+2, x+1, y+10);

            // Inner bottom/right
            g.setColor(UIManager.getColor("CheckBox.light"));
            g.drawLine(x+1, y+11, x+11, y+11);
            g.drawLine(x+11, y+1, x+11, y+10);

            // inside box
            if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
                g.setColor(UIManager.getColor("CheckBox.background"));
            } else {
                g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
            }
            g.fillRect(x+2, y+2, csize-4, csize-4);
        } else {
            g.setColor(UIManager.getColor("CheckBox.shadow"));
            g.drawRect(x+1, y+1, csize-3, csize-3);

            if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
                g.setColor(UIManager.getColor("CheckBox.background"));
            } else {
                g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
            }
            g.fillRect(x+2, y+2, csize-4, csize-4);
        }

        if(model.isEnabled()) {
            g.setColor(UIManager.getColor("CheckBox.foreground"));
        } else {
            g.setColor(UIManager.getColor("CheckBox.shadow"));
        }

        // paint check
        if (model.isSelected()) {
            if (SwingUtilities2.isScaledGraphics(g)) {
                int[] xPoints = {3, 5, 9, 9, 5, 3};
                int[] yPoints = {5, 7, 3, 5, 9, 7};
                g.translate(x, y);
                g.fillPolygon(xPoints, yPoints, 6);
                g.drawPolygon(xPoints, yPoints, 6);
                g.translate(-x, -y);
            } else {
                g.drawLine(x + 9, y + 3, x + 9, y + 3);
                g.drawLine(x + 8, y + 4, x + 9, y + 4);
                g.drawLine(x + 7, y + 5, x + 9, y + 5);
                g.drawLine(x + 6, y + 6, x + 8, y + 6);
                g.drawLine(x + 3, y + 7, x + 7, y + 7);
                g.drawLine(x + 4, y + 8, x + 6, y + 8);
                g.drawLine(x + 5, y + 9, x + 5, y + 9);
                g.drawLine(x + 3, y + 5, x + 3, y + 5);
                g.drawLine(x + 3, y + 6, x + 4, y + 6);
            }
        }
    }
}
 
Example 3
Source File: BasicArrowButton.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Paints a triangle.
 *
 * @param g the {@code Graphics} to draw to
 * @param x the x coordinate
 * @param y the y coordinate
 * @param size the size of the triangle to draw
 * @param direction the direction in which to draw the arrow;
 *        one of {@code SwingConstants.NORTH},
 *        {@code SwingConstants.SOUTH}, {@code SwingConstants.EAST} or
 *        {@code SwingConstants.WEST}
 * @param isEnabled whether or not the arrow is drawn enabled
 */
public void paintTriangle(Graphics g, int x, int y, int size,
                                int direction, boolean isEnabled) {
    if (SwingUtilities2.isScaledGraphics(g)) {
        paintScaledTriangle(g, x, y, size, direction, isEnabled);
    } else {
        paintUnscaledTriangle(g, x, y, size, direction, isEnabled);
    }
}
 
Example 4
Source File: BasicArrowButton.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Paints a triangle.
 *
 * @param g the {@code Graphics} to draw to
 * @param x the x coordinate
 * @param y the y coordinate
 * @param size the size of the triangle to draw
 * @param direction the direction in which to draw the arrow;
 *        one of {@code SwingConstants.NORTH},
 *        {@code SwingConstants.SOUTH}, {@code SwingConstants.EAST} or
 *        {@code SwingConstants.WEST}
 * @param isEnabled whether or not the arrow is drawn enabled
 */
public void paintTriangle(Graphics g, int x, int y, int size,
                                int direction, boolean isEnabled) {
    if (SwingUtilities2.isScaledGraphics(g)) {
        paintScaledTriangle(g, x, y, size, direction, isEnabled);
    } else {
        paintUnscaledTriangle(g, x, y, size, direction, isEnabled);
    }
}
 
Example 5
Source File: BasicArrowButton.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Paints a triangle.
 *
 * @param g the {@code Graphics} to draw to
 * @param x the x coordinate
 * @param y the y coordinate
 * @param size the size of the triangle to draw
 * @param direction the direction in which to draw the arrow;
 *        one of {@code SwingConstants.NORTH},
 *        {@code SwingConstants.SOUTH}, {@code SwingConstants.EAST} or
 *        {@code SwingConstants.WEST}
 * @param isEnabled whether or not the arrow is drawn enabled
 */
public void paintTriangle(Graphics g, int x, int y, int size,
                                int direction, boolean isEnabled) {
    if (SwingUtilities2.isScaledGraphics(g)) {
        paintScaledTriangle(g, x, y, size, direction, isEnabled);
    } else {
        paintUnscaledTriangle(g, x, y, size, direction, isEnabled);
    }
}