List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:dk.sdu.mmmi.featureous.views.codecharacterization.TanglingViewChart.java
public TanglingViewChart(boolean pkg, boolean sortByValue) { this.sortByValue = sortByValue; this.pkg = pkg; data = new DefaultKeyedValues2DDataset(); String title = "Computational unit characterization"; jchart = ChartFactory.createStackedBarChart(title, (pkg) ? "Package" : "Class", "Tangling", data, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) jchart.getPlot(); // chart.getLegend().setPosition(RectangleEdge.RIGHT); // chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); // chart.getLegend().setHorizontalAlignment(HorizontalAlignment.LEFT); LegendItemCollection lic = new LegendItemCollection(); // lic.add(new LegendItem("Infrastructural unit", "", "", "", new Rectangle(10, 10), Color.GREEN)); // lic.add(new LegendItem("Group-feature unit", "", "", "", new Rectangle(10, 10), Color.BLUE)); // lic.add(new LegendItem("Single-feature unit", "", "", "", new Rectangle(10, 10), Color.RED)); plot.setFixedLegendItems(lic);//w w w . ja v a 2 s .c o m // chart.removeLegend(); plot.setDomainAxis(new SparselyLabeledCategoryAxis(20)); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); xAxis.setLabel((pkg) ? "Package" : "Class"); // xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 5, 5)); // xAxis.setMaximumCategoryLabelLines(1); xAxis.setLowerMargin(0); xAxis.setCategoryMargin(0); xAxis.setUpperMargin(0); // xAxis.setMaximumCategoryLabelWidthRatio(20f); jchart.setBackgroundPaint(Color.white); StackedBarRenderer renderer = new StackedBarRenderer() { @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); double start = plot.getDomainAxis().getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double end = plot.getDomainAxis().getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); String compUnit = data.getRowKey(row).toString(); // Calculate y coeffs double posBase = getBase(); // for(int i = 0; i<row; i++){ // Number val = dataset.getValue(i, column); // if(val!=null){ // posBase = posBase + val.doubleValue(); // } // } Number value = dataset.getValue(row, column); if (value == null) { return; } double val = value.doubleValue(); double translatedBase = plot.getRangeAxis().valueToJava2D(posBase, dataArea, plot.getRangeAxisEdge()); double translatedValue = plot.getRangeAxis().valueToJava2D(posBase + val, dataArea, plot.getRangeAxisEdge()); if (Controller.getInstance().getTraceSet().getSelectionManager().getSelectedClasses() .contains(compUnit) || Controller.getInstance().getTraceSet().getSelectionManager().getSelectedPkgs() .contains(compUnit)) { g2.setPaint(UIUtils.SELECTION_COLOR); g2.setStroke(new BasicStroke(3f)); Line2D l2d = new Line2D.Double(start, translatedBase, start, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(end, translatedBase, end, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(start, translatedBase, end, translatedBase); g2.draw(l2d); l2d = new Line2D.Double(start, translatedValue, end, translatedValue); g2.draw(l2d); } } }; renderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset cd, int i, int i1) { String key = data.getRowKey(i).toString(); // key = key.substring(0, key.length()-1); return "<html>" + i + " - " + key + "<br>" + Double.toString(cd.getValue(i, i1).doubleValue()) + "</hmtl>"; } }); plot.setRenderer(renderer); panel = new ChartPanel(jchart); panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel)); createView(); Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this); }
From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalLineAndShapeRenderer.java
/** * Draw a single data item./*from w w w . j a v a 2 s . c o m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area in which the data is drawn. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset (a {@link StatisticalCategoryDataset} is required). * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass. */ @Override 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) { // nothing is drawn for null... final Number v = dataset.getValue(row, column); if (v == null) { return; } // *************** This line was changed relative to StatisticalLineAndShapeRenderer***** final AsymmetricStatisticalCategoryDataset statData = (AsymmetricStatisticalCategoryDataset) dataset; // *************** end of changed line ********************************************** final Number meanValue = statData.getMeanValue(row, column); final PlotOrientation orientation = plot.getOrientation(); // current data point... final double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); final double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge()); Shape shape = getItemShape(row, column); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); } if (getItemShapeVisible(row, column)) { if (getItemShapeFilled(row, column)) { g2.setPaint(getItemPaint(row, column)); g2.fill(shape); } else { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.setStroke(getItemOutlineStroke(row, column)); g2.draw(shape); } } if (getItemLineVisible(row, column)) { if (column != 0) { final Number previousValue = statData.getValue(row, column - 1); if (previousValue != null) { // previous data point... final double previous = previousValue.doubleValue(); final double x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge()); final double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(y0, x0, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(x0, y0, x1, y1); } g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.draw(line); } } } final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); rectX = rectX + row * state.getBarWidth(); g2.setPaint(getItemPaint(row, column)); // ************* This is the block with changes relative to StatisticalLineAndShapeRenderer ********* // standard deviation lines final Number highValObj = statData.getUpperValue(row, column); final Number lowValObj = statData.getLowerValue(row, column); if (highValObj != null && lowValObj != null) { // rinke added this test double highVal = highValObj.doubleValue(); double lowVal = lowValObj.doubleValue(); if (highVal > rangeAxis.getRange().getUpperBound()) { highVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation); } else { highVal = rangeAxis.valueToJava2D(highVal, dataArea, yAxisLocation); } if (lowVal < rangeAxis.getRange().getLowerBound()) { lowVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation); } else { lowVal = rangeAxis.valueToJava2D(lowVal, dataArea, yAxisLocation); } // ****************** end of changed block ********************************** if (errorIndicatorPaint != null) { g2.setPaint(errorIndicatorPaint); } else { g2.setPaint(getItemPaint(row, column)); } final Line2D line = new Line2D.Double(); if (orientation == PlotOrientation.HORIZONTAL) { line.setLine(lowVal, x1, highVal, x1); g2.draw(line); line.setLine(lowVal, x1 - 5.0d, lowVal, x1 + 5.0d); g2.draw(line); line.setLine(highVal, x1 - 5.0d, highVal, x1 + 5.0d); g2.draw(line); } else { // PlotOrientation.VERTICAL line.setLine(x1, lowVal, x1, highVal); g2.draw(line); line.setLine(x1 - 5.0d, highVal, x1 + 5.0d, highVal); g2.draw(line); line.setLine(x1 - 5.0d, lowVal, x1 + 5.0d, lowVal); g2.draw(line); } } // draw the item label if there is one... if (isItemLabelVisible(row, column)) { if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (meanValue.doubleValue() < 0.0)); } else if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (meanValue.doubleValue() < 0.0)); } } // collect entity and tool tip information... if (state.getInfo() != null) { final EntityCollection entities = state.getEntityCollection(); if (entities != null && shape != null) { String tip = null; final 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); } final CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:org.trade.ui.chart.renderer.HeikinAshiRenderer.java
/** * Method drawItem.//from ww w .j ava2 s. co m * * @param g2 * Graphics2D * @param state * XYItemRendererState * @param dataArea * Rectangle2D * @param info * PlotRenderingInfo * @param plot * XYPlot * @param domainAxis * ValueAxis * @param rangeAxis * ValueAxis * @param dataset * XYDataset * @param series * int * @param item * int * @param crosshairState * CrosshairState * @param pass * int * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D, * XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, * ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int) */ 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 (dataset instanceof HeikinAshiDataset) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } HeikinAshiDataset highLowData = (HeikinAshiDataset) dataset; double x = highLowData.getXValue(series, item); double yHigh = highLowData.getHighValue(series, item); double yLow = highLowData.getLowValue(series, item); double yOpen = highLowData.getOpenValue(series, item); double yClose = highLowData.getCloseValue(series, item); RectangleEdge domainEdge = plot.getDomainAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge); RectangleEdge edge = plot.getRangeAxisEdge(); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge); double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge); double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge); int itemCount = highLowData.getItemCount(series); double xxWidth = dataArea.getWidth() / itemCount; xxWidth -= 2 * this.getAutoWidthGap(); xxWidth *= this.getAutoWidthFactor(); xxWidth = Math.min(xxWidth, this.maxCandleWidth); double stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth); Paint outlinePaint = null; outlinePaint = getItemOutlinePaint(series, item); g2.setStroke(getItemStroke(series, item)); g2.setPaint(outlinePaint); double yyMaxOpenClose = Math.max(yyOpen, yyClose); double yyMinOpenClose = Math.min(yyOpen, yyClose); double maxOpenClose = Math.max(yOpen, yClose); double minOpenClose = Math.min(yOpen, yClose); Shape body = null; boolean highlight = highlight(series, item); /********************************** * draw the upper shadow START **********************************/ if (yHigh > maxOpenClose) { if (highlight) { body = new Rectangle2D.Double(xx - (stickWidth / 2), yyHigh - 10, stickWidth, (yyMaxOpenClose - yyHigh) + 10); g2.setPaint(Color.YELLOW); g2.fill(body); g2.draw(body); } } if (yHigh > maxOpenClose) { if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(Color.black); } g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose)); } /********************************** * draw the lower shadow START **********************************/ if (yLow < minOpenClose) { if (highlight) { body = new Rectangle2D.Double(xx - (stickWidth / 2), yyMinOpenClose, stickWidth, (yyLow - yyMinOpenClose) + 10); g2.setPaint(Color.YELLOW); g2.fill(body); g2.draw(body); } if (yLow < minOpenClose) { if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(Color.BLACK); } g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose)); } } /********************************** * draw the body **********************************/ body = new Rectangle2D.Double(xx - (stickWidth / 2), yyMinOpenClose, stickWidth, yyMaxOpenClose - yyMinOpenClose); if (nightMode) { g2.setPaint(Color.white); } else { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } g2.fill(body); g2.draw(body); if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(outlinePaint); } g2.draw(body); // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(body, dataset, series, item, tip, null); entities.add(entity); } } }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintGrid(final Graphics2D g2d) { if (WorkspaceSettings.getInstance().isShowGrid()) { final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); final double gridSize = getGridSize() * scaleFactor; if (gridSize < 1) { return; }/*from w w w . ja va 2s . c om*/ final int gridDivisions = Math.max(1, getGridDivisions()); final Color primaryColor = WorkspaceSettings.getInstance().getGridColor(); final Color secondaryColor = ColorUtility.convertToBrighter(primaryColor); // draw vertical lines g2d.setStroke(new BasicStroke(.1f)); int horizontalLineCount = 0; final Line2D.Double line = new Line2D.Double(); final double gridHeight = getHeight(); final double gridWidth = getWidth(); for (double w = gridSize; w < gridWidth; w += gridSize) { if (horizontalLineCount % gridDivisions == gridDivisions - 1) { g2d.setColor(primaryColor); } else { g2d.setColor(secondaryColor); } horizontalLineCount++; line.setLine(w, 0, w, gridHeight); g2d.draw(line); } // draw horizontal lines int verticalLineCount = 0; for (double h = gridSize; h < gridHeight; h += gridSize) { if (verticalLineCount % gridDivisions == gridDivisions - 1) { g2d.setColor(primaryColor); } else { g2d.setColor(secondaryColor); } verticalLineCount++; line.setLine(0, h, gridWidth, h); g2d.draw(line); } } }
From source file:net.sqs2.omr.session.logic.PageImageRenderer.java
private static void drawFormAreas(int pageIndex, float densityThreshold, FormMaster master, PageTaskResult pageTaskResult, Graphics2D g, MarkRecognitionConfig markRecognizationConfig, DeskewedImageSource pageSource, int focusedColumnIndex, Rectangle scope) { int formAreaIndexInPage = 0; int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; int maxX = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE; for (FormArea formArea : master.getFormAreaListByPageIndex(pageIndex)) { FormAreaResult result = (FormAreaResult) pageTaskResult.getPageAreaResultList() .get(formAreaIndexInPage); if (formArea.isMarkArea()) { if (focusedColumnIndex == formArea.getQuestionIndex()) { Rectangle rect = formArea.getRect(); Point2D p1 = pageSource.getPoint((int) rect.getX(), (int) rect.getY()); Point2D p2 = pageSource.getPoint((int) (rect.getX() + rect.getWidth()), (int) (rect.getY() + rect.getHeight())); minX = Math.min(minX, (int) p1.getX()); minY = Math.min(minY, (int) p1.getY()); maxX = Math.max(maxX, (int) p2.getX()); maxY = Math.max(maxY, (int) p2.getY()); if (result.getDensity() < densityThreshold) { g.setColor(FOCUSED_MARKED_COLOR); } else { g.setColor(FOCUSED_NO_MARKED_COLOR); }/*from w w w .j av a 2s . c o m*/ } else { if (result.getDensity() < densityThreshold) { g.setColor(MARKED_COLOR); } else { g.setColor(NO_MARKED_COLOR); } } g.fillPolygon(pageSource.createRectPolygon( getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin(), markRecognizationConfig.getVerticalMargin()))); g.drawPolygon(pageSource.createRectPolygon( getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin() + 3, markRecognizationConfig.getVerticalMargin() + 3))); } else { g.setColor(TEXTAREA_COLOR); g.fillPolygon(pageSource.createRectPolygon(formArea.getRect())); } formAreaIndexInPage++; } if (scope != null) { int borderMarginX = 20; int borderMarginY = 3; int margin = 40; int x = minX - borderMarginX; int y = minY - borderMarginY; int width = maxX - minX + borderMarginX * 2; int height = maxY - minY + borderMarginY * 2; scope.x = minX - margin; scope.y = minY - margin; scope.width = maxX - minX + margin * 2; scope.height = maxY - minY + margin * 2; Stroke stroke = new BasicStroke(4.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 2.0f, new float[] { 4.0f, 8.0f }, 0.0f); g.setStroke(stroke); g.setColor(FOCUSED_SCOPE_COLOR); g.drawRoundRect(x, y, width, height, 20, 20); } }
From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java
/** * Draws the visual representation of a single data item when the plot has a * vertical orientation./*from w w w . j ava 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. * @param row the row index (zero-based). * @param column the column index (zero-based). */ @Override public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } //Determine the catgory start and end. 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; domainAxis.setCategoryMargin(0.25); rangeAxis.setUpperMargin(0.3); rangeAxis.setLowerMargin(0.3); double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * 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 * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than the category width double offset = (categoryWidth - state.getBarWidth()) / 2; xx = xx + offset; } double xxmid = xx + state.getBarWidth() / 2.0; //Draw the box. Paint p = getItemPaint(row, column); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Shape box = null; Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); 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); // set the paint according to the right technical replicate int length = GuiUtils.getAvailableColors().length; int colorIndex = row % length; Color color = GuiUtils.getAvailableColors()[colorIndex]; g2.setPaint(color); // draw the upper whisker g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower whisker g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin)); // draw the body box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3)); g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175)); // if (getFillBox()) { // g2.fill(box); // } g2.draw(box); } // draw mean g2.setPaint(getArtifactPaint()); double yyAverage = 0.0; double aRadius = 2.0; // mean radius Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); Ellipse2D.Double avgEllipse = new Ellipse2D.Double((xxmid - aRadius), (yyAverage - aRadius), aRadius * 2, aRadius * 2); g2.draw(avgEllipse); } //draw median double yyMedian = 0.0; Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } //Outliers and Farouts double oRadius = 2.0; //outlier radius double foRadius = 1.0; //farout radius // From outlier array sort out which are outliers and put these into a // list. If there are any farouts, add them to the farout list. // draw the outliers and farouts only if they are within the data area. double yyOutlier; double yyFarout; List outliers = new ArrayList(); List farOutValues = new ArrayList(); List yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { Number outlierNum = (Number) yOutliers.get(i); double outlier = outlierNum.doubleValue(); Number minOutlier = bawDataset.getMinOutlier(row, column); Number maxOutlier = bawDataset.getMaxOutlier(row, column); Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); if (outlier > maxOutlier.doubleValue() || outlier < minOutlier.doubleValue()) { yyFarout = rangeAxis.valueToJava2D(outlier, dataArea, location); Outlier faroutToAdd = new Outlier(xxmid, yyFarout, foRadius); if (dataArea.contains(faroutToAdd.getPoint())) { farOutValues.add(faroutToAdd); } } else if (outlier > maxRegular.doubleValue() || outlier < minRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); Outlier outlierToAdd = new Outlier(xxmid, yyOutlier, oRadius); if (dataArea.contains(outlierToAdd.getPoint())) { outliers.add(outlierToAdd); } } } //draw the outliers g2.setPaint(this.outlierPaint); for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); Shape dot = createEllipse(point, oRadius); g2.draw(dot); } //draw the farout values g2.setPaint(this.farOutColor); for (Iterator iterator = farOutValues.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); Shape triangle = createTriangleVertical(point, foRadius); g2.draw(triangle); } } }
From source file:convcao.com.agent.ConvcaoNeptusInteraction.java
@Override public void paint(Graphics2D g2, StateRenderer2D renderer) { Graphics2D g = (Graphics2D) g2.create(); Point2D center = renderer.getScreenPosition(coords.squareCenter); double width = renderer.getZoom() * coords.cellWidth * coords.numCols; double height = renderer.getZoom() * coords.cellWidth * coords.numRows; g.setColor(new Color(0, 0, 255, 64)); g.translate(center.getX(), center.getY()); g.rotate(-renderer.getRotation());// ww w . j ava2 s. c o m g.fill(new Rectangle2D.Double(-width / 2, -height / 2, width, height)); g.rotate(renderer.getRotation()); g.translate(-center.getX(), -center.getY()); if (!active) { g.dispose(); return; } g.setColor(Color.orange); int pos = 50; for (String v : nameTable.values()) { g.drawString(v + ": " + depths.get(v) + "m", 15, pos); pos += 20; } for (String vehicle : nameTable.values()) { LocationType src = positions.get(vehicle); LocationType dst = destinations.get(vehicle); if (!arrived.get(vehicle)) g.setColor(Color.red.darker()); else g.setColor(Color.green.darker()); float dash[] = { 4.0f }; g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash, 0.0f)); g.draw(new Line2D.Double(renderer.getScreenPosition(src), renderer.getScreenPosition(dst))); Point2D dstPt = renderer.getScreenPosition(dst); if (!arrived.get(vehicle)) g.setColor(Color.red.darker()); else g.setColor(Color.green.darker()); g.fill(new Ellipse2D.Double(dstPt.getX() - 4, dstPt.getY() - 4, 8, 8)); } g.dispose(); }
From source file:krasa.cpu.CpuUsagePanel.java
@Override public void paintComponent(final Graphics g) { final boolean pressed = getModel().isPressed(); final boolean stateChanged = myWasPressed != pressed; myWasPressed = pressed;/*w ww . ja va 2 s.c om*/ Image bufferedImage = myBufferedImage; if (bufferedImage == null || stateChanged) { final Dimension size = getSize(); final Insets insets = getInsets(); bufferedImage = UIUtil.createImage(g, size.width, size.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) bufferedImage.getGraphics().create(); final int max = 100; int system = CpuUsageManager.system; int process = CpuUsageManager.process; final int otherProcesses = system - process; final int totalBarLength = size.width - insets.left - insets.right - 3; final int processUsageBarLength = totalBarLength * process / max; final int otherProcessesUsageBarLength = totalBarLength * otherProcesses / max; final int barHeight = Math.max(size.height, getFont().getSize() + 2); final int yOffset = (size.height - barHeight) / 2; final int xOffset = insets.left; // background g2.setColor(UIUtil.getPanelBackground()); g2.fillRect(0, 0, size.width, size.height); // gauge (ide) g2.setColor(ideColor); g2.fillRect(xOffset + 1, yOffset, processUsageBarLength + 1, barHeight); // gauge (system) g2.setColor(systemColor); g2.fillRect(xOffset + processUsageBarLength + 1, yOffset, otherProcessesUsageBarLength + 1, barHeight); // label g2.setFont(getFont()); // final String info = CpuUsageBundle.message("cpu.usage.panel.message.text", CpuUsageManager.process, // CpuUsageManager.system); final String info = fixedLengthString(String.valueOf(process), 3) + "% / " + fixedLengthString(String.valueOf(system), 3) + "%"; final FontMetrics fontMetrics = g.getFontMetrics(); final int infoWidth = fontMetrics.charsWidth(info.toCharArray(), 0, info.length()); final int infoHeight = fontMetrics.getAscent(); UISettings.setupAntialiasing(g2); final Color fg = pressed ? UIUtil.getLabelDisabledForeground() : JBColor.foreground(); g2.setColor(fg); g2.drawString(info, xOffset + (totalBarLength - infoWidth) / 2, yOffset + infoHeight + (barHeight - infoHeight) / 2 - 1); // border g2.setStroke(new BasicStroke(1)); g2.setColor(JBColor.GRAY); g2.drawRect(0, 0, size.width - 2, size.height - 1); g2.dispose(); myBufferedImage = bufferedImage; } draw(g, bufferedImage); }
From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a horizontal orientation./*from w w w .j av a 2s. co 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. * @param row the row index (zero-based). * @param column the column index (zero-based). */ public void drawHorizontalItem(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 = Math.abs(categoryEnd - categoryStart); double yy = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * 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; yy = yy + offset + (row * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than // the category width double offset = (categoryWidth - state.getBarWidth()) / 2; yy = yy + offset; } Paint p = getItemPaint(row, column); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Number xQ1 = bawDataset.getQ1Value(row, column); Number xQ3 = bawDataset.getQ3Value(row, column); Number xMax = bawDataset.getMaxRegularValue(row, column); Number xMin = bawDataset.getMinRegularValue(row, column); Shape box = null; if (xQ1 != null && xQ3 != null && xMax != null && xMin != null) { double xxQ1 = rangeAxis.valueToJava2D(xQ1.doubleValue(), dataArea, location); double xxQ3 = rangeAxis.valueToJava2D(xQ3.doubleValue(), dataArea, location); double xxMax = rangeAxis.valueToJava2D(xMax.doubleValue(), dataArea, location); double xxMin = rangeAxis.valueToJava2D(xMin.doubleValue(), dataArea, location); double yymid = yy + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxMax, yymid, xxQ3, yymid)); g2.draw(new Line2D.Double(xxMax, yy, xxMax, yy + state.getBarWidth())); // draw the lower shadow... g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid)); g2.draw(new Line2D.Double(xxMin, yy, xxMin, yy + state.getBarWidth())); // draw the box... box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), state.getBarWidth()); if (this.fillBox) { g2.fill(box); } g2.draw(box); } g2.setPaint(this.artifactPaint); double aRadius = 0; // average radius // draw mean - SPECIAL AIMS REQUIREMENT... Number xMean = bawDataset.getMeanValue(row, column); if (xMean != null) { double xxMean = rangeAxis.valueToJava2D(xMean.doubleValue(), dataArea, location); aRadius = state.getBarWidth() / 4; Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxMean - aRadius, yy + aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } // draw median... Number xMedian = bawDataset.getMedianValue(row, column); if (xMedian != null) { double xxMedian = rangeAxis.valueToJava2D(xMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + state.getBarWidth())); } // 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(box, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java
@Override public void renderCellHD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/*from w ww. j a v a 2s. c o m*/ try { int index = (int) ((v - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } Color c = _gradientColors[index]; //System.out.println(c); g2D.setColor(c); // System.out.println((int) cellWidth + " " + ((int) cellHeight)) ; g2D.fillRoundRect((int) anchorX + 1, (int) anchorY + 1, (int) cellWidth - 2, (int) cellHeight - 2, 4, 4); if (drawSubMap.isSelected()) { //paint the sub heatmap block // System.out.println("draw submap"); if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return; } else { g2D.setStroke(UI.strokeDash1_5); //need to determine the number of cMatrices CoolMapObject object = getCoolMapObject(); List<CMatrix> matrices = object.getBaseCMatrices(); Double value; //row and column indices Integer[] rowIndices; Integer[] colIndices; //whether they are group node or node if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfColName(columnNode.getName()) }; } //then determine the width int subMatrixWidth = Math.round(cellWidth * 1.0f / matrices.size()); int subAnchorX = anchorX; int subCellHeight = Math.round(cellHeight * 1.0f / rowIndices.length); int subCellWidth = Math.round(subMatrixWidth * 1.0f / colIndices.length); // System.out.println("CW:" + cellWidth + " " + colIndices.length + " " + subCellWidth); // System.out.println("CH:" + cellHeight + " " + rowIndices.length + " " + subCellHeight); if (subCellHeight < 1) { subCellHeight = 1; } if (subCellWidth < 1) { subCellWidth = 1; } int matrixIndex = 0; for (CMatrix matrix : matrices) { int rowIndex = 0; for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } int columnIndex = 0; for (Integer j : colIndices) { if (j == null || j < 0) { continue; } try { value = (Double) matrix.getValue(i, j); index = (int) ((value - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } c = _gradientColors[index]; g2D.setColor(c); int subCellX = Math .round(subMatrixWidth * 1.0f * columnIndex / colIndices.length) + subAnchorX; int subCellY = Math.round(cellHeight * 1.0f * rowIndex / rowIndices.length) + anchorY; // System.out.println("WTF:" + columnIndex + " " + rowIndex + "----" + subCellX + " " + subCellY + " " + subCellWidth + " " + subCellHeight); g2D.fillRect(subCellX, subCellY, subCellWidth, subCellHeight); } catch (Exception e) { //draw it here e.printStackTrace(); } columnIndex++; } //end of column loop rowIndex++; } //end of row loop g2D.setColor(UI.colorBlack1); g2D.drawRect(subAnchorX, anchorY, subMatrixWidth, cellHeight); // // subAnchorX += subMatrixWidth; matrixIndex++; subAnchorX = anchorX + Math.round(cellWidth * 1.0f * matrixIndex / matrices.size()); } //end of matrix loop g2D.setStroke(UI.stroke2); g2D.setColor(Color.BLACK); g2D.drawRect(anchorX, anchorY, cellWidth, cellHeight); } } } catch (Exception e) { // System.out.println("Null pointer exception:" + v + "," + _minValue + "," + _maxValue + "," + _gradientColors + " " + getName() + "" + this); //e.printStackTrace(); } } }