/** * Created an entity for the axis. * * @param cursor the initial cursor value. * @param state the axis state after completion of the drawing with a possibly updated cursor * position. * @param dataArea the data area. * @param edge the edge. * @param plotState the PlotRenderingInfo from which a reference to the entity collection can be * obtained. * @since 1.0.13 */ protected void createAndAddEntity( double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) { if (plotState == null || plotState.getOwner() == null) { return; // no need to create entity if we can´t save it anyways... } Rectangle2D hotspot = null; if (edge.equals(RectangleEdge.TOP)) { hotspot = new Rectangle2D.Double( dataArea.getX(), state.getCursor(), dataArea.getWidth(), cursor - state.getCursor()); } else if (edge.equals(RectangleEdge.BOTTOM)) { hotspot = new Rectangle2D.Double( dataArea.getX(), cursor, dataArea.getWidth(), state.getCursor() - cursor); } else if (edge.equals(RectangleEdge.LEFT)) { hotspot = new Rectangle2D.Double( state.getCursor(), dataArea.getY(), cursor - state.getCursor(), dataArea.getHeight()); } else if (edge.equals(RectangleEdge.RIGHT)) { hotspot = new Rectangle2D.Double( cursor, dataArea.getY(), state.getCursor() - cursor, dataArea.getHeight()); } EntityCollection e = plotState.getOwner().getEntityCollection(); if (e != null) { e.add(new AxisEntity(hotspot, this)); } }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; String message = "Hello, World!"; Font f = new Font("Serif", Font.BOLD, 36); g2.setFont(f); FontRenderContext context = g2.getFontRenderContext(); Rectangle2D bounds = f.getStringBounds(message, context); double x = (getWidth() - bounds.getWidth()) / 2; double y = (getHeight() - bounds.getHeight()) / 2; double ascent = -bounds.getY(); double baseY = y + ascent; g2.drawString(message, (int) x, (int) baseY); g2.setPaint(Color.LIGHT_GRAY); g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY)); Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight()); g2.draw(rect); }
/** * returns the skew transform * * @param svgHandle a svg handle * @param bounds the bounds of the area to transform * @param firstPoint the first clicked point by the user * @param currentPoint the current point of the drag action by the user * @param item the selection item * @return the skew transform */ protected AffineTransform getSkewTransform( SVGHandle svgHandle, Rectangle2D bounds, Point2D firstPoint, Point2D currentPoint, SelectionItem item) { // getting the skew factor double skewX = 0, skewY = 0; boolean isHorizontal = (item.getType() == SelectionItem.NORTH || item.getType() == SelectionItem.SOUTH); if (bounds.getWidth() > 0 && bounds.getHeight() > 0) { if (isHorizontal) { skewX = (currentPoint.getX() - firstPoint.getX()) / bounds.getHeight(); } else { skewY = (currentPoint.getY() - firstPoint.getY()) / bounds.getWidth(); } } // getting the center point Point2D centerPoint = getRotationSkewCenterPoint(svgHandle, bounds); // creating the affine transform AffineTransform af = AffineTransform.getTranslateInstance(-centerPoint.getX(), -centerPoint.getY()); af.preConcatenate(AffineTransform.getShearInstance(skewX, skewY)); af.preConcatenate(AffineTransform.getTranslateInstance(centerPoint.getX(), centerPoint.getY())); return af; }
public void drawTextEdge(ModelImpl objectModel) { Renderable renderable = objectModel.getObj(); TextDataImpl textData = (TextDataImpl) renderable.getTextData(); if (textData != null) { model.colorMode.textColor(this, textData, objectModel); model.sizeMode.setSizeFactor2d(model.edgeSizeFactor, textData, objectModel); if (edgeRefresh) { builder.buildEdgeText((EdgeData) renderable, textData, model, currentTimeInterval); } if (textData.getSizeFactor() * renderer.getCharWidth('a') < PIXEL_LIMIT) { return; } String txt = textData.getLine().getText(); Rectangle2D r = renderer.getBounds(txt); float posX = renderable.getModel().getViewportX() + (float) r.getWidth() / -2 * textData.getSizeFactor(); float posY = renderable.getModel().getViewportY() + (float) r.getHeight() / -2 * textData.getSizeFactor(); r.setRect( 0, 0, r.getWidth() / drawable.getDraggingMarkerX(), r.getHeight() / drawable.getDraggingMarkerY()); textData.getLine().setBounds(r); renderer.draw3D(txt, posX, posY, 0, textData.getSizeFactor()); } }
private void downloadSample(File file, Rectangle2D bbox) throws IOException { final double max = 0.25; int xMul = (int) Math.ceil(bbox.getWidth() / max); int yMul = (int) Math.ceil(bbox.getHeight() / max); for (int x = 0; x < xMul; x++) { for (int y = 0; y < yMul; y++) { File f = new File(file.getAbsolutePath() + ".part" + x + y); double xPos = bbox.getX() + x * max; double yPos = bbox.getY() + y * max; String b = "" + xPos; b += "," + yPos; b += "," + (xPos + Math.min(max, bbox.getWidth() - max * x)); b += "," + (yPos + Math.min(max, bbox.getHeight() - max * y)); URL downloadUrl = new URL("http://api.openstreetmap.org/api/0.6/map?bbox=" + b); byte[] buffer = new byte[4096]; try (InputStream in = downloadUrl.openStream(); OutputStream out = new FileOutputStream(f); ) { int len = 0; do { out.write(buffer, 0, len); len = in.read(buffer); } while (len > 0); } } } }
// TODO misleading name - is centered around point and scaled font but not scale center point // (probably :) public void drawAntialiasedTextCenteredNoScale( Graphics2D g2, String text, int fontSize, Position pos, ImmutablePoint center, Color fgColor, Color bgColor) { Color original = g2.getColor(); FontRenderContext frc = g2.getFontRenderContext(); TextLayout tl = new TextLayout(text, getFont(fontSize), frc); Rectangle2D bounds = tl.getBounds(); center = center.translate((int) (bounds.getWidth() / -2), (int) (bounds.getHeight() / -2)); if (bgColor != null) { g2.setColor(bgColor); g2.fillRect( getOffsetX(pos) + center.getX() - 6, getOffsetY(pos) + center.getY() - 5, 12 + (int) bounds.getWidth(), 10 + (int) bounds.getHeight()); } g2.setColor(fgColor); tl.draw( g2, getOffsetX(pos) + center.getX(), getOffsetY(pos) + center.getY() + (int) bounds.getHeight()); g2.setColor(original); }
/** * Reserve some space on each axis side because we draw a centered label at each extremity. * * @param g2 the graphics device. * @param plot the plot. * @param plotArea the plot area. * @param edge the edge. * @param space the space already reserved. * @return The reserved space. */ public AxisSpace reserveSpace( Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) { this.internalMarkerCycleBoundTick = null; AxisSpace ret = super.reserveSpace(g2, plot, plotArea, edge, space); if (this.internalMarkerCycleBoundTick == null) { return ret; } FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); Rectangle2D r = TextUtilities.getTextBounds(this.internalMarkerCycleBoundTick.getText(), g2, fm); if (RectangleEdge.isTopOrBottom(edge)) { if (isVerticalTickLabels()) { space.add(r.getHeight() / 2, RectangleEdge.RIGHT); } else { space.add(r.getWidth() / 2, RectangleEdge.RIGHT); } } else if (RectangleEdge.isLeftOrRight(edge)) { if (isVerticalTickLabels()) { space.add(r.getWidth() / 2, RectangleEdge.TOP); } else { space.add(r.getHeight() / 2, RectangleEdge.TOP); } } return ret; }
protected void drawToolTip( DrawContext dc, java.awt.Rectangle viewport, String text, int x, int y, ToolTipAttributes attributes) { java.awt.geom.Rectangle2D textBounds = this.computeTextBounds(dc, text, attributes.getFont()); java.awt.geom.Rectangle2D bgBounds = this.computeBackgroundBounds( dc, textBounds.getWidth(), textBounds.getHeight(), attributes.getInsets()); java.awt.Point screenPoint = this.adjustDrawPointToViewport(x, y, bgBounds, viewport); java.awt.geom.Point2D textTranslation = this.computeTextTranslation(dc, textBounds, attributes.getInsets()); GL2 gl = dc.getGL(); OGLStackHandler stackHandler = new OGLStackHandler(); stackHandler.pushModelview(gl); try { gl.glTranslated( screenPoint.getX() + bgBounds.getX(), screenPoint.getY() + bgBounds.getY(), 0); this.drawToolTipInterior(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes); this.drawToolTipOutline(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes); gl.glTranslated(textTranslation.getX(), textTranslation.getY(), 0); this.drawToolTipText(dc, text, 0, 0, attributes); } finally { stackHandler.pop(gl); } }
public void drawStuff(Graphics2D g2) { g2.setColor(Color.BLACK); g2.fillRect(0, 0, 650, 450); g2.setColor(Color.BLACK); g2.drawRect(0, 0, 650, 450); for (int i = 0; i < blocks.size(); i++) { if (blocks.get(i).isOnMagnet()) continue; Shape curShape = blocks.get(i).getFrame(); Rectangle2D boundingBox = (Rectangle2D) curShape; g2.setColor(Color.WHITE); g2.fillRect( (int) boundingBox.getX(), (int) boundingBox.getY(), (int) boundingBox.getWidth(), (int) boundingBox.getHeight()); g2.setColor(Color.BLUE); g2.drawRect( (int) boundingBox.getX(), (int) boundingBox.getY(), (int) boundingBox.getWidth(), (int) boundingBox.getHeight()); } g2.setColor(Color.GRAY); g2.fillRect(0, 380, 650, 70); g2.setColor(Color.BLACK); g2.drawRect(0, 380, 650, 70); }
@Override public Point paint(Graphics2D g2, Point p) { Position = p; Font tmp = g2.getFont(); g2.setFont(new Font("SansSerif", Font.PLAIN, 18)); Rectangle2D NBounds = g2.getFont().getStringBounds(Integer.toString(currentNumber), g2.getFontRenderContext()); g2.draw( Arrow2D.getArrow( new Point( (int) (getPosition().getX() + NBounds.getCenterX()), (int) (getPosition().getY() - NBounds.getHeight())), new Point( (int) (getPosition().getX() + NBounds.getCenterX()), (int) getPosition().getY()), 8, 30)); g2.drawString( Integer.toString(currentNumber), (float) Position.getX(), (float) (Position.getY() - NBounds.getHeight())); g2.setFont(tmp); ShapeSize = new Rectangle2D.Double(0, 0, NBounds.getWidth(), NBounds.getHeight() + NBounds.getHeight()); return new Point((int) (p.getX() + ShapeSize.getWidth()), (int) p.getY()); }
@Override public void drawGui(Graphics g) { Graphics2D page = (Graphics2D) g; int height = -4; int spacing = -2; final Font font = new Font("Consolas", Font.BOLD, 13); for (String str : debug) { g.setFont(font); page.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); Rectangle2D rect = g.getFontMetrics().getStringBounds(str, g); if (font.getSize() <= 20) height += rect.getHeight() + 1; else height += rect.getHeight() + 2; g.setColor(new Color(85, 85, 85, 190)); this.drawString( str, font, Color.WHITE, this.panel.getWidth() - (int) rect.getWidth() - 3, height, g); height += spacing; } }
@Override public void mouseDragged(MouseEvent e) { Canvas c = context.getTabbedPaneController().getCurrentTabContent(); SelectionModel selectionModel = c.getSelectionModel(); if (!selectionModel.prepareForMove()) { moved = false; return; } Point thisCoord = e.getPoint(); int dx = thisCoord.x - previousPosition.x; int dy = thisCoord.y - previousPosition.y; if (selectionRec == null) { selectionRec = selectionModel.getSelectionBounds(); } selectionRec.setRect( selectionRec.getX() + dx, selectionRec.getY() + dy, selectionRec.getWidth(), selectionRec.getHeight()); c.setSelectionRectangleBounds( selectionRec.getX(), selectionRec.getY(), selectionRec.getWidth(), selectionRec.getHeight()); c.setShowSelectionRectangle(true); c.repaint(); previousPosition = (Point) thisCoord.clone(); moved = true; }
/** * Get the bounding box of the shape when stroked. This method takes account of the thickness of * the stroke. */ public Rectangle2D getBounds() { // FIXME: these bounds REALLY need to be cached. But it's // painful because of the public members. if (stroke == null) { return shape.getBounds2D(); } else if (stroke instanceof BasicStroke) { // For some reason (antialiasing?) the bounds returned by // BasicStroke is off by one. This code works around it. // if all we want is the bounds, then we don't need to actually // stroke the shape. We've had reports that this is no longer // necessary with JDK1.3. Rectangle2D rect = shape.getBounds2D(); int width = (int) ((BasicStroke) stroke).getLineWidth() + 2; return new Rectangle2D.Double( rect.getX() - width, rect.getY() - width, rect.getWidth() + width + width, rect.getHeight() + width + width); } else { // For some reason (antialiasing?) the bounds returned by // BasicStroke is off by one. This code works around it. // We've had reports that this is no longer // necessary with JDK1.3. Rectangle2D rect = stroke.createStrokedShape(shape).getBounds2D(); return new Rectangle2D.Double( rect.getX() - 1, rect.getY() - 1, rect.getWidth() + 2, rect.getHeight() + 2); } }
/** * Draws the waferedge, including the notch. * * @param g2 the graphics device. * @param plotArea the plot area. */ protected void drawWaferEdge(Graphics2D g2, Rectangle2D plotArea) { // draw the wafer Ellipse2D waferEdge = getWaferEdge(plotArea); g2.setColor(Color.black); g2.draw(waferEdge); // calculate and draw the notch // horizontal orientation is considered notch right // vertical orientation is considered notch down Arc2D notch; Rectangle2D waferFrame = waferEdge.getFrame(); double notchDiameter = waferFrame.getWidth() * 0.04; if (this.orientation == PlotOrientation.HORIZONTAL) { Rectangle2D notchFrame = new Rectangle2D.Double( waferFrame.getX() + waferFrame.getWidth() - (notchDiameter / 2), waferFrame.getY() + (waferFrame.getHeight() / 2) - (notchDiameter / 2), notchDiameter, notchDiameter); notch = new Arc2D.Double(notchFrame, 90d, 180d, Arc2D.OPEN); } else { Rectangle2D notchFrame = new Rectangle2D.Double( waferFrame.getX() + (waferFrame.getWidth() / 2) - (notchDiameter / 2), waferFrame.getY() + waferFrame.getHeight() - (notchDiameter / 2), notchDiameter, notchDiameter); notch = new Arc2D.Double(notchFrame, 0d, 180d, Arc2D.OPEN); } g2.setColor(Color.white); g2.fill(notch); g2.setColor(Color.black); g2.draw(notch); }
/** * Draws the background to the specified graphics device. If the dial frame specifies a window, * the clipping region will already have been set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // the indicator bounds is calculated from the templateValue (which // determines the minimum size), the maxTemplateValue (which, if // specified, provides a maximum size) and the actual value FontMetrics fm = g2.getFontMetrics(this.font); double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm); // calculate the bounds of the template value String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); double minW = tb.getWidth(); double minH = tb.getHeight(); double maxW = Double.MAX_VALUE; double maxH = Double.MAX_VALUE; if (this.maxTemplateValue != null) { s = this.formatter.format(this.maxTemplateValue); tb = TextUtilities.getTextBounds(s, g2, fm); maxW = Math.max(tb.getWidth(), minW); maxH = Math.max(tb.getHeight(), minH); } double w = fixToRange(valueBounds.getWidth(), minW, maxW); double h = fixToRange(valueBounds.getHeight(), minH, maxH); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point Shape savedClip = g2.getClip(); g2.clip(fb); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString( valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); g2.setClip(savedClip); }
protected void invalidate() { // Retrieve current bounds and set local vars Rectangle2D tmp = graph.getCellBounds(vertex.getCell()); if (tmp != null) { tmp = (Rectangle2D) tmp.clone(); graph.toScreen(tmp); int handlesize = graph.getHandleSize(); int s2 = 2 * handlesize; double left = tmp.getX() - handlesize; double top = tmp.getY() - handlesize; double w2 = tmp.getX() + (tmp.getWidth() / 2) - handlesize; double h2 = tmp.getY() + (tmp.getHeight() / 2) - handlesize; double right = tmp.getX() + tmp.getWidth() - handlesize; double bottom = tmp.getY() + tmp.getHeight() - handlesize; // Update control point positions r[0].setFrame(left, top, s2, s2); r[1].setFrame(w2, top, s2, s2); r[2].setFrame(right, top, s2, s2); r[3].setFrame(left, h2, s2, s2); r[4].setFrame(right, h2, s2, s2); r[5].setFrame(left, bottom, s2, s2); r[6].setFrame(w2, bottom, s2, s2); r[7].setFrame(right, bottom, s2, s2); } }
/** * Calculates the location of the waferedge. * * @param plotArea the plot area. * @return The wafer edge. */ public Ellipse2D getWaferEdge(Rectangle2D plotArea) { Ellipse2D edge = new Ellipse2D.Double(); double diameter = plotArea.getWidth(); double upperLeftX = plotArea.getX(); double upperLeftY = plotArea.getY(); // get major dimension if (plotArea.getWidth() != plotArea.getHeight()) { double major, minor; if (plotArea.getWidth() > plotArea.getHeight()) { major = plotArea.getWidth(); minor = plotArea.getHeight(); } else { major = plotArea.getHeight(); minor = plotArea.getWidth(); } // ellipse diameter is the minor dimension diameter = minor; // set upperLeft point if (plotArea.getWidth() == minor) { // x is minor upperLeftY = plotArea.getY() + (major - minor) / 2; } else { // y is minor upperLeftX = plotArea.getX() + (major - minor) / 2; } } edge.setFrame(upperLeftX, upperLeftY, diameter, diameter); return edge; }
/** * Method draws component`s content. * * @param g - Graphics instance to use for draw. */ public void paintComponent(Graphics g) { // prepare double buffer Graphics bufg = prepareForPaint(); // preparing variables String level = this.getSettings().getLevel().toString(); // fill rectangle with scores Graphics2D g2 = (Graphics2D) bufg; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); bufg.setColor(Color.yellow); bufg.setFont(this.getSettings().getFont()); FontMetrics fm = bufg.getFontMetrics(); Rectangle2D area = fm.getStringBounds(level, bufg); bufg.drawString( level, (int) (getWidth() - area.getWidth()) / 2, (int) (getHeight() + area.getHeight()) / 5 * 3); area = fm.getStringBounds(getSettings().getString("LEVEL"), bufg); bufg.drawString( getSettings().getString("LEVEL"), (int) (getWidth() - area.getWidth()) / 2, (int) (getHeight() + area.getHeight()) / 5 * 2); // draw it at right upper corner g.drawImage(this.getBuf(), 0, 0, this); }
/** {@inheritDoc} */ public boolean setBounds( final double x, final double y, final double width, final double height) { if (lineShape == null || !super.setBounds(x, y, width, height)) { return false; } final Rectangle2D lineBounds = lineShape.getBounds2D(); final Rectangle2D lineStrokeBounds = getLineBoundsWithStroke(); final double strokeOutset = Math.max( lineStrokeBounds.getWidth() - lineBounds.getWidth(), lineStrokeBounds.getHeight() - lineBounds.getHeight()); double adjustedX = x + strokeOutset / 2; double adjustedY = y + strokeOutset / 2; double adjustedWidth = width - strokeOutset; double adjustedHeight = height - strokeOutset; TEMP_TRANSFORM.setToIdentity(); TEMP_TRANSFORM.translate(adjustedX, adjustedY); TEMP_TRANSFORM.scale( adjustedWidth / lineBounds.getWidth(), adjustedHeight / lineBounds.getHeight()); TEMP_TRANSFORM.translate(-lineBounds.getX(), -lineBounds.getY()); lineShape.transformPoints(TEMP_TRANSFORM); return true; }
private Rectangle2D getLabelBB() { Rectangle2D bb = getContentsBoundingBox(); return new Rectangle2D.Double( bb.getMaxX() - labelBB.getWidth(), bb.getMinY() - labelBB.getHeight(), labelBB.getWidth(), labelBB.getHeight()); }
public Rectangle2D evaluate(Rectangle2D v0, Rectangle2D v1, float fraction) { double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction); double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction); double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction); double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction); Rectangle2D value = (Rectangle2D) v0.clone(); value.setRect(x, y, w, h); return value; }
/** * Calculates the axis space required. * * @param g2 the graphics device. * @param plotArea the plot area. * @return The space. */ protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); PlotOrientation orientation = getOrientation(); // work out the space required by the domain axis... AxisSpace fixed = getFixedDomainAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.HORIZONTAL) { space.setLeft(fixed.getLeft()); space.setRight(fixed.getRight()); } else if (orientation == PlotOrientation.VERTICAL) { space.setTop(fixed.getTop()); space.setBottom(fixed.getBottom()); } } else { ValueAxis xAxis = getDomainAxis(); RectangleEdge xEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation); if (xAxis != null) { space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space); } } Rectangle2D adjustedPlotArea = space.shrink(plotArea, null); // work out the maximum height or width of the non-shared axes... int n = this.subplots.size(); this.subplotAreas = new Rectangle2D[n]; double x = adjustedPlotArea.getX(); double y = adjustedPlotArea.getY(); double usableSize = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1); } else if (orientation == PlotOrientation.VERTICAL) { usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1); } for (int i = 0; i < n; i++) { XYPlot plot = (XYPlot) this.subplots.get(i); // calculate sub-plot area if (orientation == PlotOrientation.HORIZONTAL) { double w = usableSize * plot.getWeight() / this.totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight()); x = x + w + this.gap; } else if (orientation == PlotOrientation.VERTICAL) { double h = usableSize * plot.getWeight() / this.totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h); y = y + h + this.gap; } AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null); space.ensureAtLeast(subSpace); } return space; }
private void paintFirms(Graphics2D g2d) { Rectangle2D rec = new Rectangle2D.Double(); ArrayList<Firm> firms = SleepStoneTest.firms; Stroke normalStroke = new BasicStroke(); Stroke boldStroke = new BasicStroke(4f); g2d.setStroke(boldStroke); for (Firm x : firms) { rec.setRect(firmsPlace.get(x)); FirmStatus status = x.getStatus(); g2d.setColor(Color.black); g2d.drawString(x.getFirmName(), Math.round(rec.getMinX()), Math.round(rec.getMaxY() + 15d)); g2d.drawString( Integer.toString(x.getWorkers().size()), Math.round(rec.getMinX()), Math.round(rec.getMinY() - 15d)); // g2d.setColor(Color.RED); g2d.drawImage( firmIcon.getImage(), (int) rec.getX(), (int) rec.getY(), (int) rec.getWidth(), (int) rec.getHeight(), FirmStatus.getStatusColor(status), null); // draw the jobs done indicator if (status == FirmStatus.PRODUCING) { g2d.setColor(Color.black); g2d.setStroke(boldStroke); Rectangle jobsIndicator = new Rectangle( (int) rec.getMaxX() + 5, (int) rec.getMinY(), (int) (firmSpacing / 2d), (int) rec.getHeight()); g2d.draw(jobsIndicator); float jobsToDo = x.getJobsToDo(); float jobsDone = x.getJobsDone().availablePermits(); float percentComplete = jobsDone / jobsToDo; g2d.setColor(Color.BLUE); jobsIndicator.setBounds( (int) rec.getMaxX() + 5, (int) rec.getMinY(), (int) (firmSpacing / 2d), (int) (((float) (rec.getHeight())) * percentComplete)); g2d.fill(jobsIndicator); g2d.setStroke(normalStroke); } // index++; } }
public void addTriggerToParking(TaxiwayParkingModel model) { Rectangle2D square = ((java.awt.geom.Ellipse2D.Float) model.getParkingCircle()).getBounds2D(); square.setFrame( square.getX() - (double) (20F * scale), square.getY() - (double) (20F * scale), square.getWidth() + (double) (40F * scale), square.getHeight() + (double) (40F * scale)); TriggerModel triggerModel = new TriggerModel(); triggerModel.setShouldNotify(false); triggerModel.setType73("YES"); triggerModel.setTypeJet("YES"); triggerModel.setShouldNotify(true); java.awt.geom.Point2D.Float point = new java.awt.geom.Point2D.Float( (float) (square.getX() + square.getWidth() / 2D), (float) (square.getY() + square.getHeight() / 2D)); java.awt.geom.Point2D.Float vertexPoints[] = new java.awt.geom.Point2D.Float[4]; vertexPoints[0] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float((float) square.getX(), (float) square.getY()), model.getHeading()); vertexPoints[1] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float( (float) square.getX(), (float) (square.getY() + square.getHeight())), model.getHeading()); vertexPoints[2] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float( (float) (square.getX() + square.getWidth()), (float) (square.getY() + square.getHeight())), model.getHeading()); vertexPoints[3] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float( (float) (square.getX() + square.getWidth()), (float) square.getY()), model.getHeading()); for (int i = 0; i < 4; i++) { VertexModel vertexModel = new VertexModel(); vertexModel.setShouldNotify(false); vertexModel.setLatLon( Utilities.getLatLonForPixel( model.getCenterPoint().getLat(), model.getCenterPoint().getLon(), vertexPoints[i].getX(), vertexPoints[i].getY(), scale)); vertexModel.setShouldNotify(true); triggerModel.addVertexModel(vertexModel); } addTriggerModel(triggerModel); }
/* * (non-Javadoc) * * @see br.arca.morcego.Component#paint(java.awt.Graphics) */ public void paint(Graphics g) { // TODO: paint a fancy textbox with description of node Graphics2D graphic = (Graphics2D) g; TextArea textArea = new TextArea(text); textArea.setLocation(0, 0); textArea.setVisible(true); Font font = new Font(null, Font.PLAIN, 10); FontRenderContext frc = new FontRenderContext(null, false, false); TextLayout l = new TextLayout(text, font, frc); Rectangle2D textBounds = l.getBounds(); int margin = Config.getInteger(Config.descriptionMargin); int border = 1; int distX = 5; int distY = 5; int width = (int) textBounds.getWidth() + 2 * margin + 2 * border; int height = (int) textBounds.getHeight() + 2 * margin + 2 * border; int cornerX = originX - width - distX; int cornerY = originY - height - distY; if (cornerX < 0) { cornerX = 0; } if (cornerY < 0) { cornerY = 0; } graphic.setColor(Config.getColor(Config.descriptionBorder)); graphic.fillRect( cornerX - margin - border, cornerY - margin - border, (int) textBounds.getWidth() + 2 * margin + 2 * border, (int) textBounds.getHeight() + 2 * margin + 2 * border); graphic.setColor(Config.getColor(Config.descriptionBackground)); graphic.fillRect( cornerX - margin, cornerY - margin, (int) textBounds.getWidth() + 2 * margin, (int) textBounds.getHeight() + 2 * margin); graphic.setColor(Config.getColor(Config.descriptionColor)); textArea.paint(g); l.draw(graphic, cornerX, cornerY + (int) textBounds.getHeight()); }
/** * @param g2 * @param string */ protected void drawText(Graphics2D g2, String text) { g2.setColor(getActiveColor()); g2.setFont(new Font("Arial", Font.BOLD, 10)); String tt = text; Rectangle2D sB1 = g2.getFontMetrics().getStringBounds(tt, g2); double sw0 = 10.0 / sB1.getWidth(); double sh0 = 10.0 / sB1.getHeight(); g2.translate(5, 5); g2.scale(sw0, sh0); g2.drawString(text, (int) (-sB1.getWidth() / 2.0), (int) (sB1.getHeight() / 2.0)); }
/** * Creates a temporary list of ticks that can be used when drawing the axis. * * @param g2 the graphics device (used to get font measurements). * @param state the axis state. * @param dataArea the area inside the axes. * @param edge the location of the axis. * @return A list of ticks. */ @Override public List<CategoryTick> refreshTicks( Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List<CategoryTick> ticks = new java.util.ArrayList<CategoryTick>(); // sanity check for data area... if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) { return ticks; } CategoryPlot plot = (CategoryPlot) getPlot(); List<Comparable> categories = plot.getCategoriesForAxis(this); double max = 0.0; if (categories != null) { CategoryLabelPosition position = this.categoryLabelPositions.getLabelPosition(edge); float r = this.maximumCategoryLabelWidthRatio; if (r <= 0.0) { r = position.getWidthRatio(); } float l; if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) { l = (float) calculateCategorySize(categories.size(), dataArea, edge); } else { if (RectangleEdge.isLeftOrRight(edge)) { l = (float) dataArea.getWidth(); } else { l = (float) dataArea.getHeight(); } } int categoryIndex = 0; for (Comparable category : categories) { g2.setFont(getTickLabelFont(category)); TextBlock label = createLabel(category, l * r, edge, g2); if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) { max = Math.max(max, calculateTextBlockHeight(label, position, g2)); } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) { max = Math.max(max, calculateTextBlockWidth(label, position, g2)); } ticks.add( new CategoryTick( category, label, position.getLabelAnchor(), position.getRotationAnchor(), position.getAngle())); categoryIndex = categoryIndex + 1; } } state.setMax(max); return ticks; }
public void layout(IAtomContainer atomContainer, Rectangle2D canvas) { atomLayout(atomContainer); double canvasWidth = canvas.getWidth(); double canvasHeight = canvas.getHeight(); Rectangle2D molBounds = GeometryTools.getRectangle2D(atomContainer); double molWidth = molBounds.getWidth(); double molHeight = molBounds.getHeight(); double scaleFactor = Math.min(canvasWidth / molWidth, canvasHeight / molHeight); Point2d center = new Point2d(canvas.getCenterX(), canvas.getCenterY()); scaleAndCenter(atomContainer, scaleFactor, center); }
public VoronoiCore(Rectangle2D rectangle) { PolygonSimple poly = new PolygonSimple(4); poly.add(rectangle.getMinX(), rectangle.getMinY()); poly.add(rectangle.getMinX() + rectangle.getWidth(), rectangle.getMinY()); poly.add( rectangle.getMinX() + rectangle.getWidth(), rectangle.getMinY() + rectangle.getHeight()); poly.add(rectangle.getMinX(), rectangle.getMinY() + rectangle.getHeight()); this.clipPolygon = poly; init(); diagram.setClipPoly(poly); }
private void drawSkillName( Graphics g, String skillText, Rectangle2D textRect, int skillBoxY, int skillBoxX) { // Get width and Y pos. int skillNameWidth = (int) textRect.getWidth(); int skillStringY = skillBoxY + (skillRectHeight - (int) textRect.getHeight()) + fm.getAscent(); // if text is 2 long for the box... Split that shit up boiii if (skillNameWidth > skillBoxSize) { // Split by whitespace String[] arr = skillText.split(" "); String curr; Rectangle2D textRect2; // Loop thru each substring from the end and draw appropriately for (int j = arr.length - 1; j >= 0; j--) { curr = arr[j]; textRect = fm.getStringBounds(curr, g); // If this substring is less than half the width of the box and theres anotha substring if ((int) textRect.getWidth() < skillBoxSize / 2 && j != 0) { // Get and measure the otha 1 String anotha1 = arr[j - 1]; textRect2 = fm.getStringBounds(anotha1, g); // Draw both on the same line if can fit int combinedW = (int) textRect.getWidth() + (int) textRect2.getWidth() + 2; String combined = anotha1 + " " + curr; if (combinedW < skillBoxSize) { g.drawString(combined, skillBoxX + (skillBoxSize - combinedW) / 2, skillStringY); j--; } // Otherwise, draw one of those suckas else { g.drawString( curr, skillBoxX + (skillBoxSize - (int) textRect.getWidth()) / 2, skillStringY); } } // Otherwise, draw one of those suckas else { g.drawString( curr, skillBoxX + (skillBoxSize - (int) textRect.getWidth()) / 2, skillStringY); } // Decrease dat Y skillStringY -= (int) textRect.getHeight(); } } else { g.drawString( skillText, skillBoxX + (skillBoxSize - skillNameWidth) / 2, skillBoxY + (skillRectHeight - (int) textRect.getHeight()) + fm.getAscent()); } }