@ -38,6 +38,7 @@ import userinterface.graph.Graph;
import userinterface.graph.GraphResultListener ;
import prism.* ;
import parser.* ;
import parser.type.TypeInterval ;
public class GUIGraphPicker extends javax . swing . JDialog
{
@ -99,8 +100,7 @@ public class GUIGraphPicker extends javax.swing.JDialog
setVisible ( true ) ;
/* If OK was pressed. */
if ( ! graphCancelled )
{
if ( ! graphCancelled ) {
/* Collect series keys. */
Vector < Graph . SeriesKey > seriesKeys = new Vector < Graph . SeriesKey > ( ) ;
@ -110,22 +110,19 @@ public class GUIGraphPicker extends javax.swing.JDialog
/* Add single constant values to each serie */
seriesValues . add ( otherValues ) ;
for ( int i = 0 ; i < multiSeries . size ( ) ; i + + )
{
ArrayList < Values > temp = ( ArrayList < Values > ) seriesValues . clone ( ) ;
for ( int i = 0 ; i < multiSeries . size ( ) ; i + + ) {
ArrayList < Values > temp = ( ArrayList < Values > ) seriesValues . clone ( ) ;
seriesValues . clear ( ) ;
/ / For each of the possible value in the range
for ( int j = 0 ; j < multiSeries . get ( i ) . getNumSteps ( ) ; j + + )
{
for ( int j = 0 ; j < multiSeries . get ( i ) . getNumSteps ( ) ; j + + ) {
/ / Clone the list
ArrayList copy = ( ArrayList < Values > ) temp . clone ( ) ;
ArrayList copy = ( ArrayList < Values > ) temp . clone ( ) ;
/ / For each element in the list
for ( int k = 0 ; k < copy . size ( ) ; k + + )
{
for ( int k = 0 ; k < copy . size ( ) ; k + + ) {
Values v = new Values ( ) ;
Values cp = ( Values ) copy . get ( k ) ;
Values cp = ( Values ) copy . get ( k ) ;
v . addValues ( cp ) ;
v . addValue ( multiSeries . get ( i ) . getName ( ) , multiSeries . get ( i ) . getValue ( j ) ) ;
seriesValues . add ( v ) ;
@ -134,25 +131,30 @@ public class GUIGraphPicker extends javax.swing.JDialog
}
/* Do all series settings. */
for ( int serie = 0 ; serie < seriesValues . size ( ) ; serie + + ) / / each combination of series
for ( int serie = 0 ; serie < seriesValues . size ( ) ; serie + + ) / / each combination of series
{
Values values = seriesValues . get ( serie ) ;
String seriesName = ( seriesValues . size ( ) > 1 ) ? values . toString ( ) : seriesNameField . getText ( ) ;
/ / For properties that return an interval , we add a pair of series
/ / ( the pair is stored as a linked list )
if ( experiment . getPropertyType ( ) instanceof TypeInterval ) {
Graph . SeriesKey key = graphModel . addSeries ( seriesName + " (min)" ) ;
key . next = graphModel . addSeries ( seriesName + " (max)" ) ;
seriesKeys . add ( key ) ;
} else {
seriesKeys . add ( graphModel . addSeries ( seriesName ) ) ;
}
}
/* If there are results already, then lets render them! */
if ( resultsKnown & & resultsCollection . getCurrentIteration ( ) > 0 )
{
for ( int series = 0 ; series < seriesValues . size ( ) ; series + + ) / / each combination of series
if ( resultsKnown & & resultsCollection . getCurrentIteration ( ) > 0 ) {
for ( int series = 0 ; series < seriesValues . size ( ) ; series + + ) / / each combination of series
{
Values values = seriesValues . get ( series ) ;
Graph . SeriesKey seriesKey = seriesKeys . get ( series ) ;
/** Range over x-axis. */
for ( int i = 0 ; i < rangingConstant . getNumSteps ( ) ; i + + )
{
for ( int i = 0 ; i < rangingConstant . getNumSteps ( ) ; i + + ) {
Object value = rangingConstant . getValue ( i ) ;
/** Values used in the one experiment for this series. */
@ -161,47 +163,50 @@ public class GUIGraphPicker extends javax.swing.JDialog
useThis . addValue ( ranger , value ) ;
/** Get this particular result. **/
try
{
try {
Object result = resultsCollection . getResult ( useThis ) ;
double x = 0 , y = 0 ;
double x = 0 , y = 0 ;
boolean validX = true ;
boolean validY = true ;
if ( value instanceof Double )
{ x = ( ( Double ) value ) . doubleValue ( ) ; }
else if ( value instanceof Integer )
{ x = ( ( Integer ) value ) . intValue ( ) ; }
else
{ validX = false ; }
/ / For now , to plot intervals , just pick lower value
if ( result instanceof Interval ) {
result = ( ( Interval ) result ) . lower ;
}
if ( result instanceof Double )
{ y = ( ( Double ) result ) . doubleValue ( ) ; }
else if ( value instanceof Integer )
{ y = ( ( Integer ) result ) . intValue ( ) ; }
else
{ validY = false ; }
if ( validX & & validY ) {
graphModel . addPointToSeries ( seriesKey , new XYDataItem ( x , y ) ) ;
}
}
catch ( PrismException pe )
{
if ( value instanceof Double ) {
x = ( ( Double ) value ) . doubleValue ( ) ;
} else if ( value instanceof Integer ) {
x = ( ( Integer ) value ) . intValue ( ) ;
} else {
validX = false ;
}
/ / Add point to graph ( if of valid type )
if ( validX ) {
if ( result instanceof Double ) {
y = ( ( Double ) result ) . doubleValue ( ) ;
graphModel . addPointToSeries ( seriesKey , new XYDataItem ( x , y ) ) ;
} else if ( result instanceof Integer ) {
y = ( ( Integer ) result ) . intValue ( ) ;
graphModel . addPointToSeries ( seriesKey , new XYDataItem ( x , y ) ) ;
} else if ( result instanceof Interval ) {
Interval interval = ( Interval ) result ;
if ( interval . lower instanceof Double ) {
y = ( ( Double ) interval . lower ) . doubleValue ( ) ;
graphModel . addPointToSeries ( seriesKey , new XYDataItem ( x , y ) ) ;
y = ( ( Double ) interval . upper ) . doubleValue ( ) ;
graphModel . addPointToSeries ( seriesKey . next , new XYDataItem ( x , y ) ) ;
} else if ( result instanceof Integer ) {
y = ( ( Integer ) interval . lower ) . intValue ( ) ;
graphModel . addPointToSeries ( seriesKey , new XYDataItem ( x , y ) ) ;
y = ( ( Integer ) interval . upper ) . intValue ( ) ;
graphModel . addPointToSeries ( seriesKey . next , new XYDataItem ( x , y ) ) ;
}
}
}
} catch ( PrismException pe ) {
/ / No result found .
}
}
}
}
else if ( ! resultsKnown & & resultsCollection . getCurrentIteration ( ) = = 0 )
{
for ( int series = 0 ; series < seriesValues . size ( ) ; series + + ) / / each combination of series
} else if ( ! resultsKnown & & resultsCollection . getCurrentIteration ( ) = = 0 ) {
for ( int series = 0 ; series < seriesValues . size ( ) ; series + + ) / / each combination of series
{
Values values = seriesValues . get ( series ) ;
Graph . SeriesKey seriesKey = seriesKeys . get ( series ) ;
@ -231,21 +236,20 @@ public class GUIGraphPicker extends javax.swing.JDialog
/ / for each ranging constant in rc , add :
/ / ( 1 ) a row in the picker list
/ / ( 2 ) an item in the "x axis" drop down menu
for ( int i = 0 ; i < resultsCollection . getRangingConstants ( ) . size ( ) ; i + + )
{
DefinedConstant dc = ( DefinedConstant ) resultsCollection . getRangingConstants ( ) . get ( i ) ;
for ( int i = 0 ; i < resultsCollection . getRangingConstants ( ) . size ( ) ; i + + ) {
DefinedConstant dc = ( DefinedConstant ) resultsCollection . getRangingConstants ( ) . get ( i ) ;
pickerList . addConstant ( new GraphConstantLine ( dc , this ) ) ;
this . selectAxisConstantCombo . addItem ( dc . getName ( ) ) ;
}
/ / select the first constant for the x axis
if ( selectAxisConstantCombo . getItemCount ( ) > 0 ) selectAxisConstantCombo . setSelectedIndex ( 0 ) ;
if ( selectAxisConstantCombo . getItemCount ( ) > 0 )
selectAxisConstantCombo . setSelectedIndex ( 0 ) ;
/ / and disable it in the picker list
pickerList . disableLine ( 0 ) ;
/ / if there is only one ranging constant , disable controls
if ( resultsCollection . getRangingConstants ( ) . size ( ) = = 1 )
{
if ( resultsCollection . getRangingConstants ( ) . size ( ) = = 1 ) {
selectAxisConstantCombo . setEnabled ( false ) ;
pickerList . setEnabled ( false ) ;
header . setEnabled ( false ) ;
@ -257,13 +261,11 @@ public class GUIGraphPicker extends javax.swing.JDialog
this . newGraphRadio . setSelected ( true ) ;
/ / add existing graphs to choose from
for ( int i = 0 ; i < graphHandler . getNumModels ( ) ; i + + )
{
for ( int i = 0 ; i < graphHandler . getNumModels ( ) ; i + + ) {
existingGraphCombo . addItem ( graphHandler . getGraphName ( i ) ) ;
}
/ / if there are no graphs , disable control
if ( graphHandler . getNumModels ( ) = = 0 )
{
if ( graphHandler . getNumModels ( ) = = 0 ) {
existingGraphCombo . setEnabled ( false ) ;
this . existingGraphRadio . setEnabled ( false ) ;
}
@ -288,8 +290,7 @@ public class GUIGraphPicker extends javax.swing.JDialog
DefinedConstant temp ;
Object value ;
if ( selectAxisConstantCombo . getSelectedItem ( ) = = null )
{
if ( selectAxisConstantCombo . getSelectedItem ( ) = = null ) {
return ;
}
@ -299,35 +300,30 @@ public class GUIGraphPicker extends javax.swing.JDialog
otherValues = new Values ( ) ;
multiSeries = new Vector < DefinedConstant > ( ) ;
/ / go through constants in picker list
for ( int j = 0 ; j < pickerList . getNumConstants ( ) ; j + + )
{
for ( int j = 0 ; j < pickerList . getNumConstants ( ) ; j + + ) {
/ / get constant
temp = pickerList . getConstantLine ( j ) . getDC ( ) ;
/ / ignore constant for x - axis
if ( temp . getName ( ) . equals ( ranger ) ) continue ;
if ( temp . getName ( ) . equals ( ranger ) )
continue ;
/ / get value
value = pickerList . getConstantLine ( j ) . getSelectedValue ( ) ;
/ / if we find any constants selected "All Series" , clear name , disable and bail out
if ( value instanceof String )
{
if ( value instanceof String ) {
this . seriesNameLabel . setEnabled ( false ) ;
this . seriesNameField . setText ( "" ) ;
this . seriesNameField . setEnabled ( false ) ;
return ;
}
/ / we add other constants to a list
else
{
else {
otherValues . addValue ( temp . getName ( ) , value ) ;
}
}
/ / use values object string for name
if ( otherValues . getNumValues ( ) ! = 0 )
{
if ( otherValues . getNumValues ( ) ! = 0 ) {
this . seriesNameField . setText ( otherValues . toString ( ) ) ;
}
else
{
} else {
this . seriesNameField . setText ( "New Series" ) ;
}
this . seriesNameLabel . setEnabled ( true ) ;
@ -583,28 +579,22 @@ public class GUIGraphPicker extends javax.swing.JDialog
multiSeries = new Vector < DefinedConstant > ( ) ;
/ / go through all constants in picker list
for ( int j = 0 ; j < pickerList . getNumConstants ( ) ; j + + )
{
for ( int j = 0 ; j < pickerList . getNumConstants ( ) ; j + + ) {
/ / get constant
DefinedConstant tmpConstant = pickerList . getConstantLine ( j ) . getDC ( ) ;
/ / if its the constant for the x - axis , store info about the constant
if ( tmpConstant . getName ( ) . equals ( ranger ) )
{
if ( tmpConstant . getName ( ) . equals ( ranger ) ) {
rangingConstant = tmpConstant ;
}
/ / otherwise store info about the selected values
else
{
else {
/ / Is this constant just a value , or does it have a range ?
Object value = pickerList . getConstantLine ( j ) . getSelectedValue ( ) ;
if ( value instanceof String )
{
if ( value instanceof String ) {
/* Yes, calculate the numSeries. */
multiSeries . add ( pickerList . getConstantLine ( j ) . getDC ( ) ) ;
numSeries * = tmpConstant . getNumSteps ( ) ;
}
else
{
} else {
/* No, just the one. */
otherValues . addValue ( tmpConstant . getName ( ) , value ) ;
}
@ -612,34 +602,32 @@ public class GUIGraphPicker extends javax.swing.JDialog
}
/ / sort out which one to add it to
if ( rangingConstant = = null )
if ( rangingConstant = = null )
return ;
/ / if there are a lot of series , check if this is what the user really wanted
if ( numSeries > MAX_NUM_SERIES_BEFORE_QUERY ) {
String [ ] choices =
{ "Yes" , "No" } ;
String [ ] choices = { "Yes" , "No" } ;
int choice = - 1 ;
choice = plugin . optionPane ( "Warning: This will plot " + numSeries + " series.\nAre you sure you want to continue?" , "Question" , JOptionPane . YES_NO_OPTION , JOptionPane . QUESTION_MESSAGE , choices , choices [ 0 ] ) ;
if ( choice ! = 0 ) return ;
choice = plugin . optionPane ( "Warning: This will plot " + numSeries + " series.\nAre you sure you want to continue?" , "Question" ,
JOptionPane . YES_NO_OPTION , JOptionPane . QUESTION_MESSAGE , choices , choices [ 0 ] ) ;
if ( choice ! = 0 )
return ;
}
if ( newGraphRadio . isSelected ( ) )
{
if ( newGraphRadio . isSelected ( ) ) {
/* Make new graph. */
graphModel = new Graph ( ) ;
graphHandler . addGraph ( graphModel ) ;
graphModel . getYAxisSettings ( ) . setHeading ( resultsCollection . getResultName ( ) ) ;
graphModel . getXAxisSettings ( ) . setHeading ( ranger ) ;
}
else
{
} else {
/* Add to an existing graph. */
graphModel = graphHandler . getModel ( existingGraphCombo . getSelectedItem ( ) . toString ( ) ) ;
if ( ! ranger . equals ( graphModel . getXAxisSettings ( ) . getHeading ( ) ) ) / / FIXME : must do this better in future
if ( ! roughExists ( ranger , graphModel . getXAxisSettings ( ) . getHeading ( ) ) )
graphModel . getXAxisSettings ( ) . setHeading ( graphModel . getXAxisSettings ( ) . getHeading ( ) + ", " + ranger ) ;
if ( ! ranger . equals ( graphModel . getXAxisSettings ( ) . getHeading ( ) ) ) / / FIXME : must do this better in future
if ( ! roughExists ( ranger , graphModel . getXAxisSettings ( ) . getHeading ( ) ) )
graphModel . getXAxisSettings ( ) . setHeading ( graphModel . getXAxisSettings ( ) . getHeading ( ) + ", " + ranger ) ;
}
graphCancelled = false ;
@ -695,22 +683,28 @@ public class GUIGraphPicker extends javax.swing.JDialog
private javax . swing . JTextField seriesNameField ;
private javax . swing . JLabel seriesNameLabel ;
private javax . swing . JLabel topComboLabel ;
/ / End of variables declaration
public static int factorial ( int i )
{
if ( i < 0 ) return 1 ;
if ( i = = 0 ) return 1 ;
if ( i < 0 )
return 1 ;
if ( i = = 0 )
return 1 ;
else
return i * factorial ( i - 1 ) ;
return i * factorial ( i - 1 ) ;
}
public static boolean roughExists ( String test , String inThis )
{
int i = inThis . indexOf ( test ) ;
if ( i = = - 1 ) return false ;
if ( ! ( ( i = = 0 ) | | ( inThis . charAt ( i - 1 ) = = ' ' ) ) ) return false ;
if ( ! ( ( inThis . length ( ) = = i + 1 ) | | ( inThis . charAt ( i + 1 ) = = ',' ) ) ) return false ;
if ( i = = - 1 )
return false ;
if ( ! ( ( i = = 0 ) | | ( inThis . charAt ( i - 1 ) = = ' ' ) ) )
return false ;
if ( ! ( ( inThis . length ( ) = = i + 1 ) | | ( inThis . charAt ( i + 1 ) = = ',' ) ) )
return false ;
return true ;
}
}