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:com.bdb.weather.display.windplot.WindItemRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device./* ww w .j a va 2s . c o m*/ * @param rendererState the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState rendererState, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // // Let the base class handle drawing the line and the shapes (passes 0 and 1). This class will handle drawing the // wind direction lines. // if (pass < 2) super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); else { if (!(dataset instanceof TimeSeriesCollection) || !showWindDirectionLines) return; if (item == 0) state.resetLastDirection(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); TimeSeriesCollection collection = (TimeSeriesCollection) dataset; TimeSeries timeSeries = collection.getSeries(series); if (!(timeSeries instanceof WindSeries)) return; WindSeries windSeries = (WindSeries) timeSeries; WindSeriesDataItem windItem = windSeries.getWindDataItem(item); double speed = windItem.getWindSpeed().doubleValue(); double time = dataset.getXValue(series, item); double dir = windItem.getWindDirection().doubleValue(); if (speed > 0.0 && dir != state.getLastDirection()) { state.setLastDirection(dir); double radians = Math.toRadians(dir - 90.0); double dirXOffset = directionLineLength * Math.cos(radians); double dirYOffset = directionLineLength * Math.sin(radians); double transTime = domainAxis.valueToJava2D(time, dataArea, xAxisLocation); double transSpeed = rangeAxis.valueToJava2D(speed, dataArea, yAxisLocation); double dirX = transTime + dirXOffset; double dirY = transSpeed + dirYOffset; // update path to reflect latest point if (!Double.isNaN(transTime) && !Double.isNaN(transSpeed)) { int x1 = (int) transTime; int y1 = (int) transSpeed; int x2 = (int) dirX; int y2 = (int) dirY; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x1 = (int) transSpeed; y1 = (int) transTime; x2 = (int) dirY; y2 = (int) dirX; } g2.setPaint(windDirectionPaint); g2.setStroke(windDirectionStroke); g2.drawLine(x1, y1, x2, y2); } } } }
From source file:peakml.util.jfreechart.FastErrorBarPlot.java
@Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {/*from w ww .j a va2 s. c om*/ // add the plot area to the info (used amongst other by the axis for zooming) if (info != null) info.setPlotArea(area); // add the insets (if any) RectangleInsets insets = getInsets(); insets.trim(area); // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming) AxisSpace space = new AxisSpace(); space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) info.setDataArea(dataArea); // flood fill the whole area with the background color drawBackground(g2, dataArea); // draw the axis xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); // sanity check if (dataseries.size() == 0) return; // clip the draw area Shape originalclip = g2.getClip(); g2.clip(dataArea); // create the strokes BasicStroke stroke_solid = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f); BasicStroke stroke_dashed = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f, new float[] { 2, 4 }, 0); g2.setStroke(stroke_solid); // count the number of labels int categoryCount = 0; if (showall) { for (Data data : dataseries) categoryCount += data.yvalues.length; } else categoryCount = dataseries.size(); // draw all the values int pos = 0; boolean dashed = false; double prevx = -1, prevy = -1; for (Data data : dataseries) { if (data.yvalues.length == 0) { dashed = true; pos++; continue; } double mean[] = showall ? data.yvalues : new double[] { data.getMeanY() }; double min[] = showall ? data.yvalues : new double[] { data.getMinY() }; double max[] = showall ? data.yvalues : new double[] { data.getMaxY() }; for (int i = 0; i < mean.length; ++i) { double ypos, xpos = xaxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, pos++, categoryCount, dataArea, RectangleEdge.BOTTOM); // draw the mean value g2.setColor(Color.RED); ypos = yaxis.valueToJava2D(mean[i], dataArea, RectangleEdge.LEFT); g2.drawLine((int) xpos - 2, (int) ypos, (int) xpos + 2, (int) ypos); // conect the dots if (prevx != -1 && prevy != -1) { g2.setColor(Color.BLACK); if (dashed) g2.setStroke(stroke_dashed); g2.drawLine((int) prevx, (int) prevy, (int) xpos, (int) ypos); if (dashed) { dashed = false; g2.setStroke(stroke_solid); } } prevy = ypos; prevx = xpos; // draw the outer values g2.setColor(Color.LIGHT_GRAY); double ypos_min = yaxis.valueToJava2D(min[i], dataArea, RectangleEdge.LEFT); g2.drawLine((int) xpos - 2, (int) ypos_min, (int) xpos + 2, (int) ypos_min); double ypos_max = yaxis.valueToJava2D(max[i], dataArea, RectangleEdge.LEFT); g2.drawLine((int) xpos - 2, (int) ypos_max, (int) xpos + 2, (int) ypos_max); g2.drawLine((int) xpos, (int) ypos_min, (int) xpos, (int) ypos_max); } } // reset g2.setClip(originalclip); }
From source file:paquete.HollywoodUI.java
public void dibujarAristas() { Graphics2D g = grafico.createGraphics(); g.setFont(new Font("SansSerif", Font.BOLD, 11)); adyaTemp = new ArrayList<>(this.HollyUniverseGraph.getEdges()); for (Actor temp_actor : actoresArray) { for (Arista temp_arista : adyaTemp) { g.setColor(Color.BLACK); g.drawLine(temp_actor.getX(), temp_actor.getY(), temp_arista.getNext().getX(), temp_arista.getNext().getY()); int nx = (temp_actor.getX() + temp_arista.getNext().getX()) / 2; int ny = (temp_actor.getY() + temp_arista.getNext().getY()) / 2; g.setColor(Color.ORANGE); if (temp_arista.getRelacion().equals("Amistad")) { g.setColor(Color.BLUE); g.drawString(temp_arista.getRelacion() + "", nx + 10, ny - 3); } else if (temp_arista.getRelacion().equals("Noviazgo")) { g.setColor(Color.GREEN); g.drawString(temp_arista.getRelacion() + "", nx + 10, ny + 23); } else if (temp_arista.getRelacion().equals("Matrimonio")) { g.setColor(Color.RED); g.drawString(temp_arista.getRelacion() + "", nx - 15, ny - 5); } else if (temp_arista.getRelacion().equals("Familia")) { g.setColor(Color.YELLOW); g.drawString(temp_arista.getRelacion() + "", nx - 15, ny - 5); }// w w w .j a v a 2s . c om } } Image img; img = Toolkit.getDefaultToolkit().createImage(grafico.getSource()).getScaledInstance(800, 600, 0); label_grafico.setIcon(new ImageIcon(img)); }
From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java
public boolean renderVsParameter(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);//from w w w .ja v a 2 s . co m final double parStep; int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; //? 28.7.2004 ValueAxis domainAxis = plot.getDomainAxis(); lower = domainAxis.getRange().getLowerBound(); upper = domainAxis.getRange().getUpperBound(); parStep = Math.abs(upper - lower) / imageWidth; String colNames[] = new String[model.getNVar() + 1]; colNames[0] = firstParLabel; for (int j = 1; j < (model.getNVar() + 1); j++) colNames[j] = "" + (new Integer(j)); Dataset dataset = new Dataset(colNames); lyapunovComponent.setDataobject(dataset); double tmpRow[]; if (model instanceof ODE) { double step = stepSize; // stepSize and timeStep probably mean the same thing, one for discrete another for ODE for (double i = lower; i < upper; i += parStep) { double[] result = new double[model.getNVar()];//initializing not needed but compiler too cautious. int transX, transY; parameters.put(firstParLabel, i); result = Lua.evaluateLyapunovExponentsODE(model, parameters, initialPoint, timePeriod, stepSize); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i != lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } } } //? 28.7.2004 else { for (double i = lower; i < upper; i += parStep) { double[] result; int transX, transY; parameters.put(firstParLabel, i); result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i != lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } } } return true; }
From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use.//from w w w . j a v a 2 s. c om * paints the log lane, with time indicators. * @param gOrig * @param dMin date on the left boundary * @param dMax date on the right boundary */ protected void paintComponentLane(Graphics2D g, int width, int hight) { g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null; Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; // calculate common coordinates int unitHeight = hight / getHashMapSize(); int yTop = 0; int yBottom = hight; int pixStart = 0; String dateStr, timeStr, millisStr = null; // calculate area to be painted clipL = 0; clipR = width; // initialze start color fgColor = colorLogDark; bgColor = colorLogBright; // calculate current top int currentTop = yTop; // paint actual log lane (only the part in the clipping range determined) Iterator itr = dcModel.getSortedKeySetList().iterator(); //dcModel.getItemMap().keySet().iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int index = 0; currentTop = yTop; while (itr.hasNext()) { String dimName = (String) itr.next(); if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName)) continue; g.setColor(bgColor); g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight); g.setColor(fgColor); index++; currentTop = unit2Cord_buffer(index, hight); // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); clipLeftTs = coord2timeMillis(clipL); clipRightTs = coord2timeMillis(clipR); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use. paints the log lane, with time * indicators.//from w ww . j a v a2s. c om * * @param gOrig * @param dMin * date on the left boundary * @param dMax * date on the right boundary */ protected void paintComponentLane(Graphics2D g, int width, int hight) { g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null; Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; // calculate common coordinates int unitHeight = hight / getHashMapSize(); int yTop = 0; int yBottom = hight; int pixStart = 0; String dateStr, timeStr, millisStr = null; // calculate area to be painted clipL = 0; clipR = width; // initialze start color fgColor = colorLogDark; bgColor = colorLogBright; // calculate current top int currentTop = yTop; // paint actual log lane (only the part in the clipping range // determined) Iterator itr = dcModel.getSortedKeySetList().iterator(); // dcModel.getItemMap().keySet().iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int index = 0; currentTop = yTop; while (itr.hasNext()) { String dimName = (String) itr.next(); if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName)) continue; g.setColor(bgColor); g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight); g.setColor(fgColor); index++; currentTop = unit2Cord_buffer(index, hight); // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); clipLeftTs = coord2timeMillis(clipL); clipRightTs = coord2timeMillis(clipR); }
From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java
public boolean renderVsTime(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);// w w w . ja v a2s . c o m final int timeStep; if (Math.abs(upper - lower) >= imageWidth) { timeStep = ((int) upper - (int) lower) / imageWidth; } else { timeStep = 1; } int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; //? 14.7.2004 //LyapunovExpCalc lyapunovExpCalc; LuaLyapExp integrator = new LuaLyapExp(model, parameters, initialPoint); String colNames[] = new String[model.getNVar() + 1]; colNames[0] = "time"; for (int j = 1; j < model.getNVar() + 1; j++) colNames[j] = "" + (new Integer(j)); Dataset dataset = new Dataset(colNames); lyapunovComponent.setDataobject(dataset); double tmpRow[]; if (model instanceof ODE) { double step = stepSize; // stepSize and timeStep probably mean the same thing, one for discrete another for ODE //checking trajectory for (int i = 0; i < (int) (upper / stepSize); i++) { double[] result = new double[model.getNVar()]; int transX, transY; double[] temp = integrator.evaluateODEStep(step); double tt = integrator.getTime(); for (int h = 0; h < temp.length; h++) { result[h] = temp[h] / tt; } tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i * stepSize, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i > (int) lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } } } else {//? 14.7.2004 section of code above for (int i = (int) lower; i < (int) upper; i += timeStep) { double[] result = new double[model.getNVar()]; int transX, transY; result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, i); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i > (int) lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } } } //? } belongs to else 14.7.2004 return true; }
From source file:org.squidy.designer.zoom.ActionShape.java
@Override protected void paintShapeZoomedOut(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); RectangularShape r = (RectangularShape) getZoomedOutShape(); if (r instanceof RoundRectangle2D) { // g.setStroke(STROKE_ZOOMED_OUT); g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED); g.setStroke(StrokeUtils.getBasicStroke(20f)); if (polygonRendering) { if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Polygon shadeHorizontal = new Polygon(); Polygon shadeVertical = new Polygon(); double shift = 1; shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); Rectangle bounds = shapeZoomedOut.getBounds(); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shift = 30;/*from w w w .jav a 2 s . c o m*/ shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); bounds = shapeZoomedOut.getBounds(); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); g.fillPolygon(shadeHorizontal); g.fillPolygon(shadeVertical); } } else { g.draw(shapeZoomedOut); } } else { for (double shift = 30.; shift >= 1.; shift -= 5.) { shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Rectangle bounds = shapeZoomedOut.getBounds(); // g.fillRect(bounds.x, bounds.y, bounds.width, // bounds.height); g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3, bounds.y + bounds.height); g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width, bounds.y + bounds.height - 3); } } else { g.draw(shapeZoomedOut); } } } } super.paintShapeZoomedOut(paintContext); }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private BufferedImage createFloorImage(HmFolder floor, double scale, int floorWidth, int floorHeight, Map<Long, Integer> channelMap, Map<Long, Integer> colorMap, int borderX, int borderY, double gridSize) throws Exception { BufferedImage image = new BufferedImage(floorWidth + borderX + 1, floorHeight + borderY + 1, BufferedImage.TYPE_INT_ARGB); if (floor == null) { return image; }/*from ww w. jav a2 s .c om*/ double metricWidth = 0.0, metricHeight = 0.0, offsetX = 0.0, offsetY = 0.0; int imageWidth = 0; LengthUnit lengthUnit = LengthUnit.METERS; if (null != floor.getMetricWidth()) { metricWidth = floor.getMetricWidth().doubleValue(); } if (null != floor.getMetricHeight()) { metricHeight = floor.getMetricHeight().doubleValue(); } if (null != floor.getImageWidth()) { imageWidth = floor.getImageWidth().intValue(); } if (null != floor.getOffsetX()) { offsetX = floor.getOffsetX().doubleValue(); } if (null != floor.getOffsetY()) { offsetY = floor.getOffsetY().doubleValue(); } if (null != floor.getLengthUnit()) { lengthUnit = floor.getLengthUnit(); } Graphics2D g2 = image.createGraphics(); g2.setStroke(new BasicStroke(1)); if (getDistanceMetric(metricWidth, lengthUnit) == 0) { g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); g2.setColor(new Color(255, 255, 204)); g2.fillRect(borderX + 2, borderY + 2, 162, 25); g2.setColor(new Color(0, 51, 102)); g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); g2.drawString("Please size this floor plan.", borderX + 8, borderY + 19); return image; } double screenWidth = scale * getDistanceMetric(metricWidth, lengthUnit); double imageScale = screenWidth / imageWidth; int originX = (int) (getDistanceMetric(offsetX, lengthUnit) * scale); int originY = (int) (getDistanceMetric(offsetY, lengthUnit) * scale); g2.setColor(new Color(255, 255, 255)); if (floor.getBackground() != null && floor.getBackground().length() > 0) { LinkedMultiValueMap<String, String> metadata = new LinkedMultiValueMap<>(); String url = getImageBaseUrl(floor.getOwnerId()) + floor.getBackground(); try { BufferedImage map = ImageIO.read(clientFileService.getFile(url, "AFS_TOKEN", metadata)); AffineTransform transform = new AffineTransform(); transform.scale(imageScale, imageScale); g2.drawImage(map, new AffineTransformOp(transform, null), getFloorX(0, borderX, originX), getFloorY(0, borderY, originY)); } catch (Exception e) { logger.error(String.format("image file not found with url: %s", url)); double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } } else { double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } g2.setColor(new Color(204, 204, 204)); // Right edge border g2.drawLine(borderX + floorWidth, borderY + 1, borderX + floorWidth, borderY + floorHeight); // Left edge border (right of tick marks) g2.drawLine(borderX + 1, borderY + floorHeight, borderX + floorWidth, borderY + floorHeight); g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); Font font = new Font(Font.SANS_SERIF, Font.BOLD, 12); double actualWidth = floorWidth / scale; double actualHeight = floorHeight / scale; String firstLabel; double unitScale = scale; if (LengthUnit.FEET == lengthUnit) { firstLabel = "0 feet"; actualWidth /= HmFolder.FEET_TO_METERS; actualHeight /= HmFolder.FEET_TO_METERS; unitScale *= HmFolder.FEET_TO_METERS; } else { firstLabel = "0 meters"; } g2.drawString(firstLabel, borderX + 4, 12); double gridX = gridSize; while (gridX < actualWidth) { int x = (int) (gridX * unitScale) + borderX; g2.drawLine(x, 0, x, borderY); boolean label = true; if (gridX + gridSize >= actualWidth) { // Last mark if (x + getNumberPixelWidth(gridX) + 2 > floorWidth) { label = false; } } if (label) { g2.drawString("" + (int) gridX, x + 4, 12); } gridX += gridSize; } double gridY = 0; while (gridY < actualHeight) { int y = (int) (gridY * unitScale) + borderY; g2.drawLine(0, y, borderX, y); double lx = gridY; int dx = 1; for (int bx = borderX; bx >= 16; bx -= 7) { if (lx < 10) { dx += 7; } else { lx /= 10; } } boolean label = true; if (gridY + gridSize >= actualHeight) { // Last mark if (y - borderY + 13 > floorHeight) { label = false; } } if (label) { g2.drawString("" + (int) gridY, dx, y + 13); } gridY += gridSize; } double mapToImage = getMapToMetric(metricWidth, imageWidth, lengthUnit) * scale; if (floor.getPerimeter().size() > 0) { g2.setStroke(new BasicStroke(2)); g2.setColor(new Color(2, 159, 245)); int[] xPoints = new int[floor.getPerimeter().size()]; int[] yPoints = new int[floor.getPerimeter().size()]; int nPoints = 0; int perimId = floor.getPerimeter().get(0).getId(); for (int i = 0; i < floor.getPerimeter().size(); i++) { HmVertex vertex = floor.getPerimeter().get(i); if (vertex.getId() != perimId) { g2.drawPolygon(xPoints, yPoints, nPoints); nPoints = 0; perimId = vertex.getId(); } xPoints[nPoints] = getFloorX((int) (vertex.getX() * mapToImage), borderX, originX); yPoints[nPoints++] = getFloorY((int) (vertex.getY() * mapToImage), borderY, originY); } g2.drawPolygon(xPoints, yPoints, nPoints); } g2.setStroke(new BasicStroke(1)); g2.setColor(new Color(0, 170, 0)); g2.setFont(font.deriveFont(Font.BOLD, 11)); List<HmDeviceLocationEx> devices = deviceLocationExRep.findAllHmDevices(floor.getId()); if (null != devices && !devices.isEmpty()) { for (HmDeviceLocationEx device : devices) { double x = device.getX() * mapToImage; double y = device.getY() * mapToImage; createNodeImage(device.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } else { List<HmDevicePlanningEx> plannedDevices = devicePlanningExRep.findAllPlannedDevices(floor.getId()); for (HmDevicePlanningEx plannedDevice : plannedDevices) { double x = plannedDevice.getX() * mapToImage; double y = plannedDevice.getY() * mapToImage; createNodeImage(plannedDevice.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } return image; }
From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java
private void addAnnotations(BufferedImage pImage, int pHeight, int pWidth, double pPitch, double pYaw, boolean pDrawNorthArrow) { if (mCopyrightTextContent.length() > 0) { Graphics2D g = pImage.createGraphics(); g.drawImage(pImage, 0, 0, null); g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(), mCopyrightTextColor.getBlue())); // 1. Copyright-Vermerk // Etwas unschn: Durch JPEG-Komprimierung wird Text (insb. bei kleiner Font-Gre) wird unscharf... // TODO: Abhilfe evtl. durch Hintergrund? Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/, mCopyrightTextSize);/* ww w . j av a 2 s . co m*/ g.setFont(font); // mehrzeilige Copyright-Texte erlauben: StringTokenizer str = new StringTokenizer(mCopyrightTextContent, "\n"); int spacePerRow = mCopyrightTextSize; int rows = str.countTokens(); int startPos = spacePerRow * rows; int currRow = 0; while (str.hasMoreTokens()) { int yPos = pHeight - (startPos - (currRow * spacePerRow)) + spacePerRow / 2; g.drawString(str.nextToken().trim(), 5, yPos); currRow++; } // 2. Nordpfeil if (pDrawNorthArrow) { // Zeichenparameter: double radius = 35.; double phi = 15.; // Symbolkonstruktion: int rx = (int) radius; int ry = (int) Math.round(radius * Math.sin(-pPitch * Math.PI / 180.)); int mx = pWidth - rx - 5; int my = pHeight - ry - 5; int dx = (int) (radius * Math.sin(pYaw * Math.PI / 180.)); int dy = (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos(pYaw * Math.PI / 180.)); int px = mx - dx, py = my - dy; // Pfeilspitze int qlx = mx + (int) (radius * Math.sin((pYaw + phi) * Math.PI / 180.)); int qly = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos((pYaw + phi) * Math.PI / 180.)); int qrx = mx + (int) (radius * Math.sin((pYaw - phi) * Math.PI / 180.)); int qry = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos((pYaw - phi) * Math.PI / 180.)); // Ellipse zeichnen: g.setStroke(new BasicStroke(2.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); g.drawOval(mx - rx, my - ry, 2 * rx, 2 * ry); // Striche fr Pfeil zeichnen: g.setStroke(new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); boolean fillArrow = true; if (fillArrow) g.fill(new Polygon(new int[] { px, qlx, qrx }, new int[] { py, qly, qry }, 3)); else { g.drawLine(px, py, qlx, qly); g.drawLine(px, py, qrx, qry); g.drawLine(qlx, qly, qrx, qry); } } g.dispose(); } }