Java Code Examples for java.awt.geom.Rectangle2D

The following are top voted examples for showing how to use java.awt.geom.Rectangle2D. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: parabuild-ci   File: WaferMapPlot.java   Source Code and License 7 votes vote down vote up
/**
 * Draws the wafermap view.
 * 
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param state  the plot state.
 * @param info  the plot rendering info.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState state, 
                 PlotRenderingInfo info) {

    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }

    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    drawChipGrid(g2, area);       
    drawWaferEdge(g2, area);
    
}
 
Example 2
Project: parabuild-ci   File: NumberAxis.java   Source Code and License 6 votes vote down vote up
/**
 * Converts a data value to a coordinate in Java2D space, assuming that the
 * axis runs along one edge of the specified dataArea.
 * <p>
 * Note that it is possible for the coordinate to fall outside the plotArea.
 *
 * @param value  the data value.
 * @param area  the area for plotting the data.
 * @param edge  the axis location.
 *
 * @return The Java2D coordinate.
 */
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {
    
    Range range = getRange();
    double axisMin = range.getLowerBound();
    double axisMax = range.getUpperBound();

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        max = area.getMinY();
        min = area.getMaxY();
    }
    if (isInverted()) {
        return max - ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }
    else {
        return min + ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }

}
 
Example 3
Project: rapidminer   File: ProcessDrawUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Abbreviates the string using {@code ...} if necessary.
 *
 * @param string
 *            the string to shorten
 * @param g2
 *            the graphics context
 * @param maxWidth
 *            the max width in px the string is allowed to use
 * @return the shorted string, never {@code null}
 */
public static String fitString(String string, final Graphics2D g2, final int maxWidth) {
	if (string == null) {
		throw new IllegalArgumentException("string must not be null!");
	}
	if (g2 == null) {
		throw new IllegalArgumentException("g2 must not be null!");
	}

	Rectangle2D bounds = g2.getFont().getStringBounds(string, g2.getFontRenderContext());
	if (bounds.getWidth() <= maxWidth) {
		return string;
	}
	while (g2.getFont().getStringBounds(string + "...", g2.getFontRenderContext()).getWidth() > maxWidth) {
		if (string.length() == 0) {
			return "...";
		}
		string = string.substring(0, string.length() - 1);
	}
	return string + "...";
}
 
Example 4
Project: geomapapp   File: WWUnknownDataSet.java   Source Code and License 6 votes vote down vote up
public synchronized void setArea(final Rectangle2D rect) {
	SwingUtilities.invokeLater(new Runnable() {

		public void run() {
			tm.setArea(rect, 1);
			if (cst != null && cst.isShowing()) updateColorScale();
			if (sst != null && sst.isShowing()) updateSymbolScale();

			Iterator iter2 = xypoints.iterator();
			for (Iterator iter = graphs.iterator(); iter.hasNext();) {
				XYGraph xyg = (XYGraph) iter.next();
				DataSetGraph dsg = (DataSetGraph) iter2.next();
				synchronized (xyg.getTreeLock()) {
					xyg.paintComponent(xyg.getGraphics(), false);
				}
			}
			processVisibility();
		}
	});
}
 
Example 5
Project: rapidminer   File: LinkAndBrushChartPanel.java   Source Code and License 6 votes vote down vote up
/**
 * Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this
 * method is called twice in a row, the second call will completely restore the state of the
 * canvas.
 * 
 * @param g2
 *            the graphics device.
 * @param xor
 *            use XOR for drawing?
 */
private void drawZoomRectangle(Graphics2D g2, boolean xor) {
	Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
	if (zoomRectangle != null) {
		// fix rectangle parameters when chart is transformed
		zoomRectangle = coordinateTransformation.transformRectangle(zoomRectangle, this);
		if (!(coordinateTransformation instanceof NullCoordinateTransformation)) {
			g2 = coordinateTransformation.getTransformedGraphics(this);
		}
		if (xor) {
			// Set XOR mode to draw the zoom rectangle
			g2.setXORMode(Color.gray);
		}
		if ((Boolean) getChartFieldValueByName("fillZoomRectangle")) {
			g2.setPaint((Paint) getChartFieldValueByName("zoomFillPaint"));
			g2.fill(zoomRectangle);
		} else {
			g2.setPaint((Paint) getChartFieldValueByName("zoomOutlinePaint"));
			g2.draw(zoomRectangle);
		}
		if (xor) {
			// Reset to the default 'overwrite' mode
			g2.setPaintMode();
		}
	}
}
 
Example 6
Project: geomapapp   File: LayerComposer.java   Source Code and License 6 votes vote down vote up
public static Layer getSpreadingRateGridLayer() {
	GridTileLayer tl = new GridTileLayer(new GridRetriever() {
		public Grid2DOverlay retriveGrid(Rectangle2D tileBounds, int level) {
			return SSGridComposer.getGridWW(tileBounds, level, SSGridComposer.SPREADING_RATE);
		}
		public float getVEFactor() {
			return 1f;
		}
		public int getNumLevels() {
			return 2;
		}
		public String getName() {
			return org.geomapapp.grid.GridDialog.SPREADING_RATE;
		}
	}, ImageResampler.MERCATOR_TO_GEOGRAPHIC);

	tl.setAnnotationFactor(1/100f);
	tl.setAnnotationUnits(GridDialog.GRID_UNITS.get(GridDialog.SPREADING_RATE));
	return tl;
}
 
Example 7
Project: jmt   File: JobsDrawer.java   Source Code and License 6 votes vote down vote up
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean draw) {
	Rectangle2D txtBounds;
	double x, y;
	double gap = dCst.getElementsGap();
	g2d.setFont(dCst.getFont());
	txtBounds = dCst.getFont().getStringBounds(s, g2d.getFontRenderContext());
	x = centerX - txtBounds.getWidth() / 2.0;
	y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
	txtBounds.setRect(x - gap, y - txtBounds.getHeight() / 2.0 - gap, txtBounds.getWidth() + 2 * gap, txtBounds.getHeight() + 2 * gap);
	Color ctmp = g2d.getColor();
	g2d.setColor(c);
	if (draw) {
		g2d.drawString(s, (float) x, (float) y);
	}
	g2d.setColor(ctmp);
	return txtBounds;
}
 
Example 8
Project: freecol   File: Flag.java   Source Code and License 6 votes vote down vote up
private void drawQuarters(Graphics2D g) {
    int colors = backgroundColors.size();
    int[] x = { 0, 1, 1, 0 };
    int[] y = { 0, 0, 1, 1 };
    double halfWidth = WIDTH / 2;
    double halfHeight = HEIGHT / 2;
    double offset = (decoration == Decoration.SCANDINAVIAN_CROSS)
        ? CROSS_OFFSET : 0;
    Rectangle2D.Double rectangle = new Rectangle2D.Double();
    for (int index = 0; index < 4; index++) {
        g.setColor(backgroundColors.get(index % colors));
        rectangle.setRect(x[index] * halfWidth - offset, y[index] * halfHeight,
                          halfWidth + x[index] * offset, halfHeight);
        g.fill(rectangle);
    }
}
 
Example 9
Project: MapAnalyst   File: MainWindow.java   Source Code and License 6 votes vote down vote up
private String getNewMapImageInfo() {
    GeoImage img = manager.getNewMap();
    if (img != null) {
        StringBuilder sb = new StringBuilder();
        Rectangle2D bounds = img.getBounds2D();
        // extent in reference coordinate system
        sb.append(String.format("%1$,.1f", bounds.getWidth()));
        sb.append(" m \u00D7 ");
        sb.append(String.format("%1$,.1f", bounds.getHeight()));
        sb.append(" m<br>");

        // image size in pixels
        sb.append(getImageSizeInfo(img));
        sb.append("<br>");

        // size of pixel
        sb.append("Pixel size: ");
        sb.append(img.getPixelSizeX());
        sb.append(" m \u00D7 ");
        sb.append(img.getPixelSizeY());
        sb.append(" m");

        return sb.toString();
    }
    return null;
}
 
Example 10
Project: parabuild-ci   File: FastScatterPlot.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            Iterator iterator = ticks.iterator();
            while (iterator.hasNext()) {
                ValueTick tick = (ValueTick) iterator.next();
                double v = this.rangeAxis.valueToJava2D(
                    tick.getValue(), dataArea, RectangleEdge.LEFT
                );
                Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
                g2.setPaint(gridPaint);
                g2.setStroke(gridStroke);
                g2.draw(line);                
            }
        }
    }

}
 
Example 11
Project: openjdk-jdk10   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 12
Project: parabuild-ci   File: AxisSpace.java   Source Code and License 6 votes vote down vote up
/**
 * Calculates the reserved area.
 * 
 * @param area  the area.
 * @param edge  the edge.
 * 
 * @return The reserved area.
 */
public Rectangle2D reserved(Rectangle2D area, RectangleEdge edge) {
    Rectangle2D result = null;
    if (edge == RectangleEdge.TOP) {
        result = new Rectangle2D.Double(area.getX(), area.getY(),
                                        area.getWidth(), this.top);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result = new Rectangle2D.Double(area.getX(), area.getMaxY() - this.top,
                                        area.getWidth(), this.bottom);
    }
    else if (edge == RectangleEdge.LEFT) {
        result = new Rectangle2D.Double(area.getX(), area.getY(),
                                        this.left, area.getHeight());
    }
    else if (edge == RectangleEdge.RIGHT) {
        result = new Rectangle2D.Double(area.getMaxX() - this.right, area.getY(),
                                        this.right, area.getHeight());
    }
    return result;
}
 
Example 13
Project: parabuild-ci   File: NumberAxisTests.java   Source Code and License 6 votes vote down vote up
/**
 * Test the translation of Java2D values to data values.
 */
public void testTranslateJava2DToValue() {
    NumberAxis axis = new NumberAxis();
    axis.setRange(50.0, 100.0); 
    Rectangle2D dataArea = new Rectangle2D.Double(10.0, 50.0, 400.0, 300.0);
    double y1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);  
    assertTrue(same(y1, 95.8333333, 0.000001)); 
    double y2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);   
    assertTrue(same(y2, 95.8333333, 0.000001)); 
    double x1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);   
    assertTrue(same(x1, 58.125, 0.000001)); 
    double x2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);   
    assertTrue(same(x2, 58.125, 0.000001)); 
    axis.setInverted(true);
    double y3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);  
    assertTrue(same(y3, 54.1666667, 0.000001)); 
    double y4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);   
    assertTrue(same(y4, 54.1666667, 0.000001)); 
    double x3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);   
    assertTrue(same(x3, 91.875, 0.000001)); 
    double x4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);   
    assertTrue(same(x4, 91.875, 0.000001)); 
    
}
 
Example 14
Project: jdk8u-jdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 15
Project: geomapapp   File: LayerComposer.java   Source Code and License 6 votes vote down vote up
public static Layer getTopoGridLayer() {
	GridTileLayer tl = new GridTileLayer(new GridRetriever() {
		public Grid2DOverlay retriveGrid(Rectangle2D tileBounds, int level) {
			return GridComposer.getGridWW(tileBounds, level);
		}
		public float getVEFactor() {
			return 1f;
		}
		public int getNumLevels() {
			return 7;
		}
		public String getName() {
			return org.geomapapp.grid.GridDialog.DEM;
		}
	}, ImageResampler.MERCATOR_TO_GEOGRAPHIC);
	
	tl.setAnnotationFactor(1);
	tl.setAnnotationUnits(GridDialog.GRID_UNITS.get(GridDialog.TOPO_9));
	return tl;
}
 
Example 16
Project: geomapapp   File: LineSegmentsObject.java   Source Code and License 6 votes vote down vote up
public void drawSeg() {
	if( currentSeg==null ) return;
	synchronized( map.getTreeLock() ) {
		Graphics2D g = map.getGraphics2D();
		g.setStroke( new BasicStroke( 2f/(float)map.getZoom() ));
		g.setXORMode( Color.white);
		double max = currentSeg.x1;
		double min = currentSeg.x1;
		if( currentSeg.x2>max ) max=currentSeg.x2;
		else min=currentSeg.x2;
		if( wrap>0. ) {
			Rectangle2D rect = map.getClipRect2D();
			double offset = 0.;
			while( min+offset>rect.getX() ) offset -= wrap;
			while( max+offset< rect.getX() ) offset += wrap;
			g.translate( offset, 0.);
			while( min+offset < rect.getX()+rect.getWidth() ) {
				g.draw( currentSeg );
				offset += wrap;
				g.translate( wrap, 0.);
			}
		} else {
			g.draw( currentSeg );
		}
	}
}
 
Example 17
Project: OpenJSharp   File: TextLayout.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the bounds of this <code>TextLayout</code>.
 * The bounds are in standard coordinates.
 * <p>Due to rasterization effects, this bounds might not enclose all of the
 * pixels rendered by the TextLayout.</p>
 * It might not coincide exactly with the ascent, descent,
 * origin or advance of the <code>TextLayout</code>.
 * @return a {@link Rectangle2D} that is the bounds of this
 *        <code>TextLayout</code>.
 */
public Rectangle2D getBounds() {
    ensureCache();

    if (boundsRect == null) {
        Rectangle2D vb = textLine.getVisualBounds();
        if (dx != 0 || dy != 0) {
            vb.setRect(vb.getX() - dx,
                       vb.getY() - dy,
                       vb.getWidth(),
                       vb.getHeight());
        }
        boundsRect = vb;
    }

    Rectangle2D bounds = new Rectangle2D.Float();
    bounds.setRect(boundsRect);

    return bounds;
}
 
Example 18
Project: OpenJSharp   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public Rectangle2D getLogicalBounds() {
    setFRCTX();
    initPositions();

    LineMetrics lm = font.getLineMetrics("", frc);

    float minX, minY, maxX, maxY;
    // horiz only for now...
    minX = 0;
    minY = -lm.getAscent();
    maxX = 0;
    maxY = lm.getDescent() + lm.getLeading();
    if (glyphs.length > 0) {
        maxX = positions[positions.length - 2];
    }

    return new Rectangle2D.Float(minX, minY, maxX - minX, maxY - minY);
}
 
Example 19
Project: jdk8u-jdk   File: RenderTests.java   Source Code and License 6 votes vote down vote up
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
Example 20
Project: jaer   File: RoShamBoCNN.java   Source Code and License 6 votes vote down vote up
private void drawSymbolOverlay(GLAutoDrawable drawable, int symbolID) {
    GL2 gl = drawable.getGL().getGL2();
    if (symbolTextures == null || symbolID < 0 || symbolID >= symbolTextures.length || symbolTextures[symbolID] == null) {
        return;
    }

    int left = 10, bot = 10, offset = 0;
    final int w = chip.getSizeX() / 2, h = chip.getSizeY() / 2, sw = drawable.getSurfaceWidth(), sh = drawable.getSurfaceHeight();
    if (tracker.getNumVisibleClusters() > 0) {
        Cluster hand = tracker.getVisibleClusters().getFirst();
        offset = (int) ((float) hand.getLocation().y / 5);
    }
    symbolTextures[symbolID].bind(gl);
    symbolTextures[symbolID].enable(gl);
    drawPolygon(gl, left, bot + offset, w, h);
    symbolTextures[symbolID].disable(gl);
    String s = playToWin ? "Playing to win" : "Playing to tie";
    textRenderer.setColor(.75f, 0.75f, 0.75f, 1);
    textRenderer.begin3DRendering();
    Rectangle2D r = textRenderer.getBounds(s);
    textRenderer.draw3D(s, left, bot, 0, (float) w / sw);
    textRenderer.end3DRendering();
}
 
Example 21
Project: Equella   File: AddressBarButton.java   Source Code and License 6 votes vote down vote up
@Override
public void paint(Graphics g)
{
	super.paint(g);
	if( mouseOver )
	{
		Color underline = getForeground();

		// really all this size stuff below only needs to be recalculated if
		// font or text changes
		Rectangle2D textBounds = getFontMetrics(getFont()).getStringBounds(getText(), g);

		// this layout stuff assumes the icon is to the left, or null
		int y = getHeight() / 2 + (int) (textBounds.getHeight() / 2);
		int w = (int) textBounds.getWidth();
		int x = ((getIcon() == null || CurrentLocale.isRightToLeft()) ? 0 : getIcon().getIconWidth()
			+ getIconTextGap());

		g.setColor(underline);
		g.drawLine(x, y, x + w, y);
	}
}
 
Example 22
Project: omr-dataset-tools   File: SymbolInfo.java   Source Code and License 5 votes vote down vote up
public Rectangle2DFacade (Rectangle2D rect)
{
    x = rect.getX();
    y = rect.getY();
    width = rect.getWidth();
    height = rect.getHeight();
}
 
Example 23
Project: JavaGraph   File: JGraph.java   Source Code and License 5 votes vote down vote up
/**
 * Overwritten to freeze nodes to their center on
 * size changes.
 */
@Override
public void updateAutoSize(CellView view) {
    if (view != null && !isEditing()) {
        Rectangle2D bounds =
            (view.getAttributes() != null) ? GraphConstants.getBounds(view.getAttributes())
                : null;
        AttributeMap attrs = getModel().getAttributes(view.getCell());
        if (bounds == null) {
            bounds = GraphConstants.getBounds(attrs);
        }
        if (bounds != null) {
            boolean autosize = GraphConstants.isAutoSize(view.getAllAttributes());
            boolean resize = GraphConstants.isResize(view.getAllAttributes());
            if (autosize || resize) {
                Dimension2D d = getPreferredSize(view);
                int inset = 2 * GraphConstants.getInset(view.getAllAttributes());
                // adjust the x,y corner so that the center stays in place
                double shiftX = (bounds.getWidth() - d.getWidth() - inset) / 2;
                double shiftY = (bounds.getHeight() - d.getHeight() - inset) / 2;
                bounds.setFrame(bounds.getX() + shiftX, bounds.getY() + shiftY, d.getWidth(),
                    d.getHeight());
                // Remove resize attribute
                snap(bounds);
                if (resize) {
                    if (view.getAttributes() != null) {
                        view.getAttributes().remove(GraphConstants.RESIZE);
                    }
                    attrs.remove(GraphConstants.RESIZE);
                }
                view.refresh(getGraphLayoutCache(), getGraphLayoutCache(), false);
            }
        }
    }
}
 
Example 24
Project: parabuild-ci   File: PeriodAxis.java   Source Code and License 5 votes vote down vote up
/**
 * Converts a data value to a coordinate in Java2D space, assuming that the
 * axis runs along one edge of the specified dataArea.
 * <p>
 * Note that it is possible for the coordinate to fall outside the area.
 *
 * @param value  the data value.
 * @param area  the area for plotting the data.
 * @param edge  the edge along which the axis lies.
 *
 * @return The Java2D coordinate.
 */
public double valueToJava2D(double value,
                            Rectangle2D area,
                            RectangleEdge edge) {
    
    double result = Double.NaN;
    double axisMin = this.first.getFirstMillisecond(this.timeZone);
    double axisMax = this.last.getLastMillisecond(this.timeZone);
    if (RectangleEdge.isTopOrBottom(edge)) {
        double minX = area.getX();
        double maxX = area.getMaxX();
        if (isInverted()) {
            result = maxX + ((value - axisMin) / (axisMax - axisMin)) * (minX - maxX);
        }
        else {
            result = minX + ((value - axisMin) / (axisMax - axisMin)) * (maxX - minX);
        }
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        double minY = area.getMinY();
        double maxY = area.getMaxY();
        if (isInverted()) {
            result = minY + (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        }
        else {
            result = maxY - (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        }
    }
    return result;
    
}
 
Example 25
Project: parabuild-ci   File: Axis.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a rectangle that encloses the axis label.  This is typically used for layout
 * purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    // calculate the width of the axis label...
    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        Insets insets = getLabelInsets();
        bounds.setRect(bounds.getX(), bounds.getY(),
                       bounds.getWidth() + insets.left + insets.right,
                       bounds.getHeight() + insets.top + insets.bottom);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
Example 26
Project: parabuild-ci   File: BarRenderer3D.java   Source Code and License 5 votes vote down vote up
/**
 * Draws the outline for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
public void drawOutline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    // put an outline around the data area...
    Stroke outlineStroke = plot.getOutlineStroke();
    Paint outlinePaint = plot.getOutlinePaint();
    if ((outlineStroke != null) && (outlinePaint != null)) {
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(clip);
    }

}
 
Example 27
Project: FreeCol   File: InGameMenuBar.java   Source Code and License 5 votes vote down vote up
/**
 * Paints information about gold, tax and year.
 */
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (freeColClient != null && freeColClient.getMyPlayer() != null) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                             RenderingHints.VALUE_RENDER_QUALITY);
        final int gold = freeColClient.getMyPlayer().getGold();
        String displayString =
            Messages.message(StringTemplate.template("menuBar.statusLine")
                .addAmount("%gold%", gold)
                .addAmount("%tax%", freeColClient.getMyPlayer().getTax())
                .addAmount("%score%",
                    freeColClient.getMyPlayer().getScore())
                .addStringTemplate("%year%",
                    freeColClient.getGame().getTurn().getLabel()));
        Rectangle2D displayStringBounds
            = g2d.getFontMetrics().getStringBounds(displayString, g);
        int y = Math.round(12f*freeColClient.getGUI().getImageLibrary().getScaleFactor())
              + 3 + getInsets().top;
        g2d.drawString(displayString, getWidth() - 10 - (int) displayStringBounds.getWidth(), y);
    }
}
 
Example 28
Project: openjdk-jdk10   File: TextSourceLabel.java   Source Code and License 5 votes vote down vote up
public final Rectangle2D getAlignBounds(float x, float y) {
  if (ab == null) {
    ab = createAlignBounds();
  }
  return new Rectangle2D.Float((float)(ab.getX() + x),
                               (float)(ab.getY() + y),
                               (float)ab.getWidth(),
                               (float)ab.getHeight());
}
 
Example 29
Project: TrabalhoFinalEDA2   File: mxGraphicsCanvas2D.java   Source Code and License 5 votes vote down vote up
/**
 *
 */
public void rect(double x, double y, double w, double h)
{
	currentPath = new GeneralPath();
	currentPath.append(new Rectangle2D.Double((state.dx + x) * state.scale,
			(state.dy + y) * state.scale, w * state.scale, h * state.scale),
			false);
}
 
Example 30
Project: jmt   File: QueueDrawer.java   Source Code and License 5 votes vote down vote up
private void drawUtilization(double U, Color startC, Color border, boolean gradientFill, Graphics2D g2d) {

		double x = getProcessorXY().x, y = getProcessorXY().y;
		try {
			occupiedRect = new Rectangle2D.Double(x, y, 2 * PROC_RAD, 2 * PROC_RAD * (1 - U));
		} catch (Exception e) {
			occupiedRect = new Rectangle2D.Double(x, y, 2 * PROC_RAD, 0.0);
		}
		occupiedEll = new Ellipse2D.Double(x, y, 2 * PROC_RAD, 2 * PROC_RAD);
		if (gradientFill) {
			GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + 2 * PROC_RAD), startC.darker(),
					false);
			g2d.setPaint(gp);
		} else {
			g2d.setPaint(startC);
		}
		occupiedArea = new Area(occupiedEll);
		occupiedArea.subtract(new Area(occupiedRect));
		g2d.fill(occupiedArea);
		g2d.setPaint(Color.BLACK);
		g2d.draw(occupiedArea);

		// //draw informations about processes
		// txtBounds = drawCenteredText("job n.:" + donejobs, Color.BLACK, x +
		// PROC_RAD,y + PROC_RAD * 2 + 4 * ELEMS_GAP,g2d, false);
		// //draw orizontal line parallel to occupation
		//			
		// //draw box around text
		// txtBounds.setFrame(
		// x + PROC_RAD - txtBounds.getWidth() / 2,
		// y + 2 * PROC_RAD + 4 * ELEMS_GAP - txtBounds.getHeight() / 2,
		// txtBounds.getWidth(),
		// txtBounds.getHeight());
		//			
		// g2d.draw(txtBounds);
	}
 
Example 31
Project: openjdk-jdk10   File: ExtendedTextSourceLabel.java   Source Code and License 5 votes vote down vote up
public Rectangle2D handleGetCharVisualBounds(int index) {
  validate(index);
  float[] charinfo = getCharinfo();
  index = l2v(index) * numvals;
  if (charinfo == null || (index+vish) >= charinfo.length) {
      return new Rectangle2D.Float();
  }
  return new Rectangle2D.Float(
                               charinfo[index + visx],
                               charinfo[index + visy],
                               charinfo[index + visw],
                               charinfo[index + vish]);
}
 
Example 32
Project: JavaPPTX   File: PPGroup.java   Source Code and License 5 votes vote down vote up
@Override
protected void dumpShape(PPOutputStream os) {
   os.print("<p:grpSp>");
   os.print("<p:nvGrpSpPr>");
   os.print("<p:cNvPr id='" + getShapeId() + "' " +
            "name='" + getName() + "'/>");
   os.print("<p:cNvGrpSpPr/>");
   os.print("<p:nvPr/>");
   os.print("</p:nvGrpSpPr>");
   os.print("<p:grpSpPr>");
   Point2D pt = getInitialLocation();
   Rectangle2D bb = getGroupBounds();
   String offsetTag = os.getOffsetTag(pt.getX() + bb.getX(),
                                      pt.getY() + bb.getY());
   os.print("<a:xfrm>");
   os.print("<a:off " + offsetTag + "/>");
   os.print("<a:ext cx='" + PPUtil.pointsToUnits(bb.getWidth()) + "' " +
            "cy='" + PPUtil.pointsToUnits(bb.getHeight()) + "'/>");
   os.print("<a:chOff " + offsetTag + "/>");
   os.print("<a:chExt cx='" + PPUtil.pointsToUnits(bb.getWidth()) + "' " +
            "cy='" + PPUtil.pointsToUnits(bb.getHeight()) + "'/>");
   os.print("</a:xfrm>");
   os.print("</p:grpSpPr>");
   Point2D start = getInitialLocation();
   os.adjustOffset(start.getX(), start.getY());
   for (PPShape shape : contents) {
      shape.dumpShape(os);
   }
   os.adjustOffset(-getX(), -getY());
   os.print("</p:grpSp>");
}
 
Example 33
Project: parabuild-ci   File: AbstractCategoryItemRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * Draws a grid line against the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the value at which the grid line should be drawn.
 *
 * @see #drawDomainGridline(Graphics2D, CategoryPlot, Rectangle2D, double)
 *
 */
public void drawRangeGridline(Graphics2D g2,
                              CategoryPlot plot,
                              ValueAxis axis,
                              Rectangle2D dataArea,
                              double value) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    Paint paint = plot.getRangeGridlinePaint();
    if (paint == null) {
        paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getRangeGridlineStroke();
    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);

}
 
Example 34
Project: parabuild-ci   File: LogarithmicAxis.java   Source Code and License 5 votes vote down vote up
/**
 * Converts a coordinate in Java2D space to the corresponding data
 * value, assuming that the axis runs along one edge of the specified plotArea.
 *
 * @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 java2DToValue(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 Math.pow(
            10, axisMax - ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin)
        );
    }
    else {
        return Math.pow(
            10, axisMin + ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin)
        );
    }
}
 
Example 35
Project: litiengine   File: PhysicsEngine.java   Source Code and License 5 votes vote down vote up
@Override
public Point2D collides(final Line2D rayCast) {
  final Point2D rayCastSource = new Point2D.Double(rayCast.getX1(), rayCast.getY1());
  final List<Rectangle2D> collBoxes = this.getAllCollisionBoxes();
  collBoxes.sort((rect1, rect2) -> {
    final Point2D rect1Center = new Point2D.Double(rect1.getCenterX(), rect1.getCenterY());
    final Point2D rect2Center = new Point2D.Double(rect2.getCenterX(), rect2.getCenterY());
    final double dist1 = rect1Center.distance(rayCastSource);
    final double dist2 = rect2Center.distance(rayCastSource);

    if (dist1 < dist2) {
      return -1;
    }

    if (dist1 > dist2) {
      return 1;
    }

    return 0;
  });

  for (final Rectangle2D collisionBox : collBoxes) {
    if (collisionBox.intersectsLine(rayCast)) {
      double closestDist = -1;
      Point2D closestPoint = null;
      for (final Point2D intersection : GeometricUtilities.getIntersectionPoints(rayCast, collisionBox)) {
        final double dist = intersection.distance(rayCastSource);
        if (closestPoint == null || dist < closestDist) {
          closestPoint = intersection;
          closestDist = dist;
        }
      }

      return closestPoint;
    }
  }

  return null;
}
 
Example 36
Project: JavaPPTX   File: PPGroup.java   Source Code and License 5 votes vote down vote up
/**
* Sets the bounding rectangle for this <code>PPGroup</code>.
*
* @param bounds A rectangle specifying the new bounds
*/

  public void setBounds(Rectangle2D bounds) {
     double mx = 0;
     double my = 0;
     for (PPShape shape : contents) {
        mx = Math.min(mx, shape.getX());
        my = Math.min(my, shape.getY());
     }
     this.bounds = bounds;
  }
 
Example 37
Project: rapidminer   File: PlotterAdapter.java   Source Code and License 5 votes vote down vote up
private void drawNominalLegend(Graphics graphics, DataTable table, int legendColumn, int xOffset, int alpha) {
	Graphics2D g = (Graphics2D) graphics.create();
	g.translate(xOffset, 0);

	// painting label name
	String legendName = table.getColumnName(legendColumn);
	g.drawString(legendName, MARGIN, 15);
	Rectangle2D legendNameBounds = LABEL_FONT.getStringBounds(legendName, g.getFontRenderContext());
	g.translate(legendNameBounds.getWidth(), 0);

	// painting values
	int numberOfValues = table.getNumberOfValues(legendColumn);
	int currentX = MARGIN;

	for (int i = 0; i < numberOfValues; i++) {
		if (currentX > getWidth()) {
			break;
		}
		String nominalValue = table.mapIndex(legendColumn, i);
		if (nominalValue.length() > 16) {
			nominalValue = nominalValue.substring(0, 16) + "...";
		}
		Shape colorBullet = new Ellipse2D.Double(currentX, 7, 7.0d, 7.0d);
		Color color = getColorProvider().getPointColor((double) i / (double) (numberOfValues - 1), alpha);
		g.setColor(color);
		g.fill(colorBullet);
		g.setColor(Color.black);
		g.draw(colorBullet);
		currentX += 12;
		g.drawString(nominalValue, currentX, 15);
		Rectangle2D stringBounds = LABEL_FONT.getStringBounds(nominalValue, g.getFontRenderContext());
		currentX += stringBounds.getWidth() + 15;
	}
}
 
Example 38
Project: OpenJSharp   File: CAccessibleText.java   Source Code and License 5 votes vote down vote up
static double[] getBoundsForRange(final Accessible a, final Component c, final int location, final int length) {
    final double[] ret = new double[4];
    if (a == null) return ret;

    return CAccessibility.invokeAndWait(new Callable<double[]>() {
        public double[] call() throws Exception {
            final AccessibleContext ac = a.getAccessibleContext();
            if (ac == null) return ret;

            final AccessibleText at = ac.getAccessibleText();
            if (at == null) {
                ac.getAccessibleName();
                ac.getAccessibleEditableText();
                return ret;
            }

            final Rectangle2D boundsStart = at.getCharacterBounds(location);
            final Rectangle2D boundsEnd = at.getCharacterBounds(location + length - 1);
            if (boundsEnd == null || boundsStart == null) return ret;
            final Rectangle2D boundsUnion = boundsStart.createUnion(boundsEnd);
            if (boundsUnion.isEmpty()) return ret;

            final double localX = boundsUnion.getX();
            final double localY = boundsUnion.getY();

            final Point componentLocation = ac.getAccessibleComponent().getLocationOnScreen();
            final double screenX = componentLocation.getX() + localX;
            final double screenY = componentLocation.getY() + localY;

            ret[0] = screenX;
            ret[1] = screenY; // in java screen coords (from top-left corner of screen)
            ret[2] = boundsUnion.getWidth();
            ret[3] = boundsUnion.getHeight();
            return ret;
        }
    }, c);
}
 
Example 39
Project: jdk8u-jdk   File: CPrinterJob.java   Source Code and License 5 votes vote down vote up
private PeekGraphics createFirstPassGraphics(PrinterJob printerJob, PageFormat page) {
    // This is called from the native side.
    BufferedImage bimg = new BufferedImage((int)Math.round(page.getWidth()), (int)Math.round(page.getHeight()), BufferedImage.TYPE_INT_ARGB_PRE);
    PeekGraphics peekGraphics = createPeekGraphics(bimg.createGraphics(), printerJob);
    Rectangle2D pageFormatArea = getPageFormatArea(page);
    initPrinterGraphics(peekGraphics, pageFormatArea);
    return peekGraphics;
}
 
Example 40
Project: jdk8u-jdk   File: CAccessibleText.java   Source Code and License 5 votes vote down vote up
static double[] getBoundsForRange(final Accessible a, final Component c, final int location, final int length) {
    final double[] ret = new double[4];
    if (a == null) return ret;

    return CAccessibility.invokeAndWait(new Callable<double[]>() {
        public double[] call() throws Exception {
            final AccessibleContext ac = a.getAccessibleContext();
            if (ac == null) return ret;

            final AccessibleText at = ac.getAccessibleText();
            if (at == null) {
                ac.getAccessibleName();
                ac.getAccessibleEditableText();
                return ret;
            }

            final Rectangle2D boundsStart = at.getCharacterBounds(location);
            final Rectangle2D boundsEnd = at.getCharacterBounds(location + length - 1);
            if (boundsEnd == null || boundsStart == null) return ret;
            final Rectangle2D boundsUnion = boundsStart.createUnion(boundsEnd);
            if (boundsUnion.isEmpty()) return ret;

            final double localX = boundsUnion.getX();
            final double localY = boundsUnion.getY();

            final Point componentLocation = ac.getAccessibleComponent().getLocationOnScreen();
            if (componentLocation == null) return ret;

            final double screenX = componentLocation.getX() + localX;
            final double screenY = componentLocation.getY() + localY;

            ret[0] = screenX;
            ret[1] = screenY; // in java screen coords (from top-left corner of screen)
            ret[2] = boundsUnion.getWidth();
            ret[3] = boundsUnion.getHeight();
            return ret;
        }
    }, c);
}
 
Example 41
Project: parabuild-ci   File: XYShapeAnnotation.java   Source Code and License 5 votes vote down vote up
/**
* Draws the annotation.  This method is usually called by the {@link XYPlot} class, you 
* shouldn't need to call it directly.
*
* @param g2  the graphics device.
* @param plot  the plot.
* @param dataArea  the data area.
* @param domainAxis  the domain axis.
* @param rangeAxis  the range axis.
*/
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
        plot.getDomainAxisLocation(), orientation
    );
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
        plot.getRangeAxisLocation(), orientation
    );

    //compute transform matrix elements via sample points. Assume no rotation or shear.
    // x-axis translation
    double m02 = domainAxis.valueToJava2D(0, dataArea, domainEdge); 
    // y-axis translation
    double m12 = rangeAxis.valueToJava2D(0, dataArea, rangeEdge);
    // x-axis scale 
    double m00 = domainAxis.valueToJava2D(1, dataArea, domainEdge) - m02; 
    // y-axis scale
    double m11 = rangeAxis.valueToJava2D(1, dataArea, rangeEdge) - m12; 

    //create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
        AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
        s = t1.createTransformedShape(this.shape);
        s = t2.createTransformedShape(s);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
        s = t.createTransformedShape(this.shape);
    }

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    g2.draw(s);
    
}
 
Example 42
Project: parabuild-ci   File: LegendGraphicTests.java   Source Code and License 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    LegendGraphic g1 = new LegendGraphic(new Rectangle2D.Double(1.0, 2.0, 
            3.0, 4.0), Color.black);
    LegendGraphic g2 = new LegendGraphic(new Rectangle2D.Double(1.0, 2.0, 
            3.0, 4.0), Color.black);
    assertTrue(g1.equals(g2));
    int h1 = g1.hashCode();
    int h2 = g2.hashCode();
    assertEquals(h1, h2);
}
 
Example 43
Project: parabuild-ci   File: Plot.java   Source Code and License 5 votes vote down vote up
/**
 * Fills the specified area with the background paint.
 * 
 * @param g2  the graphics device.
 * @param area  the area.
 * 
 * @see #getBackgroundPaint()
 * @see #getBackgroundAlpha()
 */
protected void fillBackground(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundPaint != null) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
                this.backgroundAlpha));
        g2.setPaint(this.backgroundPaint);
        g2.fill(area);
        g2.setComposite(originalComposite);
    }
}
 
Example 44
Project: rapidminer   File: ColoredBlockContainer.java   Source Code and License 5 votes vote down vote up
/**
 * Draws a colored background. Returns the area wich has been filled.
 */
private Rectangle2D drawFill(Graphics2D g2, Rectangle2D area) {
	Rectangle2D filledArea = (Rectangle2D) area.clone();
	filledArea = trimMargin(filledArea);
	filledArea = trimBorder(filledArea);
	area = trimPadding(area);
	g2.setPaint(this.fillPaint);
	g2.fill(filledArea);
	drawBorder(g2, filledArea);
	return filledArea;
}
 
Example 45
Project: JavaPPTX   File: PPWindowImage.java   Source Code and License 5 votes vote down vote up
private void fillBackground(Graphics2D g) {
   Graphics2D g2 = (Graphics2D) g.create();
   Rectangle2D window = new Rectangle2D.Double(0, 0, sw, sh);
   g2.setComposite(AlphaComposite.Clear);
   g2.fill(window);
   g2.dispose();
}
 
Example 46
Project: ramus   File: MovingText.java   Source Code and License 5 votes vote down vote up
protected void paintText(final Graphics2D g) {
    if (!transparent && !movingArea.isPrinting() || isNegative()) {
        final Rectangle2D rec = movingArea.getBounds(getBounds());
        g.setColor(fiterColor(movingArea.getBackground()));
        g.fill(rec);
    }
    g.setFont(getFont());
    g.setColor(fiterColor(getColor()));

    movingArea.paintText(g, getXText(), getTextBounds(), getAlign(), 1, true);
}
 
Example 47
Project: parabuild-ci   File: PieSectionEntityTests.java   Source Code and License 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    PieSectionEntity e1 = new PieSectionEntity(
        new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), 
        new DefaultPieDataset(), 1, 2, "Key", "ToolTip", "URL"
    ); 
    PieSectionEntity e2 = new PieSectionEntity(
        new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), 
        new DefaultPieDataset(), 1, 2, "Key", "ToolTip", "URL"
    ); 
    assertTrue(e1.equals(e2));  
    
    e1.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertFalse(e1.equals(e2));
    e2.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(e1.equals(e2));  

    e1.setToolTipText("New ToolTip");
    assertFalse(e1.equals(e2));
    e2.setToolTipText("New ToolTip");
    assertTrue(e1.equals(e2));  

    e1.setURLText("New URL");
    assertFalse(e1.equals(e2));
    e2.setURLText("New URL");
    assertTrue(e1.equals(e2));  
}
 
Example 48
Project: parabuild-ci   File: CategoryItemEntityTests.java   Source Code and License 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    CategoryItemEntity e1 = new CategoryItemEntity(
        new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), "ToolTip", "URL",
        new DefaultCategoryDataset(), 1, "Category", 9
    ); 
    CategoryItemEntity e2 = new CategoryItemEntity(
        new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), "ToolTip", "URL",
        new DefaultCategoryDataset(), 1, "Category", 9
    ); 
    assertTrue(e1.equals(e2));  
    
    e1.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertFalse(e1.equals(e2));
    e2.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(e1.equals(e2));  

    e1.setToolTipText("New ToolTip");
    assertFalse(e1.equals(e2));
    e2.setToolTipText("New ToolTip");
    assertTrue(e1.equals(e2));  

    e1.setURLText("New URL");
    assertFalse(e1.equals(e2));
    e2.setURLText("New URL");
    assertTrue(e1.equals(e2));  
    
    e1.setCategory("Category 20");
    assertFalse(e1.equals(e2));
    e2.setCategory("Category 20");
    assertTrue(e1.equals(e2)); 
    
    e1.setCategoryIndex(20);
    assertFalse(e1.equals(e2));
    e2.setCategoryIndex(20);
    assertTrue(e1.equals(e2)); 
    
    e1.setSeries(88);
    assertFalse(e1.equals(e2));
    e2.setSeries(88);
    assertTrue(e1.equals(e2)); 
    
}
 
Example 49
Project: parabuild-ci   File: SymbolAxis.java   Source Code and License 4 votes vote down vote up
/**
 * Draws the grid bands for the axis when it is at the top or bottom of 
 * the plot.
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the chart should be drawn.
 * @param dataArea  the area within which the plot should be drawn
 *                  (a subset of the drawArea).
 * @param firstGridBandIsDark  True: the first grid band takes the
 *                             color of <CODE>gridBandPaint<CODE>.
 *                             False: the second grid band takes the 
 *                             color of <CODE>gridBandPaint<CODE>.
 * @param ticks  the ticks.
 */
protected void drawGridBandsHorizontal(Graphics2D g2,
                                       Rectangle2D plotArea, 
                                       Rectangle2D dataArea,
                                       boolean firstGridBandIsDark, 
                                       List ticks) {

    boolean currentGridBandIsDark = firstGridBandIsDark;
    double yy = dataArea.getY();
    double xx1, xx2;

    //gets the outline stroke width of the plot
    double outlineStrokeWidth;
    if (getPlot().getOutlineStroke() !=  null) {
        outlineStrokeWidth 
            = ((BasicStroke) getPlot().getOutlineStroke()).getLineWidth();
    }
    else {
        outlineStrokeWidth = 1d;
    }

    Iterator iterator = ticks.iterator();
    ValueTick tick;
    Rectangle2D band;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        xx1 = valueToJava2D(tick.getValue() - 0.5d, dataArea, 
                RectangleEdge.BOTTOM);
        xx2 = valueToJava2D(tick.getValue() + 0.5d, dataArea, 
                RectangleEdge.BOTTOM);
        if (currentGridBandIsDark) {
            g2.setPaint(this.gridBandPaint);
        }
        else {
            g2.setPaint(Color.white);
        }
        band = new Rectangle2D.Double(xx1, yy + outlineStrokeWidth, 
            xx2 - xx1, dataArea.getMaxY() - yy - outlineStrokeWidth);
        g2.fill(band);
        currentGridBandIsDark = !currentGridBandIsDark;
    }
    g2.setPaintMode();
}
 
Example 50
Project: geomapapp   File: PDB.java   Source Code and License 4 votes vote down vote up
public void draw( Graphics2D g ) {
		float zoom = 1f / (float) map.getZoom();
		Rectangle2D.Float rect = new Rectangle2D.Float(-3f*zoom, -3f*zoom, 6f*zoom, 6f*zoom);
		Rectangle2D.Float rect1 = new Rectangle2D.Float(-2f*zoom, -2f*zoom, 4f*zoom, 4f*zoom);
		Rectangle2D bounds = g.getClipBounds();
		AffineTransform at = g.getTransform();
		g.setColor( Color.black);
		double lastX = 0;
		double lastY = 0;
		double x, y;
		int n = 0;
		g.setStroke( new BasicStroke(zoom) );
		model.setArea( map.getClipRect2D(), map.getZoom() );

		// First Column Corner Text
		table.setCornerText( model.current.length +" Stations");
		aTable.setCornerText( aModel.analyses.size() +" Analyses");
		sTable.setCornerText( sModel.samples.size() +" Samples");

		double x1 = bounds.getX();
		double x2 = x1+bounds.getWidth();
//		double wrap = map.getWrap();
		for( int i=0 ; i<model.toPlot.length ; i++) {
			x = PDBStation.stations[model.toPlot[i]].getX();
			if(wrap>0.)while(x<x1) x+=wrap;
			y = PDBStation.stations[model.toPlot[i]].getY();

			Color a = computeStationColor(model.toPlot[i]);
			if (a == null) continue;

			g.setColor(a);
			g.translate( x - lastX, y-lastY );
			g.draw(rect1);
			g.setColor(Color.black);
			g.draw(rect);
			if( wrap>0 && x+wrap < bounds.getX()+bounds.getWidth() ) {
				x += wrap;
				g.setColor(a);
				g.translate( wrap, 0.);
				g.draw(rect1);
				g.setColor( Color.black );
				g.draw(rect);
			}
			lastX = x;
			lastY = y;
		}
		current = -1;
		g.setTransform( at);
	}
 
Example 51
Project: openjdk-jdk10   File: TextSourceLabel.java   Source Code and License 4 votes vote down vote up
protected Rectangle2D createLogicalBounds() {
  return getGV().getLogicalBounds();
}
 
Example 52
Project: openjdk-jdk10   File: DelegatingShape.java   Source Code and License 4 votes vote down vote up
public Rectangle2D getBounds2D() {
    return delegate.getBounds2D();  // assumes all delegates are immutable via the returned Rectangle2D
}
 
Example 53
Project: ramus   File: Group.java   Source Code and License 4 votes vote down vote up
public double getScaleY() {
    Rectangle2D rect = getRectangle();
    return (rect.getHeight() + getAddSize().getHeight()) / rect.getHeight();
}
 
Example 54
Project: parabuild-ci   File: PlotRenderingInfo.java   Source Code and License 4 votes vote down vote up
/**
 * Default constructor.
 * 
 * @param owner  the owner.
 */
public PlotRenderingInfo(ChartRenderingInfo owner) {
    this.owner = owner;        
    this.dataArea = new Rectangle2D.Double();
    this.subplotInfo = new java.util.ArrayList();    
}
 
Example 55
Project: parabuild-ci   File: CyclicNumberAxis.java   Source Code and License 4 votes vote down vote up
/**
 * Translates a value from data space to Java 2D space.
 * 
 * @param value  the data value.
 * @param dataArea  the data area.
 * @param edge  the edge.
 * 
 * @return The Java 2D value.
 */
public double valueToJava2D(double value, Rectangle2D dataArea, 
                            RectangleEdge edge) {
    Range range = getRange();
    
    double vmin = range.getLowerBound();
    double vmax = range.getUpperBound();
    double vp = getCycleBound();

    if ((value < vmin) || (value > vmax)) {
        return Double.NaN;
    }
    
    
    double jmin = 0.0;
    double jmax = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        jmin = dataArea.getMinX();
        jmax = dataArea.getMaxX();
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        jmax = dataArea.getMinY();
        jmin = dataArea.getMaxY();
    }

    if (isInverted()) {
        if (value == vp) {
            return this.boundMappedToLastCycle ? jmin : jmax; 
        }
        else if (value > vp) {
            return jmax - (value - vp) * (jmax - jmin) / this.period;
        } 
        else {
            return jmin + (vp - value) * (jmax - jmin) / this.period;
        }
    }
    else {
        if (value == vp) {
            return this.boundMappedToLastCycle ? jmax : jmin; 
        }
        else if (value >= vp) {
            return jmin + (value - vp) * (jmax - jmin) / this.period;
        } 
        else {
            return jmax - (vp - value) * (jmax - jmin) / this.period;
        }
    }
}
 
Example 56
Project: parabuild-ci   File: SymbolicAxis.java   Source Code and License 4 votes vote down vote up
/**
 * Draws the symbolic grid lines.
 * <P>
 * The colors are consecutively the color specified by
 * <CODE>symbolicGridPaint<CODE>
 * (<CODE>DEFAULT_SYMBOLIC_GRID_LINE_PAINT</CODE> by default) and white.
 * or if <CODE>firstGridLineIsDark</CODE> is <CODE>true</CODE> white and
 * the color specified by <CODE>symbolicGridPaint<CODE>.
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the chart should be drawn.
 * @param dataArea  the area within which the plot should be drawn
 *                  (a subset of the drawArea).
 * @param firstGridLineIsDark  True: the first symbolic grid line take the
 *                             color of <CODE>symbolicGridPaint<CODE>.
 *                             False: the first symbolic grid line is white.
 * @param ticks  the ticks.
 */
public void drawSymbolicGridLinesHorizontal(Graphics2D g2,
                                            Rectangle2D plotArea, 
                                            Rectangle2D dataArea,
                                            boolean firstGridLineIsDark, 
                                            List ticks) {

    this.symbolicGridLineList = new Vector(ticks.size());
    boolean currentGridLineIsDark = firstGridLineIsDark;
    double yy = dataArea.getY();
    double xx1, xx2;

    //gets the outline stroke width of the plot
    double outlineStrokeWidth;
    if (getPlot().getOutlineStroke() !=  null) {
        outlineStrokeWidth = ((BasicStroke) getPlot().getOutlineStroke()).getLineWidth();
    }
    else {
        outlineStrokeWidth = 1d;
    }

    Iterator iterator = ticks.iterator();
    ValueTick tick;
    Rectangle2D symbolicGridLine;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        xx1 = valueToJava2D(tick.getValue() - 0.5d, dataArea, RectangleEdge.BOTTOM);
        xx2 = valueToJava2D(tick.getValue() + 0.5d, dataArea, RectangleEdge.BOTTOM);
        if (currentGridLineIsDark) {
            g2.setPaint(this.symbolicGridPaint);
            //g2.setXORMode((Color) this.symbolicGridPaint);
        }
        else {
            g2.setPaint(Color.white);
            //g2.setXORMode(Color.white);
        }
        symbolicGridLine =
            new Rectangle2D.Double(xx1,
                                   yy + outlineStrokeWidth, xx2 - xx1,
                                   dataArea.getMaxY() - yy - outlineStrokeWidth);
        g2.fill(symbolicGridLine);
        this.symbolicGridLineList.add(symbolicGridLine);
        currentGridLineIsDark = !currentGridLineIsDark;
    }
    g2.setPaintMode();
}
 
Example 57
Project: cuttlefish   File: TikzExporter.java   Source Code and License 4 votes vote down vote up
/**
 * Prints the necessary information to display a vertex in the tikz output
 * @param vertex
 */
private void exportVertex(Vertex vertex)
{
	Point2D coordinates = null;
	// if the size is fixed we have to scale the coordinates
	if(fixedSize) {
		Point2D origCoordinates = layout.transform(vertex);		
		coordinates = new Point2D.Double(alpha*(origCoordinates.getX()-xmin), beta*(origCoordinates.getY()-ymin));
		s = Math.max(alpha, beta);
	} else {
		coordinates = layout.transform(vertex);
		s = 1;
	}
	p.print("\\node at (" + formatter.format(coordinates.getX()*coordinateFactor)
			+ "," + formatter.format((maxY - coordinates.getY())*coordinateFactor) + ") [");
	if (vertex.getShape() != null)
	{
		if (vertex.getShape() instanceof Rectangle2D)
			p.print("rectangle,");
		else
			p.print("circle,");
	}
	p.print(" line width=" + formatter.format(vertex.getWidth()*s) + ",");
	
	if ((vertex.getColor() != null) && (vertex.getWidth() > 0))
		p.print(" draw=" + colors.get(vertex.getColor()) + ",");
	if (vertex.getFillColor() != null)
		p.print(" fill=" + colors.get(vertex.getFillColor()) + ",");
	p.print(" inner sep=0pt,");
	p.print(" minimum size = " + formatter.format((vertex.getSize())*nodeSizeFactor*s) + "pt,");
	
	if ((vertex.getLabel() != null) && (true))
	{			
		p.print(" label={[label distance=0]"+					
				//calculateAngle(vertex)
				"315"
				+":" + escapeChars(vertex.getLabel()) + "}");
	}
	if(nodeStyle.compareToIgnoreCase("ball") == 0) {
		p.print(", shading=ball,");
		if (vertex.getFillColor() != null) //The color reappears in the shading
			p.print(" ball color="+ colors.get(vertex.getFillColor() ) );
		else
			p.print(" ball color=black");
	}
				
	p.print("] (" + vertex.getId() + ") {};\n");
}
 
Example 58
Project: QN-ACTR-Release   File: QueueDrawer.java   Source Code and License 4 votes vote down vote up
/**
 * drawing the legend
 * 
 * @param ca
 *            color of the legend
 * @param sa
 *            Comments
 * @param f
 *            font
 * @param x
 *            initial abscissa
 * @param y
 *            initial ordinate
 * @param g2d
 * @return panel lenght 
 */
private double drawLegend(Color[] ca, String[] sa, Font f, double x, double y, Graphics2D g2d, boolean draw) {
	Rectangle2D[] ra = new Rectangle2D[ca.length];
	Rectangle2D[] tba = new Rectangle2D[ca.length];
	double maxw = 0.0, gap = 5.0;
	String ts = "Legenda";
	// backup
	Color ctmp = g2d.getColor();
	Font ftmp = g2d.getFont();

	g2d.setFont(f);
	Rectangle2D tr = f.getStringBounds(ts, g2d.getFontRenderContext());
	maxw = tr.getWidth();
	for (int i = 0; i < ca.length; i++) {
		tba[i] = f.getStringBounds(sa[i], g2d.getFontRenderContext());
		ra[i] = new Rectangle2D.Double(x + gap, y + gap + (tr.getHeight() + gap) * (i + 1), tr.getHeight(), tr.getHeight());
		if (draw) {
			g2d.setColor(ca[i]);
			g2d.fill(ra[i]);
			g2d.setColor(Color.BLACK);
			g2d.draw(ra[i]);
			g2d.drawString(sa[i], (float) (x + gap * 2 + tr.getHeight()), (float) (y + gap + (tr.getHeight() + gap) * (i + 1) + tr.getHeight()
					/ 2.0 - tr.getY() / 2.0));
		}
		if (maxw < tba[i].getWidth()) {
			maxw = tba[i].getWidth();
		}
	}
	if (draw) {
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (y + (tr.getHeight() + gap) * (ca.length + 1) + gap));
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.fillRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.setColor(Color.WHITE);
		g2d.drawString(ts, (float) (x + gap + (maxw - tr.getWidth() + tr.getHeight()) / 2.0), (float) (y + tr.getY() / 2.0 + tr.getHeight()));
	}

	// restore
	g2d.setFont(ftmp);
	g2d.setColor(ctmp);
	return (maxw + 3.0 * gap + tr.getHeight());

}
 
Example 59
Project: openjdk-jdk10   File: CFont.java   Source Code and License 4 votes vote down vote up
Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext,
                                                 int glyphCode) {
   throw new InternalError("Not implemented");
}
 
Example 60
Project: JuniperBotJ   File: BoxBlurFilter.java   Source Code and License 4 votes vote down vote up
@Override
public Rectangle2D getBounds2D(BufferedImage src) {
    return new Rectangle(0, 0, src.getWidth(), src.getHeight());
}