@ -41,24 +41,24 @@ import com.jme3.export.binary.BinaryImporter;
* @author Marcin Roguski ( Kaelthas )
* /
public class ConfigDialog extends AbstractConfigDialog {
private static final long serialVersionUID = 2863364888664674247L ;
private static final Logger LOGGER = Logger . getLogger ( ConfigDialog . class . getName ( ) ) ;
private String baseFolderName ;
private File configFile ; //the config file
private Map < String , BlenderKeyConfiguration > configMap ; //the blender key configuration map
private BlenderKeyConfiguration blenderKeyConfiguration ; //the configuration for the files
private IConfigExecutable configExecutable ; //this is called after clicking the 'OK' button
private ConfigExecutable configExecutable ; //this is called after clicking the 'OK' button
/ * *
* Constructor . Builds the whole window and stores its data .
* @param testAssetsFolderName the path to test files folder
* /
public ConfigDialog ( String baseFolderName , I ConfigExecutable configExecutable ) {
if ( baseFolderName = = null ) {
public ConfigDialog ( String baseFolderName , ConfigExecutable configExecutable ) {
if ( baseFolderName = = null ) {
throw new IllegalArgumentException ( "No test asset folder given!" ) ;
}
if ( configExecutable = = null ) {
if ( configExecutable = = null ) {
throw new IllegalArgumentException ( "No config executable given!" ) ;
}
this . baseFolderName = baseFolderName ;
@ -67,17 +67,18 @@ public class ConfigDialog extends AbstractConfigDialog {
//setting up version selection (as a folder list in a compo box)
File baseFolder = new File ( baseFolderName ) ;
if ( ! baseFolder . exists ( ) | | ! baseFolder . isDirectory ( ) ) {
if ( ! baseFolder . exists ( ) | | ! baseFolder . isDirectory ( ) ) {
throw new IllegalArgumentException ( "The given base folder path either does not exists or does not point to a directory!" ) ;
}
File [ ] folders = baseFolder . listFiles ( new FileFilter ( ) {
@Override
public boolean accept ( File file ) {
return file . isDirectory ( ) & & file . getName ( ) . charAt ( 0 ) ! = '.' ;
return file . isDirectory ( ) & & file . getName ( ) . charAt ( 0 ) ! = '.' ;
}
} ) ;
for ( File folder : folders ) {
( ( DefaultComboBoxModel ) jComboBoxVersionSelection . getModel ( ) ) . addElement ( folder . getName ( ) ) ;
for ( File folder : folders ) {
( ( DefaultComboBoxModel ) jComboBoxVersionSelection . getModel ( ) ) . addElement ( folder . getName ( ) ) ;
configMap . put ( folder . getName ( ) , null ) ;
}
this . initListeners ( ) ;
@ -103,6 +104,7 @@ public class ConfigDialog extends AbstractConfigDialog {
//loading blender files
File [ ] blenderFiles = testAssetsFolder . listFiles ( new FileFilter ( ) {
@Override
public boolean accept ( File file ) {
return file . isFile ( ) & & file . canRead ( ) & & file . getName ( ) . endsWith ( ".blend" ) ;
@ -111,6 +113,7 @@ public class ConfigDialog extends AbstractConfigDialog {
//loading the blender files configuration
File [ ] files = testAssetsFolder . listFiles ( new FileFilter ( ) {
@Override
public boolean accept ( File file ) {
return file . isFile ( ) & & file . canRead ( ) & & file . getName ( ) . endsWith ( ".conf" ) ;
@ -121,9 +124,9 @@ public class ConfigDialog extends AbstractConfigDialog {
} else {
BinaryImporter jmeImporter = new BinaryImporter ( ) ;
String instructionToUser = files . length = = 1 ?
"No other config file to load! No configuration set!" :
"Please choose different config file!" ;
String instructionToUser = files . length = = 1
? "No other config file to load! No configuration set!"
: "Please choose different config file!" ;
do {
if ( files . length > 1 ) {
configFile = ( File ) JOptionPane . showInputDialog ( null , "Choose the config file!" , "Config file selection" ,
@ -131,7 +134,7 @@ public class ConfigDialog extends AbstractConfigDialog {
} else {
configFile = files [ 0 ] ;
}
if ( configFile = = null ) {
if ( configFile = = null ) {
JOptionPane . showMessageDialog ( this , "No config file selected!\nEmpty configuration will be created!" ,
"No configuration selected" , JOptionPane . INFORMATION_MESSAGE ) ;
blenderKeyConfiguration = new BlenderKeyConfiguration ( blenderFiles . length ) ;
@ -155,7 +158,7 @@ public class ConfigDialog extends AbstractConfigDialog {
LOGGER . log ( Level . SEVERE , "Unable to load configuration due to unpredicted error!" , e ) ;
}
}
} while ( blenderKeyConfiguration = = null & & files . length > 1 ) ;
} while ( blenderKeyConfiguration = = null & & files . length > 1 ) ;
}
configFile = new File ( testAssetsFolder , "test.conf" ) ;
@ -164,7 +167,7 @@ public class ConfigDialog extends AbstractConfigDialog {
//enlisting the files in the list
DefaultListModel defaultListModel = ( DefaultListModel ) jListBlenderFiles . getModel ( ) ;
defaultListModel . removeAllElements ( ) ;
for ( int i = 0 ; i < blenderFiles . length ; + + i ) {
for ( int i = 0 ; i < blenderFiles . length ; + + i ) {
defaultListModel . addElement ( new FileListItem ( blenderFiles [ i ] ) ) ;
}
return blenderFiles ;
@ -178,17 +181,17 @@ public class ConfigDialog extends AbstractConfigDialog {
//setting properties
BlenderTableModel propertiesModel = ( BlenderTableModel ) jTableProperties . getModel ( ) ;
int rowCount = propertiesModel . getRowCount ( ) ;
for ( int i = 0 ; i < rowCount ; + + i ) {
for ( int i = 0 ; i < rowCount ; + + i ) {
propertiesModel . removeRow ( 0 ) ;
}
Field [ ] fields = blenderKey . getClass ( ) . getDeclaredFields ( ) ;
for ( Field field : fields ) {
for ( Field field : fields ) {
field . setAccessible ( true ) ;
if ( ! "animations" . equalsIgnoreCase ( field . getName ( ) ) & &
( field . getModifiers ( ) & Modifier . STATIC ) = = 0 ) {
if ( ! "animations" . equalsIgnoreCase ( field . getName ( ) )
& & ( field . getModifiers ( ) & Modifier . STATIC ) = = 0 ) {
try {
propertiesModel . addRow ( new Object [ ] { field . getName ( ) , field . get ( blenderKey ) } ) ;
propertiesModel . addRow ( new Object [ ] { field . getName ( ) , field . get ( blenderKey ) } ) ;
} catch ( IllegalArgumentException e ) {
LOGGER . log ( Level . SEVERE , e . getMessage ( ) , e ) ;
} catch ( IllegalAccessException e ) {
@ -200,15 +203,15 @@ public class ConfigDialog extends AbstractConfigDialog {
//setting animations
DefaultTableModel animationsModel = ( DefaultTableModel ) jTableAnimations . getModel ( ) ;
rowCount = animationsModel . getRowCount ( ) ;
for ( int i = 0 ; i < rowCount ; + + i ) {
for ( int i = 0 ; i < rowCount ; + + i ) {
animationsModel . removeRow ( 0 ) ;
}
Map < String , Map < String , int [ ] > > animations = blenderKey . getAnimations ( ) ;
if ( animations ! = null ) {
for ( Entry < String , Map < String , int [ ] > > animationEntry : animations . entrySet ( ) ) {
for ( Entry < String , int [ ] > animDataEntry : animationEntry . getValue ( ) . entrySet ( ) ) {
if ( animations ! = null ) {
for ( Entry < String , Map < String , int [ ] > > animationEntry : animations . entrySet ( ) ) {
for ( Entry < String , int [ ] > animDataEntry : animationEntry . getValue ( ) . entrySet ( ) ) {
int [ ] frames = animDataEntry . getValue ( ) ;
animationsModel . addRow ( new Object [ ] { animationEntry . getKey ( ) , animDataEntry . getKey ( ) ,
animationsModel . addRow ( new Object [ ] { animationEntry . getKey ( ) , animDataEntry . getKey ( ) ,
Integer . valueOf ( frames [ 0 ] ) , Integer . valueOf ( frames [ 1 ] ) } ) ;
}
}
@ -224,23 +227,23 @@ public class ConfigDialog extends AbstractConfigDialog {
* @param configuration the blender config to store
* /
private void storeConfig ( BlenderKeyConfiguration configuration ) {
if ( configuration . lastUsedKey ! = null ) { //reading animations
DefaultTableModel animationsTableModel = ( DefaultTableModel ) jTableAnimations . getModel ( ) ;
if ( configuration . lastUsedKey . getAnimations ( ) ! = null ) {
if ( configuration . lastUsedKey ! = null ) { //reading animations
DefaultTableModel animationsTableModel = ( DefaultTableModel ) jTableAnimations . getModel ( ) ;
if ( configuration . lastUsedKey . getAnimations ( ) ! = null ) {
configuration . lastUsedKey . getAnimations ( ) . clear ( ) ;
}
int animCounter = 0 ;
for ( int i = 0 ; i < animationsTableModel . getRowCount ( ) ; + + i ) {
String objectName = ( String ) animationsTableModel . getValueAt ( i , 0 ) ;
String animName = ( String ) animationsTableModel . getValueAt ( i , 1 ) ;
Number startFrame = ( Number ) animationsTableModel . getValueAt ( i , 2 ) ;
Number stopFrame = ( Number ) animationsTableModel . getValueAt ( i , 3 ) ;
if ( objectName ! = null & & animName ! = null & & startFrame . intValue ( ) < = stopFrame . intValue ( ) ) {
for ( int i = 0 ; i < animationsTableModel . getRowCount ( ) ; + + i ) {
String objectName = ( String ) animationsTableModel . getValueAt ( i , 0 ) ;
String animName = ( String ) animationsTableModel . getValueAt ( i , 1 ) ;
Number startFrame = ( Number ) animationsTableModel . getValueAt ( i , 2 ) ;
Number stopFrame = ( Number ) animationsTableModel . getValueAt ( i , 3 ) ;
if ( objectName ! = null & & animName ! = null & & startFrame . intValue ( ) < = stopFrame . intValue ( ) ) {
configuration . lastUsedKey . addAnimation ( objectName , animName , startFrame . intValue ( ) , stopFrame . intValue ( ) ) ;
+ + animCounter ;
}
}
if ( animCounter < animationsTableModel . getRowCount ( ) ) {
if ( animCounter < animationsTableModel . getRowCount ( ) ) {
JOptionPane . showMessageDialog ( ConfigDialog . this , "Some animations had errors!\nThey had not been added!" ,
"Invalid animations definitions" , JOptionPane . WARNING_MESSAGE ) ;
}
@ -252,7 +255,7 @@ public class ConfigDialog extends AbstractConfigDialog {
//storing the config
JmeExporter jmeExporter = new BinaryExporter ( ) ;
try {
if ( ! jmeExporter . save ( configuration , configFile ) ) {
if ( ! jmeExporter . save ( configuration , configFile ) ) {
JOptionPane . showMessageDialog ( ConfigDialog . this , "Unable to save the config data!" , "Config save problem" , JOptionPane . ERROR_MESSAGE ) ;
}
} catch ( IOException e ) {
@ -267,25 +270,26 @@ public class ConfigDialog extends AbstractConfigDialog {
private void initListeners ( ) {
//selection of blender version
jComboBoxVersionSelection . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent evt ) {
//save the previous congifuration
if ( blenderKeyConfiguration ! = null ) {
if ( blenderKeyConfiguration ! = null ) {
ConfigDialog . this . storeConfig ( blenderKeyConfiguration ) ;
blenderKeyConfiguration = null ;
}
//load new configuration
File [ ] blenderFiles = ConfigDialog . this . prepareFilesList ( baseFolderName + '/' + jComboBoxVersionSelection . getSelectedItem ( ) . toString ( ) ) ;
if ( blenderKeyConfiguration . lastUsedKey ! = null ) {
for ( int i = 0 ; i < blenderFiles . length ; + + i ) {
if ( blenderFiles [ i ] . getPath ( ) . equalsIgnoreCase ( blenderKeyConfiguration . lastUsedKey . getName ( ) ) ) {
File [ ] blenderFiles = ConfigDialog . this . prepareFilesList ( baseFolderName + '/' + jComboBoxVersionSelection . getSelectedItem ( ) . toString ( ) ) ;
if ( blenderKeyConfiguration . lastUsedKey ! = null ) {
for ( int i = 0 ; i < blenderFiles . length ; + + i ) {
if ( blenderFiles [ i ] . getPath ( ) . equalsIgnoreCase ( blenderKeyConfiguration . lastUsedKey . getName ( ) ) ) {
jListBlenderFiles . setSelectedIndex ( i ) ;
break ;
}
}
}
if ( blenderKeyConfiguration . logLevel = = null ) {
if ( blenderKeyConfiguration . logLevel = = null ) {
blenderKeyConfiguration . logLevel = Level . INFO ;
}
JRadioButtonLevel . setSelectedLevel ( blenderKeyConfiguration . logLevel ) ;
@ -293,14 +297,15 @@ public class ConfigDialog extends AbstractConfigDialog {
} ) ;
//selection of the file changes the config on the right
jListBlenderFiles . addListSelectionListener ( new ListSelectionListener ( ) {
@Override
public void valueChanged ( ListSelectionEvent evt ) {
BlenderKeyConfiguration config = ConfigDialog . this . blenderKeyConfiguration ;
FileListItem selectedItem = ( FileListItem ) ConfigDialog . this . jListBlenderFiles . getSelectedValue ( ) ;
if ( selectedItem ! = null ) {
if ( selectedItem ! = null ) {
String fileName = selectedItem . getFile ( ) . getName ( ) ;
config . lastUsedKey = config . blenderKeys . get ( fileName ) ;
if ( config . lastUsedKey = = null ) {
if ( config . lastUsedKey = = null ) {
config . lastUsedKey = new BlenderKey ( selectedItem . getFile ( ) . getPath ( ) ) ;
config . blenderKeys . put ( fileName , config . lastUsedKey ) ;
}
@ -311,12 +316,13 @@ public class ConfigDialog extends AbstractConfigDialog {
}
} ) ;
jTableProperties . getModel ( ) . addTableModelListener ( new TableModelListener ( ) {
@Override
public void tableChanged ( TableModelEvent evt ) {
if ( evt . getType ( ) = = TableModelEvent . UPDATE ) {
if ( evt . getType ( ) = = TableModelEvent . UPDATE ) {
BlenderKeyConfiguration config = ConfigDialog . this . blenderKeyConfiguration ;
int row = evt . getFirstRow ( ) ;
String name = ( String ) jTableProperties . getModel ( ) . getValueAt ( row , 0 ) ;
String name = ( String ) jTableProperties . getModel ( ) . getValueAt ( row , 0 ) ;
Object value = jTableProperties . getModel ( ) . getValueAt ( row , 1 ) ;
try {
Field field = config . lastUsedKey . getClass ( ) . getDeclaredField ( name ) ;
@ -335,38 +341,43 @@ public class ConfigDialog extends AbstractConfigDialog {
}
} ) ;
jTableAnimations . getModel ( ) . addTableModelListener ( new TableModelListener ( ) {
@Override
public void tableChanged ( TableModelEvent evt ) {
if ( evt . getType ( ) = = TableModelEvent . INSERT ) {
if ( evt . getType ( ) = = TableModelEvent . INSERT ) {
jButtonRemoveAnimation . setEnabled ( true ) ;
} else if ( evt . getType ( ) = = TableModelEvent . DELETE & & jTableAnimations . getModel ( ) . getRowCount ( ) = = 0 ) {
} else if ( evt . getType ( ) = = TableModelEvent . DELETE & & jTableAnimations . getModel ( ) . getRowCount ( ) = = 0 ) {
jButtonRemoveAnimation . setEnabled ( false ) ;
}
}
} ) ;
jButtonAddAnimation . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent evt ) {
( ( DefaultTableModel ) jTableAnimations . getModel ( ) ) . addRow ( new Object [ ] { "" , "" , Integer . valueOf ( - 1 ) , Integer . valueOf ( - 1 ) } ) ;
( ( DefaultTableModel ) jTableAnimations . getModel ( ) ) . addRow ( new Object [ ] { "" , "" , Integer . valueOf ( - 1 ) , Integer . valueOf ( - 1 ) } ) ;
}
} ) ;
jButtonRemoveAnimation . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent evt ) {
int row = jTableAnimations . getSelectedRow ( ) ;
if ( row > = 0 ) {
( ( DefaultTableModel ) jTableAnimations . getModel ( ) ) . removeRow ( row ) ;
if ( row > = 0 ) {
( ( DefaultTableModel ) jTableAnimations . getModel ( ) ) . removeRow ( row ) ;
}
}
} ) ;
//button listeners
jButtonOK . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent evt ) {
ConfigDialog . this . storeConfig ( blenderKeyConfiguration ) ;
//running the test
SwingUtilities . invokeLater ( new Runnable ( ) {
@Override
public void run ( ) {
configExecutable . execute ( ConfigDialog . this . blenderKeyConfiguration . getKeyToUse ( ) ,
@ -378,6 +389,7 @@ public class ConfigDialog extends AbstractConfigDialog {
}
} ) ;
jButtonCancel . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent evt ) {
ConfigDialog . this . dispose ( ) ;
@ -391,6 +403,7 @@ public class ConfigDialog extends AbstractConfigDialog {
* @author Marcin Roguski ( Kaelthas )
* /
public static class BlenderKeyConfiguration implements Savable {
private Map < String , BlenderKey > blenderKeys ;
private BlenderKey lastUsedKey ;
private Level logLevel ;
@ -399,7 +412,8 @@ public class ConfigDialog extends AbstractConfigDialog {
/ * *
* Constructor for jme serialization .
* /
public BlenderKeyConfiguration ( ) { }
public BlenderKeyConfiguration ( ) {
}
/ * *
* Constructor that creates new empty configuration for every blender file .
@ -423,7 +437,7 @@ public class ConfigDialog extends AbstractConfigDialog {
oc . writeStringSavableMap ( blenderKeys , "keys" , null ) ;
oc . write ( lastUsedKey , "last-key" , null ) ;
oc . write ( useModelKey , "use-model-key" , false ) ;
oc . write ( logLevel = = null ? null : logLevel . getName ( ) , "log-level" , Level . INFO . getName ( ) ) ;
oc . write ( logLevel = = null ? null : logLevel . getName ( ) , "log-level" , Level . INFO . getName ( ) ) ;
}
@Override
@ -434,7 +448,7 @@ public class ConfigDialog extends AbstractConfigDialog {
lastUsedKey = ( BlenderKey ) ic . readSavable ( "last-key" , null ) ;
useModelKey = ic . readBoolean ( "use-model-key" , false ) ;
String logLevelName = ic . readString ( "log-level" , Level . INFO . getName ( ) ) ;
logLevel = logLevelName = = null ? Level . INFO : Level . parse ( logLevelName ) ;
logLevel = logLevelName = = null ? Level . INFO : Level . parse ( logLevelName ) ;
}
}
}