本文整理汇总了Java中java.awt.Graphics2D.clip方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.clip方法的具体用法?Java Graphics2D.clip怎么用?Java Graphics2D.clip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.clip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawNoDataMessage
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
// FontMetrics fm = g2.getFontMetrics(this.noDataMessageFont);
// Rectangle2D bounds = TextUtilities.getTextBounds(message, g2, fm);
// float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
// float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
// g2.drawString(message, x, y);
TextBlock block = TextUtilities.createTextBlock(
this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint,
0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)
);
block.draw(
g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER
);
}
g2.setClip(savedClip);
}
示例2: drawNoDataMessage
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
TextBlock block = TextUtilities.createTextBlock(
this.noDataMessage, this.noDataMessageFont,
this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
new G2TextMeasurer(g2));
block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(),
TextBlockAnchor.CENTER);
}
g2.setClip(savedClip);
}
示例3: drawGridBands
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the grid bands. Alternate bands are colored using
* <CODE>gridBandPaint<CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by
* default).
*
* @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 edge the axis location.
* @param ticks the ticks.
*/
protected void drawGridBands(Graphics2D g2,
Rectangle2D plotArea,
Rectangle2D dataArea,
RectangleEdge edge,
List ticks) {
Shape savedClip = g2.getClip();
g2.clip(dataArea);
if (RectangleEdge.isTopOrBottom(edge)) {
drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks);
}
else if (RectangleEdge.isLeftOrRight(edge)) {
drawGridBandsVertical(g2, plotArea, dataArea, true, ticks);
}
g2.setClip(savedClip);
}
示例4: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void draw(final BufferedImage from,final Image to) {
final Graphics2D g2d = (Graphics2D) to.getGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.setColor(Color.ORANGE);
g2d.fillRect(0, 0, to.getWidth(null), to.getHeight(null));
g2d.rotate(Math.toRadians(45));
g2d.clip(new Rectangle(41, 42, 43, 44));
g2d.drawImage(from, 50, 50, Color.blue, null);
g2d.dispose();
}
示例5: drawOccupant
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draw one occupant object. First verify that the object is actually
* visible before any drawing, set up the clip appropriately and use the
* DisplayMap to determine which object to call upon to render this
* particular Locatable. Note that we save and restore the graphics
* transform to restore back to normalcy no matter what the renderer did to
* to the coordinate system.
*
* @param g2 the Graphics2D object to use to render
* @param xleft the leftmost pixel of the rectangle
* @param ytop the topmost pixel of the rectangle
* @param obj the Locatable object to draw
*/
private void drawOccupant(Graphics2D g2, int xleft, int ytop, Object obj) {
Rectangle cellToDraw = new Rectangle(xleft, ytop, cellSize, cellSize);
// Only draw if the object is visible within the current clipping
// region.
if (cellToDraw.intersects(g2.getClip().getBounds())) {
Graphics2D g2copy = (Graphics2D) g2.create();
g2copy.clip(cellToDraw);
// Get the drawing object to display this occupant.
Display displayObj = displayMap.findDisplayFor(obj.getClass());
displayObj.draw(obj, this, g2copy, cellToDraw);
g2copy.dispose();
}
}
示例6: getHighRes
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static boolean getHighRes(double[] wesn, int width, int height, BufferedImage image) {
getImage(wesn, width, height, image);
Graphics2D g = image.createGraphics();
Rectangle rect = new Rectangle(0, 0, width, height);
double scale = (wesn[1] - wesn[0]) / (double)width;
double r = 1/scale;
if(r < (double)res[0]) return false;
int ires = 0;
while( r < (double)highRes[ires] && ires<highRes.length-1) ires++;
if(ires == highRes.length-1) ires--;
double gridScale = 600 / (double) highRes[ires];
int x1 = (int) Math.floor( wesn[0] / gridScale);
int x2 = (int) Math.ceil( wesn[1] / gridScale);
int xmax = (int) Math.ceil( 360 / gridScale);
int y1 = (int) Math.ceil( wesn[3] / gridScale);
int y2 = (int) Math.floor( wesn[2] / gridScale);
Rectangle clipRect = new Rectangle(8, 8, 600, 600);
int xgrid, ygrid;
String name;
File file;
double x0, y0;
double west;
double north;
double offset;
double pad = 8 / (double) highRes[ires];
BufferedImage im = null;
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
AffineTransform at = new AffineTransform();
boolean returnVal = false;
for( int x=x1 ; x<x2 ; x++ ) {
xgrid = x;
offset = -pad;
while(xgrid < 0) {
xgrid += xmax;
offset -= 360;
}
while(xgrid >= xmax) {
xgrid -= xmax;
offset += 360;
}
west = (double) xgrid * gridScale + offset;
x0 = (west - wesn[0]) / scale;
for( int y=y1 ; y>y2 ; y--) {
north = (double)y *gridScale + pad;
if( y>0 ) {
name = "g" + highRes[ires] + "_" + xgrid + "_N" + y +".jpg";
} else {
ygrid = -y;
name = "g" + highRes[ires] + "_" + xgrid + "_S" + ygrid +".jpg";
}
String url = "file:/usr/local/seabeam/kn166-14/copy/science/tiles/g"+highRes[ires]+"/" + name;
im = null;
try {
BufferedInputStream in = new BufferedInputStream(
(URLFactory.url(url)).openStream());
//JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
//im = decoder.decodeAsBufferedImage();
im = ImageIO.read(in);
in.close();
} catch ( Exception ioe) {
continue;
}
g.setTransform(at);
g.setClip(rect);
y0 = (wesn[3] - north) / scale ;
g.translate(x0, y0);
double scl = 1 / ((double) highRes[ires] * scale);
g.scale(scl, scl);
g.clip(clipRect);
returnVal = true;
g.drawRenderedImage(im, at);
}
}
return returnVal;
}
示例7: paintNewline
import java.awt.Graphics2D; //导入方法依赖的package包/类
static void paintNewline(Graphics2D g, Shape viewAlloc, Rectangle clipBounds,
DocumentView docView, EditorView view, int viewStartOffset)
{
Rectangle2D viewRectReadonly = ViewUtils.shape2Bounds(viewAlloc);
PaintState paintState = PaintState.save(g);
Shape origClip = g.getClip();
try {
JTextComponent textComponent = docView.getTextComponent();
SplitOffsetHighlightsSequence highlights = docView.getPaintHighlights(view, 0);
boolean showNonPrintingChars = docView.op.isNonPrintableCharactersVisible();
float charWidth = docView.op.getDefaultCharWidth();
boolean logFiner = ViewHierarchyImpl.PAINT_LOG.isLoggable(Level.FINER);
if (logFiner) {
ViewHierarchyImpl.PAINT_LOG.finer(" Newline-View-Id=" + view.getDumpId() + // NOI18N
", startOffset=" + viewStartOffset + ", alloc=" + viewAlloc + '\n' // NOI18N
);
}
while (highlights.moveNext()) {
int hiStartOffset = highlights.getStartOffset();
int hiStartSplitOffset = highlights.getStartSplitOffset();
int hiEndOffset = Math.min(highlights.getEndOffset(), viewStartOffset + 1); // TBD
int hiEndSplitOffset = highlights.getEndSplitOffset();
AttributeSet attrs = highlights.getAttributes();
if (hiStartOffset > viewStartOffset) { // HL above newline
break;
}
double startX = viewRectReadonly.getX() + hiStartSplitOffset * charWidth;
double endX = (hiEndOffset > viewStartOffset)
? viewRectReadonly.getMaxX()
: Math.min(viewRectReadonly.getX() + hiEndSplitOffset * charWidth, viewRectReadonly.getMaxX());
Rectangle2D.Double renderPartRect = new Rectangle2D.Double(startX, viewRectReadonly.getY(), endX - startX, viewRectReadonly.getHeight());
fillBackground(g, renderPartRect, attrs, textComponent);
boolean hitsClip = (clipBounds == null) || renderPartRect.intersects(clipBounds);
if (hitsClip) {
// First render background and background related highlights
// Do not g.clip() before background is filled since otherwise there would be
// painting artifacts for italic fonts (one-pixel slanting lines) at certain positions.
// Clip to part's alloc since textLayout.draw() renders fully the whole text layout
g.clip(renderPartRect);
paintBackgroundHighlights(g, renderPartRect, attrs, docView);
// Render foreground with proper color
g.setColor(HighlightsViewUtils.validForeColor(attrs, textComponent));
Object strikeThroughValue = (attrs != null)
? attrs.getAttribute(StyleConstants.StrikeThrough)
: null;
if (showNonPrintingChars && hiStartSplitOffset == 0) { // First part => render newline char visible representation
TextLayout textLayout = docView.op.getNewlineCharTextLayout();
if (textLayout != null) {
paintTextLayout(g, renderPartRect, textLayout, docView);
}
}
if (strikeThroughValue != null) {
paintStrikeThrough(g, viewRectReadonly, strikeThroughValue, attrs, docView);
}
g.setClip(origClip);
}
if (logFiner) {
ViewHierarchyImpl.PAINT_LOG.finer(" Highlight <" +
hiStartOffset + '_' + hiStartSplitOffset + "," + // NOI18N
hiEndOffset + '_' + hiEndSplitOffset + ">, Color=" + // NOI18N
ViewUtils.toString(g.getColor()) + '\n'); // NOI18N
}
if (clipBounds != null && (renderPartRect.getX() > clipBounds.getMaxX())) {
break;
}
}
} finally {
g.setClip(origClip);
paintState.restore();
}
}
示例8: initContext
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void initContext(TestEnvironment env, Context ctx) {
ctx.graphics = env.getGraphics();
int w = env.getWidth();
int h = env.getHeight();
ctx.size = env.getIntValue(sizeList);
ctx.outdim = getOutputSize(ctx.size, ctx.size);
ctx.pixscale = 1.0;
if (hasGraphics2D) {
Graphics2D g2d = (Graphics2D) ctx.graphics;
AlphaComposite ac = (AlphaComposite) env.getModifier(compRules);
if (env.isEnabled(doExtraAlpha)) {
ac = AlphaComposite.getInstance(ac.getRule(), 0.125f);
}
g2d.setComposite(ac);
if (env.isEnabled(doXor)) {
g2d.setXORMode(Color.white);
}
if (env.isEnabled(doClipping)) {
Polygon p = new Polygon();
p.addPoint(0, 0);
p.addPoint(w, 0);
p.addPoint(0, h);
p.addPoint(w, h);
p.addPoint(0, 0);
g2d.clip(p);
}
Transform tx = (Transform) env.getModifier(transforms);
Dimension envdim = new Dimension(w, h);
tx.init(g2d, ctx, envdim);
w = envdim.width;
h = envdim.height;
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
env.getModifier(renderHint));
}
switch (env.getIntValue(animList)) {
case 0:
ctx.animate = false;
ctx.maxX = 3;
ctx.maxY = 1;
ctx.orgX = (w - ctx.outdim.width) / 2;
ctx.orgY = (h - ctx.outdim.height) / 2;
break;
case 1:
ctx.animate = true;
ctx.maxX = Math.max(Math.min(32, w - ctx.outdim.width), 3);
ctx.maxY = 1;
ctx.orgX = (w - ctx.outdim.width - ctx.maxX) / 2;
ctx.orgY = (h - ctx.outdim.height) / 2;
break;
case 2:
ctx.animate = true;
ctx.maxX = (w - ctx.outdim.width) + 1;
ctx.maxY = (h - ctx.outdim.height) + 1;
ctx.maxX = adjustWidth(ctx.maxX, ctx.maxY);
ctx.maxX = Math.max(ctx.maxX, 3);
ctx.maxY = Math.max(ctx.maxY, 1);
// ctx.orgX = ctx.orgY = 0;
break;
}
ctx.initX = ctx.maxX / 2;
ctx.initY = ctx.maxY / 2;
}
示例9: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a printer).
* <P>
* This plot relies on an {@link org.jfree.chart.renderer.DefaultPolarItemRenderer} to draw
* each item in the plot. This allows the visual representation of the data to be changed
* easily.
* <P>
* The optional info argument collects information about the rendering of
* the plot (dimensions, tooltip information etc). Just pass in <code>null</code> if
* you do not need this information.
*
* @param g2 the graphics device.
* @param plotArea the area within which the plot (including axes and labels) should be drawn.
* @param parentState ignored.
* @param info collects chart drawing information (<code>null</code> permitted).
*/
public void draw(Graphics2D g2,
Rectangle2D plotArea,
PlotState parentState,
PlotRenderingInfo info) {
// if the plot area is too small, just return...
boolean b1 = (plotArea.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (plotArea.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (info != null) {
info.setPlotArea(plotArea);
}
// adjust the drawing area for the plot insets (if any)...
Insets insets = getInsets();
if (insets != null) {
plotArea.setRect(plotArea.getX() + insets.left,
plotArea.getY() + insets.top,
plotArea.getWidth() - insets.left - insets.right,
plotArea.getHeight() - insets.top - insets.bottom);
}
Rectangle2D dataArea = plotArea;
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
double h = Math.min(dataArea.getWidth() / 2.0, dataArea.getHeight() / 2.0) - MARGIN;
Rectangle2D quadrant = new Rectangle2D.Double(
dataArea.getCenterX(), dataArea.getCenterY(), h, h
);
AxisState state = drawAxis(g2, plotArea, quadrant);
if (this.renderer != null) {
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())
);
drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
// draw...
render(g2, dataArea, info);
g2.setClip(originalClip);
g2.setComposite(originalComposite);
}
drawOutline(g2, dataArea);
drawCornerTextItems(g2, dataArea);
}
示例10: saveBaseMap
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Saves current image.
*/
public void saveBaseMap() throws IOException {
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));
int ok = chooser.showSaveDialog(null);
if(ok==chooser.CANCEL_OPTION) return;
Insets ins = new Insets(0,0,0,0);
Rectangle r = getVisibleRect();
int w = width;
int h = height;
Font font = null;
if(mapBorder != null) {
ins = mapBorder.getBorderInsets(this);
float scale = (float)width / (float)r.width;
font = mapBorder.getFont();
Font font1 = font.deriveFont(scale*(float)font.getSize());
mapBorder.setFont(font1);
ins = mapBorder.getBorderInsets(this);
w += ins.left+ins.right;
h += ins.bottom+ins.top;
}
BufferedImage im = new BufferedImage(w, h,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = im.createGraphics();
if(mapBorder != null) {
// GMA 1.4.8: TESTING - Has no affect on borders
mapBorder.paintBorder(this, g2, 0, 0, w, h);
g2.clip( mapBorder.getInteriorRectangle(this,
0, 0, w, h) );
g2.translate(ins.left, ins.top);
mapBorder.setFont(font);
}
for( int i=0 ; i<overlays.size() ; i++) {
if( overlays.get(i) instanceof MapOverlay ) {
((MapOverlay)overlays.get(i)).draw(g2);
break;
}
}
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream( chooser.getSelectedFile()));
//JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//encoder.encode(im);
ImageIO.write(im, "JPEG", out);
out.flush();
out.close();
}
示例11: render
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws a representation of the data within the dataArea region, using the
* current renderer.
* <P>
* The <code>info</code> and <code>crosshairState</code> arguments may be <code>null</code>.
*
* @param g2 the graphics device.
* @param dataArea the region in which the data is to be drawn.
* @param info an optional object for collection dimension information.
* @param crosshairState an optional object for collecting crosshair info.
*/
public void render(Graphics2D g2, Rectangle2D dataArea,
PlotRenderingInfo info, CrosshairState crosshairState) {
// now get the data and plot it (the visual representation will depend
// on the renderer that has been set)...
ContourDataset data = this.getContourDataset();
if (data != null) {
ColorBar zAxis = getColorBar();
if (this.clipPath != null) {
GeneralPath clipper = getClipPath().draw(
g2, dataArea, this.domainAxis, this.rangeAxis
);
if (this.clipPath.isClip()) {
g2.clip(clipper);
}
}
if (this.renderAsPoints) {
pointRenderer(g2, dataArea, info, this,
this.domainAxis, this.rangeAxis, zAxis,
data, crosshairState);
}
else {
contourRenderer(g2, dataArea, info, this,
this.domainAxis, this.rangeAxis, zAxis,
data, crosshairState);
}
// draw vertical crosshair if required...
setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
if (isDomainCrosshairVisible()) {
drawVerticalLine(g2, dataArea,
getDomainCrosshairValue(),
getDomainCrosshairStroke(),
getDomainCrosshairPaint());
}
// draw horizontal crosshair if required...
setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
if (isRangeCrosshairVisible()) {
drawHorizontalLine(g2, dataArea,
getRangeCrosshairValue(),
getRangeCrosshairStroke(),
getRangeCrosshairPaint());
}
}
else if (this.clipPath != null) {
getClipPath().draw(g2, dataArea, this.domainAxis, this.rangeAxis);
}
}
示例12: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a printer).
*
* @param g2 the graphics device.
* @param plotArea the area within which the plot should be drawn.
* @param parentState the state from the parent plot, if there is one.
* @param info collects info about the drawing (<code>null</code> permitted).
*/
public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState,
PlotRenderingInfo info) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Entering draw() method, plot area = " + plotArea.toString());
}
// adjust for insets...
Insets insets = getInsets();
if (insets != null) {
plotArea.setRect(plotArea.getX() + insets.left,
plotArea.getY() + insets.top,
plotArea.getWidth() - insets.left - insets.right,
plotArea.getHeight() - insets.top - insets.bottom
);
}
if (info != null) {
info.setPlotArea(plotArea);
info.setDataArea(plotArea);
}
drawBackground(g2, plotArea);
drawOutline(g2, plotArea);
Shape savedClip = g2.getClip();
g2.clip(plotArea);
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
drawPie(g2, plotArea, info);
}
else {
drawNoDataMessage(g2, plotArea);
}
g2.setClip(savedClip);
g2.setComposite(originalComposite);
drawOutline(g2, plotArea);
}
示例13: paintBorder
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintBorder(Component c, Graphics g,
int x, int y, int width, int height) {
if (!(g instanceof Graphics2D)) {
return;
}
Graphics2D g2 = (Graphics2D) g.create();
int[] widths = getWidths();
// Position and size of the border interior.
int intX = x + widths[LEFT];
int intY = y + widths[TOP];
int intWidth = width - (widths[RIGHT] + widths[LEFT]);
int intHeight = height - (widths[TOP] + widths[BOTTOM]);
// Coordinates of the interior corners, from NW clockwise.
int[][] intCorners = {
{ intX, intY },
{ intX + intWidth, intY },
{ intX + intWidth, intY + intHeight },
{ intX, intY + intHeight, },
};
// Draw the borders for all sides.
for (int i = 0; i < 4; i++) {
Value style = getBorderStyle(i);
Polygon shape = getBorderShape(i);
if ((style != Value.NONE) && (shape != null)) {
int sideLength = (i % 2 == 0 ? intWidth : intHeight);
// "stretch" the border shape by the interior area dimension
shape.xpoints[2] += sideLength;
shape.xpoints[3] += sideLength;
Color color = getBorderColor(i);
BorderPainter painter = getBorderPainter(i);
double angle = i * Math.PI / 2;
g2.setClip(g.getClip()); // Restore initial clip
g2.translate(intCorners[i][0], intCorners[i][1]);
g2.rotate(angle);
g2.clip(shape);
painter.paint(shape, g2, color, i);
g2.rotate(-angle);
g2.translate(-intCorners[i][0], -intCorners[i][1]);
}
}
g2.dispose();
}
示例14: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
* <P>
* This plot relies on a {@link PolarItemRenderer} to draw each
* item in the plot. This allows the visual representation of the data to
* be changed easily.
* <P>
* The optional info argument collects information about the rendering of
* the plot (dimensions, tooltip information etc). Just pass in
* <code>null</code> if you do not need this information.
*
* @param g2 the graphics device.
* @param area the area within which the plot (including axes and
* labels) should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState ignored.
* @param info collects chart drawing information (<code>null</code>
* permitted).
*/
public void draw(Graphics2D g2,
Rectangle2D area,
Point2D anchor,
PlotState parentState,
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);
Rectangle2D dataArea = area;
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
double h = Math.min(dataArea.getWidth() / 2.0,
dataArea.getHeight() / 2.0) - MARGIN;
Rectangle2D quadrant = new Rectangle2D.Double(dataArea.getCenterX(),
dataArea.getCenterY(), h, h);
AxisState state = drawAxis(g2, area, quadrant);
if (this.renderer != null) {
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, getForegroundAlpha()));
drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
// draw...
render(g2, dataArea, info);
g2.setClip(originalClip);
g2.setComposite(originalComposite);
}
drawOutline(g2, dataArea);
drawCornerTextItems(g2, dataArea);
}
示例15: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the fast scatter plot on a Java 2D graphics device (such as the
* screen or a printer).
*
* @param g2 the graphics device.
* @param area the area within which the plot (including axis labels)
* should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the state from the parent plot (ignored).
* @param info collects chart drawing information (<code>null</code>
* permitted).
*/
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
PlotState parentState,
PlotRenderingInfo info) {
// set up info collection...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
AxisSpace space = new AxisSpace();
space = this.domainAxis.reserveSpace(g2, this, area,
RectangleEdge.BOTTOM, space);
space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT,
space);
Rectangle2D dataArea = space.shrink(area, null);
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
AxisState domainAxisState = this.domainAxis.draw(g2,
dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(),
area, dataArea, RectangleEdge.LEFT, info);
drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
getForegroundAlpha()));
render(g2, dataArea, info, null);
g2.setClip(originalClip);
g2.setComposite(originalComposite);
drawOutline(g2, dataArea);
}