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.utils.params;
031:
032: import java.io.*;
033: import java.util.Properties;
034:
035: import org.jvnet.substance.SubstanceLookAndFeel;
036: import org.jvnet.substance.utils.SubstanceConstants.ImageWatermarkKind;
037:
038: /**
039: * Reads the properties from a local file. This class is <b>for internal use
040: * only</b>.
041: *
042: * @author Kirill Grouchnikov
043: */
044: public class PropertiesFileParamReader implements ParamReader {
045: /**
046: * Parser for the local file.
047: */
048: protected Properties props;
049:
050: /**
051: * Loads property file.
052: *
053: * @param configFile
054: * Location of the configuration file.
055: * @return Property parser.
056: * @throws IOException
057: */
058: private static Properties loadProperties(String configFile)
059: throws IOException {
060: InputStream in = null;
061: try {
062: in = new FileInputStream(configFile);
063: Properties p = new Properties();
064: p.load(in);
065: return p;
066: } finally {
067: if (in != null) {
068: try {
069: in.close();
070: } catch (Exception e) {
071: // ignore
072: }
073: }
074: }
075: }
076:
077: /**
078: * Creates a new local file reader.
079: *
080: * @param configFile
081: * Location of the configuration file.
082: */
083: public PropertiesFileParamReader(String configFile) {
084: try {
085: this .props = loadProperties(configFile);
086: } catch (Exception exc) {
087: this .props = null;
088: }
089: }
090:
091: /*
092: * (non-Javadoc)
093: *
094: * @see org.jvnet.substance.utils.params.ParamReader#getButtonShaperProperty()
095: */
096: public String getButtonShaperProperty() {
097: if (this .props == null)
098: return null;
099: return this .props
100: .getProperty(SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY);
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.jvnet.substance.utils.params.ParamReader#getGradientPainterProperty()
107: */
108: public String getGradientPainterProperty() {
109: if (this .props == null)
110: return null;
111: return this .props
112: .getProperty(SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY);
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see org.jvnet.substance.utils.params.ParamReader#getTitlePainterProperty()
119: */
120: public String getTitlePainterProperty() {
121: if (this .props == null)
122: return null;
123: return this .props
124: .getProperty(SubstanceLookAndFeel.TITLE_PAINTER_PROPERTY);
125: }
126:
127: /*
128: * (non-Javadoc)
129: *
130: * @see org.jvnet.substance.utils.params.ParamReader#getBorderPainterProperty()
131: */
132: public String getBorderPainterProperty() {
133: if (this .props == null)
134: return null;
135: return this .props
136: .getProperty(SubstanceLookAndFeel.BORDER_PAINTER_PROPERTY);
137: }
138:
139: /*
140: * (non-Javadoc)
141: *
142: * @see org.jvnet.substance.utils.params.ParamReader#getThemeProperty()
143: */
144: public String getThemeProperty() {
145: if (this .props == null)
146: return null;
147: return this .props
148: .getProperty(SubstanceLookAndFeel.THEME_PROPERTY);
149: }
150:
151: /*
152: * (non-Javadoc)
153: *
154: * @see org.jvnet.substance.utils.params.ParamReader#getTraceFileNameProperty()
155: */
156: public String getTraceFileNameProperty() {
157: if (this .props == null)
158: return null;
159: return this .props.getProperty(SubstanceLookAndFeel.TRACE_FILE);
160: }
161:
162: /*
163: * (non-Javadoc)
164: *
165: * @see org.jvnet.substance.utils.params.ParamReader#getWatermarkThemeProperty()
166: */
167: public String getWatermarkProperty() {
168: if (this .props == null)
169: return null;
170: return this .props
171: .getProperty(SubstanceLookAndFeel.WATERMARK_PROPERTY);
172: }
173:
174: /*
175: * (non-Javadoc)
176: *
177: * @see org.jvnet.substance.utils.params.ParamReader#getWatermarkImageProperty()
178: */
179: public String getWatermarkImageProperty() {
180: if (this .props == null)
181: return null;
182: return this .props
183: .getProperty(SubstanceLookAndFeel.WATERMARK_IMAGE_PROPERTY);
184: }
185:
186: /*
187: * (non-Javadoc)
188: *
189: * @see org.jvnet.substance.utils.params.ParamReader#toBleedWatermark()
190: */
191: public boolean toBleedWatermark() {
192: if (this .props == null)
193: return false;
194: String paramToBleedWatermark = this .props
195: .getProperty(SubstanceLookAndFeel.WATERMARK_TO_BLEED);
196: return (paramToBleedWatermark != null);
197: }
198:
199: /*
200: * (non-Javadoc)
201: *
202: * @see org.jvnet.substance.utils.params.ParamReader#toShowExtraElementProperty()
203: */
204: public boolean toShowExtraElementProperty() {
205: if (this .props == null)
206: return true;
207: String paramNoExtraElements = this .props
208: .getProperty(SubstanceLookAndFeel.NO_EXTRA_ELEMENTS);
209: return (paramNoExtraElements == null);
210: }
211:
212: /*
213: * (non-Javadoc)
214: *
215: * @see org.jvnet.substance.utils.params.ParamReader#isDebugUiMode()
216: */
217: public boolean isDebugUiMode() {
218: if (this .props == null)
219: return true;
220: String paramDebugUiMode = this .props
221: .getProperty(SubstanceLookAndFeel.DEBUG_UI_MODE);
222: return (paramDebugUiMode == null);
223: }
224:
225: /*
226: * (non-Javadoc)
227: *
228: * @see org.jvnet.substance.utils.params.ParamReader#toShowHeapStatusPanelProperty()
229: */
230: public String toShowHeapStatusPanelProperty() {
231: if (this .props == null)
232: return null;
233: return this .props
234: .getProperty(SubstanceLookAndFeel.HEAP_STATUS_PANEL);
235: }
236:
237: /*
238: * (non-Javadoc)
239: *
240: * @see org.jvnet.substance.utils.params.ParamReader#toEnableInvertedThemes()
241: */
242: public boolean toEnableInvertedThemes() {
243: if (this .props == null)
244: return false;
245: String paramEnableInvertedThemes = this .props
246: .getProperty(SubstanceLookAndFeel.ENABLE_INVERTED_THEMES);
247: return (paramEnableInvertedThemes != null);
248: }
249:
250: /*
251: * (non-Javadoc)
252: *
253: * @see org.jvnet.substance.utils.params.ParamReader#toEnableNegatedThemes()
254: */
255: public boolean toEnableNegatedThemes() {
256: if (this .props == null)
257: return false;
258: String paramEnableNegatedThemes = this .props
259: .getProperty(SubstanceLookAndFeel.ENABLE_NEGATED_THEMES);
260: return (paramEnableNegatedThemes != null);
261: }
262:
263: /*
264: * (non-Javadoc)
265: *
266: * @see org.jvnet.substance.utils.params.ParamReader#getWatermarkImageKindProperty()
267: */
268: public ImageWatermarkKind getWatermarkImageKindProperty() {
269: if (this .props == null)
270: return null;
271: String paramWatermarkImageKind = this .props
272: .getProperty(SubstanceLookAndFeel.WATERMARK_IMAGE_KIND);
273: if (paramWatermarkImageKind == null)
274: return null;
275: return ImageWatermarkKind.valueOf(paramWatermarkImageKind);
276: }
277:
278: /*
279: * (non-Javadoc)
280: *
281: * @see org.jvnet.substance.utils.params.ParamReader#getWatermarkImageOpacityProperty()
282: */
283: public Float getWatermarkImageOpacityProperty() {
284: if (this .props == null)
285: return null;
286: String paramWatermarkImageOpacity = this .props
287: .getProperty(SubstanceLookAndFeel.WATERMARK_IMAGE_OPACITY);
288: if (paramWatermarkImageOpacity == null)
289: return null;
290: try {
291: return Float.parseFloat(paramWatermarkImageOpacity);
292: } catch (NumberFormatException nfe) {
293: return null;
294: }
295: }
296: }
|