Debian Codegraph @

src/com/jidesoft/plaf/vsnet/VsnetUtils.java

raw
1 /*
2 * @(#)VsnetUtils.java
3 *
4 * Copyright 2002-2003 JIDE Software. All rights reserved.
5 */
6 package com.jidesoft.plaf.vsnet;
7
8 import com.jidesoft.utils.ColorUtils;
9
10 import javax.swing.plaf.ColorUIResource;
11 import java.awt.*;
12
13 /**
14 */
15 class VsnetUtils {
16
17 static Color getLighterColor(Color color) {
18 if (Color.BLACK.equals(color)) {
19 return color;
20 }
21 else if (Color.WHITE.equals(color)) {
22 return color;
23 }
24 return ColorUtils.getDerivedColor(color, 0.93f);
25 }
26
27 static final Color DARK_GREEN = new Color(0, 128, 0);
28 static final Color DARK_MAGENTA = new Color(128, 0, 128);
29
30 static Color getMenuSelectionColor(Color color) {
31 if (DARK_GREEN.equals(color) || DARK_MAGENTA.equals(color)) {
32 return color;
33 }
34 return ColorUtils.getDerivedColor(color, 0.8555f);
35 }
36
37 static Color getMenuBackgroundColor(Color color) {
38 return getLighterColor(color);
39 }
40
41 static Color getToolBarBackgroundColor(Color color) {
42 if (Color.BLACK.equals(color)) {
43 return color;
44 }
45 else if (Color.WHITE.equals(color)) {
46 return color;
47 }
48 return ColorUtils.getDerivedColor(color, 0.645f);
49 }
50
51 static Color getGripperForegroundColor(Color color) {
52 int r = getGripperValue(color.getRed());
53 int g = getGripperValue(color.getGreen());
54 int b = getGripperValue(color.getBlue());
55 if (r >= 255) r = 255;
56 if (g >= 255) g = 255;
57 if (b >= 255) b = 255;
58 return new ColorUIResource(r, g, b);
59 }
60
61 static int getGripperValue(int x) {
62 if (x == 255) {
63 return 0;
64 }
65 else if (x >= 0 && x <= 64) {
66 return x * 33 / 64 + 123;
67 }
68 else {
69 return (x - 65) * 157 / 189 + 33;
70 }
71 }
72
73 static Color getDefaultBackgroundColor(Color color) {
74 Color backIDE;
75
76 // Check for the 'Classic' control color
77 if ((color.getRed() == 212) && (color.getGreen() == 208) && (color.getBlue() == 200)) {
78 // Use the exact background for this color
79 backIDE = new ColorUIResource(247, 243, 233);
80 }
81 else if ((color.getRed() == 236) && (color.getGreen() == 233) && (color.getBlue() == 216)) {
82 // Check for the 'XP' control color
83 // Use the exact background for this color
84 backIDE = new ColorUIResource(255, 251, 233);
85 }
86 else {
87 // Calculate the IDE background color as only half as dark as the control color
88 int r = color.getRed() + 35;
89 int g = color.getGreen() + 35;
90 int b = color.getBlue() + 35;
91 if (r >= 255) r = 255;
92 if (g >= 255) g = 255;
93 if (b >= 255) b = 255;
94 backIDE = new ColorUIResource(r, g, b);
95 }
96
97 return backIDE;
98 }
99
100 private static double RATIO1 = 0.80;
101 private static double RATIO2 = 0.92f;
102 private static double RATIO3 = 0.86f;
103
104 /**
105 * Adjusts the ratio we used to derive different colors from a base color.
106 *
107 * @param selectedAndFocused the ratio for selected and rollover color. Default is 0.755f.
108 * @param rollover the ratio for rollover color. Default is 0.78f.
109 * @param selected the ratio for selected color. Default is 0.86f.
110 */
111 public static void setColorRatios(double selectedAndFocused, double rollover, double selected) {
112 RATIO1 = selectedAndFocused;
113 RATIO2 = rollover;
114 RATIO3 = selected;
115 }
116
117 static int getLightColor(int x, double ratio) {
118 return (int) ((255 - x) * ratio + x);
119 }
120
121 static Color getLighterColor(Color color, float ratio) {
122 if (DARK_GREEN.equals(color) || DARK_MAGENTA.equals(color)) {
123 return color;
124 }
125 return ColorUtils.getDerivedColor(color, ratio);
126 }
127
128 static Color getSelectedAndRolloverButtonColor(Color color) {
129 return getLighterColor(color, (float) RATIO1);
130 }
131
132 static Color getRolloverButtonColor(Color color) {
133 return getLighterColor(color, (float) RATIO2);
134 }
135
136 static Color getSelectedButtonColor(Color color) {
137 return getLighterColor(color, (float) RATIO3);
138 }
139
140 static Color getButtonBorderColor(Color color) {
141 if (DARK_GREEN.equals(color) || DARK_MAGENTA.equals(color)) {
142 return new ColorUIResource(Color.WHITE);
143 }
144 return color;
145 }
146 }