Code output now appears during run, add script kill button

master
skylarmt 9 years ago
parent d338f24f08
commit 502ef6d9a0

@ -61,6 +61,8 @@ import javax.swing.JOptionPane;
public class CodeRunner { public class CodeRunner {
private ScriptEngine se; private ScriptEngine se;
private StringWriter sw = new StringWriter();
private PrintWriter pw = new PrintWriter(sw);
// If we need to wrap code around input to make everything nice. // If we need to wrap code around input to make everything nice.
private boolean wrapRequired = false; private boolean wrapRequired = false;
@ -82,12 +84,6 @@ public class CodeRunner {
case "js": case "js":
case "rhino": case "rhino":
se = new ScriptEngineManager().getEngineByName("rhino"); se = new ScriptEngineManager().getEngineByName("rhino");
// Context ctx = Context.getCurrentContext();
// if (ctx == null) {
// ctx = Context.enter();
// }
//ctx.setWrapFactory(new JsWrapFactory());
//ctx.getWrapFactory().setJavaPrimitiveWrap(false);
wrapRequired = true; wrapRequired = true;
try { try {
// Add custom functions. // Add custom functions.
@ -97,6 +93,7 @@ public class CodeRunner {
+ getFunctions("js")); + getFunctions("js"));
// Allow engine access from scripts. // Allow engine access from scripts.
se.put("engine", se); se.put("engine", se);
attachWriters();
} catch (Exception ex) { } catch (Exception ex) {
initError(ex); initError(ex);
} }
@ -113,6 +110,7 @@ public class CodeRunner {
+ getFunctions("py")); + getFunctions("py"));
// Allow engine access from scripts. // Allow engine access from scripts.
se.put("engine", se); se.put("engine", se);
attachWriters();
} catch (Exception ex) { } catch (Exception ex) {
initError(ex); initError(ex);
} }
@ -127,6 +125,12 @@ public class CodeRunner {
this(lang); this(lang);
} }
public void attachWriters() {
se.getContext().setWriter(pw);
se.getContext().setErrorWriter(pw);
Debug.println("Attached writers.");
}
/** /**
* Inits the Python engine on application start. * Inits the Python engine on application start.
* *
@ -138,6 +142,20 @@ public class CodeRunner {
} }
} }
public StringWriter getStringWriter() {
return sw;
}
public PrintWriter getPrintWriter() {
return pw;
}
public String getBufferDump() {
String dump = sw.toString();
sw.getBuffer().setLength(0);
return dump;
}
private void initError(Exception ex) { private void initError(Exception ex) {
JOptionPane.showMessageDialog(null, "Error: " JOptionPane.showMessageDialog(null, "Error: "
+ "Could not properly initialize " + scriptLang + " scripting engine." + "Could not properly initialize " + scriptLang + " scripting engine."
@ -146,16 +164,13 @@ public class CodeRunner {
} }
/** /**
* Parse a String of JavaScript. * Parse a String of code.
* *
* @param eval A String of JavaScript to evaluate. * @param eval A String of code to evaluate.
* @return the result. * @return the result.
*/ */
public Object evalString(String eval) { public Object evalString(String eval) {
try { try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
se.getContext().setWriter(pw);
Object res = se.eval(wrapMath(eval)); Object res = se.eval(wrapMath(eval));
if (res == null) { if (res == null) {
res = ""; res = "";
@ -167,6 +182,22 @@ public class CodeRunner {
} }
} }
/**
* Parse code and use the default output writers.
*
* @param eval A String of code to evaluate.
*/
public void evalCode(String eval) {
try {
Object res = se.eval(wrapMath(eval));
if (res == null) {
res = "";
}
} catch (ScriptException ex) {
sw.append(formatEx(ex));
}
}
private String formatEx(ScriptException ex) { private String formatEx(ScriptException ex) {
String err = ex.getMessage(); String err = ex.getMessage();
//err = err.replace("sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: ", ""); //err = err.replace("sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: ", "");

@ -231,6 +231,15 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runCodeBtnActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runCodeBtnActionPerformed"/>
</Events> </Events>
</MenuItem> </MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="killButton">
<Properties>
<Property name="text" type="java.lang.String" value="Kill script"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="killButtonActionPerformed"/>
</Events>
</MenuItem>
<Menu class="javax.swing.JMenu" name="codeLangMenu"> <Menu class="javax.swing.JMenu" name="codeLangMenu">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Language"/> <Property name="text" type="java.lang.String" value="Language"/>

@ -71,6 +71,10 @@ import org.fife.ui.rtextarea.RTextScrollPane;
*/ */
public class Editor extends javax.swing.JInternalFrame { public class Editor extends javax.swing.JInternalFrame {
private CodeRunner cr;
private RunThread rt;
private UpdateOutput uo;
private final JFileChooser fc = new JFileChooser(); private final JFileChooser fc = new JFileChooser();
private boolean isSaved = false; private boolean isSaved = false;
private RSyntaxTextArea codeBox = new RSyntaxTextArea(); private RSyntaxTextArea codeBox = new RSyntaxTextArea();
@ -93,13 +97,16 @@ public class Editor extends javax.swing.JInternalFrame {
FileFilter filter = new FileNameExtensionFilter("JavaScript (syjs, js)", "syjs", "js"); FileFilter filter = new FileNameExtensionFilter("JavaScript (syjs, js)", "syjs", "js");
fc.setFileFilter(filter); fc.setFileFilter(filter);
fc.addChoosableFileFilter(filter); fc.addChoosableFileFilter(filter);
filter = new FileNameExtensionFilter("Python (sypy, py)", "sypy", "py"); fc.addChoosableFileFilter(new FileNameExtensionFilter(
fc.addChoosableFileFilter(filter); "Python (sypy, py)", "sypy", "py"));
fc.addChoosableFileFilter(new FileNameExtensionFilter(
"Plain Text (txt, text)", "txt", "text"));
int font_size = 12; int font_size = 12;
try { try {
font_size = Integer.valueOf(PrefStorage.getSetting("editfont")); font_size = Integer.valueOf(PrefStorage.getSetting("editfont"));
} catch (Exception ex) { } catch (Exception ex) {
Debug.printerr("Font size error!");
} }
codeBox.setFont(new Font(Font.MONOSPACED, Font.PLAIN, font_size)); codeBox.setFont(new Font(Font.MONOSPACED, Font.PLAIN, font_size));
outputBox.setFont(new Font(Font.MONOSPACED, Font.PLAIN, font_size)); outputBox.setFont(new Font(Font.MONOSPACED, Font.PLAIN, font_size));
@ -247,6 +254,7 @@ public class Editor extends javax.swing.JInternalFrame {
pasteBtn = new javax.swing.JMenuItem(); pasteBtn = new javax.swing.JMenuItem();
runMenu = new javax.swing.JMenu(); runMenu = new javax.swing.JMenu();
runCodeBtn = new javax.swing.JMenuItem(); runCodeBtn = new javax.swing.JMenuItem();
killButton = new javax.swing.JMenuItem();
codeLangMenu = new javax.swing.JMenu(); codeLangMenu = new javax.swing.JMenu();
javascriptOption = new javax.swing.JRadioButtonMenuItem(); javascriptOption = new javax.swing.JRadioButtonMenuItem();
pythonOption = new javax.swing.JRadioButtonMenuItem(); pythonOption = new javax.swing.JRadioButtonMenuItem();
@ -491,6 +499,15 @@ public class Editor extends javax.swing.JInternalFrame {
}); });
runMenu.add(runCodeBtn); runMenu.add(runCodeBtn);
killButton.setText("Kill script");
killButton.setEnabled(false);
killButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
killButtonActionPerformed(evt);
}
});
runMenu.add(killButton);
codeLangMenu.setText("Language"); codeLangMenu.setText("Language");
javascriptOption.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK)); javascriptOption.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK));
@ -636,9 +653,11 @@ public class Editor extends javax.swing.JInternalFrame {
private void runCodeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runCodeBtnActionPerformed private void runCodeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runCodeBtnActionPerformed
if (javascriptOption.isSelected()) { if (javascriptOption.isSelected()) {
new RunThread("javascript").start(); rt = new RunThread("javascript");
rt.start();
} else if (pythonOption.isSelected()) { } else if (pythonOption.isSelected()) {
new RunThread("python").start(); rt = new RunThread("python");
rt.start();
} }
}//GEN-LAST:event_runCodeBtnActionPerformed }//GEN-LAST:event_runCodeBtnActionPerformed
@ -666,47 +685,90 @@ public class Editor extends javax.swing.JInternalFrame {
execCode(lang); execCode(lang);
setRunning(false); setRunning(false);
} }
}
public void setRunning(boolean isRunning) { private void setRunning(boolean isRunning) {
final boolean running = isRunning; final boolean running = isRunning;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
if (running) { if (running) {
runMenu.setText("Running..."); runMenu.setText("Running...");
codeBox.setEnabled(false); codeBox.setEditable(false);
for (Component mu : jMenuBar1.getComponents()) { for (Component mu : jMenuBar1.getComponents()) {
mu.setEnabled(false); mu.setEnabled(false);
} }
jMenuBar1.setEnabled(false); runMenu.setEnabled(true);
runCodeBtn.setEnabled(false);
codeLangMenu.setEnabled(false);
killButton.setEnabled(true);
} else { } else {
runMenu.setText("Run"); runMenu.setText("Run");
codeBox.setEnabled(true); codeBox.setEditable(true);
for (Component mu : jMenuBar1.getComponents()) { for (Component mu : jMenuBar1.getComponents()) {
mu.setEnabled(true); mu.setEnabled(true);
} }
jMenuBar1.setEnabled(true); runCodeBtn.setEnabled(true);
codeLangMenu.setEnabled(true);
killButton.setEnabled(false);
} }
} }
}); });
} }
}
private void execCode(String lang) { private void execCode(String lang) {
if (!checkRequiredVersion(codeBox.getText(), lang)) { if (!checkRequiredVersion(codeBox.getText(), lang)) {
return; return;
} }
CodeRunner cr = new CodeRunner(lang); cr = new CodeRunner(lang);
uo = new UpdateOutput(cr);
String script = loadExternalScripts(codeBox.getText(), lang); String script = loadExternalScripts(codeBox.getText(), lang);
Debug.println(lang); Debug.println(lang);
Debug.println(script); Debug.println(script);
Object result = cr.evalString(script); uo.start();
cr.evalCode(script);
uo.kill();
}
private class UpdateOutput extends Thread {
private final CodeRunner cr;
private boolean keepGoing = true;
public void kill() {
keepGoing = false;
flush();
}
@Override
public void run() {
while (keepGoing) {
try { try {
outputBox.append(result.toString() + "\n"); flush();
} catch (NullPointerException ex) { Thread.sleep(100);
} catch (Exception ex) {
} }
} }
}
private void flush() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String d = cr.getBufferDump();
if (!d.equals("")) {
outputBox.append(d);
Debug.println(d);
}
}
});
}
public UpdateOutput(CodeRunner c) {
cr = c;
}
}
private boolean checkRequiredVersion(String script, String lang) { private boolean checkRequiredVersion(String script, String lang) {
String prefix = "//"; String prefix = "//";
@ -855,6 +917,16 @@ public class Editor extends javax.swing.JInternalFrame {
)); ));
}//GEN-LAST:event_packPluginMenuActionPerformed }//GEN-LAST:event_packPluginMenuActionPerformed
private void killButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_killButtonActionPerformed
uo.kill();
rt.stop();
setRunning(false);
outputBox.append(""
+ "\n============="
+ "\nScript killed"
+ "\n=============\n");
}//GEN-LAST:event_killButtonActionPerformed
private void createShared(String id) { private void createShared(String id) {
try { try {
String padid = Pads.genPad(id, codeBox.getText()); String padid = Pads.genPad(id, codeBox.getText());
@ -945,6 +1017,7 @@ public class Editor extends javax.swing.JInternalFrame {
private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JSplitPane jSplitPane1; private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JRadioButtonMenuItem javascriptOption; private javax.swing.JRadioButtonMenuItem javascriptOption;
private javax.swing.JMenuItem killButton;
private javax.swing.ButtonGroup langBtnGroup; private javax.swing.ButtonGroup langBtnGroup;
private javax.swing.JMenuItem openMenu; private javax.swing.JMenuItem openMenu;
private javax.swing.JMenu openSampleBtn; private javax.swing.JMenu openSampleBtn;

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo"> <Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<NonVisualComponents> <NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="themeGroup"> <Component class="javax.swing.ButtonGroup" name="themeGroup">
</Component> </Component>
@ -13,13 +13,13 @@
<Image iconType="3" name="/net/apocalypselabs/symat/icons/settings.png"/> <Image iconType="3" name="/net/apocalypselabs/symat/icons/settings.png"/>
</Property> </Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[390, 293]"/> <Dimension value="[524, 274]"/>
</Property> </Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[390, 293]"/> <Dimension value="[524, 274]"/>
</Property> </Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[390, 293]"/> <Dimension value="[524, 274]"/>
</Property> </Property>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
@ -43,22 +43,22 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jPanel1" max="32767" attributes="0"/> <Component id="jPanel1" max="32767" attributes="0"/>
<Component id="jPanel3" max="32767" attributes="0"/> <Component id="jPanel3" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jPanel2" max="32767" attributes="0"/> <Group type="102" attributes="0">
<Component id="jPanel4" max="32767" attributes="0"/> <Component id="jPanel2" min="-2" max="-2" attributes="0"/>
</Group> <EmptySpace max="-2" attributes="0"/>
<Component id="jPanel5" max="32767" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="32767" attributes="0"/> <Component id="jPanel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="applyBtn" min="-2" max="-2" attributes="0"/> <Component id="applyBtn" 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"/> <Component id="saveBtn" min="-2" max="-2" attributes="0"/>
@ -71,22 +71,24 @@
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jPanel5" max="32767" attributes="0"/>
<Component id="jPanel2" max="32767" attributes="0"/> <Component id="jPanel2" max="32767" attributes="0"/>
<Component id="jPanel1" max="32767" attributes="0"/> <Component id="jPanel1" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jPanel3" alignment="1" max="32767" attributes="0"/> <Component id="jPanel3" max="32767" attributes="0"/>
<Component id="jPanel4" max="32767" attributes="0"/> <Component id="jPanel4" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="applyBtn" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="applyBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="saveBtn" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="saveBtn" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace min="-2" pref="40" max="-2" attributes="0"/> </Group>
<EmptySpace min="-2" pref="57" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -236,7 +238,6 @@
<Component id="quickStart" min="-2" max="-2" attributes="0"/> <Component id="quickStart" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="skipUpdates" min="-2" max="-2" attributes="0"/> <Component id="skipUpdates" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -276,7 +277,7 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <EmptySpace min="0" pref="96" max="32767" attributes="0"/>
</Group> </Group>
<Component id="nameBox" max="32767" attributes="0"/> <Component id="nameBox" max="32767" attributes="0"/>
</Group> </Group>
@ -287,7 +288,7 @@
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="nameBox" min="-2" max="-2" attributes="0"/> <Component id="nameBox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <EmptySpace pref="13" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -302,5 +303,44 @@
</Component> </Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="jPanel5">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Text size"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="textSize" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="textSize" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JSpinner" name="textSize">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="12" maximum="48" minimum="8" numberType="java.lang.Integer" stepSize="2" type="number"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents> </SubComponents>
</Form> </Form>

@ -56,6 +56,7 @@ public class Settings extends javax.swing.JInternalFrame {
*/ */
public Settings() { public Settings() {
initComponents(); initComponents();
jPanel5.setVisible(false);
setBackground(Theme.windowColor()); setBackground(Theme.windowColor());
} }
@ -83,14 +84,16 @@ public class Settings extends javax.swing.JInternalFrame {
jPanel4 = new javax.swing.JPanel(); jPanel4 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
nameBox = new javax.swing.JTextField(); nameBox = new javax.swing.JTextField();
jPanel5 = new javax.swing.JPanel();
textSize = new javax.swing.JSpinner();
setClosable(true); setClosable(true);
setIconifiable(true); setIconifiable(true);
setTitle("Settings"); setTitle("Settings");
setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/icons/settings.png"))); // NOI18N setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/icons/settings.png"))); // NOI18N
setMaximumSize(new java.awt.Dimension(390, 293)); setMaximumSize(new java.awt.Dimension(524, 274));
setMinimumSize(new java.awt.Dimension(390, 293)); setMinimumSize(new java.awt.Dimension(524, 274));
setPreferredSize(new java.awt.Dimension(390, 293)); setPreferredSize(new java.awt.Dimension(524, 274));
addComponentListener(new java.awt.event.ComponentAdapter() { addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentShown(java.awt.event.ComponentEvent evt) { public void componentShown(java.awt.event.ComponentEvent evt) {
formComponentShown(evt); formComponentShown(evt);
@ -192,8 +195,7 @@ public class Settings extends javax.swing.JInternalFrame {
.addContainerGap() .addContainerGap()
.addComponent(quickStart) .addComponent(quickStart)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(skipUpdates) .addComponent(skipUpdates))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
); );
applyBtn.setText("Apply"); applyBtn.setText("Apply");
@ -213,7 +215,7 @@ public class Settings extends javax.swing.JInternalFrame {
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup() .addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jLabel1) .addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE)) .addGap(0, 96, Short.MAX_VALUE))
.addComponent(nameBox) .addComponent(nameBox)
); );
jPanel4Layout.setVerticalGroup( jPanel4Layout.setVerticalGroup(
@ -222,26 +224,48 @@ public class Settings extends javax.swing.JInternalFrame {
.addComponent(jLabel1) .addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)) .addContainerGap(13, Short.MAX_VALUE))
);
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Text size"));
textSize.setModel(new javax.swing.SpinnerNumberModel(12, 8, 48, 2));
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(textSize)
.addContainerGap())
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(textSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
); );
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(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.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)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 0, 0) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(applyBtn) .addComponent(applyBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveBtn))) .addComponent(saveBtn)))
@ -252,17 +276,18 @@ public class Settings extends javax.swing.JInternalFrame {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, 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)) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(applyBtn) .addComponent(applyBtn)
.addComponent(saveBtn)) .addComponent(saveBtn)))
.addGap(40, 40, 40)) .addGap(57, 57, 57))
); );
pack(); pack();
@ -288,6 +313,7 @@ public class Settings extends javax.swing.JInternalFrame {
skipUpdates.setSelected( skipUpdates.setSelected(
PrefStorage.getSetting("skipupdates", "").equals("yes")); PrefStorage.getSetting("skipupdates", "").equals("yes"));
nameBox.setText(PrefStorage.getSetting("author", "")); nameBox.setText(PrefStorage.getSetting("author", ""));
textSize.setValue(Integer.valueOf(PrefStorage.getSetting("editfont")));
}//GEN-LAST:event_formComponentShown }//GEN-LAST:event_formComponentShown
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed
@ -301,6 +327,7 @@ public class Settings extends javax.swing.JInternalFrame {
PrefStorage.saveSetting("quickstart", quickStart.isSelected() ? "yes" : ""); PrefStorage.saveSetting("quickstart", quickStart.isSelected() ? "yes" : "");
PrefStorage.saveSetting("skipupdates", skipUpdates.isSelected() ? "yes" : ""); PrefStorage.saveSetting("skipupdates", skipUpdates.isSelected() ? "yes" : "");
PrefStorage.saveSetting("author", nameBox.getText()); PrefStorage.saveSetting("author", nameBox.getText());
PrefStorage.saveSetting("editfont", String.valueOf(textSize.getValue()));
PrefStorage.save(); PrefStorage.save();
Main.updateDisplay(); Main.updateDisplay();
} }
@ -322,11 +349,13 @@ public class Settings extends javax.swing.JInternalFrame {
private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JTextField nameBox; private javax.swing.JTextField nameBox;
private javax.swing.JCheckBox quickStart; private javax.swing.JCheckBox quickStart;
private javax.swing.JButton saveBtn; private javax.swing.JButton saveBtn;
private javax.swing.JCheckBox showRecent; private javax.swing.JCheckBox showRecent;
private javax.swing.JCheckBox skipUpdates; private javax.swing.JCheckBox skipUpdates;
private javax.swing.JSpinner textSize;
private javax.swing.JRadioButton themeDark; private javax.swing.JRadioButton themeDark;
private javax.swing.ButtonGroup themeGroup; private javax.swing.ButtonGroup themeGroup;
private javax.swing.JRadioButton themeLight; private javax.swing.JRadioButton themeLight;

Loading…
Cancel
Save