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;
031:
032: import org.jvnet.substance.border.*;
033: import org.jvnet.substance.button.*;
034: import org.jvnet.substance.painter.*;
035: import org.jvnet.substance.painter.decoration.Glass3DDecorationPainter;
036: import org.jvnet.substance.painter.highlight.ClassicHighlightPainter;
037: import org.jvnet.substance.plugin.*;
038: import org.jvnet.substance.skin.SubstanceAbstractSkin;
039: import org.jvnet.substance.theme.SubstanceAquaTheme;
040: import org.jvnet.substance.theme.SubstanceTheme;
041: import org.jvnet.substance.watermark.SubstanceStripeWatermark;
042: import org.jvnet.substance.watermark.SubstanceWatermark;
043:
044: /**
045: * The default look and feel that sets theme, watermark, button shaper and
046: * painters based on VM / config / plugin parameters. Use to revert to the
047: * default settings.
048: *
049: * @author Kirill Grouchnikov
050: * @since 3.2
051: */
052: public class SubstanceDefaultLookAndFeel extends SubstanceLookAndFeel {
053: /**
054: * Default skin.
055: *
056: * @author Kirill Grouchnikov
057: */
058: private static class SubstanceDefaultSkin extends
059: SubstanceAbstractSkin {
060: /**
061: * Creates the default skin.
062: */
063: public SubstanceDefaultSkin() {
064: // set theme
065: String paramTheme = SubstanceLookAndFeel.paramReader
066: .getThemeProperty();
067: if (paramTheme != null) {
068: try {
069: Class<?> themeClass = Class.forName(paramTheme);
070: if (themeClass != null) {
071: Object obj = themeClass.newInstance();
072: if (obj instanceof SubstanceTheme) {
073: this .theme = (SubstanceTheme) obj;
074: }
075: }
076: } catch (Exception exc) {
077: }
078: }
079:
080: if (this .theme == null) {
081: for (Object themePlugin : SubstanceLookAndFeel.themePlugins
082: .getAvailablePlugins(true)) {
083: String defaultThemeClassName = ((SubstanceThemePlugin) themePlugin)
084: .getDefaultThemeClassName();
085: if (defaultThemeClassName != null) {
086: try {
087: Class<?> themeClass = Class
088: .forName(defaultThemeClassName);
089: if (themeClass != null) {
090: Object obj = themeClass.newInstance();
091: if (obj instanceof SubstanceTheme) {
092: this .theme = (SubstanceTheme) obj;
093: }
094: }
095: } catch (Exception exc) {
096: }
097: }
098: }
099: }
100: if (this .theme == null) {
101: this .theme = new SubstanceAquaTheme();
102: }
103:
104: // set watermark
105: String paramWatermark = SubstanceLookAndFeel.paramReader
106: .getWatermarkProperty();
107: if (paramWatermark != null) {
108: try {
109: Class<?> watermarkClass = Class
110: .forName(paramWatermark);
111: if (watermarkClass != null) {
112: Object obj = watermarkClass.newInstance();
113: if (obj instanceof SubstanceWatermark) {
114: this .watermark = (SubstanceWatermark) obj;
115: }
116: }
117: } catch (Exception exc) {
118: }
119: }
120:
121: if (this .watermark == null) {
122: for (Object watermarkPlugin : SubstanceLookAndFeel.watermarkPlugins
123: .getAvailablePlugins(true)) {
124: String defaultWatermarkClassName = ((SubstanceWatermarkPlugin) watermarkPlugin)
125: .getDefaultWatermarkClassName();
126: if (defaultWatermarkClassName != null) {
127: try {
128: Class<?> watermarkClass = Class
129: .forName(defaultWatermarkClassName);
130: if (watermarkClass != null) {
131: Object obj = watermarkClass
132: .newInstance();
133: if (obj instanceof SubstanceWatermark) {
134: this .watermark = (SubstanceWatermark) obj;
135: }
136: }
137: } catch (Exception exc) {
138: }
139: }
140: }
141: }
142: if (this .watermark == null) {
143: this .watermark = new SubstanceStripeWatermark();
144: }
145:
146: // set buttonShaper
147: String paramButtonShaper = SubstanceLookAndFeel.paramReader
148: .getButtonShaperProperty();
149: if (paramButtonShaper != null) {
150: try {
151: Class<?> buttonShaperClass = Class
152: .forName(paramButtonShaper);
153: if (buttonShaperClass != null) {
154: Object obj = buttonShaperClass.newInstance();
155: if (obj instanceof SubstanceButtonShaper) {
156: this .buttonShaper = (SubstanceButtonShaper) obj;
157: }
158: }
159: } catch (Exception exc) {
160: }
161: }
162:
163: if (this .buttonShaper == null) {
164: for (Object buttonShaperPlugin : SubstanceLookAndFeel.shaperPlugins
165: .getAvailablePlugins(true)) {
166: for (ButtonShaperInfo buttonShaperInfo : ((SubstanceButtonShaperPlugin) buttonShaperPlugin)
167: .getButtonShapers()) {
168: if (buttonShaperInfo.isDefault()) {
169: try {
170: Class<?> buttonShaperClass = Class
171: .forName(buttonShaperInfo
172: .getClassName());
173: if (buttonShaperClass != null) {
174: Object obj = buttonShaperClass
175: .newInstance();
176: if (obj instanceof SubstanceButtonShaper) {
177: this .buttonShaper = (SubstanceButtonShaper) obj;
178: }
179: }
180: } catch (Exception exc) {
181: }
182: }
183: }
184: }
185: }
186: if (this .buttonShaper == null) {
187: this .buttonShaper = new StandardButtonShaper();
188: }
189:
190: // set gradientPainter
191: String paramGradientPainter = SubstanceLookAndFeel.paramReader
192: .getGradientPainterProperty();
193: if (paramGradientPainter != null) {
194: try {
195: Class<?> gradientPainterClass = Class
196: .forName(paramGradientPainter);
197: if (gradientPainterClass != null) {
198: Object obj = gradientPainterClass.newInstance();
199: if (obj instanceof SubstanceGradientPainter) {
200: this .gradientPainter = (SubstanceGradientPainter) obj;
201: }
202: }
203: } catch (Exception exc) {
204: }
205: }
206:
207: if (this .gradientPainter == null) {
208: for (Object gradientPainterPlugin : SubstanceLookAndFeel.painterPlugins
209: .getAvailablePlugins(true)) {
210: for (GradientPainterInfo gradientPainterInfo : ((SubstanceGradientPainterPlugin) gradientPainterPlugin)
211: .getGradientPainters()) {
212: if (gradientPainterInfo.isDefault()) {
213: try {
214: Class<?> gradientPainterClass = Class
215: .forName(gradientPainterInfo
216: .getClassName());
217: if (gradientPainterClass != null) {
218: Object obj = gradientPainterClass
219: .newInstance();
220: if (obj instanceof SubstanceGradientPainter) {
221: this .gradientPainter = (SubstanceGradientPainter) obj;
222: }
223: }
224: } catch (Exception exc) {
225: }
226: }
227: }
228: }
229: }
230: if (this .gradientPainter == null) {
231: this .gradientPainter = new StandardGradientPainter();
232: }
233:
234: // set border painter
235: String paramBorderPainter = SubstanceLookAndFeel.paramReader
236: .getBorderPainterProperty();
237: if (paramBorderPainter != null) {
238: try {
239: Class<?> borderPainterClass = Class
240: .forName(paramBorderPainter);
241: if (borderPainterClass != null) {
242: Object obj = borderPainterClass.newInstance();
243: if (obj instanceof SubstanceBorderPainter) {
244: this .borderPainter = (SubstanceBorderPainter) obj;
245: }
246: }
247: } catch (Exception exc) {
248: }
249: }
250:
251: if (this .borderPainter == null) {
252: for (Object borderPainterPlugin : SubstanceLookAndFeel.borderPainterPlugins
253: .getAvailablePlugins(true)) {
254: for (BorderPainterInfo borderPainterInfo : ((SubstanceBorderPainterPlugin) borderPainterPlugin)
255: .getBorderPainters()) {
256: if (borderPainterInfo.isDefault()) {
257: try {
258: Class<?> borderPainterClass = Class
259: .forName(borderPainterInfo
260: .getClassName());
261: if (borderPainterClass != null) {
262: Object obj = borderPainterClass
263: .newInstance();
264: if (obj instanceof SubstanceBorderPainter) {
265: this .borderPainter = (SubstanceBorderPainter) obj;
266: }
267: }
268: } catch (Exception exc) {
269: }
270: }
271: }
272: }
273: }
274: if (this .borderPainter == null) {
275: this .borderPainter = new StandardBorderPainter();
276: }
277:
278: this .highlightPainter = new ClassicHighlightPainter();
279: this .decorationPainter = new Glass3DDecorationPainter();
280: }
281:
282: public String getDisplayName() {
283: return "Default";
284: }
285: }
286:
287: /*
288: * (non-Javadoc)
289: *
290: * @see org.jvnet.substance.SubstanceLookAndFeel#getID()
291: */
292: @Override
293: public String getID() {
294: return "Substance Default";
295: }
296:
297: /*
298: * (non-Javadoc)
299: *
300: * @see org.jvnet.substance.SubstanceLookAndFeel#getName()
301: */
302: @Override
303: public String getName() {
304: return "Substance Default";
305: }
306:
307: /*
308: * (non-Javadoc)
309: *
310: * @see org.jvnet.substance.SubstanceLookAndFeel#initialize()
311: */
312: @Override
313: public void initialize() {
314: super .initialize();
315: setSkin(new SubstanceDefaultSkin());
316: }
317: }
|