List of usage examples for java.awt.geom Rectangle2D getX
public abstract double getX();
From source file:com.att.aro.ui.view.diagnostictab.GraphPanel.java
private void zoomEventUIUpdate() { // allow for better scrolling efficiency for new size chartPanelScrollPane().getHorizontalScrollBar().setUnitIncrement(zoomCounter * 10); // update the screen panels for repaint getChartPanel().updateUI();// ww w . j a va 2s .c o m // updates the scroll bar after resize updates. // SwingUtilities.invokeLater(new Runnable() { // public void run() { // resetScrollPosition(); Rectangle2D plotArea = getChartPanel().getScreenDataArea(); XYPlot plot = (XYPlot) getAdvancedGraph().getPlot(); int plotWidth = initialPlotAreaWidth; for (int i = 1; i <= zoomCounter; i++) { plotWidth = (plotWidth * 2) + 16; } plotArea.setRect(plotArea.getX(), plotArea.getY(), plotWidth, plotArea.getHeight()); double scrollPoint = new Float( plot.getDomainAxis().valueToJava2D(getCrosshair(), plotArea, plot.getDomainAxisEdge())).intValue(); int width = chartPanelScrollPane().getWidth(); scrollPoint = Math.max(0, scrollPoint - (width / 2)); this.pointX = (int) scrollPoint; }
From source file:probe.com.view.body.quantdatasetsoverview.quantproteinstabsheet.studies.ProteinStudyComparisonScatterPlotLayout.java
/** * Creates a sample jFreeChart.//from w ww . j ava2 s .c om * * @param dataset the dataset. * * @return The jFreeChart. */ private void generateScatterplotchart(DiseaseGroupsComparisonsProteinLayout cp, int w, int h) { final XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries downSer = new XYSeries(0); XYSeries stableSer = new XYSeries(1); XYSeries upSer = new XYSeries(2); XYSeries novalueProvidedSer = new XYSeries(3); XYSeries downSerII = new XYSeries(4); XYSeries stableSerII = new XYSeries(5); XYSeries upSerII = new XYSeries(6); XYSeries novalueProvidedSerII = new XYSeries(7); // XYSeries plusSeries = new XYSeries(6); double downCounter = 1; double stableCounter = 3; double upCounter = 5; double novalueProvidedCounter = 3; patientGroupsNumToDsIdMap.clear(); final Map<Integer, int[]> paTGrNumbtrendMap = new HashMap<Integer, int[]>(); double maxPatNumber = -1.0; for (String protTrend : cp.getPatientsNumToTrindMap().keySet()) { List<Integer> patNums = cp.getPatientsNumToTrindMap().get(protTrend); int coun = 0; for (int i : patNums) { if (i > maxPatNumber) { maxPatNumber = i; } if (!patientGroupsNumToDsIdMap.containsKey(i)) { ComparisonDetailsBean pGr = new ComparisonDetailsBean(); patientGroupsNumToDsIdMap.put(i, pGr); } if (!paTGrNumbtrendMap.containsKey(i)) { int[] values = new int[4]; paTGrNumbtrendMap.put(i, values); } int[] values = paTGrNumbtrendMap.get(i); ComparisonDetailsBean pGr = patientGroupsNumToDsIdMap.get(i); if (protTrend.equalsIgnoreCase("noValueProvided")) { values[3] = values[3] + 1; pGr.addNovalueProvided(cp.getDSID(3, coun)); } else if (protTrend.equalsIgnoreCase("up")) { values[2] = values[2] + 1; pGr.addUpRegulated(cp.getDSID(0, coun)); } else if (protTrend.equalsIgnoreCase("down")) { values[0] = values[0] + 1; pGr.addDownRegulated(cp.getDSID(2, coun)); } else { values[1] = values[1] + 1; pGr.addNotRegulated(cp.getDSID(1, coun)); } paTGrNumbtrendMap.put(i, values); patientGroupsNumToDsIdMap.put(i, pGr); coun++; } } for (int i : paTGrNumbtrendMap.keySet()) { int[] values = paTGrNumbtrendMap.get(i); if ((values[2] > 1)) { upSer.add(upCounter, i); upSerII.add(upCounter, i); } else if ((values[2] == 1)) { upSer.add(upCounter, i); } if ((values[1] == 1)) { stableSer.add(stableCounter, i); } else if ((values[1] > 1)) { stableSer.add(stableCounter, i); stableSerII.add(stableCounter, i); } if ((values[0] > 1)) { downSer.add(downCounter, i); downSerII.add(downCounter, i); } else if ((values[0] == 1)) { downSer.add(downCounter, i); } if ((values[3] == 1)) { novalueProvidedSer.add(novalueProvidedCounter, i); } else if ((values[3] > 1)) { novalueProvidedSer.add(stableCounter, i); novalueProvidedSerII.add(stableCounter, i); } } dataset.addSeries(downSer); dataset.addSeries(stableSer); dataset.addSeries(upSer); dataset.addSeries(novalueProvidedSer); dataset.addSeries(downSerII); dataset.addSeries(stableSerII); dataset.addSeries(upSerII); dataset.addSeries(novalueProvidedSerII); // if((downSerII.getItemCount()+stableSerII.getItemCount()+upSerII.getItemCount()+downSer.getItemCount()+stableSer.getItemCount()+upSer.getItemCount())==0) // return; // dataset.addSeries(plusSeries); final String[] labels = new String[] { " ", ("Decreased (" + cp.getSignificantDown() + ")"), " ", ("Equal (" + cp.getStable() + ")"), " ", ("Increased (" + cp.getSignificantUp() + ")"), "" }; final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, Color.RED, Color.LIGHT_GRAY }; final SymbolAxis domainAxis = new SymbolAxis("X", labels) { @Override protected void drawGridBandsVertical(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea, boolean firstGridBandIsDark, List ticks) { List udatedTicksList = new ArrayList(); for (Object tick : ticks) { if (tick.toString().equalsIgnoreCase(labels[custTrend + 1])) { udatedTicksList.add(tick); } } // System.out.println("at ticks is "+ticks); // System.out.println("at udatedTicksList is "+udatedTicksList); // int factor = (int) ((plotArea.getHeight() / 5) * 0.25); // // Rectangle2D up = new Rectangle((int) drawArea.getX(), (int) drawArea.getY() - factor, (int) drawArea.getWidth(), (int) drawArea.getHeight()); // Rectangle2D pa = new Rectangle((int) plotArea.getX(), (int) plotArea.getY() - factor, (int) plotArea.getWidth(), (int) plotArea.getHeight()); super.drawGridBandsVertical(g2, drawArea, plotArea, firstGridBandIsDark, udatedTicksList); //To change body of generated methods, choose Tools | Templates. } int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labels.length) { x = 0; } return labelsColor[x++]; } }; domainAxis.setAutoRangeIncludesZero(false); Font f = new Font("Verdana", Font.PLAIN, 11); domainAxis.setTickLabelFont(f); domainAxis.setAutoRange(false); domainAxis.setLabel(null); // domainAxis.setGridBandsVisible(false); String xTile = "#Patients"; JFreeChart jFreeChart = ChartFactory.createScatterPlot(null, null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend false, // tooltips? false // URLs? ); XYPlot plot1 = (XYPlot) jFreeChart.getPlot(); XYPlot xyplot = new XYPlot(dataset, plot1.getDomainAxis(), plot1.getRangeAxis(), plot1.getRenderer()) { @Override public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea, List ticks) { if (custTrend == -1) { super.drawDomainTickBands(g2, dataArea, ticks); return; } List udatedTicksList = new ArrayList(); for (Object tick : ticks) { if (tick.toString().equalsIgnoreCase(labels[custTrend + 1])) { udatedTicksList.add(tick); } } Rectangle2D up; int factor = (int) ((dataArea.getHeight() / 5) * 0.5); if (custTrend == 4) { up = new Rectangle((int) dataArea.getX(), (int) dataArea.getY() + factor, (int) dataArea.getWidth(), (int) dataArea.getHeight()); } else if (custTrend == 2) { up = new Rectangle((int) dataArea.getX(), (int) dataArea.getY() - factor, (int) dataArea.getWidth(), (int) dataArea.getHeight()); } else { up = new Rectangle((int) dataArea.getX(), (int) dataArea.getY() - factor, (int) dataArea.getWidth(), (int) dataArea.getHeight()); } super.drawDomainTickBands(g2, up, udatedTicksList); //To change body of generated methods, choose Tools | Templates. } @Override protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { super.drawDomainGridlines(g2, dataArea, ticks); //To change body of generated methods, choose Tools | Templates. } private int x = 0; @Override public Paint getDomainGridlinePaint() { if (x >= labels.length) { x = 0; } if (x == 1 || x == 3 || x == 5) { x++; return Color.WHITE; } else { x++; return super.getDomainGridlinePaint(); //To change body of generated methods, choose Tools | Templates. } } }; if (custTrend != -1) { domainAxis.setGridBandsVisible(true); if (custTrend == 4) { domainAxis.setGridBandPaint(Color.decode("#ffe5e5")); xyplot.setDomainTickBandPaint(Color.decode("#ffe5e5")); domainAxis.setGridBandAlternatePaint(Color.decode("#ffe5e5")); } else if (custTrend == 0) { domainAxis.setGridBandPaint(Color.decode("#e5ffe5")); xyplot.setDomainTickBandPaint(Color.white); } else if (custTrend == 2) { domainAxis.setGridBandPaint(Color.decode("#e6f4ff")); xyplot.setDomainTickBandPaint(Color.white); } } else { domainAxis.setGridBandsVisible(false); } xyplot.setOrientation(PlotOrientation.HORIZONTAL); JFreeChart tempScatterPlot = new JFreeChart(xyplot); tempScatterPlot.setBackgroundPaint(Color.WHITE); tempScatterPlot.getLegend().setVisible(false); Color c = new Color(242, 242, 242); xyplot.setDomainAxis(domainAxis); xyplot.setDomainGridlinePaint(Color.GRAY); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.GRAY); xyplot.setOutlinePaint(Color.GRAY); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); ValueAxis va = xyplot.getDomainAxis(); va.setAutoRange(false); va.setMinorTickCount(0); va.setVisible(true); maxPatNumber = Math.ceil(maxPatNumber / 100.0) * 100; xyplot.getRangeAxis().setRange(0, maxPatNumber); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabel(xTile); rangeAxis.setLabelFont(f); rangeAxis.setLabelPaint(Color.GRAY); va.setRange(0, 6); xyplot.setBackgroundPaint(Color.WHITE); renderer.setUseOutlinePaint(true); Color c0 = new Color(80, 183, 71); renderer.setSeriesPaint(0, c0); renderer.setSeriesOutlinePaint(0, Color.WHITE); Color c1 = new Color(1, 141, 244); renderer.setSeriesPaint(1, c1); renderer.setSeriesOutlinePaint(1, Color.WHITE); Color c2 = new Color(204, 0, 0); renderer.setSeriesPaint(2, c2); renderer.setSeriesOutlinePaint(2, Color.WHITE); renderer.setSeriesPaint(3, Color.decode("#b5babb")); renderer.setSeriesOutlinePaint(3, Color.WHITE); renderer.setSeriesPaint(4, new Color(150, 212, 145)); renderer.setSeriesOutlinePaint(4, new Color(150, 212, 145)); renderer.setSeriesPaint(5, new Color(103, 187, 248)); renderer.setSeriesOutlinePaint(5, new Color(103, 187, 248)); renderer.setSeriesPaint(6, new Color(224, 102, 102)); renderer.setSeriesOutlinePaint(6, new Color(224, 102, 102)); renderer.setSeriesPaint(7, Color.decode("#b5babb")); renderer.setSeriesOutlinePaint(7, Color.GRAY); // renderer.setSeriesPaint(6, Color.BLACK); // renderer.setSeriesOutlinePaint(6, Color.BLACK); Shape downArr = ShapeUtilities.createDownTriangle(7f); Shape notRShape = ShapeUtilities.createDiamond(7f); Shape upArr = ShapeUtilities.createUpTriangle(7); Shape downArrII = ShapeUtilities.createTranslatedShape(ShapeUtilities.createDownTriangle(6f), 5, -5); Shape notRShapeII = ShapeUtilities.createTranslatedShape(ShapeUtilities.createDiamond(6f), 0, -7); Shape upArrII = ShapeUtilities.createTranslatedShape(ShapeUtilities.createUpTriangle(6f), 4, -4); // Shape plus = ShapeUtilities.createTranslatedShape(ShapeUtilities.createRegularCross(3f, 0.4f), 11, -7); renderer.setSeriesShape(0, downArr); renderer.setSeriesShape(1, notRShape); renderer.setSeriesShape(2, upArr); renderer.setSeriesShape(3, notRShape); renderer.setSeriesShape(4, downArrII); renderer.setSeriesShape(5, notRShapeII); renderer.setSeriesShape(6, upArrII); renderer.setSeriesShape(7, notRShapeII); // renderer.setSeriesShape(6, plus); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new SymbolicXYItemLabelGenerator() { private final int[] indexer = new int[] { 0, 1, 2, 3, 0, 1, 2, 3 }; @Override public String generateLabel(XYDataset dataset, int series, int category) { if (series > 3) { int patNumber = (int) dataset.getYValue(series, category); // int trend = (int) dataset.getXValue(series, category); if (series == 7 || series == 5) { return "\t " + paTGrNumbtrendMap.get(patNumber)[indexer[series]]; } else { return "\t " + paTGrNumbtrendMap.get(patNumber)[indexer[series]]; } } return ""; //To change body of generated methods, choose Tools | Templates. } }); ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT, TextAnchor.TOP_LEFT, 0.0); renderer.setSeriesPositiveItemLabelPosition(4, position); renderer.setSeriesPositiveItemLabelPosition(5, position); renderer.setSeriesPositiveItemLabelPosition(6, position); renderer.setSeriesPositiveItemLabelPosition(7, position); renderer.setBaseItemLabelFont(f); tempScatterPlot.setBorderVisible(false); xyplot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); heighlightedScatterPlottImgUrl = saveToFile(tempScatterPlot, w, h, defaultScatterPlotRenderingInfo); xyplot.setBackgroundPaint(Color.WHITE); defaultScatterPlottImgUrl = saveToFile(tempScatterPlot, w, h, defaultScatterPlotRenderingInfo); // xyplot.setBackgroundPaint(c); if (custTrend != -1) { domainAxis.setGridBandsVisible(true); if (custTrend == 4) { domainAxis.setGridBandPaint(Color.decode("#ffe5e5")); xyplot.setDomainTickBandPaint(Color.decode("#ffe5e5")); domainAxis.setGridBandAlternatePaint(Color.decode("#ffe5e5")); } else if (custTrend == 0) { domainAxis.setGridBandPaint(Color.decode("#e5ffe5")); xyplot.setDomainTickBandPaint(c); } else if (custTrend == 2) { domainAxis.setGridBandPaint(Color.decode("#e6f4ff")); xyplot.setDomainTickBandPaint(c); } } String textTitle = comparisonTitle.getValue().split("bold;'>")[1].replace("</font>", ""); TextTitle title = new TextTitle(textTitle, f); scatterPlot = new JFreeChart(xyplot); scatterPlot.setTitle(title); scatterPlot.setBorderVisible(false); scatterPlot.setBackgroundPaint(Color.WHITE); scatterPlot.getLegend().setVisible(false); dsKeyDatasetMap.clear(); for (int i = 0; i < defaultScatterPlotRenderingInfo.getEntityCollection().getEntityCount(); i++) { final ChartEntity entity = defaultScatterPlotRenderingInfo.getEntityCollection().getEntity(i); if (entity instanceof XYItemEntity) { int x = ((XYItemEntity) entity).getSeriesIndex(); int y = ((XYItemEntity) entity).getItem(); if (((XYItemEntity) entity).getDataset().getYValue(x, y) > (int) ((XYItemEntity) entity).getDataset().getYValue(x, y)) { continue; } if (((XYItemEntity) entity).getSeriesIndex() > 3) { continue; } String[] arr = ((XYItemEntity) entity).getShapeCoords().split(","); int xSer = Integer.valueOf(arr[0]); int ySer = Integer.valueOf(arr[1]); int ySerEnd = Integer.valueOf(arr[3]); int patGrNumber = (int) ((XYItemEntity) entity).getDataset().getYValue(x, y); int trend = Integer.valueOf(((XYItemEntity) entity).getDataset() .getSeriesKey(((XYItemEntity) entity).getSeriesIndex()).toString()); ComparisonDetailsBean cpDetails = patientGroupsNumToDsIdMap.get(patGrNumber); List<Integer> dsList = cpDetails.getRegulatedList(trend); StringBuilder sb = new StringBuilder(); for (int dsId : dsList) { QuantDatasetObject ds; sb.append("<h4>").append((Quant_Central_Manager.getFullQuantDatasetMap().get(dsId)).getAuthor()) .append(" ") .append((Quant_Central_Manager.getFullQuantDatasetMap().get(dsId)).getYear()) .append("<h4/>"); sb.append("<p></p>"); ds = Quant_Central_Manager.getFullQuantDatasetMap().get(dsId); dsKeyDatasetMap.put("_-_" + dsId + "_-_" + comparisonProtein.getProteinAccssionNumber() + "_-_", ds); } String tooltip = sb.toString().substring(0, sb.toString().length() - 7); SquaredDot square = new SquaredDot("squared"); if (paTGrNumbtrendMap.get(patGrNumber)[trend] > 1) { square.setWidth(20 + "px"); square.setHeight(15 + "px"); } else { square.setWidth(10 + "px"); square.setHeight(10 + "px"); } square.setDescription(tooltip); square.setParam("trend", trend); square.setParam("pGrNumber", patGrNumber); int top = (ySer - 4); if (ySer > ySerEnd) { top = ySerEnd - 3; } defaultChartLayout.addComponent(square, "left: " + (xSer - 5) + "px; top: " + top + "px;"); } } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Handle event in chart//from w w w .j a v a 2 s .com * * @param event The event * * @return Did we handle this event */ public boolean chartPanelMouseDragged(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { return EVENT_DONTPASSON; } closestAnnotation = null; //Ignore shift down drag. if (event.isShiftDown()) { return EVENT_PASSON; } if (dragging && (draggedAnnotation == null)) { return EVENT_PASSON; } dragging = true; if (draggedAnnotation == null) { draggedAnnotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), true, event.isShiftDown()); } if (draggedAnnotation == null) { return EVENT_PASSON; } draggedAnnotation.setPosition(event); if (draggedAnnotation instanceof RangeFilter) { rangeFiltersChanged(); } if ((draggedAnnotation instanceof WayPoint) || (draggedAnnotation instanceof TrackSegment)) { Rectangle2D r = getChartPanel().getScreenDataArea(); if (event.getX() < r.getX()) { panPlot(false, 0.02); } else if (event.getX() > r.getX() + r.getWidth()) { panPlot(true, 0.02); } } signalChartChanged(); try { setLocationPositions(); } catch (Exception exc) { LogUtil.logException("Setting locations", exc); } return EVENT_DONTPASSON; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawInformationBox(Graphics2D g2, Activities activities, Rectangle2D rect, List<String> params, List<String> values, String totalParam, double totalValue, Color background_color, Color border_color) { final Font oldFont = g2.getFont(); final Font paramFont = oldFont; final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont); final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1); final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont); final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1); final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont); final int x = (int) rect.getX(); final int y = (int) rect.getY(); final int width = (int) rect.getWidth(); final int height = (int) rect.getHeight(); final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(border_color);/*from www . ja v a 2 s . c o m*/ g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15); g2.setColor(background_color); g2.setComposite(Utils.makeComposite(0.75f)); g2.fillRoundRect(x, y, width, height, 15, 15); g2.setComposite(oldComposite); g2.setColor(oldColor); final Date date = activities.getDate().getTime(); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy"); final String dateString = simpleDateFormat.format(date); final int padding = 5; int yy = y + padding + dateFontMetrics.getAscent(); g2.setFont(dateFont); g2.setColor(COLOR_BLUE); g2.drawString(dateString, ((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x, yy); int index = 0; final int dateInfoHeightMargin = 5; final int infoTotalHeightMargin = 5; final int paramValueHeightMargin = 0; yy += dateFontMetrics.getDescent() + dateInfoHeightMargin + Math.max(paramFontMetrics.getAscent(), valueFontMetrics.getAscent()); for (String param : params) { final String value = values.get(index++); g2.setColor(Color.BLACK); g2.setFont(paramFont); g2.drawString(param + ":", padding + x, yy); g2.setFont(valueFont); g2.drawString(value, width - padding - valueFontMetrics.stringWidth(value) + x, yy); // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent() yy += paramValueHeightMargin + Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight()); } if (values.size() > 1) { yy -= paramValueHeightMargin; yy += infoTotalHeightMargin; if (totalValue > 0.0) { g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR); } else if (totalValue < 0.0) { g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR); } g2.setFont(paramFont); g2.drawString(totalParam + ":", padding + x, yy); g2.setFont(valueFont); final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace(); final String totalValueStr = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalValue); g2.drawString(totalValueStr, width - padding - valueFontMetrics.stringWidth(totalValueStr) + x, yy); } g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Returns a cartesian point from a polar angle, length and bounding box * * @param bounds the area inside which the point needs to be. * @param angle the polar angle, in degrees. * @param length the relative length. Given in percent of maximum extend. * * @return The cartesian point./*from w w w. j av a2 s .co m*/ */ protected Point2D getWebPoint(Rectangle2D bounds, double angle, double length) { double angrad = Math.toRadians(angle); double x = Math.cos(angrad) * length * bounds.getWidth() / 2; double y = -Math.sin(angrad) * length * bounds.getHeight() / 2; return new Point2D.Double(bounds.getX() + x + bounds.getWidth() / 2, bounds.getY() + y + bounds.getHeight() / 2); }
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Applies any scaling that is in effect for the chart drawing to the * given rectangle./*from ww w .j ava 2 s . co m*/ * * @param rect the rectangle. * * @return A new scaled rectangle. */ public Rectangle scale(Rectangle2D rect) { Rectangle insets = this.getClientArea(); int x = (int) Math.round(rect.getX() * getScaleX()) + insets.x; int y = (int) Math.round(rect.getY() * this.getScaleY()) + insets.y; int w = (int) Math.round(rect.getWidth() * this.getScaleX()); int h = (int) Math.round(rect.getHeight() * this.getScaleY()); return new Rectangle(x, y, w, h); }
From source file:de.laures.cewolf.jfree.ThermometerPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device./*w w w. j ava 2 s . c o m*/ * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { RoundRectangle2D outerStem = new RoundRectangle2D.Double(); RoundRectangle2D innerStem = new RoundRectangle2D.Double(); RoundRectangle2D mercuryStem = new RoundRectangle2D.Double(); Ellipse2D outerBulb = new Ellipse2D.Double(); Ellipse2D innerBulb = new Ellipse2D.Double(); String temp = null; FontMetrics metrics = null; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); // adjust for padding... Rectangle2D interior = (Rectangle2D) area.clone(); this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); int stemTop = (int) (interior.getMinY() + getBulbRadius()); int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop); outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter()); outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2); innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); innerThermometer.add(tempArea); if ((this.dataset != null) && (this.dataset.getValue() != null)) { double current = this.dataset.getValue().doubleValue(); double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); int i = getColumnDiameter() - getGap() * 2; // already calculated int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); if (k < (getGap() + interior.getMinY())) { k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } Area mercury = new Area(innerBulb); if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } g2.setPaint(getCurrentPaint()); g2.fill(mercury); // draw range indicators... if (this.subrangeIndicatorsVisible) { g2.setStroke(this.subrangeIndicatorStroke); Range range = this.rangeAxis.getRange(); // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[NORMAL]); g2.draw(line); } // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[WARNING]); g2.draw(line); } // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[CRITICAL]); g2.draw(line); } } // draw the axis... if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null); break; case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null); break; } } // draw text value on screen g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); metrics = g2.getFontMetrics(); switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap()); break; default: } /***/ } g2.setPaint(this.thermometerPaint); g2.setFont(this.valueFont); // draw units indicator metrics = g2.getFontMetrics(); int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20)); } // draw thermometer outline g2.setStroke(this.thermometerStroke); g2.draw(outerThermometer); g2.draw(innerThermometer); drawOutline(g2, area); }
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Returns the data area for the chart (the area inside the axes) with the * current scaling applied (that is, the area as it appears on screen). * * @return The scaled data area.//from ww w .j a v a2s. c o m */ public Rectangle getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Rectangle clientArea = this.getClientArea(); int x = (int) (dataArea.getX() * this.scaleX + clientArea.x); int y = (int) (dataArea.getY() * this.scaleY + clientArea.y); int w = (int) (dataArea.getWidth() * this.scaleX); int h = (int) (dataArea.getHeight() * this.scaleY); return new Rectangle(x, y, w, h); }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * draw the time line/* w w w. j a v a2s . co m*/ * * @param g2 param * @param plot param * @param dataArea param * @param domainAxis param * @param rangeAxis param * @param rendererIndex param * @param info param */ private void drawTime(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { try { Animation animation = control.getSomeAnimation(); if (animation == null) { return; } Real dttm = animation.getAniValue(); if (dttm == null) { return; } g2.setStroke(new BasicStroke()); g2.setColor(Color.black); double timeValue = dttm.getValue(CommonUnit.secondsSinceTheEpoch); int x = (int) domainAxis.valueToJava2D(timeValue * 1000, dataArea, RectangleEdge.BOTTOM); if ((x < dataArea.getX()) || (x > dataArea.getX() + dataArea.getWidth())) { return; } int bottom = (int) (dataArea.getY() + dataArea.getHeight()); int top = (int) (dataArea.getY()); int offset = 0; if (false && (clockImage == null)) { clockImage = GuiUtils.getImage("/auxdata/ui/icons/clock.gif"); clockImage.getHeight(this); offset = clockImage.getHeight(null); } // g2.drawLine(x, (int) dataArea.getY(), x, bottom - offset); int w = 8; int w2 = w / 2; int[] xs = { x - w2, x, x + w2, x }; int[] ys = { top, top + w, top, top }; // g2.drawLine(x, top, x, top+10); g2.fillPolygon(xs, ys, xs.length); if (clockImage != null) { g2.drawImage(clockImage, x - clockImage.getWidth(null) / 2, bottom - clockImage.getHeight(null), null); } } catch (VisADException exc) { } catch (RemoteException exc) { } }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Applies any scaling that is in effect for the chart drawing to the given * rectangle.//from www . j a v a 2 s . c o m * * @param rect * the rectangle. * * @return A new scaled rectangle. */ public Rectangle scale(final Rectangle2D rect) { final Rectangle insets = this.getClientArea(); final int x = (int) Math.round(rect.getX() * getScaleX()) + insets.x; final int y = (int) Math.round(rect.getY() * this.getScaleY()) + insets.y; final int w = (int) Math.round(rect.getWidth() * this.getScaleX()); final int h = (int) Math.round(rect.getHeight() * this.getScaleY()); return new Rectangle(x, y, w, h); }