List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
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 . ja va 2 s . com * * @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: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();//from w w w .j ava 2 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
/** * Handles a 'mouse released' event./*from w ww . j ava 2 s. 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:gda.plots.TurboXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself.//from w w w . j a v a 2s . c om * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item, CrosshairState crosshairState, int pass) { if (_item > 0) return; SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); try { int x0 = -1; // the x position in pixels of the previous point int y0 = -1; // the y position in pixels of the previous point int x1 = -1; // the x position in pixels of the current point int y1 = -1; // the y position in pixels of the current point int xmin = (int) dataArea.getMinX(); int xmax = (int) dataArea.getMaxX(); int ymin = (int) dataArea.getMinY(); int ymax = (int) dataArea.getMaxY(); GeneralPath path = null; /* * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear * maths */ double xl = 0., mx = Double.NaN, cx = 0.; if (domainAxis instanceof SimpleNumberAxis) { xl = domainAxis.getRange().getLowerBound(); mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl); cx = xmin; } double yl = 0., my = Double.NaN, cy = 0.; if (rangeAxis instanceof SimpleNumberAxis) { yl = rangeAxis.getRange().getLowerBound(); my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl); cy = ymax; } List<XYDataItem> list = sxys.getData(); boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my); Paint paint = sxys.getPaint(); Stroke stroke = sxys.getStroke(); Paint paint_symbol = sxys.getSymbolPaint(); Stroke stroke_symbol = new BasicStroke(); drawLines = sxys.isDrawLines(); boolean filled = sxys.getFilled(); Shape shape = sxys.getSymbol(); boolean drawMarkers = sxys.isDrawMarkers() & shape != null; int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */ if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) { Rectangle shapeBoundingBox = shape.getBounds(); tooltipThresholdCounts = (int) dataArea.getWidth() / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold); } java.util.Vector<ddouble> markerPositions = null; Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } boolean prevLineAdded = false; // In case the iterator does not work then use the TODO comment iterator use and why not always // comment variables synchronized (list) { Iterator<XYDataItem> iter = list.iterator(); /* * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The * variable addThis determines if the current point is to be added to the path If previous line was * added that the current must be even if off the screen - but in this case the flag prevLineAdded is * set false so that the next does not have to be added. */ for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) { XYDataItem dataitem = iter.next(); double x = dataitem.getX().doubleValue(); double y = dataitem.getY().doubleValue(); x = xValueTransformer.transformValue(x); x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation) : (int) ((x - xl) * mx + cx); y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) : (int) ((y - yl) * my + cy); boolean addThis = true; if (item == 0) { x0 = x1; y0 = y1; if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) { addThis = false; } } else { if (x1 == x0 && y1 == y0) { addThis = false; } if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin) || (y1 > ymax && y0 > ymax)) { if (prevLineAdded) { path = addPointToLine(path, orientation, x1, y1); } addThis = false; } } if (addThis) { /* * If the current point is to be added then ensure previous one is as well to prevent lines * not crossing the edge of the screen */ if (!prevLineAdded) { path = addPointToLine(path, orientation, x0, y0); } path = addPointToLine(path, orientation, x1, y1); prevLineAdded = true; } prevLineAdded = addThis; if (addThis && drawMarkers) { if (markerPositions == null) { markerPositions = new java.util.Vector<ddouble>(); } markerPositions.add(new ddouble(item, x1, y1)); if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) { drawMarkers = false; markerPositions = null; } } } if (path != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(path); } if (markerPositions != null) { if (drawMarkers) { g2.setPaint(paint_symbol); g2.setStroke(stroke_symbol); for (ddouble dd : markerPositions) { Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y); if (filled) { g2.fill(shape_item); } else { g2.draw(shape_item); } entityArea = shape_item; // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y); } } g2.setPaint(paint); g2.setStroke(stroke); } } } } catch (Exception e) { e.printStackTrace(); } }
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; }//www . j a v a 2s.co 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.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
public Dimension getPreferredSize() { final ElementRenderer rendererRoot = getElementRenderer(); if (rendererRoot == null) { return new Dimension(0, 0); }//from w ww. ja v a2s . 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.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 www. ja v a 2 s. co m } } if (selectedTextWrapper != null) { selectedTextWrapper = null; } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse dragged' event./* w w w. j av a2 s . c om*/ * * @param e the mouse event. */ public void mouseDragged(MouseEvent e) { if (this.zoomingEnabled) { // if the popup menu has already been triggered, then ignore dragging... if (popup != null && popup.isShowing()) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // use XOR to erase the previous zoom rectangle (if any)... g2.setXORMode(java.awt.Color.gray); if (zoomRectangle != null) { if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } } Rectangle2D scaledDataArea = getScaledDataArea(); if (this.horizontalZoom && this.verticalZoom) { // 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()); zoomRectangle = new Rectangle2D.Double(zoomPoint.getX(), zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY()); } else if (this.horizontalZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); zoomRectangle = new Rectangle2D.Double(zoomPoint.getX(), scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight()); } else if (this.verticalZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(), ymax - zoomPoint.getY()); } if (zoomRectangle != null) { // use XOR to draw the new zoom rectangle... if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } } g2.dispose(); } }
From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java
/** * Draws a single task./*w ww.j a va 2 s. c o m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, TrackTaskSeriesCollection dataset, int row, int column, int pass) { log.debug("Working on item at position - column: " + column + " row: " + row); int seriesCount = getRowCount(); int categoryCount = getColumnCount(); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // Y0 Number value0 = dataset.getEndValue(row, column); if (value0 == null) { return; } double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // Y1 Number value1 = dataset.getStartValue(row, column); if (value1 == null) { return; } double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; Number tempNum = value1; value1 = value0; value0 = tempNum; } double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); // BREADTH double rectBreadth = state.getBarWidth(); // BAR HEIGHT double rectLength = Math.abs(java2dValue1 - java2dValue0); Rectangle2D bar = null; if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectStart = rectStart + row * (state.getBarWidth() + seriesGap); } else { rectStart = rectStart + row * state.getBarWidth(); } // correct the start/stop Bars point if (startBars > (int) (java2dValue1 - rectLength)) { this.startBars = (int) (java2dValue1 - rectLength); } if (stopBars < (int) java2dValue1) { stopBars = (int) java2dValue1; } // The coordinates for the bar labels int startLabelX = 0; int startLabelY = 0; int endLabelX = 0; int endLabelY = 0; int barLabelX = 0; int barLabelY = 0; Polygon outer = null; Polygon inner = null; boolean isMilestone = dataset.isMilestone(column, row); boolean isSupertask = dataset.isSupertask(column, row); if (isMilestone) { // The start point for the end date label endLabelX = (int) (java2dValue1 + rectBreadth / 2); endLabelY = (int) (rectStart + (3 * rectBreadth / 4)); barLabelX = (int) (java2dValue1 - rectBreadth / 2); barLabelY = (int) (rectStart + (3 * rectBreadth / 4)); int breadth = (int) rectBreadth; int centerX = (int) java2dValue1; int centerY = (int) (rectStart + rectBreadth / 2); int[] xPoints = { centerX, centerX - breadth / 2, centerX, centerX + breadth / 2 }; int[] yPoints = { centerY - breadth / 2, centerY, centerY + breadth / 2, centerY }; outer = new Polygon(xPoints, yPoints, 4); //calculate the difference from the ratio int diff = (int) (rectBreadth / (2 * msInfo.getRatio())); int[] xPointsI = { centerX, centerX - breadth / 2 + diff, centerX, centerX + breadth / 2 - diff }; int[] yPointsI = { centerY - breadth / 2 + diff, centerY, centerY + breadth / 2 - diff, centerY }; inner = new Polygon(xPointsI, yPointsI, 4); } else if (isSupertask) { // The start point for the end date label startLabelX = (int) (java2dValue1 - rectLength - rectBreadth / 2); startLabelY = (int) (rectStart + rectBreadth * 3 / 4); endLabelX = (int) (java2dValue1 + rectBreadth / 2); endLabelY = (int) (rectStart + rectBreadth * 3 / 4); barLabelX = (int) (java2dValue1 - rectLength + rectBreadth / 3); barLabelY = (int) (rectStart + rectBreadth); int breadth = (int) rectBreadth; int length = (int) rectLength; int startX = (int) (java2dValue1 - rectLength); int startY = (int) rectStart; int[] xPoints = { startX - breadth / 2, startX + length + breadth / 2, startX + length + breadth / 2, startX + length, startX + length - breadth / 2, startX + breadth / 2, startX, startX - breadth / 2 }; int[] yPoints = { startY, startY, startY + breadth / 2, startY + breadth, startY + breadth / 2, startY + breadth / 2, startY + breadth, startY + breadth / 2 }; outer = new Polygon(xPoints, yPoints, 8); //calculate the difference from the ratio int diff = (int) (rectBreadth / (2 * stInfo.getRatio())); int[] xPointsI = { startX - breadth / 2 + diff, startX + length + breadth / 2 - diff, startX + length + breadth / 2 - diff, startX + length, startX + length - breadth / 2 + diff, startX + length - breadth / 2 + diff, startX + breadth / 2 - diff, startX + breadth / 2 - diff, startX, startX - breadth / 2 + diff }; int[] yPointsI = { startY + diff, startY + diff, startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2, startY + breadth / 2 - diff, startY + breadth / 2 - diff, startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2 }; inner = new Polygon(xPointsI, yPointsI, 10); } else { rectBreadth = rectBreadth / 2.0; // The start point for the end date label startLabelX = (int) (java2dValue1 - rectLength); startLabelY = (int) (rectStart + rectBreadth * 3 / 4); endLabelX = (int) java2dValue1; endLabelY = (int) (rectStart + rectBreadth * 3 / 4); barLabelX = (int) (java2dValue1 - rectLength); barLabelY = (int) (rectStart); //+ rectBreadth * 4 / 3 ); bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth); // percent complete could be obtained in the // ReportBeans, set in the ReportBean and set in the Item by the GanttGenerator // currently this is not relevant. Rectangle2D completeBar = null; Rectangle2D incompleteBar = null; Number percent = dataset.getPercentComplete(row, column); double start = getStartPercent(); double end = getEndPercent(); if (percent != null) { double p = percent.doubleValue(); completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start)); incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start)); } /** This is for displaying e.g. (german Soll und Ist Termine). This implementation is designed to display only one Series. * If you need Soll und Ist, you can generate two gantt charts. * --->> Paint seriesPaint = getItemPaint (row, column); */ Paint seriesPaint = tsInfo.getInnerColor(); g2.setPaint(seriesPaint); g2.fill(bar); if (tsInfo.isDisplayIDLabel() && (!tsInfo.isDisplaySynopsis())) { // draw the tasks ID drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, tsInfo.getLabelFontID(), false, (int) rectLength); } else if (tsInfo.isDisplaySynopsis()) { if (tsInfo.isDisplayDateLabel()) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); label = dataset.getItem(column, row).getDescription() + " - " + label; drawLabel(label, g2, barLabelX, barLabelY, tsInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false); } else { drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true); } } if (tsInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); // draw the tasks start date drawLabel(label, g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the tasks end date drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false); } if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } // draw the outline... if (state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } } // Draw milestone or Supertask if (isMilestone) { g2.setPaint(msInfo.getOuterColor()); g2.fill(outer); g2.draw(outer); g2.setPaint(msInfo.getInnerColor()); g2.fill(inner); g2.draw(inner); Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(outer); } // draw the milestones due date if (msInfo.isDisplayDateLabel()) { // format milestone date to the requested format using the current locale String label = (new SimpleDateFormat(msInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); drawLabel(label, g2, endLabelX, endLabelY, msInfo.getLabelFont(), false); } if (msInfo.isDisplayIDLabel() && (!msInfo.isDisplaySynopsis())) { // for milestones the ID is aligned at the left side. drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, msInfo.getLabelFontID(), true, (int) rectLength); } else if (msInfo.isDisplaySynopsis()) { drawLabel(dataset.getItem(column, row).getDescription(), g2, barLabelX, barLabelY, msInfo.getLabelFont(), true, (int) rectLength); } } else if (isSupertask) { g2.setPaint(stInfo.getOuterColor()); g2.fill(outer); g2.draw(outer); g2.setPaint(stInfo.getInnerColor()); g2.fill(inner); g2.draw(inner); Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(outer); } // draw the supertasks ID if (stInfo.isDisplayIDLabel() && (!stInfo.isDisplaySynopsis())) { drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, stInfo.getLabelFontID(), false, (int) rectLength); } else if (stInfo.isDisplaySynopsis()) { if (stInfo.isDisplayDateLabel()) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); label = dataset.getItem(column, row).getDescription() + " - " + label; drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false); } else { drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); } } if (stInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); // draw the supertasks start date drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false); } } }
From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.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). * //from w w w.ja va2 s.c om * @return The scaled data area. */ public Rectangle getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Rectangle clientArea = this.getClientArea(); int x = (int) Math.round((dataArea.getX() * this.scaleX + clientArea.x)); int y = (int) Math.round((dataArea.getY() * this.scaleY + clientArea.y)); int w = (int) Math.round((dataArea.getWidth() * this.scaleX)); int h = (int) Math.round((dataArea.getHeight() * this.scaleY)); return new Rectangle(x, y, w, h); }