001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ViewDefaults.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.extchart.property;
030:
031: import org.openesb.tools.extpropertysheet.IExtProperty;
032: import org.openesb.tools.extpropertysheet.IExtPropertyOption;
033: import org.openesb.tools.extpropertysheet.IExtPropertyOptions;
034: import org.openesb.tools.extpropertysheet.impl.ExtProperty;
035: import org.openesb.tools.extpropertysheet.impl.ExtPropertyGroup;
036: import org.openesb.tools.extpropertysheet.impl.ExtPropertyOptions;
037: import java.awt.Color;
038: import java.awt.Font;
039:
040: /**
041: * ViewDefaults.java
042: *
043: * ViewDefaults defines all methods to access defaults common to all view
044: * objects.
045: *
046: * @author Chris Johnston
047: * @modified by Rahul
048: * @version :$Revision: 1.1 $
049: */
050: public class ViewDefaults extends ExtPropertyGroup implements Constants {
051:
052: /** the RCS id */
053: private static final String RCS_ID = "$Id: ViewDefaults.java,v 1.1 2007/07/03 19:24:54 rahul_dwivedi Exp $";
054:
055: /** DEFAULT_DISPLAY_TITLE is used as a hard default. */
056: public static final boolean DEFAULT_DISPLAY_TITLE = true;
057:
058: /** DEFAULT_TITLE is used as a hard default. */
059: public static final String DEFAULT_TITLE = "Chart";
060:
061: /** DEFAULT_BACKGROUND_COLOR is used as a hard default. */
062: public static final Color DEFAULT_BACKGROUND_COLOR = Color.WHITE;
063:
064: /** DEFAULT_TEXT_COLOR is used as a hard default. */
065: public static final Color DEFAULT_TEXT_COLOR = Color.BLACK;
066:
067: /** DEFAULT_TITLE_FONT_SIZE is used as a hard default. */
068: public static final int DEFAULT_TITLE_FONT_SIZE = 20;
069:
070: /** Default value for BorderVisible property */
071: public static final boolean DEFAULT_BORDER_VISIBLE = false;
072:
073: /** DEFAULT_ALL_FIELDS_FONT_SIZE is used as a hard default. */
074: public static final int DEFAULT_ALL_FIELDS_FONT_SIZE = 9;
075:
076: /** DEFAULT_TITLE_STYLE is used as a hard default. */
077: public static final int DEFAULT_ALL_FIELDS_FONT_STYLE = Font.PLAIN;
078:
079: /** DEFAULT_TITLE_ALIGNMENT is used as a hard default. */
080: public static final int DEFAULT_TITLE_ALIGNMENT = CENTER;
081:
082: /** DEFAULT_TITLE_STYLE is used as a hard default. */
083: public static final int DEFAULT_TITLE_STYLE = Font.BOLD
084: + Font.ITALIC;
085:
086: /** DEFAULT_TITLE_FONT is used as a hard default. */
087: public static final Font DEFAULT_TITLE_FONT = new Font("SansSerif",
088: DEFAULT_TITLE_STYLE, DEFAULT_TITLE_FONT_SIZE);
089:
090: /** DEFAULT_NULL_REAL is used as a hard default. */
091: //public static final String DEFAULT_NULL_REAL = "0.0";
092: /** DEFAULT_NULL_INTEGRAL is used as a hard default. */
093: //public static final String DEFAULT_NULL_INTEGRAL = "0";
094: /** DEFAULT_NULL_STRING is used as a hard default. */
095: //public static final String DEFAULT_NULL_STRING = "";
096: /** DEFAULT_INTEGRAL_NUMBER_FORMAT is used as a hard default. */
097: public static final int DEFAULT_INTEGRAL_NUMBER_FORMAT = 0; //"##########0";
098:
099: /** DEFAULT_REAL_NUMBER_FORMAT is used as a hard default. */
100: public static final int DEFAULT_REAL_NUMBER_FORMAT = 0; //"##########0.0";
101:
102: /** DEFAULT_FONT_SIZES is used for an initial list of font sizes. */
103: public static final int[] DEFAULT_FONT_SIZES = { 7, 8, 9, 10, 11,
104: 12, 13, 14, 16, 18, 20, 22, 24, 28, 36, 48 };
105:
106: /** Default refreshing frequency in seconds */
107: public static final int DEFAULT_FREQUENCY = 60;
108:
109: /** SUGGESTED_INTEGRAL_NUMBER_FORMATS contains a list of suggested integral number display formats. */
110: public static final String[] SUGGESTED_INTEGRAL_NUMBER_FORMATS = {
111: "0", "#0", "##0", "#,##0", "#,###,##0", "#,###,###,##0" };
112:
113: private static final ExtPropertyOptions INTEGRAL_NUMBAR_FORMATS_OPTIONS = new ExtPropertyOptions(
114: SUGGESTED_INTEGRAL_NUMBER_FORMATS, true);
115:
116: public static final String[] SUG_HORIZONTAL = { "" + LEFT,
117: "" + RIGHT, "" + CENTER };
118: public static final String[] SUG_HORIZONTAL_DISPLAY = { "LEFT",
119: "RIGHT", "CENTER"
120:
121: };
122:
123: public static final ExtPropertyOptions TITLE_ALIGN_OPTIONS = new ExtPropertyOptions(
124: SUG_HORIZONTAL, SUG_HORIZONTAL_DISPLAY);
125: /** SUGGESTED_REAL_NUMBER_FORMATS contains a list of suggested real number display formats. */
126: public static final String[] SUGGESTED_REAL_NUMBER_FORMATS = {
127: "$0", "0", "#,###,###,##0", "$0.00", "$#,##0.00",
128: "$#,###,##0.00", "0.000", "#,##0.000", "#,###,##0.000" };
129:
130: private static final ExtPropertyOptions REAL_NUMBER_FORMATS_OPTIONS = new ExtPropertyOptions(
131: SUGGESTED_REAL_NUMBER_FORMATS, true);
132:
133: /** MY_DEFAULT_KEYS contains the default keys for this class. */
134: protected static final String[] MY_DEFAULT_KEYS = {
135: DISPLAY_TITLE_KEY, TITLE_KEY, TITLE_FONT_SIZE_KEY,
136: TITLE_FONT_KEY, TITLE_ALIGNMENT_KEY, TITLE_COLOR_KEY,
137: TITLE_BACKGROUND_KEY, BACKGROUND_COLOR_KEY, FREQUENCY,
138: TEXT_COLOR_KEY,
139: //NULL_REAL_KEY,
140: //NULL_INTEGRAL_KEY,
141: //NULL_STRING_KEY,
142: // INTEGRAL_NUMBER_FORMAT_KEY,
143: REAL_NUMBER_FORMAT_KEY };
144:
145: /**
146: */
147: public ViewDefaults() {
148: super ();
149: initDefault();
150: }
151:
152: private void initDefault() {
153:
154: setDisplayTitle(DEFAULT_DISPLAY_TITLE);
155: setTitle(DEFAULT_TITLE);
156: setTitleFont(DEFAULT_TITLE_FONT);
157: setTitleAlignment(DEFAULT_TITLE_ALIGNMENT);
158: setBackgroundColor(DEFAULT_BACKGROUND_COLOR);
159: setFrequency(DEFAULT_FREQUENCY);
160: setTextColor(DEFAULT_TEXT_COLOR);
161: //setNullReal(DEFAULT_NULL_REAL);
162: //setNullIntegral(DEFAULT_NULL_INTEGRAL);
163: //setNullString(DEFAULT_NULL_STRING);
164: //setIntegralNumberFormat(DEFAULT_INTEGRAL_NUMBER_FORMAT);
165: setRealNumberFormat(DEFAULT_REAL_NUMBER_FORMAT);
166:
167: }
168:
169: /**
170: * @see com.stc.ebam.server.chart.engine.view.ViewDefaults.getKeys()
171: */
172: public String[] getKeys() {
173: return MY_DEFAULT_KEYS;
174: }
175:
176: /**
177: * Sets if display title
178: * @param displayTitle - true/false
179: */
180: public void setDisplayTitle(boolean displayTitle) {
181: this .setProperty(ViewDefaults.DISPLAY_TITLE_KEY, Boolean
182: .valueOf(displayTitle));
183: }
184:
185: /**
186: * Returns if display title
187: * @return - true/false
188: */
189: public boolean isDisplayTitle() {
190: Boolean val = (Boolean) getPropertyValue(ViewDefaults.DISPLAY_TITLE_KEY);
191: if (val != null) {
192: return val.booleanValue();
193: }
194: //return default
195: return DEFAULT_DISPLAY_TITLE;
196: }
197:
198: /**
199: * Sets title
200: * @param title - title
201: */
202: public void setTitle(String title) {
203: this .setProperty(ViewDefaults.TITLE_KEY, title);
204: }
205:
206: /**
207: * Return title
208: * @return - title
209: */
210: public String getTitle() {
211: String val = (String) this
212: .getPropertyValue(ViewDefaults.TITLE_KEY);
213: if (val != null) {
214: return val;
215: }
216:
217: //return default
218: return DEFAULT_TITLE;
219: }
220:
221: /**
222: * Sets title font
223: * @param font - title font
224: */
225: public void setTitleFont(Font font) {
226: this .setFont(font, TITLE_FONT_KEY);
227: }
228:
229: /**
230: * Returns title font
231: * @return title font
232: */
233: public Font getTitleFont() {
234: return this .getFont(TITLE_FONT_KEY);
235: }
236:
237: /**
238: * Sets title text color
239: * @param color - color
240: */
241: public void setTitleColor(Color color) {
242: this .setProperty(TITLE_COLOR_KEY, color);
243: }
244:
245: /**
246: * Returns title text color
247: * @return title text color
248: */
249: public Color getTitleColor() {
250: return (Color) this .getPropertyValue(TITLE_COLOR_KEY);
251: }
252:
253: /**
254: * Sets title background color
255: * @param color - color
256: */
257: public void setTitleBackground(Color color) {
258: this .setProperty(TITLE_BACKGROUND_KEY, color);
259: }
260:
261: /**
262: * Returns title background color
263: * @return title background color
264: */
265: public Color getTitleBackground() {
266: return (Color) this .getPropertyValue(TITLE_BACKGROUND_KEY);
267: }
268:
269: /**
270: * Sets title alignment
271: * @param alignment - title alignment
272: */
273: public void setTitleAlignment(int alignment) {
274: this .setProperty(TITLE_ALIGNMENT_KEY, new Integer(alignment),
275: TITLE_ALIGN_OPTIONS);
276: }
277:
278: /**
279: * Set refreshing frequency
280: * @param frequency - frequency in seconds
281: */
282: public void setFrequency(int frequency) {
283: this .setProperty(FREQUENCY, new Integer(frequency));
284: }
285:
286: /**
287: * Return refreshing frequency
288: * @return frequency in seconds
289: */
290: public int getFrequency() {
291: Integer val = (Integer) this .getPropertyValue(FREQUENCY);
292: if (val != null) {
293: return val.intValue();
294: }
295: return DEFAULT_FREQUENCY;
296: }
297:
298: /**
299: * Returns title alignment
300: * @return - title alignment
301: */
302: public int getTitleAlignment() {
303: Integer val = (Integer) this
304: .getPropertyValue(TITLE_ALIGNMENT_KEY);
305: if (val != null) {
306: return val.intValue();
307: }
308: return DEFAULT_TITLE_ALIGNMENT;
309: }
310:
311: /**
312: * Sets data limit
313: * @param limit - limit
314: */
315: public void setDataLimit(int limit) {
316: this .setProperty(DATA_LIMIT_KEY, new Integer(limit));
317: }
318:
319: /**
320: * Returns data limit
321: * @return limit
322: */
323: public int getDataLimit() {
324: Integer val = (Integer) this .getPropertyValue(DATA_LIMIT_KEY);
325: if (val != null) {
326: return val.intValue();
327: }
328: return Integer.MAX_VALUE;
329: }
330:
331: /**
332: * Returns if border is visible
333: * @return true/false
334: */
335: public boolean isBorderVisible() {
336: Boolean val = (Boolean) this
337: .getPropertyValue(BORDER_VISIBLE_KEY);
338: if (val != null) {
339: return val.booleanValue();
340: }
341: return DEFAULT_BORDER_VISIBLE;
342: }
343:
344: /**
345: * Sets border visible
346: * @param visible - visible
347: */
348: public void setBorderVisible(boolean visible) {
349: this .setProperty(BORDER_VISIBLE_KEY, new Boolean(visible));
350: }
351:
352: /**
353: * Returns border paint
354: * @return border paint
355: */
356: public Color getBorderPaint() {
357: Color val = (Color) this .getPropertyValue(BORDER_PAINT_KEY);
358: return val;
359: }
360:
361: /**
362: * Sets border paint
363: * @param color - border paint
364: */
365: public void setBorderPaint(Color color) {
366: this .setProperty(BORDER_PAINT_KEY, color);
367: }
368:
369: /**
370: * Sets background color
371: * @param color - background color
372: */
373: public void setBackgroundColor(Color color) {
374: this .setProperty(BACKGROUND_COLOR_KEY, color);
375: }
376:
377: /**
378: * Returns background color
379: * @return - background color
380: */
381: public Color getBackgroundColor() {
382: Color val = (Color) this .getPropertyValue(BACKGROUND_COLOR_KEY);
383: if (val != null) {
384: return val;
385: }
386: return DEFAULT_BACKGROUND_COLOR;
387: }
388:
389: /**
390: * Sets text color
391: * @param color - text color
392: */
393: public void setTextColor(Color color) {
394: this .setProperty(TEXT_COLOR_KEY, color);
395: }
396:
397: /**
398: * Returns text color
399: * @return - text color
400: */
401: public Color getTextColor() {
402: Color val = (Color) this .getPropertyValue(TEXT_COLOR_KEY);
403: if (val != null) {
404: return val;
405: }
406: //return default
407: return DEFAULT_TEXT_COLOR;
408: }
409:
410: /**
411: * Sets null real
412: * @param nullReal - null real
413: */
414: /*
415: public void setNullReal(String nullReal) {
416: this.setProperty(NULL_REAL_KEY, nullReal);
417: }
418: **/
419: /**
420: * Returns null real
421: * @return - null real
422: */
423: /*
424: public String getNullReal() {
425: String val = (String) this.getPropertyValue(NULL_REAL_KEY);
426: if (val != null) {
427: return val;
428: }
429:
430: //return default
431: return DEFAULT_NULL_REAL;
432: }
433: **/
434: /**
435: * Sets null integral
436: * @param nullIntg - null integral
437: */
438: /*
439: public void setNullIntegral(String nullIntg) {
440: this.setProperty(NULL_INTEGRAL_KEY, nullIntg);
441: }
442: **/
443: /**
444: * Returns null integral
445: * @return - null integral
446: */
447: /*
448: public String getNullIntegral() {
449: String val = (String) this.getPropertyValue(NULL_INTEGRAL_KEY);
450: if (val != null) {
451: return val;
452: }
453:
454: //return default
455: return DEFAULT_NULL_INTEGRAL;
456: }
457: /**
458: * Sets null String
459: * @param nullStr - null string
460: */
461: /*
462: public void setNullString(String nullStr) {
463: this.setProperty(ViewDefaults.NULL_STRING_KEY, nullStr);
464: }
465: /**
466: * Returns null string
467: * @return - null string
468: */
469: /*
470: public String getNullString() {
471: String val = (String) this.getPropertyValue(ViewDefaults.NULL_STRING_KEY);
472: if (val != null) {
473: return val;
474: }
475:
476: //return default
477: return DEFAULT_NULL_STRING;
478: }
479: /**
480: * Sets integral number format
481: * @param intNumFormat - integral number format
482: */
483: /* public void setIntegralNumberFormat(int intNumFormat) {
484: setProperty(ViewDefaults.INTEGRAL_NUMBER_FORMAT_KEY, new Integer(intNumFormat),INTEGRAL_NUMBAR_FORMATS_OPTIONS);
485: }
486: */
487: /**
488: * Return integral number format
489: * @return - integral number format
490: */
491: /*
492: public String getIntegralNumberFormat() {
493: Integer val = ((Integer) this.getPropertyValue(ViewDefaults.INTEGRAL_NUMBER_FORMAT_KEY));
494: if (val != null && val.intValue() < SUGGESTED_INTEGRAL_NUMBER_FORMATS.length) {
495: return SUGGESTED_INTEGRAL_NUMBER_FORMATS[val.intValue()];
496: }
497:
498: //return default
499: return SUGGESTED_INTEGRAL_NUMBER_FORMATS[0];
500: }
501: */
502: /**
503: * Sets real number format
504: * @param rFormat - real number format
505: */
506: public void setRealNumberFormat(int rFormat) {
507: setProperty(ViewDefaults.REAL_NUMBER_FORMAT_KEY, new Integer(
508: rFormat), REAL_NUMBER_FORMATS_OPTIONS);
509: }
510:
511: /**
512: * Returns real number format
513: * @return - real number format
514: */
515: public String getRealNumberFormat() {
516: Integer val = ((Integer) this
517: .getPropertyValue(ViewDefaults.REAL_NUMBER_FORMAT_KEY));
518: if (val != null
519: && val.intValue() < SUGGESTED_REAL_NUMBER_FORMATS.length) {
520: return SUGGESTED_REAL_NUMBER_FORMATS[val.intValue()];
521: }
522:
523: //return default
524: return SUGGESTED_REAL_NUMBER_FORMATS[0];
525:
526: }
527:
528: /**
529: * Return property template name
530: * @return - template name
531: */
532: public String getPropertyTemplateName() {
533: return null;
534: }
535:
536: /**
537: * Returns a font property
538: * @param property - property name
539: * @return font
540: */
541: protected Font getFont(String property) {
542: Font val = (Font) this .getPropertyValue(property);
543: if (val == null) {
544: val = this .DEFAULT_TITLE_FONT;
545: }
546: return val;
547: }
548:
549: /**
550: * Set font property
551: * @param font - font
552: * @param property - property name
553: */
554: public void setFont(Font font, String property) {
555: if (font != null) {
556: setProperty(property + FONT_NAME_SUFFIX, font);
557: }
558: }
559:
560: }
|