List of usage examples for java.awt.geom Rectangle2D getWidth
public abstract double getWidth();
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
protected int findCursorOnSelectedItem(int x, int y) { if (getSelectedMask() != null && !getSelectedMask().getRectangleFrame().isEmpty()) { Rectangle2D screenArea = getScreenDataArea(); Rectangle2D maskArea = ChartMaskingUtilities .translateChartRectangle(getSelectedMask(), getScreenDataArea(), getChart()) .getRectangleFrame();/*w w w . j ava2 s . com*/ Rectangle2D intersect = screenArea.createIntersection(maskArea); Point2D point = new Point2D.Double(x, y); double minX = maskArea.getMinX(); double maxX = maskArea.getMaxX(); double minY = maskArea.getMinY(); double maxY = maskArea.getMaxY(); double width = maskArea.getWidth(); double height = maskArea.getHeight(); if (!intersect.isEmpty() && screenArea.contains(point)) { // if (y > minY && y < maxY) { // if (minX > screenArea.getMinX() + 1 // && minX < screenArea.getMaxX() - 1) { // if (x > minX - 4 && x < minX + (width < 8 ? width / 2 : 4)) { // return Cursor.W_RESIZE_CURSOR; // } // } // if (maxX > screenArea.getMinX() + 1 // && maxX < screenArea.getMaxX() - 1) { // if (x > maxX - (width < 8 ? width / 2 : 4) && x < maxX + 4) { // return Cursor.E_RESIZE_CURSOR; // } // } // } if (height > 8 && width > 8) { Rectangle2D center = new Rectangle2D.Double(minX + 4, minY + 4, width - 8, height - 8); if (screenArea.createIntersection(center).contains(point)) { return Cursor.MOVE_CURSOR; } } if (height > 8) { Rectangle2D west = new Rectangle2D.Double(minX - 4, minY + 4, width < 8 ? width / 2 + 4 : 8, height - 8); if (screenArea.createIntersection(west).contains(point)) { return Cursor.W_RESIZE_CURSOR; } Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY + 4, width < 8 ? width / 2 + 4 : 8, height - 8); if (screenArea.createIntersection(east).contains(point)) { return Cursor.E_RESIZE_CURSOR; } } if (width > 8) { Rectangle2D north = new Rectangle2D.Double(minX + 4, minY - 4, width - 8, height < 8 ? height / 2 + 4 : 8); if (screenArea.createIntersection(north).contains(point)) { return Cursor.N_RESIZE_CURSOR; } Rectangle2D south = new Rectangle2D.Double(minX + 4, maxY - (height < 8 ? height / 2 : 4), width - 8, height < 8 ? height / 2 + 4 : 8); if (screenArea.createIntersection(south).contains(point)) { return Cursor.S_RESIZE_CURSOR; } } Rectangle2D northwest = new Rectangle2D.Double(minX - 4, minY - 4, width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8); if (screenArea.createIntersection(northwest).contains(point)) { return Cursor.NW_RESIZE_CURSOR; } Rectangle2D northeast = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY - 4, width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8); if (screenArea.createIntersection(northeast).contains(point)) { return Cursor.NE_RESIZE_CURSOR; } Rectangle2D southwest = new Rectangle2D.Double(minX - 4, maxY - (height < 8 ? height / 2 : 4), width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8); if (screenArea.createIntersection(southwest).contains(point)) { return Cursor.SW_RESIZE_CURSOR; } Rectangle2D southeast = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), maxY - (height < 8 ? height / 2 : 4), width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8); if (screenArea.createIntersection(southeast).contains(point)) { return Cursor.SE_RESIZE_CURSOR; } } // System.out.println("intersect X:[" + intersect.getMinX() + ", " + // (intersect.getMinX() + intersect.getWidth()) + // "], Y:[" + intersect.getMinY() + ", " + // (intersect.getMinY() + intersect.getHeight()) + // "], x=" + point.getX() + ", y=" + point.getY() + // " " + intersect.contains(point)); } return Cursor.DEFAULT_CURSOR; }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Returns the data area for the chart (the area inside the axes) with the * current scaling applied./*from w ww . j a v a2 s . c om*/ * * @return the scaled data area. */ public Rectangle2D getScaledDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Insets insets = getInsets(); // double x = dataArea.getX() * scaleX + insets.left; // double y = dataArea.getY() * scaleY + insets.top; // double w = dataArea.getWidth() * scaleX; // double h = dataArea.getHeight() * scaleY; // return new Rectangle2D.Double(x, y, w, h); double x = dataArea.getX() + insets.left; double y = dataArea.getY() + insets.top; double w = dataArea.getWidth(); double h = dataArea.getHeight(); return new Rectangle2D.Double(x, y, w, h); }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChart(Set<QuantDiseaseGroupsComparison> selectedComparisonList) { if (userCustomizedComparison != null) { return updateBubbleChartChartWithCustUserData(selectedComparisonList); }//from ww w . ja v a 2 s . co m tooltipsProtNumberMap.clear(); DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2 || qp.getSignificantTrindCategory() == 5) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { double[] tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[3] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[x] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.LIGHT_GRAY }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int i = 0; @Override public RectangleInsets getTickLabelInsets() { // System.out.println("at ---- super.getTickLabelInsets() " + super.getTickLabelInsets()); // if (i == 0) { // i++; // return new RectangleInsets(-5, -5, 0, 0); // }else // return super.getTickLabelInsets(); //To change body of generated methods, choose Tools | Templates. } int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 2]; int x = 0; xAxisLabels[x] = ""; int maxLength = -1; //init labels color final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 2]; diseaseGroupslabelsColor[x] = Color.WHITE; x++; for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); String updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x].length() > maxLength) { maxLength = xAxisLabels[x].length(); } diseaseGroupslabelsColor[x] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x] = ""; diseaseGroupslabelsColor[x] = Color.WHITE; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); // legend.setMargin(20, 0, 0, 0); //// legend.setBorder(1, 1, 1, 1); // legend.setFrame(new BlockBorder(1, 0, 1, 0, Color.LIGHT_GRAY)); // generatedChart.removeLegend(); // xyplot.setForegroundAlpha(0.65F); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); // exporter.writeChartToPDFFile(generatedChart, 595, 842, "bublechart.pdf"); return generatedChart; }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChartWithCustUserData( Set<QuantDiseaseGroupsComparison> selectedComparisonList) { tooltipsProtNumberMap.clear();// w w w . j a va 2 s.c o m DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); if (userCustomizedComparison.getComparProtsMap().size() > upper) { upper = userCustomizedComparison.getComparProtsMap().size(); } for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] tempWidthValue = new double[8]; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (String key : userCustomizedComparison.getComparProtsMap().keySet()) { userCustomizedComparison.getComparProtsMap().get(key).updateLabelLayout(); { tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key) .getSignificantTrindCategory() + 1] + 1; } } int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(userCustomizedComparison.getComparisonHeader(), tooltipNumbess); for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { tempWidthValue[z] = scaleValues(tempWidthValue[z], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { xAxisValue[length] = z; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[z]; serColorArr[length] = dataColor[z]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(++counter, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(userCustomizedComparison.getComparisonHeader(), seriesValues); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[6] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; length = 0; if (upper < 10) { upper = 10; } tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } yAxisValue = new double[length]; xAxisValue = new double[length]; widthValue = new double[length]; serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); seriesValues = new double[][] { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.WHITE, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.WHITE }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 3]; xAxisLabels[0] = " "; final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 3]; int x = 0; int maxLength = -1; //init labels color String updatedHeader = userCustomizedComparison.getComparisonHeader().split(" / ")[0].split("\n")[0] + " / " + userCustomizedComparison.getComparisonHeader().split(" / ")[1].split("\n")[0] + ""; diseaseGroupslabelsColor[0] = Color.WHITE; diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get("UserData"); xAxisLabels[x + 1] = updatedHeader + " (" + userCustomizedComparison.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[++x].length(); } for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x + 1] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[x + 1].length(); } diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x + 1] = " "; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); return generatedChart; }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Handles a 'mouse dragged' event.//from ww w. j a v a 2 s. c o m * * @param e the mouse event. */ public void mouseDragged(MouseEvent e) { // if the popup menu has already been triggered, then ignore dragging... if (this.popup != null && this.popup.isShowing()) { return; } // if no initial zoom point was set, ignore dragging... if (this.zoomPoint == null) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // Erase the previous zoom rectangle (if any)... drawRectangle(g2); boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.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()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(), xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY()); } else if (hZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(), xmax - this.zoomPoint.getX(), scaledDataArea.getHeight()); } else if (vZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(), scaledDataArea.getWidth(), ymax - this.zoomPoint.getY()); } // Draw the new zoom rectangle... drawRectangle(g2); g2.dispose(); }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
public Dimension getPreferredSize() { final ElementRenderer rendererRoot = getElementRenderer(); if (rendererRoot == null) { return new Dimension(0, 0); }/* ww w . j a v a2 s. c o m*/ final float zoom = getRenderContext().getZoomModel().getZoomAsPercentage(); try { final Rectangle2D bounds = rendererRoot.getBounds(); final int leftBorder; if (isShowLeftBorder()) { leftBorder = (int) getLeftBorder(); } else { leftBorder = 0; } final int topBorder; if (isShowTopBorder()) { topBorder = (int) getTopBorder(); } else { topBorder = 0; } final int width = (int) (zoom * (leftBorder + bounds.getWidth())); final int height = (int) (zoom * (topBorder + bounds.getHeight())); return new Dimension(width, height); } catch (Exception e) { UncaughtExceptionsModel.getInstance().addException(e); return new Dimension(0, (int) (zoom * rendererRoot.getVisualHeight())); } }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
protected int findCursorOnSelectedItem(int x, int y) { if (isInternalLegendEnabled && isInternalLegendSelected) { Rectangle2D screenArea = getScreenDataArea(); Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(), screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(), internalLegendSetup.getHeight()); Rectangle2D intersect = screenArea.createIntersection(legendArea); Point2D point = new Point2D.Double(x, y); double minX = legendArea.getMinX(); double maxX = legendArea.getMaxX(); double minY = legendArea.getMinY(); double width = legendArea.getWidth(); double height = legendArea.getHeight(); if (!intersect.isEmpty() && screenArea.contains(point)) { if (width > 8) { Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height); if (screenArea.createIntersection(center).contains(point)) { return Cursor.MOVE_CURSOR; }// w ww. ja v a 2 s . c o m } Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height); if (screenArea.createIntersection(west).contains(point)) { return Cursor.W_RESIZE_CURSOR; } Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY, width < 8 ? width / 2 + 4 : 8, height); if (screenArea.createIntersection(east).contains(point)) { return Cursor.E_RESIZE_CURSOR; } } } else if (getSelectedMask() != null && !getSelectedMask().isEmpty()) { Rectangle2D screenArea = getScreenDataArea(); Rectangle2D maskArea = ChartMaskingUtilities.getDomainMaskFrame(getSelectedMask(), getScreenDataArea(), getChart()); Rectangle2D intersect = screenArea.createIntersection(maskArea); Point2D point = new Point2D.Double(x, y); double minX = maskArea.getMinX(); double maxX = maskArea.getMaxX(); double minY = maskArea.getMinY(); double width = maskArea.getWidth(); double height = maskArea.getHeight(); if (!intersect.isEmpty() && screenArea.contains(point)) { if (width > 8) { Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height); if (screenArea.createIntersection(center).contains(point)) { return Cursor.MOVE_CURSOR; } } Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height); if (screenArea.createIntersection(west).contains(point)) { return Cursor.W_RESIZE_CURSOR; } Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY, width < 8 ? width / 2 + 4 : 8, height); if (screenArea.createIntersection(east).contains(point)) { return Cursor.E_RESIZE_CURSOR; } } } return Cursor.DEFAULT_CURSOR; }
From source file:org.gumtree.vis.awt.JChartPanel.java
private void selectText(double xNew, double yNew) { for (Entry<Rectangle2D, String> item : textContentMap.entrySet()) { Rectangle2D rect = item.getKey(); Point2D screenPoint = ChartMaskingUtilities.translateChartPoint( new Point2D.Double(rect.getMinX(), rect.getMinY()), getScreenDataArea(), getChart()); Rectangle2D screenRect = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, rect.getWidth(), rect.getHeight()); if (screenRect.contains(xNew, yNew)) { if (selectedTextWrapper == rect) { selectedTextWrapper = null; } else { selectedTextWrapper = rect; setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); return; }//from w ww . j a va2s . c om } } if (selectedTextWrapper != null) { selectedTextWrapper = null; } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse released' event.//from w w w. j av a2s . com * <P> * On Windows, we need to check if this is a popup trigger, but only if we * haven't already been tracking a zoom rectangle. * * @param e Information about the event. */ public void mouseReleased(MouseEvent e) { if (zoomRectangle != null) { // if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) { if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) { if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) { autoRangeBoth(); } else { double x, y, w, h; Rectangle2D scaledDataArea = getScaledDataArea(); //for a mouseReleased event, (horizontalZoom || verticalZoom) //will be true, so we can just test for either being false; //otherwise both are true if (!verticalZoom) { x = zoomPoint.getX(); y = scaledDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = scaledDataArea.getHeight(); } else if (!horizontalZoom) { x = scaledDataArea.getMinX(); y = zoomPoint.getY(); w = scaledDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } g2.dispose(); this.zoomRectangle = null; } // notify a redraw event CoreStatusEvent ev = new CoreStatusEvent(this); ev.setType(CoreStatusEvent.REDRAW); ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev); } else if (e.isPopupTrigger()) { if (popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:spinworld.gui.RadarPlot.java
/** * Draws the label for one axis.//from w ww .j a va 2s .c o m * * @param g2 the graphics device. * @param plotArea whole plot drawing area (e.g. including space for labels) * @param plotDrawingArea the plot drawing area (just spanning of axis) * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, Rectangle2D plotDrawingArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } double angle = normalize(startAngle); Font font = getLabelFont(); Point2D labelLocation; do { Rectangle2D labelBounds = font.getStringBounds(label, frc); LineMetrics lm = font.getLineMetrics(label, frc); double ascent = lm.getAscent(); labelLocation = calculateLabelLocation(labelBounds, ascent, plotDrawingArea, startAngle); boolean leftOut = angle > 90 && angle < 270 && labelLocation.getX() < plotArea.getX(); boolean rightOut = (angle < 90 || angle > 270) && labelLocation.getX() + labelBounds.getWidth() > plotArea.getX() + plotArea.getWidth(); if (leftOut || rightOut) { font = font.deriveFont(font.getSize2D() - 1); } else { break; } } while (font.getSize() > 8); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(font); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); }