List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:de.codesourcery.planning.swing.PlanningCanvas.java
private BoundingBox renderSlotTitle(IFactorySlot slot, RenderContext ctx, boolean layoutOnly) { final String label = labelProvider.getLabel(slot); if (StringUtils.isBlank(label)) { return null; }/*from w ww . j a v a 2 s .c o m*/ final Rectangle2D labelBounds = ctx.getLabelBounds(label); final int y = ctx.currentY; int width; if (!layoutOnly) { width = ctx.xTimelineStart; ctx.drawLabel(ctx.viewport.getX(), y, label); } else { width = (int) (labelBounds.getWidth() + ctx.options.getSlotTitleRightBorder()); } final BoundingBox boundingBox = createBoundingBox(ctx.viewport.getX(), y, width, (int) labelBounds.getHeight()); // make sure all slot titles are rendered // at the same width ( = width of longest slot title) if (layoutOnly && width > ctx.xTimelineStart) { ctx.xTimelineStart = ctx.viewport.getX() + width; } return boundingBox; }
From source file:savant.view.swing.GraphPane.java
private void drawMessageHelper(Graphics2D g2, String message, Font font, int w, int h, int offset) { g2.setFont(font);/* w w w . j av a 2 s . c om*/ FontMetrics metrics = g2.getFontMetrics(); Rectangle2D stringBounds = font.getStringBounds(message, g2.getFontRenderContext()); int preferredWidth = (int) stringBounds.getWidth() + metrics.getHeight(); int preferredHeight = (int) stringBounds.getHeight() + metrics.getHeight(); w = Math.min(preferredWidth, w); h = Math.min(preferredHeight, h); int x = (getWidth() - (int) stringBounds.getWidth()) / 2; int y = (getHeight() / 2) + ((metrics.getAscent() - metrics.getDescent()) / 2) + offset; g2.drawString(message, x, y); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void mouseDragged(MouseEvent e) { // when not allowed to zoom / select, return if (blockSelectionOrZoom) { return;// w w w . j a v a 2s . c o m } // if the popup menu has already been triggered, then ignore dragging... if (getChartFieldValueByName("popup") != null && ((JPopupMenu) getChartFieldValueByName("popup")).isShowing()) { return; } // handle panning if we have a start point if (getChartFieldValueByName("panLast") != null) { double dx = e.getX() - ((Point) getChartFieldValueByName("panLast")).getX(); double dy = e.getY() - ((Point) getChartFieldValueByName("panLast")).getY(); if (dx == 0.0 && dy == 0.0) { return; } double wPercent = -dx / ((Double) getChartFieldValueByName("panW")); double hPercent = dy / ((Double) getChartFieldValueByName("panH")); boolean old = getChart().getPlot().isNotify(); getChart().getPlot().setNotify(false); Pannable p = (Pannable) getChart().getPlot(); if (p.getOrientation() == PlotOrientation.VERTICAL) { p.panDomainAxes(wPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); p.panRangeAxes(hPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); } else { p.panDomainAxes(hPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); p.panRangeAxes(wPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); } setChartFieldValue((getChartFieldByName("panLast")), e.getPoint()); getChart().getPlot().setNotify(old); return; } // if no initial zoom point was set, ignore dragging... if (getChartFieldValueByName("zoomPoint") == null) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // erase the previous zoom rectangle (if any). We only need to do // this is we are using XOR mode, which we do when we're not using // the buffer (if there is a buffer, then at the end of this method we // just trigger a repaint) if (!(Boolean) getChartFieldValueByName("useBuffer")) { drawZoomRectangle(g2, true); } boolean hZoom = false; boolean vZoom = false; if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) { hZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); vZoom = (Boolean) getChartFieldValueByName("domainZoomable"); } else { hZoom = (Boolean) getChartFieldValueByName("domainZoomable"); vZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); } Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint"); Rectangle2D scaledDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY()); if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(), zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY())); } else if (hZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(), scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight())); } else if (vZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(), ymax - zoomPoint.getY())); } // Draw the new zoom rectangle... if ((Boolean) getChartFieldValueByName("useBuffer")) { repaint(); } else { // with no buffer, we use XOR to draw the rectangle "over" the // chart... drawZoomRectangle(g2, true); } g2.dispose(); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. */// www . j a va 2 s .c om public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // if buffer is being refreshed, it needs clearing unless it is // new - use the following flag to track this... boolean clearBuffer = true; // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? if (this.refreshBuffer) { this.refreshBuffer = false; // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (clearBuffer) { bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight); } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } } g2.drawImage(this.chartBuffer, insets.left, insets.top, this); g2.draw((Shape) activeROI.getShapesList().get(1)); // Dibujar las rois que se encuentren activas } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.drawImage(this.chartBuffer, insets.left, insets.top, this); // Se pintan las Roi activa drawsROIs(g2); g2.setTransform(saved); } g2.dispose(); this.anchor = null; }
From source file:probe.com.view.body.quantdatasetsoverview.quantproteinstabsheet.studies.ProteinStudyComparisonScatterPlotLayout.java
/** * Creates a sample jFreeChart./*from w w w. j a v a2 s.co m*/ * * @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:org.apache.fop.render.pcl.PCLRenderer.java
/** * Draw an image at the indicated location. * @param uri the URI/URL of the image// w w w . j ava2 s. co m * @param pos the position of the image * @param foreignAttributes an optional Map with foreign attributes, may be null */ protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) { uri = URISpecification.getURL(uri); Rectangle posInt = new Rectangle((int) pos.getX(), (int) pos.getY(), (int) pos.getWidth(), (int) pos.getHeight()); Point origin = new Point(currentIPPosition, currentBPPosition); int x = origin.x + posInt.x; int y = origin.y + posInt.y; ImageManager manager = getUserAgent().getFactory().getImageManager(); ImageInfo info = null; try { ImageSessionContext sessionContext = getUserAgent().getImageSessionContext(); info = manager.getImageInfo(uri, sessionContext); //Only now fully load/prepare the image Map hints = ImageUtil.getDefaultHints(sessionContext); org.apache.xmlgraphics.image.loader.Image img = manager.getImage(info, FLAVORS, hints, sessionContext); //...and process the image if (img instanceof ImageGraphics2D) { ImageGraphics2D imageG2D = (ImageGraphics2D) img; RendererContext context = createRendererContext(posInt.x, posInt.y, posInt.width, posInt.height, foreignAttributes); getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(), context, x, y, posInt.width, posInt.height); } else if (img instanceof ImageRendered) { ImageRendered imgRend = (ImageRendered) img; RenderedImage ri = imgRend.getRenderedImage(); setCursorPos(x, y); gen.paintBitmap(ri, new Dimension(posInt.width, posInt.height), false); } else if (img instanceof ImageXMLDOM) { ImageXMLDOM imgXML = (ImageXMLDOM) img; renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(), pos, foreignAttributes); } else { throw new UnsupportedOperationException("Unsupported image type: " + img); } } catch (ImageException ie) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageError(this, (info != null ? info.toString() : uri), ie, null); } catch (FileNotFoundException fe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageNotFound(this, (info != null ? info.toString() : uri), fe, null); } catch (IOException ioe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageIOError(this, (info != null ? info.toString() : uri), ioe, null); } }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * {@inheritDoc}/*from w w w.ja v a2 s . c o m*/ * @todo Copied from AbstractPathOrientedRenderer */ protected void handleRegionTraits(RegionViewport region) { Rectangle2D viewArea = region.getViewArea(); float startx = (float) (viewArea.getX() / 1000f); float starty = (float) (viewArea.getY() / 1000f); float width = (float) (viewArea.getWidth() / 1000f); float height = (float) (viewArea.getHeight() / 1000f); if (region.getRegionReference().getRegionClass() == FO_REGION_BODY) { currentBPPosition = region.getBorderAndPaddingWidthBefore(); currentIPPosition = region.getBorderAndPaddingWidthStart(); } drawBackAndBorders(region, startx, starty, width, height); }
From source file:org.apache.fop.render.ps.PSRenderer.java
/** {@inheritDoc} */ protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) { endTextObject();//from www . j av a2 s . com int x = currentIPPosition + (int) Math.round(pos.getX()); int y = currentBPPosition + (int) Math.round(pos.getY()); uri = URISpecification.getURL(uri); if (log.isDebugEnabled()) { log.debug("Handling image: " + uri); } int width = (int) pos.getWidth(); int height = (int) pos.getHeight(); Rectangle targetRect = new Rectangle(x, y, width, height); ImageManager manager = getUserAgent().getFactory().getImageManager(); ImageInfo info = null; try { ImageSessionContext sessionContext = getUserAgent().getImageSessionContext(); info = manager.getImageInfo(uri, sessionContext); PSRenderingContext renderingContext = new PSRenderingContext(getUserAgent(), gen, getFontInfo()); if (!isOptimizeResources() || PSImageUtils.isImageInlined(info, renderingContext)) { if (log.isDebugEnabled()) { log.debug("Image " + info + " is inlined"); } //Determine supported flavors ImageFlavor[] flavors; ImageHandlerRegistry imageHandlerRegistry = userAgent.getFactory().getImageHandlerRegistry(); flavors = imageHandlerRegistry.getSupportedFlavors(renderingContext); //Only now fully load/prepare the image Map hints = ImageUtil.getDefaultHints(sessionContext); org.apache.xmlgraphics.image.loader.Image img = manager.getImage(info, flavors, hints, sessionContext); //Get handler for image ImageHandler basicHandler = imageHandlerRegistry.getHandler(renderingContext, img); //...and embed as inline image basicHandler.handleImage(renderingContext, img, targetRect); } else { if (log.isDebugEnabled()) { log.debug("Image " + info + " is embedded as a form later"); } //Don't load image at this time, just put a form placeholder in the stream PSResource form = getFormForImage(info.getOriginalURI()); PSImageUtils.drawForm(form, info, targetRect, gen); } } catch (ImageException ie) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageError(this, (info != null ? info.toString() : uri), ie, null); } catch (FileNotFoundException fe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageNotFound(this, (info != null ? info.toString() : uri), fe, null); } catch (IOException ioe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageIOError(this, (info != null ? info.toString() : uri), ioe, null); } }
From source file:extern.NpairsBoxAndWhiskerRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a horizontal orientation./*www . j a v a2 s .c o m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset (must be an instance of * {@link BoxAndWhiskerCategoryDataset}). * @param row the row index (zero-based). * @param column the column index (zero-based). */ public void 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(); double widthWeWannaUse = Math.min(state.getBarWidth(), dataArea.getWidth() / 10); if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); // double usedWidth = (state.getBarWidth() * seriesCount) // + (seriesGap * (seriesCount - 1)); double usedWidth = (widthWeWannaUse * 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)); yy = yy + offset + (row * (widthWeWannaUse + seriesGap)); } else { // offset the start of the box if the box width is smaller than // the category width // double offset = (categoryWidth - state.getBarWidth()) / 2; double offset = (categoryWidth - widthWeWannaUse) / 2; yy = yy + offset; } g2.setPaint(getItemPaint(row, column)); 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; double yymid = yy + widthWeWannaUse / 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())); g2.draw(new Line2D.Double(xxMax, yy, xxMax, yy + widthWeWannaUse)); // draw the lower shadow... g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid)); // g2.draw(new Line2D.Double(xxMin, yy, xxMin, // yy + state.getBarWidth())); g2.draw(new Line2D.Double(xxMin, yy, xxMin, yy + widthWeWannaUse)); // draw the box... // box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, // Math.abs(xxQ1 - xxQ3), state.getBarWidth()); box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), widthWeWannaUse); if (this.fillBox) { g2.fill(box); } g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); 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; aRadius = widthWeWannaUse / 4; // here we check that the average marker will in fact be visible // before drawing it... if ((xxMean > (dataArea.getMinX() - aRadius)) && (xxMean < (dataArea.getMaxX() + aRadius))) { 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())); g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + widthWeWannaUse)); } // collect entity and tool tip information... if (state.getInfo() != null && box != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, box); } } }
From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;/*from ww w .ja va 2 s . c o m*/ } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }