List of usage examples for java.awt.geom Rectangle2D getY
public abstract double getY();
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 ww w . j av a 2 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: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 . j a v a 2s . c o m*/ * @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:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * draw the time line/*from ww w.j a v a2 s . c o m*/ * * @param g2 param * @param plot param * @param dataArea param * @param domainAxis param * @param rangeAxis param * @param rendererIndex param * @param info param */ private void drawTime(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { try { Animation animation = control.getSomeAnimation(); if (animation == null) { return; } Real dttm = animation.getAniValue(); if (dttm == null) { return; } g2.setStroke(new BasicStroke()); g2.setColor(Color.black); double timeValue = dttm.getValue(CommonUnit.secondsSinceTheEpoch); int x = (int) domainAxis.valueToJava2D(timeValue * 1000, dataArea, RectangleEdge.BOTTOM); if ((x < dataArea.getX()) || (x > dataArea.getX() + dataArea.getWidth())) { return; } int bottom = (int) (dataArea.getY() + dataArea.getHeight()); int top = (int) (dataArea.getY()); int offset = 0; if (false && (clockImage == null)) { clockImage = GuiUtils.getImage("/auxdata/ui/icons/clock.gif"); clockImage.getHeight(this); offset = clockImage.getHeight(null); } // g2.drawLine(x, (int) dataArea.getY(), x, bottom - offset); int w = 8; int w2 = w / 2; int[] xs = { x - w2, x, x + w2, x }; int[] ys = { top, top + w, top, top }; // g2.drawLine(x, top, x, top+10); g2.fillPolygon(xs, ys, xs.length); if (clockImage != null) { g2.drawImage(clockImage, x - clockImage.getWidth(null) / 2, bottom - clockImage.getHeight(null), null); } } catch (VisADException exc) { } catch (RemoteException exc) { } }
From source file:org.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; }/* w w w . ja v a2 s.com*/ 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.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected boolean installEditor(final ReportElementInlineEditor inlineEditor, final Element element) { if (inlineEditor == null) { throw new NullPointerException(); }//from w w w. jav a 2s . c o m this.inlineEditor = inlineEditor; final CachedLayoutData data = ModelUtility.getCachedLayoutData(element); if (data == null) { removeEditor(); return false; } final Component editorComponent = inlineEditor.getElementCellEditorComponent(this, element); if (editorComponent == null) { removeEditor(); return false; } if (editorRemover == null) { final KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); editorRemover = new CellEditorRemover(fm); fm.addPropertyChangeListener("permanentFocusOwner", editorRemover); // NON-NLS } this.editorComponent = editorComponent; final float zoomFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); final Rectangle2D bounds = getElementRenderer().getBounds(); final int x = (int) ((getLeftBorder() + StrictGeomUtility.toExternalValue(data.getX())) * zoomFactor); final int y = (int) ((getTopBorder() + (StrictGeomUtility.toExternalValue(data.getY()) - bounds.getY()) * zoomFactor)); final int width = (int) (StrictGeomUtility.toExternalValue(data.getWidth()) * zoomFactor); final int height = (int) (StrictGeomUtility.toExternalValue(data.getHeight()) * zoomFactor); editorComponent.setBounds(x, y, width, height); add(editorComponent); editorComponent.validate(); inlineEditor.addCellEditorListener(this); List<Element> selectedElements = getRenderContext().getSelectionModel() .getSelectedElementsOfType(Element.class); final Element[] visualElements = selectedElements.toArray(new Element[selectedElements.size()]); if (visualElements.length > 0) { oldValues = new ArrayList<Object>(); for (int i = 0; i < visualElements.length; i++) { final Object attribute = visualElements[i].getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE); oldValues.add(attribute); } } return true; }
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 www .j a va 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.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;/*from w ww. j a va2 s . c o 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: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). * /*w ww .ja v a 2s. co 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:com.isti.traceview.common.TraceViewChartPanel.java
/** * Applies any scaling that is in effect for the chart drawing to the given rectangle. * /*ww w .ja v a 2 s .c o m*/ * @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); }
From source file:com.isti.traceview.common.TraceViewChartPanel.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 . j a v a2 s . c om*/ * @return The scaled data area. */ public Rectangle2D getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Insets insets = getInsets(); double x = dataArea.getX() * this.scaleX + insets.left; double y = dataArea.getY() * this.scaleY + insets.top; double w = dataArea.getWidth() * this.scaleX; double h = dataArea.getHeight() * this.scaleY; return new Rectangle2D.Double(x, y, w, h); }