Add script opening from arguments, upgrade to version 0.5.3

This commit is contained in:
skylarmt 2014-12-05 15:40:13 -07:00
parent 5e12bb58d5
commit 36e10a7af8
3 changed files with 45 additions and 12 deletions

View File

@ -27,6 +27,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
@ -67,7 +69,8 @@ public class CodeEditor extends javax.swing.JInternalFrame {
int font_size = 12; int font_size = 12;
try { try {
font_size = Integer.valueOf(PrefStorage.getSetting("editor-fontsize")); font_size = Integer.valueOf(PrefStorage.getSetting("editor-fontsize"));
} catch (Exception ex) { } } catch (Exception ex) {
}
codeBox.setFont(new Font(Font.MONOSPACED, Font.PLAIN, font_size)); codeBox.setFont(new Font(Font.MONOSPACED, Font.PLAIN, font_size));
TabStop[] tabs = new TabStop[30]; TabStop[] tabs = new TabStop[30];
for (int i = 0; i < tabs.length; i++) { for (int i = 0; i < tabs.length; i++) {
@ -278,14 +281,29 @@ public class CodeEditor extends javax.swing.JInternalFrame {
File f = fc.getSelectedFile(); File f = fc.getSelectedFile();
codeBox.setText(readFile(f.toString(), StandardCharsets.UTF_8)); codeBox.setText(readFile(f.toString(), StandardCharsets.UTF_8));
isSaved = true; isSaved = true;
lastSaved = codeBox.getText();
setTitle("Editor - " + f.getName()); setTitle("Editor - " + f.getName());
} catch (IOException ex) { } catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this, "Error: Cannot load file: " + ex.getMessage()); JOptionPane.showInternalMessageDialog(this,
"Error: Cannot load file: " + ex.getMessage());
} }
} }
codeBox.setCaretPosition(0); codeBox.setCaretPosition(0);
}//GEN-LAST:event_jMenuItem1ActionPerformed }//GEN-LAST:event_jMenuItem1ActionPerformed
public void openFileFromString(String file) {
try {
File f = new File(file);
codeBox.setText(readFile(f.toString(), StandardCharsets.UTF_8));
isSaved = true;
lastSaved = codeBox.getText();
setTitle("Editor - " + f.getName());
} catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this,
"Error: Cannot load file: " + ex.getMessage());
}
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
if (!isSaved) { if (!isSaved) {
int r = fc.showSaveDialog(this); int r = fc.showSaveDialog(this);

View File

@ -32,8 +32,9 @@ import javax.swing.JInternalFrame;
*/ */
public class MainGUI extends javax.swing.JFrame { public class MainGUI extends javax.swing.JFrame {
public static final String APP_NAME = "SyMAT 0.5.1"; public static final String APP_NAME = "SyMAT 0.5.3";
public static final double APP_CODE = 0.51; public static final double APP_CODE = 0.53;
public static String argfile = "";
/** /**
* Creates new form MainGUI * Creates new form MainGUI
@ -62,8 +63,17 @@ public class MainGUI extends javax.swing.JFrame {
System.err.println("Fail: Cannot check update server. \n" System.err.println("Fail: Cannot check update server. \n"
+ " Assuming local copy up-to-date."); + " Assuming local copy up-to-date.");
} }
// Open shell unless prog was run with argument
if (argfile.equals("")) {
Interpreter sh = new Interpreter(); Interpreter sh = new Interpreter();
loadFrame(sh); loadFrame(sh);
} else {
CodeEditor ed = new CodeEditor();
loadFrame(ed);
ed.openFileFromString(argfile);
argfile = "";
}
} }
/** /**
@ -247,6 +257,11 @@ public class MainGUI extends javax.swing.JFrame {
new MainGUI().setVisible(true); new MainGUI().setVisible(true);
} }
}); });
// Trigger open passed script file
if (args.length == 1) {
argfile = args[0];
}
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables

View File

@ -6,7 +6,7 @@
<h1>Welcome to SyMAT!</h1> <h1>Welcome to SyMAT!</h1>
<p>SyMAT is a Java-based algebra and calculus system. <p>SyMAT is a Java-based algebra and calculus system.
Scripts and commands are in JavaScript.</p> Scripts and commands are in JavaScript.</p>
<p><b>License:</b><br> <p><b>Copyright:</b><br>
SyMAT is licensed under the GNU Lesser General Public License.</p> SyMAT is copyright &copy; 2014 Apocalypse Laboratories.</p>
</body> </body>
</html> </html>