@ -70,7 +70,7 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
private JTable initValuesTable ;
private DefineValuesTable initValuesModel ;
/ / Last valid contents of tet x boxes
/ / Last valid contents of text boxes
private String lastWidth ;
private String lastConf ;
private String lastNumSamples ;
@ -79,6 +79,7 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
private boolean atLeastOneQuant ;
/ / Variables declaration - do not modify / / GEN - BEGIN : variables
/ / Note : this code has now been modified manually ; form is no longer used .
javax . swing . JTextField widthField ;
javax . swing . JComboBox selectSimulationMethod ;
javax . swing . JComboBox automaticCalculateCombo ;
@ -116,6 +117,7 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
private javax . swing . JButton okayButton ;
javax . swing . JTextField pathLengthField ;
javax . swing . JPanel topPanel ;
javax . swing . JCheckBox useDefaultInitialCheck ;
/ / End of variables declaration / / GEN - END : variables
@ -176,16 +178,18 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
/ / create "initial state" table
initValuesModel = new DefineValuesTable ( ) ;
initValuesTable = new JTable ( ) ;
initValuesTable = new Greyable JTable( ) ;
initValuesTable . setModel ( initValuesModel ) ;
initValuesTable . setSelectionMode ( DefaultListSelectionModel . SINGLE_INTERVAL_SELECTION ) ;
initValuesTable . setCellSelectionEnabled ( true ) ;
/ / set up simulation information based on previous info ( or defaults - see above )
information = lastSimulationInformation ;
/ / set initial state as passed in to constructor
information . setInitialState ( modulesFile . getInitialValues ( ) ) ;
/ / currently , we deliberately do not recall the last initial state used
/ / since it may no longer be valid due to changes in the model
information . setInitialState ( null ) ;
/ / initialise
initComponents ( ) ;
this . getRootPane ( ) . setDefaultButton ( okayButton ) ;
@ -206,6 +210,7 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
* initialize the form .
* WARNING : Do NOT modify this code . The content of this method is
* always regenerated by the Form Editor .
* Note : this code has now been modified manually ; form is no longer used .
* /
private void initComponents ( ) / / GEN - BEGIN : initComponents
{
@ -248,6 +253,7 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
jPanel19 = new javax . swing . JPanel ( ) ;
jPanel20 = new javax . swing . JPanel ( ) ;
/ / distributedCheck = new javax . swing . JCheckBox ( ) ;
useDefaultInitialCheck = new javax . swing . JCheckBox ( ) ;
addWindowListener ( new java . awt . event . WindowAdapter ( )
{
@ -307,9 +313,22 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
gridBagConstraints . gridx = 0 ;
gridBagConstraints . gridy = 4 ;
jPanel1 . add ( jPanel5 , gridBagConstraints ) ;
useDefaultInitialCheck . setText ( "Use default initial state" ) ;
useDefaultInitialCheck . addActionListener ( new java . awt . event . ActionListener ( )
{
public void actionPerformed ( java . awt . event . ActionEvent evt )
{
useDefaultInitialCheckActionPerformed ( evt ) ;
}
} ) ;
gridBagConstraints = new java . awt . GridBagConstraints ( ) ;
gridBagConstraints . gridx = 1 ;
gridBagConstraints . gridy = 1 ;
gridBagConstraints . fill = java . awt . GridBagConstraints . BOTH ;
jPanel1 . add ( useDefaultInitialCheck , gridBagConstraints ) ;
topPanel . setLayout ( new java . awt . BorderLayout ( ) ) ;
gridBagConstraints = new java . awt . GridBagConstraints ( ) ;
gridBagConstraints . gridx = 1 ;
gridBagConstraints . gridy = 3 ;
@ -784,47 +803,34 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
topPanel . setPreferredSize ( new Dimension ( 300 , 300 ) ) ;
}
/ * *
* Populate dialog using ' information ' field .
* /
private void initValues ( )
{
Value v ;
/ / Use default initial state ?
/ / ( currently always the case on initialisation )
if ( information . getInitialState ( ) = = null ) {
/ *
int n , i , j , n2 ;
Declaration decl ;
Module module ;
/ / first add all globals
n = mf . getNumGlobals ( ) ;
for ( i = 0 ; i < n ; i + + )
{
decl = mf . getGlobal ( i ) ;
v = new Value ( decl . getName ( ) , decl . getType ( ) , "" ) ;
initValuesModel . addValue ( v ) ;
/ / Tick box
useDefaultInitialCheck . setSelected ( true ) ;
/ / Put variable names in table , but no values
for ( int i = 0 ; i < modulesFile . getNumVars ( ) ; i + + ) {
initValuesModel . addValue ( new Value ( modulesFile . getVarName ( i ) , modulesFile . getVarType ( i ) , null ) ) ;
}
/ / then add all module variables
n = mf . getNumModules ( ) ;
for ( i = 0 ; i < n ; i + + )
{
module = mf . getModule ( i ) ;
n2 = module . getNumDeclarations ( ) ;
for ( j = 0 ; j < n2 ; j + + )
{
decl = module . getDeclaration ( j ) ;
v = new Value ( decl . getName ( ) , decl . getType ( ) , "" ) ;
initValuesModel . addValue ( v ) ;
}
}
* /
/ / Disable table
if ( initValuesTable . getCellEditor ( ) ! = null )
initValuesTable . getCellEditor ( ) . stopCellEditing ( ) ;
initValuesTable . getSelectionModel ( ) . clearSelection ( ) ;
initValuesTable . setEnabled ( false ) ;
} else {
for ( int i = 0 ; i < information . getInitialState ( ) . getNumValues ( ) ; i + + ) {
try {
v = new Value ( information . getInitialState ( ) . getName ( i ) , information . getInitialState ( ) . getType ( i ) , information . getInitialState ( ) . getValue ( i ) ) ;
initValuesModel . addValue ( v ) ;
} catch ( Exception e ) {
}
/ / Untick box
useDefaultInitialCheck . setSelected ( false ) ;
/ / Set up table ( from information )
/ / Need to add to add some validity checks here if re - enabled
for ( int i = 0 ; i < modulesFile . getNumVars ( ) ; i + + ) {
initValuesModel . addValue ( new Value ( modulesFile . getVarName ( i ) , modulesFile . getVarType ( i ) , information . getInitialState ( ) . getValue ( i ) ) ) ;
}
initValuesTable . setEnabled ( true ) ;
}
/ / populate parameter text boxes
@ -842,10 +848,6 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
/ / distributedCheck . setSelected ( information . isDistributed ( ) ) ;
}
/ * * Call this static method to construct a new GUIValuesPicker to define
* initialState . If you don ' t want any default values , then pass in null for
* initDefaults
* /
/ * *
* Create a new GUIConstantsPicker dialog to define info for simulation - based property checking .
* @param parent Parent GUI window
@ -940,23 +942,72 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
}
information . setMaxPathLength ( maxPathLength ) ;
/ / Store initial state
Values newInitState = new Values ( ) ;
for ( i = 0 ; i < initValuesModel . getNumValues ( ) ; i + + ) {
parameter = initValuesModel . getValue ( i ) . name ;
newInitState . addValue ( initValuesModel . getValue ( i ) . name , initValuesModel . getValue ( i ) . value ) ;
if ( useDefaultInitialCheck . isSelected ( ) ) {
information . setInitialState ( null ) ;
} else {
Values newInitState = new Values ( ) ;
for ( i = 0 ; i < initValuesModel . getNumValues ( ) ; i + + ) {
parameter = initValuesModel . getValue ( i ) . name ;
Object parameterValue = null ;
if ( initValuesModel . getValue ( i ) . type instanceof TypeBool ) {
String bool = initValuesModel . getValue ( i ) . value . toString ( ) ;
if ( ! ( bool . equals ( "true" ) | | bool . equals ( "false" ) ) )
throw new NumberFormatException ( ) ;
parameterValue = new Boolean ( bool ) ;
} else if ( initValuesModel . getValue ( i ) . type instanceof TypeInt ) {
parameterValue = new Integer ( initValuesModel . getValue ( i ) . value . toString ( ) ) ;
} else {
throw new NumberFormatException ( ) ;
}
newInitState . addValue ( parameter , parameterValue ) ;
}
information . setInitialState ( newInitState ) ;
}
information . setInitialState ( newInitState ) ;
/ / information . setDistributed ( distributedCheck . isSelected ( ) ) ;
cancelled = false ;
lastSimulationInformation = information ;
dispose ( ) ;
} catch ( NumberFormatException e ) {
gui . errorDialog ( "Invalid number value entered for parameter \"" + parameter + "\"" ) ;
gui . errorDialog ( "Invalid value entered for parameter \"" + parameter + "\"" ) ;
}
} / / GEN - LAST : event_okayButtonActionPerformed
private void useDefaultInitialCheckActionPerformed ( java . awt . event . ActionEvent evt )
{
/ / If ticking . . .
if ( useDefaultInitialCheck . isSelected ( ) ) {
/ / Clear values in table
for ( int i = 0 ; i < modulesFile . getNumVars ( ) ; i + + ) {
initValuesModel . getValue ( i ) . value = null ;
}
/ / Disable table
if ( initValuesTable . getCellEditor ( ) ! = null )
initValuesTable . getCellEditor ( ) . stopCellEditing ( ) ;
initValuesTable . getSelectionModel ( ) . clearSelection ( ) ;
initValuesTable . setEnabled ( false ) ;
}
/ / If unticking
else {
/ / Set up table ( based on default initial state )
try {
State defaultInitialState = modulesFile . getDefaultInitialState ( ) ;
if ( defaultInitialState = = null )
throw new PrismException ( "" ) ;
for ( int i = 0 ; i < modulesFile . getNumVars ( ) ; i + + ) {
initValuesModel . getValue ( i ) . value = defaultInitialState . varValues [ i ] ;
}
} catch ( PrismException e ) {
/ / In case of error , clear values
for ( int i = 0 ; i < modulesFile . getNumVars ( ) ; i + + ) {
initValuesModel . getValue ( i ) . value = null ;
}
}
initValuesTable . setEnabled ( true ) ;
}
}
private void cancelButtonActionPerformed ( java . awt . event . ActionEvent evt ) / / GEN - FIRST : event_cancelButtonActionPerformed
{ / / GEN - HEADEREND : event_cancelButtonActionPerformed
dispose ( ) ;
@ -1028,7 +1079,7 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
case 1 :
return v . type . getTypeString ( ) ;
case 2 :
return v . value . toString ( ) ;
return v . value = = null ? "" : v . value . toString ( ) ;
default :
return "" ;
}
@ -1095,7 +1146,28 @@ public class GUISimulationPicker extends javax.swing.JDialog implements KeyListe
public String toString ( )
{
return name + "=" + value . toString ( ) ;
return name + "=" + value ;
}
}
public class GreyableJTable extends JTable
{
private static final long serialVersionUID = 1L ;
private TableCellRenderer tableCellRenderer = new TableCellRenderer ( )
{
private static final long serialVersionUID = 1L ;
public Component getTableCellRendererComponent ( JTable table , Object value , boolean isSelected , boolean hasFocus , int row , int column )
{
Component c = GreyableJTable . super . getCellRenderer ( row , column ) . getTableCellRendererComponent ( table , value , isSelected , hasFocus , row , column ) ;
c . setEnabled ( table ! = null & & table . isEnabled ( ) ) ;
return c ;
}
} ;
public TableCellRenderer getCellRenderer ( int row , int column )
{
return tableCellRenderer ;
}
}
}