Save As now catches exeptions
This commit is contained in:
parent
6b53f931bc
commit
1a32edd373
@ -1,4 +1,4 @@
|
|||||||
#Sat, 08 Apr 2017 08:35:31 +0200
|
#Sat, 08 Apr 2017 10:00:51 +0200
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -127,7 +127,7 @@ public class Globals {
|
|||||||
.getPath()).toString();
|
.getPath()).toString();
|
||||||
|
|
||||||
pathlist.add(dp);
|
pathlist.add(dp);
|
||||||
LOGGER.info(String.format("Path %s",dp));
|
LOGGER.info(String.format("Path %s", dp));
|
||||||
tloader = new AutoTraderLoader(pathlist);
|
tloader = new AutoTraderLoader(pathlist);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -180,20 +180,28 @@ public class Globals {
|
|||||||
prefs.put(STRATEGYPREFS, cfgs.toString());
|
prefs.put(STRATEGYPREFS, cfgs.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveFile(File f) {
|
public static class FileStrings {
|
||||||
|
|
||||||
|
public static final String SESIMVERSION = "sesim_version";
|
||||||
|
public static final String STRATEGIES = "strategies";
|
||||||
|
public static final String TRADERS = "traders";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void saveFile(File f) throws FileNotFoundException {
|
||||||
|
|
||||||
JSONObject sobj = new JSONObject();
|
JSONObject sobj = new JSONObject();
|
||||||
|
|
||||||
JSONArray traders = getTraders();
|
JSONArray traders = getTraders();
|
||||||
JSONObject strategies = getStrategies();
|
JSONObject strategies = getStrategies();
|
||||||
sobj.put("strategies", strategies);
|
|
||||||
sobj.put("traders", traders);
|
sobj.put(FileStrings.SESIMVERSION, "0.1");
|
||||||
try {
|
sobj.put(FileStrings.STRATEGIES, strategies);
|
||||||
PrintWriter out = new PrintWriter(f.getAbsolutePath());
|
sobj.put(FileStrings.TRADERS, traders);
|
||||||
|
|
||||||
|
PrintWriter out;
|
||||||
|
out = new PrintWriter(f.getAbsolutePath());
|
||||||
out.print(sobj.toString(4));
|
out.print(sobj.toString(4));
|
||||||
out.close();
|
out.close();
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,9 @@
|
|||||||
<Property name="mnemonic" type="int" value="115"/>
|
<Property name="mnemonic" type="int" value="115"/>
|
||||||
<Property name="text" type="java.lang.String" value="Save"/>
|
<Property name="text" type="java.lang.String" value="Save"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveMenuItemActionPerformed"/>
|
||||||
|
</Events>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem class="javax.swing.JMenuItem" name="saveAsMenuItem">
|
<MenuItem class="javax.swing.JMenuItem" name="saveAsMenuItem">
|
||||||
<Properties>
|
<Properties>
|
||||||
|
@ -42,6 +42,7 @@ import java.util.logging.Logger;
|
|||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER;
|
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
@ -346,6 +347,11 @@ public class SeSimApplication extends javax.swing.JFrame {
|
|||||||
|
|
||||||
saveMenuItem.setMnemonic('s');
|
saveMenuItem.setMnemonic('s');
|
||||||
saveMenuItem.setText("Save");
|
saveMenuItem.setText("Save");
|
||||||
|
saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
saveMenuItemActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
fileMenu.add(saveMenuItem);
|
fileMenu.add(saveMenuItem);
|
||||||
|
|
||||||
saveAsMenuItem.setMnemonic('a');
|
saveAsMenuItem.setMnemonic('a');
|
||||||
@ -607,18 +613,20 @@ public class SeSimApplication extends javax.swing.JFrame {
|
|||||||
|
|
||||||
String[] e = ((FileNameExtensionFilter) fc.getFileFilter()).getExtensions();
|
String[] e = ((FileNameExtensionFilter) fc.getFileFilter()).getExtensions();
|
||||||
|
|
||||||
System.out.printf("Abs: %s\n", f.getAbsoluteFile());
|
|
||||||
|
|
||||||
String fn = f.getAbsolutePath();
|
String fn = f.getAbsolutePath();
|
||||||
|
|
||||||
if (!f.getAbsolutePath().endsWith(e[0])) {
|
if (!f.getAbsolutePath().endsWith(e[0])) {
|
||||||
f = new File(f.getAbsolutePath() + "." + e[0]);
|
f = new File(f.getAbsolutePath() + "." + e[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
Globals.saveFile(f);
|
Globals.saveFile(f);
|
||||||
|
}
|
||||||
|
catch (Exception ex){
|
||||||
|
|
||||||
System.out.printf("Sel File: %s \n", f.getAbsolutePath());
|
JOptionPane.showMessageDialog(this, "Can't save file "+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}//GEN-LAST:event_saveAsMenuItemActionPerformed
|
}//GEN-LAST:event_saveAsMenuItemActionPerformed
|
||||||
|
|
||||||
@ -704,6 +712,10 @@ javax.swing.SwingUtilities.invokeLater(()->{
|
|||||||
System.out.printf("Accel Spinner PRop Change\n");
|
System.out.printf("Accel Spinner PRop Change\n");
|
||||||
}//GEN-LAST:event_accelSpinnerPropertyChange
|
}//GEN-LAST:event_accelSpinnerPropertyChange
|
||||||
|
|
||||||
|
private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
|
||||||
|
// TODO add your handling code here:
|
||||||
|
}//GEN-LAST:event_saveMenuItemActionPerformed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
* @throws java.lang.IllegalAccessException
|
* @throws java.lang.IllegalAccessException
|
||||||
|
Loading…
Reference in New Issue
Block a user