List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalLineAndShapeRenderer.java
/** * Draw a single data item./* ww w . j ava2 s .c om*/ * * @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:edu.scripps.fl.curves.plot.MyXYErrorRenderer.java
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 (pass == 0 && (dataset instanceof IntervalXYDataset) && getItemVisible(series, item)) { IntervalXYDataset ixyd = (IntervalXYDataset) dataset; PlotOrientation orientation = plot.getOrientation(); if (getSeriesXError(series)) { double x0 = ixyd.getStartXValue(series, item); double x1 = ixyd.getEndXValue(series, item); double y = ixyd.getYValue(series, item); org.jfree.ui.RectangleEdge edge = plot.getDomainAxisEdge(); double xx0 = domainAxis.valueToJava2D(x0, dataArea, edge); double xx1 = domainAxis.valueToJava2D(x1, dataArea, edge); double yy = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); Line2D cap1 = null;/*from w w w .j a va 2s.com*/ Line2D cap2 = null; double adj = capLength / 2D; Line2D line; if (orientation == PlotOrientation.VERTICAL) { line = new java.awt.geom.Line2D.Double(xx0, yy, xx1, yy); cap1 = new java.awt.geom.Line2D.Double(xx0, yy - adj, xx0, yy + adj); cap2 = new java.awt.geom.Line2D.Double(xx1, yy - adj, xx1, yy + adj); } else { line = new java.awt.geom.Line2D.Double(yy, xx0, yy, xx1); cap1 = new java.awt.geom.Line2D.Double(yy - adj, xx0, yy + adj, xx0); cap2 = new java.awt.geom.Line2D.Double(yy - adj, xx1, yy + adj, xx1); } if (errorPaint != null) g2.setPaint(errorPaint); else g2.setPaint(getItemPaint(series, item)); if (errorStroke != null) g2.setStroke(errorStroke); else g2.setStroke(getItemStroke(series, item)); g2.draw(line); g2.draw(cap1); g2.draw(cap2); } if (getSeriesYError(series)) { double y0 = ixyd.getStartYValue(series, item); double y1 = ixyd.getEndYValue(series, item); double x = ixyd.getXValue(series, item); org.jfree.ui.RectangleEdge edge = plot.getRangeAxisEdge(); double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge); double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); Line2D cap1 = null; Line2D cap2 = null; double adj = capLength / 2D; Line2D line; if (orientation == PlotOrientation.VERTICAL) { line = new java.awt.geom.Line2D.Double(xx, yy0, xx, yy1); cap1 = new java.awt.geom.Line2D.Double(xx - adj, yy0, xx + adj, yy0); cap2 = new java.awt.geom.Line2D.Double(xx - adj, yy1, xx + adj, yy1); } else { line = new java.awt.geom.Line2D.Double(yy0, xx, yy1, xx); cap1 = new java.awt.geom.Line2D.Double(yy0, xx - adj, yy0, xx + adj); cap2 = new java.awt.geom.Line2D.Double(yy1, xx - adj, yy1, xx + adj); } if (errorPaint != null) g2.setPaint(errorPaint); else g2.setPaint(getItemPaint(series, item)); if (errorStroke != null) g2.setStroke(errorStroke); else g2.setStroke(getItemStroke(series, item)); g2.draw(line); g2.draw(cap1); g2.draw(cap2); } } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryFieldPanel.java
@Override public void paint(Graphics g) { // TODO Auto-generated method stub super.paint(g); if (selected) { //this block was copied from RolloverCommand.paintComp() g.setColor(RolloverCommand.getActiveColor()); Insets insets = getInsets(); insets.set(1, 1, 1, 1);/* www . j a v a2s. c o m*/ Dimension size = getSize(); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); RoundRectangle2D.Double rr = new RoundRectangle2D.Double(insets.left, insets.top, size.width - insets.right - insets.left, size.height - insets.bottom - insets.top, 10, 10); g2d.draw(rr); rr = new RoundRectangle2D.Double(insets.left + 1, insets.top + 1, size.width - insets.right - insets.left - 2, size.height - insets.bottom - insets.top - 2, 10, 10); g2d.draw(rr); } }
From source file:dk.sdu.mmmi.featureous.views.featurecharacterization.FeatureViewChart.java
public FeatureViewChart(List<TraceModel> ftms, final boolean pkg) { this.pkg = pkg; data = new DefaultCategoryDataset(); chart = ChartFactory.createStackedBarChart("Feature characterization", "Feature", "Scattering", data, PlotOrientation.VERTICAL, true, false, false); plot = (CategoryPlot) chart.getPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); xAxis.setMaximumCategoryLabelLines(2); // 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);/*from ww w.j ava 2s. c om*/ // chart.removeLegend(); panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.white); this.ftms = ftms; scattering = new ArrayList<Result>( new StaticScattering(pkg).calculateAndReturnAll(new HashSet<TraceModel>(ftms), null)); Result.sortByName(scattering); for (Result r : scattering) { // OutputUtil.log(r.name + ";" +r.value); } panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel)); StackedBarRenderer r2 = 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); } } }; plot.setRenderer(r2, true); StackedBarRenderer r = (StackedBarRenderer) plot.getRenderer(); r.setDrawBarOutline(true); plot.getRenderer().setOutlineStroke(new BasicStroke(0.1f)); Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this); }
From source file:convcao.com.caoAgent.convcaoNeptusInteraction.java
@Override public void paint(Graphics2D g, StateRenderer2D renderer) { 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());/* w ww. 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) 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)); } }
From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java
public BufferedImage getFlattenedImage(boolean overlayAscan) { ROIPanel pan = view;/* w w w. j ava2s. c o m*/ BufferedImage rst = previewPanel.getImage(); if (axis == AXIS_Y) { int wide = 0; for (int i = 0; i < pan.getImage().getWidth(); i++) { if (getUseData(i)) { wide++; } } if (rst == null || rst.getWidth() != wide || rst.getHeight() != pan.getImage().getHeight()) { rst = ImageOperations.getBi(wide, pan.getImage().getHeight()); } else { ImageOperations.setImage(Color.BLACK, rst); } // This will get the smoothed out aScan from the Dynamic?Range panel int posX = 0; int posY = 0; for (int i = 0; i < pan.getImage().getWidth(); i++) { posY = 0; if (getUseData(i)) { int start = (int) (pan.getImage().getHeight() * (1 - getSelectionValue(i))); for (int j = start; j < pan.getImage().getHeight(); j++) { if (j > 0 && i > 0) { try { rst.setRGB(posX, posY, pan.getImage().getRGB(i, j)); } catch (Exception e) { System.out.println("Org [" + i + "," + j + "], Pos :[" + posX + "," + posY); } } posY++; } posX++; } } } else if (axis == AXIS_X) { int high = 0; for (int i = 0; i < pan.getImage().getHeight(); i++) { if (getUseData(i)) { high++; } } if (rst == null || rst.getHeight() != high || rst.getWidth() != pan.getImage().getWidth()) { rst = ImageOperations.getBi(pan.getImage().getWidth(), high); } else { ImageOperations.setImage(Color.BLACK, rst); } // This will get the smoothed out aScan from the Dynamic?Range panel int posX = 0; int posY = 0; for (int i = 0; i < pan.getImage().getHeight(); i++) { posX = 0; if (getUseData(i)) { int start = (int) (pan.getImage().getWidth() * (1 - getSelectionValue(i))); for (int j = start; j < pan.getImage().getWidth(); j++) { if (j > 0 && i > 0) { try { rst.setRGB(posX, posY, pan.getImage().getRGB(j, i)); } catch (Exception e) { System.out.println("Org [" + i + "," + j + "], Pos :[" + posX + "," + posY); } } posX++; } posY++; } } } if (overlayAscan) { Graphics2D g = rst.createGraphics(); g.setColor(Color.cyan); GraphicsToolkit.setRenderingQuality(g, GraphicsToolkit.HIGH_QUALITY); float max = DataAnalysisToolkit.getMaxf(aScan); float min = DataAnalysisToolkit.getMinf(aScan); Line2D.Double line = new Line2D.Double(); GeneralPath path = new GeneralPath(); for (int i = 0; i < aScan.length; i++) { int xP = 0; int yP = 0; float p1 = ((aScan[i] - min) / (max - min)); double x = 0; double y = 0; if (axis == AXIS_Y) { y = rst.getHeight() / (double) (aScan.length - 1) * i; x = rst.getWidth() * (1 - p1); } else if (axis == AXIS_X) { x = rst.getWidth() / (double) (aScan.length - 1) * i; y = rst.getHeight() * (1 - p1); } if (i == 0) { path.moveTo(x, y); } else { path.lineTo(x, y); } } g.draw(path); } return rst; }
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 2s.c om // 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:com.isti.traceview.common.TraceViewChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal axis. * //from w w w .j a va2s . c om * @param g2 * the graphics device. * @param x * the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(Graphics2D g2, int x) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (this.verticalTraceLine != null) { g2.draw(this.verticalTraceLine); this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } else { this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } g2.draw(this.verticalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this * method is called twice in a row, the second call will completely restore the state of the * canvas.// w w w. j a v a 2 s. c om * * @param g2 * the graphics device. */ private void drawZoomRectangle(Graphics2D g2) { // Set XOR mode to draw the zoom rectangle g2.setXORMode(Color.gray); if (this.zoomRectangle != null) { if (this.fillZoomRectangle) { g2.fill(this.zoomRectangle); } else { g2.draw(this.zoomRectangle); } } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical axis. * /*from w w w. j a v a2 s . c om*/ * @param g2 * the graphics device. * @param y * the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { if (this.horizontalTraceLine != null) { g2.draw(this.horizontalTraceLine); this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(this.horizontalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }