/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.component;
import javax.swing.table.AbstractTableModel;
import javolution37.javolution.xml.XmlElement;
import javolution37.javolution.xml.XmlFormat;
import com.jstatcom.model.JSCInt;
import com.jstatcom.project.ProjectManager;
import com.jstatcom.project.SettingsElement;
/**
* Holds user set properties. This can be used together with the
* AppSettings dialog to edit user settings.
*
* @author Markus Kraetzig
*/
public final class AppSettings extends AbstractTableModel implements
SettingsElement {
private JSCInt saveLastState = new JSCInt("lastState", 1);
private JSCInt sControlEdit = new JSCInt("sControlEdit", 0);
private JSCInt exitDialog = new JSCInt("exitDialog", 1);
private JSCInt showExplorer = new JSCInt("showExplorer", 1);
private static final int defaultMax = 10000;
private JSCInt maxArrayDisplaySize = new JSCInt("maxArrayDisplaySize",
defaultMax);
/**
* XML format field for (de)serialization.
*/
public static final XmlFormat AppSettings_XML = new XmlFormat(
AppSettings.class) {
public void format(AppSettings data, XmlElement xml) {
xml.add(data.saveLastState);
xml.add(data.sControlEdit);
xml.add(data.exitDialog);
xml.add(data.showExplorer);
xml.add(data.maxArrayDisplaySize);
}
public AppSettings parse(XmlElement xml) {
AppSettings settings = new AppSettings();
if (xml.hasNext()) {
JSCInt val = (JSCInt) xml.getNext();
settings.saveLastState = val;
}
if (xml.hasNext()) {
JSCInt val = (JSCInt) xml.getNext();
settings.sControlEdit = val;
}
if (xml.hasNext()) {
JSCInt val = (JSCInt) xml.getNext();
settings.exitDialog = val;
}
if (xml.hasNext()) {
JSCInt val = (JSCInt) xml.getNext();
settings.showExplorer = val;
}
if (xml.hasNext()) {
JSCInt val = (JSCInt) xml.getNext();
if (val.intVal() < 0)
val.setInt(defaultMax);
settings.maxArrayDisplaySize = val;
}
return settings;
}
};
/**
* Default constructor.
*
*/
public AppSettings() {
}
/**
* Copy constructor.
*
* @param appSettings
* the instance to create a copy of
*/
public AppSettings(AppSettings appSettings) {
super();
this.saveLastState = appSettings.saveLastState.copy();
this.sControlEdit = appSettings.sControlEdit.copy();
this.exitDialog = appSettings.exitDialog.copy();
this.showExplorer = appSettings.showExplorer.copy();
this.maxArrayDisplaySize = appSettings.maxArrayDisplaySize.copy();
}
/*
* (non-Javadoc)
*
* @see com.jstatcom.project.SettingsElement#setElement()
*/
public void setElement() {
TopFrame topFrame = ProjectManager.getInstance().getTopFrame();
if (topFrame != null)
topFrame.setAppSettings(this);
}
/**
* Gets JSCInt indicating whether save last state is on.
*
* @return JSCInt
*/
public JSCInt getSaveLastState() {
return saveLastState;
}
/**
* Gets JSCInt indicating whether the symbol table data table
* elements should be editable.
*
* @return JSCInt
*/
public JSCInt getSControlEdit() {
return sControlEdit;
}
/**
* Gets JSCInt indicating whether exit Dialog should be
* shown.
*
* @return JSCInt
*/
public JSCInt getExitDialog() {
return exitDialog;
}
/**
* Gets JSCInt indicating whether explorer panel should be
* shown.
*
* @return JSCInt
*/
public JSCInt getShowExplorer() {
return showExplorer;
}
/**
* Gets JSCInt indicating the maximum array size (number of elements) that should
* be displayed in the symbol control.
*
* @return JSCInt
*/
public JSCInt getMaxArrayDisplaySize() {
return maxArrayDisplaySize;
}
public int getColumnCount() {
return 2;
}
public int getRowCount() {
return 5;
}
public boolean isCellEditable(int row, int col) {
if (col == 1)
return true;
return false;
}
public String getColumnName(int col) {
if (col == 0)
return "Property";
if (col == 1)
return "Value";
throw new RuntimeException("Invalid column index " + col + ".");
}
public Object getValueAt(int row, int col) {
if (row >= getRowCount() || col >= getColumnCount())
throw new IndexOutOfBoundsException("Index " + row + ":" + col
+ " is out of range.");
// 1. column with property name
if (col == 0) {
if (row == 0)
return "save/restore last project state";
if (row == 1)
return "matrices in symbol table editable (expert)";
if (row == 2)
return "show exit dialog";
if (row == 3)
return "show explorer panel";
if (row == 4)
return "maximum number of array elements to display in symbol control";
}
// 2. column with property value
if (col == 1) {
if (row == 0)
return Boolean.valueOf(saveLastState.intVal() != 0);
if (row == 1)
return Boolean.valueOf(sControlEdit.intVal() != 0);
if (row == 2)
return Boolean.valueOf(exitDialog.intVal() != 0);
if (row == 3)
return Boolean.valueOf(showExplorer.intVal() != 0);
if (row == 4)
return maxArrayDisplaySize.intVal();
}
throw new RuntimeException("Should never be reached.");
}
public void setValueAt(Object value, int row, int col) {
if (col == 1) {
if (row == 0)
saveLastState.setVal(((Boolean) value).booleanValue() ? 1 : 0);
if (row == 1)
sControlEdit.setVal(((Boolean) value).booleanValue() ? 1 : 0);
if (row == 2)
exitDialog.setVal(((Boolean) value).booleanValue() ? 1 : 0);
if (row == 3)
showExplorer.setVal(((Boolean) value).booleanValue() ? 1 : 0);
if (row == 4) {
Integer val = null;
try {
val = Integer.parseInt(value + "");
} catch (Exception ex) {
}
if (val != null && val >= 0)
maxArrayDisplaySize.setVal(val.intValue());
}
}
}
}
Ads help maintain this website.