Allow editing of global strings and numbers, add aliases to CodeRunner langs
This commit is contained in:
parent
d3e78ce6e9
commit
a9575e64e4
@ -75,6 +75,8 @@ public class CodeRunner {
|
|||||||
scriptLang = lang;
|
scriptLang = lang;
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case "javascript":
|
case "javascript":
|
||||||
|
case "js":
|
||||||
|
case "rhino":
|
||||||
se = new ScriptEngineManager().getEngineByName("rhino");
|
se = new ScriptEngineManager().getEngineByName("rhino");
|
||||||
wrapRequired = true;
|
wrapRequired = true;
|
||||||
try {
|
try {
|
||||||
@ -89,6 +91,7 @@ public class CodeRunner {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "python":
|
case "python":
|
||||||
|
case "py":
|
||||||
se = new ScriptEngineManager().getEngineByName("python");
|
se = new ScriptEngineManager().getEngineByName("python");
|
||||||
try {
|
try {
|
||||||
se.eval("from math import *\n"
|
se.eval("from math import *\n"
|
||||||
|
@ -53,7 +53,7 @@ package net.apocalypselabs.symat;
|
|||||||
public class Debug {
|
public class Debug {
|
||||||
|
|
||||||
// If output should be on or off
|
// If output should be on or off
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = true;
|
||||||
|
|
||||||
public static void println(Object data) {
|
public static void println(Object data) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -239,7 +239,8 @@ public class Functions {
|
|||||||
* @return The variable
|
* @return The variable
|
||||||
*/
|
*/
|
||||||
public static Object global(String name) {
|
public static Object global(String name) {
|
||||||
return GLOBALS.get(name);
|
Object item = GLOBALS.get(name);
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="remBtn" min="-2" max="-2" attributes="0"/>
|
<Component id="remBtn" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="saveBtn" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace min="-2" pref="37" max="-2" attributes="0"/>
|
||||||
<Component id="refreshBtn" min="-2" max="-2" attributes="0"/>
|
<Component id="refreshBtn" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
@ -61,6 +63,7 @@
|
|||||||
<Component id="addBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="addBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="remBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="remBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="refreshBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="refreshBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="saveBtn" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
@ -104,7 +107,7 @@
|
|||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Group type="102" alignment="1" attributes="0">
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jScrollPane1" pref="208" max="32767" attributes="0"/>
|
<Component id="jScrollPane1" pref="212" max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
@ -178,7 +181,6 @@
|
|||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Component class="javax.swing.JTextArea" name="valBox">
|
<Component class="javax.swing.JTextArea" name="valBox">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="editable" type="boolean" value="false"/>
|
|
||||||
<Property name="columns" type="int" value="1"/>
|
<Property name="columns" type="int" value="1"/>
|
||||||
<Property name="rows" type="int" value="1"/>
|
<Property name="rows" type="int" value="1"/>
|
||||||
<Property name="tabSize" type="int" value="4"/>
|
<Property name="tabSize" type="int" value="4"/>
|
||||||
@ -196,5 +198,13 @@
|
|||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="refreshBtnActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="refreshBtnActionPerformed"/>
|
||||||
</Events>
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="saveBtn">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Save"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveBtnActionPerformed"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.apocalypselabs.symat;
|
package net.apocalypselabs.symat;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,8 +54,6 @@ import javax.swing.JOptionPane;
|
|||||||
*/
|
*/
|
||||||
public class Globals extends javax.swing.JInternalFrame {
|
public class Globals extends javax.swing.JInternalFrame {
|
||||||
|
|
||||||
private int hashCode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form Globals
|
* Creates new form Globals
|
||||||
*/
|
*/
|
||||||
@ -80,6 +79,7 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
jScrollPane2 = new javax.swing.JScrollPane();
|
jScrollPane2 = new javax.swing.JScrollPane();
|
||||||
valBox = new javax.swing.JTextArea();
|
valBox = new javax.swing.JTextArea();
|
||||||
refreshBtn = new javax.swing.JButton();
|
refreshBtn = new javax.swing.JButton();
|
||||||
|
saveBtn = new javax.swing.JButton();
|
||||||
|
|
||||||
setClosable(true);
|
setClosable(true);
|
||||||
setIconifiable(true);
|
setIconifiable(true);
|
||||||
@ -123,7 +123,7 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
|
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
|
|
||||||
remBtn.setText("Remove");
|
remBtn.setText("Remove");
|
||||||
@ -135,7 +135,6 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
|
|
||||||
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Value"));
|
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Value"));
|
||||||
|
|
||||||
valBox.setEditable(false);
|
|
||||||
valBox.setColumns(1);
|
valBox.setColumns(1);
|
||||||
valBox.setRows(1);
|
valBox.setRows(1);
|
||||||
valBox.setTabSize(4);
|
valBox.setTabSize(4);
|
||||||
@ -164,6 +163,13 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
saveBtn.setText("Save");
|
||||||
|
saveBtn.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
saveBtnActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||||
getContentPane().setLayout(layout);
|
getContentPane().setLayout(layout);
|
||||||
layout.setHorizontalGroup(
|
layout.setHorizontalGroup(
|
||||||
@ -180,6 +186,8 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(remBtn)
|
.addComponent(remBtn)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(saveBtn)
|
||||||
|
.addGap(37, 37, 37)
|
||||||
.addComponent(refreshBtn)
|
.addComponent(refreshBtn)
|
||||||
.addGap(0, 0, Short.MAX_VALUE)))
|
.addGap(0, 0, Short.MAX_VALUE)))
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
@ -191,7 +199,8 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(addBtn)
|
.addComponent(addBtn)
|
||||||
.addComponent(remBtn)
|
.addComponent(remBtn)
|
||||||
.addComponent(refreshBtn))
|
.addComponent(refreshBtn)
|
||||||
|
.addComponent(saveBtn))
|
||||||
.addGap(18, 18, 18)
|
.addGap(18, 18, 18)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
@ -204,12 +213,30 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
|
|
||||||
private void keyListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_keyListValueChanged
|
private void keyListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_keyListValueChanged
|
||||||
if (keyList.getSelectedValue() != null) {
|
if (keyList.getSelectedValue() != null) {
|
||||||
|
valBox.setEditable(true);
|
||||||
try {
|
try {
|
||||||
valBox.setText(Functions.GLOBALS.get(
|
Object item = Functions.GLOBALS.get(
|
||||||
keyList.getSelectedValue().toString()).toString());
|
keyList.getSelectedValue());
|
||||||
|
if (item.getClass().equals(sun.org.mozilla.javascript.internal.NativeArray.class)) {
|
||||||
|
Object[] arr = ((sun.org.mozilla.javascript.internal.NativeArray) item).toArray();
|
||||||
|
valBox.setText(Arrays.toString(arr));
|
||||||
|
valBox.setEditable(false);
|
||||||
|
} else if (item.getClass().equals(org.mozilla.javascript.NativeArray.class)) {
|
||||||
|
Object[] arr = ((org.mozilla.javascript.NativeArray) item).toArray();
|
||||||
|
valBox.setText(Arrays.toString(arr));
|
||||||
|
valBox.setEditable(false);
|
||||||
|
// } else if (item.getClass().equals(PyList.class)) {
|
||||||
|
// Object[] arr = ((PyList) item).toArray();
|
||||||
|
// valBox.setText(Arrays.toString(arr));
|
||||||
|
// valBox.setEditable(false);
|
||||||
|
} else {
|
||||||
|
valBox.setText(Functions.GLOBALS.get(
|
||||||
|
keyList.getSelectedValue()).toString());
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
valBox.setText("Error. Note some datatypes "
|
valBox.setText("error");
|
||||||
+ "cannot be displayed here.");
|
valBox.setEditable(false);
|
||||||
|
Debug.stacktrace(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_keyListValueChanged
|
}//GEN-LAST:event_keyListValueChanged
|
||||||
@ -249,12 +276,27 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
refreshList();
|
refreshList();
|
||||||
}//GEN-LAST:event_refreshBtnActionPerformed
|
}//GEN-LAST:event_refreshBtnActionPerformed
|
||||||
|
|
||||||
private void refreshList() {
|
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed
|
||||||
if (Functions.GLOBALS.hashCode() != hashCode) {
|
try {
|
||||||
keyList.setListData(Functions.GLOBALS.keySet().toArray());
|
setVar(keyList.getSelectedValue().toString(), valBox.getText());
|
||||||
hashCode = Functions.GLOBALS.hashCode();
|
} catch (Exception ex) {
|
||||||
valBox.setText("");
|
|
||||||
}
|
}
|
||||||
|
}//GEN-LAST:event_saveBtnActionPerformed
|
||||||
|
|
||||||
|
private void refreshList() {
|
||||||
|
keyList.setListData(Functions.GLOBALS.keySet().toArray());
|
||||||
|
valBox.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setVar(String key, String val) {
|
||||||
|
try {
|
||||||
|
double value = Double.parseDouble(val);
|
||||||
|
Functions.GLOBALS.put(key, value);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Functions.GLOBALS.put(key, val);
|
||||||
|
}
|
||||||
|
refreshList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
@ -266,6 +308,7 @@ public class Globals extends javax.swing.JInternalFrame {
|
|||||||
private javax.swing.JList keyList;
|
private javax.swing.JList keyList;
|
||||||
private javax.swing.JButton refreshBtn;
|
private javax.swing.JButton refreshBtn;
|
||||||
private javax.swing.JButton remBtn;
|
private javax.swing.JButton remBtn;
|
||||||
|
private javax.swing.JButton saveBtn;
|
||||||
private javax.swing.JTextArea valBox;
|
private javax.swing.JTextArea valBox;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
<Component class="javax.swing.JLabel" name="dispLabel">
|
<Component class="javax.swing.JLabel" name="dispLabel">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||||
<Connection code="MainGUI.ubuntuRegular.deriveFont(24.0F)" type="code"/>
|
<Connection code="MainGUI.ubuntuRegular.deriveFont(20.0F)" type="code"/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||||
|
@ -100,7 +100,7 @@ public class SplashScreen extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dispLabel.setFont(MainGUI.ubuntuRegular.deriveFont(24.0F));
|
dispLabel.setFont(MainGUI.ubuntuRegular.deriveFont(20.0F));
|
||||||
dispLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
dispLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||||
dispLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/splash.gif"))); // NOI18N
|
dispLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/splash.gif"))); // NOI18N
|
||||||
dispLabel.setText("<html><br><br> Loading...");
|
dispLabel.setText("<html><br><br> Loading...");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user