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

The following are Jave code examples for showing how to use getComposite() 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: brModelo   File: Tabela.java   View Source Code Vote up 6 votes
private void FillCampos(Graphics2D g, Rectangle r, boolean normal) {
    Composite originalComposite = g.getComposite();
    float alfa = 1f - getAlfa();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));
    Paint bkpp = g.getPaint();
    g.setColor(getMaster().getBackground()); //# Não: isDisablePainted()? disabledColor : 
    if (!normal) {
        if (isGradiente()) {
            g.setColor(getGradienteStartColor());
        } else {
            g.setColor(getForeColor());
        }
    }
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlfa()));
    g.fill(r);

    g.setPaint(bkpp);
    g.setComposite(originalComposite);
}
 
Example 2
Project: incubator-netbeans   File: BalloonManager.java   View Source Code Vote up 6 votes
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    
    g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    
    Composite oldC = g2d.getComposite();
    Shape s = getMask( getWidth(), getHeight() );

    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f*currentAlpha ) );
    g2d.setColor( Color.black );
    g2d.fill( getShadowMask(s) );
    
    g2d.setColor( UIManager.getColor( "ToolTip.background" ) ); //NOI18N
    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, currentAlpha ) );
    Point2D p1 = s.getBounds().getLocation();
    Point2D p2 = new Point2D.Double(p1.getX(), p1.getY()+s.getBounds().getHeight());
    if( isMouseOverEffect )
        g2d.setPaint( new GradientPaint( p2, getMouseOverGradientStartColor(), p1, getMouseOverGradientFinishColor() ) );
    else
        g2d.setPaint( new GradientPaint( p2, getDefaultGradientStartColor(), p1, getDefaultGradientFinishColor() ) );
    g2d.fill(s);
    g2d.setColor( Color.black );
    g2d.draw(s);
    g2d.setComposite( oldC );
}
 
Example 3
Project: geomapapp   File: FocalMechanismSolutionDB.java   View Source Code Vote up 6 votes
private BufferedImage drawFMSImage() {
	BufferedImage fms = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

	Graphics2D g = fms.createGraphics();
	Composite c = g.getComposite();

	g.setComposite(AlphaComposite.getInstance(
					AlphaComposite.CLEAR, 0));
	g.fillRect(0, 0, size, size);
	g.setComposite(c);

	g.translate(size / 2, size / 2);
	FMSDraw.drawFMS(g, size / 2,
			eq.strike1,
			eq.dip1, 
			eq.rake1, 
			eq.strike2, 
			eq.dip2, 
			eq.rake2);
	return fms;
}
 
Example 4
Project: KeysPerSecond   File: Menu.java   View Source Code Vote up 6 votes
/**
 * Paints a menu item
 * @param g The graphics to use
 * @param menuItem The menu item to paint
 * @param hasCursor Whether or not the cursor is over the component
 * @param defaultTextIconGap The gap between the text and the icon
 */
private static final void paintMenuItem(Graphics2D g, JMenuItem menuItem, boolean hasCursor, int defaultTextIconGap){
	g.setColor(Main.config.customColors ? Main.config.background : Color.BLACK);
	g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
	if(menuItem instanceof JCheckBoxMenuItem && menuItem.isSelected()){
		g.drawImage(ColorManager.checkmark, 0, 0, 22, 22, 0, 0, 100, 100, menuItem);
	}else if(menuItem instanceof JMenu){
		g.drawImage(ColorManager.arrow, menuItem.getWidth() - 12, 5, menuItem.getWidth(), 17, 0, 0, 128, 128, menuItem);
	}
	g.setColor(Main.config.customColors ? Main.config.foreground : Color.CYAN);
	if(hasCursor){
		g.drawLine(0, 0, menuItem.getWidth(), 0);
		g.drawLine(0, menuItem.getHeight() - 1, menuItem.getWidth(), menuItem.getHeight() - 1);
		Composite prev = g.getComposite();
		g.setComposite(MenuItemUI.mode);
		g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
		g.setComposite(prev);
	}
	FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
	int mnemIndex = menuItem.getDisplayedMnemonicIndex();
	int y = (22 - fm.getHeight()) / 2;
	SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, menuItem.getText(), mnemIndex, 22 + defaultTextIconGap, y + fm.getAscent());
}
 
Example 5
Project: parabuild-ci   File: Plot.java   View Source Code Vote up 6 votes
/**
 * Draws the background image (if there is one) aligned within the specified area.
 * 
 * @param g2  the graphics device.
 * @param area  the area.
 */
protected void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundImage != null) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, this.backgroundAlpha));
        Rectangle2D dest = new Rectangle2D.Double(
            0.0, 0.0,
            this.backgroundImage.getWidth(null), this.backgroundImage.getHeight(null)
        );
        Align.align(dest, area, this.backgroundImageAlignment);
        g2.drawImage(
            this.backgroundImage,
            (int) dest.getX(), (int) dest.getY(),
            (int) dest.getWidth() + 1, (int) dest.getHeight() + 1, null
        );
        g2.setComposite(originalComposite);
    }
}
 
Example 6
Project: Caritemere   File: InfoWindow.java   View Source Code Vote up 6 votes
public void render(Graphics g) {
	Graphics2D g2d = (Graphics2D) g;
	AlphaComposite orig = (AlphaComposite) g2d.getComposite();
	if (fading) {
		float alpha = 1f - (float) (((double) System.currentTimeMillis() - (double) startFadeTime) / (double) fadeTime);
		if (alpha < 0f)
			alpha = 0f;
		AlphaComposite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
		g2d.setComposite(comp);
	}
	g2d.setColor(MainGui.gui.getTheme().getColor(Theme.COL_INFO_WINDOW_BG));
	g2d.fillRect(x, y, MainGui.INFO_WINDOW_WIDTH, h);
	g2d.setColor(MainGui.gui.getTheme().getColor(Theme.COL_INFO_WINDOW_BG).darker());
	g2d.fillRect(x, y + (h - MainGui.SPACER_SIZE / 2), MainGui.INFO_WINDOW_WIDTH, MainGui.SPACER_SIZE / 2);
	g2d.drawRect(x, y, MainGui.INFO_WINDOW_WIDTH - 1, (h - MainGui.SPACER_SIZE / 2));
	GameRenderer.renderFormattedText(g2d, text, Theme.FONT_TEXT, x + MainGui.SPACER_SIZE, y + MainGui.SPACER_SIZE, 1, MainGui.INFO_WINDOW_WIDTH - (MainGui.SPACER_SIZE * 2));
	g2d.setComposite(orig);
}
 
Example 7
Project: brModelo   File: Desenhador.java   View Source Code Vote up 6 votes
public void DrawImagem(Graphics2D g) {
    BufferedImage imgB = getImagem();
    if (imgB == null) {
        return;
    }
    Rectangle rec = getBounds();
    rec.grow(-2, -2);
    if (imgres == null) {
        imgres = imgB.getScaledInstance(rec.width, rec.height, Image.SCALE_SMOOTH);
    }

    Composite originalComposite = g.getComposite();
    if (alfa != 1f) {
        int type = AlphaComposite.SRC_OVER;
        g.setComposite(AlphaComposite.getInstance(type, alfa));
    }
    Image img = imgres;
    if (isDisablePainted()) {
        img = util.Utilidades.dye(new ImageIcon(imgres), disabledColor);
    }
    
    g.drawImage(img, rec.x, rec.y, null);
    g.setComposite(originalComposite);
}
 
Example 8
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * It draw a temporary point when a point is moved in another place
 * @param g The graphic object
 * @param p The position of the point
 * @param c The color of the point
 * @param size The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
	g.setColor(c);

	int fontSize = 7 + pointSize;
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);
	double x = Math.max((p.getX() - tran_x) / scale, 0);
	double y = Math.max((-p.getY() + tran_y) / scale, 0);
	double X = (x * scale) + tran_x;
	double Y = -((y * scale) - tran_y);

	g.drawString("(" + format2Dec.format(x) + ", " + format2Dec.format(y) + ")", (int) (X - (fontSize * 3)), (int) Y - 5 - pointSize);

	g.drawOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);

	g.setColor(Color.gray);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);
	g.fillOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);
	g.setComposite(oldComp);

}
 
Example 9
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * It draw a temporary point when a point is moved in another place
 * @param g The graphic object
 * @param p The position of the point
 * @param c The color of the point
 * @param size The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
	g.setColor(c);

	int fontSize = 7 + pointSize;
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);
	double x = Math.max((p.getX() - tran_x) / scale, 0);
	double y = Math.max((-p.getY() + tran_y) / scale, 0);
	double X = (x * scale) + tran_x;
	double Y = -((y * scale) - tran_y);

	g.drawString("(" + format2Dec.format(x) + ", " + format2Dec.format(y) + ")", (int) (X - (fontSize * 3)), (int) Y - 5 - pointSize);

	g.drawOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);

	g.setColor(Color.GRAY);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);
	g.fillOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);
	g.setComposite(oldComp);

}
 
Example 10
Project: alevin-svn2   File: AbstractSearchField.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
	super.paintComponent(g);

	Graphics2D g2d = (Graphics2D) g;
	Composite originalComposite = g2d.getComposite();

	boolean cond = this.getText().equals("")
			&& (!this.isFocusOwner() || !this.isEditable());

	if (!isEditable())
		g2d.setComposite(alphaComposite);

	// hack: assuming insets on all sites
	// are the same, because on mac margins are
	// not accepted...
	int mg = getInsets().top;
	// draw icons
	if (cond)
		g.drawImage(searchIcon, this.getWidth() - 18 - mg, 1 + mg, 16, 16,
				null);
	else
		g.drawImage(clearIcon, this.getWidth() - 18 - mg, 1 + mg, 16, 16,
				null);

	if (!isEditable())
		g2d.setComposite(originalComposite);

	// draw instruction
	if (cond) {
		g.setColor(Color.GRAY);
		g.drawString("Search for sites / edges...", 4 + mg, 14 + mg);
	}
}
 
Example 11
Project: parabuild-ci   File: DefaultPolarItemRenderer.java   View Source Code Vote up 5 votes
/**
 * Plots the data for a given series.
 * 
 * @param g2  the drawing surface.
 * @param dataArea  the data area.
 * @param info  collects plot rendering info.
 * @param plot  the plot.
 * @param dataset  the dataset.
 * @param seriesIndex  the series index.
 */
public void drawSeries(Graphics2D g2, 
                       Rectangle2D dataArea, 
                       PlotRenderingInfo info,
                       PolarPlot plot,
                       XYDataset dataset,
                       int seriesIndex) {
    
    Polygon poly = new Polygon();
    int numPoints = dataset.getItemCount(seriesIndex);
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i);
        double radius = dataset.getYValue(seriesIndex, i);
        Point p = plot.translateValueThetaRadiusToJava2D(theta, radius, 
                dataArea);
        poly.addPoint(p.x, p.y);
    }
    g2.setPaint(getSeriesPaint(seriesIndex));
    g2.setStroke(getSeriesStroke(seriesIndex));
    if (isSeriesFilled(seriesIndex)) {
        Composite savedComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.5f));
        g2.fill(poly);
        g2.setComposite(savedComposite);
    }
    else {
        g2.draw(poly);
    }
}
 
Example 12
Project: JavaGraph   File: DisplayTreeCellRenderer.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    if (isTransparent()) {
        Graphics2D g2 = (Graphics2D) g;
        final Composite oldComposite = g2.getComposite();
        g2.setComposite(TRANSPARENT_COMPOSITE);
        super.paintComponent(g);
        g2.setComposite(oldComposite);
    } else {
        super.paintComponent(g);
    }
}
 
Example 13
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 14
Project: chordatlas   File: FeatureCache.java   View Source Code Vote up 5 votes
@Override
		public void paint( Graphics2D g, PanMouseAdaptor ma ) {

			{
				Composite old = g.getComposite();
				Composite comp = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.5f );
				g.setComposite( comp );

				// draw rectified image at the width of the ortho image...
				
				double height = getRectified().getHeight() / 40.;

				g.drawImage( getRectified(), 
						ma.toX( Math.min( start, end ) ), 
						ma.toY( 0 - height ), 
						ma.toZoom( Math.abs(start - end) ), 
						ma.toZoom( height ), null );
				g.setComposite( old );
			}

//			for ( int i = 0; i < miniFacades.size(); i++ )
//				miniFacades.get( i ).paint( g, ma );

			//			for (double d : o.windowCuts)
			//				g.drawLine( ma.toX(d), 0, ma.toX(d), 10000 );
			//			
			g.setColor( Color.orange );
			//			
			//			for (double d : o.classCuts)
			//				g.drawLine( ma.toX(d), 0, ma.toX(d), 10000 );
			//		
			//			g.setColor( new Color(255, 100,100, 255) );
			//			if (o.windows != null)
			//			for (Rectangle2D.Double w : o.windows) {
			//				g.drawRect( ma.toX( w.x ), ma.toY (-w.y-w.height), ma.toZoom( w.width ), ma.toZoom( w.height ) );
			//			}
		}
 
Example 15
Project: VASSAL-src   File: ZoneHighlight.java   View Source Code Vote up 5 votes
public void draw(Graphics2D g2d, Shape s, double scale) {

    if ((color != null && opacity > 0 ) || STYLE_IMAGE.equals(style)) {
      final Stroke oldStroke = g2d.getStroke();
      final Color oldColor = g2d.getColor();
      final Composite oldComposite = g2d.getComposite();
      final Paint oldPaint = g2d.getPaint();
      if (!STYLE_PLAIN.equals(style)) {
        g2d.setPaint(getPaint());
      }
      else {
        g2d.setColor(color);
      }

      g2d.setComposite(AlphaComposite.getInstance(
        AlphaComposite.SRC_OVER, opacity/100.0f));
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                           RenderingHints.VALUE_ANTIALIAS_ON);

      if (COVERAGE_FULL.equals(coverage)) {
        g2d.fill(s);
      }
      else {
        final Stroke stroke = new BasicStroke((float)(width*scale),
                                              BasicStroke.CAP_ROUND,
                                              BasicStroke.JOIN_ROUND);
        g2d.setStroke(stroke);
        g2d.draw(s);
      }

      g2d.setColor(oldColor);
      g2d.setStroke(oldStroke);
      g2d.setComposite(oldComposite);
      g2d.setPaint(oldPaint);
    }
  }
 
Example 16
Project: freecol   File: ReportLabourPanel.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g) {
    if (selected) {
        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.paint(g);
}
 
Example 17
Project: Motunautr   File: FileIcon.java   View Source Code Vote up 5 votes
@Override
	protected void paintComponent(@NonNull final Graphics g) {
		super.paintComponent(g);
		if (hovered) {
			g.setColor(new Color(0, 0, 0, 0.4f));
			g.fillRect(0, 0, getWidth(), getHeight());
		}
		final Graphics2D g2 = (Graphics2D) g;
		final Composite oldComp = g2.getComposite();
		if (!hovered)
			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
		if (icon != null)
			g.drawImage(icon, (getWidth() - ICON_SIZE) / 2, PADDING_Y, ICON_SIZE, ICON_SIZE, null);
		if (isExpandable) {
//			g.drawImage(expandIcon, (getWidth() + ICON_SIZE) / 2 - EXPAND_ICON_SIZE / 2, PADDING_Y + ICON_SIZE - EXPAND_ICON_SIZE, EXPAND_ICON_SIZE, EXPAND_ICON_SIZE, null);
			final int expandX = (getWidth() + ICON_SIZE) / 2, expandY = PADDING_Y + ICON_SIZE;
			final int expandSize = 10;
			g.setColor(Color.white);
			g2.setStroke(new BasicStroke(3, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10));
			g.drawPolyline(
					new int[] {expandX - expandSize / 2, expandX, expandX + expandSize / 2},
					new int[] {expandY - expandSize / 2, expandY, expandY - expandSize / 2}, 3);
			g.setColor(Color.black);
			g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10));
			g.drawPolyline(
					new int[] {expandX - expandSize / 2, expandX, expandX + expandSize / 2},
					new int[] {expandY - expandSize / 2, expandY, expandY - expandSize / 2}, 3);
		}
		g2.setComposite(oldComp);
	}
 
Example 18
Project: parabuild-ci   File: BarRenderer3D.java   View Source Code Vote up 4 votes
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
public void drawBackground(Graphics2D g2, CategoryPlot plot, 
                           Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // higlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 
                plot.getBackgroundAlpha()));
        g2.drawImage(backgroundImage, (int) x1, (int) y3, 
                (int) (x3 - x1 + 1), (int) (y1 - y3 + 1), null);
        g2.setComposite(originalComposite);
    }

}
 
Example 19
Project: brModelo   File: Legenda.java   View Source Code Vote up 4 votes
@Override
    public void DoPaint(Graphics2D g) {
        super.DoPaint(g);
        Rectangle rec = getArea();
        Color bkpc = g.getColor();

        g.setColor(getBorderColor());

        g.drawRect(rec.x, rec.y, rec.width, rec.height);

        Rectangle bkp = g.getClipBounds();
        g.clipRect(rec.x, rec.y, rec.width, rec.height);

        Font fn = getFont();
        Font font = new Font(fn.getFontName(), fn.getStyle(), fn.getSize() - 2);

        fn = g.getFont();
        g.setFont(font);

        altura = g.getFontMetrics().getHeight() + g.getFontMetrics().getDescent();
        alturaTitulo = altura + altura / 2;

        Composite originalComposite = g.getComposite();
        float alfa = 0.8f;
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));

        if (getTipo() == TipoLegenda.tpObjetos) {
            altura = Math.max(32, altura);
        }

        int posi = altura + alturaTitulo + rec.y;
        final int lft = rec.x + 2;

        for (ItemDeLegenda it : getItens()) {

            if (it.isSelecionada()) {
                g.setColor(isDisablePainted()? disabledColor : new Color(204, 204, 255, 50));
                g.fillRect(lft, posi - altura - 2, getWidth(), altura + 4);
            }
            g.setColor(isDisablePainted()? disabledColor : it.cor);
            int moveleft;
            switch (getTipo()) {
                case tpLinhas:
                    moveleft = 3 * altura;
                    g.fillRoundRect(lft, posi - (altura / 2) - 2, moveleft - 2, 4, 2, 2);
                    g.setColor(bkpc);
                    g.drawString(it.texto, lft + moveleft, posi - 6);
                    break;
                case tpObjetos:
                    ImageIcon img = Editor.fromControler().getImagemNormal(getMaster().getCassesDoDiagrama()[it.getTag()].getSimpleName());
                    g.drawImage(util.TratadorDeImagens.ReColorBlackImg(img, it.getCor()), lft, posi - altura, null);
                    moveleft = altura + 2;
                    g.drawString(it.texto, lft + moveleft, posi - altura / 2 + 6);
                    break;
                default:
                    moveleft = altura;
                    g.fillRect(lft, posi - altura, altura - 4, altura - 4);
                    g.setColor(bkpc);
                    g.drawRect(lft, posi - altura, altura - 4, altura - 4);
                    g.drawString(it.texto, lft + moveleft, posi - 6);
            }
            it.Area = new Point(posi - altura - 2, altura + 4);
            posi += altura + 4;
        }

        g.setComposite(originalComposite);

//        g.setColor(Color.LIGHT_GRAY);
//        g.drawLine(lft - 1, posi - altura - 2, getLeft() + getWidth() - 1, posi - altura - 2);
        g.setClip(bkp);
        g.setFont(fn);
    }
 
Example 20
Project: brModelo   File: baseDrawerFromForma.java   View Source Code Vote up 4 votes
@Override
public void DoPaint(Graphics2D g) {
    g.setPaint(this.getForeColor());
    if (blankPaint) {
        DimensioneParaPintura();
        super.DoPaint(g);
        return;
    }
    Composite ori = g.getComposite();
    
    if (isGradiente()) {
        PaintGradiente(g);
    }
    Paint paintg = g.getPaint();
    Composite orig = g.getComposite();
    
    g.setComposite(ori);
    g.setPaint(this.getForeColor());
    super.DoPaint(g);
    g.setPaint(paintg);
    g.setComposite(orig);
    DimensioneParaPintura();
    if (roundrect > 0) {
        if (isPintarBorda()) {
            g.setPaint(getCorBorda());
            g.drawRoundRect(L, T, W, H, roundrect, roundrect);
        }
        margemTitulo = g.getFontMetrics(getFont()).getHeight() + 4 * distSelecao;
        if (delimite) {
            g.drawLine(L + 1, T + margemTitulo, W + L - distSelecao + 1, T + margemTitulo);
        }
    } else {
        if (isPintarBorda()) {
            g.setPaint(isDisablePainted()? disabledColor : Color.darkGray);
            g.drawRect(L, T, W, H);

            g.setPaint(isDisablePainted()? disabledColor : Color.gray);
            g.drawRect(L, T, W + 1, H + 1);

            g.setPaint(getCorBorda());
            g.drawRect(L, T, W - 1, H - 1);
        }
        margemTitulo = g.getFontMetrics(getFont()).getHeight() + 4 * distSelecao;
        if (delimite) {
            g.drawLine(L + 1, T + margemTitulo, W + L - distSelecao + 1, T + margemTitulo);
        }
    }
    g.setPaint(paintg);
    //Pode terminar a pintura na forma gradiente, cor da borda e etc, deve ser tratado pelas classes descedentes.
}