List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
private void paintThumbnail(Graphics2D g2, PhotoInfo photo, int startx, int starty, boolean isSelected) { log.debug("paintThumbnail entry " + photo.getUuid()); long startTime = System.currentTimeMillis(); long thumbReadyTime = 0; long thumbDrawnTime = 0; long endTime = 0; // Current position in which attributes can be drawn int ypos = starty + rowHeight / 2; boolean useOldThumbnail = false; Thumbnail thumbnail = null;//from www .j a v a 2 s . c om log.debug("finding thumb"); boolean hasThumbnail = photo.hasThumbnail(); log.debug("asked if has thumb"); if (hasThumbnail) { log.debug("Photo " + photo.getUuid() + " has thumbnail"); thumbnail = photo.getThumbnail(); log.debug("got thumbnail"); } else { /* Check if the thumbnail has been just invalidated. If so, use the old one until we get the new thumbnail created. */ thumbnail = photo.getOldThumbnail(); if (thumbnail != null) { useOldThumbnail = true; } else { // No success, use default thumnail. thumbnail = Thumbnail.getDefaultThumbnail(); } // Inform background task scheduler that we have some work to do ctrl.getBackgroundTaskScheduler().registerTaskProducer(this, TaskPriority.CREATE_VISIBLE_THUMBNAIL); } thumbReadyTime = System.currentTimeMillis(); log.debug("starting to draw"); // Find the position for the thumbnail BufferedImage img = thumbnail.getImage(); if (img == null) { thumbnail = Thumbnail.getDefaultThumbnail(); img = thumbnail.getImage(); } float scaleX = ((float) thumbWidth) / ((float) img.getWidth()); float scaleY = ((float) thumbHeight) / ((float) img.getHeight()); float scale = Math.min(scaleX, scaleY); int w = (int) (img.getWidth() * scale); int h = (int) (img.getHeight() * scale); int x = startx + (columnWidth - w) / (int) 2; int y = starty + (rowHeight - h) / (int) 2; log.debug("drawing thumbnail"); // Draw shadow int offset = isSelected ? 2 : 0; int shadowX[] = { x + 3 - offset, x + w + 1 + offset, x + w + 1 + offset }; int shadowY[] = { y + h + 1 + offset, y + h + 1 + offset, y + 3 - offset }; GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, shadowX.length); polyline.moveTo(shadowX[0], shadowY[0]); for (int index = 1; index < shadowX.length; index++) { polyline.lineTo(shadowX[index], shadowY[index]); } ; BasicStroke shadowStroke = new BasicStroke(4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); Stroke oldStroke = g2.getStroke(); g2.setStroke(shadowStroke); g2.setColor(Color.DARK_GRAY); g2.draw(polyline); g2.setStroke(oldStroke); // Paint thumbnail g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, new AffineTransform(scale, 0f, 0f, scale, x, y), null); if (useOldThumbnail) { creatingThumbIcon.paintIcon(this, g2, startx + (columnWidth - creatingThumbIcon.getIconWidth()) / (int) 2, starty + (rowHeight - creatingThumbIcon.getIconHeight()) / (int) 2); } log.debug("Drawn, drawing decorations"); if (isSelected) { Stroke prevStroke = g2.getStroke(); Color prevColor = g2.getColor(); g2.setStroke(new BasicStroke(3.0f)); g2.setColor(Color.BLUE); g2.drawRect(x, y, w, h); g2.setColor(prevColor); g2.setStroke(prevStroke); } thumbDrawnTime = System.currentTimeMillis(); boolean drawAttrs = (thumbWidth >= 100); if (drawAttrs) { // Increase ypos so that attributes are drawn under the image ypos += ((int) h) / 2 + 3; // Draw the attributes // Draw the qualoity icon to the upper left corner of the thumbnail int quality = photo.getQuality(); if (showQuality && quality != 0) { int qx = startx + (columnWidth - quality * starIcon.getIconWidth()) / (int) 2; for (int n = 0; n < quality; n++) { starIcon.paintIcon(this, g2, qx, ypos); qx += starIcon.getIconWidth(); } ypos += starIcon.getIconHeight(); } ypos += 6; if (photo.getRawSettings() != null) { // Draw the "RAW" icon int rx = startx + (columnWidth + w - rawIcon.getIconWidth()) / (int) 2 - 5; int ry = starty + (columnWidth - h - rawIcon.getIconHeight()) / (int) 2 + 5; rawIcon.paintIcon(this, g2, rx, ry); } if (photo.getHistory().getHeads().size() > 1) { // Draw the "unresolved conflicts" icon int rx = startx + (columnWidth + w - 10) / (int) 2 - 20; int ry = starty + (columnWidth - h - 10) / (int) 2; g2.setColor(Color.RED); g2.fillRect(rx, ry, 10, 10); } Color prevBkg = g2.getBackground(); if (isSelected) { g2.setBackground(Color.BLUE); } else { g2.setBackground(this.getBackground()); } Font attrFont = new Font("Arial", Font.PLAIN, 10); FontRenderContext frc = g2.getFontRenderContext(); if (showDate && photo.getShootTime() != null) { FuzzyDate fd = new FuzzyDate(photo.getShootTime(), photo.getTimeAccuracy()); String dateStr = fd.format(); TextLayout txt = new TextLayout(dateStr, attrFont, frc); // Calculate the position for the text Rectangle2D bounds = txt.getBounds(); int xpos = startx + ((int) (columnWidth - bounds.getWidth())) / 2 - (int) bounds.getMinX(); g2.clearRect(xpos - 2, ypos - 2, (int) bounds.getWidth() + 4, (int) bounds.getHeight() + 4); txt.draw(g2, xpos, (int) (ypos + bounds.getHeight())); ypos += bounds.getHeight() + 4; } String shootPlace = photo.getShootingPlace(); if (showPlace && shootPlace != null && shootPlace.length() > 0) { TextLayout txt = new TextLayout(photo.getShootingPlace(), attrFont, frc); // Calculate the position for the text Rectangle2D bounds = txt.getBounds(); int xpos = startx + ((int) (columnWidth - bounds.getWidth())) / 2 - (int) bounds.getMinX(); g2.clearRect(xpos - 2, ypos - 2, (int) bounds.getWidth() + 4, (int) bounds.getHeight() + 4); txt.draw(g2, xpos, (int) (ypos + bounds.getHeight())); ypos += bounds.getHeight() + 4; } g2.setBackground(prevBkg); } endTime = System.currentTimeMillis(); log.debug("paintThumbnail: exit " + photo.getUuid()); log.debug("Thumb fetch " + (thumbReadyTime - startTime) + " ms"); log.debug("Thumb draw " + (thumbDrawnTime - thumbReadyTime) + " ms"); log.debug("Deacoration draw " + (endTime - thumbDrawnTime) + " ms"); log.debug("Total " + (endTime - startTime) + " ms"); }
From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.//w w w . j a v a 2 s . c o m * @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 item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ 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 (!getItemVisible(series, item)) { return; } XYAreaRendererState areaState = (XYAreaRendererState) state; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { y1 = 0.0; } double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge()); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... int itemCount = dataset.getItemCount(series); double x0 = dataset.getXValue(series, Math.max(item - 1, 0)); double y0 = dataset.getYValue(series, Math.max(item - 1, 0)); if (Double.isNaN(y0)) { y0 = 0.0; } double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge()); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge()); double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1)); double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1)); if (Double.isNaN(y2)) { y2 = 0.0; } double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge()); double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge()); double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); Polygon hotspot = null; if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { hotspot = new Polygon(); hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0)); hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0)); hotspot.addPoint((int) transY1, (int) transX1); hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0)); hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0)); } else { // vertical orientation hotspot = new Polygon(); hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero); hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0)); hotspot.addPoint((int) transX1, (int) transY1); hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0)); hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero); } if (item == 0) { // create a new area polygon for the series areaState.area = new Polygon(); // the first point is (x, 0) double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.area.addPoint((int) transX1, (int) zero); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.area.addPoint((int) zero, (int) transX1); } } // Add each point to Area (x, y) if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.area.addPoint((int) transX1, (int) transY1); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.area.addPoint((int) transY1, (int) transX1); } PlotOrientation orientation = plot.getOrientation(); Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(stroke); Shape shape = null; if (getPlotShapes()) { shape = getItemShape(series, item); if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } else if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } g2.draw(shape); } if (getPlotLines()) { if (item > 0) { if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.line.setLine(transX0, transY0, transX1, transY1); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.line.setLine(transY0, transX0, transY1, transX1); } g2.draw(areaState.line); } } // Check if the item is the last item for the series. // and number of items > 0. We can't draw an area for a single point. if (getPlotArea() && item > 0 && item == (itemCount - 1)) { if (orientation == PlotOrientation.VERTICAL) { // Add the last point (x,0) areaState.area.addPoint((int) transX1, (int) transZero); } else if (orientation == PlotOrientation.HORIZONTAL) { // Add the last point (x,0) areaState.area.addPoint((int) transZero, (int) transX1); } Paint fillPaint = getItemFillPaint(series, item); if (fillPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) fillPaint; GradientPaintTransformer t = new StandardGradientPaintTransformer(); fillPaint = t.transform(gp, areaState.area.getBounds()); } g2.setPaint(fillPaint); g2.fill(areaState.area); // draw an outline around the Area. if (isOutline()) { g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(areaState.area); } } updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation); // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null && hotspot != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url); entities.add(entity); } } }
From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java
/** * Draws the tasks/subtasks for one item. * /*www. j a va 2s .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 drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) { int count = dataset.getSubIntervalCount(row, column); if (count == 0 && getItemVisible(row, column)) { drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column); } for (int subinterval = 0; subinterval < count; subinterval++) { RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // value 0 Number value0 = dataset.getStartValue(row, column, subinterval); if (value0 == null) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // value 1 Number value1 = dataset.getEndValue(row, column, subinterval); if (value1 == null) { return; } double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (translatedValue1 < translatedValue0) { double temp = translatedValue1; translatedValue1 = translatedValue0; translatedValue0 = temp; } double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row, column); double rectLength = Math.abs(translatedValue1 - translatedValue0); double rectBreadth = state.getBarWidth(); // DRAW THE BARS... Rectangle2D bar = null; if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth); } else if (plot.getOrientation() == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(rectStart, translatedValue0, rectBreadth, rectLength); } Rectangle2D completeBar = null; Rectangle2D incompleteBar = null; Number percent = dataset.getPercentComplete(row, column, subinterval); double start = getStartPercent(); double end = getEndPercent(); if (percent != null) { double p = percent.doubleValue(); if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { completeBar = new Rectangle2D.Double(translatedValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start)); incompleteBar = new Rectangle2D.Double(translatedValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start)); } else if (plot.getOrientation() == PlotOrientation.VERTICAL) { completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, translatedValue0 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p); incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, translatedValue0, rectBreadth * (end - start), rectLength * (1 - p)); } } Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (getToolTipGenerator(row, column) != null) { tip = getToolTipGenerator(row, column).generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } } }
From source file:spinworld.gui.RadarPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer)./*from w w w . j a va 2 s. c om*/ * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { int seriesCount = 0, catCount = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { seriesCount = this.dataset.getRowCount(); catCount = this.dataset.getColumnCount(); } else { seriesCount = this.dataset.getColumnCount(); catCount = this.dataset.getRowCount(); } // ensure we have origin and maximum value for each axis ensureBoundaryValues(seriesCount, catCount); // Next, setup the plot area // adjust the plot area by the interior spacing value double gapHorizontal = area.getWidth() * getInteriorGap(); double gapVertical = area.getHeight() * getInteriorGap(); double X = area.getX() + gapHorizontal / 2; double Y = area.getY() + gapVertical / 2; double W = area.getWidth() - gapHorizontal; double H = area.getHeight() - gapVertical; double headW = area.getWidth() * this.headPercent; double headH = area.getHeight() * this.headPercent; // make the chart area a square double min = Math.min(W, H) / 2; X = (X + X + W) / 2 - min; Y = (Y + Y + H) / 2 - min; W = 2 * min; H = 2 * min; Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2); Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H); // draw the axis and category label for (int cat = 0; cat < catCount; cat++) { double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); Point2D endPoint = getWebPoint(radarArea, angle, 1); // 1 = end of axis Line2D line = new Line2D.Double(centre, endPoint); g2.setPaint(this.axisLinePaint); g2.setStroke(this.axisLineStroke); g2.draw(line); if (isAxisTickVisible()) { drawTicks(g2, radarArea, angle, cat); } drawLabel(g2, area, radarArea, 0.0, cat, angle, 360.0 / catCount); } // Now actually plot each of the series polygons.. for (int series = 0; series < seriesCount; series++) { drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW); } } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, area); }
From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java
@Override public void paintComponent(final Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 0;/* w w w . ja v a 2 s.c o m*/ int y = 0; int width = (int) getSize().getWidth(); int height = (int) getSize().getHeight(); // draw background depending special roles and hovering if (getModel() != null && getModel().isSpecialAtt()) { if (Attributes.LABEL_NAME.equals(getModel().getSpecialAttName())) { // label special attributes have a distinct color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.LABEL_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.LABEL_NAME, false, hovered))); } else if (Attributes.WEIGHT_NAME.equals(getModel().getSpecialAttName())) { // weight special attributes have another distinct color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, false, hovered))); } else if (Attributes.PREDICTION_NAME.equals(getModel().getSpecialAttName())) { // prediction special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.PREDICTION_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.PREDICTION_NAME, false, hovered))); } else if (getModel().getSpecialAttName().startsWith(Attributes.CONFIDENCE_NAME + "_")) { // confidence special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, false, hovered))); } else if (Attributes.ID_NAME.equals(getModel().getSpecialAttName())) { // id special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ID_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.ID_NAME, false, hovered))); } else { // other special attributes have another color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, true, hovered), x, height, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, false, hovered))); } } else { // regular attributes g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, false, hovered))); } g2.fillRoundRect(x, y, width, height, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH); // draw border g2.setPaint(new GradientPaint(x, y, COLOR_BORDER_GRADIENT_FIRST, x, height, COLOR_BORDER_GRADIENT_SECOND)); if (hovered) { g2.setStroke(new BasicStroke(1.0f)); } else { g2.setStroke(new BasicStroke(0.5f)); } g2.drawRoundRect(x, y, width - 1, height - 1, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH); // let Swing draw its components super.paintComponent(g2); }
From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java
/** * Draws the bar for a single (series, category) data item. * /*from w w w . ja v a 2s . c o m*/ * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge); // in the following code, barL0 is (in Java2D coordinates) the LEFT // end of the bar for a horizontal bar chart, and the TOP end of the // bar for a vertical bar chart. Whether this is the BASE of the bar // or not depends also on (a) whether the data value is 'negative' // relative to the base value and (b) whether or not the range axis is // inverted. This only matters if/when we apply the minimumBarLength // attribute, because we should extend the non-base end of the bar boolean positive = (value >= this.base); boolean inverted = rangeAxis.isInverted(); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); double barLengthAdj = 0.0; if (barLength > 0.0 && barLength < getMinimumBarLength()) { barLengthAdj = getMinimumBarLength() - barLength; } double barL0Adj = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { if (positive && inverted || !positive && !inverted) { barL0Adj = barLengthAdj; } } else { if (positive && !inverted || !positive && inverted) { barL0Adj = barLengthAdj; } } // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj); } Paint itemPaint = getItemPaint(row, column); if (dataset.getValue(row, column).doubleValue() >= 0) { itemPaint = Color.red; } else { itemPaint = Color.GREEN; } GradientPaintTransformer t = getGradientPaintTransformer(); if (t != null && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); // draw the outline... if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (dataset.getValue(row, column).doubleValue() >= 0) { paint = Color.red; } else { paint = Color.green; } if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:spinworld.gui.RadarPlot.java
/** * Draws a radar plot polygon./*www.j a v a 2 s . co m*/ * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon double _maxValue = getMaxValue(cat).doubleValue(); double _origin = getOrigin(cat).doubleValue(); double lowerBound = Math.min(_origin, _maxValue); double upperBound = Math.max(_origin, _maxValue); boolean lesser = value < lowerBound; boolean greater = value > upperBound; if ((lesser || greater) && !drawOutOfRangePoints) { continue; } if (lesser) { value = lowerBound; } if (greater) { value = upperBound; } double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound); if (_maxValue < _origin) { // inversed length = 1 - length; } Point2D point = getWebPoint(plotArea, angle, length); polygon.addPoint((int) point.getX(), (int) point.getY()); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); double px = point.getX(); double py = point.getY(); g2.setPaint(paint); if (lesser || greater) { // user crosshair for out-of-range data points distinguish g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); double delta = 3; g2.draw(new Line2D.Double(px - delta, py, px + delta, py)); g2.draw(new Line2D.Double(px, py - delta, px, py + delta)); } else { // put an elipse at the point being plotted.. Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH); g2.fill(head); g2.setStroke(getHeadOutlineStroke(series)); g2.setPaint(outlinePaint); g2.draw(head); } if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;/*www . ja v a 2 s . c o m*/ } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java
@Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;//from w w w.j a v a2s . co m } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java
/** * Draws a single task./* ww w.jav a 2 s .c om*/ * * @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, GanttCategoryDataset dataset, int row, int column) { PlotOrientation orientation = plot.getOrientation(); 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; } // count the number of non-null values int totalBars = countNonNullValues(dataset, column); if (totalBars == 0) { return; } // count non-null values up to but not including the current value int priorBars = countPriorNonNullValues(dataset, column, row); // double rectStart = calculateBarW0(plot, orientation, dataArea, // domainAxis, state, row, column); // double rectBreadth = state.getBarWidth(); double rectBreadth = (domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())) / totalBars; double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) + rectBreadth * priorBars; double rectLength = Math.abs(java2dValue1 - java2dValue0); Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth); } else if (orientation == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength); } 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(); if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { 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)); } else if (plot.getOrientation() == PlotOrientation.VERTICAL) { completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p); incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p)); } } Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } // draw the outline... if (isDrawBarOutline() && 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); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, false); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }