001: /*
002: * MCS Media Computer Software Copyright (c) 2006 by MCS
003: * -------------------------------------- Created on 11.09.2006 by w.klaas
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License. You may obtain a copy of
007: * the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017: /**
018: *
019: */package de.mcs.jmeasurement.gui;
020:
021: import java.awt.Dimension;
022: import java.awt.Point;
023: import java.util.Properties;
024:
025: import de.mcs.utils.StringUtils;
026:
027: /**
028: * @author w.klaas
029: *
030: */
031: public class StoreProperties extends Properties {
032:
033: /**
034: *
035: */
036: private static final long serialVersionUID = 1L;
037:
038: /** default dimension of the main window. */
039: private static final String DEFAULT_WINDOW_DIMENSION = "800,600";
040:
041: /** key name. */
042: private static final String KEY_WINDOW_DIMENSION = "WindowDimension";
043:
044: /** default location of the main window. */
045: private static final String DEFAULT_WINDOW_LOCATION = "0,0";
046:
047: /** key name. */
048: private static final String KEY_WINDOW_LOCATION = "WindowLocation";
049:
050: /** default dimension of the point dialog. */
051: private static final String DEFAULT_POINT_DIALOG_DIMENSION = "500,600";
052:
053: /** key name. */
054: private static final String KEY_POINT_DIALOG_DIMENSION = "PointDialogDimension";
055:
056: /** key name. */
057: private static final String KEY_POINT_DIALOG_LOCATION = "PointDialogLocation";
058:
059: /** key name. */
060: private static final String KEY_FILTER_ITEMS = "FilterItems";
061:
062: /** key name. */
063: private static final String KEY_URL_LIST = "UrlList";
064:
065: /** key name. */
066: private static final String KEY_COLUMN_SIZES = "ColumnSizes";
067:
068: /**
069: * @return getting the last saved dimension of the main window.
070: */
071: public final Dimension getWindowDimesions() {
072: Dimension dimension = new Dimension();
073: String strWindowDimesion = getProperty(KEY_WINDOW_DIMENSION);
074: if (null == strWindowDimesion) {
075: strWindowDimesion = DEFAULT_WINDOW_DIMENSION;
076: }
077: String[] split = null;
078: do {
079: split = strWindowDimesion.split(",");
080: if (split.length != 2) {
081: strWindowDimesion = DEFAULT_WINDOW_DIMENSION;
082: }
083: } while (split.length != 2);
084: try {
085: int x = Integer.parseInt(split[0]);
086: int y = Integer.parseInt(split[1]);
087: dimension.setSize(x, y);
088: } catch (Exception e) {
089: dimension.setSize(800, 600);
090: }
091: return dimension;
092: }
093:
094: /**
095: * setting window dímension.
096: *
097: * @param dimension
098: * the window dimension
099: */
100: public final void setWindowDimesions(final Dimension dimension) {
101: String strPoint = Integer.toString(dimension.width) + ","
102: + Integer.toString(dimension.height);
103: setProperty(KEY_WINDOW_DIMENSION, strPoint);
104: }
105:
106: /**
107: * @return getting the last saved location of the main window.
108: */
109: public final Point getWindowLocation() {
110: Point location = new Point();
111: String strWindowDimesion = getProperty(KEY_WINDOW_LOCATION);
112: if (null == strWindowDimesion) {
113: strWindowDimesion = DEFAULT_WINDOW_LOCATION;
114: }
115: String[] split = null;
116: do {
117: split = strWindowDimesion.split(",");
118: if (split.length != 2) {
119: strWindowDimesion = DEFAULT_WINDOW_LOCATION;
120: }
121: } while (split.length != 2);
122: try {
123: int x = Integer.parseInt(split[0]);
124: int y = Integer.parseInt(split[1]);
125: location.setLocation(x, y);
126: } catch (Exception e) {
127: location.setLocation(0, 0);
128: }
129: return location;
130: }
131:
132: /**
133: * setting main window location.
134: *
135: * @param point
136: * the main location
137: */
138: public final void setWindowoLocation(final Point point) {
139: String strPoint = Integer.toString(point.x) + ","
140: + Integer.toString(point.y);
141: setProperty(KEY_WINDOW_LOCATION, strPoint);
142: }
143:
144: /**
145: * @return the filter item list
146: */
147: public final String[] getFilterItems() {
148: String value = getProperty(KEY_FILTER_ITEMS);
149: if (value != null) {
150: return StringUtils.csvStringToArray(value, ',', '"');
151: }
152: return null;
153: }
154:
155: /**
156: * @param items
157: * setting the filter item list.
158: */
159: public final void setFilterItems(final String[] items) {
160: String value = StringUtils.arrayToCSVString(items, ',', '"');
161: setProperty(KEY_FILTER_ITEMS, value);
162: }
163:
164: /**
165: *
166: * @return getting the url list.
167: */
168: public final String[] getUrlList() {
169: String value = getProperty(KEY_URL_LIST);
170: if (value != null) {
171: return StringUtils.csvStringToArray(value, ',', '"');
172: }
173: return null;
174: }
175:
176: /**
177: *
178: * @param items
179: * the url list to save.
180: */
181: public final void setUrlList(final String[] items) {
182: String value = StringUtils.arrayToCSVString(items, ',', '"');
183: setProperty(KEY_URL_LIST, value);
184: }
185:
186: /**
187: *
188: * @return getting the column sizes.
189: */
190: public final int[] getColumnSizes() {
191: String value = getProperty(KEY_COLUMN_SIZES);
192: if (value != null) {
193: String[] values = StringUtils.csvStringToArray(value, ',',
194: '"');
195: int[] sizes = new int[values.length];
196: for (int i = 0; i < values.length; i++) {
197: try {
198: sizes[i] = Integer.parseInt(values[i]);
199: } catch (Exception e) {
200: sizes[i] = 0;
201: }
202: }
203: return sizes;
204: }
205: return null;
206: }
207:
208: /**
209: *
210: * @param items
211: * the column sizes to save.
212: */
213: public final void setColumnSizes(final int[] items) {
214: StringBuffer value = new StringBuffer();
215: for (int i = 0; i < items.length; i++) {
216: value.append(items[i]).append(',');
217: }
218: if (value.length() > 1) {
219: value.deleteCharAt(value.length() - 1);
220: setProperty(KEY_COLUMN_SIZES, value.toString());
221: }
222: }
223:
224: /**
225: * @return getting the last saved dimension of the point dialog window.
226: */
227: public final Dimension getPointDialogDimesions() {
228: Dimension dimension = new Dimension();
229: String strWindowDimesion = getProperty(KEY_POINT_DIALOG_DIMENSION);
230: if (null == strWindowDimesion) {
231: strWindowDimesion = DEFAULT_POINT_DIALOG_DIMENSION;
232: }
233: String[] split = null;
234: do {
235: split = strWindowDimesion.split(",");
236: if (split.length != 2) {
237: strWindowDimesion = DEFAULT_POINT_DIALOG_DIMENSION;
238: }
239: } while (split.length != 2);
240: try {
241: int x = Integer.parseInt(split[0]);
242: int y = Integer.parseInt(split[1]);
243: dimension.setSize(x, y);
244: } catch (Exception e) {
245: dimension.setSize(500, 600);
246: }
247: return dimension;
248: }
249:
250: /**
251: * setting point dialog window dímension.
252: *
253: * @param dimension
254: * the point dialog dimension
255: */
256: public final void setPointDialogDimesions(final Dimension dimension) {
257: String strPoint = Integer.toString(dimension.width) + ","
258: + Integer.toString(dimension.height);
259: setProperty(KEY_POINT_DIALOG_DIMENSION, strPoint);
260: }
261:
262: /**
263: * @return getting the last saved location of the point dialog window.
264: */
265: public final Point getPointDialogLocation() {
266: Dimension dim = getPointDialogDimesions();
267: Point location = new Point();
268: String strWindowDimesion = getProperty(KEY_POINT_DIALOG_LOCATION);
269: if (null == strWindowDimesion) {
270: return ReportViewer.getCenterWindowPosition(dim);
271: }
272: String[] split = null;
273: do {
274: split = strWindowDimesion.split(",");
275: if (split.length != 2) {
276: return ReportViewer.getCenterWindowPosition(dim);
277: }
278: } while (split.length != 2);
279: try {
280: int x = Integer.parseInt(split[0]);
281: int y = Integer.parseInt(split[1]);
282: location.setLocation(x, y);
283: } catch (Exception e) {
284: location.setLocation(0, 0);
285: }
286: return location;
287: }
288:
289: /**
290: * setting point dialog window location.
291: *
292: * @param point
293: * the point dialog location
294: */
295: public final void setPointDialogLocation(final Point point) {
296: String strPoint = Integer.toString(point.x) + ","
297: + Integer.toString(point.y);
298: setProperty(KEY_POINT_DIALOG_LOCATION, strPoint);
299: }
300:
301: }
|