Browse Source

Code tidy of main options dialog (and removal of old XML stuff).

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@77 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 20 years ago
parent
commit
c3a8641e17
  1. 98
      prism/classes/dtds/options.dtd
  2. 624
      prism/src/userinterface/GUIOptionsDialog.java

98
prism/classes/dtds/options.dtd

@ -1,98 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : options.dtd
Created on : July 15, 2005, 3:58 AM
Last change: July 15, 2005, 3:58 AM
Author : Andrew Hinton
Description:
Document to describe the structure of an options file.
This version is current for PRISM 2.1.dev9.simapmc4
-->
<!ELEMENT options (prism, model, properties, simulator, log)>
<!ELEMENT prism (#PCDATA)>
<!ATTLIST prism
verbose (true|false) #REQUIRED
fairness (true|false) #REQUIRED
precomputation (true|false) #REQUIRED
compact (true|false) #REQUIRED
cuddMaxMem CDATA #REQUIRED
cuddEpsilon CDATA #REQUIRED
iterativeMethod (power|jacobi|gaussSeidel|jor|sor) #REQUIRED
overRelaxation CDATA #REQUIRED
backwards (true|false) #REQUIRED
pseudo (true|false) #REQUIRED
termination (relative|absolute) #REQUIRED
maxIterations CDATA #REQUIRED
terminationEpsilon CDATA #REQUIRED
engine (mtbdd|sparse|hybrid) #REQUIRED
hybridNumLevels CDATA #REQUIRED
hybridMaxMemory CDATA #REQUIRED
hybridSORLevels CDATA #REQUIRED
hybridSORMaxMemory CDATA #REQUIRED>
<!ELEMENT model (editor, editor)>
<!ATTLIST model
autoParse (true|false) #REQUIRED
autoManual (true|false) #REQUIRED
parseDelay CDATA #REQUIRED
>
<!ELEMENT editor ((regEx)*)>
<!ATTLIST editor
fontName CDATA #REQUIRED
fontStyle CDATA #REQUIRED
fontSize CDATA #REQUIRED
fontColourR CDATA #REQUIRED
fontColourG CDATA #REQUIRED
fontColourB CDATA #REQUIRED
bgColourR CDATA #REQUIRED
bgColourG CDATA #REQUIRED
bgColourB CDATA #REQUIRED>
<!ELEMENT regEx (#PCDATA)>
<!ATTLIST regEx
description CDATA #REQUIRED
expression CDATA #REQUIRED
colourR CDATA #REQUIRED
colourG CDATA #REQUIRED
colourB CDATA #REQUIRED
style CDATA #REQUIRED
>
<!ELEMENT properties (#PCDATA)>
<!ATTLIST properties
fontName CDATA #REQUIRED
fontStyle CDATA #REQUIRED
fontSize CDATA #REQUIRED
selectionColourR CDATA #REQUIRED
selectionColourG CDATA #REQUIRED
selectionColourB CDATA #REQUIRED
warningColourR CDATA #REQUIRED
warningColourG CDATA #REQUIRED
warningColourB CDATA #REQUIRED
additionStrategy (warn|never) #REQUIRED
clearListOnLoad (true|false) #REQUIRED>
<!ELEMENT simulator (#PCDATA)>
<!ATTLIST simulator
engine (prism|apmc) #REQUIRED
simultaneous (true|false) #REQUIRED
apmcStrategy CDATA #REQUIRED
newPathAskDefault (true|false) #REQUIRED
renderAllValues (true|false) #REQUIRED>
<!ELEMENT log (#PCDATA)>
<!ATTLIST log
fontName CDATA #REQUIRED
fontStyle CDATA #REQUIRED
fontSize CDATA #REQUIRED
selectionColourR CDATA #REQUIRED
selectionColourG CDATA #REQUIRED
selectionColourB CDATA #REQUIRED
bgColourR CDATA #REQUIRED
bgColourG CDATA #REQUIRED
bgColourB CDATA #REQUIRED
bufferLength CDATA #REQUIRED>

624
prism/src/userinterface/GUIOptionsDialog.java

@ -1,6 +1,6 @@
//==============================================================================
//
// Copyright (c) 2002-2004, Andrew Hinton, Dave Parker
// Copyright (c) 2002-2006, Andrew Hinton, Dave Parker
//
// This file is part of PRISM.
//
@ -27,36 +27,23 @@ import userinterface.util.*;
import prism.*;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import java.net.*;
import settings.*;
/**
*
* @author ug60axh
*/
public class GUIOptionsDialog extends javax.swing.JDialog implements EntityResolver
public class GUIOptionsDialog extends javax.swing.JDialog
{
private ArrayList panels;
private PrismSettings settings;
/** Creates new form GUIOptionsDialog */
public GUIOptionsDialog(GUIPrism parent)
{
super(parent, true);
settings = parent.getPrism().getSettings();
panels = new ArrayList();
initComponents();
private ArrayList panels;
private PrismSettings settings;
/** Creates new form GUIOptionsDialog */
public GUIOptionsDialog(GUIPrism parent)
{
super(parent, true);
settings = parent.getPrism().getSettings();
panels = new ArrayList();
initComponents();
setLocationRelativeTo(getParent()); // centre
//setResizable(false);
//setResizable(false);
for(int i = 0; i < settings.optionOwners.length; i++)
{
@ -70,457 +57,162 @@ public class GUIOptionsDialog extends javax.swing.JDialog implements EntityResol
theTabs.add(table);
theTabs.setTitleAt(panels.indexOf(table), settings.propertyOwnerNames[i]);
}
}
public void addPanel(OptionsPanel p)
{
/*panels.add(p);
theTabs.add(p);
theTabs.setTitleAt(panels.indexOf(p), p.getTabText());
pack();*/
}
public void show()
{
/*for(int i = 0; i < panels.size(); i++)
{
OptionsPanel p = (OptionsPanel)panels.get(i);
p.synchronizeGUI();
}
pack();*/
super.show();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents()//GEN-BEGIN:initComponents
{
jPanel1 = new javax.swing.JPanel();
theTabs = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
defaultButton = new javax.swing.JButton();
saveSettingsButton = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
cancelButton = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
closeDialog(evt);
}
});
jPanel1.setLayout(new java.awt.BorderLayout());
theTabs.setMinimumSize(new java.awt.Dimension(300, 50));
theTabs.setPreferredSize(new java.awt.Dimension(300, 500));
jPanel1.add(theTabs, java.awt.BorderLayout.CENTER);
}
public void addPanel(OptionsPanel p)
{
// defunct
}
public void show()
{
super.show();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents()//GEN-BEGIN:initComponents
{
jPanel1 = new javax.swing.JPanel();
theTabs = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
defaultButton = new javax.swing.JButton();
saveSettingsButton = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
cancelButton = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
closeDialog(evt);
}
});
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel2.setLayout(new java.awt.BorderLayout());
theTabs.setMinimumSize(new java.awt.Dimension(300, 50));
theTabs.setPreferredSize(new java.awt.Dimension(300, 500));
jPanel1.add(theTabs, java.awt.BorderLayout.CENTER);
jPanel2.setMinimumSize(new java.awt.Dimension(300, 35));
jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
defaultButton.setMnemonic('D');
defaultButton.setText("Load Defaults");
defaultButton.setMaximumSize(new java.awt.Dimension(220, 50));
defaultButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
defaultButtonActionPerformed(evt);
}
});
jPanel2.setLayout(new java.awt.BorderLayout());
jPanel3.add(defaultButton);
jPanel2.setMinimumSize(new java.awt.Dimension(300, 35));
jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
saveSettingsButton.setMnemonic('S');
saveSettingsButton.setText("Save Options");
saveSettingsButton.setPreferredSize(new java.awt.Dimension(120, 25));
saveSettingsButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
saveSettingsButtonActionPerformed(evt);
}
});
defaultButton.setMnemonic('D');
defaultButton.setText("Load Defaults");
defaultButton.setMaximumSize(new java.awt.Dimension(220, 50));
defaultButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
defaultButtonActionPerformed(evt);
}
});
jPanel3.add(defaultButton);
saveSettingsButton.setMnemonic('S');
saveSettingsButton.setText("Save Options");
saveSettingsButton.setPreferredSize(new java.awt.Dimension(120, 25));
saveSettingsButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
saveSettingsButtonActionPerformed(evt);
}
});
jPanel3.add(saveSettingsButton);
jPanel3.add(saveSettingsButton);
jPanel2.add(jPanel3, java.awt.BorderLayout.CENTER);
jPanel2.add(jPanel3, java.awt.BorderLayout.CENTER);
jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
cancelButton.setText("OK");
cancelButton.setMaximumSize(new java.awt.Dimension(200, 50));
cancelButton.setMinimumSize(new java.awt.Dimension(80, 25));
cancelButton.setPreferredSize(new java.awt.Dimension(80, 25));
cancelButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
cancelButtonActionPerformed(evt);
}
});
cancelButton.setText("OK");
cancelButton.setMaximumSize(new java.awt.Dimension(200, 50));
cancelButton.setMinimumSize(new java.awt.Dimension(80, 25));
cancelButton.setPreferredSize(new java.awt.Dimension(80, 25));
cancelButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
cancelButtonActionPerformed(evt);
}
});
jPanel4.add(cancelButton);
jPanel4.add(cancelButton);
jPanel2.add(jPanel4, java.awt.BorderLayout.EAST);
jPanel2.add(jPanel4, java.awt.BorderLayout.EAST);
getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
pack();
}//GEN-END:initComponents
private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveSettingsButtonActionPerformed
{//GEN-HEADEREND:event_saveSettingsButtonActionPerformed
StringBuffer errors = new StringBuffer("");
boolean valid = true;
/*settings.backup();
for(int i = 0; i < panels.size(); i++)
{
OptionsPanel p = (OptionsPanel)panels.get(i);
try
{
p.apply();
}
catch(PrismException ex)
{
valid = false;
errors.append(p.getTabText()+" errors:\n");
errors.append(ex.getMessage());
}
}
if(!valid)
{
JOptionPane.showMessageDialog(this, errors.toString(), "Invalid Options", JOptionPane.ERROR_MESSAGE);
//restore settings
settings.restore();
}
else*/
{
//settings.backup();
settings.notifySettingsListeners();
try
{
settings.saveSettingsFile();
}
catch(PrismException e)
{
GUIPrism.getGUI().errorDialog("Error saving settings:\n"+e.getMessage());
}
}
/*try
{
JFileChooser choose = GUIPrism.getGUI().getChooser();
GUIPrismFileFilter ff = new GUIPrismFileFilter("PRISM options configuration (*.xml)");
ff.addExtension("xml");
GUIPrismFileFilter[] ffs =
{ ff };
choose.resetChoosableFileFilters();
for(int j = 0; j < ffs.length; j++)
choose.addChoosableFileFilter(ffs[j]);
choose.setFileFilter(ff);
choose.setSelectedFile(new File(""));
int result = choose.showOpenDialog(GUIPrism.getGUI());
if(result == JFileChooser.APPROVE_OPTION)
{
File file = choose.getSelectedFile();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(this);
Document doc = builder.parse(file);
Element options = doc.getDocumentElement();
NodeList children = options.getChildNodes();
for(int i = 0; i < panels.size(); i++)
{
((OptionsPanel)panels.get(i)).loadXMLElement(doc, (Element)children.item(i));
}
}
}
catch(DOMException e)
{
//TODO handle these exceptions
GUIPrism.getGUI().errorDialog("Problem loading options: DOM Exception: "+e.getMessage());
}
catch(ParserConfigurationException e)
{
GUIPrism.getGUI().errorDialog("Problem loading options: Parser Exception: "+e.getMessage());
}
catch(SAXException e)
{
GUIPrism.getGUI().errorDialog("Problem loading options: SAX Exception: "+e.getMessage());
}
catch(FileNotFoundException e)
{
GUIPrism.getGUI().errorDialog("Problem loading options: File Not Found: "+e.getMessage());
}
catch(IOException e)
{
GUIPrism.getGUI().errorDialog("Problem loading options: Input/Output exception: "+e.getMessage());
}*/
}//GEN-LAST:event_saveSettingsButtonActionPerformed
private void defaultButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_defaultButtonActionPerformed
{//GEN-HEADEREND:event_defaultButtonActionPerformed
/*for(int i = 0; i < panels.size(); i++)
{
OptionsPanel p = (OptionsPanel)panels.get(i);
p.defaultGUI();
}*/
String[] selection =
{"Yes", "No"};
int selectionNo = -1;
selectionNo = JOptionPane.showOptionDialog(this, "Are you sure you wish to load the default settings?\nAll previous settings will be lost.", "Save Settings", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, selection, selection[0]);
switch(selectionNo)
{
case 0:
{
settings.loadDefaults();
settings.notifySettingsListeners();
/*for(int i = 0; i < panels.size(); i++)
{
OptionsPanel p = (OptionsPanel)panels.get(i);
p.synchronizeGUI();
}*/
}
case 1:
{break;}
}
}//GEN-LAST:event_defaultButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed
{//GEN-HEADEREND:event_cancelButtonActionPerformed
hide();
}//GEN-LAST:event_cancelButtonActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
{
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
InputSource inputSource = null;
// override the resolve method for the dtd
if (systemId.endsWith("dtd"))
{
// get appropriate dtd from classpath
InputStream inputStream = ClassLoader.getSystemResourceAsStream("dtds/options.dtd");
if (inputStream != null) inputSource = new InputSource(inputStream);
}
return inputSource;
}
pack();
}//GEN-END:initComponents
private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveSettingsButtonActionPerformed
{//GEN-HEADEREND:event_saveSettingsButtonActionPerformed
settings.notifySettingsListeners();
try
{
settings.saveSettingsFile();
}
catch(PrismException e)
{
GUIPrism.getGUI().errorDialog("Error saving settings:\n"+e.getMessage());
}
}//GEN-LAST:event_saveSettingsButtonActionPerformed
private void defaultButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_defaultButtonActionPerformed
{//GEN-HEADEREND:event_defaultButtonActionPerformed
String[] selection =
{"Yes", "No"};
int selectionNo = -1;
selectionNo = JOptionPane.showOptionDialog(this, "Are you sure you wish to load the default settings?\nAll previous settings will be lost.", "Save Settings", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, selection, selection[0]);
if (selectionNo == 0) {
settings.loadDefaults();
settings.notifySettingsListeners();
}
}//GEN-LAST:event_defaultButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed
{//GEN-HEADEREND:event_cancelButtonActionPerformed
hide();
}//GEN-LAST:event_cancelButtonActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
{
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
// Variables declaration - do not modify//GEN-BEGIN:variables
javax.swing.JButton cancelButton;
javax.swing.JButton defaultButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JButton saveSettingsButton;
javax.swing.JTabbedPane theTabs;
// End of variables declaration//GEN-END:variables
/*public void writeToConfigFile()
{
System.out.println("writing to config file");
try
{
URL url = ClassLoader.getSystemResource("config");
File file = new File(url.getPath()+"/currentOptions.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element options = doc.createElement("options");
for(int i = 0; i < panels.size(); i++)
{
OptionsPanel op = (OptionsPanel)panels.get(i);
Element opEl = op.saveXMLElement(doc);
options.appendChild(opEl);
}
doc.appendChild(options);
//File writing
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty("doctype-system", "options.dtd");
t.setOutputProperty("indent", "yes");
t.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(file)));
}
catch(DOMException e)
{
//TODO handle these exceptions
GUIPrism.getGUI().setTaskBarText("Error exporting settings file: "+e.getMessage());
}
catch(ParserConfigurationException e)
{
GUIPrism.getGUI().setTaskBarText("Error exporting settings file: "+e.getMessage());
}
catch(TransformerConfigurationException e)
{
GUIPrism.getGUI().setTaskBarText("Error exporting settings file: "+e.getMessage());
}
catch(FileNotFoundException e)
{
GUIPrism.getGUI().setTaskBarText("Error exporting settings file: "+e.getMessage());
}
catch(TransformerException e)
{
GUIPrism.getGUI().setTaskBarText("Error exporting settings file: "+e.getMessage());
}
}
public void readFromConfigFile()
{
System.out.println("reading from config file");
try
{
URL url = ClassLoader.getSystemResource("config");
File file = new File(url.getPath()+"/currentOptions.xml");
if(file.exists())
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(this);
Document doc = builder.parse(file);
Element options = doc.getDocumentElement();
NodeList children = options.getChildNodes();
for(int i = 0; i < panels.size(); i++)
{
((OptionsPanel)panels.get(i)).loadXMLElement(doc, (Element)children.item(i));
}
}
else
{
GUIPrism.getGUI().setTaskBarText("Error importing settings file: File does not exist.");
}
}
catch(DOMException e)
{
//TODO handle these exceptions
GUIPrism.getGUI().setTaskBarText("Error importing settings file: "+e.getMessage());
}
catch(ParserConfigurationException e)
{
GUIPrism.getGUI().setTaskBarText("Error importing settings file: "+e.getMessage());
}
catch(SAXException e)
{
GUIPrism.getGUI().setTaskBarText("Error importing settings file: "+e.getMessage());
}
catch(FileNotFoundException e)
{
GUIPrism.getGUI().setTaskBarText("Error importing settings file: "+e.getMessage());
}
catch(IOException e)
{
GUIPrism.getGUI().setTaskBarText("Error importing settings file: "+e.getMessage());
}
}
public void writeToPropertiesFile()
{
File file = new File(System.getProperty("user.home")+"/.prism");
System.out.println(file.toString());
Properties properties = new Properties();
for(int i = 0; i < panels.size(); i++)
{
OptionsPanel op = (OptionsPanel)panels.get(i);
op.saveProperties(properties);
}
try
{
properties.store(new FileOutputStream(file), "prism configuration file");
}
catch(IOException e)
{
e.printStackTrace();
GUIPrism.getGUI().setTaskBarText("Error exporting properties file: "+e.getMessage());
}
}
public void readFromPropertiesFile()
{
File file = new File(System.getProperty("user.home")+"/.prism");
System.out.println(file.toString());
Properties properties = new Properties();
try
{
properties.load(new FileInputStream(file));
}
catch(IOException e)
{
e.printStackTrace();
GUIPrism.getGUI().setTaskBarText("Error importing properties file: "+e.getMessage());
}
for(int i = 0; i < panels.size(); i++)
{
OptionsPanel op = (OptionsPanel)panels.get(i);
op.loadProperties(properties);
}
}*/
// Variables declaration - do not modify//GEN-BEGIN:variables
javax.swing.JButton cancelButton;
javax.swing.JButton defaultButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JButton saveSettingsButton;
javax.swing.JTabbedPane theTabs;
// End of variables declaration//GEN-END:variables
}
Loading…
Cancel
Save