001: /*
002: * @(#)VsnetUtils.java
003: *
004: * Copyright 2002-2003 JIDE Software. All rights reserved.
005: */
006: package com.jidesoft.plaf.vsnet;
007:
008: import com.jidesoft.utils.ColorUtils;
009:
010: import javax.swing.plaf.ColorUIResource;
011: import java.awt.*;
012:
013: /**
014: */
015: class VsnetUtils {
016:
017: static Color getLighterColor(Color color) {
018: if (Color.BLACK.equals(color)) {
019: return color;
020: } else if (Color.WHITE.equals(color)) {
021: return color;
022: }
023: return ColorUtils.getDerivedColor(color, 0.93f);
024: }
025:
026: final static Color DARK_GREEN = new Color(0, 128, 0);
027: final static Color DARK_MAGENTA = new Color(128, 0, 128);
028:
029: static Color getMenuSelectionColor(Color color) {
030: if (DARK_GREEN.equals(color) || DARK_MAGENTA.equals(color)) {
031: return color;
032: }
033: return ColorUtils.getDerivedColor(color, 0.8555f);
034: }
035:
036: static Color getMenuBackgroundColor(Color color) {
037: return getLighterColor(color);
038: }
039:
040: static Color getToolBarBackgroundColor(Color color) {
041: if (Color.BLACK.equals(color)) {
042: return color;
043: } else if (Color.WHITE.equals(color)) {
044: return color;
045: }
046: return ColorUtils.getDerivedColor(color, 0.645f);
047: }
048:
049: static Color getGripperForegroundColor(Color color) {
050: int r = getGripperValue(color.getRed());
051: int g = getGripperValue(color.getGreen());
052: int b = getGripperValue(color.getBlue());
053: if (r >= 255)
054: r = 255;
055: if (g >= 255)
056: g = 255;
057: if (b >= 255)
058: b = 255;
059: return new Color(r, g, b);
060: }
061:
062: static int getGripperValue(int x) {
063: if (x == 255) {
064: return 0;
065: } else if (x >= 0 && x <= 64) {
066: return (int) (x * 33 / 64 + 123);
067: } else {
068: return (int) ((x - 65) * 157 / 189 + 33);
069: }
070: }
071:
072: static Color getDefaultBackgroundColor(Color color) {
073: Color backIDE;
074:
075: // Check for the 'Classic' control color
076: if ((color.getRed() == 212) && (color.getGreen() == 208)
077: && (color.getBlue() == 200)) {
078: // Use the exact background for this color
079: backIDE = new Color(247, 243, 233);
080: } else if ((color.getRed() == 236) && (color.getGreen() == 233)
081: && (color.getBlue() == 216)) {
082: // Check for the 'XP' control color
083: // Use the exact background for this color
084: backIDE = new Color(255, 251, 233);
085: } else {
086: // Calculate the IDE background color as only half as dark as the control color
087: int r = color.getRed() + 35;
088: int g = color.getGreen() + 35;
089: int b = color.getBlue() + 35;
090: if (r >= 255)
091: r = 255;
092: if (g >= 255)
093: g = 255;
094: if (b >= 255)
095: b = 255;
096: backIDE = new Color(r, g, b);
097: }
098:
099: return backIDE;
100: }
101:
102: private static double RATIO1 = 0.755; // 0.502;
103: private static double RATIO2 = 0.78f; // 0.78;
104: private static double RATIO3 = 0.86f; //0.86;
105:
106: /**
107: * Adjusts the ratio we used to derive different colors from a base color.
108: *
109: * @param selectedAndFocused the ratio for selected and rollover color. Default is 0.755f.
110: * @param rollover the ratio for rollover color. Default is 0.78f.
111: * @param selected the ratio for selected color. Default is 0.86f.
112: */
113: public static void setColorRatios(double selectedAndFocused,
114: double rollover, double selected) {
115: RATIO1 = selectedAndFocused;
116: RATIO2 = rollover;
117: RATIO3 = selected;
118: }
119:
120: static int getLightColor(int x, double ratio) {
121: return (int) ((255 - x) * ratio + x);
122: }
123:
124: static Color getLighterColor(Color color, float ratio) {
125: if (DARK_GREEN.equals(color) || DARK_MAGENTA.equals(color)) {
126: return color;
127: }
128: return ColorUtils.getDerivedColor(color, ratio);
129: }
130:
131: static Color getSelectedAndRolloverButtonColor(Color color) {
132: return getLighterColor(color, (float) RATIO1);
133: }
134:
135: static Color getRolloverButtonColor(Color color) {
136: return getLighterColor(color, (float) RATIO2);
137: }
138:
139: static Color getSelectedButtonColor(Color color) {
140: return getLighterColor(color, (float) RATIO3);
141: }
142:
143: static Color getButtonBorderColor(Color color) {
144: if (DARK_GREEN.equals(color) || DARK_MAGENTA.equals(color)) {
145: return new ColorUIResource(Color.WHITE);
146: }
147: return color;
148: }
149: }
|