I have a main GUI where the user can bring up the option to edit
program preferences - they are quite simple. If the user chooses to do
this, a table comes up with the description, parameter name, default
value and custom value (custom value column is editable). The user can
hit ok and the table frame closes. Once done, the user can hit the
execute button on the GUI, and a new simulation is instatiated that
does the hard work. This is supposed to take in the edited "custom"
values or the default values if nothing has been changed. So my
questions are:
Where to I store Object [][] simulationPrefs - in the initial GUI
class, the prefs class or the simulation class?
What's the best way of passing it to and fro classes - as an object,
or a dataVector (the object is converted to a dataVector, so it can be
displayed in the table class).
How do I deal with the possibility that the user won't change the
preferences (currently, the custom column == default column)
Finally, is the is best way of doing this? Is there a better way that
won't require a massive rewrite? I don't really want to store any data
in files, and it is very important that the description is included in
the Object.
Maybe all I need to do is pass the parameter name column and the
custom value columns to the simulation class - but how do I do that if
the user doesn't enter the preferences frame?
It is also important to make things as easy for any future programmers
to change, which is why maybe having the Object [][] simulationPrefs
in the simulation class may be the clearest way of placing things.
Here is the table class code - I've removed most of the irrelevant
bits from it.
// ...imports
class RunOmcdFrame_Preferences extends JFrame{
DefaultTableModel simulationTable = new DefaultTableModel() {
public boolean isCellEditable(int row, int column) {
if (column == 3) {
return true;
}
return false;
}
};
//... GUI
private String[] columnNames = {"Preference Description",
"Parameter",
"Default",
"Custom"};
public RunOmcdFrame_Preferences(int selection) {
userOption = selection;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
simulationTable.setDataVector(getSimulationPrefs(), columnNames);
JTable tableS = new JTable(simulationTable);
JTableHeader headerS = tableS.getTableHeader();
headerS.setReorderingAllowed(false);
JTableHeader headerM = tableM.getTableHeader();
headerS.setReorderingAllowed(false);
tableS.getColumn("Custom").setCellRenderer(
new MultiRenderer());
tableS.getColumn("Custom").setCellEditor(
new MultiEditor());
tableS.getColumn("Default").setCellRenderer(
new MultiRenderer());
calcColumnWidths(tableS); // Set widths
// ...more GUI
jTabbedPane1.setSelectedComponent(jScrollPaneSimulation);
// ...etc for more tables in tabbed pane
}
private Object[][] getSimulationPrefs(){
Object [][] simulationPrefs = new Object[][]
{
{"Parameter A description", "intParamA",
new Integer(100), new Integer(100)},
{"Parameter B description", "comboParamB",
new ComboString("true"), new ComboString("true")},
{"Parameter C description", "floatParamC",
new Float (12.4), new Float (12.4)},
{"Parameter D description", "boolParamD",
new Boolean(true), new Boolean(true)}};
return simulationPrefs;
}
}
class MultiRenderer extends DefaultTableCellRenderer {
//...snip
}
class MultiEditor implements TableCellEditor {
//...snip
} |