001: /*
002: * @(#)VsnetUtils.java
003: *
004: * Copyright 2002-2003 JIDE Software. All rights reserved.
005: */
006: package com.jidesoft.plaf.eclipse;
007:
008: import java.awt.*;
009:
010: /**
011: */
012: public class EclipseUtils {
013:
014: static Color getLighterColor(Color backColor) {
015: int r = getLighterColor(backColor.getRed());
016: int g = getLighterColor(backColor.getGreen());
017: int b = getLighterColor(backColor.getBlue());
018: if (r >= 255)
019: r = 255;
020: if (g >= 255)
021: g = 255;
022: if (b >= 255)
023: b = 255;
024: return new Color(r, g, b);
025: }
026:
027: static int getLighterColor(int x) {
028: return (int) (x * 36.0 / 255.0 + 219.5);
029: }
030:
031: static Color getMenuSelectionColor(Color backColor) {
032: int r = getMenuSelectionValue(backColor.getRed());
033: int g = getMenuSelectionValue(backColor.getGreen());
034: int b = getMenuSelectionValue(backColor.getBlue());
035: if (r >= 255)
036: r = 255;
037: if (g >= 255)
038: g = 255;
039: if (b >= 255)
040: b = 255;
041: return new Color(r, g, b);
042: }
043:
044: static int getMenuSelectionValue(int x) {
045: return (int) (x * 76.0 / 255.0 + 179.5);
046: }
047:
048: static Color getMenuBackgroundColor(Color backColor) {
049: int r = getMenuValue(backColor.getRed());
050: int g = getMenuValue(backColor.getGreen());
051: int b = getMenuValue(backColor.getBlue());
052: if (r >= 255)
053: r = 255;
054: if (g >= 255)
055: g = 255;
056: if (b >= 255)
057: b = 255;
058: return new Color(r, g, b);
059: }
060:
061: static int getMenuValue(int x) {
062: return (int) (x * 36.0 / 255.0 + 219.5);
063: }
064:
065: static Color getDefaultBackgroundColor(Color backColor) {
066: Color backIDE;
067:
068: // Check for the 'Classic' control color
069: if ((backColor.getRed() == 212)
070: && (backColor.getGreen() == 208)
071: && (backColor.getBlue() == 200)) {
072: // Use the exact background for this color
073: backIDE = new Color(247, 243, 233);
074: } else if ((backColor.getRed() == 236)
075: && (backColor.getGreen() == 233)
076: && (backColor.getBlue() == 216)) {
077: // Check for the 'XP' control color
078: // Use the exact background for this color
079: backIDE = new Color(255, 251, 233);
080: } else {
081: // Calculate the IDE background color as only half as dark as the control color
082: int r = backColor.getRed() + 35;
083: int g = backColor.getGreen() + 35;
084: int b = backColor.getBlue() + 35;
085: if (r >= 255)
086: r = 255;
087: if (g >= 255)
088: g = 255;
089: if (b >= 255)
090: b = 255;
091: backIDE = new Color(r, g, b);
092: }
093:
094: return backIDE;
095: }
096:
097: private static final BasicStroke DOTTED_STROKE = new BasicStroke(
098: 1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f,
099: new float[] { 0, 2, 0, 2 }, 0);
100:
101: public static void fillRectWithHatch(Graphics2D g, Rectangle rect,
102: Color color) {
103: Stroke oldStroke = g.getStroke();
104:
105: g.setColor(Color.white);
106: g.fillRect(rect.x, rect.y, rect.width, rect.height);
107:
108: g.setColor(color);
109: g.setStroke(DOTTED_STROKE);
110:
111: for (int i = 0; i < rect.width; i++) {
112: if (i % 2 == 0) {
113: g.drawLine(rect.x + i, rect.y, rect.x + i, rect.y
114: + rect.height - 1);
115: } else {
116: g.drawLine(rect.x + i, rect.y + 1, rect.x + i, rect.y
117: + rect.height - 1);
118: }
119: }
120: g.setStroke(oldStroke);
121: }
122:
123: final static double RATIO1 = 0.67;
124: final static double RATIO2 = 0.78;
125: final static double RATIO3 = 0.86;
126:
127: static int getLightColor(int x, double ratio) {
128: return (int) ((255 - x) * ratio + x);
129: }
130:
131: static Color getLighterColor(Color backColor, double ratio) {
132: int r = getLightColor(backColor.getRed(), ratio);
133: int g = getLightColor(backColor.getGreen(), ratio) + 1;
134: int b = getLightColor(backColor.getBlue(), ratio);
135: if (r >= 255)
136: r = 255;
137: if (g >= 255)
138: g = 255;
139: if (b >= 255)
140: b = 255;
141: return new Color(r, g, b);
142: }
143:
144: static Color getSelectedAndFocusedButtonColor(Color backColor) {
145: return getLighterColor(backColor, RATIO1);
146: }
147:
148: static Color getFocusedButtonColor(Color backColor) {
149: return getLighterColor(backColor, RATIO2);
150: }
151:
152: static Color getSelectedButtonColor(Color backColor) {
153: return getLighterColor(backColor, RATIO3);
154: }
155: }
|