de.mcs.jmeasurement.gui.StoreProperties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JMeasurement Show documentation
Show all versions of JMeasurement Show documentation
JMeasurement profiling programs in production enviroment
/*
* MCS Media Computer Software Copyright (c) 2006 by MCS
* -------------------------------------- Created on 11.09.2006 by w.klaas
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
/**
*
*/
package de.mcs.jmeasurement.gui;
import java.awt.Dimension;
import java.awt.Point;
import java.util.Properties;
import de.mcs.utils.StringUtils;
/**
* @author w.klaas
*
*/
public class StoreProperties extends Properties {
/**
*
*/
private static final long serialVersionUID = 1L;
/** default dimension of the main window. */
private static final String DEFAULT_WINDOW_DIMENSION = "800,600";
/** key name. */
private static final String KEY_WINDOW_DIMENSION = "WindowDimension";
/** default location of the main window. */
private static final String DEFAULT_WINDOW_LOCATION = "0,0";
/** key name. */
private static final String KEY_WINDOW_LOCATION = "WindowLocation";
/** default dimension of the point dialog. */
private static final String DEFAULT_POINT_DIALOG_DIMENSION = "500,600";
/** key name. */
private static final String KEY_POINT_DIALOG_DIMENSION = "PointDialogDimension";
/** key name. */
private static final String KEY_POINT_DIALOG_LOCATION = "PointDialogLocation";
/** key name. */
private static final String KEY_FILTER_ITEMS = "FilterItems";
/** key name. */
private static final String KEY_URL_LIST = "UrlList";
/** key name. */
private static final String KEY_COLUMN_SIZES = "ColumnSizes";
/**
* @return getting the last saved dimension of the main window.
*/
public final Dimension getWindowDimesions() {
Dimension dimension = new Dimension();
String strWindowDimesion = getProperty(KEY_WINDOW_DIMENSION);
if (null == strWindowDimesion) {
strWindowDimesion = DEFAULT_WINDOW_DIMENSION;
}
String[] split = null;
do {
split = strWindowDimesion.split(",");
if (split.length != 2) {
strWindowDimesion = DEFAULT_WINDOW_DIMENSION;
}
} while (split.length != 2);
try {
int x = Integer.parseInt(split[0]);
int y = Integer.parseInt(split[1]);
dimension.setSize(x, y);
} catch (Exception e) {
dimension.setSize(800, 600);
}
return dimension;
}
/**
* setting window d�mension.
*
* @param dimension
* the window dimension
*/
public final void setWindowDimesions(final Dimension dimension) {
String strPoint = Integer.toString(dimension.width) + "," + Integer.toString(dimension.height);
setProperty(KEY_WINDOW_DIMENSION, strPoint);
}
/**
* @return getting the last saved location of the main window.
*/
public final Point getWindowLocation() {
Point location = new Point();
String strWindowDimesion = getProperty(KEY_WINDOW_LOCATION);
if (null == strWindowDimesion) {
strWindowDimesion = DEFAULT_WINDOW_LOCATION;
}
String[] split = null;
do {
split = strWindowDimesion.split(",");
if (split.length != 2) {
strWindowDimesion = DEFAULT_WINDOW_LOCATION;
}
} while (split.length != 2);
try {
int x = Integer.parseInt(split[0]);
int y = Integer.parseInt(split[1]);
location.setLocation(x, y);
} catch (Exception e) {
location.setLocation(0, 0);
}
return location;
}
/**
* setting main window location.
*
* @param point
* the main location
*/
public final void setWindowoLocation(final Point point) {
String strPoint = Integer.toString(point.x) + "," + Integer.toString(point.y);
setProperty(KEY_WINDOW_LOCATION, strPoint);
}
/**
* @return the filter item list
*/
public final String[] getFilterItems() {
String value = getProperty(KEY_FILTER_ITEMS);
if (value != null) {
return StringUtils.csvStringToArray(value, ',', '"');
}
return null;
}
/**
* @param items
* setting the filter item list.
*/
public final void setFilterItems(final String[] items) {
String value = StringUtils.arrayToCSVString(items, ',', '"');
setProperty(KEY_FILTER_ITEMS, value);
}
/**
*
* @return getting the url list.
*/
public final String[] getUrlList() {
String value = getProperty(KEY_URL_LIST);
if (value != null) {
return StringUtils.csvStringToArray(value, ',', '"');
}
return null;
}
/**
*
* @param items
* the url list to save.
*/
public final void setUrlList(final String[] items) {
String value = StringUtils.arrayToCSVString(items, ',', '"');
setProperty(KEY_URL_LIST, value);
}
/**
*
* @return getting the column sizes.
*/
public final int[] getColumnSizes() {
String value = getProperty(KEY_COLUMN_SIZES);
if (value != null) {
String[] values = StringUtils.csvStringToArray(value, ',', '"');
int[] sizes = new int[values.length];
for (int i = 0; i < values.length; i++) {
try {
sizes[i] = Integer.parseInt(values[i]);
} catch (Exception e) {
sizes[i] = 0;
}
}
return sizes;
}
return null;
}
/**
*
* @param items
* the column sizes to save.
*/
public final void setColumnSizes(final int[] items) {
StringBuffer value = new StringBuffer();
for (int i = 0; i < items.length; i++) {
value.append(items[i]).append(',');
}
if (value.length() > 1) {
value.deleteCharAt(value.length() - 1);
setProperty(KEY_COLUMN_SIZES, value.toString());
}
}
/**
* @return getting the last saved dimension of the point dialog window.
*/
public final Dimension getPointDialogDimesions() {
Dimension dimension = new Dimension();
String strWindowDimesion = getProperty(KEY_POINT_DIALOG_DIMENSION);
if (null == strWindowDimesion) {
strWindowDimesion = DEFAULT_POINT_DIALOG_DIMENSION;
}
String[] split = null;
do {
split = strWindowDimesion.split(",");
if (split.length != 2) {
strWindowDimesion = DEFAULT_POINT_DIALOG_DIMENSION;
}
} while (split.length != 2);
try {
int x = Integer.parseInt(split[0]);
int y = Integer.parseInt(split[1]);
dimension.setSize(x, y);
} catch (Exception e) {
dimension.setSize(500, 600);
}
return dimension;
}
/**
* setting point dialog window d�mension.
*
* @param dimension
* the point dialog dimension
*/
public final void setPointDialogDimesions(final Dimension dimension) {
String strPoint = Integer.toString(dimension.width) + "," + Integer.toString(dimension.height);
setProperty(KEY_POINT_DIALOG_DIMENSION, strPoint);
}
/**
* @return getting the last saved location of the point dialog window.
*/
public final Point getPointDialogLocation() {
Dimension dim = getPointDialogDimesions();
Point location = new Point();
String strWindowDimesion = getProperty(KEY_POINT_DIALOG_LOCATION);
if (null == strWindowDimesion) {
return ReportViewer.getCenterWindowPosition(dim);
}
String[] split = null;
do {
split = strWindowDimesion.split(",");
if (split.length != 2) {
return ReportViewer.getCenterWindowPosition(dim);
}
} while (split.length != 2);
try {
int x = Integer.parseInt(split[0]);
int y = Integer.parseInt(split[1]);
location.setLocation(x, y);
} catch (Exception e) {
location.setLocation(0, 0);
}
return location;
}
/**
* setting point dialog window location.
*
* @param point
* the point dialog location
*/
public final void setPointDialogLocation(final Point point) {
String strPoint = Integer.toString(point.x) + "," + Integer.toString(point.y);
setProperty(KEY_POINT_DIALOG_LOCATION, strPoint);
}
}