Add threading for scripts, add confirmation msg after code export
This commit is contained in:
parent
b5c4c9c205
commit
1899132535
@ -130,7 +130,7 @@
|
|||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runMenuActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runMenuActionPerformed"/>
|
||||||
</Events>
|
</Events>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem5">
|
<MenuItem class="javax.swing.JMenuItem" name="runCodeBtn">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
|
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
|
||||||
<KeyStroke key="F5"/>
|
<KeyStroke key="F5"/>
|
||||||
@ -138,7 +138,7 @@
|
|||||||
<Property name="text" type="java.lang.String" value="Run code"/>
|
<Property name="text" type="java.lang.String" value="Run code"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
<Events>
|
<Events>
|
||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem5ActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runCodeBtnActionPerformed"/>
|
||||||
</Events>
|
</Events>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
|
@ -159,7 +159,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
|
|||||||
javascriptOption = new javax.swing.JRadioButtonMenuItem();
|
javascriptOption = new javax.swing.JRadioButtonMenuItem();
|
||||||
pythonOption = new javax.swing.JRadioButtonMenuItem();
|
pythonOption = new javax.swing.JRadioButtonMenuItem();
|
||||||
runMenu = new javax.swing.JMenu();
|
runMenu = new javax.swing.JMenu();
|
||||||
jMenuItem5 = new javax.swing.JMenuItem();
|
runCodeBtn = new javax.swing.JMenuItem();
|
||||||
|
|
||||||
jMenuItem4.setText("jMenuItem4");
|
jMenuItem4.setText("jMenuItem4");
|
||||||
|
|
||||||
@ -297,14 +297,14 @@ public class CodeEditor extends javax.swing.JInternalFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
|
runCodeBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
|
||||||
jMenuItem5.setText("Run code");
|
runCodeBtn.setText("Run code");
|
||||||
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
|
runCodeBtn.addActionListener(new java.awt.event.ActionListener() {
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
jMenuItem5ActionPerformed(evt);
|
runCodeBtnActionPerformed(evt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
runMenu.add(jMenuItem5);
|
runMenu.add(runCodeBtn);
|
||||||
|
|
||||||
jMenuBar1.add(runMenu);
|
jMenuBar1.add(runMenu);
|
||||||
|
|
||||||
@ -399,13 +399,27 @@ public class CodeEditor extends javax.swing.JInternalFrame {
|
|||||||
|
|
||||||
}//GEN-LAST:event_runMenuActionPerformed
|
}//GEN-LAST:event_runMenuActionPerformed
|
||||||
|
|
||||||
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
|
private void runCodeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runCodeBtnActionPerformed
|
||||||
if (javascriptOption.isSelected()) {
|
if (javascriptOption.isSelected()) {
|
||||||
execCode("javascript");
|
new RunThread("javascript").start();
|
||||||
} else if (pythonOption.isSelected()) {
|
} else if (pythonOption.isSelected()) {
|
||||||
execCode("python");
|
new RunThread("python").start();
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_jMenuItem5ActionPerformed
|
}//GEN-LAST:event_runCodeBtnActionPerformed
|
||||||
|
|
||||||
|
private class RunThread extends Thread {
|
||||||
|
|
||||||
|
String lang = "";
|
||||||
|
|
||||||
|
public RunThread(String codelang) {
|
||||||
|
lang = codelang;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
execCode(lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void execCode(String lang) {
|
private void execCode(String lang) {
|
||||||
CodeRunner cr = new CodeRunner(lang);
|
CodeRunner cr = new CodeRunner(lang);
|
||||||
@ -477,7 +491,6 @@ public class CodeEditor extends javax.swing.JInternalFrame {
|
|||||||
private javax.swing.JMenuBar jMenuBar1;
|
private javax.swing.JMenuBar jMenuBar1;
|
||||||
private javax.swing.JMenuBar jMenuBar2;
|
private javax.swing.JMenuBar jMenuBar2;
|
||||||
private javax.swing.JMenuItem jMenuItem4;
|
private javax.swing.JMenuItem jMenuItem4;
|
||||||
private javax.swing.JMenuItem jMenuItem5;
|
|
||||||
private javax.swing.JPanel jPanel1;
|
private javax.swing.JPanel jPanel1;
|
||||||
private javax.swing.JPanel jPanel2;
|
private javax.swing.JPanel jPanel2;
|
||||||
private javax.swing.JScrollPane jScrollPane1;
|
private javax.swing.JScrollPane jScrollPane1;
|
||||||
@ -487,6 +500,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
|
|||||||
private javax.swing.JMenuItem openMenu;
|
private javax.swing.JMenuItem openMenu;
|
||||||
private javax.swing.JTextArea outputBox;
|
private javax.swing.JTextArea outputBox;
|
||||||
private javax.swing.JRadioButtonMenuItem pythonOption;
|
private javax.swing.JRadioButtonMenuItem pythonOption;
|
||||||
|
private javax.swing.JMenuItem runCodeBtn;
|
||||||
private javax.swing.JMenu runMenu;
|
private javax.swing.JMenu runMenu;
|
||||||
private javax.swing.JMenuItem saveAsMenu;
|
private javax.swing.JMenuItem saveAsMenu;
|
||||||
private javax.swing.JMenuItem saveMenu;
|
private javax.swing.JMenuItem saveMenu;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Apocalypse Laboratories
|
* Apocalypse Laboratories
|
||||||
* Open Source License
|
* Open Source License
|
||||||
*
|
*
|
||||||
* Source code can be used for any purpose, as long as:
|
* Source code can be used for any purpose, as long as:
|
||||||
* - Compiled binaries are rebranded and trademarks are not
|
* - Compiled binaries are rebranded and trademarks are not
|
||||||
* visible by the end user at any time, except to give
|
* visible by the end user at any time, except to give
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* - and you provide your modified source code for download,
|
* - and you provide your modified source code for download,
|
||||||
* under the terms of the GNU LGPL v3 or a comparable
|
* under the terms of the GNU LGPL v3 or a comparable
|
||||||
* license.
|
* license.
|
||||||
*
|
*
|
||||||
* Compiled binaries cannot be redistributed or mirrored,
|
* Compiled binaries cannot be redistributed or mirrored,
|
||||||
* unless:
|
* unless:
|
||||||
* - You have written permission from Apocalypse Laboratories;
|
* - You have written permission from Apocalypse Laboratories;
|
||||||
@ -22,7 +22,7 @@
|
|||||||
* not even behind a paywall or other blocking mechanism;
|
* not even behind a paywall or other blocking mechanism;
|
||||||
* - or you have received a multi-computer license, in which
|
* - or you have received a multi-computer license, in which
|
||||||
* case you should take measures to prevent unauthorized
|
* case you should take measures to prevent unauthorized
|
||||||
* downloads, such as preventing download access from the
|
* downloads, such as preventing download access from the
|
||||||
* Internet.
|
* Internet.
|
||||||
*/
|
*/
|
||||||
package net.apocalypselabs.symat;
|
package net.apocalypselabs.symat;
|
||||||
@ -75,10 +75,10 @@ public class CodeExport extends javax.swing.JInternalFrame {
|
|||||||
previewPane.setText(html);
|
previewPane.setText(html);
|
||||||
previewPane.setCaretPosition(0);
|
previewPane.setCaretPosition(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create CodeExport window with a set language for syntax highlighting.
|
* Create CodeExport window with a set language for syntax highlighting.
|
||||||
*
|
*
|
||||||
* @param code The code.
|
* @param code The code.
|
||||||
* @param lang Options are "js" or "python".
|
* @param lang Options are "js" or "python".
|
||||||
*/
|
*/
|
||||||
@ -351,6 +351,7 @@ public class CodeExport extends javax.swing.JInternalFrame {
|
|||||||
htmlWorker.setStyleSheet(styles);
|
htmlWorker.setStyleSheet(styles);
|
||||||
htmlWorker.parse(new StringReader(k));
|
htmlWorker.parse(new StringReader(k));
|
||||||
document.close();
|
document.close();
|
||||||
|
savedMsg();
|
||||||
}
|
}
|
||||||
} catch (IOException | DocumentException e) {
|
} catch (IOException | DocumentException e) {
|
||||||
JOptionPane.showInternalMessageDialog(this, "Error saving: " + e.getMessage());
|
JOptionPane.showInternalMessageDialog(this, "Error saving: " + e.getMessage());
|
||||||
@ -361,11 +362,16 @@ public class CodeExport extends javax.swing.JInternalFrame {
|
|||||||
try {
|
try {
|
||||||
PrintStream out = new PrintStream(new FileOutputStream(path));
|
PrintStream out = new PrintStream(new FileOutputStream(path));
|
||||||
out.print(content);
|
out.print(content);
|
||||||
|
savedMsg();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
JOptionPane.showInternalMessageDialog(this, "Error saving: " + ex.getMessage());
|
JOptionPane.showInternalMessageDialog(this, "Error saving: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void savedMsg() {
|
||||||
|
JOptionPane.showInternalMessageDialog(this, "Export complete!");
|
||||||
|
}
|
||||||
|
|
||||||
private String addSaveExt(String path, String format) {
|
private String addSaveExt(String path, String format) {
|
||||||
if (!path.matches(".*\\.(" + format + ")")) {
|
if (!path.matches(".*\\.(" + format + ")")) {
|
||||||
path += "." + format;
|
path += "." + format;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user