List of usage examples for java.awt Graphics drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2);
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system. From source file:com.cburch.logisim.circuit.appear.AppearanceAnchor.java
@Override public void paint(Graphics g, HandleGesture gesture) { Location location = getLocation(); int x = location.getX(); int y = location.getY(); g.setColor(SYMBOL_COLOR);// ww w . j a v a2 s . co m g.drawOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS); Location e0 = location.translate(facing, RADIUS); Location e1 = location.translate(facing, RADIUS + INDICATOR_LENGTH); g.drawLine(e0.getX(), e0.getY(), e1.getX(), e1.getY()); }
From source file:edu.upf.bioevo.manhattanPlotter.QQPlot.java
void drawPlot() { int dotRadius; int xIncrement = (IMAGE_WIDTH - (xMargin * 2)) / (int) (maxExpectedLogValue + 1); int yIncrement = (IMAGE_HEIGHT - (yMargin * 2)) / (int) (maxObservedLogValue + 1); Graphics g = image.getGraphics(); // Cleans image g.setColor(Color.WHITE);//from w w w. ja v a2 s. c om g.fillRect(0, 0, image.getWidth(), image.getHeight()); // Draws axis lines g.setColor(Color.black); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, IMAGE_WIDTH - xMargin, IMAGE_HEIGHT - yMargin); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin, yMargin); // Draws confidence interval if (ic95Option) { g.setColor(Color.lightGray); for (int i = 0; i < upperCI.length - 1; i++) { int[] xPoints = { xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement) }; int[] yPoints = { IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i + 1] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i + 1] * yIncrement))) }; g.fillPolygon(xPoints, yPoints, 4); } } // Draws dots dotRadius = 4; g.setColor(Color.black); for (int i = 0; i < orderedLog10ObservedValues.length; i++) { int xPosition = xMargin + ((int) (orderedLog10ExpectedValues[i] * xIncrement)); int yPosition = IMAGE_HEIGHT - (yMargin + ((int) (orderedLog10ObservedValues[i] * yIncrement))); g.fillOval(xPosition - dotRadius, yPosition - dotRadius, dotRadius * 2, dotRadius * 2); } // --draw y axis scale // ----Calculates interval between labels in y axis int yInterval = 1; int verticalMaxValue = (int) maxObservedLogValue + 1; if (verticalMaxValue > 20) { yInterval = 5; } if (verticalMaxValue > 100) { yInterval = 50; } if (verticalMaxValue > 1000) { yInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= verticalMaxValue; i = i + yInterval) { int yPos = IMAGE_HEIGHT - (yMargin + (int) (((float) i / verticalMaxValue) * (IMAGE_HEIGHT - 2 * yMargin))); g.fillRect(45, yPos, 15, 3); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, 5, yPos + 10); } // --draw x axis scale // ----Calculates interval between labels in x axis int xInterval = 1; int horizontalMaxValue = (int) maxExpectedLogValue + 1; if (horizontalMaxValue > 20) { xInterval = 5; } if (horizontalMaxValue > 100) { xInterval = 50; } if (horizontalMaxValue > 1000) { xInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= horizontalMaxValue; i = i + xInterval) { int xPos = (xMargin + (int) (((float) i / horizontalMaxValue) * (IMAGE_WIDTH - 2 * xMargin))); g.fillRect(xPos, IMAGE_HEIGHT - yMargin, 3, 15); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, xPos - 15, IMAGE_HEIGHT - yMargin + 45); } // Draws identity line g.setColor(Color.RED); int endLineValue = horizontalMaxValue < verticalMaxValue ? horizontalMaxValue : verticalMaxValue; g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin + ((int) (endLineValue * xIncrement)), IMAGE_HEIGHT - (yMargin + ((int) (endLineValue * yIncrement)))); // -- title g.setColor(Color.blue); g.setFont(new Font("arial", 1, 35)); g.drawString(label, IMAGE_WIDTH / 7, 40); }
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
private void drawAxisLabels(Graphics graphics) { final int x = 20; final int y = origin.y; final int d = 50; graphics.setColor(Color.black); final int y2 = y - d; graphics.drawLine(x, y, x, y - d); graphics.drawLine(x, y2, x - 5, y2 + 5); graphics.drawLine(x, y2, x + 5, y2 + 5); graphics.drawString(axisLabel1, x - 15, y2 - 10); final int x2 = x + d; graphics.drawLine(x, y, x2, y);/*from w w w. ja v a 2s . c o m*/ graphics.drawLine(x2, y, x2 - 5, y - 5); graphics.drawLine(x2, y, x2 - 5, y + 5); graphics.drawString(axisLabel2, x2 - 10, y + 20); }
From source file:org.esa.s1tbx.ocean.toolviews.polarview.polarplot.PolarCanvas.java
private void drawAxisLabels(Graphics graphics) { final int x = 20; final int y = origin.y + 50; final int d = 50; graphics.setColor(Color.black); final int y2 = y - d; graphics.drawLine(x, y, x, y - d); graphics.drawLine(x, y2, x - 5, y2 + 5); graphics.drawLine(x, y2, x + 5, y2 + 5); graphics.drawString(axisLabel1, x - 15, y2 - 10); final int x2 = x + d; graphics.drawLine(x, y, x2, y);// www . ja v a 2s . c om graphics.drawLine(x2, y, x2 - 5, y - 5); graphics.drawLine(x2, y, x2 - 5, y + 5); graphics.drawString(axisLabel2, x2 - 10, y + 20); }
From source file:metrics.java
License:asdf
public void paint(Graphics g) { g.translate(100, 100);//from ww w. j a v a2s.c o m FontMetrics fm = null; int ascent, descent, leading, width1, width2, height; String string1 = "dsdas"; String string2 = "asdf"; int xPos = 25, yPos = 50; fm = g.getFontMetrics(); ascent = fm.getAscent(); descent = fm.getDescent(); leading = fm.getLeading(); height = fm.getHeight(); width1 = fm.stringWidth(string1); width2 = fm.stringWidth(string2); g.drawString(string1, xPos, yPos); g.drawLine(xPos, yPos - ascent - leading, xPos + width1, yPos - ascent - leading); g.drawLine(xPos, yPos - ascent, xPos + width1, yPos - ascent); g.drawLine(xPos, yPos, xPos + width1, yPos); g.drawLine(xPos, yPos + descent, xPos + width1, yPos + descent); g.drawString(string2, xPos, yPos + height); g.drawLine(xPos, yPos - ascent - leading + height, xPos + width2, yPos - ascent - leading + height); g.drawLine(xPos, yPos - ascent + height, xPos + width2, yPos - ascent + height); g.drawLine(xPos, yPos + height, xPos + width2, yPos + height); g.drawLine(xPos, yPos + descent + height, xPos + width2, yPos + descent + height); }
From source file:Main.java
public void paintStrikeLine(Graphics g, Shape a) { Color c = (Color) getElement().getAttributes().getAttribute("strike-color"); if (c != null) { int y = a.getBounds().y + a.getBounds().height - (int) getGlyphPainter().getDescent(this); y = y - (int) (getGlyphPainter().getAscent(this) * 0.3f); int x1 = (int) a.getBounds().getX(); int x2 = (int) (a.getBounds().getX() + a.getBounds().getWidth()); Color old = g.getColor(); g.setColor(c);//w ww. j a v a 2 s .c o m g.drawLine(x1, y, x2, y); g.setColor(old); } }
From source file:Main.java
public void paint(Graphics g) { g.translate(100, 100);/* w w w .j a v a2 s . com*/ FontMetrics fm = null; int ascent, descent, leading, width1, width2, height; String string1 = "www.java2s.com"; String string2 = "java2s.com"; int xPos = 25, yPos = 50; fm = g.getFontMetrics(); ascent = fm.getAscent(); descent = fm.getDescent(); leading = fm.getLeading(); height = fm.getHeight(); width1 = fm.stringWidth(string1); width2 = fm.stringWidth(string2); g.drawString(string1, xPos, yPos); g.drawLine(xPos, yPos - ascent - leading, xPos + width1, yPos - ascent - leading); g.drawLine(xPos, yPos - ascent, xPos + width1, yPos - ascent); g.drawLine(xPos, yPos, xPos + width1, yPos); g.drawLine(xPos, yPos + descent, xPos + width1, yPos + descent); g.drawString(string2, xPos, yPos + height); g.drawLine(xPos, yPos - ascent - leading + height, xPos + width2, yPos - ascent - leading + height); g.drawLine(xPos, yPos - ascent + height, xPos + width2, yPos - ascent + height); g.drawLine(xPos, yPos + height, xPos + width2, yPos + height); g.drawLine(xPos, yPos + descent + height, xPos + width2, yPos + descent + height); }
From source file:layout.BLDComponent.java
public void paint(Graphics g) { int width = getWidth(); int height = getHeight(); float alignmentX = getAlignmentX(); g.setColor(normalHue);// w ww .ja v a 2 s . c o m g.fill3DRect(0, 0, width, height, true); /* Draw a vertical white line at the alignment point.*/ // XXX: This code is probably not the best. g.setColor(Color.white); int x = (int) (alignmentX * (float) width) - 1; g.drawLine(x, 0, x, height - 1); /* Say what the alignment point is. */ g.setColor(Color.black); g.drawString(Float.toString(alignmentX), 3, height - 3); if (printSize) { System.out.println("BLDComponent " + name + ": size is " + width + "x" + height + "; preferred size is " + getPreferredSize().width + "x" + getPreferredSize().height); } }
From source file:ScaleTest_2008.java
/** * Paints the test image that will be downscaled and timed by the various * scaling methods. A different image is rendered into each of the four * quadrants of this image: RGB stripes, a picture, vector art, and * a black and white grid.// w w w .j a v a2 s .com */ private void paintOriginalImage() { Graphics g = originalImage.getGraphics(); // Erase to black g.setColor(Color.BLACK); g.fillRect(0, 0, FULL_SIZE, FULL_SIZE); // RGB quadrant for (int i = 0; i < QUAD_SIZE; i += 3) { int x = i; g.setColor(Color.RED); g.drawLine(x, 0, x, QUAD_SIZE); x++; g.setColor(Color.GREEN); g.drawLine(x, 0, x, QUAD_SIZE); x++; g.setColor(Color.BLUE); g.drawLine(x, 0, x, QUAD_SIZE); } // Picture quadrant try { URL url = getClass().getResource("BBGrayscale.png"); BufferedImage picture = ImageIO.read(url); // Center picture in quadrant area int xDiff = QUAD_SIZE - picture.getWidth(); int yDiff = QUAD_SIZE - picture.getHeight(); g.drawImage(picture, QUAD_SIZE + xDiff / 2, yDiff / 2, null); } catch (Exception e) { System.out.println("Problem reading image file: " + e); } // Vector drawing quadrant g.setColor(Color.WHITE); g.fillRect(0, QUAD_SIZE, QUAD_SIZE, QUAD_SIZE); g.setColor(Color.BLACK); g.drawOval(2, QUAD_SIZE + 2, QUAD_SIZE - 4, QUAD_SIZE - 4); g.drawArc(20, QUAD_SIZE + 20, (QUAD_SIZE - 40), QUAD_SIZE - 40, 190, 160); int eyeSize = 7; int eyePos = 30 - (eyeSize / 2); g.fillOval(eyePos, QUAD_SIZE + eyePos, eyeSize, eyeSize); g.fillOval(QUAD_SIZE - eyePos - eyeSize, QUAD_SIZE + eyePos, eyeSize, eyeSize); // B&W grid g.setColor(Color.WHITE); g.fillRect(QUAD_SIZE + 1, QUAD_SIZE + 1, QUAD_SIZE, QUAD_SIZE); g.setColor(Color.BLACK); for (int i = 0; i < QUAD_SIZE; i += 4) { int pos = QUAD_SIZE + i; g.drawLine(pos, QUAD_SIZE + 1, pos, FULL_SIZE); g.drawLine(QUAD_SIZE + 1, pos, FULL_SIZE, pos); } originalImagePainted = true; }
From source file:Main.java
private void paintArrow(Graphics g, int x, int y, Color highlight) { int mid, i, j; Color oldColor = g.getColor(); boolean isEnabled = isEnabled(); j = 0;//w ww.ja v a 2 s .c o m arrowSize = Math.max(arrowSize, 2); mid = (arrowSize / 2) - 1; g.translate(x, y); switch (direction) { case NORTH: for (i = 0; i < arrowSize; i++) { g.drawLine(mid - i, i, mid + i, i); } if (!isEnabled) { g.setColor(highlight); g.drawLine(mid - i + 2, i, mid + i, i); } break; case SOUTH: if (!isEnabled) { g.translate(1, 1); g.setColor(highlight); for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } g.translate(-1, -1); g.setColor(oldColor); } j = 0; for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } break; case WEST: for (i = 0; i < arrowSize; i++) { g.drawLine(i, mid - i, i, mid + i); } if (!isEnabled) { g.setColor(highlight); g.drawLine(i, mid - i + 2, i, mid + i); } break; case EAST: if (!isEnabled) { g.translate(1, 1); g.setColor(highlight); for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(j, mid - i, j, mid + i); j++; } g.translate(-1, -1); g.setColor(oldColor); } j = 0; for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(j, mid - i, j, mid + i); j++; } break; } g.translate(-x, -y); g.setColor(oldColor); }