Java Code Examples for java.awt.Graphics#drawPolyline()
The following examples show how to use
java.awt.Graphics#drawPolyline() .
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: Poly.java From Logisim with GNU General Public License v3.0 | 6 votes |
@Override public void paint(Graphics g, HandleGesture gesture) { List<Handle> hs = getHandles(gesture); int[] xs = new int[hs.size()]; int[] ys = new int[hs.size()]; int i = -1; for (Handle h : hs) { i++; xs[i] = h.getX(); ys[i] = h.getY(); } if (setForFill(g)) { g.fillPolygon(xs, ys, xs.length); } if (setForStroke(g)) { if (closed) g.drawPolygon(xs, ys, xs.length); else g.drawPolyline(xs, ys, xs.length); } }
Example 2
Source File: PlayerDiagram.java From settlers-remake with MIT License | 6 votes |
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.WHITE); g.fillRect(0, 0, WATCHED_DISTANCE * 2, IMAGE_HEIGHT); g.setColor(Color.DARK_GRAY); g.drawString("Stones", 50, 30); g.setColor(Color.GREEN); g.drawString("Trees", 50, 45); ((Graphics2D) g).scale(1, -1); g.translate(0, -IMAGE_HEIGHT); g.setColor(Color.DARK_GRAY); g.drawPolyline(polylinex, founds[1], WATCHED_DISTANCE); g.setColor(Color.GREEN); g.drawPolyline(polylinex, founds[0], WATCHED_DISTANCE); }
Example 3
Source File: ControlledBuffer.java From Logisim with GNU General Public License v3.0 | 6 votes |
@Override public void paintIcon(InstancePainter painter) { Graphics g = painter.getGraphics(); Icon icon = isInverter ? ICON_INVERTER : ICON_BUFFER; if (icon != null) { icon.paintIcon(painter.getDestination(), g, 2, 2); } else { int x = isInverter ? 0 : 2; g.setColor(Color.BLACK); int[] xp = new int[] { x + 15, x + 1, x + 1, x + 15 }; int[] yp = new int[] { 10, 3, 17, 10 }; g.drawPolyline(xp, yp, 4); if (isInverter) g.drawOval(x + 13, 8, 4, 4); g.setColor(Value.FALSE_COLOR); g.drawLine(x + 8, 14, x + 8, 18); } }
Example 4
Source File: PainterShaped.java From Logisim with GNU General Public License v3.0 | 5 votes |
static void paintAnd(InstancePainter painter, int width, int height) { Graphics g = painter.getGraphics(); GraphicsUtil.switchToWidth(g, 2); int[] xp = new int[] { -width / 2, -width + 1, -width + 1, -width / 2 }; int[] yp = new int[] { -width / 2, -width / 2, width / 2, width / 2 }; GraphicsUtil.drawCenteredArc(g, -width / 2, 0, width / 2, -90, 180); g.drawPolyline(xp, yp, 4); if (height > width) { g.drawLine(-width + 1, -height / 2, -width + 1, height / 2); } }
Example 5
Source File: GraphicsUtil.java From Logisim with GNU General Public License v3.0 | 5 votes |
static public void drawArrow2(Graphics g, int x0, int y0, int x1, int y1, int x2, int y2) { int[] xs = { x0, x1, x2 }; int[] ys = { y0, y1, y2 }; GraphicsUtil.switchToWidth(g, 7); g.drawPolyline(xs, ys, 3); Color oldColor = g.getColor(); g.setColor(Color.WHITE); GraphicsUtil.switchToWidth(g, 3); g.drawPolyline(xs, ys, 3); g.setColor(oldColor); GraphicsUtil.switchToWidth(g, 1); }
Example 6
Source File: Drawgates.java From Logisim with GNU General Public License v3.0 | 5 votes |
static void paintOutputgate(Graphics g, int xpin, int y, int xoutput, int youtput, boolean up) { int[] yPoints, xPoints; xPoints = new int[] { xoutput, xpin, xpin }; if (!up) yPoints = new int[] { youtput, youtput, y + AbstractTtlGate.height - AbstractTtlGate.pinheight }; else yPoints = new int[] { youtput, youtput, y + AbstractTtlGate.pinheight }; g.drawPolyline(xPoints, yPoints, 3); }
Example 7
Source File: GraphMultiCurve.java From moa with GNU General Public License v3.0 | 5 votes |
/** * Draws a single curve on the canvas. * @param g the Graphics context in which to paint * @param i index of the currently selected measure */ private void paintFullCurve(Graphics g, int i){ if (this.measures[i].getNumberOfValues(this.measureSelected) == 0) { // no values of this measure available return; } g.setColor(this.colors[i]); int height = getHeight(); // // compute the relation of minimum PF and current PF // double processFrequencyFactor = pf / this.min_processFrequency; int n = this.measures[i].getNumberOfValues(this.measureSelected); int[] x = new int[n]; int[] y = new int[n]; for (int j = 0; j < n; j++) { x[j] = (int) (j * x_resolution); y[j] = (int)(height-(this.measures[i].getValue(this.measureSelected, j)/this.upper_y_value)*height); if (this.isStandardDeviationPainted) { int len = (int) ((this.measureStds[i].getValue(this.measureSelected, j)/this.upper_y_value)*height); paintStandardDeviation(g, len, x[j], y[j]); } } g.drawPolyline(x, y, n); }
Example 8
Source File: Drawgates.java From Logisim with GNU General Public License v3.0 | 5 votes |
static void paintBuffer(Graphics g, int x, int y, int width, int height) { int[] xp = new int[4]; int[] yp = new int[4]; xp[0] = x - 4; yp[0] = y; xp[1] = x - width; yp[1] = y - height / 2; xp[2] = x - width; yp[2] = y + height / 2; xp[3] = x - 4; yp[3] = y; g.drawPolyline(xp, yp, 4); }
Example 9
Source File: Drawgates.java From Logisim with GNU General Public License v3.0 | 5 votes |
public static void paintAnd(Graphics g, int x, int y, int width, int height, boolean negated) { if (negated) paintNegatedOutput(g, x, y); int[] xp = new int[] { x - width / 2, x - width, x - width, x - width / 2 }; int[] yp = new int[] { y - width / 2, y - width / 2, y + width / 2, y + width / 2 }; GraphicsUtil.drawCenteredArc(g, x - width / 2, y, width / 2, -90, 180); g.drawPolyline(xp, yp, 4); if (height > width) { g.drawLine(x - width, y - height / 2, x - width, y + height / 2); } }
Example 10
Source File: EquilateralTriangleMarker.java From pdfxtk with Apache License 2.0 | 5 votes |
public void paint(Graphics g, int width) { if(background != null) g.setColor(background); if(opaque && !open) g.fillPolygon(p); if(foreground != null) g.setColor(foreground); if(open) g.drawPolyline(p.xpoints, p.ypoints, p.npoints); else g.drawPolygon(p); }
Example 11
Source File: Buffer.java From Logisim with GNU General Public License v3.0 | 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 12
Source File: NandGate.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public void paintIconShaped(InstancePainter painter) { Graphics g = painter.getGraphics(); int[] xp = new int[] { 8, 0, 0, 8 }; int[] yp = new int[] { 2, 2, 18, 18 }; g.drawPolyline(xp, yp, 4); GraphicsUtil.drawCenteredArc(g, 8, 10, 8, -90, 180); g.drawOval(16, 8, 4, 4); }
Example 13
Source File: SxArrow.java From SikuliX1 with MIT License | 5 votes |
private void drawPolylineArrow(Graphics g, int[] xPoints, int[] yPoints, int headLength, int headwidth) { double theta1; Object tempX1 = ((Array.get(xPoints, ((xPoints.length) - 2)))); Object tempX2 = ((Array.get(xPoints, ((xPoints.length) - 1)))); Integer fooX1 = (Integer) tempX1; int x1 = fooX1.intValue(); Integer fooX2 = (Integer) tempX2; int x2 = fooX2.intValue(); Object tempY1 = ((Array.get(yPoints, ((yPoints.length) - 2)))); Object tempY2 = ((Array.get(yPoints, ((yPoints.length) - 1)))); Integer fooY1 = (Integer) tempY1; int y1 = fooY1.intValue(); Integer fooY2 = (Integer) tempY2; int y2 = fooY2.intValue(); int deltaX = (x2 - x1); int deltaY = (y2 - y1); double theta = Math.atan((double) (deltaY) / (double) (deltaX)); if (deltaX < 0.0) { theta1 = theta + Math.PI; //If theta is negative make it positive } else { theta1 = theta; //else leave it alone } int lengthdeltaX = -(int) (Math.cos(theta1) * headLength); int lengthdeltaY = -(int) (Math.sin(theta1) * headLength); int widthdeltaX = (int) (Math.sin(theta1) * headwidth); int widthdeltaY = (int) (Math.cos(theta1) * headwidth); g.drawPolyline(xPoints, yPoints, xPoints.length); g.drawLine(x2, y2, x2 + lengthdeltaX + widthdeltaX, y2 + lengthdeltaY - widthdeltaY); g.drawLine(x2, y2, x2 + lengthdeltaX - widthdeltaX, y2 + lengthdeltaY + widthdeltaY); }
Example 14
Source File: AndGate.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override protected void paintIconShaped(InstancePainter painter) { Graphics g = painter.getGraphics(); int[] xp = new int[] { 10, 2, 2, 10 }; int[] yp = new int[] { 2, 2, 18, 18 }; g.drawPolyline(xp, yp, 4); GraphicsUtil.drawCenteredArc(g, 10, 10, 8, -90, 180); }
Example 15
Source File: ControlledBuffer.java From Logisim with GNU General Public License v3.0 | 5 votes |
private void paintShape(InstancePainter painter) { Direction facing = painter.getAttributeValue(StdAttr.FACING); Location loc = painter.getLocation(); int x = loc.getX(); int y = loc.getY(); double rotate = 0.0; Graphics g = painter.getGraphics(); g.translate(x, y); if (facing != Direction.EAST && g instanceof Graphics2D) { rotate = -facing.toRadians(); ((Graphics2D) g).rotate(rotate); } if (isInverter) { PainterShaped.paintNot(painter); } else { GraphicsUtil.switchToWidth(g, 2); int d = isInverter ? 10 : 0; int[] xp = new int[] { -d, -19 - d, -19 - d, -d }; int[] yp = new int[] { 0, -7, 7, 0 }; g.drawPolyline(xp, yp, 4); // if (isInverter) g.drawOval(-9, -4, 9, 9); } if (rotate != 0.0) { ((Graphics2D) g).rotate(-rotate); } g.translate(-x, -y); }
Example 16
Source File: Clock.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public void paintInstance(InstancePainter painter) { Graphics g = painter.getGraphics(); Bounds bds = painter.getInstance().getBounds(); int x = bds.getX(); int y = bds.getY(); painter.drawRoundBounds(Color.WHITE); GraphicsUtil.switchToWidth(g, 2); g.setColor(painter.getAttributeValue(StdAttr.ATTR_LABEL_COLOR)); painter.drawLabel(); boolean drawUp; if (painter.getShowState()) { ClockState state = getState(painter); g.setColor(state.sending.getColor()); drawUp = state.sending == Value.TRUE; } else { g.setColor(Color.BLACK); drawUp = true; } x += 10; y += 10; int[] xs = { x - 6, x - 6, x, x, x + 6, x + 6 }; int[] ys; if (drawUp) { ys = new int[] { y, y - 4, y - 4, y + 4, y + 4, y }; } else { ys = new int[] { y, y + 4, y + 4, y - 4, y - 4, y }; } g.drawPolyline(xs, ys, xs.length); painter.drawPorts(); }
Example 17
Source File: GraphicsUtil.java From Logisim with GNU General Public License v3.0 | 5 votes |
static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) { double offs = headAngle * Math.PI / 180.0; double angle = Math.atan2(y0 - y1, x0 - x1); int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1, x1 + (int) (headLength * Math.cos(angle - offs)) }; int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1, y1 + (int) (headLength * Math.sin(angle - offs)) }; g.drawLine(x0, y0, x1, y1); g.drawPolyline(xs, ys, 3); }
Example 18
Source File: ComponentPeer.java From netbeans with Apache License 2.0 | 5 votes |
public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { g.setColor(Color.RED); try { Rectangle start = pane.modelToView(p0); Rectangle end = pane.modelToView(p1); if (start.x < 0) { LOG.log(Level.INFO, "#182545: negative view position: {0} for: {1}", new Object[] {start, p0}); return; } int waveLength = end.x + end.width - start.x; if (waveLength > 0) { int[] wf = {0, 0, -1, -1}; int[] xArray = new int[waveLength + 1]; int[] yArray = new int[waveLength + 1]; int yBase = (int) (start.y + start.height - 2); for (int i = 0; i <= waveLength; i++) { xArray[i] = start.x + i; yArray[i] = yBase + wf[xArray[i] % 4]; } g.drawPolyline(xArray, yArray, waveLength); } } catch (BadLocationException e) { Exceptions.printStackTrace(e); } }
Example 19
Source File: PullResistor.java From Logisim with GNU General Public License v3.0 | 4 votes |
private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) { boolean color = painter.shouldDrawColor(); Direction facing = painter.getAttributeValue(StdAttr.FACING); Graphics g = painter.getGraphics(); Color baseColor = g.getColor(); GraphicsUtil.switchToWidth(g, 3); if (color && inColor != null) g.setColor(inColor); if (facing == Direction.EAST) { GraphicsUtil.drawText(g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER_OVERALL); } else if (facing == Direction.WEST) { GraphicsUtil.drawText(g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER_OVERALL); } else if (facing == Direction.NORTH) { GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP); } else { GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE); } double rotate = 0.0; if (g instanceof Graphics2D) { rotate = Direction.SOUTH.toRadians() - facing.toRadians(); if (rotate != 0.0) ((Graphics2D) g).rotate(rotate); } g.drawLine(0, -30, 0, -26); g.drawLine(-6, -30, 6, -30); if (color && outColor != null) g.setColor(outColor); g.drawLine(0, -4, 0, 0); g.setColor(baseColor); GraphicsUtil.switchToWidth(g, 2); if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) { int[] xp = { 0, -5, 5, -5, 5, -5, 0 }; int[] yp = { -25, -23, -19, -15, -11, -7, -5 }; g.drawPolyline(xp, yp, xp.length); } else { g.drawRect(-5, -25, 10, 20); } if (rotate != 0.0) { ((Graphics2D) g).rotate(-rotate); } }
Example 20
Source File: GraphCurve.java From moa with GNU General Public License v3.0 | 4 votes |
private void paintFullCurve(Graphics g, MeasureCollection m, int mSelect, Color color){ if (m.getNumberOfValues(mSelect)==0) return; boolean corrupted = false; int height = getHeight(); int width = getWidth(); int n = m.getNumberOfValues(mSelect); if(x_resolution > 1) n = (int)(n / (int)x_resolution); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; i ++) { if(x_resolution > 1){ //we need to compress the values double sum_y = 0; int counter = 0; for (int j = 0; j < x_resolution; j++) { if((i)*x_resolution+j<m.getNumberOfValues(mSelect)){ sum_y+= m.getValue(mSelect,i); counter++; } sum_y/=counter; } x[i] = i; y[i] = (int)(height-(sum_y/max_value)*height); } else{ //spreading one value x[i] = (i)*(int)(1/x_resolution)+(int)(1/x_resolution/2); double value = m.getValue(mSelect,i); if(Double.isNaN(value)){ corrupted = true; break; } y[i] = (int)(height-(value/max_value)*height); } } if(!corrupted){ g.setColor(color); g.drawPolyline(x, y, n); } }