List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:Main.java
/** * Creates a nifty looking inner shadow for the window. * @param width The width of the shadow. * @param height The height of the shadow. * @return The translucent shadow that was created. *//*from w w w .java 2 s . c om*/ public static BufferedImage genInnerShadow(int width, int height) { BufferedImage shadowOuter = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = shadowOuter.getGraphics(); Graphics2D g2 = (Graphics2D) g; Point2D center = new Point2D.Float(width / 2, height / 2); float radius = width; Point2D focus = new Point2D.Float(width / 2, height / 2); float[] dist = { 0.0f, 1.0f }; Color[] colors = { new Color(0, 0, 0, 0), new Color(0, 0, 0, 220) }; RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE); g2.setPaint(p); g2.fillRect(0, 0, width, height); return shadowOuter; }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static void drawMaskBoarder(Graphics2D g2, Rectangle2D frame) { g2.setPaint(Color.orange); g2.setStroke(new BasicStroke(1)); g2.draw(frame);/*from w w w. ja va2 s . c om*/ Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(frame); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) { g2.setPaint(Color.orange); g2.setStroke(new BasicStroke(1)); Rectangle2D frame = mask.getRectangleFrame(); g2.draw(frame);/*from www. ja va2s .c o m*/ Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); Color fillColor = new Color(250, 250, 50, 10); g2.setPaint(fillColor); g2.fill(mask.getShape()); }
From source file:org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.java
/** * Returns an ARGB image filled with the given paint and using the given image as a mask. * @param paint the paint to fill the visible portions of the image with * @return a masked image filled with the given paint * @throws IOException if the image cannot be read * @throws IllegalStateException if the image is not a stencil. *///from w w w . ja v a 2 s. co m public static BufferedImage getStencilImage(PDImage pdImage, Paint paint) throws IOException { // get mask (this image) BufferedImage mask = getRGBImage(pdImage, null); // compose to ARGB BufferedImage masked = new BufferedImage(mask.getWidth(), mask.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = masked.createGraphics(); // draw the mask //g.drawImage(mask, 0, 0, null); // fill with paint using src-in //g.setComposite(AlphaComposite.SrcIn); g.setPaint(paint); g.fillRect(0, 0, mask.getWidth(), mask.getHeight()); g.dispose(); // set the alpha int width = masked.getWidth(); int height = masked.getHeight(); WritableRaster raster = masked.getRaster(); WritableRaster alpha = mask.getRaster(); final float[] transparent = new float[4]; float[] alphaPixel = null; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { alphaPixel = alpha.getPixel(x, y, alphaPixel); if (alphaPixel[0] == 255) { raster.setPixel(x, y, transparent); } } } return masked; }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static void drawShape(Graphics2D g2, Rectangle2D imageArea, Shape shape, Color color, JFreeChart chart) { g2.clip(imageArea);//from w ww .ja v a 2 s . c om g2.setPaint(color); Shape newShape = translateChartShape(shape, imageArea, chart); if (shape == null) { return; } g2.draw(newShape); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
private static void drawDomainMask(Graphics2D g2, Rectangle2D imageArea, RangeMask mask, RangeMask selectedMask, JFreeChart chart, double fontSizeRate, Color fillColor) { g2.clip(imageArea);/*from w w w . j a v a 2s . co m*/ g2.setPaint(fillColor); Rectangle2D translatedRectangle = getDomainMaskFrame(mask, imageArea, chart); if (translatedRectangle == null || translatedRectangle.isEmpty()) { return; } drawMask(g2, translatedRectangle); if (mask == selectedMask) { drawMaskBoarder(g2, translatedRectangle); } drawMaskName(g2, mask, translatedRectangle, fontSizeRate); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
/** * Draws mask rectangle (if present)./*from ww w .j ava 2 s . c o m*/ * 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 static void drawMaskRectangle(Graphics2D g2, Rectangle2D imageArea, Abstract2DMask mask, Abstract2DMask selectedMask, JFreeChart chart, double fontSizeRate, Color fillColor) { g2.clip(imageArea); g2.setPaint(fillColor); Abstract2DMask translatedMask = translateChartRectangle(mask, imageArea, chart); if (translatedMask == null || translatedMask.getRectangleFrame().isEmpty()) { return; } drawMask(g2, translatedMask.getShape()); if (mask == selectedMask) { drawMaskBoarder(g2, translatedMask); } drawMaskName(g2, translatedMask, imageArea, fontSizeRate); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
private static void drawMaskName(Graphics2D g2, AbstractMask mask, Rectangle2D imageArea, double fontSizeRate) { if (mask.getName() == null) { return;//from w w w .j a v a 2 s . co m } Point2D fontLocation = mask.getTitleLocation(imageArea); g2.setPaint(Color.black); Font currentFont = g2.getFont(); g2.setFont(currentFont.deriveFont((float) (maskNameFont.getSize() * fontSizeRate)).deriveFont(Font.ITALIC)); g2.drawString(mask.getName(), (int) fontLocation.getX(), (int) fontLocation.getY()); g2.setFont(currentFont); }
From source file:main.java.whiteSocket.Bloop.java
public static BufferedImage createWhiteImage() { BufferedImage testOut = new BufferedImage(Bloop.blooprint.getWidth(), Bloop.blooprint.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = testOut.createGraphics(); graphics.setPaint(Color.white); graphics.fillRect(0, 0, testOut.getWidth(), testOut.getHeight()); return testOut; }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * @param g2 graphics2D object/*from ww w . java 2s .c o m*/ */ private static void plotColorScaleBar(Graphics2D g2) { // calculate color scale bar dimensions & location Point csBarTL = new Point(heatmapWidth + colorScaleHorizontalMargin, colorScaleVerticalMargin); Point csBarBL = new Point(heatmapWidth + colorScaleHorizontalMargin, fullHeight - colorScaleVerticalMargin); Rectangle csBar = new Rectangle(csBarTL.x, csBarTL.y, colorScaleWidth - 2 * colorScaleHorizontalMargin, fullHeight - 2 * colorScaleVerticalMargin); // plot the color scale linear gradient LinearGradientPaint gradient = new LinearGradientPaint(csBarTL, csBarBL, gradientFractions, gradientColors); g2.setPaint(gradient); g2.fill(csBar); // plot a border around color scale g2.setColor(Color.black); g2.drawRect(csBar.x, csBar.y, csBar.width, csBar.height); }