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

The following are Jave code examples for showing how to use getPaint() 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: incubator-netbeans   File: AquaViewTabDisplayerUI.java   View Source Code Vote up 6 votes
@Override
protected void paintTabBackground(Graphics g, int index, int x, int y,
                                  int width, int height) {
    Graphics2D g2d = (Graphics2D) g;
    Paint p = g2d.getPaint();
    if( isSelected(index) ) {
        g2d.setPaint( ColorUtil.getGradientPaint(x, y, UIManager.getColor("NbTabControl.selectedTabBrighterBackground"),
                x, y+height/2, UIManager.getColor("NbTabControl.selectedTabDarkerBackground")) );
    } else if( isMouseOver(index) ) {
        g2d.setPaint( ColorUtil.getGradientPaint(x, y, UIManager.getColor("NbTabControl.mouseoverTabBrighterBackground"),
                x, y+height/2, UIManager.getColor("NbTabControl.mouseoverTabDarkerBackground")) );
    } else {
        g2d.setPaint( ColorUtil.getGradientPaint(x, y, UIManager.getColor("NbTabControl.inactiveTabBrighterBackground"),
                x, y+height/2, UIManager.getColor("NbTabControl.inactiveTabDarkerBackground")) );
    }
    g2d.fillRect(x, y, width, height);
    g2d.setPaint(p);
}
 
Example 2
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 3
Project: brModelo   File: Diagrama.java   View Source Code Vote up 6 votes
/**
 * Mostra a área de impressão no diagrama
 *
 * @param g
 * @param wdt largura
 * @param ht altura
 */
public void PaintAI(Graphics2D g, int wdt, int ht) {
    Paint bkppaint = g.getPaint();
    g.setColor(new Color(221, 221, 221));
    int w = wdt;
    while (w < getWidth()) {
        g.drawLine(w, 1, w, getHeight() - 1);
        w += wdt;
    }
    int h = ht;
    while (h < getHeight()) {
        g.drawLine(1, h, getWidth() - 1, h);
        h += ht;
    }
    g.setPaint(bkppaint);
}
 
Example 4
Project: brModelo   File: Selecionador.java   View Source Code Vote up 6 votes
@Override
public void DoPaint(Graphics2D g) {
    Paint bkppaint = g.getPaint();
    //super.DoPaint(g); //To change body of generated methods, choose Tools | Templates.
    Graphics2D Canvas = g;
    Stroke stroke = g.getStroke();
    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            2f,
            new float[]{2f, 2f},
            1f));

    //Composite ori = g.getComposite();
    //g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, 1f));

    Canvas.setPaint(Color.BLACK);
    Canvas.drawRect(getLeft(), getTop(), getWidth() - 2, getHeight() - 2);
    g.setStroke(stroke);
    g.setPaint(bkppaint);//g.setComposite(ori);
}
 
Example 5
Project: brModelo   File: FormaTriangular.java   View Source Code Vote up 5 votes
@Override
protected void DoPaintDoks(Graphics2D g) {
    Point[] pts = getPontosDoTriangulo();
    Paint bkpP = g.getPaint();
    g.setPaint(Color.orange);
    for (Point pt : pts) {
        g.fillRect(pt.x - 2, pt.y - 2, 4, 4);
    }
    g.setPaint(bkpP);
}
 
Example 6
Project: incubator-netbeans   File: RendererPanel.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics g) {
    if (isRoot && colorManager.isAqua() && node.isExpandable() && node.isRenderedWithGradient()) {
        Graphics2D g2d = (Graphics2D) g;
        Paint oldPaint = g2d.getPaint();
        g2d.setPaint(new GradientPaint(0, 0, Color.white, 0, getHeight() / 2, getBackground()));
        g2d.fillRect(0, 0, getWidth(), getHeight());
        g2d.setPaint(oldPaint);
    } else {
        super.paintComponent(g);
    }
}
 
Example 7
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 8
Project: GIFKR   File: ColorInterpolator.java   View Source Code Vote up 5 votes
@Override
public void paintGraph(Graphics2D g, int width, int height) {
	g.setColor(keyframes.get(0).getValue());
	g.fillRect(0, gradPadding, (int) (keyframes.get(0).getTime()*width), height-2*gradPadding);
	g.setColor(keyframes.get(keyframes.size()-1).getValue());
	g.fillRect((int) ((keyframes.get(keyframes.size()-1).getTime())*width), gradPadding, width - (int) ((keyframes.get(keyframes.size()-1).getTime())*width), height-2*gradPadding);

	Paint origP = g.getPaint();

	for(int i = 0; i < keyframes.size()-1; i++) {

		Keyframe<Color> k0 = keyframes.get(i), k1 = keyframes.get(i+1);

		g.setPaint(new GradientPaint(k0.getTime()*width, 0, k0.getValue(), k1.getTime()*width, 0, k1.getValue()));
		g.fillRect((int) (k0.getTime()*width), gradPadding-3, (int) (k1.getTime()*width-k0.getTime()*width), height-2*(gradPadding-3));
	}
	g.setPaint(origP);

	g.setStroke(new BasicStroke(3)); //Draw red bar at each keyframe
	g.setColor(Color.BLACK);//new Color(255, 0, 0, 32));
	for(int i = 0; i < keyframes.size(); i++)
		g.drawLine((int) (keyframes.get(i).getTime() * width), 0, (int) (keyframes.get(i).getTime() * width), height);
	g.setStroke(new BasicStroke(1)); //Draw red bar at each keyframe
	g.setColor(Color.WHITE);//new Color(255, 0, 0, 32));
	for(int i = 0; i < keyframes.size(); i++)
		g.drawLine((int) (keyframes.get(i).getTime() * width), 0, (int) (keyframes.get(i).getTime() * width), height);
}
 
Example 9
Project: JavaGraph   File: JVertexView.java   View Source Code Vote up 5 votes
/**
 * Paints the background, with a given shape.
 */
private void paintBackground(Graphics2D g, Shape shape) {
    Paint oldPaint = g.getPaint();
    Paint newPaint = JAttr.createPaint(shape.getBounds(), getBackground());
    g.setPaint(newPaint);
    g.fill(shape);
    g.setPaint(oldPaint);
}
 
Example 10
Project: brModelo   File: Impressor.java   View Source Code Vote up 5 votes
/**
 * Pinta a área que não será impressa
 */
private void PinteNoArea(Graphics2D Canvas) {
    if (getDiagrama() != null) {
        Paint bkp = Canvas.getPaint();
        Canvas.setColor(new Color(241, 241, 241));

        int x = PaginasW * LarguraPagina;
        Canvas.fillRect(x + 2, 2, getWidth() - (x + 4), getHeight() - 4);

        int y = PaginasH * AlturaPagina;
        Canvas.fillRect(2, y + 2, getWidth() - 4, getHeight() - (y + 4));
        Canvas.setPaint(bkp);
    }
}
 
Example 11
Project: brModelo   File: FormaNaoRetangularDisformeBase.java   View Source Code Vote up 5 votes
@Override
protected void DoPaintDoks(Graphics2D g) {
    Point[] pts = getPontosColaterais();
    Paint bkpP = g.getPaint();
    g.setPaint(Color.yellow);
    for (int i = 0; i < pts.length; i++) {
        if (shouldMove(i)) {
            Point p = getReposicionePonto(i);
            g.fillRect(pts[i].x - 2 + p.x, pts[i].y - 2 + p.y, 4, 4);
        } else {
            g.fillRect(pts[i].x - 2, pts[i].y - 2, 4, 4);
        }
    }
    g.setPaint(bkpP);
}
 
Example 12
Project: parabuild-ci   File: ClipPath.java   View Source Code Vote up 5 votes
/**
 * Draws the clip path.
 *
 * @param g2  current graphics2D.
 * @param dataArea  the dataArea that the plot is being draw in.
 * @param horizontalAxis  the horizontal axis.
 * @param verticalAxis  the vertical axis.
 *
 * @return The GeneralPath defining the outline
 */
public GeneralPath draw(Graphics2D g2,
                        Rectangle2D dataArea,
                        ValueAxis horizontalAxis, ValueAxis verticalAxis) {

    GeneralPath generalPath = generateClipPath(
        dataArea, horizontalAxis, verticalAxis
    );
    if (this.fillPath || this.drawPath) {
        Composite saveComposite = g2.getComposite();
        Paint savePaint = g2.getPaint();
        Stroke saveStroke = g2.getStroke();

        if (this.fillPaint != null) {
            g2.setPaint(this.fillPaint);
        }
        if (this.composite != null) {
            g2.setComposite(this.composite);
        }
        if (this.fillPath) {
            g2.fill(generalPath);
        }

        if (this.drawStroke != null) {
            g2.setStroke(this.drawStroke);
        }
        if (this.drawPath) {
            g2.draw(generalPath);
        }
        g2.setPaint(savePaint);
        g2.setComposite(saveComposite);
        g2.setStroke(saveStroke);
    }
    return generalPath;

}
 
Example 13
Project: brModelo   File: FormaLosangular.java   View Source Code Vote up 5 votes
@Override
protected void DoPaintDoks(Graphics2D g) {
    Point[] pts = getAllSubPoints();
    Paint bkpP = g.getPaint();
    g.setPaint(Color.orange);
    for (Point pt : pts) {
        g.fillRect(pt.x - 2, pt.y - 2, 4, 4);
    }
    g.setPaint(bkpP);
}
 
Example 14
Project: brModelo   File: FormaArea.java   View Source Code Vote up 5 votes
protected void PaintGradiente(Graphics2D g) { //, boolean round) {
        Paint bkp = g.getPaint();
        int dist = distSelecao;

        int W = getWidth() - dist;
        int H = 2 * alturaTexto - 1 - dist;
        boolean dv = getGDirecao() == VERTICAL;

        Composite originalComposite = g.getComposite();
        int type = AlphaComposite.SRC_OVER;

        g.setComposite(AlphaComposite.getInstance(type, alfa));

        Stroke bkps = g.getStroke();
        if (isDashed()) {
            g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
        }

//        GradientPaint GP = new GradientPaint(getLeft(), getTop(), Color.LIGHT_GRAY, dv ? getLeft() : getLeft() + W, dv ? getTop() + H : getTop(), Color.white, true);
//        g.setPaint(GP);
        int w = getWidth() - dist;
        int h = getHeight() - dist;
        int L = getLeft();
        int T = getTop();

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

        g.fillRect(getLeft() + 1, getTop() + 1, W, H);
        g.setComposite(originalComposite);
        g.setPaint(bkp);
        g.setStroke(bkps);
    }
 
Example 15
Project: brModelo   File: FormaNaoRetangularBase.java   View Source Code Vote up 5 votes
@Override
protected void DoPaintDoks(Graphics2D g) {
    Point[] pts = getPontosColaterais();
    Paint bkpP = g.getPaint();
    g.setPaint(Color.yellow);
    for (int i = 0; i < pts.length; i ++) {
        g.fillRect(pts[i].x -2, pts[i].y -2, 4, 4);
    }
    g.setPaint(bkpP);
}
 
Example 16
Project: litiengine   File: AmbientLight.java   View Source Code Vote up 4 votes
private void renderLightSource(final Graphics2D g, final LightSource light, final double longerDimension) {
  final Point2D lightCenter = light.getDimensionCenter();

  final Area lightArea = new Area(light.getLightShape());
  if (light.getLightShapeType().equals(LightSource.RECTANGLE)) {
    g.setColor(light.getColor());
    g.fill(lightArea);
    return;
  }

  // cut the light area where shadow Boxes are (this simulates light falling
  // into and out of rooms)
  for (final StaticShadow col : this.environment.getStaticShadows()) {
    if (!GeometricUtilities.shapeIntersects(light.getLightShape(), col.getBoundingBox())) {
      continue;
    }
    final Area boxInLight = new Area(col.getBoundingBox());
    boxInLight.intersect(lightArea);

    final Line2D[] bounds = GeometricUtilities.getLines(col.getBoundingBox());
    for (final Line2D line : bounds) {
      final Vector2D lineVector = new Vector2D(line.getP1(), line.getP2());
      final Vector2D lightVector = new Vector2D(lightCenter, line.getP1());

      if (light.getDimensionCenter().getY() < line.getY1() && light.getDimensionCenter().getY() < line.getY2() && col.getBoundingBox().contains(light.getDimensionCenter()) || lineVector.normalVector().dotProduct(lightVector) >= 0) {
        continue;
      }

      final Path2D shadowParallelogram = new Path2D.Double();
      final Point2D shadowPoint1 = GeometricUtilities.project(lightCenter, line.getP1(), longerDimension);
      final Point2D shadowPoint2 = GeometricUtilities.project(lightCenter, line.getP2(), longerDimension);

      // construct a shape from our points
      shadowParallelogram.moveTo(line.getP1().getX(), line.getP1().getY());
      shadowParallelogram.lineTo(shadowPoint1.getX(), shadowPoint1.getY());
      shadowParallelogram.lineTo(shadowPoint2.getX(), shadowPoint2.getY());
      shadowParallelogram.lineTo(line.getP2().getX(), line.getP2().getY());
      shadowParallelogram.closePath();

      final Area shadowArea = new Area(shadowParallelogram);
      if (light.getDimensionCenter().getY() < col.getBoundingBox().getMaxY() && !col.getBoundingBox().contains(light.getDimensionCenter())) {
        shadowArea.add(boxInLight);
      }
      shadowArea.intersect(lightArea);
      lightArea.subtract(shadowArea);
    }
  }

  final Paint oldPaint = g.getPaint();

  // render parts that lie within the shadow with a gradient from the light
  // color to transparent
  final Area lightRadiusArea = new Area(light.getLightShape());
  final Color[] transColors = new Color[] { new Color(light.getColor().getRed(), light.getColor().getGreen(), light.getColor().getBlue(), light.getBrightness()), new Color(light.getColor().getRed(), light.getColor().getGreen(), light.getColor().getBlue(), 0) };
  try {
    g.setPaint(new RadialGradientPaint(new Point2D.Double(lightRadiusArea.getBounds2D().getCenterX(), lightRadiusArea.getBounds2D().getCenterY()), (float) (lightRadiusArea.getBounds2D().getWidth() / 2), new float[] { 0.0f, 1.00f }, transColors));
  } catch (final Exception e) {
    g.setColor(light.getColor());
  }
  g.fill(lightArea);
  g.setPaint(oldPaint);
}
 
Example 17
Project: incubator-netbeans   File: SheetTable.java   View Source Code Vote up 4 votes
/** Paint the expandable sets.  These are painted double width,
 *  across the entire width of the table. */
private void paintExpandableSets(Graphics g) {
    int start = 0;
    int end = getRowCount();

    Insets ins = getInsets();

    boolean canBeSelected = isKnownComponent(
            KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
        );

    for (int i = 0; i < end; i++) {
        int idx = start + i;
        Object value = getValueAt(idx, 0);

        if (value instanceof PropertySet) {
            Rectangle r = getCellRect(idx, 0, false);
            r.x = ins.left;
            r.width = getWidth() - (ins.left + ins.right);

            if (g.hitClip(r.x, r.y, r.width, r.height)) {
                PropertySet ps = (PropertySet) value;

                String txt = ps.getHtmlDisplayName();
                boolean isHtml = txt != null;

                if (!isHtml) {
                    txt = ps.getDisplayName();
                }

                if (htmlrenderer == null) {
                    htmlrenderer = HtmlRenderer.createRenderer();
                }

                JComponent painter = (JComponent) htmlrenderer.getTableCellRendererComponent(
                        this, txt, false, false, idx, 0
                    );

                htmlrenderer.setHtml(isHtml);
                htmlrenderer.setParentFocused(true);

                htmlrenderer.setIconTextGap(2);

                htmlrenderer.setIcon(
                    getPropertySetModel().isExpanded(ps) ? PropUtils.getExpandedIcon() : PropUtils.getCollapsedIcon()
                );

                boolean selected = canBeSelected && (getSelectedRow() == idx);

                if (!selected) {
                    painter.setBackground(PropUtils.getSetRendererColor());
                    painter.setForeground(PropUtils.getSetForegroundColor());
                } else {
                    painter.setBackground(PropUtils.getSelectedSetRendererColor());
                    painter.setForeground(PropUtils.getSelectedSetForegroundColor());
                }

                if( PropUtils.isAqua ) {
                    painter.setOpaque(false);
                    Graphics2D g2d = (Graphics2D) g;
                    Paint oldPaint = g2d.getPaint();
                    g2d.setPaint( new GradientPaint(r.x,r.y, Color.white, r.x, r.y+r.height/2, painter.getBackground()) );
                    g2d.fillRect(r.x, r.y, r.width, r.height);
                    g2d.setPaint(oldPaint);
                } else {
                    painter.setOpaque(true);
                }

                paintComponent(g, painter, r.x, r.y, r.width, r.height);
            }
        }
    }
}
 
Example 18
Project: OpenJSharp   File: Decoration.java   View Source Code Vote up 4 votes
public void drawTextAndDecorations(Label label,
                            Graphics2D g2d,
                            float x,
                            float y) {

    if (fgPaint == null && bgPaint == null && swapColors == false) {
        drawTextAndEmbellishments(label, g2d, x, y);
    }
    else {
        Paint savedPaint = g2d.getPaint();
        Paint foreground, background;

        if (swapColors) {
            background = fgPaint==null? savedPaint : fgPaint;
            if (bgPaint == null) {
                if (background instanceof Color) {
                    Color bg = (Color)background;
                    // 30/59/11 is standard weights, tweaked a bit
                    int brightness = 33 * bg.getRed()
                        + 53 * bg.getGreen()
                        + 14 * bg.getBlue();
                    foreground = brightness > 18500 ? Color.BLACK : Color.WHITE;
                } else {
                    foreground = Color.WHITE;
                }
            } else {
                foreground = bgPaint;
            }
        }
        else {
            foreground = fgPaint==null? savedPaint : fgPaint;
            background = bgPaint;
        }

        if (background != null) {

            Rectangle2D bgArea = label.getLogicalBounds();
            bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(),
                                        y + (float)bgArea.getY(),
                                        (float)bgArea.getWidth(),
                                        (float)bgArea.getHeight());

            g2d.setPaint(background);
            g2d.fill(bgArea);
        }

        g2d.setPaint(foreground);
        drawTextAndEmbellishments(label, g2d, x, y);
        g2d.setPaint(savedPaint);
    }
}
 
Example 19
Project: jdk8u-jdk   File: Decoration.java   View Source Code Vote up 4 votes
public void drawTextAndDecorations(Label label,
                            Graphics2D g2d,
                            float x,
                            float y) {

    if (fgPaint == null && bgPaint == null && swapColors == false) {
        drawTextAndEmbellishments(label, g2d, x, y);
    }
    else {
        Paint savedPaint = g2d.getPaint();
        Paint foreground, background;

        if (swapColors) {
            background = fgPaint==null? savedPaint : fgPaint;
            if (bgPaint == null) {
                if (background instanceof Color) {
                    Color bg = (Color)background;
                    // 30/59/11 is standard weights, tweaked a bit
                    int brightness = 33 * bg.getRed()
                        + 53 * bg.getGreen()
                        + 14 * bg.getBlue();
                    foreground = brightness > 18500 ? Color.BLACK : Color.WHITE;
                } else {
                    foreground = Color.WHITE;
                }
            } else {
                foreground = bgPaint;
            }
        }
        else {
            foreground = fgPaint==null? savedPaint : fgPaint;
            background = bgPaint;
        }

        if (background != null) {

            Rectangle2D bgArea = label.getLogicalBounds();
            bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(),
                                        y + (float)bgArea.getY(),
                                        (float)bgArea.getWidth(),
                                        (float)bgArea.getHeight());

            g2d.setPaint(background);
            g2d.fill(bgArea);
        }

        g2d.setPaint(foreground);
        drawTextAndEmbellishments(label, g2d, x, y);
        g2d.setPaint(savedPaint);
    }
}
 
Example 20
Project: openjdk-jdk10   File: Decoration.java   View Source Code Vote up 4 votes
public void drawTextAndDecorations(Label label,
                            Graphics2D g2d,
                            float x,
                            float y) {

    if (fgPaint == null && bgPaint == null && swapColors == false) {
        drawTextAndEmbellishments(label, g2d, x, y);
    }
    else {
        Paint savedPaint = g2d.getPaint();
        Paint foreground, background;

        if (swapColors) {
            background = fgPaint==null? savedPaint : fgPaint;
            if (bgPaint == null) {
                if (background instanceof Color) {
                    Color bg = (Color)background;
                    // 30/59/11 is standard weights, tweaked a bit
                    int brightness = 33 * bg.getRed()
                        + 53 * bg.getGreen()
                        + 14 * bg.getBlue();
                    foreground = brightness > 18500 ? Color.BLACK : Color.WHITE;
                } else {
                    foreground = Color.WHITE;
                }
            } else {
                foreground = bgPaint;
            }
        }
        else {
            foreground = fgPaint==null? savedPaint : fgPaint;
            background = bgPaint;
        }

        if (background != null) {

            Rectangle2D bgArea = label.getLogicalBounds();
            bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(),
                                        y + (float)bgArea.getY(),
                                        (float)bgArea.getWidth(),
                                        (float)bgArea.getHeight());

            g2d.setPaint(background);
            g2d.fill(bgArea);
        }

        g2d.setPaint(foreground);
        drawTextAndEmbellishments(label, g2d, x, y);
        g2d.setPaint(savedPaint);
    }
}