001: /*
002: * SubstanceNetbeansImageCreator.java
003: *
004: * Created on Aug 11, 2007, 10:07:48 AM
005: *
006: * To change this template, choose Tools | Templates
007: * and open the template in the editor.
008: */
009: package org.jvnet.substance.netbeans;
010:
011: import java.awt.Color;
012: import java.awt.Component;
013: import java.awt.Graphics;
014: import java.awt.Graphics2D;
015: import java.awt.image.BufferedImage;
016: import java.util.HashMap;
017: import java.util.Map;
018: import javax.swing.Icon;
019: import javax.swing.ImageIcon;
020: import javax.swing.SwingConstants;
021: import org.jvnet.substance.SubstanceImageCreator;
022: import org.jvnet.substance.theme.SubstanceTheme;
023: import org.jvnet.substance.utils.MemoryAnalyzer;
024: import org.jvnet.substance.utils.SubstanceColorUtilities;
025: import org.jvnet.substance.utils.SubstanceCoreUtilities;
026: import org.jvnet.substance.utils.SubstanceSizeUtils;
027: import org.netbeans.swing.tabcontrol.plaf.TabControlButton;
028:
029: /**
030: * Image utilities for the module.
031: *
032: * @author Kirill Grouchnikov
033: */
034: public class SubstanceNetbeansImageCreator {
035:
036: /**
037: * Returns <code>pin down</code> icon.
038: *
039: * @param theme
040: * Theme for the icon.
041: * @return <code>Pin down</code> icon.
042: */
043: public static Icon getPinDownIcon(SubstanceTheme theme) {
044: int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
045: BufferedImage image = SubstanceCoreUtilities.getBlankImage(
046: iSize, iSize);
047: Graphics2D graphics = (Graphics2D) image.getGraphics();
048: int start = iSize / 4;
049: int end = (3 * iSize / 4) - 1;
050: int center = (start + end) / 2;
051: Color color = theme.getColorScheme().getForegroundColor();
052: graphics.setColor(color);
053: graphics.drawRect(start, start, end - start, end - start);
054: graphics.fillRect(center, center, 2, 2);
055: return new ImageIcon(SubstanceImageCreator.overlayEcho(image,
056: SubstanceColorUtilities.getColorStrength(color), 1, 1));
057: }
058:
059: /**
060: * Returns <code>pin down</code> icon.
061: *
062: * @param theme
063: * Theme for the icon.
064: * @return <code>Pin down</code> icon.
065: */
066: public static Icon getPinUpIcon(SubstanceTheme theme) {
067: int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
068: BufferedImage image = SubstanceCoreUtilities.getBlankImage(
069: iSize, iSize);
070: Graphics2D graphics = (Graphics2D) image.getGraphics();
071: int start = (iSize / 4) - 1;
072: int end = 3 * iSize / 4;
073: int center = (start + end) / 2;
074: Color color = theme.getColorScheme().getForegroundColor();
075: graphics.setColor(color);
076:
077: graphics.drawLine(start, start, center - 1, start);
078: graphics.drawLine(center + 2, start, end, start);
079: graphics.drawLine(end, start, end, center - 1);
080: graphics.drawLine(end, center + 2, end, end);
081: graphics.drawLine(end, end, center + 2, end);
082: graphics.drawLine(center - 1, end, start, end);
083: graphics.drawLine(start, end, start, center + 2);
084: graphics.drawLine(start, center - 1, start, start);
085: return new ImageIcon(SubstanceImageCreator.overlayEcho(image,
086: SubstanceColorUtilities.getColorStrength(color), 1, 1));
087: }
088:
089: protected static Map<String, Map<Integer, Icon>> iconMap = new HashMap<String, Map<Integer, Icon>>();
090:
091: private static synchronized void computeTabIcons(
092: SubstanceTheme theme) {
093: String themeId = theme.getDisplayName();
094: // MemoryAnalyzer.enqueueUsage("Computing icons for " + themeId);
095: Map<Integer, Icon> themeIcons = iconMap.get(themeId);
096: if (themeIcons == null) {
097: // MemoryAnalyzer.enqueueUsage("Creating map for " + themeId);
098: themeIcons = new HashMap<Integer, Icon>();
099: iconMap.put(themeId, themeIcons);
100: themeIcons.put(TabControlButton.ID_RESTORE_BUTTON,
101: new WrapperIcon(SubstanceImageCreator
102: .getRestoreIcon(theme)));
103: themeIcons
104: .put(
105: TabControlButton.ID_CLOSE_BUTTON,
106: new WrapperIcon(
107: SubstanceImageCreator
108: .getCloseIcon(
109: SubstanceSizeUtils
110: .getTabCloseIconSize(SubstanceSizeUtils
111: .getComponentFontSize(null)),
112: theme)));
113:
114: themeIcons
115: .put(
116: TabControlButton.ID_MAXIMIZE_BUTTON,
117: new WrapperIcon(
118: SubstanceImageCreator
119: .getMaximizeIcon(
120: SubstanceSizeUtils
121: .getTabCloseIconSize(SubstanceSizeUtils
122: .getComponentFontSize(null)),
123: theme)));
124:
125: themeIcons
126: .put(
127: TabControlButton.ID_DROP_DOWN_BUTTON,
128: new WrapperIcon(
129: SubstanceImageCreator
130: .getArrowIcon(
131: SubstanceSizeUtils
132: .getArrowIconWidth(SubstanceSizeUtils
133: .getComponentFontSize(null)),
134: SubstanceSizeUtils
135: .getArrowIconHeight(SubstanceSizeUtils
136: .getComponentFontSize(null)),
137: SubstanceSizeUtils
138: .getArrowStrokeWidth(SubstanceSizeUtils
139: .getComponentFontSize(null)),
140: SwingConstants.SOUTH,
141: theme)));
142:
143: themeIcons
144: .put(
145: TabControlButton.ID_SCROLL_LEFT_BUTTON,
146: new WrapperIcon(
147: SubstanceImageCreator
148: .getArrowIcon(
149: SubstanceSizeUtils
150: .getArrowIconWidth(SubstanceSizeUtils
151: .getComponentFontSize(null)),
152: SubstanceSizeUtils
153: .getArrowIconHeight(SubstanceSizeUtils
154: .getComponentFontSize(null)),
155: SubstanceSizeUtils
156: .getArrowStrokeWidth(SubstanceSizeUtils
157: .getComponentFontSize(null)),
158: SwingConstants.WEST,
159: theme)));
160:
161: themeIcons
162: .put(
163: TabControlButton.ID_SCROLL_RIGHT_BUTTON,
164: new WrapperIcon(
165: SubstanceImageCreator
166: .getArrowIcon(
167: SubstanceSizeUtils
168: .getArrowIconWidth(SubstanceSizeUtils
169: .getComponentFontSize(null)),
170: SubstanceSizeUtils
171: .getArrowIconHeight(SubstanceSizeUtils
172: .getComponentFontSize(null)),
173: SubstanceSizeUtils
174: .getArrowStrokeWidth(SubstanceSizeUtils
175: .getComponentFontSize(null)),
176: SwingConstants.EAST,
177: theme)));
178:
179: // themeIcons.put(TabControlButton.ID_PIN_BUTTON,
180: // new WrapperIcon(SubstanceNetbeansImageCreator.getPinDownIcon(theme)));
181: // themeIcons.put(TabControlButton.ID_SLIDE_DOWN_BUTTON,
182: // new WrapperIcon(SubstanceNetbeansImageCreator.getPinUpIcon(theme)));
183: // themeIcons.put(TabControlButton.ID_SLIDE_LEFT_BUTTON,
184: // new WrapperIcon(SubstanceNetbeansImageCreator.getPinUpIcon(theme)));
185: // themeIcons.put(TabControlButton.ID_SLIDE_RIGHT_BUTTON,
186: // new WrapperIcon(SubstanceNetbeansImageCreator.getPinUpIcon(theme)));
187: }
188: }
189:
190: public static Icon getTabIcon(SubstanceTheme theme, int buttonId) {
191: computeTabIcons(theme);
192: return iconMap.get(theme.getDisplayName()).get(buttonId);
193: }
194:
195: private static class WrapperIcon implements Icon {
196:
197: private Icon delegate;
198: private int dx;
199: private int dy;
200: private static final int sizeW = 8;
201: private static final int sizeH = 8;
202:
203: public WrapperIcon(Icon delegate) {
204: this .delegate = delegate;
205: this .dx = (sizeW - this .delegate.getIconWidth()) / 2;
206: this .dy = (sizeH - this .delegate.getIconHeight()) / 2;
207: }
208:
209: public int getIconHeight() {
210: return sizeH;
211: }
212:
213: public int getIconWidth() {
214: return sizeW;
215: }
216:
217: public void paintIcon(Component c, Graphics g, int x, int y) {
218: this.delegate.paintIcon(c, g, x + this.dx, y + this.dy);
219: }
220: }
221: }
|