List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:gda.plots.TurboXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself./*from w ww. ja v a 2 s. c o m*/ * * @param g2 * the graphics device. * @param state * 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 crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item, CrosshairState crosshairState, int pass) { if (_item > 0) return; SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); try { int x0 = -1; // the x position in pixels of the previous point int y0 = -1; // the y position in pixels of the previous point int x1 = -1; // the x position in pixels of the current point int y1 = -1; // the y position in pixels of the current point int xmin = (int) dataArea.getMinX(); int xmax = (int) dataArea.getMaxX(); int ymin = (int) dataArea.getMinY(); int ymax = (int) dataArea.getMaxY(); GeneralPath path = null; /* * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear * maths */ double xl = 0., mx = Double.NaN, cx = 0.; if (domainAxis instanceof SimpleNumberAxis) { xl = domainAxis.getRange().getLowerBound(); mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl); cx = xmin; } double yl = 0., my = Double.NaN, cy = 0.; if (rangeAxis instanceof SimpleNumberAxis) { yl = rangeAxis.getRange().getLowerBound(); my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl); cy = ymax; } List<XYDataItem> list = sxys.getData(); boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my); Paint paint = sxys.getPaint(); Stroke stroke = sxys.getStroke(); Paint paint_symbol = sxys.getSymbolPaint(); Stroke stroke_symbol = new BasicStroke(); drawLines = sxys.isDrawLines(); boolean filled = sxys.getFilled(); Shape shape = sxys.getSymbol(); boolean drawMarkers = sxys.isDrawMarkers() & shape != null; int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */ if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) { Rectangle shapeBoundingBox = shape.getBounds(); tooltipThresholdCounts = (int) dataArea.getWidth() / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold); } java.util.Vector<ddouble> markerPositions = null; Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } boolean prevLineAdded = false; // In case the iterator does not work then use the TODO comment iterator use and why not always // comment variables synchronized (list) { Iterator<XYDataItem> iter = list.iterator(); /* * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The * variable addThis determines if the current point is to be added to the path If previous line was * added that the current must be even if off the screen - but in this case the flag prevLineAdded is * set false so that the next does not have to be added. */ for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) { XYDataItem dataitem = iter.next(); double x = dataitem.getX().doubleValue(); double y = dataitem.getY().doubleValue(); x = xValueTransformer.transformValue(x); x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation) : (int) ((x - xl) * mx + cx); y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) : (int) ((y - yl) * my + cy); boolean addThis = true; if (item == 0) { x0 = x1; y0 = y1; if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) { addThis = false; } } else { if (x1 == x0 && y1 == y0) { addThis = false; } if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin) || (y1 > ymax && y0 > ymax)) { if (prevLineAdded) { path = addPointToLine(path, orientation, x1, y1); } addThis = false; } } if (addThis) { /* * If the current point is to be added then ensure previous one is as well to prevent lines * not crossing the edge of the screen */ if (!prevLineAdded) { path = addPointToLine(path, orientation, x0, y0); } path = addPointToLine(path, orientation, x1, y1); prevLineAdded = true; } prevLineAdded = addThis; if (addThis && drawMarkers) { if (markerPositions == null) { markerPositions = new java.util.Vector<ddouble>(); } markerPositions.add(new ddouble(item, x1, y1)); if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) { drawMarkers = false; markerPositions = null; } } } if (path != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(path); } if (markerPositions != null) { if (drawMarkers) { g2.setPaint(paint_symbol); g2.setStroke(stroke_symbol); for (ddouble dd : markerPositions) { Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y); if (filled) { g2.fill(shape_item); } else { g2.draw(shape_item); } entityArea = shape_item; // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y); } } g2.setPaint(paint); g2.setStroke(stroke); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java
/** * Draw a single data item./*from www. ja va 2s . co m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { if (!isSeriesVisible(row)) { return; } if ((pass == 1) && !isItemLabelVisible(row, column)) { return; } // setup for collecting optional entity info... Shape entityArea = null; final EntityCollection entities = state.getEntityCollection(); double y1 = 0.0; Number n = dataset.getValue(row, column); if (n != null) { y1 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, column); y1 = y1 / total; } } final double[] stack1 = getStackValues(dataset, row, column); // 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()); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... double y0 = 0.0; n = dataset.getValue(row, Math.max(column - 1, 0)); if (n != null) { y0 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, Math.max(column - 1, 0)); y0 = y0 / total; } } final double[] stack0 = getStackValues(dataset, row, Math.max(column - 1, 0)); // FIXME: calculate xx0 double xx0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); final int itemCount = dataset.getColumnCount(); double y2 = 0.0; n = dataset.getValue(row, Math.min(column + 1, itemCount - 1)); if (n != null) { y2 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, Math.min(column + 1, itemCount - 1)); y2 = y2 / total; } } final double[] stack2 = getStackValues(dataset, row, Math.min(column + 1, itemCount - 1)); double xx2 = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); // This gets rid of the white lines between most category values // Doug Moran - Hitachi Vantara xx0 = Math.round(xx0); xx1 = Math.round(xx1); xx2 = Math.round(xx2); // FIXME: calculate xxLeft and xxRight final double xxLeft = xx0; final double xxRight = xx2; final double[] stackLeft = averageStackValues(stack0, stack1); final double[] stackRight = averageStackValues(stack1, stack2); final double[] adjStackLeft = adjustedStackValues(stack0, stack1); final double[] adjStackRight = adjustedStackValues(stack1, stack2); final float transY1; final RectangleEdge edge1 = plot.getRangeAxisEdge(); final GeneralPath left = new GeneralPath(); final GeneralPath right = new GeneralPath(); if (y1 >= 0.0) { // handle positive value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1); final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1); final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { final double yleft = (y0 + y1) / 2.0 + stackLeft[1]; final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo((float) xx1, transY1); left.lineTo((float) xx1, transStack1); left.lineTo((float) xxLeft, transStackLeft); left.lineTo((float) xxLeft, transYLeft); left.closePath(); } else { left.moveTo((float) xx1, transStack1); left.lineTo((float) xx1, transY1); left.lineTo((float) xxLeft, transStackLeft); left.closePath(); } final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { final double yright = (y1 + y2) / 2.0 + stackRight[1]; final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transYRight); right.lineTo((float) xxRight, transStackRight); right.closePath(); } else { right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transStackRight); right.closePath(); } } else { // handle negative value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1); final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1); final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { left.moveTo((float) xx1, transStack1); left.lineTo((float) xx1, transY1); left.lineTo((float) xxLeft, transStackLeft); left.clone(); } else { final double yleft = (y0 + y1) / 2.0 + stackLeft[0]; final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo((float) xx1, transY1); left.lineTo((float) xx1, transStack1); left.lineTo((float) xxLeft, transStackLeft); left.lineTo((float) xxLeft, transYLeft); left.closePath(); } final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transStackRight); right.closePath(); } else { final double yright = (y1 + y2) / 2.0 + stackRight[0]; final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transYRight); right.lineTo((float) xxRight, transStackRight); right.closePath(); } } if (pass == 0) { final Paint itemPaint = getItemPaint(row, column); g2.setPaint(itemPaint); g2.fill(left); g2.fill(right); // add an entity for the item... if (entities != null) { final GeneralPath gp = new GeneralPath(left); gp.append(right, false); entityArea = gp; addItemEntity(entities, dataset, row, column, entityArea); } } else if (pass == 1) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, transY1, y1 < 0.0); } }
From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java
/** * Draws a single task./*from ww w . j a v a2 s . com*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, TrackTaskSeriesCollection dataset, int row, int column, int pass) { log.debug("Working on item at position - column: " + column + " row: " + row); int seriesCount = getRowCount(); int categoryCount = getColumnCount(); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // Y0 Number value0 = dataset.getEndValue(row, column); if (value0 == null) { return; } double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // Y1 Number value1 = dataset.getStartValue(row, column); if (value1 == null) { return; } double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; Number tempNum = value1; value1 = value0; value0 = tempNum; } double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); // BREADTH double rectBreadth = state.getBarWidth(); // BAR HEIGHT double rectLength = Math.abs(java2dValue1 - java2dValue0); Rectangle2D bar = null; if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectStart = rectStart + row * (state.getBarWidth() + seriesGap); } else { rectStart = rectStart + row * state.getBarWidth(); } // correct the start/stop Bars point if (startBars > (int) (java2dValue1 - rectLength)) { this.startBars = (int) (java2dValue1 - rectLength); } if (stopBars < (int) java2dValue1) { stopBars = (int) java2dValue1; } // The coordinates for the bar labels int startLabelX = 0; int startLabelY = 0; int endLabelX = 0; int endLabelY = 0; int barLabelX = 0; int barLabelY = 0; Polygon outer = null; Polygon inner = null; boolean isMilestone = dataset.isMilestone(column, row); boolean isSupertask = dataset.isSupertask(column, row); if (isMilestone) { // The start point for the end date label endLabelX = (int) (java2dValue1 + rectBreadth / 2); endLabelY = (int) (rectStart + (3 * rectBreadth / 4)); barLabelX = (int) (java2dValue1 - rectBreadth / 2); barLabelY = (int) (rectStart + (3 * rectBreadth / 4)); int breadth = (int) rectBreadth; int centerX = (int) java2dValue1; int centerY = (int) (rectStart + rectBreadth / 2); int[] xPoints = { centerX, centerX - breadth / 2, centerX, centerX + breadth / 2 }; int[] yPoints = { centerY - breadth / 2, centerY, centerY + breadth / 2, centerY }; outer = new Polygon(xPoints, yPoints, 4); //calculate the difference from the ratio int diff = (int) (rectBreadth / (2 * msInfo.getRatio())); int[] xPointsI = { centerX, centerX - breadth / 2 + diff, centerX, centerX + breadth / 2 - diff }; int[] yPointsI = { centerY - breadth / 2 + diff, centerY, centerY + breadth / 2 - diff, centerY }; inner = new Polygon(xPointsI, yPointsI, 4); } else if (isSupertask) { // The start point for the end date label startLabelX = (int) (java2dValue1 - rectLength - rectBreadth / 2); startLabelY = (int) (rectStart + rectBreadth * 3 / 4); endLabelX = (int) (java2dValue1 + rectBreadth / 2); endLabelY = (int) (rectStart + rectBreadth * 3 / 4); barLabelX = (int) (java2dValue1 - rectLength + rectBreadth / 3); barLabelY = (int) (rectStart + rectBreadth); int breadth = (int) rectBreadth; int length = (int) rectLength; int startX = (int) (java2dValue1 - rectLength); int startY = (int) rectStart; int[] xPoints = { startX - breadth / 2, startX + length + breadth / 2, startX + length + breadth / 2, startX + length, startX + length - breadth / 2, startX + breadth / 2, startX, startX - breadth / 2 }; int[] yPoints = { startY, startY, startY + breadth / 2, startY + breadth, startY + breadth / 2, startY + breadth / 2, startY + breadth, startY + breadth / 2 }; outer = new Polygon(xPoints, yPoints, 8); //calculate the difference from the ratio int diff = (int) (rectBreadth / (2 * stInfo.getRatio())); int[] xPointsI = { startX - breadth / 2 + diff, startX + length + breadth / 2 - diff, startX + length + breadth / 2 - diff, startX + length, startX + length - breadth / 2 + diff, startX + length - breadth / 2 + diff, startX + breadth / 2 - diff, startX + breadth / 2 - diff, startX, startX - breadth / 2 + diff }; int[] yPointsI = { startY + diff, startY + diff, startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2, startY + breadth / 2 - diff, startY + breadth / 2 - diff, startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2 }; inner = new Polygon(xPointsI, yPointsI, 10); } else { rectBreadth = rectBreadth / 2.0; // The start point for the end date label startLabelX = (int) (java2dValue1 - rectLength); startLabelY = (int) (rectStart + rectBreadth * 3 / 4); endLabelX = (int) java2dValue1; endLabelY = (int) (rectStart + rectBreadth * 3 / 4); barLabelX = (int) (java2dValue1 - rectLength); barLabelY = (int) (rectStart); //+ rectBreadth * 4 / 3 ); bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth); // percent complete could be obtained in the // ReportBeans, set in the ReportBean and set in the Item by the GanttGenerator // currently this is not relevant. Rectangle2D completeBar = null; Rectangle2D incompleteBar = null; Number percent = dataset.getPercentComplete(row, column); double start = getStartPercent(); double end = getEndPercent(); if (percent != null) { double p = percent.doubleValue(); completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start)); incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start)); } /** This is for displaying e.g. (german Soll und Ist Termine). This implementation is designed to display only one Series. * If you need Soll und Ist, you can generate two gantt charts. * --->> Paint seriesPaint = getItemPaint (row, column); */ Paint seriesPaint = tsInfo.getInnerColor(); g2.setPaint(seriesPaint); g2.fill(bar); if (tsInfo.isDisplayIDLabel() && (!tsInfo.isDisplaySynopsis())) { // draw the tasks ID drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, tsInfo.getLabelFontID(), false, (int) rectLength); } else if (tsInfo.isDisplaySynopsis()) { if (tsInfo.isDisplayDateLabel()) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); label = dataset.getItem(column, row).getDescription() + " - " + label; drawLabel(label, g2, barLabelX, barLabelY, tsInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false); } else { drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true); } } if (tsInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); // draw the tasks start date drawLabel(label, g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the tasks end date drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false); } if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } // draw the outline... if (state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } } // Draw milestone or Supertask if (isMilestone) { g2.setPaint(msInfo.getOuterColor()); g2.fill(outer); g2.draw(outer); g2.setPaint(msInfo.getInnerColor()); g2.fill(inner); g2.draw(inner); Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(outer); } // draw the milestones due date if (msInfo.isDisplayDateLabel()) { // format milestone date to the requested format using the current locale String label = (new SimpleDateFormat(msInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); drawLabel(label, g2, endLabelX, endLabelY, msInfo.getLabelFont(), false); } if (msInfo.isDisplayIDLabel() && (!msInfo.isDisplaySynopsis())) { // for milestones the ID is aligned at the left side. drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, msInfo.getLabelFontID(), true, (int) rectLength); } else if (msInfo.isDisplaySynopsis()) { drawLabel(dataset.getItem(column, row).getDescription(), g2, barLabelX, barLabelY, msInfo.getLabelFont(), true, (int) rectLength); } } else if (isSupertask) { g2.setPaint(stInfo.getOuterColor()); g2.fill(outer); g2.draw(outer); g2.setPaint(stInfo.getInnerColor()); g2.fill(inner); g2.draw(inner); Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(outer); } // draw the supertasks ID if (stInfo.isDisplayIDLabel() && (!stInfo.isDisplaySynopsis())) { drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, stInfo.getLabelFontID(), false, (int) rectLength); } else if (stInfo.isDisplaySynopsis()) { if (stInfo.isDisplayDateLabel()) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); label = dataset.getItem(column, row).getDescription() + " - " + label; drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false); } else { drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); } } if (stInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); // draw the supertasks start date drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false); } } }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.renderer.HierarchicalBarRenderer.java
/** * Draws the bar for one item in the dataset. * * @param g2//from w ww .ja v a 2 s.c om * the graphics device. * @param state * the renderer state. * @param dataArea * the plot area. * @param plot * the plot. * @param domainAxis * the domain (category) axis. * @param rangeAxis * the range (value) axis. * @param data * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = data.getValue(row, column); if (dataValue == null) { return; } // BAR X double rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); int seriesCount = this.getRowCount(); // BAR Y double value = dataValue.doubleValue(); double base = 0.0; double lclip = this.getLowerClip(); double uclip = this.getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = this.getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge edge = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); double rectY = Math.min(transY2, transY1); double rectWidth = state.getBarWidth(); double rectHeight = Math.abs(transY2 - transY1); // draw the bar... double shift = 0.0; rectWidth = 0.0; double widthFactor = 1.0; double seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - ((seriesCount - 1 - row) * shift * 2)), rectHeight); double rrX; double rrY; double rrW; double rrH; if (row == 0) { @SuppressWarnings("unchecked") Iterator it = this.datasetTree[column].getDescendants(); int numElement = -1; while (it.hasNext()) { try { Element elt = (Element) it.next(); numElement++; String name = elt.getAttributeValue("name"); dataValue = Double.valueOf(elt.getAttributeValue("avg")); // System.out.println("["+column+"] "+name+" \t--> // "+dataValue); // BAR X rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); seriesCount = this.getRowCount(); // BAR Y value = dataValue.doubleValue(); base = 0.0; lclip = this.getLowerClip(); uclip = this.getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = this.getLowerClip(); if (value >= uclip) { value = uclip; } } edge = plot.getRangeAxisEdge(); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); rectY = Math.min(transY2, transY1); rectWidth = state.getBarWidth(); rectHeight = Math.abs(transY2 - transY1); // draw the bar... shift = 0.0; rectWidth = 0.0; widthFactor = 1.0; seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } rrX = (rectX + ((seriesCount - 1 - row) * shift)); rrY = rectY; rrW = (rectWidth - ((seriesCount - 1 - row) * shift * 2)); rrH = rectHeight; // IMPORTANT NOTE : // dev attribute is used to save width of the element // min attribute is used to save X position of the element // max attribute is used to save the number of child already // managed if (numElement == 0) { elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); elt.setAttribute("max", "0"); } else { Element parent = elt.getParentElement(); // System.out.println(" Parent // "+parent.getAttributeValue("name") // + " rrX/rrW/child -> " // + parent.getAttributeValue("min")+"/" // + parent.getAttributeValue("dev")+"/" // + parent.getAttributeValue("max") ); double pW = Double.valueOf(parent.getAttributeValue("dev")); double pX = Double.valueOf(parent.getAttributeValue("min")); int numChild = Integer.valueOf(parent.getAttributeValue("max")); rrW = pW / parent.getChildren().size(); rrX = pX + (rrW * numChild); rrX += HierarchicalBarRenderer.INCLUSION_MARGIN; rrW -= (HierarchicalBarRenderer.INCLUSION_MARGIN * 2); elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); parent.setAttribute("max", "" + (numChild + 1)); } RoundRectangle2D rbar = new RoundRectangle2D.Double(rrX, rrY, rrW, rrH, HierarchicalBarRenderer.CORNER, HierarchicalBarRenderer.CORNER); Rectangle2D childSumLine = null; double childSum = Double.valueOf(elt.getAttributeValue("sum")); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(childSum, dataArea, edge); rectY = Math.min(transY2, transY1); childSum = (childSum / dataValue.doubleValue()) * rrH; if ((childSum < rrH) && (childSum > 0) && ((childSum / rrH) < 0.95)) { childSumLine = new Rectangle2D.Double(rrX, rectY, rrW, 1); } Paint itemPaint = this.getItemPaintFromName(name, this.series, column); GradientPaintTransformer t = this.getGradientPaintTransformer(); if ((t != null) && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); Color c = g2.getColor(); g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), this.alpha)); g2.fill(rbar); g2.setColor(Color.DARK_GRAY); if (childSumLine != null) { g2.fill(childSumLine); } // draw the outline... if (this.isDrawBarOutline() && (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD)) { Stroke stroke = this.getItemOutlineStroke(row, column); Paint paint = this.getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(rbar); } } } catch (ClassCastException e) { continue; } } } // //////////////////////////// // draw the item labels if there are any... double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge); CategoryItemLabelGenerator generator = this.getItemLabelGenerator(row, column); if ((generator != null) && this.isItemLabelVisible(row, column)) { this.drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = this.getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(data, row, column); } String url = null; if (this.getItemURLGenerator(row, column) != null) { url = this.getItemURLGenerator(row, column).generateURL(data, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, data, row, data.getColumnKey(column), column); entities.add(entity); } } }
From source file:net.technicpack.launcher.lang.ResourceLoader.java
public BufferedImage getCircleClippedImage(String imageName) { BufferedImage contentImage = getImage(imageName); // copy the picture to an image with transparency capabilities BufferedImage outputImage = new BufferedImage(contentImage.getWidth(), contentImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) outputImage.getGraphics(); g2.drawImage(contentImage, 0, 0, null); // Create the area around the circle to cut out Area cutOutArea = new Area(new Rectangle(0, 0, outputImage.getWidth(), outputImage.getHeight())); int diameter = (outputImage.getWidth() < outputImage.getHeight()) ? outputImage.getWidth() : outputImage.getHeight();//from ww w . j a v a 2s . c om cutOutArea.subtract(new Area(new Ellipse2D.Float((outputImage.getWidth() - diameter) / 2, (outputImage.getHeight() - diameter) / 2, diameter, diameter))); // Set the fill color to an opaque color g2.setColor(Color.WHITE); // Set the composite to clear pixels g2.setComposite(AlphaComposite.Clear); // Turn on antialiasing g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear the cut out area g2.fill(cutOutArea); // dispose of the graphics object g2.dispose(); return outputImage; }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public BufferedImage getCircleClippedImage(BufferedImage contentImage) { // copy the picture to an image with transparency capabilities BufferedImage outputImage = new BufferedImage(contentImage.getWidth(), contentImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) outputImage.getGraphics(); g2.drawImage(contentImage, 0, 0, null); // Create the area around the circle to cut out Area cutOutArea = new Area(new Rectangle(0, 0, outputImage.getWidth(), outputImage.getHeight())); int diameter = (outputImage.getWidth() < outputImage.getHeight()) ? outputImage.getWidth() : outputImage.getHeight();/*w w w . j a va2 s.c o m*/ cutOutArea.subtract(new Area(new Ellipse2D.Float((outputImage.getWidth() - diameter) / 2, (outputImage.getHeight() - diameter) / 2, diameter, diameter))); // Set the fill color to an opaque color g2.setColor(Color.WHITE); // Set the composite to clear pixels g2.setComposite(AlphaComposite.Clear); // Turn on antialiasing g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear the cut out area g2.fill(cutOutArea); // dispose of the graphics object g2.dispose(); return outputImage; }
From source file:nl.b3p.imagetool.ImageTool.java
public static BufferedImage drawGeometries(BufferedImage bi, CombineImageSettings settings, int srid, Bbox bbox, int width, int height) throws Exception { List wktGeoms = settings.getWktGeoms(); if (wktGeoms == null || wktGeoms.size() <= 0) { return bi; }/*from w w w . ja v a 2 s . c o m*/ BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE); // BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D gbi = newBufIm.createGraphics(); gbi.drawImage(bi, 0, 0, null); for (int i = 0; i < wktGeoms.size(); i++) { gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); CombineImageWkt ciw = (CombineImageWkt) wktGeoms.get(i); Color color = settings.getDefaultWktGeomColor(); if (ciw.getColor() != null) { color = ciw.getColor(); } gbi.setColor(color); String wktGeom = ciw.getWktGeom(); Geometry geom = geometrieFromText(wktGeom, srid); Shape shape = createImage(geom, srid, bbox, width, height); Point centerPoint = null; if (geom instanceof Polygon) { gbi.fill(shape); } else if (geom instanceof com.vividsolutions.jts.geom.Point) { centerPoint = calculateCenter(shape, srid, bbox, width, height); gbi.draw(new Ellipse2D.Double(centerPoint.getX(), centerPoint.getY(), 4, 4)); } else { gbi.setStroke(new BasicStroke(3)); gbi.draw(shape); } if (ciw.getLabel() != null) { if (centerPoint == null) { centerPoint = calculateCenter(shape, srid, bbox, width, height); } gbi.setColor(Color.black); gbi.drawString(ciw.getLabel(), (float) centerPoint.getX(), (float) centerPoint.getY()); } } gbi.dispose(); return newBufIm; }
From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java
protected void drawTitledMessageBox(Graphics2D g2d, String title, String message, int x, int y, int w, int h) { /* Do some calculations and init variables. */ g2d.setFont(KBConfiguration.OHD_messageBoxFont); FontMetrics fm = g2d.getFontMetrics(); int labelHeight = KBConfiguration.OHD_messageBoxFont.getSize() + (KBConfiguration.OHD_padding * 2); int angling = labelHeight; Rectangle2D testRectangle = fm.getStringBounds(title, g2d); int labelWidth = (int) testRectangle.getWidth(); if (w < labelWidth + (2 * angling)) { w = labelWidth + (2 * angling);//from ww w.ja v a2 s . c o m } y += labelHeight; /* Now draw the box... */ drawMessageBox(g2d, message, x, y, w, h); /* Draw the label background */ g2d.setColor(KBConfiguration.OHD_labelBoxColor); GeneralPath label = new GeneralPath(); label.moveTo(x, y); label.lineTo(x + angling, y - labelHeight); label.lineTo(x + angling + labelWidth, y - labelHeight); label.lineTo(x + (angling * 2) + labelWidth, y); label.closePath(); g2d.fill(label); /* Draw the label Lines.. */ g2d.setColor(KBConfiguration.OHD_borderBoxTopLeft); g2d.drawLine(x, y, x + angling, y - labelHeight); g2d.drawLine(x + angling, y - labelHeight, x + angling + labelWidth, y - labelHeight); g2d.setColor(KBConfiguration.OHD_borderBoxBottomRight); g2d.drawLine(x + angling + labelWidth, y - labelHeight, x + (angling * 2) + labelWidth, y); g2d.setColor(KBConfiguration.OHD_borderBoxBackground); g2d.drawLine(x + (angling * 2) + labelWidth, y, x, y); /*Then add the title... */ g2d.setColor(KBConfiguration.OHD_labelFontBoxColor); g2d.drawString(title, x + angling, y - KBConfiguration.OHD_padding); }
From source file:nl.b3p.viewer.image.ImageTool.java
public static BufferedImage drawGeometries(BufferedImage bi, CombineImageSettings settings, int srid, Bbox bbox, int width, int height) throws Exception { List wktGeoms = settings.getWktGeoms(); if (wktGeoms == null || wktGeoms.size() <= 0) { return bi; }//w w w. j av a 2 s. c o m BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE); // BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D gbi = newBufIm.createGraphics(); gbi.drawImage(bi, 0, 0, null); for (int i = 0; i < wktGeoms.size(); i++) { gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); CombineImageWkt ciw = (CombineImageWkt) wktGeoms.get(i); Color color = settings.getDefaultWktGeomColor(); if (ciw.getColor() != null) { color = ciw.getColor(); } gbi.setColor(color); String wktGeom = ciw.getWktGeom(); Geometry geom = geometrieFromText(wktGeom, srid); Shape shape = createImage(geom, srid, bbox, width, height); Point centerPoint = null; if (geom instanceof Polygon) { gbi.fill(shape); } else if (geom instanceof com.vividsolutions.jts.geom.Point) { centerPoint = calculateCenter(shape, srid, bbox, width, height); gbi.fill(new Ellipse2D.Double(centerPoint.getX(), centerPoint.getY(), 8, 8)); } else { float strokeWidth = ciw.getStrokeWidth() != null ? ciw.getStrokeWidth() : 3f; gbi.setStroke(new BasicStroke(strokeWidth)); gbi.draw(shape); } if (ciw.getLabel() != null) { if (centerPoint == null) { centerPoint = calculateCenter(shape, srid, bbox, width, height); } gbi.setColor(Color.black); gbi.drawString(ciw.getLabel(), (float) centerPoint.getX(), (float) centerPoint.getY()); } } gbi.dispose(); return newBufIm; }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * render sector element on map// ww w .ja v a 2 s . co m * * @param destination * @param point * @param element */ private void renderSector(final Graphics2D destination, final Point point, final double azimuth, final double beamwidth, final IDataElement sector) { int size = getSize(); int x = getSectorXCoordinate(point, size); int y = getSectorYCoordinate(point, size); destination.setColor(networkRendererStyle.changeColor(getColor(sector), networkRendererStyle.getAlpha())); GeneralPath path = new GeneralPath(); path.moveTo(x, y); Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth), beamwidth); path.append(a.getPathIterator(null), true); path.closePath(); destination.draw(path); destination.fill(path); // create border destination.setColor(networkRendererStyle.getBorderColor()); destination.draw(path); }