001: /*
002: * @(#)XertoPainter.java 3/22/2005
003: *
004: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.plaf.xerto;
007:
008: import com.jidesoft.icons.IconsFactory;
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 Xerto 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 XertoPainter extends BasicPainter {
023:
024: private static XertoPainter _instance;
025: private final static ImageIcon SELECTED = IconsFactory
026: .getImageIcon(XertoPainter.class, "icons/selected.gif");
027: private final static ImageIcon SELECTED_C = IconsFactory
028: .getImageIcon(XertoPainter.class, "icons/selected_c.gif");
029: private final static ImageIcon ROLLOVER = IconsFactory
030: .getImageIcon(XertoPainter.class, "icons/rollover.gif");
031: private final static ImageIcon ROLLOVER_C = IconsFactory
032: .getImageIcon(XertoPainter.class, "icons/rollover_c.gif");
033: private final static ImageIcon PRESSED = IconsFactory.getImageIcon(
034: XertoPainter.class, "icons/pressed.gif");
035: private final static ImageIcon PRESSED_C = IconsFactory
036: .getImageIcon(XertoPainter.class, "icons/pressed_c.gif");
037:
038: public static ThemePainter getInstance() {
039: if (_instance == null) {
040: _instance = new XertoPainter();
041: }
042: return _instance;
043: }
044:
045: protected XertoPainter() {
046: }
047:
048: // public void paintContentBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
049: // JideSwingUtilities.fillGradient((Graphics2D) g, rect,
050: // XertoUtils.getMidControlColor(), XertoUtils.getControlColor(), false);
051: // }
052: //
053:
054: @Override
055: public void paintCollapsiblePaneTitlePaneBackground(JComponent c,
056: Graphics g, Rectangle rect, int orientation, int state) {
057: Graphics2D g2d = (Graphics2D) g;
058: Color gradientBot = c.getBackground();
059: Color gradientTop = XertoUtils.getHeighlightColor(gradientBot);
060: JideSwingUtilities.fillGradient(g2d, rect, gradientTop,
061: gradientBot, true);
062: }
063:
064: @Override
065: public void paintCollapsiblePaneTitlePaneBackgroundEmphasized(
066: JComponent c, Graphics g, Rectangle rect, int orientation,
067: int state) {
068: Graphics2D g2d = (Graphics2D) g;
069: Color gradientBot = XertoUtils
070: .getEmBaseColor(c.getBackground());
071: Color gradientTop = c.getBackground();
072: JideSwingUtilities.fillGradient(g2d, rect, gradientTop,
073: gradientBot, true);
074: }
075:
076: @Override
077: public void paintMenuItemBackground(JComponent c, Graphics g,
078: Rectangle rect, int orientation, int state,
079: boolean showBorder) {
080: super .paintMenuItemBackground(c, g, rect, orientation, state,
081: showBorder);
082: }
083:
084: @Override
085: public void paintButtonBackground(JComponent c, Graphics g,
086: Rectangle rect, int orientation, int state) {
087: if (state == STATE_DEFAULT) {
088: super .paintButtonBackground(c, g, rect, orientation, state);
089: } else if (state == STATE_ROLLOVER) {
090: paintImageBorder(g, rect, ROLLOVER, ROLLOVER_C, null);
091: } else if (state == STATE_SELECTED) {
092: paintImageBorder(g, rect, SELECTED, SELECTED_C, Color.WHITE);
093: } else if (state == STATE_PRESSED) {
094: paintImageBorder(g, rect, PRESSED, PRESSED_C, null);
095: }
096: }
097:
098: private void paintImageBorder(Graphics g, Rectangle rect,
099: ImageIcon icon, ImageIcon center, Color background) {
100: JideSwingUtilities.drawImageBorder(g, icon, rect, new Insets(4,
101: 4, 4, 4), false);
102:
103: if (center == null) {
104: Color oldColor = g.getColor();
105: g.setColor(background);
106: g.fillRect(rect.x + 4, rect.y + 4, rect.width - 8,
107: rect.height - 8);
108: g.setColor(oldColor);
109: } else {
110: g.drawImage(center.getImage(), rect.x + 4, rect.y + 4,
111: rect.x + rect.width - 4, rect.y + rect.height - 4,
112: 0, 0, center.getIconWidth(),
113: center.getIconHeight(), background, null);
114: }
115: }
116:
117: @Override
118: public void paintGripper(JComponent c, Graphics g, Rectangle rect,
119: int orientation, int state) {
120: if (rect.width > 30) {
121: orientation = SwingConstants.VERTICAL;
122: }
123:
124: int h = (orientation == SwingConstants.HORIZONTAL) ? rect.height
125: : rect.width;
126: int count = Math.min(9, (h - 6) / 4);
127: int y = rect.y;
128: int x = rect.x;
129:
130: if (orientation == SwingConstants.HORIZONTAL) {
131: y += rect.height / 2 - count * 2;
132: x += rect.width / 2 - 1;
133: } else {
134: x += rect.width / 2 - count * 2;
135: y += rect.height / 2 - 1;
136: }
137:
138: for (int i = 0; i < count; i++) {
139: g.setColor(getGripperForegroundLt());
140: g.fillRect(x + 1, y + 1, 2, 2);
141: g.setColor(XertoUtils.getControlMidShadowColor());
142: g.fillRect(x, y, 2, 2);
143: g.setColor(XertoUtils.getControlLightShadowColor());
144: g.fillRect(x, y, 1, 1);
145: g.setColor(XertoUtils.getControlDarkShadowColor());
146: g.fillRect(x + 1, y + 1, 1, 1);
147:
148: if (orientation == SwingConstants.HORIZONTAL) {
149: y += 4;
150: } else {
151: x += 4;
152: }
153: }
154: }
155:
156: @Override
157: public void paintDockableFrameTitlePane(JComponent c, Graphics g,
158: Rectangle rect, int orientation, int state) {
159: Graphics2D g2d = (Graphics2D) g;
160: if (ThemePainter.STATE_SELECTED == state) {
161: JideSwingUtilities.fillGradient(g2d, new Rectangle(rect.x,
162: rect.y, rect.width, rect.height), XertoUtils
163: .getFrameActiveTitleTopColor(), XertoUtils
164: .getFrameActiveTitleBottomColor(),
165: orientation == SwingConstants.HORIZONTAL);
166: } else {
167: JideSwingUtilities.fillGradient(g2d, new Rectangle(rect.x,
168: rect.y, rect.width, rect.height), XertoUtils
169: .getFrameInactiveTitleTopColor(), XertoUtils
170: .getFrameInactiveTitleBottomColor(),
171: orientation == SwingConstants.HORIZONTAL);
172: }
173: }
174:
175: @Override
176: public Color getGripperForeground() {
177: return XertoUtils.getControlLightShadowColor();
178: }
179:
180: @Override
181: public Color getGripperForegroundLt() {
182: return Color.WHITE;
183: }
184:
185: @Override
186: public Color getSelectionSelectedDk() {
187: return XertoUtils.getControlMidShadowColor();
188: }
189:
190: @Override
191: public Color getSelectionSelectedLt() {
192: return XertoUtils.getControlLightShadowColor();
193: }
194:
195: }
|