001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.plugin;
031:
032: import java.awt.*;
033: import java.awt.image.BufferedImage;
034: import java.util.*;
035: import java.util.List;
036:
037: import javax.swing.*;
038: import javax.swing.plaf.*;
039:
040: import org.jvnet.lafplugin.LafComponentPlugin;
041: import org.jvnet.substance.SubstanceImageCreator;
042: import org.jvnet.substance.SubstanceLookAndFeel;
043: import org.jvnet.substance.color.ColorScheme;
044: import org.jvnet.substance.fonts.FontSet;
045: import org.jvnet.substance.theme.SubstanceTheme;
046: import org.jvnet.substance.utils.*;
047: import org.jvnet.substance.utils.icon.SubstanceIconFactory;
048:
049: import contrib.ch.randelshofer.quaqua.ButtonStateIcon;
050: import contrib.ch.randelshofer.quaqua.util.Images;
051:
052: /**
053: * Core plugin for additional UI delegates. Contains information on Quaqua and
054: * Xoetrope color chooser panels. This class is <b>for internal use only</b>.
055: *
056: * @author Kirill Grouchnikov
057: */
058: public class BasePlugin implements LafComponentPlugin {
059:
060: /**
061: * Common directory for Quaqua images.
062: */
063: protected final static String commonDir = "/contrib/ch/randelshofer/quaqua/images/";
064:
065: /**
066: * Color chooser class name from Quaqua.
067: */
068: protected final static String quaquaColorChooserClassName = "contrib.ch.randelshofer.quaqua.Quaqua14ColorChooserUI";
069:
070: /**
071: * Indication whether the Quaqua color chooser is available. The lite
072: * version strips away the Quaqua color chooser.
073: */
074: protected boolean hasQuaquaColorChooser;
075:
076: /**
077: * Creates the base plugin.
078: */
079: public BasePlugin() {
080: try {
081: Class.forName(quaquaColorChooserClassName);
082: this .hasQuaquaColorChooser = true;
083: } catch (ClassNotFoundException cnfe) {
084: this .hasQuaquaColorChooser = false;
085: }
086: }
087:
088: /**
089: * From Quaqua
090: */
091: protected Icon createButtonStateIcon(final String location,
092: final int states) {
093: BufferedImage[] images = Images.split(Toolkit
094: .getDefaultToolkit().getImage(
095: this .getClass().getResource(location)), states,
096: true);
097:
098: return new ButtonStateIcon(images);
099: }
100:
101: /**
102: * From Quaqua
103: */
104: protected Object makeImage(String location) {
105: return new UIDefaults.ProxyLazyValue(
106: "contrib.ch.randelshofer.quaqua.QuaquaIconFactory",
107: "createImage", new Object[] { location });
108: }
109:
110: protected static Object makeButtonStateIcon(String location,
111: int states) {
112: return new UIDefaults.ProxyLazyValue(
113: "contrib.ch.randelshofer.quaqua.QuaquaIconFactory",
114: "createButtonStateIcon", new Object[] { location,
115: new Integer(states) });
116: }
117:
118: protected Object makeBufferedImage(String location) {
119: return new UIDefaults.ProxyLazyValue(
120: "contrib.ch.randelshofer.quaqua.QuaquaIconFactory",
121: "createBufferedImage", new Object[] { location });
122: }
123:
124: public static Object makeIcon(Class baseClass, String location) {
125: return new UIDefaults.ProxyLazyValue(
126: "contrib.ch.randelshofer.quaqua.QuaquaIconFactory",
127: "createIcon", new Object[] { baseClass, location });
128: }
129:
130: /*
131: * (non-Javadoc)
132: *
133: * @see org.jvnet.lafplugin.LafComponentPlugin#getDefaults(java.lang.Object)
134: */
135: public Object[] getDefaults(Object mTheme) {
136: ResourceBundle bundle = ResourceBundle
137: .getBundle("contrib.ch.randelshofer.quaqua.Labels");
138: List labelsList = new LinkedList();
139: for (Enumeration i = bundle.getKeys(); i.hasMoreElements();) {
140: String key = (String) i.nextElement();
141: labelsList.add(key);
142: labelsList.add(bundle.getObject(key));
143: }
144: if (this .hasQuaquaColorChooser) {
145: SubstanceTheme theme = (SubstanceTheme) mTheme;
146: InsetsUIResource visualMargin = new InsetsUIResource(0, 0,
147: 0, 0);
148: ColorScheme colorScheme = theme.getColorScheme();
149: Color foregroundColor = new ColorUIResource(colorScheme
150: .getForegroundColor());
151: Object[] mainDefaults = new Object[] {
152: // quaqua
153: "Slider.upThumbSmall",
154: new UIDefaults.LazyValue() {
155: public Object createValue(UIDefaults table) {
156: return SubstanceIconFactory
157: .getSliderHorizontalIcon(
158: SubstanceSizeUtils
159: .getSliderIconSize(SubstanceSizeUtils
160: .getControlFontSize()) - 2,
161: true);
162: }
163: },
164:
165: // quaqua
166: "Slider.leftThumbSmall",
167: new UIDefaults.LazyValue() {
168: public Object createValue(UIDefaults table) {
169: return SubstanceIconFactory
170: .getSliderVerticalIcon(
171: SubstanceSizeUtils
172: .getSliderIconSize(SubstanceSizeUtils
173: .getControlFontSize()) - 2,
174: true);
175: }
176: },
177:
178: // quaqua
179: "Component.visualMargin",
180: visualMargin,
181:
182: // quaqua
183: // "ColorChooser.swatchesSwatchSize",
184: // new DimensionUIResource(5, 5),
185: //
186: // // quaqua
187: // "ColorChooser.resetMnemonic",
188: // new Integer(-1),
189: //
190: // // class names of default choosers for quaqua
191: // "ColorChooser.defaultChoosers",
192: // new String[] {
193: // "contrib.ch.randelshofer.quaqua.colorchooser.ColorWheelChooser",
194: // "contrib.ch.randelshofer.quaqua.colorchooser.ColorSlidersChooser",
195: // "contrib.ch.randelshofer.quaqua.colorchooser.ColorPalettesChooser",
196: // "contrib.ch.randelshofer.quaqua.colorchooser.SwatchesChooser",
197: // "contrib.ch.randelshofer.quaqua.colorchooser.CrayonsChooser",
198: // "contrib.ch.randelshofer.quaqua.colorchooser.ColorPicker",
199: // "contrib.net.xoetrope.editor.color.ColorWheelPanel" },
200: //
201: // quaqua
202: "ColorChooser.foreground",
203: foregroundColor,
204: //
205: // // quaqua
206: // "ColorChooser.swatchesSwatchSize",
207: // new DimensionUIResource(5, 5),
208: //
209: // // quaqua
210: // "ColorChooser.resetMnemonic",
211: // new Integer(-1),
212: //
213: // // quaqua
214: // "ColorChooser.crayonsImage",
215: // new UIDefaults.LazyValue() {
216: // public Object createValue(UIDefaults table) {
217: // return Toolkit
218: // .getDefaultToolkit()
219: // .createImage(
220: // this
221: // .getClass()
222: // .getResource(
223: // commonDir
224: // + "ColorChooser.crayons.png"));
225: // }
226: // },
227:
228: // quaqua
229: // "ColorChooser.textSliderGap",
230: // new Integer(3),
231: //
232: // // quaqua
233: // "ColorChooser.colorPalettesIcon",
234: // makeButtonStateIcon(commonDir
235: // + "ColorChooser.colorPalettesIcons.png", 3),
236: //
237: // // quaqua
238: // "ColorChooser.colorSlidersIcon",
239: // makeButtonStateIcon(commonDir
240: // + "ColorChooser.colorSlidersIcons.png", 3),
241: //
242: // // quaqua
243: // "ColorChooser.colorSwatchesIcon",
244: // makeButtonStateIcon(commonDir
245: // + "ColorChooser.colorSwatchesIcons.png", 3),
246: //
247: // // quaqua
248: // "ColorChooser.colorWheelIcon",
249: // makeButtonStateIcon(commonDir
250: // + "ColorChooser.colorWheelIcons.png", 3),
251: //
252: // // quaqua
253: // "ColorChooser.crayonsIcon",
254: // makeButtonStateIcon(commonDir
255: // + "ColorChooser.crayonsIcons.png", 3),
256: //
257: // // quaqua
258: // "ColorChooser.imagePalettesIcon",
259: // makeButtonStateIcon(commonDir
260: // + "ColorChooser.imagePalettesIcons.png", 3),
261: //
262: // // Note: The following colors are used in color lists.
263: // // It is important that these colors are neutral (black,
264: // // white
265: // // or a shade of gray with saturation 0).
266: // // If they aren't neutral, human perception of the color
267: // // is negatively affected.
268: // "ColorChooser.listSelectionBackground",
269: // new ColorUIResource(0xd4d4d4),
270: //
271: // "ColorChooser.listSelectionForeground",
272: // new ColorUIResource(0x000000),
273: //
274: // // Icon of the color picker tool
275: // "ColorChooser.colorPickerIcon",
276: // makeIcon(this.getClass(), commonDir
277: // + "ColorChooser.colorPickerIcon.png"),
278: // // Magnifying glass used as the cursor image
279: // "ColorChooser.colorPickerMagnifier",
280: // this.makeBufferedImage(commonDir
281: // + "ColorChooser.colorPickerMagnifier.png"),
282: // // Hot spot of the magnifier cursor
283: // "ColorChooser.colorPickerHotSpot",
284: // new UIDefaults.ProxyLazyValue("java.awt.Point",
285: // new Object[] { new Integer(29), new Integer(29) }),
286: // // Pick point relative to hot spot
287: // "ColorChooser.colorPickerPickOffset",
288: // new UIDefaults.ProxyLazyValue("java.awt.Point",
289: // new Object[] { new Integer(-13), new Integer(-13) }),
290: // // Rectangle used for drawing the mask of the magnifying
291: // // glass
292: // "ColorChooser.colorPickerGlassRect",
293: // new UIDefaults.ProxyLazyValue("java.awt.Rectangle",
294: // new Object[] { new Integer(2), new Integer(2),
295: // new Integer(29), new Integer(29) }),
296: // // Capture rectangle. Width and height must be equal
297: // sized
298: // // and must be odd.
299: // // The position of the capture rectangle is relative to
300: // the
301: // // hot spot.
302: // "ColorChooser.colorPickerCaptureRect",
303: // new UIDefaults.ProxyLazyValue("java.awt.Rectangle",
304: // new Object[] { new Integer(-15), new Integer(-15),
305: // new Integer(5), new Integer(5) }),
306: // // Zoomed (magnified) capture image. Width and height
307: // must
308: // // be a multiple of the capture rectangles size.
309: // "ColorChooser.colorPickerZoomRect",
310: // new UIDefaults.ProxyLazyValue("java.awt.Rectangle",
311: // new Object[] { new Integer(4), new Integer(4),
312: // new Integer(25), new Integer(25) }),
313:
314: // class names of default choosers
315: "ColorChooser.defaultChoosers",
316: new String[] {
317: "contrib.ch.randelshofer.quaqua.colorchooser.ColorWheelChooser",
318: "contrib.ch.randelshofer.quaqua.colorchooser.ColorSlidersChooser",
319: "contrib.ch.randelshofer.quaqua.colorchooser.ColorPalettesChooser",
320: "contrib.ch.randelshofer.quaqua.colorchooser.SwatchesChooser",
321: "contrib.ch.randelshofer.quaqua.colorchooser.CrayonsChooser",
322: "contrib.ch.randelshofer.quaqua.colorchooser.Quaqua15ColorPicker",
323: "contrib.net.xoetrope.editor.color.ColorWheelPanel" },
324: // "ColorChooser.swatchesDefaultRecentColor", ...,
325: // "ColorChooser.swatchesRecentSwatchSize", ...,
326: "ColorChooser.swatchesSwatchSize",
327: new DimensionUIResource(5, 5),
328: "ColorChooser.resetMnemonic",
329: new Integer(-1),
330: "ColorChooser.crayonsImage",
331: makeImage(commonDir + "ColorChooser.crayons.png"),
332: "ColorChooser.textSliderGap",
333: new Integer(0),
334: "ColorChooser.colorPalettesIcon",
335: makeButtonStateIcon(commonDir
336: + "ColorChooser.colorPalettesIcons.png", 3),
337: "ColorChooser.colorSlidersIcon",
338: makeButtonStateIcon(commonDir
339: + "ColorChooser.colorSlidersIcons.png", 3),
340: "ColorChooser.colorSwatchesIcon",
341: makeButtonStateIcon(commonDir
342: + "ColorChooser.colorSwatchesIcons.png", 3),
343: "ColorChooser.colorWheelIcon",
344: makeButtonStateIcon(commonDir
345: + "ColorChooser.colorWheelIcons.png", 3),
346: "ColorChooser.crayonsIcon",
347: makeButtonStateIcon(commonDir
348: + "ColorChooser.crayonsIcons.png", 3),
349: "ColorChooser.imagePalettesIcon",
350: makeButtonStateIcon(commonDir
351: + "ColorChooser.imagePalettesIcons.png", 3),
352:
353: // Icon of the color picker tool
354: "ColorChooser.colorPickerIcon",
355: // makeIcon(getClass(), commonDir
356: // + "ColorChooser.colorPickerIcon.png"),
357: new IconUIResource(SubstanceImageCreator
358: .getSearchIcon(15, SubstanceThemeUtilities
359: .getTheme(null,
360: ComponentState.ACTIVE),
361: true)),
362:
363: // Magnifying glass used as the cursor image
364: "ColorChooser.colorPickerMagnifier",
365: makeBufferedImage(commonDir
366: + "ColorChooser.colorPickerMagnifier.png"),
367: // Hot spot of the magnifier cursor
368: "ColorChooser.colorPickerHotSpot",
369: new UIDefaults.ProxyLazyValue("java.awt.Point",
370: new Object[] { new Integer(29),
371: new Integer(29) }),
372: // Pick point relative to hot spot
373: "ColorChooser.colorPickerPickOffset",
374: new UIDefaults.ProxyLazyValue("java.awt.Point",
375: new Object[] { new Integer(-13),
376: new Integer(-13) }),
377: // Rectangle used for drawing the mask of the magnifying
378: // glass
379: "ColorChooser.colorPickerGlassRect",
380: new UIDefaults.ProxyLazyValue("java.awt.Rectangle",
381: new Object[] { new Integer(2),
382: new Integer(2), new Integer(29),
383: new Integer(29) }),
384: // Capture rectangle. Width and height must be equal sized
385: // and must be odd.
386: // The position of the capture rectangle is relative to the
387: // hot spot.
388: "ColorChooser.colorPickerCaptureRect",
389: new UIDefaults.ProxyLazyValue("java.awt.Rectangle",
390: new Object[] { new Integer(-15),
391: new Integer(-15), new Integer(5),
392: new Integer(5) }),
393: // Zoomed (magnified) capture image. Width and height must
394: // be a multiple of the capture rectangles size.
395: "ColorChooser.colorPickerZoomRect",
396: new UIDefaults.ProxyLazyValue("java.awt.Rectangle",
397: new Object[] { new Integer(4),
398: new Integer(4), new Integer(25),
399: new Integer(25) }),
400:
401: // // Localization support
402: // "Labels",
403: // ResourceBundleUtil
404: // .getBundle("contrib.ch.randelshofer.quaqua.Labels"),
405:
406: };
407:
408: Object[] colorDefaults = null;
409: FontSet substanceFontSet = SubstanceLookAndFeel
410: .getFontPolicy().getFontSet("Substance", null);
411: Font controlFont = substanceFontSet.getControlFont();
412:
413: Font fontBoldBaseP1 = new FontUIResource(controlFont
414: .deriveFont(Font.BOLD, controlFont.getSize() + 1));
415:
416: Font fontPlainBaseM2 = new FontUIResource(controlFont
417: .deriveFont((float) (controlFont.getSize() - 2)));
418:
419: colorDefaults = new Object[] { "ColorChooserUI",
420: "org.jvnet.substance.SubstanceColorChooserUI",
421:
422: "ColorChooser.font", controlFont,
423:
424: "ColorChooser.smallFont", fontPlainBaseM2,
425:
426: "ColorChooser.crayonsFont", fontBoldBaseP1 };
427:
428: Object[] labelDefaults = new Object[mainDefaults.length
429: + labelsList.size()];
430: for (int i = 0; i < mainDefaults.length; i++)
431: labelDefaults[i] = mainDefaults[i];
432: int start = mainDefaults.length;
433: for (int i = 0; i < labelsList.size(); i++)
434: labelDefaults[start + i] = labelsList.get(i);
435: mainDefaults = labelDefaults;
436:
437: if (colorDefaults != null) {
438: Object[] defaults = new Object[mainDefaults.length
439: + colorDefaults.length];
440: for (int i = 0; i < mainDefaults.length; i++)
441: defaults[i] = mainDefaults[i];
442: start = mainDefaults.length;
443: for (int i = 0; i < colorDefaults.length; i++)
444: defaults[start + i] = colorDefaults[i];
445: return defaults;
446: }
447: return mainDefaults;
448: } else {
449: Object[] defaults = new Object[labelsList.size()];
450: for (int i = 0; i < labelsList.size(); i++)
451: defaults[i] = labelsList.get(i);
452: return defaults;
453: }
454: }
455:
456: /*
457: * (non-Javadoc)
458: *
459: * @see org.jvnet.lafplugin.LafPlugin#uninitialize()
460: */
461: public void uninitialize() {
462: }
463:
464: /*
465: * (non-Javadoc)
466: *
467: * @see org.jvnet.lafplugin.LafPlugin#initialize()
468: */
469: public void initialize() {
470: try {
471: if (System.getProperty("substancelaf.useDecorations") != null) {
472: JFrame.setDefaultLookAndFeelDecorated(true);
473: JDialog.setDefaultLookAndFeelDecorated(true);
474: }
475: } catch (Exception exc) {
476: // probably running in unsecure JNLP - ignore
477: }
478: }
479: }
|