Java Code Examples for java.awt.Graphics2D.setComposite()

The following are Jave code examples for showing how to use setComposite() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ramus   File: XMLDiagram.java   View Source Code Vote up 6 votes
@Override
public void paintGroup(Graphics2D g, Group selection) {
    super.paintGroup(g, selection);
    Bounds[] bounds = selection.getBounds();
    g.setComposite(instance);
    if (bounds.length > 0) {
        Component component = getComponent(bounds[0]);
        try {
            if (((XMLComponent) component).isY())
                paintYShow(g, selection.getTranslate().getY(), bounds[0]);
            else
                paintXShow(g, selection.getTranslate().getX(), bounds[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Project: Tarski   File: mxGraphHandler.java   View Source Code Vote up 6 votes
/**
 *
 */
public void paint(Graphics g) {
  if (isVisible() && previewBounds != null) {
    if (dragImage != null) {
      // LATER: Clipping with mxUtils doesnt fix the problem
      // of the drawImage being painted over the scrollbars
      Graphics2D tmp = (Graphics2D) g.create();

      if (graphComponent.getPreviewAlpha() < 1) {
        tmp.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            graphComponent.getPreviewAlpha()));
      }

      tmp.drawImage(dragImage.getImage(), previewBounds.x, previewBounds.y,
          dragImage.getIconWidth(), dragImage.getIconHeight(), null);
      tmp.dispose();
    } else if (!imagePreview) {
      mxSwingConstants.PREVIEW_BORDER.paintBorder(graphComponent, g, previewBounds.x,
          previewBounds.y, previewBounds.width, previewBounds.height);
    }
  }
}
 
Example 3
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * Draw a semi-trasparet area
 * @param g The graphic object
 * @param dragPoint The first point
 * @param beginPoint The second point
 * @param c The color of the area
 */
public void drawDragArea(Graphics2D g, Point dragPoint, Point beginPoint, Color c) {
	g.setColor(c);

	Polygon poly = new Polygon();

	poly.addPoint((int) beginPoint.getX(), (int) beginPoint.getY());
	poly.addPoint((int) beginPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) beginPoint.getY());

	//Set the widths of the shape's outline
	Stroke oldStro = g.getStroke();
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	g.setStroke(stroke);
	g.drawPolygon(poly);
	g.setStroke(oldStro);

	//Set the trasparency of the iside of the rectangle
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
	g.setComposite(alphaComp);
	g.fillPolygon(poly);
	g.setComposite(oldComp);

}
 
Example 4
Project: incubator-netbeans   File: SplashUISupport.java   View Source Code Vote up 6 votes
public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    if (!isEnabled()) {
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.3f));
    }                
    Color oldColor = g.getColor();
    Dimension size = getSize();
    g.setColor(getBackground());
    g.fillRect(0, 0, size.width, size.height);
    int i = (size.height - SIZE) / 2;
    if (value.color != null) {
        g.setColor(Color.black);
        g.drawRect(i, i, SIZE, SIZE);
        g.setColor(value.color);
        g.fillRect(i + 1, i + 1, SIZE - 1, SIZE - 1);
    }
    if (value.text != null) {
        g.setColor(Color.black);
        if (value.color != null)
            g.drawString(value.text, i + SIZE + 5, i + SIZE);
        else
            g.drawString(value.text, 5, i + SIZE);
    }
    g.setColor(oldColor);
}
 
Example 5
Project: BasicsProject   File: GifCaptcha.java   View Source Code Vote up 6 votes
/**
 * 画随机码图
 * @param fontcolor 随机字体颜色
 * @param strs 字符数组
 * @param flag 透明度使用
 * @return BufferedImage
 */
private BufferedImage graphicsImage(Color[] fontcolor,char[] strs,int flag)
{
    BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
    //或得图形上下文
    //Graphics2D g2d=image.createGraphics();
    Graphics2D g2d = (Graphics2D)image.getGraphics();
    //利用指定颜色填充背景
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, width, height);
    AlphaComposite ac3;
    int h  = height - ((height - font.getSize()) >>1) ;
    int w = width/len;
    g2d.setFont(font);
    for(int i=0;i<len;i++)
    {
        ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(flag, i));
        g2d.setComposite(ac3);
        g2d.setColor(fontcolor[i]);
        g2d.drawOval(num(width), num(height), 5+num(10), 5+num(10));
        g2d.drawString(strs[i]+"", (width-(len-i)*w)+(w-font.getSize())+1, h-4);
    }
    g2d.dispose();
    return image;
}
 
Example 6
Project: brModelo   File: LivreBase.java   View Source Code Vote up 5 votes
@Override
protected void PinteRegiao(Graphics2D g) {
    Composite originalComposite = g.getComposite();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));
    g.setPaint(this.getForeColor());

    if (isGradiente()) {
        int dist = 0;
        int w = getWidth() - dist;
        int h = getHeight() - dist;
        int L = getLeft();
        int T = getTop();
        boolean dv = getGDirecao() == VERTICAL;

        GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true);
        g.setPaint(GP);
    }

    if (getTipoDesenho() != TipoDraw.tpTexto) {
        Stroke bkp = g.getStroke();
        if (isDashed()) {
            g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
        }
        if (isGradiente()) {
            g.fill(getRegiao());
        }
        g.draw(getRegiao()); //Pinta as eventuais linhas internas do dezenho. Ex. LivreVariosDocumemtos 

        g.setStroke(bkp);
    }
    g.setComposite(originalComposite);
}
 
Example 7
Project: JavaPPTX   File: PPWindowImage.java   View Source Code Vote up 5 votes
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();
}
 
Example 8
Project: geomapapp   File: GridToWorldWindTiler.java   View Source Code Vote up 5 votes
private void gridToTile(int tileX, int tileY, int level, File parent) throws IOException{
		double delta = levelZeroDelta / Math.pow(2, level);

//		double lon1 = lon0 + delta;
		double lat0 = getLatFromTileY(tileY, level, levelZeroDelta);
		double lat1 = lat0 + delta;

		int multiplier = getLonMultiplier(lat0, lat1);
		double lon0 = getLonFromTile(lat0, lat1, tileX, level, levelZeroDelta);
		double lon1 = lon0 + delta * multiplier;

		double[] tileWESN = new double[] {lon0, lon1, lat0, lat1};

		MapProjection proj = grid.getProjection();
		Point2D ul = proj.getMapXY(lon0, lat1);
		Point2D lr = proj.getMapXY(lon1, lat0);

		Rectangle bounds = new Rectangle();
		bounds.x = (int)Math.floor(ul.getX());
		bounds.y = (int)Math.floor(ul.getY());
		bounds.width = (int) Math.ceil(lr.getX()) - bounds.x;
		bounds.height = (int) Math.ceil(lr.getY()) - bounds.y;

		Grid2D subGrid = GridUtilities.getSubGrid(bounds, grid);
		BufferedImage tileImage = renderer.gridImage(subGrid).image;

//		System.out.println(bounds + "\t" + grid.getBounds());

		tileImage = imageProcessor.processImage(tileImage, tileWESN, tileWESN);

		BufferedImage scaledTileImage = new BufferedImage(TILE_SIZE, TILE_SIZE, tileImage.getType());
		Graphics2D g = scaledTileImage.createGraphics();
		g.setComposite(AlphaComposite.Src);
		g.drawImage(tileImage, 0, 0, TILE_SIZE, TILE_SIZE, null);

		StringBuffer sb = new StringBuffer();
		sb.append(tileY).append("_").append(tileX).append(".").append(outputFormat);

		ImageIO.write(scaledTileImage, outputFormat, new File(parent, sb.toString()));
	}
 
Example 9
Project: freecol   File: FreeColComboBoxRenderer.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Composite oldComposite = g2d.getComposite();
    Color oldColor = g2d.getColor();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, getWidth(), getHeight());
    g2d.setComposite(oldComposite);
    g2d.setColor(oldColor);

    super.paintComponent(g);
}
 
Example 10
Project: UpdateBuilder   File: TransparentComponent.java   View Source Code Vote up 5 votes
public Graphics setup(Graphics g) {
	float t;
	if (this.hovering) {
		t = getHoverTransparency();
	} else {
		t = getTransparency();
	}
	
	Graphics2D copy = (Graphics2D)g.create();
	copy.setComposite(AlphaComposite.getInstance(3, t));
	return copy;
}
 
Example 11
Project: openjdk-jdk10   File: JPEGsNotAcceleratedTest.java   View Source Code Vote up 5 votes
public BufferedImage getDestImage() {
    BufferedImage destBI =
        new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D)destBI.getGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setColor(Color.blue);
    g.fillRect(0, 0, TEST_W, TEST_H);
    return destBI;
}
 
Example 12
Project: GlitchKernel   File: SelectionManager.java   View Source Code Vote up 5 votes
private void drawFreeHandShape(SelectionShape selectionPoint, Graphics g)
{
	Graphics2D g2 = (Graphics2D) g;
	if(selectionPoint.isFreeHandSelectionConnected())
	{
		g2.setComposite(AlphaComposite.SrcOver.derive(0.7f));
		g2.setPaint(new Color(221, 0, 72));
	}
	for(int i = 0; i < selectionPoint.getFreeHandSelectionPointList().size(); i++)
	{
		Point point = selectionPoint.getFreeHandSelectionPointList().get(i);
		if(i < selectionPoint.getFreeHandSelectionPointList().size() - 1)
		{
			Point point2 = selectionPoint.getFreeHandSelectionPointList().get(i + 1);
			if(i == selectionPoint.getFreeHandSelectionPointList().size() - 1 || i == 0)
			{
				g2.setStroke(new BasicStroke(6));
			}
			else
			{
				g2.setStroke(new BasicStroke(2));
			}
			g2.drawLine(point.x, point.y, point2.x, point2.y);
		}
		
	}
	g2.dispose();
}
 
Example 13
Project: KeysPerSecond   File: BasePanel.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics g1) {
	Graphics2D g = (Graphics2D) g1;

	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, Main.config.getBackgroundOpacity()));
	g.setColor(Main.config.getBackgroundColor());
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
	g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	BufferedImage colorImage = isActive() ? ColorManager.pressed : ColorManager.unpressed;
	g.drawImage(colorImage, 2, 2, this.getWidth() - 2, this.getHeight() - 2, 0, 0, colorImage.getWidth(), colorImage.getHeight(), this);

	g.setColor(isActive() ? Main.config.getBackgroundColor() : Main.config.getForegroundColor());

	String titleString = getTitle();
	Font titleFont = Main.config.mode.getTitleFont(titleString);
	Point namePos = Main.config.mode.getTitleDrawPosition(g, this, titleString, titleFont);
	g.setFont(titleFont);
	g.drawString(titleString, namePos.x, namePos.y);

	String valueString = getValue();
	Font valueFont = Main.config.mode.getValueFont(valueString);
	Point keyCountPos = Main.config.mode.getValueDrawPosition(g, this, valueString, valueFont);
	g.setFont(valueFont);
	g.drawString(valueString, keyCountPos.x, keyCountPos.y);
}
 
Example 14
Project: openjdk-jdk10   File: NonOpaqueDestLCDAATest.java   View Source Code Vote up 5 votes
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);
}
 
Example 15
Project: VASSAL-src   File: SetupStack.java   View Source Code Vote up 5 votes
private BufferedImage featherDragImage(BufferedImage src,
                                         int w, int h, int b) {
// FIXME: duplicated from PieceMover!
      final BufferedImage dst =
        ImageUtils.createCompatibleTranslucentImage(w, h);

      final Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);

      // paint the rectangle occupied by the piece at specified alpha
      g.setColor(new Color(0xff, 0xff, 0xff, CURSOR_ALPHA));
      g.fillRect(0, 0, w, h);

      // feather outwards
      for (int f = 0; f < b; ++f) {
        final int alpha = CURSOR_ALPHA * (f + 1) / b;
        g.setColor(new Color(0xff, 0xff, 0xff, alpha));
        g.drawRect(f, f, w-2*f, h-2*f);
      }

      // paint in the source image
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
      g.drawImage(src, 0, 0, null);
      g.dispose();

      return dst;
    }
 
Example 16
Project: OpenJSharp   File: TranslucentWindowPainter.java   View Source Code Vote up 5 votes
private static final Image clearImage(Image bb) {
    Graphics2D g = (Graphics2D)bb.getGraphics();
    int w = bb.getWidth(null);
    int h = bb.getHeight(null);

    g.setComposite(AlphaComposite.Src);
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, w, h);

    return bb;
}
 
Example 17
Project: jdk8u-jdk   File: NonOpaqueDestLCDAATest.java   View Source Code Vote up 5 votes
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);
}
 
Example 18
Project: web-framework-for-java   File: IOHelper.java   View Source Code Vote up 4 votes
public static void createThumbnail(String filename, int thumbWidth, String outFilename) throws IOException {
	BufferedImage originalBufferedImage = null;
	try {
		File originFile = new File(filename);
		String imageType = originFile.getName().substring(originFile.getName().lastIndexOf(".") + 1);
		originalBufferedImage = ImageIO.read(originFile);

		int thumbnailWidth = thumbWidth;

		int widthToScale, heightToScale;
		if (originalBufferedImage.getWidth() > originalBufferedImage.getHeight()) {

			heightToScale = (int) (1.1 * thumbnailWidth);
			widthToScale = (int) ((heightToScale * 1.0) / originalBufferedImage.getHeight()
					* originalBufferedImage.getWidth());

		} else {
			widthToScale = (int) (1.1 * thumbnailWidth);
			heightToScale = (int) ((widthToScale * 1.0) / originalBufferedImage.getWidth()
					* originalBufferedImage.getHeight());
		}

		BufferedImage resizedImage = new BufferedImage(widthToScale, heightToScale,
				originalBufferedImage.getType());
		Graphics2D g = resizedImage.createGraphics();

		g.setComposite(AlphaComposite.Src);
		g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		g.drawImage(originalBufferedImage, 0, 0, widthToScale, heightToScale, null);
		g.dispose();

		int x = (resizedImage.getWidth() - thumbnailWidth) / 2;
		int y = (resizedImage.getHeight() - thumbnailWidth) / 2;

		if (x < 0 || y < 0) {
			throw new IllegalArgumentException("Width of new thumbnail is bigger than original image");
		}
		BufferedImage thumbnailBufferedImage = resizedImage.getSubimage(x, y, thumbnailWidth, thumbnailWidth);
		ImageIO.write(thumbnailBufferedImage, imageType.toUpperCase(), new File(outFilename));
	} catch (IOException ioe) {
		throw ioe;
	}
}
 
Example 19
Project: parabuild-ci   File: PiePlot.java   View Source Code Vote up 4 votes
/**
 * Draws the labels for the pie sections.
 * 
 * @param g2  the graphics device.
 * @param keys  the keys.
 * @param totalValue  the total value.
 * @param plotArea  the plot area.
 * @param linkArea  the link area.
 * @param state  the state.
 */
protected void drawLabels(Graphics2D g2, List keys, double totalValue, 
                          Rectangle2D plotArea, Rectangle2D linkArea, 
                          PiePlotState state) {   

    Composite originalComposite = g2.getComposite();
    g2.setComposite(
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));

    // classify the keys according to which side the label will appear...
    DefaultKeyedValues leftKeys = new DefaultKeyedValues();
    DefaultKeyedValues rightKeys = new DefaultKeyedValues();
   
    double runningTotal1 = 0.0;
    Iterator iterator1 = keys.iterator();
    while (iterator1.hasNext()) {
        Comparable key = (Comparable) iterator1.next();
        boolean include = true;
        double v = 0.0;
        Number n = this.dataset.getValue(key);
        if (n == null) {
            include = !this.ignoreNullValues;
        }
        else {
            v = n.doubleValue();
            include = this.ignoreZeroValues ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal1 = runningTotal1 + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right, 
            // otherwise left
            double mid = this.startAngle + (this.direction.getFactor()
                * ((runningTotal1 - v / 2.0) * 360) / totalValue);
            if (Math.cos(Math.toRadians(mid)) < 0.0) {
                leftKeys.addValue(key, new Double(mid));
            }
            else {
                rightKeys.addValue(key, new Double(mid));
            }
        }
    }
   
    g2.setFont(getLabelFont());
    float maxLabelWidth 
        = (float) (getMaximumLabelWidth() * plotArea.getWidth());
    
    // draw the labels...
    if (this.labelGenerator != null) {
        drawLeftLabels(leftKeys, g2, plotArea, linkArea, maxLabelWidth, 
                state);
        drawRightLabels(rightKeys, g2, plotArea, linkArea, maxLabelWidth, 
                state);
    }
    g2.setComposite(originalComposite);

}
 
Example 20
Project: incubator-netbeans   File: SplashComponentPreview.java   View Source Code Vote up 4 votes
public void originalPaint(Graphics graphics) {
    Graphics2D g2d = (Graphics2D)graphics;
    if (!isEnabled()) {
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.3f));
    }
    
    graphics.setColor(color_text);
    graphics.drawImage(image, 0, 0, null);
    
    if (text == null) {
        // no text to draw
        return;
    }
    
    if (fm == null) {
        // XXX(-ttran) this happened on Japanese Windows NT, don't
        // fully understand why
        return;
    }
    
    SwingUtilities.layoutCompoundLabel(fm, text, null,
            SwingConstants.BOTTOM, SwingConstants.LEFT, SwingConstants.BOTTOM, SwingConstants.LEFT,
            this.view, new Rectangle(), rect, 0);
    // turn anti-aliasing on for the splash text
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.drawString(text, rect.x, rect.y + fm.getAscent());
    // Draw progress bar if applicable
    
    if (draw_bar && Boolean.getBoolean("netbeans.splash.nobar") == false && maxSteps > 0/* && barLength > 0*/) {
        graphics.setColor(color_bar);
        graphics.fillRect(bar.x, bar.y, barStart + barLength, bar.height);
        graphics.setColor(color_corner);
        graphics.drawLine(bar.x, bar.y, bar.x, bar.y + bar.height);
        graphics.drawLine(bar.x + barStart + barLength, bar.y, bar.x + barStart + barLength, bar.y + bar.height);
        graphics.setColor(color_edge);
        graphics.drawLine(bar.x, bar.y + bar.height / 2, bar.x, bar.y + bar.height / 2);
        graphics.drawLine(bar.x + barStart + barLength, bar.y + bar.height / 2, bar.x + barStart + barLength, bar.y + bar.height / 2);
        barStart += barLength;
        barLength = 0;
    }
}