本文整理匯總了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);
}
}
示例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 + "...";
}
示例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();
}
});
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
示例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;
}
示例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 );
}
}
}