当前位置: 首页>>代码示例>>Java>>正文


Java Rectangle2D类代码示例

本文整理汇总了Java中java.awt.geom.Rectangle2D的典型用法代码示例。如果您正苦于以下问题:Java Rectangle2D类的具体用法?Java Rectangle2D怎么用?Java Rectangle2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Rectangle2D类属于java.awt.geom包,在下文中一共展示了Rectangle2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: valueToJava2D

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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);
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:37,代码来源:NumberAxis.java

示例2: fitString

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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 + "...";
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:32,代码来源:ProcessDrawUtils.java

示例3: setArea

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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();
		}
	});
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:21,代码来源:WWUnknownDataSet.java

示例4: drawZoomRectangle

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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();
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:LinkAndBrushChartPanel.java

示例5: getSpreadingRateGridLayer

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:21,代码来源:LayerComposer.java

示例6: drawCenteredText

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:18,代码来源:JobsDrawer.java

示例7: drawQuarters

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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);
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:17,代码来源:Flag.java

示例8: getNewMapImageInfo

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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;
}
 
开发者ID:berniejenny,项目名称:MapAnalyst,代码行数:27,代码来源:MainWindow.java

示例9: drawRangeGridlines

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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);                
            }
        }
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:FastScatterPlot.java

示例10: getGlyphMetrics

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:StandardGlyphVector.java

示例11: draw

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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);
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:34,代码来源:WaferMapPlot.java

示例12: reserved

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:AxisSpace.java

示例13: testTranslateJava2DToValue

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
/**
 * 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)); 
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:NumberAxisTests.java

示例14: getTopoGridLayer

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:21,代码来源:LayerComposer.java

示例15: drawSeg

import java.awt.geom.Rectangle2D; //导入依赖的package包/类
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 );
		}
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:27,代码来源:LineSegmentsObject.java


注:本文中的java.awt.geom.Rectangle2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。