List of usage examples for java.awt Graphics2D getComposite
public abstract Composite getComposite();
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);/*w ww . j a va 2s.c om*/ int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.SRC", x, y + 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);/*www . j av a 2 s .co m*/ int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.DST_IN", x, y + 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);//from w ww. j av a2 s .c o m int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.DST_OVER", x, y + 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);/*from ww w. jav a2 s. c om*/ int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.CLEAR", x, y + 80); }
From source file:WeatherWizard.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension size = getSize();/*from w ww . j av a 2s. c om*/ Composite origComposite; setupWeatherReport(); origComposite = g2.getComposite(); if (alpha0 != null) g2.setComposite(alpha0); g2.drawImage(img0, 0, 0, size.width, size.height, 0, 0, img0.getWidth(null), img0.getHeight(null), null); if (img1 != null) { if (alpha1 != null) g2.setComposite(alpha1); g2.drawImage(img1, 0, 0, size.width, size.height, 0, 0, img1.getWidth(null), img1.getHeight(null), null); } g2.setComposite(origComposite); // Freezing, Cold, Cool, Warm, Hot, // Blue, Green, Yellow, Orange, Red Font font = new Font("Serif", Font.PLAIN, 36); g.setFont(font); String tempString = feels + " " + temperature + "F"; FontRenderContext frc = ((Graphics2D) g).getFontRenderContext(); Rectangle2D boundsTemp = font.getStringBounds(tempString, frc); Rectangle2D boundsCond = font.getStringBounds(condStr, frc); int wText = Math.max((int) boundsTemp.getWidth(), (int) boundsCond.getWidth()); int hText = (int) boundsTemp.getHeight() + (int) boundsCond.getHeight(); int rX = (size.width - wText) / 2; int rY = (size.height - hText) / 2; g.setColor(Color.LIGHT_GRAY); g2.fillRect(rX, rY, wText, hText); g.setColor(textColor); int xTextTemp = rX - (int) boundsTemp.getX(); int yTextTemp = rY - (int) boundsTemp.getY(); g.drawString(tempString, xTextTemp, yTextTemp); int xTextCond = rX - (int) boundsCond.getX(); int yTextCond = rY - (int) boundsCond.getY() + (int) boundsTemp.getHeight(); g.drawString(condStr, xTextCond, yTextCond); }
From source file:de.dakror.villagedefense.game.entity.Entity.java
public void drawEntity(Graphics2D g) { if (alpha == 0) return;/* w w w . j a v a 2s .c om*/ drawBump(g, false); Composite c = g.getComposite(); if (this instanceof Struct) g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); draw(g); g.setComposite(c); if (isHungry()) { g.drawImage(Game.getImage("icon/hunger.png"), (int) x, (int) (y - Tile.SIZE - Math.cos(tick / 10f) * Tile.SIZE / 4), 32, 32, Game.w); } else if (this instanceof Struct && !((Struct) this).isWorking()) { g.drawImage(Game.getImage("icon/sleep.png"), (int) (x + width * 0.75f), (int) (y - Tile.SIZE - Math.cos(tick / 10f) * Tile.SIZE / 4), 32, 32, Game.w); } drawBump(g, true); }
From source file:com.appnativa.rare.ui.chart.jfreechart.XYPlotEx.java
@Override protected void fillBackground(Graphics2D g2, Rectangle2D area, PlotOrientation orientation) { Paint p = this.getBackgroundPaint(); if (p == null) { return;// ww w . jav a 2 s.com } iPainter painter = ChartHelper.getPainter(p); if (painter == null) { super.fillBackground(g2, area, orientation); return; } Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha())); graphics = SwingGraphics.fromGraphics(g2, null, graphics); float x = UIScreen.snapToPosition(area.getX()); float y = UIScreen.snapToPosition(area.getY()); float w = UIScreen.snapToSize(area.getWidth()); float h = UIScreen.snapToSize(area.getHeight()); painter.paint(graphics, x, y, w, h, iPainter.UNKNOWN); g2.setComposite(originalComposite); }
From source file:edu.cuny.jfree.chart.annotations.CategoryIntervalAnnotation.java
public void draw(final Graphics2D g2, final CategoryPlot plot, final Rectangle2D dataArea, final CategoryAxis domainAxis, final ValueAxis rangeAxis) { final AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha());//from w w w . j a va 2 s. c om final Composite oldComposite = g2.getComposite(); g2.setComposite(alphaComposite); final CategoryDataset dataset = plot.getDataset(); final int catIndex = dataset.getColumnIndex(category); final int catCount = dataset.getColumnCount(); double lineX1 = 0.0D; double lineY = 0.0D; double lineX2 = 0.0D; final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); final RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); if (orientation == PlotOrientation.HORIZONTAL) { lineY = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); lineX1 = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge); lineX2 = rangeAxis.valueToJava2D(value2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.VERTICAL) { lineY = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge); lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); } g2.setPaint(paint); g2.setStroke(stroke); g2.drawLine((int) lineX1, (int) lineY, (int) lineX2, (int) lineY); g2.setComposite(oldComposite); }
From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, ChartPanel chartPanel, boolean scale) { if (entity != null) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();// www. j a v a 2 s . c o m Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; if (scale) { transformed = scaleAtOrigin(entity, hoverScaleX, hoverScaleY).createTransformedShape(entity); } transformed = getTranslateInstance( entity.getBounds2D().getCenterX() - transformed.getBounds2D().getCenterX(), entity.getBounds2D().getCenterY() - transformed.getBounds2D().getCenterY()) .createTransformedShape(transformed); g2.setComposite(getInstance(AlphaComposite.SRC_OVER, fillAlpha)); g2.fill(transformed); g2.setColor(Color.DARK_GRAY); g2.draw(transformed); g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } }
From source file:VASSAL.build.module.map.MapShader.java
public void draw(Graphics g, Map map) { if (shadingVisible) { double zoom = map.getZoom(); buildStroke(zoom);/* www . j a v a2s.com*/ final Graphics2D g2 = (Graphics2D) g; final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); final Paint oldPaint = g2.getPaint(); final Stroke oldStroke = g2.getStroke(); g2.setComposite(getComposite()); g2.setColor(getColor()); g2.setPaint(scaleImage && pattern.equals(TYPE_IMAGE) && imageName != null ? getTexture(zoom) : getTexture()); Area area = getShadeShape(map); if (zoom != 1.0) { area = new Area(AffineTransform.getScaleInstance(zoom, zoom).createTransformedShape(area)); } g2.fill(area); if (border) { g2.setComposite(getBorderComposite()); g2.setStroke(getStroke(map.getZoom())); g2.setColor(getBorderColor()); g2.draw(area); } g2.setComposite(oldComposite); g2.setColor(oldColor); g2.setPaint(oldPaint); g2.setStroke(oldStroke); } }