Java Code Examples for java.awt.AlphaComposite#getInstance()
The following examples show how to use
java.awt.AlphaComposite#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FadingButtonTF.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void paint(Graphics g) { // Create an image for the button graphics if necessary if (buttonImage == null || buttonImage.getWidth() != getWidth() || buttonImage.getHeight() != getHeight()) { buttonImage = getGraphicsConfiguration(). createCompatibleImage(getWidth(), getHeight()); } Graphics gButton = buttonImage.getGraphics(); gButton.setClip(g.getClip()); // Have the superclass render the button for us super.paint(gButton); // Make the graphics object sent to this paint() method translucent Graphics2D g2d = (Graphics2D)g; AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); g2d.setComposite(newComposite); // Copy the button's image to the destination graphics, translucently g2d.drawImage(buttonImage, 0, 0, null); }
Example 2
Source File: Displayable.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
static public Composite getComposite( byte mode, float alpha ) { final Composite composite; switch ( mode ) { case Displayable.COMPOSITE_ADD: composite = AddARGBComposite.getInstance( alpha ); break; case Displayable.COMPOSITE_SUBTRACT: composite = SubtractARGBComposite.getInstance( alpha ); break; case Displayable.COMPOSITE_MULTIPLY: composite = MultiplyARGBComposite.getInstance( alpha ); break; case Displayable.COMPOSITE_DIFFERENCE: composite = DifferenceARGBComposite.getInstance( alpha ); break; case Displayable.COMPOSITE_COLOR_YCBCR: composite = ColorYCbCrComposite.getInstance( alpha ); break; default: composite = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha ); } return composite; }
Example 3
Source File: MainPanel.java From javagame with MIT License | 6 votes |
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // �A���t�@�l AlphaComposite composite = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.5f); g2.setColor(Color.RED); g2.fillOval(50, 50, 100, 100); // �A���t�@�l���Z�b�g�i�Ȍ�̕`��͔������ɂȂ�j g2.setComposite(composite); g2.setColor(Color.BLUE); g2.fillRect(90, 90, 100, 100); }
Example 4
Source File: SubcircuitFactory.java From Logisim with GNU General Public License v3.0 | 6 votes |
@Override public void paintGhost(InstancePainter painter) { Graphics g = painter.getGraphics(); Color fg = g.getColor(); int v = fg.getRed() + fg.getGreen() + fg.getBlue(); Composite oldComposite = null; if (g instanceof Graphics2D && v > 50) { oldComposite = ((Graphics2D) g).getComposite(); Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); ((Graphics2D) g).setComposite(c); } paintBase(painter, g); if (oldComposite != null) { ((Graphics2D) g).setComposite(oldComposite); } }
Example 5
Source File: DefaultPolarItemRenderer.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Creates a new instance of DefaultPolarItemRenderer */ public DefaultPolarItemRenderer() { this.seriesFilled = new BooleanList(); this.drawOutlineWhenFilled = true; this.fillComposite = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.3f); this.useFillPaint = false; // use item paint for fills by default this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0); this.shapesVisible = true; this.connectFirstAndLastPoint = true; this.toolTipGeneratorList = new ObjectList(); this.urlGenerator = null; this.legendItemToolTipGenerator = null; this.legendItemURLGenerator = null; }
Example 6
Source File: AnimationLayer.java From netbeans with Apache License 2.0 | 6 votes |
/** * Paints the current state (i.e. the state corresponding to the current * phase) of the given component. * * @param g graphics context. * @param comp component to paint. */ private void paintComponent(Graphics g, Component comp) { Rectangle bounds = currentBounds(comp); float alpha = currentAlpha(comp); Graphics gg = g.create(bounds.x, bounds.y, bounds.width, bounds.height); if (alpha != 1f) { AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); ((Graphics2D)gg).setComposite(alphaComposite); } comp.setBounds(bounds); comp.validate(); // Intentionally using print instead of paint. // Print doesn't use double buffering and it solves some mysterious // problems with modified clip during painting of containers. // BTW: animated transitions library also uses print() if (comp instanceof JComponent) { comp.print(gg); } else { java.awt.peer.ComponentPeer peer = FakePeerSupport.getPeer(comp); if (peer != null) { peer.paint(gg); } } gg.dispose(); }
Example 7
Source File: DefaultPolarItemRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Creates a new instance of DefaultPolarItemRenderer */ public DefaultPolarItemRenderer() { this.seriesFilled = new BooleanList(); this.drawOutlineWhenFilled = true; this.fillComposite = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.3f); this.useFillPaint = false; // use item paint for fills by default this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0); this.shapesVisible = true; this.connectFirstAndLastPoint = true; this.toolTipGeneratorList = new ObjectList(); this.urlGenerator = null; this.legendItemToolTipGenerator = null; this.legendItemURLGenerator = null; }
Example 8
Source File: BlendComposite.java From sambox with Apache License 2.0 | 6 votes |
/** * Creates a blend composite * * @param blendMode Desired blend mode * @param constantAlpha Constant alpha, must be in the inclusive range [0.0...1.0] or it will be clipped. * @return a blend composite. */ public static Composite getInstance(BlendMode blendMode, float constantAlpha) { if (constantAlpha < 0) { LOG.warn("using 0 instead of incorrect Alpha " + constantAlpha); constantAlpha = 0; } else if (constantAlpha > 1) { LOG.warn("using 1 instead of incorrect Alpha " + constantAlpha); constantAlpha = 1; } if (blendMode == BlendMode.NORMAL) { return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, constantAlpha); } else { return new BlendComposite(blendMode, constantAlpha); } }
Example 9
Source File: ImageScope.java From MyBox with Apache License 2.0 | 5 votes |
public static BufferedImage indicateCircle(BufferedImage source, Color color, int lineWidth, DoubleCircle circle) { try { if (!circle.isValid()) { return source; } int width = source.getWidth(); int height = source.getHeight(); int imageType = source.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_ARGB; } BufferedImage target = new BufferedImage(width, height, imageType); Graphics2D g = target.createGraphics(); g.drawImage(source, 0, 0, width, height, null); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); g.setComposite(ac); g.setColor(color); BasicStroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1f, new float[]{lineWidth, lineWidth}, 0f); g.setStroke(stroke); g.drawOval((int) circle.getCenterX() - (int) circle.getRadius(), (int) circle.getCenterY() - (int) circle.getRadius(), 2 * (int) circle.getRadius(), 2 * (int) circle.getRadius()); g.dispose(); return target; } catch (Exception e) { logger.error(e.toString()); return source; } }
Example 10
Source File: SWTGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Creates a new instance. * * @param gc the graphics context. */ public SWTGraphics2D(GC gc) { super(); this.gc = gc; this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); setStroke(new BasicStroke()); }
Example 11
Source File: AwtRenderingBackend.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void setGlobalAlpha(final double globalAlpha) { if (LOG.isDebugEnabled()) { LOG.debug("[" + id_ + "] setGlobalAlpha(" + globalAlpha + ")"); } if (globalAlpha >= 0 && globalAlpha <= 1) { globalAlpha_ = (float) globalAlpha; final AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, globalAlpha_); graphics2D_.setComposite(composite); } }
Example 12
Source File: BigDialButton.java From magarena with GNU General Public License v3.0 | 5 votes |
private void rotateIconImage() { final int W = 24; final int H = 24; final BufferedImage image = ImageHelper.getCompatibleBufferedImage( W, H, BufferedImage.TRANSLUCENT ); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // This makes a big difference to quality of rotated image if rotation is not a factor of 90 degrees. g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC) ; g2d.setTransform(AffineTransform.getRotateInstance( Math.toRadians(INTERVAL * position), W * 0.5d, H * 0.5d) ); g2d.setPaint(tintColor); g2d.fillOval(2, 2, W-4, H-4); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OUT); g2d.setComposite(ac); g2d.fillOval((W - 8) / 2, 3, 8, 8); g2d.dispose(); super.setIcon(new ImageIcon(image)); }
Example 13
Source File: NeutralLossDataPointRenderer.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public void setTransparency(float transparency) { if ((transparency > 1.0) || (transparency < 0)) transparency = 1.0f; int type = AlphaComposite.SRC_OVER; alphaComp = (AlphaComposite.getInstance(type, transparency)); alphaCompOriginal = (AlphaComposite.getInstance(type, 1.0f)); }
Example 14
Source File: SWTGraphics2D.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Creates a new instance. * * @param gc the graphics context. */ public SWTGraphics2D(GC gc) { super(); this.gc = gc; this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); setStroke(new BasicStroke()); }
Example 15
Source File: SerialUtilitiesTest.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Serialize an <code>AlphaComposite</code>, restore it, and check for * equality. */ public void testAlphaCompositeSerialization() { final Composite c1 = AlphaComposite.getInstance(2, 0.345f); Composite c2 = null; try { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(buffer); SerialUtilities.writeComposite(c1, out); out.close(); final ByteArrayInputStream bias = new ByteArrayInputStream( buffer.toByteArray()); final ObjectInputStream in = new ObjectInputStream(bias); c2 = SerialUtilities.readComposite(in); in.close(); } catch (Exception e) { e.printStackTrace(); } // we want to check that the two objects are equal, but can't rely on // AlphaComposite's equals() method because it is just the default // method inherited from Object... final AlphaComposite ac1 = (AlphaComposite) c1; final AlphaComposite ac2 = (AlphaComposite) c2; assertEquals(ac1.getRule(), ac2.getRule()); assertEquals(ac1.getAlpha(), ac2.getAlpha(), 0.001f); }
Example 16
Source File: SWTGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Creates a new instance. * * @param gc the graphics context. */ public SWTGraphics2D(GC gc) { super(); this.gc = gc; this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); setStroke(new BasicStroke()); }
Example 17
Source File: FrameImage.java From scipio-erp with Apache License 2.0 | 4 votes |
/** * combineBufferedImage. * SCIPIO: 2017-07-10: modified to take a typeReferenceImage instance of bufImgType, so we have the full * information to replicate the original image type, needed for indexed images. */ public static BufferedImage combineBufferedImage(Image image1, Image image2, BufferedImage typeReferenceImage) { // Full image loading image1 = new ImageIcon(image1).getImage(); image2 = new ImageIcon(image2).getImage(); // New BufferedImage creation // SCIPIO: indexed images fix BufferedImage bufferedImage; Graphics2D g; if (image1 instanceof BufferedImage && ImagePixelType.isTypeImageOpFriendly(((BufferedImage) image1).getType())) { // still create a copy to avoid modifying the original bufferedImage = ImageTransform.cloneBufferedImage((BufferedImage) image1); g = bufferedImage.createGraphics(); } else { bufferedImage = ImageTransform.createBufferedImage(ImageType.DEFAULT_IMAGEOP.getImageTypeInfoFor(typeReferenceImage), image1.getWidth(null), image1.getHeight(null)); g = bufferedImage.createGraphics(); g.drawImage(image1, null, null); } // Draw Image combine Point2D center = new Point2D.Float(bufferedImage.getHeight() / 2f, bufferedImage.getWidth() / 2f); AffineTransform at = AffineTransform.getTranslateInstance(center.getX( ) - (image2.getWidth(null) / 2f), center.getY( ) - (image2.getHeight(null) / 2f)); g.transform(at); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(image2, 0, 0, null); Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .35f); g.setComposite(c); at = AffineTransform.getTranslateInstance(center.getX( ) - (bufferedImage.getWidth(null) / 2f), center.getY( ) - (bufferedImage.getHeight(null) / 2f)); g.setTransform(at); g.drawImage(bufferedImage, 0, 0, null); g.dispose(); // SCIPIO: new: we convert to the target type only at the very end, in separate step, so the previous operations don't suffer from color loss if (ImageType.imageMatchesRequestedType(bufferedImage, typeReferenceImage)) { return bufferedImage; } else { BufferedImage resultImage = ImageTransform.createCompatibleBufferedImage(typeReferenceImage, bufferedImage.getWidth(null), bufferedImage.getHeight(null)); ImageTransform.copyToBufferedImage(bufferedImage, resultImage); return( resultImage ); } }
Example 18
Source File: TICPlotRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
private AlphaComposite makeComposite(double alpha) { int type = AlphaComposite.SRC_OVER; return (AlphaComposite.getInstance(type, (float) alpha)); }
Example 19
Source File: ChromaticityDiagram.java From MyBox with Apache License 2.0 | 4 votes |
public BufferedImage drawData() { try { image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); g = image.createGraphics(); if (bgColor != null) { g.setColor(bgColor); g.fillRect(0, 0, width, height); } if (fontSize <= 0) { fontSize = 20; } dataFont = new Font(null, Font.PLAIN, fontSize); commentsFont = new Font(null, Font.BOLD, fontSize + 8); if (Color.BLACK.equals(bgColor)) { textColor = Color.WHITE; } else { textColor = Color.BLACK; } // Title / Bottom AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); g.setComposite(ac); if (title == null) { title = message("ChromaticityDiagram"); } g.setFont(commentsFont); g.setColor(textColor); g.drawString(title, margins + 400, 50); g.setFont(dataFont); g.drawString(message("ChromaticityDiagramComments"), 20, endH + 55); backGround(); outlines(); whitePoints(); primariesLines(); calculate(); g.dispose(); return image; } catch (Exception e) { logger.error(e.toString()); return null; } }
Example 20
Source File: Spin.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void paint(Graphics _g) { // System.out.println("paint()"); if(isPainting) return; isPainting = true; synchronized(paintLock) { zoom(); if(use2D) { if(alphaHalf == null) { alphaHalf = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .7f); } } Graphics g = _g; makeOff(false); if(memG == null) return; long start = System.currentTimeMillis(); paintBg(memG); bgTime = System.currentTimeMillis() - start; if(use2D) { ((Graphics2D)memG). setRenderingHint(RenderingHints.KEY_ANTIALIASING, bAntiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); } paintBundles(memG); spriteTime = System.currentTimeMillis() - bgTime - start; paintServices(memG); fgTime = System.currentTimeMillis() - spriteTime - start; if(bShowBundleLegend) { paintBundleStateLegend(memG); } SpinItem infoItem = getInfoItem(); if(infoItem != null) { if(bShowBundleInfo) { infoItem.paintInfo(memG, 10, size.height - 100); } } if(bShowConsole) { console.paint(memG); } if(bShowFrameRate) { paintFrameRate(memG); } if(bShowHelp) { paintHelp(memG, size.width/2-100, 50); } if(bShowDeps) { paintDeps(memG, (hotX > size.width / 2) ? 40 : (size.width / 2), 20); } if(bSearchMode) { paintSearch(memG, 10, size.height - 140); } if(use2D) { ((Graphics2D)memG). setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } g.drawImage(memImage, 0, 0, null); } isPainting = false; }