Debian Codegraph @

src/com/jidesoft/plaf/eclipse/EclipseUtils.java

raw
1 /*
2 * @(#)VsnetUtils.java
3 *
4 * Copyright 2002-2003 JIDE Software. All rights reserved.
5 */
6 package com.jidesoft.plaf.eclipse;
7
8 import java.awt.*;
9
10 /**
11 */
12 public class EclipseUtils {
13
14 static Color getLighterColor(Color backColor) {
15 int r = getLighterColor(backColor.getRed());
16 int g = getLighterColor(backColor.getGreen());
17 int b = getLighterColor(backColor.getBlue());
18 if (r >= 255) r = 255;
19 if (g >= 255) g = 255;
20 if (b >= 255) b = 255;
21 return new Color(r, g, b);
22 }
23
24 static int getLighterColor(int x) {
25 return (int) (x * 36.0 / 255.0 + 219.5);
26 }
27
28
29 static Color getMenuSelectionColor(Color backColor) {
30 int r = getMenuSelectionValue(backColor.getRed());
31 int g = getMenuSelectionValue(backColor.getGreen());
32 int b = getMenuSelectionValue(backColor.getBlue());
33 if (r >= 255) r = 255;
34 if (g >= 255) g = 255;
35 if (b >= 255) b = 255;
36 return new Color(r, g, b);
37 }
38
39 static int getMenuSelectionValue(int x) {
40 return (int) (x * 76.0 / 255.0 + 179.5);
41 }
42
43 static Color getMenuBackgroundColor(Color backColor) {
44 int r = getMenuValue(backColor.getRed());
45 int g = getMenuValue(backColor.getGreen());
46 int b = getMenuValue(backColor.getBlue());
47 if (r >= 255) r = 255;
48 if (g >= 255) g = 255;
49 if (b >= 255) b = 255;
50 return new Color(r, g, b);
51 }
52
53 static int getMenuValue(int x) {
54 return (int) (x * 36.0 / 255.0 + 219.5);
55 }
56
57 static Color getDefaultBackgroundColor(Color backColor) {
58 Color backIDE;
59
60 // Check for the 'Classic' control color
61 if ((backColor.getRed() == 212) && (backColor.getGreen() == 208) && (backColor.getBlue() == 200)) {
62 // Use the exact background for this color
63 backIDE = new Color(247, 243, 233);
64 }
65 else if ((backColor.getRed() == 236) && (backColor.getGreen() == 233) && (backColor.getBlue() == 216)) {
66 // Check for the 'XP' control color
67 // Use the exact background for this color
68 backIDE = new Color(255, 251, 233);
69 }
70 else {
71 // Calculate the IDE background color as only half as dark as the control color
72 int r = backColor.getRed() + 35;
73 int g = backColor.getGreen() + 35;
74 int b = backColor.getBlue() + 35;
75 if (r >= 255) r = 255;
76 if (g >= 255) g = 255;
77 if (b >= 255) b = 255;
78 backIDE = new Color(r, g, b);
79 }
80
81 return backIDE;
82 }
83
84 private static final BasicStroke DOTTED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE,
85 BasicStroke.JOIN_ROUND, 1.0f, new float[]{0, 2, 0, 2}, 0);
86
87 public static void fillRectWithHatch(Graphics2D g, Rectangle rect, Color color) {
88 Stroke oldStroke = g.getStroke();
89
90 g.setColor(Color.white);
91 g.fillRect(rect.x, rect.y, rect.width, rect.height);
92
93 g.setColor(color);
94 g.setStroke(DOTTED_STROKE);
95
96 for (int i = 0; i < rect.width; i++) {
97 if (i % 2 == 0) {
98 g.drawLine(rect.x + i, rect.y, rect.x + i, rect.y + rect.height - 1);
99 }
100 else {
101 g.drawLine(rect.x + i, rect.y + 1, rect.x + i, rect.y + rect.height - 1);
102 }
103 }
104 g.setStroke(oldStroke);
105 }
106
107 static final double RATIO1 = 0.67;
108 static final double RATIO2 = 0.78;
109 static final double RATIO3 = 0.86;
110
111 static int getLightColor(int x, double ratio) {
112 return (int) ((255 - x) * ratio + x);
113 }
114
115 static Color getLighterColor(Color backColor, double ratio) {
116 int r = getLightColor(backColor.getRed(), ratio);
117 int g = getLightColor(backColor.getGreen(), ratio) + 1;
118 int b = getLightColor(backColor.getBlue(), ratio);
119 if (r >= 255) r = 255;
120 if (g >= 255) g = 255;
121 if (b >= 255) b = 255;
122 return new Color(r, g, b);
123 }
124
125 static Color getSelectedAndFocusedButtonColor(Color backColor) {
126 return getLighterColor(backColor, RATIO1);
127 }
128
129 static Color getFocusedButtonColor(Color backColor) {
130 return getLighterColor(backColor, RATIO2);
131 }
132
133 static Color getSelectedButtonColor(Color backColor) {
134 return getLighterColor(backColor, RATIO3);
135 }
136 }