List of usage examples for java.awt Graphics2D 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:edu.oregonstate.eecs.mcplan.domains.racetrack.RacetrackVisualization.java
private void drawJtsLineString(final Geometry geom, final Graphics2D g) { final Coordinate[] coords = geom.getCoordinates(); for (int j = 1; j < coords.length; ++j) { g.drawLine((int) coords[j - 1].x, (int) coords[j - 1].y, (int) coords[j].x, (int) coords[j].y); }//from ww w .j ava 2s . c o m }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void paintLine(Graphics2D g2d, int x1, int y1, int x2, int y2, Color col) throws Exception { g2d.setPaint(col);/* w w w.j a v a 2s. c o m*/ g2d.drawLine(x1, y1, x2, y2); }
From source file:TextBouncer.java
protected void drawAxes(Graphics2D g2) { if (mAxes == false) return;/* w w w. j av a 2s .c om*/ g2.setPaint(getForeground()); g2.setStroke(new BasicStroke()); Dimension d = getSize(); int side = 20; int arrow = 4; int w = d.width / 2, h = d.height / 2; g2.drawLine(w - side, h, w + side, h); g2.drawLine(w + side - arrow, h - arrow, w + side, h); g2.drawLine(w, h - side, w, h + side); g2.drawLine(w + arrow, h + side - arrow, w, h + side); }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
/** Creates new form TimeFrameVisualizer */ public TimeFrameVisualizer() { initComponents();/*from w w w . j av a 2 s . c om*/ try { STROKED = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = STROKED.createGraphics(); g2d.setColor(Constants.DS_BACK_LIGHT); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Constants.DS_BACK); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); DAILY_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = DAILY_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLUE); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); EXACT_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = EXACT_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.dispose(); ONE_DAY_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = ONE_DAY_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLUE); g2d.drawLine(1, 0, 1, 2); g2d.dispose(); ARRIVE_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = ARRIVE_FRAME_FILL.createGraphics(); g2d.setColor(Color.RED); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLACK); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); } catch (Exception e) { } popupInfo = new HashMap<String, Object>(); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { repaint(); } }); addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { fireClickEvent(e); } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); }
From source file:MWC.GUI.JFreeChart.StepperXYPlot.java
/** * draw the new stepper line into the plot * // w w w . j av a2 s . co m * @param g2 * @param linePosition * @param dataArea */ protected void plotStepperLine(final Graphics2D g2, final double linePosition, final Rectangle2D dataArea) { // prepare to draw final Stroke oldStroke = g2.getStroke(); g2.setXORMode(Color.darkGray); // thicken up the line g2.setStroke(new BasicStroke(3)); if (this.getOrientation() == PlotOrientation.VERTICAL) { // draw the line g2.drawLine((int) linePosition - 1, (int) dataArea.getY() + 1, (int) linePosition - 1, (int) dataArea.getY() + (int) dataArea.getHeight() - 1); } else { // draw the line g2.drawLine((int) dataArea.getY() + 1, (int) linePosition - 1, (int) dataArea.getY() + (int) dataArea.getHeight() - 1, (int) linePosition - 1); } // and restore everything g2.setStroke(oldStroke); g2.setPaintMode(); }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawThickLine(Graphics2D g2d, int x1, int y1, int x2, int y2, int width, Color c) throws Exception { g2d.setPaint(c);/*w w w. jav a 2s . c o m*/ g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); g2d.drawLine(x1, y1, x2, y2); }
From source file:uk.co.modularaudio.mads.base.soundfile_player.ui.rollpainter.SoundfileDisplaySampleFactory.java
private void fillInMinMaxLine(final Graphics2D g, final int pixelX, final float minValue, final float maxValue) { final float multiplier = displayHeight / 2.0f; final int yMinVal = (int) (-(minValue * displayMultiplier) * multiplier + multiplier); final int yMaxVal = (int) (-(maxValue * displayMultiplier) * multiplier + multiplier); g.drawLine(pixelX, yMinVal, pixelX, yMaxVal); }
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java
/** * Draws an arrow head at the correct angle * * @param g The Java2D Graphics/* w w w. ja v a 2 s . c o m*/ * @param tailX position X on target node * @param tailY position Y on target node * @param headX position X on source node * @param headY position Y on source node */ private static void drawArrow(final Graphics2D g, final int tailX, final int tailY, final int headX, final int headY) { final double t1 = Math.abs(headY - tailY); final double t2 = Math.abs(headX - tailX); double theta = Math.atan(t1 / t2); if (headX >= tailX) { if (headY > tailY) theta = Math.PI + theta; else theta = -(Math.PI + theta); } else if (headX < tailX && headY > tailY) theta = 2 * Math.PI - theta; final double cosTheta = FastMath.cos(theta); final double sinTheta = FastMath.sin(theta); final Point p2 = new Point(-8, -3); final Point p3 = new Point(-8, +3); int x = (int) Math.round((cosTheta * p2.x) - (sinTheta * p2.y)); p2.y = (int) Math.round((sinTheta * p2.x) + (cosTheta * p2.y)); p2.x = x; x = (int) Math.round((cosTheta * p3.x) - (sinTheta * p3.y)); p3.y = (int) Math.round((sinTheta * p3.x) + (cosTheta * p3.y)); p3.x = x; p2.translate(tailX, tailY); p3.translate(tailX, tailY); Stroke oldStroke = g.getStroke(); g.setStroke(new BasicStroke(2)); g.drawLine(tailX, tailY, headX, headY); g.drawLine(tailX, tailY, p2.x, p2.y); g.drawLine(p3.x, p3.y, tailX, tailY); g.setStroke(oldStroke); }
From source file:org.uva.itast.blended.omr.scanners.SolidSquareMarkScanner.java
/** * @param pageImage/* w w w . ja va 2 s. c o m*/ */ public void putEmphasisMarkOnImage(PageImage pageImage, Color color) { Graphics2D g = pageImage.getReportingGraphics(); // int centerColor=imagen.getRGB(maxsimX, maxsimY); // g.setXORMode(new Color(centerColor)); // g.setColor(Color.RED); // g.fillOval(maxsimX - markWidth/2, maxsimY - markHeight/2, markWidth, // markHeight); // g.setPaintMode(); Dimension2D markDimsPx = pageImage.sizeInPixels(new Size(markWidth, markHeight)); int markWidth = (int) markDimsPx.getWidth(); int markHeight = (int) markDimsPx.getHeight(); g.setColor(color); AffineTransform t = g.getTransform(); g.drawLine(maxsimX, maxsimY - markHeight / 2 - 1, maxsimX, maxsimY - markHeight / 2 - (int) (20 / t.getScaleY())); Polygon arrowHead = new Polygon(); arrowHead.addPoint(maxsimX, (int) (maxsimY - markHeight / 2 - 1 / t.getScaleY())); arrowHead.addPoint((int) (maxsimX - 6 / t.getScaleX()), (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY())); arrowHead.addPoint((int) (maxsimX + 6 / t.getScaleX()), (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY())); g.fillPolygon(arrowHead); g.setStroke(new BasicStroke(2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { (float) (3 / t.getScaleX()), (float) (3 / t.getScaleY()) }, 0)); g.drawRect(maxsimX - markWidth / 2 - 1, maxsimY - markHeight / 2 - 1, markWidth + 1, markHeight + 1); }
From source file:tests.TestDrawing.java
@Test public void testDrawing() { BufferedImage img = null;//from w w w. j av a 2 s. com BufferedImage imgs[] = new BufferedImage[2]; try { imgs[0] = ImageIO.read(new File("../captures/4.jpg")); // eventually C:\\ImageTest\\pic2.jpg imgs[1] = ImageIO.read(new File("../captures/5.jpg")); // eventually C:\\ImageTest\\pic2.jpg img = ImageIO.read(new File("../captures/5.jpg")); // eventually C:\\ImageTest\\pic2.jpg for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { int rgbDiff = RgbCalculator.absoluteDifference(imgs[0].getRGB(x, y), imgs[1].getRGB(x, y)); img.setRGB(x, y, rgbDiff); } } Graphics2D g2d = img.createGraphics(); g2d.setBackground(Color.BLUE); g2d.setColor(Color.RED); Vector3D[] corners = new Vector3D[] { new Vector3D(new double[] { 172, 78, 0 }), new Vector3D(new double[] { 455, 71, 0 }), new Vector3D(new double[] { 507, 350, 0 }), new Vector3D(new double[] { 143, 362, 0 }) }; //draw lines from corner to corner for (int c = 0; c < corners.length; c++) { Vector3D v1 = corners[c]; Vector3D v2 = corners[(c + 1) % corners.length]; g2d.drawLine((int) v1.getX(), (int) v1.getY(), (int) v2.getX(), (int) v2.getY()); } for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { Vector3D currentPos = new Vector3D(new double[] { x, y, 0 }); double[] normalizedCoordinates = new double[2]; { //normalize x coordinate Line floor = new Line(corners[0], corners[3], 0.5); Line roof = new Line(corners[1], corners[2], 0.5); double floorDistance = floor.distance(currentPos) * 1 / corners[0].distance(corners[3]); double roofDistance = roof.distance(currentPos) * 1 / corners[1].distance(corners[2]); normalizedCoordinates[0] = interpolate(0, 1, floorDistance / (floorDistance + roofDistance)); } { //normalize y coordinate Line floor = new Line(corners[0], corners[1], 0.5); Line roof = new Line(corners[2], corners[3], 0.5); double floorDistance = floor.distance(currentPos) * 1 / corners[0].distance(corners[1]); double roofDistance = roof.distance(currentPos) * 1 / corners[2].distance(corners[3]); normalizedCoordinates[1] = interpolate(0, 1, floorDistance / (floorDistance + roofDistance)); } boolean isEdge = false; for (int d = 0; d < 2; d++) { double val = normalizedCoordinates[d]; if (Math.abs((double) ((int) (val * 8)) - (val * 8)) < 0.05) { isEdge = true; } } if (isEdge) { //color corners red: img.setRGB(x, y, Color.RED.getRGB()); } } } JFrame dialog = new JFrame(); ImagePanel imagePanel = new ImagePanel(img); dialog.add(imagePanel); imagePanel.setSize(100, 100); dialog.pack(); dialog.setSize(300, 300); dialog.setVisible(true); } catch (IOException e) { throw new RuntimeException(e); } assertTrue("hello", true); }