List of usage examples for java.awt.geom Rectangle2D getX
public abstract double getX();
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private int calcDropPosition(final AbstractElement destination, final Point dropPoint) { int result = DRAG_POSITION_UNKNOWN; if (destination.getClass() == ElementRoot.class) { result = dropPoint.getX() < destination.getBounds().getCenterX() ? DRAG_POSITION_LEFT : DRAG_POSITION_RIGHT;/*from ww w.jav a2 s.c o m*/ } else { final boolean destinationIsLeft = destination.isLeftDirection(); final Rectangle2D bounds = destination.getBounds(); if (bounds != null && dropPoint != null) { final double edgeOffset = bounds.getWidth() * 0.2d; if (dropPoint.getX() >= (bounds.getX() + edgeOffset) && dropPoint.getX() <= (bounds.getMaxX() - edgeOffset)) { result = dropPoint.getY() < bounds.getCenterY() ? DRAG_POSITION_TOP : DRAG_POSITION_BOTTOM; } else if (destinationIsLeft) { result = dropPoint.getX() < bounds.getCenterX() ? DRAG_POSITION_LEFT : DRAG_POSITION_UNKNOWN; } else { result = dropPoint.getX() > bounds.getCenterX() ? DRAG_POSITION_RIGHT : DRAG_POSITION_UNKNOWN; } } } return result; }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.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 ww. ja v a 2 s.com * @return The scaled data area. */ public Rectangle getScreenDataArea() { final Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); final Rectangle clientArea = this.getClientArea(); final int x = (int) (dataArea.getX() * this.scaleX + clientArea.x); final int y = (int) (dataArea.getY() * this.scaleY + clientArea.y); final int w = (int) (dataArea.getWidth() * this.scaleX); final int h = (int) (dataArea.getHeight() * this.scaleY); return new Rectangle(x, y, w, h); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private void drawDestinationElement(final Graphics2D g, final MindMapPanelConfig cfg) { if (this.destinationElement != null && this.draggedElement != null) { g.setColor(new Color((cfg.getSelectLineColor().getRGB() & 0xFFFFFF) | 0x80000000, true)); g.setStroke(new BasicStroke(this.config.safeScaleFloatValue(3.0f, 0.1f))); final Rectangle2D rectToDraw = new Rectangle2D.Double(); rectToDraw.setRect(this.destinationElement.getBounds()); final double selectLineGap = cfg.getSelectLineGap() * 3.0d * cfg.getScale(); rectToDraw.setRect(rectToDraw.getX() - selectLineGap, rectToDraw.getY() - selectLineGap, rectToDraw.getWidth() + selectLineGap * 2, rectToDraw.getHeight() + selectLineGap * 2); final int position = calcDropPosition(this.destinationElement, this.draggedElement.getPosition()); boolean draw = !this.draggedElement.isPositionInside() && !this.destinationElement.getModel().hasAncestor(this.draggedElement.getElement().getModel()); switch (this.draggedElement.getModifier()) { case NONE: { switch (position) { case DRAG_POSITION_TOP: { rectToDraw.setRect(rectToDraw.getX(), rectToDraw.getY(), rectToDraw.getWidth(), rectToDraw.getHeight() / 2); }//from w w w. ja v a2 s. co m break; case DRAG_POSITION_BOTTOM: { rectToDraw.setRect(rectToDraw.getX(), rectToDraw.getY() + rectToDraw.getHeight() / 2, rectToDraw.getWidth(), rectToDraw.getHeight() / 2); } break; case DRAG_POSITION_LEFT: { rectToDraw.setRect(rectToDraw.getX(), rectToDraw.getY(), rectToDraw.getWidth() / 2, rectToDraw.getHeight()); } break; case DRAG_POSITION_RIGHT: { rectToDraw.setRect(rectToDraw.getX() + rectToDraw.getWidth() / 2, rectToDraw.getY(), rectToDraw.getWidth() / 2, rectToDraw.getHeight()); } break; default: draw = false; break; } } break; case MAKE_JUMP: { } break; default: throw new Error("Unexpected state " + this.draggedElement.getModifier()); } if (draw) { g.fill(rectToDraw); } } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * On left axis//from w w w .j av a 2 s.co m * * @param mouseEvent the event * * @return on left axis */ private boolean isOnLeftRangeAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getY() < dataArea.getY()) { return false; } if (mouseEvent.getY() > dataArea.getY() + dataArea.getHeight()) { return false; } // System.err.println("mouse:" + mouseEvent.getX() +" da:" + dataArea); double left = dataArea.getX(); if (mouseEvent.getX() < left) { return true; } if (mouseEvent.getX() > left + 20) { return false; } return true; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) { if (paint instanceof Color) { final Color color = (Color) paint; final int alpha = color.getAlpha(); if (fill) { if (alpha != currentFillGState) { currentFillGState = alpha; PdfGState gs = fillGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(alpha / 255.00f); fillGState[alpha] = gs; }/* www . ja va2 s.c om*/ cb.setGState(gs); } cb.setColorFill(color); } else { if (alpha != currentStrokeGState) { currentStrokeGState = alpha; PdfGState gs = strokeGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setStrokeOpacity(alpha / 255.0f); strokeGState[alpha] = gs; } cb.setGState(gs); } cb.setColorStroke(color); } } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; final Point2D p1 = gp.getPoint1(); transform.transform(p1, p1); final Point2D p2 = gp.getPoint2(); transform.transform(p2, p2); final Color c1 = gp.getColor1(); final Color c2 = gp.getColor2(); final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(), normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2); final PdfShadingPattern pat = new PdfShadingPattern(shading); if (fill) { cb.setShadingFill(pat); } else { cb.setShadingStroke(pat); } } else if (paint instanceof TexturePaint) { try { final TexturePaint tp = (TexturePaint) paint; final BufferedImage img = tp.getImage(); final Rectangle2D rect = tp.getAnchorRect(); final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight()); final AffineTransform inverse = this.normalizeMatrix(); inverse.translate(rect.getX(), rect.getY()); inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight()); final double[] mx = new double[6]; inverse.getMatrix(mx); pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } else { try { int type = BufferedImage.TYPE_4BYTE_ABGR; if (paint.getTransparency() == Transparency.OPAQUE) { type = BufferedImage.TYPE_3BYTE_BGR; } final BufferedImage img = new BufferedImage((int) width, (int) height, type); final Graphics2D g = (Graphics2D) img.getGraphics(); g.transform(transform); final AffineTransform inv = transform.createInverse(); Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()); fillRect = inv.createTransformedShape(fillRect); g.setPaint(paint); g.fill(fillRect); if (invert) { final AffineTransform tx = new AffineTransform(); tx.scale(1, -1); tx.translate(-xoffset, -yoffset); g.drawImage(img, tx, null); } g.dispose(); // g = null; final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(width, height); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } }
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 a 2 s . co m*/ * * @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.plot1d.LogarithmizableAxis.java
/** * Converts a coordinate in Java2D space to the corresponding data * value, assuming that the axis runs along one edge of the specified * plotArea.//from ww w . j a va 2s.co m * * @param java2DValue the coordinate in Java2D space. * @param plotArea the area in which the data is plotted. * @param edge the axis location. * * @return The data value. */ public double java2DToLogValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) { Range range = getRange(); double axisMin = switchedLog10(range.getLowerBound()); double axisMax = switchedLog10(range.getUpperBound()); double plotMin = 0.0; double plotMax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { plotMin = plotArea.getX(); plotMax = plotArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { plotMin = plotArea.getMaxY(); plotMax = plotArea.getMinY(); } if (isInverted()) { return switchedPow10(axisMax - ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin)); } else { return switchedPow10(axisMin + ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin)); } }
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 ww . ja v a 2s .c o m * @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); }
From source file:org.gumtree.vis.awt.JChartPanel.java
private void drawTextInputBox(Graphics2D g2) { if (textInputFlag && textInputPoint != null) { // g2.drawChars("Input Text Here".toCharArray(), 1, 60, (int) textInputPoint.getX(), (int) textInputPoint.getY()); Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); String inputText = textInputContent == null ? "" : textInputContent; FontMetrics fm = g2.getFontMetrics(); // int sWidth; // if (textInputCursorIndex == 0 || inputText.length() == 0) { // sWidth = 0; // } else if (textInputCursorIndex < inputText.length()){ // sWidth = fm.stringWidth(inputText.substring(0, textInputCursorIndex)); // } else { // sWidth = fm.stringWidth(inputText); // } String[] lines = inputText.split("\n", 100); int cursorY = 0; int cursorX = 0; int charCount = 0; int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3 + i * 15); // charCount += lines[i].length() + 1; if (textInputCursorIndex > charCount && textInputCursorIndex < charCount + lines[i].length() + 1) { cursorY = i;// w w w.j a v a 2 s . co m cursorX = fm.stringWidth(lines[i].substring(0, textInputCursorIndex - charCount)); } else if (textInputCursorIndex == charCount + lines[i].length() + 1) { cursorY = i + 1; cursorX = 0; } charCount += lines[i].length() + 1; int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; // g2.drawString(inputText, (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3); g2.setColor(Color.MAGENTA); // g2.drawString("|", (float) textInputPoint.getX() + 2 + sWidth, (float) textInputPoint.getY() - 3); g2.drawLine((int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + (cursorY - 1) * 15, (int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + cursorY * 15); g2.setColor(Color.BLACK); g2.setColor(oldColor); // int boxWidth = fm.stringWidth(inputText) + 10; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(textInputPoint.getX(), textInputPoint.getY() - 15, maxWidth + 8, maxHeight); // ChartMaskingUtilities.drawMaskBoarder(g2, inputBox); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) textInputPoint.getX(), (int) textInputPoint.getY() - 15, maxWidth + 8, maxHeight); } if (textContentMap.size() > 0) { Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); Rectangle2D imageArea = getScreenDataArea(); for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) { Rectangle2D rect = entry.getKey(); Point2D screenPoint = ChartMaskingUtilities .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, getChart()); String text = entry.getValue(); if (text == null) { continue; } String[] lines = text.split("\n"); g2.setColor(Color.BLACK); for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15); } if (rect == selectedTextWrapper) { FontMetrics fm = g2.getFontMetrics(); int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight); } // g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3); } g2.setColor(oldColor); } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Applies any scaling that is in effect for the chart drawing to the given rectangle. * //from w w w. ja va 2s . com * @param rect * the rectangle. * @return A new scaled rectangle. */ public Rectangle2D scale(Rectangle2D rect) { Insets insets = getInsets(); double x = rect.getX() * getScaleX() + insets.left; double y = rect.getY() * this.getScaleY() + insets.top; double w = rect.getWidth() * this.getScaleX(); double h = rect.getHeight() * this.getScaleY(); return new Rectangle2D.Double(x, y, w, h); }