本文整理汇总了Java中java.awt.Graphics2D.create方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.create方法的具体用法?Java Graphics2D.create怎么用?Java Graphics2D.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintHeader
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Paints the header
*
* @param g
*/
private void paintHeader(Graphics2D g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setClip(new Rectangle(x, y, width, HEADER_HEIGHT));
if (node.getParentNodeContainer().getSelection().contains(node)) {
g2d.setColor(new Color(0x555555));
} else {
g2d.setColor(new Color(0x333333));
}
g2d.fillRect(x + 5, y + 5, width - 11, HEADER_HEIGHT - 5);
if (node.getParentNodeContainer().getSelection().contains(node)) {
g2d.setColor(new Color(0x1da6b0));
g2d.fillRect(x + 5, y + HEADER_HEIGHT - 2, width - 11, 2);
} else {
g2d.setColor(new Color(0xa0a0a0));
g2d.fillRect(x + 10, y + HEADER_HEIGHT - 2, width - 21, 2);
}
g2d.dispose();
}
示例2: drawCenteredText
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws text centered in the process.
*
* @param process
* the process in question
* @param g2
* the graphics context
* @param font
* @param text
* @param color
* @param yOffset
*/
private void drawCenteredText(ExecutionUnit process, Graphics2D g2, Font font, String text, Color color, double yOffset) {
double width = model.getProcessWidth(process);
double height = model.getProcessHeight(process);
Graphics2D g2d = (Graphics2D) g2.create();
g2d.setFont(font);
Rectangle2D bounds = g2d.getFontMetrics().getStringBounds(text, g2d);
int x = (int) (width / 2 - bounds.getWidth() / 2);
int y = (int) (height / 2 + bounds.getHeight() / 2 + yOffset);
g2d.setColor(color);
g2d.drawString(text, x, y);
g2d.dispose();
}
示例3: drawAnnoDragIndicators
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the drag indicators for annotations.
*
* @param g
* the graphics context to draw upon
* @param anno
* the current annotation to draw
* @param loc
* the location of the annotation
* @param printing
* if we are currently printing
*/
private void drawAnnoDragIndicators(final Graphics2D g, final WorkflowAnnotation anno, final Rectangle2D loc,
final boolean printing) {
if (printing) {
// never draw them for printing
return;
}
AnnotationDragHelper dragged = model.getDragged();
if (dragged.getHoveredOperator() == null) {
return;
}
Graphics2D g2 = (Graphics2D) g.create();
int padding = 15;
Rectangle2D opRect = rendererModel.getOperatorRect(dragged.getHoveredOperator());
opRect = new Rectangle2D.Double(opRect.getX(), opRect.getY(), opRect.getWidth(), opRect.getHeight());
Rectangle2D shadowRect = new Rectangle2D.Double(opRect.getX() - padding - 1, opRect.getY() - padding - 1,
opRect.getWidth() + 2 * padding + 1, opRect.getHeight() + 2 * padding + 1);
g2.setColor(DRAG_LINK_COLOR);
g2.setStroke(DRAG_BORDER_STROKE);
g2.draw(shadowRect);
g2.dispose();
}
示例4: printAnnotationFromEditor
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Bypass the cache and the speedy image drawing and directly paint the JEditorPane to the
* context. Required for printing in SVG format which would turn out pixelated if it were drawn
* as an image.
*
* @param anno
* the annotation to draw
* @param g2
* the graphics context to draw upon
*/
private void printAnnotationFromEditor(final WorkflowAnnotation anno, final Graphics2D g2) {
Graphics2D gPr = (Graphics2D) g2.create();
Rectangle2D loc = anno.getLocation();
gPr.translate(loc.getX(), loc.getY());
gPr.setClip(0, 0, (int) loc.getWidth(), (int) loc.getHeight());
// paint each annotation with the same JEditorPane
Dimension size = new Dimension((int) loc.getWidth(), (int) loc.getHeight());
pane.setSize(size);
pane.setText(AnnotationDrawUtils.createStyledCommentString(anno));
pane.setCaretPosition(0);
// draw annotation area to image and then to graphics
// otherwise heavyweight JEdiorPane draws over everything and outside of panel
// paint JEditorPane to context
pane.paint(gPr);
gPr.dispose();
}
示例5: drawOpAnno
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the annotation for the given operator (if he has one).
*/
private void drawOpAnno(final Operator operator, final Graphics2D g2, final ProcessRendererModel rendererModel,
final boolean printing) {
WorkflowAnnotations annotations = rendererModel.getOperatorAnnotations(operator);
if (annotations == null) {
return;
}
for (WorkflowAnnotation anno : annotations.getAnnotationsDrawOrder()) {
// selected is drawn by highlight decorator
if (anno.equals(model.getSelected())) {
continue;
}
// paint the annotation itself
Graphics2D g2P = (Graphics2D) g2.create();
drawer.drawAnnotation(anno, g2P, printing);
g2P.dispose();
}
}
示例6: 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();
}
}
示例7: clear
import java.awt.Graphics2D; //导入方法依赖的package包/类
static void clear(Graphics2D g, int type, int w, int h) {
Graphics2D gg = (Graphics2D) g.create();
if (type > OPAQUE) {
gg.setColor(new Color(0, 0, 0, 0));
gg.setComposite(AlphaComposite.Src);
} else {
gg.setColor(new Color(0xAD, 0xD8, 0xE6));
}
gg.fillRect(0, 0, w, h);
}
示例8: drawOperatorBackgrounds
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws operator backgrounds and then calls all registered {@link ProcessDrawDecorator}s for
* the annotations render phase.
*
* @param process
* the process to draw the operator backgrounds for
* @param g2
* the graphics context to draw upon
* @param printing
* if {@code true} we are printing instead of drawing to the screen
*/
public void drawOperatorBackgrounds(final ExecutionUnit process, final Graphics2D g2, final boolean printing) {
Graphics2D gBG = (Graphics2D) g2.create();
// draw background of operators
for (Operator op : process.getOperators()) {
Rectangle2D frame = model.getOperatorRect(op);
if (frame == null) {
continue;
}
// only draw background if operator is visisble
Rectangle2D opBounds = new Rectangle2D.Double(frame.getX() - 10, frame.getY(), frame.getWidth() + 20,
frame.getHeight());
if (g2.getClipBounds() != null && !g2.getClipBounds().intersects(opBounds)) {
continue;
}
renderOperatorBackground(op, gBG);
}
// draw connections background for all operators
for (Operator operator : process.getOperators()) {
renderConnectionsBackground(operator.getInputPorts(), operator.getOutputPorts(), gBG);
}
// draw connections background for process
renderConnectionsBackground(process.getInnerSinks(), process.getInnerSources(), gBG);
gBG.dispose();
// let decorators draw
drawPhaseDecorators(process, g2, RenderPhase.OPERATOR_BACKGROUND, printing);
}
示例9: drawShadow
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws a shadow around the given rectangle.
*
* @param rect
* the rectangle which should get a shadow
* @param g2
* the graphics context to draw the shadow on
*/
public static void drawShadow(final Rectangle2D rect, final Graphics2D g2) {
Graphics2D g2S = (Graphics2D) g2.create();
Rectangle2D shadow = new Rectangle2D.Double(rect.getX() + 5, rect.getY() + ProcessDrawer.HEADER_HEIGHT + 5,
rect.getWidth(), rect.getHeight() - ProcessDrawer.HEADER_HEIGHT);
GeneralPath bottom = new GeneralPath();
bottom.moveTo(shadow.getX(), rect.getMaxY());
bottom.lineTo(rect.getMaxX(), rect.getMaxY());
bottom.lineTo(shadow.getMaxX(), shadow.getMaxY());
bottom.lineTo(shadow.getMinX(), shadow.getMaxY());
bottom.closePath();
g2S.setPaint(new GradientPaint((float) rect.getX(), (float) rect.getMaxY(), Color.gray, (float) rect.getX(),
(float) shadow.getMaxY(), TRANSPARENT_GRAY));
g2S.fill(bottom);
GeneralPath right = new GeneralPath();
right.moveTo(rect.getMaxX(), shadow.getMinY());
right.lineTo(shadow.getMaxX(), shadow.getMinY());
right.lineTo(shadow.getMaxX(), shadow.getMaxY());
right.lineTo(rect.getMaxX(), rect.getMaxY());
right.closePath();
g2S.setPaint(new GradientPaint((float) rect.getMaxX(), (float) shadow.getY(), Color.gray, (float) shadow.getMaxX(),
(float) shadow.getY(), TRANSPARENT_GRAY));
g2S.fill(right);
g2S.dispose();
}
示例10: overshadowRect
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Shadows the given rectangle. Gives a disabled look to the given area.
*
* @param rect
* the area to draw the shadow over
* @param g
* the context to draw upon
*/
private void overshadowRect(final Rectangle2D rect, final Graphics2D g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(GRAY_OUT);
g2.fill(rect);
g2.dispose();
}
示例11: drawOverflowIndicator
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws indicator in case the annotation text overflows on the y axis.
*
* @param anno
* the annotation
* @param g
* the graphics context to draw upon
* @param loc
* the location of the annotation
* @param printing
* if we are currently printing
*/
private void drawOverflowIndicator(final WorkflowAnnotation anno, final Graphics2D g, final Rectangle2D loc,
final boolean printing) {
if (printing) {
// never draw them for printing
return;
}
Graphics2D g2 = (Graphics2D) g.create();
int size = 20;
int xOffset = 10;
int yOffset = 10;
int stepSize = size / 4;
int dotSize = 3;
int x = (int) loc.getMaxX() - size - xOffset;
int y = (int) loc.getMaxY() - size - yOffset;
GradientPaint gp = new GradientPaint(x, y, Color.WHITE, x, y + size * 1.5f, Color.LIGHT_GRAY);
g2.setPaint(gp);
g2.fillRect(x, y, size, size);
g2.setColor(Color.BLACK);
g2.drawRect(x, y, size, size);
g2.fillOval(x + stepSize, y + stepSize * 2, dotSize, dotSize);
g2.fillOval(x + stepSize * 2, y + stepSize * 2, dotSize, dotSize);
g2.fillOval(x + stepSize * 3, y + stepSize * 2, dotSize, dotSize);
g2.dispose();
}
示例12: fillBackground
import java.awt.Graphics2D; //导入方法依赖的package包/类
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();
}
示例13: drawCursor
import java.awt.Graphics2D; //导入方法依赖的package包/类
/** dessine un cursseur dont le centre en X est centerX, et le centre en Y est centerY */
public static void drawCursor(final Graphics2D g, final Color fillColor, final Color drawColor, final int centerX, final int centerY) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(fillColor);
g2.fillRoundRect(centerX - CURSOR_W / 2, centerY - CURSOR_H / 2, CURSOR_W, CURSOR_H, ARC_SIZE, ARC_SIZE);
g2.setColor(drawColor);
g2.drawRoundRect(centerX - CURSOR_W / 2, centerY - CURSOR_H / 2, CURSOR_W, CURSOR_H, ARC_SIZE, ARC_SIZE);
g2.dispose();
}
示例14: drawPoints
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawPoints(Graphics2D g, int pixWidth, int pixHeight) {
double sx = 0.0d;
double sy = 0.0d;
sx = ((double) pixWidth - LABEL_MARGIN_X) / (maxX - minX);
sy = ((double) pixHeight - LABEL_MARGIN_Y) / (maxY - minY);
Graphics2D coordinateSpace = (Graphics2D) g.create();
coordinateSpace.translate(LABEL_MARGIN_X, LABEL_MARGIN_Y);
drawGrid(coordinateSpace, -minX, -minY, sx, sy);
drawPoints(coordinateSpace, -minX, -minY, sx, sy);
coordinateSpace.dispose();
}
示例15: calcFontMetrics
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void calcFontMetrics( Graphics2D g2d, int w, int h ) {
FontMetrics fm;
Graphics2D g2 = (Graphics2D)g2d.create();
/// ABP
if ( g2Transform != NONE && textToUse != FILE_TEXT ) {
g2.setFont( g2.getFont().deriveFont( getAffineTransform( g2Transform )) );
fm = g2.getFontMetrics();
}
else {
fm = g2.getFontMetrics();
}
maxAscent = fm.getMaxAscent();
maxDescent = fm.getMaxDescent();
if (maxAscent == 0) maxAscent = 10;
if (maxDescent == 0) maxDescent = 5;
if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
/// Give slight extra room for each character
maxAscent += 3;
maxDescent += 3;
gridWidth = fm.getMaxAdvance() + 6;
gridHeight = maxAscent + maxDescent;
if ( force16Cols )
numCharAcross = 16;
else
numCharAcross = ( w - 10 ) / gridWidth;
numCharDown = ( h - 10 ) / gridHeight;
canvasInset_X = ( w - numCharAcross * gridWidth ) / 2;
canvasInset_Y = ( h - numCharDown * gridHeight ) / 2;
if ( numCharDown == 0 || numCharAcross == 0 )
throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
if ( !isPrinting )
resetScrollbar( verticalBar.getValue() * numCharAcross );
}
else {
maxDescent += fm.getLeading();
canvasInset_X = 5;
canvasInset_Y = 5;
/// gridWidth and numCharAcross will not be used in this mode...
gridHeight = maxAscent + maxDescent;
numCharDown = ( h - canvasInset_Y * 2 ) / gridHeight;
if ( numCharDown == 0 )
throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
/// If this is text loaded from file, prepares the LineBreak'ed
/// text layout at this point
if ( textToUse == FILE_TEXT ) {
if ( !isPrinting )
f2dt.fireChangeStatus( "LineBreaking Text... Please Wait", false );
lineBreakTLs = new Vector();
for ( int i = 0; i < fileText.length; i++ ) {
AttributedString as =
new AttributedString( fileText[i], g2.getFont().getAttributes() );
LineBreakMeasurer lbm =
new LineBreakMeasurer( as.getIterator(), g2.getFontRenderContext() );
while ( lbm.getPosition() < fileText[i].length() )
lineBreakTLs.add( lbm.nextLayout( (float) w ));
}
}
if ( !isPrinting )
resetScrollbar( verticalBar.getValue() );
}
}