Search in sources :

Example 21 with GradientPaint

use of java.awt.GradientPaint in project gitblit by gitblit.

the class HeaderPanel method paintComponent.

@Override
public void paintComponent(Graphics oldG) {
    Graphics2D g = (Graphics2D) oldG;
    Point2D startPoint = new Point2D.Float(0, 0);
    Point2D endPoint = new Point2D.Float(0, getHeight());
    Paint gradientPaint = new GradientPaint(startPoint, lightColor, endPoint, getBackground(), false);
    g.setPaint(gradientPaint);
    g.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    g.setColor(new Color(0xff, 0x99, 0x00));
    int stroke = 2;
    g.setStroke(new BasicStroke(stroke));
    g.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
}
Also used : BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 22 with GradientPaint

use of java.awt.GradientPaint in project openblocks by mikaelhg.

the class SliderBlueprint method paintComponent.

/**
     * Paints the CSlider
     */
@Override
public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.addRenderingHints(renderingHints);
    // gets the distance from the left side of the slider to the thumb in pixel
    int thumbX = getThumbX();
    this.reformBlueprint(blueprint, this.getWidth(), this.getHeight(), (int) (trackThickness * this.getHeight()), thumbX);
    Shape leading = this.reformLeadingTrack(blueprint);
    Shape trailing = this.reformTrailingTrack(blueprint);
    Shape thumb = this.reformThumb(blueprint, this.getHeight() / 2);
    Shape miniThumb = this.reformThumb(blueprint, this.getHeight() / 4);
    //draw shapes
    g2.setPaint(new GradientPaint(0, blueprint.trackTop, this.leadingColor, 0, blueprint.trackBottom, Color.white, false));
    g2.fill(leading);
    g2.setPaint(new GradientPaint(0, blueprint.trackTop, this.trailingColor, 0, blueprint.trackBottom, Color.white, false));
    g2.fill(trailing);
    g2.setColor(new Color(250, 250, 250, 100));
    g2.draw(leading);
    g2.draw(trailing);
    // draws the tick marks if ticks are turned on
    // also draws where the triangle where thumb starts
    g2.setColor(Color.lightGray);
    if (this.tickNumber != 0 && this.setTicks) {
        Shape ticks = this.reformTicks(blueprint);
        g2.draw(ticks);
    }
    // depending on what the start mark was set as when initialized
    if (this.startMark) {
        g2.setColor(Color.white);
        Font font = new Font("Dialog", Font.PLAIN, 8);
        FontMetrics metrics = getFontMetrics(font);
        // gets the width of the text so that the words can be centered later on
        int textWidth = metrics.stringWidth(startMarkLabel);
        g2.setFont(font);
        g2.drawString(startMarkLabel, (int) (convertToPixels(this.thumbStart) - (textWidth / 2)), (int) (blueprint.trackBottom * 1.7));
    }
    //g2.setPaint(new GradientPaint(0,0,Color.white,0,th,this.thumbColor, false));
    g2.setColor(Color.lightGray);
    g2.fill(thumb);
    //g2.setPaint(new GradientPaint(0,0,Color.darkGray,0,th,this.thumbColor, false));
    g2.setColor(Color.darkGray);
    g2.fill(miniThumb);
    g2.setColor(thumbColor);
    g2.draw(thumb);
}
Also used : Shape(java.awt.Shape) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 23 with GradientPaint

use of java.awt.GradientPaint in project openblocks by mikaelhg.

the class CTabButton method paint.

/**
     * re paints this
     */
public void paint(Graphics g) {
    // Set up graphics and buffer
    //super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Set up first layer
    int buttonHeight = this.getHeight() - (INSET * 2);
    int buttonWidth = this.getWidth() - (INSET * 2);
    int arc = buttonHeight / 3;
    Color topColoring;
    Color bottomColoring;
    if (this.focus || this.selected) {
        topColoring = this.selectedColor.darker().darker().darker();
        bottomColoring = this.selectedColor;
    } else {
        topColoring = this.buttonColor;
        bottomColoring = this.buttonColor;
    }
    // Paint the first layer
    g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
    g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight + arc, arc, arc);
    g2.setColor(Color.darkGray);
    g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight + arc, arc, arc);
    // set up paint data fields for second layer
    int highlightHeight = buttonHeight / 2 - HIGHLIGHT_INSET;
    int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2) + 1;
    if (this.focus || this.selected) {
        topColoring = Color.white;
        bottomColoring = this.selectedColor;
    } else {
        topColoring = Color.gray;
        bottomColoring = Color.darkGray;
    }
    // Paint the second layer
    g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
    g2.fillRoundRect(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET + 1, highlightWidth, highlightHeight, arc, arc);
    //g2.setColor(Color.gray);
    //g2.drawRoundRect(INSET+HIGHLIGHT_INSET,INSET+HIGHLIGHT_INSET,highlightWidth,highlightHeight,arc,arc);
    // Draw the text (if any)
    Font font;
    if (this.getText() != null) {
        if (this.selected) {
            g2.setColor(Color.white);
            font = new Font("Ariel", Font.BOLD, buttonHeight * 2 / 3);
        } else {
            g2.setColor(Color.white);
            font = new Font("Ariel", Font.PLAIN, buttonHeight * 2 / 3);
        //font = g2.getFont().deriveFont((float)(((float)buttonHeight) * .4));
        }
        g2.setFont(font);
        FontMetrics metrics = g2.getFontMetrics();
        Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
        float x = (float) ((this.getWidth() / 2) - (textBounds.getWidth() / 2));
        float y = (float) ((this.getHeight() / 2) + (textBounds.getHeight() / 2)) - metrics.getDescent();
        g2.drawString(this.getText(), x, y);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 24 with GradientPaint

use of java.awt.GradientPaint in project EnrichmentMapApp by BaderLab.

the class ColorLegendPanel method paint.

@Override
public void paint(Graphics g) {
    final int w = getWidth();
    final int h = getHeight();
    if (w <= 0 || h <= 0)
        return;
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    float ww = w / 5.f;
    // To center the legend horizontally
    float hPad = ww / 2.f;
    //Gradient line start
    Point2D.Float p1 = new Point2D.Float(hPad, 0.f);
    //Gradient line end
    Point2D.Float p2 = new Point2D.Float(hPad + ww, 0.f);
    //empty white box
    //Gradient line start
    Point2D.Float p3 = new Point2D.Float(hPad + ww, 0.f);
    //Gradient line start
    Point2D.Float p5 = new Point2D.Float(hPad + 2 * ww, 0.f);
    //Gradient line start
    Point2D.Float p7 = new Point2D.Float(hPad + 3 * ww, 0.f);
    //Gradient line end
    Point2D.Float p8 = new Point2D.Float(hPad + 4 * ww, 0.f);
    float w1 = 30;
    float w2 = 30;
    float hh = h / 2;
    // Need to create two gradients, one one for the max and one for the min
    //Acyclic gradient
    GradientPaint g1 = new GradientPaint(p1, minColor, p2, Color.WHITE, false);
    //Acyclic gradient
    GradientPaint g2 = new GradientPaint(p7, Color.WHITE, p8, maxColor, false);
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x, p1.y, w1, hh);
    Rectangle2D.Float rect2 = new Rectangle2D.Float(p3.x, p3.y, w2, hh);
    Rectangle2D.Float rect3 = new Rectangle2D.Float(p5.x, p5.y, w2, hh);
    Rectangle2D.Float rect4 = new Rectangle2D.Float(p7.x, p7.y, w1, hh);
    g2d.setFont(getLabelFont());
    // Text y offset
    float tyOffset = hh + h / 3.f;
    if (minColor != Color.WHITE) {
        g2d.setPaint(g1);
        g2d.fill(rect1);
        g2d.setPaint(Color.WHITE);
        // make a white block
        g2d.setPaint(Color.WHITE);
        g2d.fill(rect2);
        g2d.setPaint(getLabelForeground());
        g2d.drawString(phenotype1, p1.x, p1.y + tyOffset);
    } else {
        g2d.setPaint(getLabelForeground());
        g2d.drawString(phenotype1, p5.x, p5.y + tyOffset);
    }
    // Make a white block
    g2d.setPaint(Color.WHITE);
    g2d.fill(rect3);
    g2d.setPaint(g2);
    g2d.fill(rect4);
    // Border
    g2d.setPaint(UIManager.getColor("Separator.foreground"));
    g2d.draw(new Rectangle2D.Float(p1.x, p1.y, (2 * w1 + 2 * w2), hh));
    g2d.setPaint(getLabelForeground());
    g2d.drawString(phenotype2, p7.x, p7.y + tyOffset);
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 25 with GradientPaint

use of java.awt.GradientPaint in project EnrichmentMapApp by BaderLab.

the class ColorGradientWidget method renderGradient.

private void renderGradient(Graphics2D g2d) {
    // create the gradient from min to center
    final GradientPaint gradientLow = new GradientPaint((float) minimumConditionGradientRectangle.getX(), (float) minimumConditionGradientRectangle.getY(), colorGradientTheme.getMinColor(), (float) maximumConditionGradientRectangle.getX(), (float) minimumConditionGradientRectangle.getY(), colorGradientTheme.getCenterColor());
    g2d.setPaint(gradientLow);
    g2d.fillRect((int) minimumConditionGradientRectangle.getX(), (int) minimumConditionGradientRectangle.getY(), (int) minimumConditionGradientRectangle.getWidth(), (int) minimumConditionGradientRectangle.getHeight());
    // create the gradient from center to max
    final GradientPaint gradientHigh = new GradientPaint((float) maximumConditionGradientRectangle.getX(), (float) maximumConditionGradientRectangle.getY(), colorGradientTheme.getCenterColor(), (float) (maximumConditionGradientRectangle.getX() + maximumConditionGradientRectangle.getWidth()), (float) maximumConditionGradientRectangle.getY(), colorGradientTheme.getMaxColor());
    g2d.setPaint(gradientHigh);
    g2d.fillRect((int) maximumConditionGradientRectangle.getX(), (int) maximumConditionGradientRectangle.getY(), (int) maximumConditionGradientRectangle.getWidth(), (int) maximumConditionGradientRectangle.getHeight());
    // draw outline around gradient
    final Rectangle rect = new Rectangle(0, 0, gradientWidth - 1, gradientHeight - 1);
    g2d.setPaint(borderColor);
    g2d.draw(rect);
}
Also used : Rectangle(java.awt.Rectangle) GradientPaint(java.awt.GradientPaint)

Aggregations

GradientPaint (java.awt.GradientPaint)38 Graphics2D (java.awt.Graphics2D)24 Color (java.awt.Color)22 Font (java.awt.Font)12 Rectangle2D (java.awt.geom.Rectangle2D)11 BasicStroke (java.awt.BasicStroke)9 BufferedImage (java.awt.image.BufferedImage)8 FontMetrics (java.awt.FontMetrics)7 Paint (java.awt.Paint)6 Rectangle (java.awt.Rectangle)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 RadialGradientPaint (java.awt.RadialGradientPaint)4 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 MultipleGradientPaint (java.awt.MultipleGradientPaint)3 Shape (java.awt.Shape)3 TexturePaint (java.awt.TexturePaint)3 Point2D (java.awt.geom.Point2D)3 RectangularShape (java.awt.geom.RectangularShape)3 ConvolveOp (java.awt.image.ConvolveOp)3 Kernel (java.awt.image.Kernel)3