~ubuntu-branches/ubuntu/vivid/kunststoff/vivid

« back to all changes in this revision

Viewing changes to src/com/incors/plaf/kunststoff/KunststoffUtilities.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-05-14 20:24:15 UTC
  • Revision ID: james.westby@ubuntu.com-20070514202415-00ophg1zvus0kmqw
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.incors.plaf.kunststoff;
 
2
 
 
3
/*
 
4
 * This code was developed by INCORS GmbH (www.incors.com).
 
5
 * It is published under the terms of the GNU Lesser General Public License.
 
6
 */
 
7
 
 
8
import java.awt.*;
 
9
import com.incors.plaf.*;
 
10
 
 
11
/**
 
12
 * Collection of methods often used in the Kunststoff Look&Feel
 
13
 */
 
14
public class KunststoffUtilities {
 
15
 
 
16
  /**
 
17
   * Convenience method to create a translucent <code>Color</color>.
 
18
   */
 
19
  public static Color getTranslucentColor(Color color, int alpha) {
 
20
    if (color == null) {
 
21
      return null;
 
22
    } else if (alpha == 255) {
 
23
      return color;
 
24
    } else {
 
25
      return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
 
26
    }
 
27
  }
 
28
 
 
29
  /**
 
30
   * Convenience method to create a translucent <code>ColorUIResource</code>.
 
31
   */
 
32
  public static Color getTranslucentColorUIResource(Color color, int alpha) {
 
33
    if (color == null) {
 
34
      return null;
 
35
    } else if (alpha == 255) {
 
36
      return color;
 
37
    } else {
 
38
      return new ColorUIResource2(color.getRed(), color.getGreen(), color.getBlue(), alpha);
 
39
    }
 
40
  }
 
41
 
 
42
  /**
 
43
   * Convenience method to draw a gradient on the specified rectangle
 
44
   */
 
45
  public static void drawGradient(Graphics g, Color color1, Color color2, Rectangle rect, boolean isVertical) {
 
46
    Graphics2D g2D = (Graphics2D) g;
 
47
    Paint gradient = new FastGradientPaint(color1, color2, isVertical);
 
48
    g2D.setPaint(gradient);
 
49
    g2D.fill(rect);
 
50
  }
 
51
 
 
52
  /**
 
53
   * Convenience method to draw a gradient. The first rectangle defines the drawing region,
 
54
   * the second rectangle defines the size of the gradient.
 
55
   */
 
56
  public static void drawGradient(Graphics g, Color color1, Color color2, Rectangle rect, Rectangle rect2, boolean isVertical) {
 
57
    // We are currently not using the FastGradientPaint to render this gradient, because we have to decide how
 
58
    // we can use FastGradientPaint if rect and rect2 are different.
 
59
    if (isVertical) {
 
60
      Graphics2D g2D = (Graphics2D) g;
 
61
      GradientPaint gradient = new GradientPaint(0f, (float) rect.getY(), color1, 0f, (float) (rect.getHeight() + rect.getY()), color2);
 
62
      g2D.setPaint(gradient);
 
63
      g2D.fill(rect);
 
64
    } else {
 
65
      Graphics2D g2D = (Graphics2D) g;
 
66
      GradientPaint gradient = new GradientPaint((float) rect.getX(), 0f, color1, (float) (rect.getWidth() + rect.getX()), 0f, color2);
 
67
      g2D.setPaint(gradient);
 
68
      g2D.fill(rect);
 
69
    }
 
70
  }
 
71
 
 
72
  /**
 
73
   * Returns true if the display uses 24- or 32-bit color depth (= true color)
 
74
   */
 
75
  public static boolean isToolkitTrueColor(Component c) {
 
76
    int pixelsize = c.getToolkit().getColorModel().getPixelSize();
 
77
    return pixelsize >= 24;
 
78
  }
 
79
}