File: GradientWithBorderPainter.java

package info (click to toggle)
mac-widgets 0.10.0%2Bsvn416-dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,968 kB
  • ctags: 2,003
  • sloc: java: 9,909; makefile: 13; sh: 12
file content (45 lines) | stat: -rw-r--r-- 1,635 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.explodingpixels.painter;

import java.awt.Color;
import java.awt.Component;
import java.awt.GradientPaint;
import java.awt.Graphics2D;

public class GradientWithBorderPainter implements MacWidgetsPainter<Component> {

    private final Color fTopLineColor;

    private final Color fBottomLineColor;

    private final Color fTopGradientColor;

    private final Color fBottomGradientColor;

    public GradientWithBorderPainter(Color topLineColor, Color bottomLineColor,
                                     Color topGradientColor, Color bottomGradientColor) {
        fTopLineColor = topLineColor;
        fBottomLineColor = bottomLineColor;
        fTopGradientColor = topGradientColor;
        fBottomGradientColor = bottomGradientColor;
    }

    public void paint(Graphics2D g, Component object, int width, int height) {
        // create the paint - start the gradient one pixel from the top
        // of the component and finish the gradient one pixel from the
        // bottom.
        GradientPaint paint = new GradientPaint(
                0, 1, fTopGradientColor,
                0, height - 2, fBottomGradientColor);
        // install the paint and fill a rectangle with it.
        g.setPaint(paint);
        g.fillRect(0, 0, width, height);
        // set the graphics color and draw a line across the top of the
        // component.
        g.setColor(fTopLineColor);
        g.drawLine(0, 0, width, 0);
        // set the graphics color and draw a line across the bottom of the
        // component.
        g.setColor(fBottomLineColor);
        g.drawLine(0, height - 1, width, height - 1);
    }
}