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:TapTapTap.java
@Override public void paint(Graphics g, JComponent c) { int w = c.getWidth(); int h = c.getHeight(); // Paint the view. super.paint(g, c); if (!mIsRunning) { return;/*from ww w. j a v a 2 s . co m*/ } Graphics2D g2 = (Graphics2D) g.create(); float fade = (float) mFadeCount / (float) mFadeLimit; // Gray it out. Composite urComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade)); g2.fillRect(0, 0, w, h); g2.setComposite(urComposite); // Paint the wait indicator. int s = Math.min(w, h) / 5; int cx = w / 2; int cy = h / 2; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g2.setPaint(Color.white); g2.rotate(Math.PI * mAngle / 180, cx, cy); for (int i = 0; i < 12; i++) { float scale = (11.0f - (float) i) / 11.0f; g2.drawLine(cx + s, cy, cx + s * 2, cy); g2.rotate(-Math.PI / 6, cx, cy); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade)); } g2.dispose(); }
From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java
private void plotSubset(final Graphics2D g, final int start, final int end, final String title, final double startX, final double width, final double stepY, final double mean) { final FontMetrics fm = g.getFontMetrics(); final Color color = g.getColor(); g.setColor(Color.black);//from w ww . j a v a2 s.c o m g.drawString(title, (int) (startX + width / 2 - fm.stringWidth(title) / 2), 975); final String tmp = String.format("Mean: %.3fus", mean); g.drawString(tmp, (int) (startX + width / 2 - fm.stringWidth(tmp) / 2), 990); g.setColor(color); final double stepX = width / (end - start); for (int i = start; i < end; i++) { final int posX = (int) (startX + stepX * (i - start)); final int posY = 960 - ((int) (stepY * (timestamps[i] / 1000.0)) + 1); g.drawLine(posX, posY, posX, 960); } }
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java
/** * Draw a GraphNode as a rectangle with a name * * @param g The Java2D Graphics//from w ww . ja v a2s .co m * @param col The color to draw */ public void drawNode(final Graphics2D g, final Color col) { final int x = displayPosition.x; final int y = displayPosition.y; g.setFont(g.getFont().deriveFont(Font.BOLD, 11)); final FontMetrics metrics = g.getFontMetrics(); final String name = node.getId(); final Rectangle2D rect = metrics.getStringBounds(name, g); final int stringWidth = (int) rect.getWidth(); setSize(Math.max(stringWidth, 50) + 10, 25); int step = 4; int alpha = 96; for (int i = 0; i < step; ++i) { g.setColor(new Color(0, 0, 0, alpha - (32 * i))); g.drawLine(x + i + 1, y + nodeHeight + i, x + nodeWidth + i - 1, y + nodeHeight + i); g.drawLine(x + nodeWidth + i, y + i, x + nodeWidth + i, y + nodeHeight + i); } Shape clipShape = new Rectangle(x, y, nodeWidth, nodeHeight); g.setComposite(AlphaComposite.SrcAtop); g.setPaint(new GradientPaint(x, y, col, x + nodeWidth, y + nodeHeight, col.darker())); g.fill(clipShape); g.setColor(Color.blue); g.draw3DRect(x, y, nodeWidth - 1, nodeHeight - 1, true); g.setColor(Color.BLACK); g.drawString(name, x + (nodeWidth - stringWidth) / 2, y + 15); }
From source file:org.squidy.designer.zoom.impl.DataTypeShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); paintContext.pushTransform(translation); PBounds bounds = getBoundsReference(); // Rectangle rectBounds = roundedRectangleShape.getBounds(); int x = (int) bounds.x - 3; int y = (int) bounds.y - 3; int width = (int) bounds.width + 6; int height = (int) bounds.height; g.setColor(Color.WHITE);//from w w w .ja v a 2 s.co m g.fillRoundRect(x - 40, y, width + 80, height, 825, 825); g.setStroke(STROKE_SHAPE); g.setColor(Color.BLACK); g.drawRoundRect(x - 40, y, width + 80, height, 825, 825); paintContext.popTransform(translation); // 1st vertical g.drawLine(1000, 100, 1000, 220); // 1st horizontal g.drawLine(230, 220, 1780, 220); // 2nd (left) vertical g.drawLine(230, 220, 230, 700); // 2nd (left-middle) vertical g.drawLine(740, 220, 740, 960); // 2d (right-middle) vertical g.drawLine(1260, 220, 1260, 700); // 2nd (right) vertical g.drawLine(1780, 220, 1780, 700); }
From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java
protected void drawPoints() { synchronized (previousPoints) { synchronized (resizableBufferedImage) { // clear points for pen if it's been long since last changed long currentTime = new Date().getTime(); for (int id : pens.keySet()) { if (previousTimes.containsKey(id)) { long time = previousTimes.get(id); if ((currentTime - time) > POINT_CLEAR_DURATION) { previousPoints.remove(id); previousTimes.remove(id); }/*from w ww . j a v a2 s . c o m*/ } } DisplayMode displayMode = getWindowManager().getDisplayManager().getCurrentDisplayMode(); BufferedImage bufferedImage = resizableBufferedImage.getBufferedImage(); Graphics2D graphics = bufferedImage.createGraphics(); for (int id : pens.keySet()) { Pen pen = pens.get(id); LinkedList<Point> points = previousPoints.get(id); if ((pen != null) && (points != null) && (points.size() > 1)) { log.debug("id: " + id + ", points: " + points.size()); Point previousPoint = points.removeFirst(); Iterator<Point> iterator = points.iterator(); while (iterator.hasNext()) { Point point = iterator.next(); if (iterator.hasNext()) { iterator.remove(); } graphics.setStroke(pen.getStroke()); graphics.setPaint(pen.getPaint()); graphics.drawLine((int) Math.floor(previousPoint.getX()), (displayMode.getHeight() - (int) Math.floor(previousPoint.getY())), (int) Math.floor(point.getX()), (displayMode.getHeight() - (int) Math.floor(point.getY()))); previousPoint = point; } setDirty(true); } } graphics.dispose(); } } }
From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java
private void generateScatterPlot() throws IOException { final BufferedImage image = new BufferedImage(1800, 1000, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = image.createGraphics(); final FontMetrics fm = g2.getFontMetrics(); final String filename = "throughputency.png"; final File imageFile = new File(filename); final int height = 940; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (final long timestamp : timestamps) { final double ts = timestamp / 1000.0; if (ts < min) { min = ts;// w ww . ja v a 2 s . co m } if (ts > max) { max = ts; } } final double stepY = height / max; g2.setColor(Color.white); g2.fillRect(0, 0, 1800, 1000); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString("Latency ScatterPlot (microseconds)", 900 - fm.stringWidth("Latency ScatterPlot (microseconds)") / 2, 20); g2.drawString("" + max, 10, 20); g2.drawLine(100, 20, 100, 960); g2.drawLine(100, 960, 1790, 960); int start = 0; int end = 100; final double width = 1690.0 / 7.0; g2.setColor(Color.red); plotSubset(g2, start, end, "10 msgs/sec", 100, width, stepY, means[0]); start = 100; end = 1100; g2.setColor(Color.green); plotSubset(g2, start, end, "100 msgs/sec", 100 + width, width, stepY, means[1]); start = 1100; end = 11100; g2.setColor(Color.blue); plotSubset(g2, start, end, "1K msgs/sec", 100 + width * 2, width, stepY, means[2]); start = 11100; end = 111100; g2.setColor(Color.cyan); plotSubset(g2, start, end, "10K msgs/sec", 100 + width * 3, width, stepY, means[3]); start = 111100; end = 1111100; g2.setColor(Color.magenta); plotSubset(g2, start, end, "100K msgs/sec", 100 + width * 4, width, stepY, means[4]); start = 1111100; end = 11111100; g2.setColor(Color.yellow); plotSubset(g2, start, end, "1M msgs/sec", 100 + width * 5, width, stepY, means[5]); start = 11111100; end = 41111100; g2.setColor(Color.orange); plotSubset(g2, start, end, "3M msgs/sec", 100 + width * 6, width, stepY, means[6]); ImageIO.write(image, "png", imageFile); }
From source file:uk.co.modularaudio.service.audioanalysis.impl.analysers.StaticThumbnailAnalyser.java
@Override public void completeAnalysis(final AnalysisContext context, final AnalysedData analysedData, final HashedRef hashedRef) { final float rmsDb = AudioMath.levelToDbF(maxRmsValue); final float adjustedDb = (THUMBNAIL_DB - rmsDb); final float adjustmentAbs = AudioMath.dbToLevelF(adjustedDb); final Graphics2D g2d = (Graphics2D) og2d.create(BORDER_WIDTH, BORDER_WIDTH, usableWidth, usableHeight); // g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setColor(Color.BLACK);/*from www . ja va 2s. c om*/ g2d.fillRect(0, 0, usableWidth, usableHeight); g2d.setColor(minMaxColor); int curDataCount = 0; final int oneSideHeight = (usableHeight - 1) / 2; final int zeroYValue = oneSideHeight; for (int i = 0; i < usableWidth; i++) { float minSample = thumbnailValues[curDataCount++] * adjustmentAbs; float maxSample = thumbnailValues[curDataCount++] * adjustmentAbs; curDataCount++; minSample = (minSample < -1.0f ? -1.0f : minSample); maxSample = (maxSample > 1.0f ? 1.0f : maxSample); // assume goes from +1.0 to -1.0 final int curX = i; final int minY = zeroYValue + (int) (minSample * oneSideHeight); final int maxY = zeroYValue + (int) (maxSample * oneSideHeight); g2d.drawLine(curX, minY, curX, maxY); } g2d.setColor(rmsColor); curDataCount = 0; for (int i = 0; i < usableWidth; i++) { curDataCount += 2; float rms = thumbnailValues[curDataCount++] * adjustmentAbs; rms = (rms > 1.0f ? 1.0f : rms); // lSample goes from +1.0 to -1.0 // We need it to go from 0 to height final int curX = i; final int minY = zeroYValue + (int) (rms * oneSideHeight); final int maxY = zeroYValue + (int) (-rms * oneSideHeight); g2d.drawLine(curX, minY, curX, maxY); } try { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final ImageOutputStream ios = ImageIO.createImageOutputStream(os); ImageIO.write(bufferedImage, "png", ios); final InputStream contents = new ByteArrayInputStream(os.toByteArray()); // Now save this generated thumb nail onto disk then pass the path to this in the analysed data hashedStorageService.storeContentsInWarehouse(hashedWarehouse, hashedRef, contents); analysedData .setPathToStaticThumbnail(hashedStorageService.getPathToHashedRef(hashedWarehouse, hashedRef)); } catch (final Exception e) { final String msg = "Exception caught serialising static thumb nail: " + e.toString(); log.error(msg, e); } }
From source file:ucar.unidata.idv.control.chart.TrackSegment.java
/** * Draws the wayPoint./* w w w . j a va 2 s .c o m*/ * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { super.setGraphicsState(g2); if (!getPlotWrapper().okToDraw(this)) { return; } WayPoint leftWayPoint = getLeft(); WayPoint rightWayPoint = getRight(); g2.setStroke(new BasicStroke()); int x1 = leftWayPoint.getXFromValue(dataArea, domainAxis); int x2 = rightWayPoint.getXFromValue(dataArea, domainAxis); int top = (int) (dataArea.getY()); int bottom = (int) (dataArea.getY() + dataArea.getHeight()); FontMetrics fm = g2.getFontMetrics(); int width = fm.stringWidth(getName()); int height = fm.getAscent() + fm.getDescent(); if (getSelected()) { g2.setColor(Color.red); } else { g2.setColor(Color.black); } // int y = bottom-3; y = top - 2; int textLeft = x1 + (x2 - x1) / 2 - width / 2; g2.drawString(getName(), textLeft, y); g2.setStroke(new BasicStroke(2.0f)); g2.drawLine(x1, top + 1, x2, top + 1); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.gray); g2.drawLine(x1, top, x1, bottom - WayPoint.ANNOTATION_WIDTH); g2.drawLine(x2, top, x2, bottom - WayPoint.ANNOTATION_WIDTH); }
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; super.paintComponent(g2d); g2d.setPaint(gridColor);// ww w . ja va 2 s.c om Rectangle clipBounds = g.getClipBounds(); int[] indices = stripRangeForRect(clipBounds); int startIndex = indices[0]; int endIndex = indices[1]; Point p1, p2; p1 = new Point(); p2 = new Point(getWidth(), getHeight()); for (int i = startIndex; i <= endIndex; i++) { int gridLine = getGridLine(i); orientation.updateCoord(p1, gridLine); orientation.updateCoord(p2, gridLine); g2d.drawLine(p1.x, p1.y, p2.x, p2.y); } p1.setLocation(0, 0); p2.setLocation(getWidth(), getHeight()); int groupGridLine = 0; for (CategoryView v : groupings) { groupGridLine += v.size; orientation.opposite().updateCoord(p1, groupGridLine); orientation.opposite().updateCoord(p2, groupGridLine); g2d.drawLine(p1.x, p1.y, p2.x, p2.y); groupGridLine += GRID_SIZE; } for (int level = 0, levelCount = groupings.length; level < levelCount; level++) { for (HeaderCell cell : groupings[level].cells) { if (cell.endIndex < startIndex || cell.startIndex >= endIndex) continue; Rectangle rect = getRect(level, cell.startIndex, cell.endIndex); if (clipBounds != null && !clipBounds.intersects(rect)) continue; paintHeaderCell(g2d, rect, cell.levelValue); } } if (cellResizingRange != null) { Rectangle rect = new Rectangle(getWidth(), getHeight()); orientation.updateRange(rect, cellResizingRange); rect.grow(orientation.select(GRID_SIZE, 0), orientation.select(0, GRID_SIZE)); g2d.setColor(new Color(0x9999ff, false)); g2d.draw(rect); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); g2d.fill(rect); } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
private void updateLegend() { int width = DEFAULT_LEGEND_WIDTH; int height = DEFAULT_LEGENT_HEIGHT; legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); Graphics2D g = (Graphics2D) legend.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(UI.colorBlack2);/*ww w. jav a 2s.c o m*/ g.fillRoundRect(0, 0, width, height - 12, 5, 5); g.setColor(barColorBelow); int boxNum = 10; g.setStroke(UI.stroke1_5); double value; for (int i = 0; i < boxNum; i++) { value = _minValue + (_maxValue - _minValue) / boxNum * i; if (value > disectBound) { g.setColor(barColorNormal); } int h = (height - 12) / boxNum * i; g.drawLine(i * width / boxNum, height - 12 - h, (i + 1) * width / boxNum, height - 12 - h); } g.setColor(Color.BLACK); g.setFont(UI.fontMono.deriveFont(10f)); DecimalFormat format = new DecimalFormat("#.##"); g.drawString(format.format(_minValue), 2, 23); g.setColor(Color.BLACK); String maxString = format.format(_maxValue); int swidth = g.getFontMetrics().stringWidth(maxString); g.drawString(maxString, width - 2 - swidth, 23); g.dispose(); }