001: /*
002: * @(#)$fileName
003: *
004: * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.plaf.eclipse;
007:
008: import com.jidesoft.plaf.UIDefaultsLookup;
009: import com.jidesoft.plaf.basic.BasicPainter;
010: import com.jidesoft.plaf.basic.ThemePainter;
011: import com.jidesoft.swing.JideSwingUtilities;
012:
013: import javax.swing.*;
014: import java.awt.*;
015:
016: /**
017: * Painter for Eclipse L&F.
018: * <p/>
019: * Please note, this class is an internal class which is meant to be used by other JIDE classes only.
020: * Future version might break your build if you use it.
021: */
022: public class EclipsePainter extends BasicPainter {
023:
024: private static EclipsePainter _instance;
025:
026: public static ThemePainter getInstance() {
027: if (_instance == null) {
028: _instance = new EclipsePainter();
029: }
030: return _instance;
031: }
032:
033: protected Color _shadowColor;
034: protected Color _darkShadowColor;
035: protected Color _highlight;
036: protected Color _lightHighlightColor;
037:
038: protected EclipsePainter() {
039: _shadowColor = UIDefaultsLookup.getColor("controlShadow");
040: _darkShadowColor = UIDefaultsLookup.getColor("controlDkShadow");
041: _highlight = UIDefaultsLookup.getColor("controlHighlight");
042: _lightHighlightColor = UIDefaultsLookup
043: .getColor("controlLtHighlight");
044: }
045:
046: @Override
047: public void paintButtonBackground(JComponent c, Graphics g,
048: Rectangle rect, int orientation, int state) {
049: Color oldColor = g.getColor();
050: if (state == STATE_DEFAULT) {
051: } else if (state == STATE_ROLLOVER) {
052: if (orientation == HORIZONTAL) {
053: g.setColor(_lightHighlightColor); // inner 3D border
054: g.drawLine(rect.x, rect.y, rect.x + rect.width - 1,
055: rect.y);
056: g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height
057: - 1);
058:
059: g.setColor(_shadowColor); // black drop shadow __|
060: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
061: + rect.width - 1, rect.y + rect.height - 1);
062: g.drawLine(rect.x + rect.width - 1, rect.y, rect.x
063: + rect.width - 1, rect.x + rect.height - 1);
064: } else {
065: g.setColor(_lightHighlightColor); // black drop shadow __|
066: g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height
067: - 1);
068: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
069: + rect.width - 1, rect.y + rect.height - 1);
070:
071: g.setColor(_shadowColor); // inner 3D border
072: g.drawLine(rect.x, rect.y, rect.x + rect.width - 1,
073: rect.y);
074: g.drawLine(rect.x + rect.width - 1, rect.y, rect.x
075: + rect.width - 1, rect.x + rect.height - 1);
076: }
077: } else if (state == STATE_SELECTED) {
078: EclipseUtils
079: .fillRectWithHatch((Graphics2D) g, new Rectangle(2,
080: 2, rect.width - 4, rect.height - 4),
081: UIDefaultsLookup
082: .getColor("JideButton.background"));
083:
084: if (orientation == HORIZONTAL) {
085: g.setColor(_shadowColor); // inner 3D border
086: g.drawLine(rect.x, rect.y, rect.x + rect.width - 1,
087: rect.y);
088: g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height
089: - 1);
090:
091: g.setColor(_lightHighlightColor); // black drop shadow __|
092: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
093: + rect.width - 1, rect.y + rect.height - 1);
094: g.drawLine(rect.x + rect.width - 1, rect.y, rect.x
095: + rect.width - 1, rect.y + rect.height - 1);
096: } else {
097: g.setColor(_shadowColor); // inner 3D border
098: g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height
099: - 1);
100: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
101: + rect.width - 1, rect.y + rect.height - 1);
102:
103: g.setColor(_lightHighlightColor); // black drop shadow __|
104: g.drawLine(rect.x, rect.y, rect.x + rect.width - 1,
105: rect.y);
106: g.drawLine(rect.x + rect.width - 1, rect.y, rect.x
107: + rect.width - 1, rect.y + rect.height - 1);
108:
109: }
110: } else if (state == STATE_PRESSED) {
111: g.setColor(_shadowColor); // inner 3D border
112: g.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
113: g
114: .drawLine(rect.x, rect.y, rect.x, rect.y
115: + rect.height - 1);
116:
117: g.setColor(_lightHighlightColor); // black drop shadow __|
118: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
119: + rect.width - 1, rect.y + rect.height - 1);
120: g.drawLine(rect.x + rect.width - 1, rect.y, rect.x
121: + rect.width - 1, rect.y + rect.height - 1);
122: }
123: g.setColor(oldColor);
124: }
125:
126: @Override
127: public void paintSelectedMenu(JComponent c, Graphics g,
128: Rectangle rect, int orientation, int state) {
129: }
130:
131: @Override
132: public void paintGripper(JComponent c, Graphics g, Rectangle rect,
133: int orientation, int state) {
134: int h = (orientation == SwingConstants.HORIZONTAL) ? rect.height
135: : rect.width;
136: h -= 4;
137:
138: int y = rect.y + 2;
139: int x = rect.x + 2;
140:
141: Color oldColor = g.getColor();
142: if (orientation == SwingConstants.HORIZONTAL) {
143: g.setColor(_lightHighlightColor);
144: g.drawLine(x, y, x, y + h);
145: g.drawLine(x, y, x + 2, y);
146: g.setColor(_shadowColor);
147: g.drawLine(x + 2, y, x + 2, y + h);
148: g.drawLine(x, y + h, x + 2, y + h);
149: g.setColor(UIDefaultsLookup
150: .getColor("JideButton.background")); // was "control"
151: g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
152: } else {
153: g.setColor(_lightHighlightColor);
154: g.drawLine(x, y, x + h, y);
155: g.drawLine(x, y, x, y + 2);
156: g.setColor(_shadowColor);
157: g.drawLine(x, y + 2, x + h, y + 2);
158: g.drawLine(x + h, y, x + h, y + 2);
159: g.setColor(UIDefaultsLookup
160: .getColor("JideButton.background")); // was "control"
161: g.drawLine(x + 1, y + 1, x + h - 1, y + 1);
162: }
163: g.setColor(oldColor);
164: }
165:
166: @Override
167: public void paintDockableFrameTitlePane(JComponent c, Graphics g,
168: Rectangle rect, int orientation, int state) {
169: int x = rect.x;
170: int y = rect.y;
171: int w = c.getWidth();
172: int h = rect.height;
173: if (c.getBorder() != null) {
174: Insets insets = c.getBorder().getBorderInsets(c);
175: x += insets.left;
176: y += insets.top;
177: w -= insets.right + insets.left;
178: h -= insets.top + insets.bottom;
179: }
180:
181: g.setColor(Color.white);
182: g.drawLine(x, y, x + w, y);
183: g.drawLine(x, y, x, y + h - 1);
184:
185: g.setColor(Color.gray);
186: g.drawLine(x, y + h - 1, x + w, y + h - 1);
187:
188: if (state == STATE_SELECTED) {
189: int width = rect.width;
190: Graphics2D g2d = (Graphics2D) g;
191: JideSwingUtilities
192: .fillGradient(
193: g2d,
194: new Rectangle(x + 1, y + 1, width / 2,
195: h - 2),
196: UIDefaultsLookup
197: .getColor("DockableFrame.activeTitleBackground"),
198: UIDefaultsLookup
199: .getColor("DockableFrame.activeTitleBackground2"),
200: false);
201: JideSwingUtilities
202: .fillGradient(
203: g2d,
204: new Rectangle(x + 1 + width / 2, y + 1,
205: width / 2, h - 2),
206: UIDefaultsLookup
207: .getColor("DockableFrame.activeTitleBackground2"),
208: UIDefaultsLookup
209: .getColor("DockableFrame.background"),
210: false);
211: }
212: // else if (state == STATE_DEFAULT) {
213: // int width = rect.width;
214: // Graphics2D g2d = (Graphics2D) g;
215: // JideSwingUtilities.fillGradient(g2d, new Rectangle(x + 1, y + 1, width, h - 2), UIManagerLookup.getColor("DockableFrame.inactiveTitleBackground"), UIManagerLookup.getColor("DockableFrame.background"), false);
216: // }
217: }
218: }
|