Java 类java.awt.geom.Rectangle2D 实例源码
项目:parabuild-ci
文件:NumberAxis.java
/**
* 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);
}
}
项目:rapidminer
文件:ProcessDrawUtils.java
/**
* 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 + "...";
}
项目:geomapapp
文件:WWUnknownDataSet.java
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();
}
});
}
项目:rapidminer
文件:LinkAndBrushChartPanel.java
/**
* 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();
}
}
}
项目:geomapapp
文件:LayerComposer.java
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;
}
项目:jmt
文件:JobsDrawer.java
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;
}
项目:freecol
文件:Flag.java
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);
}
}
项目:MapAnalyst
文件:MainWindow.java
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;
}
项目:parabuild-ci
文件:FastScatterPlot.java
/**
* 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);
}
}
}
}
项目:openjdk-jdk10
文件:StandardGlyphVector.java
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;
}
项目:parabuild-ci
文件:WaferMapPlot.java
/**
* 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);
}
项目:parabuild-ci
文件:AxisSpace.java
/**
* 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;
}
项目:parabuild-ci
文件:NumberAxisTests.java
/**
* 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));
}
项目:jdk8u-jdk
文件:StandardGlyphVector.java
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;
}
项目:geomapapp
文件:LayerComposer.java
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;
}
项目:geomapapp
文件:LineSegmentsObject.java
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 );
}
}
}
项目:OpenJSharp
文件:TextLayout.java
/**
* 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;
}
项目:OpenJSharp
文件:StandardGlyphVector.java
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);
}
项目:jdk8u-jdk
文件:RenderTests.java
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);
}
项目:jaer
文件:RoShamBoCNN.java
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();
}
项目:Equella
文件:AddressBarButton.java
@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);
}
}
项目:omr-dataset-tools
文件:SymbolInfo.java
public Rectangle2DFacade (Rectangle2D rect)
{
x = rect.getX();
y = rect.getY();
width = rect.getWidth();
height = rect.getHeight();
}
项目:JavaGraph
文件:JGraph.java
/**
* 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);
}
}
}
}
项目:parabuild-ci
文件:PeriodAxis.java
/**
* 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;
}
项目:parabuild-ci
文件:Axis.java
/**
* 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;
}
项目:parabuild-ci
文件:BarRenderer3D.java
/**
* 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);
}
}
项目:FreeCol
文件:InGameMenuBar.java
/**
* 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);
}
}
项目:openjdk-jdk10
文件:TextSourceLabel.java
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());
}
项目:TrabalhoFinalEDA2
文件:mxGraphicsCanvas2D.java
/**
*
*/
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);
}
项目:jmt
文件:QueueDrawer.java
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);
}
项目:openjdk-jdk10
文件:ExtendedTextSourceLabel.java
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]);
}
项目:JavaPPTX
文件:PPGroup.java
@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>");
}
项目:parabuild-ci
文件:AbstractCategoryItemRenderer.java
/**
* 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);
}
项目:parabuild-ci
文件:LogarithmicAxis.java
/**
* 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)
);
}
}
项目:litiengine
文件:PhysicsEngine.java
@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;
}
项目:JavaPPTX
文件:PPGroup.java
/**
* 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;
}
项目:rapidminer
文件:PlotterAdapter.java
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;
}
}
项目:OpenJSharp
文件:CAccessibleText.java
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);
}
项目:jdk8u-jdk
文件:CPrinterJob.java
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;
}
项目:jdk8u-jdk
文件:CAccessibleText.java
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);
}