List of usage examples for java.awt Polygon addPoint
public void addPoint(int x, int y)
From source file:Main.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color);//from www .j a va 2 s . c o m Polygon p = new Polygon(); if (state == State.NORMAL) { p.addPoint(x + (getIconWidth() / 2), y); p.addPoint(x, y + getIconHeight() - 1); p.addPoint(x + getIconWidth() - 1, y + getIconHeight() - 1); } else if (state == State.PRESSED) { p.addPoint(x, y); p.addPoint(x + getIconWidth() - 1, y); p.addPoint(x + (getIconWidth() / 2), y + getIconHeight() - 1); } else { p.addPoint(x, y); p.addPoint(x, y + getIconHeight() - 1); p.addPoint(x + getIconWidth() - 1, y + (getIconHeight() / 2)); } g.fillPolygon(p); }
From source file:FillPolyPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); int radius = 40; int centerX = 50; int centerY = 100; int angle = 30; int dx = (int) (radius * Math.cos(angle * Math.PI / 180)); int dy = (int) (radius * Math.sin(angle * Math.PI / 180)); g.fillArc(centerX - radius, centerY - radius, 2 * radius, 2 * radius, angle, 360 - 2 * angle); Polygon p = new Polygon(); centerX = 150;//from w w w .j a v a 2 s .c o m for (int i = 0; i < 5; i++) p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)), (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5))); g.fillPolygon(p); p = new Polygon(); centerX = 250; for (int i = 0; i < 360; i++) { double t = i / 360.0; p.addPoint((int) (centerX + radius * t * Math.cos(8 * t * Math.PI)), (int) (centerY + radius * t * Math.sin(8 * t * Math.PI))); } g.fillPolygon(p); }
From source file:Main.java
protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawLine(10, 100, 380, 100);//from w w w .j av a 2s . co m g.drawLine(200, 30, 200, 190); g.drawLine(380, 100, 370, 90); g.drawLine(380, 100, 370, 110); g.drawLine(200, 30, 190, 40); g.drawLine(200, 30, 210, 40); g.drawString("X", 360, 80); g.drawString("Y", 220, 40); Polygon p = new Polygon(); Polygon p2 = new Polygon(); for (int x = -170; x <= 170; x++) { p.addPoint(x + 200, 100 - (int) (50 * f((x / 100.0) * 2 * Math.PI))); } for (int x = -170; x <= 170; x++) { p2.addPoint(x + 200, 100 - (int) (50 * gCos((x / 100.0) * 2 * Math.PI))); } g.setColor(Color.red); g.drawPolyline(p.xpoints, p.ypoints, p.npoints); g.drawString("-2\u03c0", 95, 115); g.drawString("-\u03c0", 147, 115); g.drawString("\u03c0", 253, 115); g.drawString("2\u03c0", 305, 115); g.drawString("0", 200, 115); g.setColor(Color.blue); g.drawPolyline(p2.xpoints, p2.ypoints, p2.npoints); }
From source file:ArrowPanel.java
/** * Returns an up arrow.//from w w w.j a va2 s .co m * * @return an up arrow. */ private Shape getUpArrow() { final Polygon result = new Polygon(); result.addPoint(7, 2); result.addPoint(2, 7); result.addPoint(12, 7); return result; }
From source file:ArrowPanel.java
/** * Returns a down arrow./* w ww . ja v a 2 s .c om*/ * * @return a down arrow. */ private Shape getDownArrow() { final Polygon result = new Polygon(); result.addPoint(7, 7); result.addPoint(2, 2); result.addPoint(12, 2); return result; }
From source file:hudson.util.StackedAreaRenderer2.java
@Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // plot non-null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;/*w ww.j av a 2s.co m*/ } double value = dataValue.doubleValue(); // leave the y values (y1, y0) untranslated as it is going to be be // stacked up later by previous series values, after this it will be // translated. double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double previousHeightx1 = getPreviousHeight(dataset, row, column); double y1 = value + previousHeightx1; RectangleEdge location = plot.getRangeAxisEdge(); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); // in column zero, the only job to do is draw any visible item labels // and this is done in the second pass... if (column == 0) { if (pass == 1) { // draw item labels, if visible if (isItemLabelVisible(row, column)) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0)); } } } else { Number previousValue = dataset.getValue(row, column - 1); if (previousValue != null) { double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double y0 = previousValue.doubleValue(); // Get the previous height, but this will be different for both // y0 and y1 as the previous series values could differ. double previousHeightx0 = getPreviousHeight(dataset, row, column - 1); // Now stack the current y values on top of the previous values. y0 += previousHeightx0; // Now translate the previous heights double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location); double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location); // Now translate the current y values. double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location); if (pass == 0) { // left half Polygon p = new Polygon(); p.addPoint((int) xx0, (int) yy0); p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2); p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2); p.addPoint((int) xx0, (int) previousHeightxx0); g2.setPaint(getItemPaint(row, column - 1)); g2.setStroke(getItemStroke(row, column - 1)); g2.fill(p); if (entities != null) addItemEntity(entities, dataset, row, column - 1, p); // right half p = new Polygon(); p.addPoint((int) xx1, (int) yy1); p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2); p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2); p.addPoint((int) xx1, (int) previousHeightxx1); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.fill(p); if (entities != null) addItemEntity(entities, dataset, row, column, p); } else { if (isItemLabelVisible(row, column)) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0)); } } } } }
From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java
/** * {@inheritDoc}/* w w w . ja v a 2 s . co m*/ */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); }
From source file:oct.analysis.application.OCTSelection.java
protected void drawSelectButton(Graphics g, int imageOffsetX, int imageOffsetY) { Polygon buttonOutline = getSelectionButtonShape(); buttonOutline.translate(imageOffsetX, imageOffsetY); g.setColor(Color.lightGray);/*from w w w . ja v a2 s. c o m*/ g.drawPolygon(buttonOutline); g.fillPolygon(buttonOutline); Polygon button = new Polygon(); button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY); button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY + 15); button.addPoint(imageOffsetX + xPositionOnOct, imageOffsetY + 20); button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY + 15); button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY); g.setColor(Color.DARK_GRAY); g.drawPolygon(button); }
From source file:oct.analysis.application.OCTSelection.java
public Polygon getSelectionButtonShape() { Polygon buttonOutline = new Polygon(); buttonOutline.addPoint(xPositionOnOct - 6, -1); buttonOutline.addPoint(xPositionOnOct - 6, 16); buttonOutline.addPoint(xPositionOnOct, 22); buttonOutline.addPoint(xPositionOnOct + 6, 16); buttonOutline.addPoint(xPositionOnOct + 6, -1); return buttonOutline; }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * {@inheritDoc}// ww w . j a va2 s.c om */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) { g2.setStroke(new BasicStroke(2.0f)); switch (message.getSeverity()) { case WARNING: g2.setColor(WARN_COLOR); case ALERT: g2.setColor(ALERT_COLOR); case SAFETY: g2.setColor(SAFETY_COLOR); default: g2.setColor(WARN_COLOR); } // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? WARN_COLOR : ALERT_COLOR); g2.draw(area); } }