List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:extern.NpairsBoxAndWhiskerRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a vertical orientation./*from ww w . jav a 2 s .c om*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @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 (must be an instance of * {@link BoxAndWhiskerCategoryDataset}). * @param row the row index (zero-based). * @param column the column index (zero-based). */ public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); double widthToUse = Math.min(state.getBarWidth(), dataArea.getWidth() / 15); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (widthToUse * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; xx = xx + offset + (row * (widthToUse + seriesGap)); } else { // offset the start of the box if the box width is smaller than the // category width double offset = (categoryWidth - widthToUse) / 2; xx = xx + offset; } double yyAverage = 0.0; double yyOutlier; Paint itemPaint = getItemPaint(row, column); g2.setPaint(itemPaint); Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = plot.getRangeAxisEdge(); Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); Shape box = null; double xxmid = xx + widthToUse / 2.0; if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) { double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location); double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location); double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location); double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location); // draw the upper shadow... g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + widthToUse, yyMax)); // draw the lower shadow... g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + widthToUse, yyMin)); // draw the body... box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), widthToUse, Math.abs(yyQ1 - yyQ3)); if (this.fillBox) { g2.fill(box); } g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(box); } g2.setPaint(this.artifactPaint); // draw mean - SPECIAL AIMS REQUIREMENT... Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null && !Double.isNaN(yMean.doubleValue())) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); // THIS IS WHAT WE CHANGED // aRadius = widthWeWannaUse / 4; aRadius = 4; // here we check that the average marker will in fact be visible // before drawing it... // WE HAD TO CHANGE THIS TOO I DON'T KNOW WHAT THEY WERE DOING if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) { Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxmid - aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } } // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null && !Double.isNaN(yMedian.doubleValue())) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + widthToUse, yyMedian)); // add a line to connect the means of the boxes if (prevX != -1.0 && prevY != -1.0) { g2.draw(new Line2D.Double(prevX, prevY, xxmid, yyMedian)); } prevX = xxmid; prevY = yyMedian; } // draw yOutliers... g2.setPaint(itemPaint); // draw outliers double oRadius = 4; // outlier radius List<Outlier> outliers = new ArrayList<Outlier>(); // From outlier array sort out which are outliers and put these into a // list If there are any farouts, set the flag on the // OutlierListCollection List<Number> yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { double outlier = yOutliers.get(i).doubleValue(); yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xxmid, yyOutlier, oRadius)); } // Process outliers. Each outlier is either added to the // appropriate outlier list or a new outlier list is made for (Outlier outlier : outliers) { Point2D point = outlier.getPoint(); drawEllipse(point, oRadius, g2); } // for (Iterator iterator = outlierListCollection.iterator(); // iterator.hasNext();) { // OutlierList list = (OutlierList) iterator.next(); // Outlier outlier = list.getAveragedOutlier(); // Point2D point = outlier.getPoint(); // // if (list.isMultiple()) { // drawMultipleEllipse(point, widthWeWannaUse, oRadius, // g2); // } // else { // drawEllipse(point, oRadius, g2); // } // } // // // draw farout indicators // if (outlierListCollection.isHighFarOut()) { // drawHighFarOut(aRadius / 2.0, g2, // xx + widthWeWannaUse / 2.0, maxAxisValue); // } // // if (outlierListCollection.isLowFarOut()) { // drawLowFarOut(aRadius / 2.0, g2, // xx + widthWeWannaUse / 2.0, minAxisValue); // } // } // // collect entity and tool tip information... // if (state.getInfo() != null && box != null) { // EntityCollection entities = state.getEntityCollection(); // if (entities != null) { // addItemEntity(entities, dataset, row, column, box); // } } }
From source file:org.pmedv.blackboard.components.BoardEditor.java
@Override protected void paintComponent(Graphics g) { Boolean useLayerColor = (Boolean) Preferences.values .get("org.pmedv.blackboard.BoardDesignerPerspective.useLayerColor"); // clear all // g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(BLANK);/* w w w.java 2 s . c om*/ g.fillRect(0, 0, getWidth(), getHeight()); // some nice anti aliasing... Graphics2D g2 = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints(rh); // TODO : Should this be done here? // Sort layers by z-index g2.setColor(Color.LIGHT_GRAY); g2.setStroke(BoardUtil.stroke_1_0f); Collections.sort(model.getLayers()); for (int i = model.getLayers().size() - 1; i >= 0; i--) { // Sort items by z-index Collections.sort(model.getLayers().get(i).getItems()); drawLayer(model.getLayers().get(i), g2); } // draw selection border if (state.equals(SelectionState.DRAGGING_NEW_SELECTION) && button1Pressed) { g2.setColor(Color.GREEN); g2.setStroke(BoardUtil.stroke_1_0f); if (dragStopX < dragStartX && dragStopY > dragStartY) { selectionBorder.setSize(dragStartX - dragStopX, dragStopY - dragStartY); selectionBorder.setLocation(dragStopX, dragStartY); } else if (dragStopY < dragStartY && dragStopX > dragStartX) { selectionBorder.setSize(dragStopX - dragStartX, dragStartY - dragStopY); selectionBorder.setLocation(dragStartX, dragStopY); } else if (dragStopX < dragStartX && dragStopY < dragStartY) { selectionBorder.setSize(dragStartX - dragStopX, dragStartY - dragStopY); selectionBorder.setLocation(dragStopX, dragStopY); } else { selectionBorder.setSize(dragStopX - dragStartX, dragStopY - dragStartY); selectionBorder.setLocation(dragStartX, dragStartY); } g2.draw(selectionBorder); } // display shape currently being drawed if (lineStartX > 0 && lineStartY > 0 && lineStopX > 0 && lineStopY > 0) { if (useLayerColor) g2.setColor(model.getCurrentLayer().getColor()); else g2.setColor(palette.getCurrentColor()); g2.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem()); // draw new line if (editorMode.equals(EditorMode.DRAW_LINE)) { if (useLayerColor) currentDrawingLine.setColor(model.getCurrentLayer().getColor()); else currentDrawingLine.setColor(palette.getCurrentColor()); currentDrawingLine.setStartType((LineEdgeType) shapesPanel.getStartLineCombo().getSelectedItem()); currentDrawingLine.setEndType((LineEdgeType) shapesPanel.getEndLineCombo().getSelectedItem()); currentDrawingLine.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem()); currentDrawingLine.getStart().setLocation(lineStartX, lineStartY); currentDrawingLine.getEnd().setLocation(lineStopX, lineStopY); currentDrawingLine.draw(g2); } else if (editorMode.equals(EditorMode.DRAW_MEASURE)) { currentDrawingLine.setStroke(Measure.DEFAULT_STROKE); currentDrawingLine.getStart().setLocation(lineStartX, lineStartY); currentDrawingLine.getEnd().setLocation(lineStopX, lineStopY); currentDrawingLine.draw(g2); } // draw new box or ellipse else if (editorMode.equals(EditorMode.DRAW_RECTANGLE) || editorMode.equals(EditorMode.DRAW_ELLIPSE)) { int xLoc = lineStartX; int yLoc = lineStartY; int width = lineStopX - lineStartX; int height = lineStopY - lineStartY; ShapeStyle style = (ShapeStyle) shapesPanel.getStyleCombo().getSelectedItem(); if (style == null || style.equals(ShapeStyle.FILLED)) { if (editorMode.equals(EditorMode.DRAW_RECTANGLE)) { g2.fillRect(xLoc, yLoc, width, height); } else { g2.fillOval(xLoc, yLoc, width, height); } } else if (style.equals(ShapeStyle.OUTLINED)) { g2.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem()); if (editorMode.equals(EditorMode.DRAW_RECTANGLE)) { g2.drawRect(xLoc, yLoc, width, height); } else { g2.drawOval(xLoc, yLoc, width, height); } } } } // draw selection handles if (selectedItem != null) { g2.setStroke(BoardUtil.stroke_1_0f); g2.setColor(Color.GREEN); selectedItem.drawHandles(g2, 8); } // draw border if (zoomLayer != null) { TransformUI ui = (TransformUI) (Object) zoomLayer.getUI(); DefaultTransformModel xmodel = (DefaultTransformModel) ui.getModel(); if (xmodel.isMirror()) { g2.setColor(Color.RED); } else { g2.setColor(Color.GREEN); } } else { g2.setColor(Color.GREEN); } g2.setStroke(DEFAULT_STROKE); Rectangle border = new Rectangle(0, 0, model.getWidth() - 1, model.getHeight() - 1); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.draw(border); if (model.getType().equals(BoardType.STRIPES) || model.getType().equals(BoardType.HOLES)) { g2.setColor(Color.BLACK); g2.setFont(miniFont); int index = 1; for (int x = 12; x < model.getWidth() - 16; x += 16) { g2.drawString(String.valueOf(index++), x, 8); } index = 1; for (int y = 18; y < model.getHeight(); y += 16) { g2.drawString(String.valueOf(index++), 3, y); } } if (editorMode.equals(EditorMode.CHECK_CONNECTIONS)) { if (connectedLines != null) { for (Line line : connectedLines) { line.drawFat(g2); } } } if (drawing) { g2.setColor(Color.BLUE); g2.setStroke(DEFAULT_STROKE); if (selectedPin != null) { g2.drawRect(lineStopX - 8, lineStopY - 8, 16, 16); } } super.paintComponents(g2); }
From source file:anl.verdi.plot.jfree.XYBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state./*from www .j ava 2s .c om*/ * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @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) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; double max = paintScale.getUpperBound(); double min = paintScale.getLowerBound(); if (dataset instanceof XYZDataset) z = ((XYZDataset) dataset).getZValue(series, item); //NOTE: so to get the max/min color instead of unknown (Qun He, UNC, 03/19/2009) if (z > max) z = max; if (z < min) z = min; Color p = (Color) this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setColor(p); g2.fill(block); if (gridLinesEnabled) { boolean aaOn = false; if (g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); aaOn = true; } g2.setPaint(gridLineColor); g2.setStroke(gridLineStroke); g2.draw(block); if (aaOn) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else { g2.setStroke(basicStroke); g2.draw(block); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedScatterRenderer.java
/** * This function is taken directly from JFreeChart with adjustments to draw differently colored * items./* ww w . j ava2s .c o m*/ * * When updating JFreeChart this function must probably be adapted. * */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } int visibleRow = state.getVisibleSeriesIndex(row); if (visibleRow < 0) { return; } int visibleRowCount = state.getVisibleSeriesCount(); PlotOrientation orientation = plot.getOrientation(); ValueSourceToMultiValueCategoryDatasetAdapter dataSet = (ValueSourceToMultiValueCategoryDatasetAdapter) dataset; List values = dataSet.getValues(row, column); if (values == null) { return; } int valueCount = values.size(); for (int i = 0; i < valueCount; i++) { // current data point... double x1; if (getUseSeriesOffset()) { x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge()); } else { x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); } Number n = (Number) values.get(i); int idx = dataSet.getValueIndex(row, column, i); double value = n.doubleValue(); double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); Shape shape = getItemShape(row, idx); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); } if (getItemShapeFilled(row, column)) { if (getUseFillPaint()) { g2.setPaint(getItemFillPaint(row, column)); } else { g2.setPaint(getItemPaint(row, idx)); } g2.fill(shape); } if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(row, column)); } else { g2.setPaint(getItemPaint(row, idx)); } g2.setStroke(getItemOutlineStroke(row, column)); g2.draw(shape); } } }
From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java
/** * Draws a stacked bar for a specific item. * * @param g2 the graphics device.// w w w . j a v a2 s .c om * @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 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(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 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; double positiveBase = 0.0; double negativeBase = 0.0; for (int i = 0; i < row; i++) { Number v = dataset.getValue(i, column); if (v != null) { double d = v.doubleValue(); if (d > 0) { positiveBase = positiveBase + d; } else { negativeBase = negativeBase + d; } } } double translatedBase; double translatedValue; RectangleEdge location = plot.getRangeAxisEdge(); if (value > 0.0) { translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location); } else { translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location); } double barL0 = Math.min(translatedBase, translatedValue); double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength()); 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 seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); 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)); } if (value > 0.0) { if (this.showPositiveTotal) { if (isLastPositiveItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfPositiveValuesForCategory(dataset, column); TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER); } } } else { if (this.showNegativeTotal) { if (isLastNegativeItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfNegativeValuesForCategory(dataset, column); TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(), (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER); } } } // 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); } } }
From source file:org.jstockchart.axis.TimeseriesDateAxis.java
protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge) { AxisState state = new AxisState(cursor); if (isAxisLineVisible()) { drawAxisLine(g2, cursor, dataArea, edge); }// w w w. j a va 2s. c o m List ticks = refreshTicks(g2, state, dataArea, edge); state.setTicks(ticks); g2.setFont(getTickLabelFont()); Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); if (isTickLabelsVisible()) { g2.setPaint(getTickLabelPaint()); float[] anchorPoint = calculateAnchorPoint(tick, cursor, dataArea, edge); //System.out.println("label:"+tick.getText()); String tickLabel = tick.getText(); if (tickLabel == "13:00") { TextUtilities.drawRotatedString("/", g2, anchorPoint[0] - 2, anchorPoint[1], tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor()); } if (hideTickLabel != null) { if (!hideTickLabel.contains(tickLabel)) { TextUtilities.drawRotatedString(tickLabel, g2, anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor()); } } else { TextUtilities.drawRotatedString(tick.getText(), g2, anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor()); } } if ((isTickMarksVisible() && tick.getTickType().equals(TickType.MAJOR)) || (isMinorTickMarksVisible() && tick.getTickType().equals(TickType.MINOR))) { double ol = (tick.getTickType().equals(TickType.MINOR)) ? getMinorTickMarkOutsideLength() : getTickMarkOutsideLength(); double il = (tick.getTickType().equals(TickType.MINOR)) ? getMinorTickMarkInsideLength() : getTickMarkInsideLength(); float xx = (float) valueToJava2D(tick.getValue(), dataArea, edge); Line2D mark = null; g2.setStroke(getTickMarkStroke()); g2.setPaint(getTickMarkPaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx); } else if (edge == RectangleEdge.RIGHT) { mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx); } else if (edge == RectangleEdge.TOP) { mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il); } else if (edge == RectangleEdge.BOTTOM) { mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il); } g2.draw(mark); } } // need to work out the space used by the tick labels... // so we can update the cursor... double used = 0.0; if (isTickLabelsVisible()) { if (edge == RectangleEdge.LEFT) { used += findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorLeft(used); } else if (edge == RectangleEdge.RIGHT) { used = findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorRight(used); } else if (edge == RectangleEdge.TOP) { used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorUp(used); } else if (edge == RectangleEdge.BOTTOM) { used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorDown(used); } } return state; }
From source file:edu.ucla.stat.SOCR.chart.gui.ExtendedStackedBarRenderer.java
/** * Draws a stacked bar for a specific item. * * @param g2 the graphics device.//from w ww . ja v a2 s . c om * @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 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(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 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; double positiveBase = 0.0; double negativeBase = 0.0; for (int i = 0; i < row; i++) { Number v = dataset.getValue(i, column); if (v != null) { double d = v.doubleValue(); if (d > 0) { positiveBase = positiveBase + d; } else { negativeBase = negativeBase + d; } } } double translatedBase; double translatedValue; RectangleEdge location = plot.getRangeAxisEdge(); if (value > 0.0) { translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location); } else { translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location); translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location); } double barL0 = Math.min(translatedBase, translatedValue); double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength()); 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 seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); 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)); } if (value > 0.0) { if (this.showPositiveTotal) { if (isLastPositiveItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfPositiveValuesForCategory(dataset, column); if (orientation == PlotOrientation.HORIZONTAL) TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) (bar.getMaxX() + 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_LEFT, 0.0, TextAnchor.CENTER_LEFT); else TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER); } } } else { if (this.showNegativeTotal) { if (isLastNegativeItem(dataset, row, column)) { g2.setPaint(Color.black); g2.setFont(this.totalLabelFont); double total = calculateSumOfNegativeValuesForCategory(dataset, column); if (orientation == PlotOrientation.HORIZONTAL) TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) (bar.getMinX() - 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_RIGHT, 0.0, TextAnchor.CENTER_RIGHT); else TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(), (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER); } } } // 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, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:extern.PlotBySplitClassRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a vertical orientation./* w w w. j a va 2 s. c o m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @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 (must be an instance of * {@link BoxAndWhiskerCategoryDataset}). * @param row the row index (zero-based). * @param column the column index (zero-based). */ public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { if (lastSplitObj != column) { lastSplitObj = column; prevX = -1; prevY = -1; } BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); double widthToUse = Math.min(state.getBarWidth(), dataArea.getWidth() / 15); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (widthToUse * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; xx = xx + offset + (row * (widthToUse + seriesGap)); } else { // offset the start of the box if the box width is smaller than the // category width double offset = (categoryWidth - widthToUse) / 2; xx = xx + offset; } double yyAverage = 0.0; double yyOutlier; Paint itemPaint = getItemPaint(row, column); g2.setPaint(itemPaint); Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = plot.getRangeAxisEdge(); Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); Shape box = null; double xxmid = xx + widthToUse / 2.0; double yyQ1 = 0; double yyQ3 = 0; if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) { yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location); yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location); double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location); double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location); // draw the upper shadow... g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + widthToUse, yyMax)); // draw the lower shadow... g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + widthToUse, yyMin)); // draw the body... box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), widthToUse, Math.abs(yyQ1 - yyQ3)); if (this.fillBox) { g2.fill(box); } g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(box); } g2.setPaint(this.artifactPaint); // draw mean - SPECIAL AIMS REQUIREMENT... Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null && !Double.isNaN(yMean.doubleValue())) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); // THIS IS WHAT WE CHANGED // aRadius = widthWeWannaUse / 4; aRadius = 4; // here we check that the average marker will in fact be visible // before drawing it... // WE HAD TO CHANGE THIS TOO I DON'T KNOW WHAT THEY WERE DOING if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) { Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxmid - aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2); //If this is a single point only, then draw this point with //the color of its class. if (yQ1 != null && yQ3 != null) { if (aRadius / 2 > Math.abs(yyQ3 - yyQ1)) { g2.setPaint(itemPaint); } } g2.fill(avgEllipse); g2.draw(avgEllipse); } } // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null && !Double.isNaN(yMedian.doubleValue())) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + widthToUse, yyMedian)); // add a line to connect the means of the boxes if (prevX != -1 && prevY != -1) { g2.setPaint(artifactPaint); g2.draw(new Line2D.Double(prevX, prevY, xxmid, yyMedian)); } prevX = xxmid; prevY = yyMedian; } // draw yOutliers... g2.setPaint(itemPaint); // draw outliers double oRadius = 4; // outlier radius List<Outlier> outliers = new ArrayList<Outlier>(); // From outlier array sort out which are outliers and put these into a // list If there are any farouts, set the flag on the // OutlierListCollection List<Number> yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { double outlier = yOutliers.get(i).doubleValue(); yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xxmid, yyOutlier, oRadius)); } // Process outliers. Each outlier is either added to the // appropriate outlier list or a new outlier list is made for (Outlier outlier : outliers) { Point2D point = outlier.getPoint(); drawEllipse(point, oRadius, g2); } } }
From source file:org.osjava.reportrunner_plugins.renderers.jfreechart.creators.TexturedBarRenderer.java
public java.awt.Paint getSeriesPaint(int row) { BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bufferedImage.createGraphics(); TexturePaint texture = null;//w w w .j ava 2 s .c o m int rowNum = row + 1; int patNum = 13; int formula = rowNum - ((rowNum / patNum) * patNum); if (formula == 0) { big.setColor(Color.orange); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 1) { big.setColor(Color.red); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 2) { Color color = Color.blue; big.setColor(Color.white); big.fillRect(0, 0, 5, 5); big.setColor(color); big.fillRect(0, 1, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 3) { Color color = Color.yellow; big.setColor(Color.orange); big.fillRect(0, 0, 5, 5); big.setColor(color); big.fillRect(1, 1, 4, 4); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 4) { big.setColor(Color.green); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 5) { big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.pink); big.fillRect(0, 0, 4, 4); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 6) { float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[0]); for (int j = 1; j < x.length; j++) { path.lineTo(x[j], y[j]); } big.setColor(new Color(226, 199, 252)); big.fillRect(0, 0, 5, 5); big.setColor(Color.blue); big.setStroke(new BasicStroke(1.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 7) { big.setColor(Color.lightGray); big.fillRect(0, 0, 5, 5); big.setColor(Color.red); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 8) { float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[0]); for (int j = 1; j < x.length; j++) { path.lineTo(x[j], y[j]); } big.setColor(Color.blue); big.fillRect(0, 0, 5, 5); big.setColor(Color.cyan); big.setStroke(new BasicStroke(2.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 9) { Color color = new Color(0xBBBBDD); big.setColor(color); big.fillRect(0, 0, 5, 5); big.setColor(new Color(199, 201, 230)); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 10) { float[] x = { 1, 2, 3, 4, 5 }; float[] y = { 1, 2, 3, 4, 5 }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[1]); path.lineTo(x[1], y[0]); path.moveTo(x[0], y[2]); path.lineTo(x[2], y[0]); path.moveTo(x[0], y[3]); path.lineTo(x[3], y[0]); path.moveTo(x[0], y[4]); path.lineTo(x[4], y[0]); big.setColor(Color.red); big.fillRect(0, 0, 5, 5); big.setColor(new Color(242, 242, 193)); big.setStroke(new BasicStroke(3.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 11) { big.setColor(new Color(252, 169, 171)); big.fillOval(0, 0, 5, 6); big.setColor(new Color(252, 230, 230)); big.fillOval(0, 0, 3, 3); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 12) { big.setColor(Color.green); big.fillRect(0, 0, 5, 5); big.setColor(new Color(20, 178, 38)); big.fillRect(2, 2, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } return texture; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param g2d// w ww . j av a2 s. co m * @param color * @param x * @param y * @param w * @param h * @param arcSizeW * @param arcSizeH */ public static void drawRoundedRect(final Graphics2D g2d, final Color color, final int x, final int y, final int w, final int h, final int arcSizeW, final int arcSizeH) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setStroke(UIHelper.getStdLineStroke()); g2d.setColor(color); g2d.drawRoundRect(x, y, w, h, arcSizeW, arcSizeH); }