Java Code Examples for java.awt.Graphics.translate()

The following are Jave code examples for showing how to use translate() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: JTitledPanel.java   View Source Code Vote up 6 votes
protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) {
    if (!c.isEnabled()) {
        return;
    }

    Color oldColor = g.getColor();
    int h = height;
    int w = width;

    g.translate(x, y);

    g.setColor(getHighlightInnerColor(c));
    g.drawLine(0, 0, 0, h - 1);
    g.drawLine(1, 0, w - 1, 0);

    g.setColor(getShadowOuterColor(c));
    g.drawLine(0, h - 1, w - 1, h - 1);
    g.drawLine(w - 1, 0, w - 1, h - 2);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 2
Project: incubator-netbeans   File: DeletedListRenderer.java   View Source Code Vote up 6 votes
@Override
public void paintComponent (Graphics g) {
    Dimension d_check = check == null ? new Dimension(0, 0) : check.getSize();
    Dimension d_label = stringDisplayer == null ? new Dimension(0,0) : 
        stringDisplayer.getPreferredSize();

    int y_check = 0;
    int y_label = 0;

    if (d_check.height >= d_label.height) {
        y_label = (d_check.height - d_label.height) / 2;
    }
    if (check != null) {
        check.setBounds (0, 0, d_check.width, d_check.height);
        check.paint(g);
    }
    if (stringDisplayer != null) {
        int y = y_label-2;
        stringDisplayer.setBounds (d_check.width, y, 
            d_label.width, getHeight()-1);
        g.translate (d_check.width, y_label);
        stringDisplayer.paint(g);
        g.translate (-d_check.width, -y_label);
    }
}
 
Example 3
Project: OpenJSharp   File: MotifGraphicsUtils.java   View Source Code Vote up 6 votes
public static void drawGroove(Graphics g, int x, int y, int w, int h,
                              Color shadow, Color highlight)
{
    Color oldColor = g.getColor();  // Make no net change to g
    g.translate(x, y);

    g.setColor(shadow);
    g.drawRect(0, 0, w-2, h-2);

    g.setColor(highlight);
    g.drawLine(1, h-3, 1, 1);
    g.drawLine(1, 1, w-3, 1);

    g.drawLine(0, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 0);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 4
Project: OpenJSharp   File: MotifScrollBarUI.java   View Source Code Vote up 6 votes
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
        return;
    }

    int w = thumbBounds.width;
    int h = thumbBounds.height;

    g.translate(thumbBounds.x, thumbBounds.y);
    g.setColor(thumbColor);
    g.fillRect(0, 0, w - 1, h - 1);

    g.setColor(thumbHighlightColor);
    drawVLine(g, 0, 0, h - 1);
    drawHLine(g, 1, w - 1, 0);

    g.setColor(thumbLightShadowColor);
    drawHLine(g, 1, w - 1, h - 1);
    drawVLine(g, w - 1, 1, h - 2);

    g.translate(-thumbBounds.x, -thumbBounds.y);
}
 
Example 5
Project: myster   File: TabPanel.java   View Source Code Vote up 6 votes
public synchronized void paint(Graphics g) {
    Tab selectedtab = null;
    Tab workingtab;

    int cwxloc = getMaxLength();//current working x location.. for
                                // graphics context transpose.
    int selectedcwxloc = 0;//yippy.

    for (int i = tabs.size() - 1; i >= 0; i--) {
        workingtab = getTab(i);
        cwxloc -= workingtab.getSize().width;
        g.translate(cwxloc, 0);
        workingtab.paint(g);
        g.translate(-cwxloc, 0);
        if (workingtab.isSelected()) {
            selectedtab = workingtab;
            selectedcwxloc = cwxloc;
        }
        cwxloc += overlap;
    }

    g.translate(selectedcwxloc, 0);
    if (selectedtab != null)
        selectedtab.paint(g);
    g.translate(-selectedcwxloc, 0);
}
 
Example 6
Project: openjdk-jdk10   File: MyCursor.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics gr) {
    gr.setColor(Color.GREEN);
    ((Graphics2D)gr).setStroke(new BasicStroke(3));

    gr.translate(width/2, height/2);
    int R = width/4;
    gr.drawOval(-R, -R, 2*R, 2*R);
    gr.drawLine(-R, R, R, -R);
}
 
Example 7
Project: Logisim   File: Tunnel.java   View Source Code Vote up 5 votes
@Override
public void paintInstance(InstancePainter painter) {
	Location loc = painter.getLocation();
	int x = loc.getX();
	int y = loc.getY();
	Graphics g = painter.getGraphics();
	g.translate(x, y);
	g.setColor(Color.BLACK);
	paintGhost(painter);
	g.translate(-x, -y);
	painter.drawPorts();
}
 
Example 8
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    if (rctx.animate) {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawLine(x, y, x + size, y);
            if ((x -= 3) < 0) x += rctx.maxX;
            if ((y -= 1) < 0) y += rctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawLine(x, y, x + size, y);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 9
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.fillPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 10
Project: openjdk-jdk10   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    if (rctx.animate) {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawLine(x, y, x, y + size);
            if ((x -= 3) < 0) x += rctx.maxX;
            if ((y -= 1) < 0) y += rctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawLine(x, y, x, y + size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 11
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    if (rctx.animate) {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawOval(x, y, size, size);
            if ((x -= 3) < 0) x += rctx.maxX;
            if ((y -= 1) < 0) y += rctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.drawOval(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 12
Project: openjdk-jdk10   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size;
    int x = rctx.initX;
    int y = rctx.initY;
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    if (rctx.animate) {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.fillRect(x, y, size, size);
            if ((x -= 3) < 0) x += rctx.maxX;
            if ((y -= 1) < 0) y += rctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.fillRect(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 13
Project: jdk8u-jdk   File: MetalBorders.java   View Source Code Vote up 5 votes
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
    if (!(c instanceof JMenuItem)) {
        return;
    }
    JMenuItem b = (JMenuItem) c;
    ButtonModel model = b.getModel();

    g.translate( x, y );

    if ( c.getParent() instanceof JMenuBar ) {
        if ( model.isArmed() || model.isSelected() ) {
            g.setColor( MetalLookAndFeel.getControlDarkShadow() );
            g.drawLine( 0, 0, w - 2, 0 );
            g.drawLine( 0, 0, 0, h - 1 );
            g.drawLine( w - 2, 2, w - 2, h - 1 );

            g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
            g.drawLine( w - 1, 1, w - 1, h - 1 );

            g.setColor( MetalLookAndFeel.getMenuBackground() );
            g.drawLine( w - 1, 0, w - 1, 0 );
        }
    } else {
        if (  model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) {
            g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
            g.drawLine( 0, 0, w - 1, 0 );

            g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
            g.drawLine( 0, h - 1, w - 1, h - 1 );
        } else {
            g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
            g.drawLine( 0, 0, 0, h - 1 );
        }
    }

    g.translate( -x, -y );
}
 
Example 14
Project: Logisim   File: Buffer.java   View Source Code Vote up 5 votes
private void paintBase(InstancePainter painter) {
	Direction facing = painter.getAttributeValue(StdAttr.FACING);
	Location loc = painter.getLocation();
	int x = loc.getX();
	int y = loc.getY();
	Graphics g = painter.getGraphics();
	g.translate(x, y);
	double rotate = 0.0;
	if (facing != Direction.EAST && g instanceof Graphics2D) {
		rotate = -facing.toRadians();
		((Graphics2D) g).rotate(rotate);
	}

	GraphicsUtil.switchToWidth(g, 2);
	int[] xp = new int[4];
	int[] yp = new int[4];
	xp[0] = 0;
	yp[0] = 0;
	xp[1] = -19;
	yp[1] = -7;
	xp[2] = -19;
	yp[2] = 7;
	xp[3] = 0;
	yp[3] = 0;
	g.drawPolyline(xp, yp, 4);

	if (rotate != 0.0) {
		((Graphics2D) g).rotate(-rotate);
	}
	g.translate(-x, -y);
}
 
Example 15
Project: MaxSim   File: ColorChooserButton.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    Color oldColor = g.getColor();
    g.translate(x, y);

    g.setColor(color);
    g.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);

    g.setColor(Color.black);
    g.drawRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 16
Project: jdk8u-jdk   File: WindowsBorders.java   View Source Code Vote up 4 votes
public void paintBorder(Component c, Graphics g, int x, int y,
                        int width, int height) {
    if (!(c instanceof JToolBar)) {
        return;
    }
    g.translate(x, y);

    XPStyle xp = XPStyle.getXP();
    if (xp != null) {
        Border xpBorder = xp.getBorder(c, Part.TP_TOOLBAR);
        if (xpBorder != null) {
            xpBorder.paintBorder(c, g, 0, 0, width, height);
        }
    }
    if (((JToolBar)c).isFloatable()) {
        boolean vertical = ((JToolBar)c).getOrientation() == VERTICAL;

        if (xp != null) {
            Part part = vertical ? Part.RP_GRIPPERVERT : Part.RP_GRIPPER;
            Skin skin = xp.getSkin(c, part);
            int dx, dy, dw, dh;
            if (vertical) {
                dx = 0;
                dy = 2;
                dw = width - 1;
                dh = skin.getHeight();
            } else {
                dw = skin.getWidth();
                dh = height - 1;
                dx = c.getComponentOrientation().isLeftToRight() ? 2 : (width-dw-2);
                dy = 0;
            }
            skin.paintSkin(g, dx, dy, dw, dh, State.NORMAL);

        } else {

            if (!vertical) {
                if (c.getComponentOrientation().isLeftToRight()) {
                    g.setColor(shadow);
                    g.drawLine(4, 3, 4, height - 4);
                    g.drawLine(4, height - 4, 2, height - 4);

                    g.setColor(highlight);
                    g.drawLine(2, 3, 3, 3);
                    g.drawLine(2, 3, 2, height - 5);
                } else {
                    g.setColor(shadow);
                    g.drawLine(width - 3, 3, width - 3, height - 4);
                    g.drawLine(width - 4, height - 4, width - 4, height - 4);

                    g.setColor(highlight);
                    g.drawLine(width - 5, 3, width - 4, 3);
                    g.drawLine(width - 5, 3, width - 5, height - 5);
                }
            } else { // Vertical
                g.setColor(shadow);
                g.drawLine(3, 4, width - 4, 4);
                g.drawLine(width - 4, 2, width - 4, 4);

                g.setColor(highlight);
                g.drawLine(3, 2, width - 4, 2);
                g.drawLine(3, 2, 3, 3);
            }
        }
    }

    g.translate(-x, -y);
}
 
Example 17
Project: openjdk-jdk10   File: MetalBorders.java   View Source Code Vote up 4 votes
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {

            g.translate(x,y);

            int messageType = JOptionPane.PLAIN_MESSAGE;
            if (c instanceof JInternalFrame) {
                Object obj = ((JInternalFrame) c).getClientProperty(
                              "JInternalFrame.messageType");
                if (obj instanceof Integer) {
                    messageType = (Integer) obj;
                }
            }

            Color borderColor;

            switch (messageType) {
            case(JOptionPane.ERROR_MESSAGE):
                borderColor = UIManager.getColor(
                    "OptionPane.errorDialog.border.background");
                break;
            case(JOptionPane.QUESTION_MESSAGE):
                borderColor = UIManager.getColor(
                    "OptionPane.questionDialog.border.background");
                break;
            case(JOptionPane.WARNING_MESSAGE):
                borderColor = UIManager.getColor(
                    "OptionPane.warningDialog.border.background");
                break;
            case(JOptionPane.INFORMATION_MESSAGE):
            case(JOptionPane.PLAIN_MESSAGE):
            default:
                borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
                break;
            }

            g.setColor(borderColor);

              // Draw outermost lines
              g.drawLine( 1, 0, w-2, 0);
              g.drawLine( 0, 1, 0, h-2);
              g.drawLine( w-1, 1, w-1, h-2);
              g.drawLine( 1, h-1, w-2, h-1);

              // Draw the bulk of the border
              for (int i = 1; i < 3; i++) {
                  g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1);
              }

            g.translate(-x,-y);

        }
 
Example 18
Project: sstore-soft   File: TableSorter.java   View Source Code Vote up 4 votes
public void paintIcon(Component c, Graphics g, int x, int y) {

            Color color = c == null ? Color.gray
                                    : c.getBackground();

            // In a compound sort, make each succesive triangle 20%
            // smaller than the previous one.
            int dx = (int) (size / 2 * Math.pow(0.8, priority));
            int dy = descending ? dx
                                : -dx;

            // Align icon (roughly) with font baseline.
            y = y + 5 * size / 6 + (descending ? -dy
                                               : 0);

            int shift = descending ? 1
                                   : -1;

            g.translate(x, y);

            // Right diagonal.
            g.setColor(color.darker());
            g.drawLine(dx / 2, dy, 0, 0);
            g.drawLine(dx / 2, dy + shift, 0, shift);

            // Left diagonal.
            g.setColor(color.brighter());
            g.drawLine(dx / 2, dy, dx, 0);
            g.drawLine(dx / 2, dy + shift, dx, shift);

            // Horizontal line.
            if (descending) {
                g.setColor(color.darker().darker());
            } else {
                g.setColor(color.brighter().brighter());
            }

            g.drawLine(dx, 0, 0, 0);
            g.setColor(color);
            g.translate(-x, -y);
        }
 
Example 19
Project: parabuild-ci   File: TableSorter.java   View Source Code Vote up 4 votes
public void paintIcon(Component c, Graphics g, int x, int y) {

            Color color = c == null ? Color.gray
                                    : c.getBackground();

            // In a compound sort, make each succesive triangle 20%
            // smaller than the previous one.
            int dx = (int) (size / 2 * Math.pow(0.8, priority));
            int dy = descending ? dx
                                : -dx;

            // Align icon (roughly) with font baseline.
            y = y + 5 * size / 6 + (descending ? -dy
                                               : 0);

            int shift = descending ? 1
                                   : -1;

            g.translate(x, y);

            // Right diagonal.
            g.setColor(color.darker());
            g.drawLine(dx / 2, dy, 0, 0);
            g.drawLine(dx / 2, dy + shift, 0, shift);

            // Left diagonal.
            g.setColor(color.brighter());
            g.drawLine(dx / 2, dy, dx, 0);
            g.drawLine(dx / 2, dy + shift, dx, shift);

            // Horizontal line.
            if (descending) {
                g.setColor(color.darker().darker());
            } else {
                g.setColor(color.brighter().brighter());
            }

            g.drawLine(dx, 0, 0, 0);
            g.setColor(color);
            g.translate(-x, -y);
        }
 
Example 20
Project: jdk8u-jdk   File: MotifBorders.java   View Source Code Vote up 4 votes
public static void drawBezel(Graphics g, int x, int y, int w, int h,
                           boolean isPressed, boolean hasFocus,
                           Color shadow, Color highlight,
                           Color darkShadow, Color focus)  {

    Color oldColor = g.getColor();
    g.translate(x, y);

    if (isPressed) {
        if (hasFocus){
            g.setColor(focus);
            g.drawRect(0, 0, w-1, h-1);
        }
        g.setColor(shadow);         // inner border
        g.drawRect(1, 1, w-3, h-3);

        g.setColor(highlight);    // inner 3D border
        g.drawLine(2, h-3, w-3, h-3);
        g.drawLine(w-3, 2, w-3, h-4);

    } else {
        if (hasFocus) {
            g.setColor(focus);
            g.drawRect(0, 0, w-1, h-1);

            g.setColor(highlight);   // inner 3D border
            g.drawLine(1, 1, 1, h-3);
            g.drawLine(2, 1, w-4, 1);

            g.setColor(shadow);
            g.drawLine(2, h-3, w-3, h-3);
            g.drawLine(w-3, 1, w-3, h-4);

            g.setColor(darkShadow);        // black drop shadow  __|
            g.drawLine(1, h-2, w-2, h-2);
            g.drawLine(w-2, h-2, w-2, 1);
        } else {
            g.setColor(highlight);    // inner 3D border
            g.drawLine(1,1,1,h-3);
            g.drawLine(2,1,w-4,1);
            g.setColor(shadow);
            g.drawLine(2,h-3,w-3,h-3);
            g.drawLine(w-3,1,w-3,h-4);

            g.setColor(darkShadow);         // black drop shadow  __|
            g.drawLine(1,h-2,w-2,h-2);
            g.drawLine(w-2,h-2,w-2,0);

        }
        g.translate(-x, -y);
    }
    g.setColor(oldColor);
}