Lots of things.

This commit is contained in:
skylarmt 2015-01-10 16:23:17 -07:00
parent 5ee2a6e345
commit cf7a74bde8
9 changed files with 289 additions and 158 deletions

2
gregrwgw.syjs Normal file
View File

@ -0,0 +1,2 @@
test
test

View File

@ -63,13 +63,13 @@ public class CodeEditor extends javax.swing.JInternalFrame {
private RSyntaxTextArea codeBox = new RSyntaxTextArea(); private RSyntaxTextArea codeBox = new RSyntaxTextArea();
private RTextScrollPane sp; private RTextScrollPane sp;
private String lastSaved = ""; private String lastSaved = "";
private CompletionProvider jscomp = new CodeCompleter("js").getProvider(); private CompletionProvider jscomp = new CodeCompleter("js").getProvider();
private CompletionProvider pycomp = new CodeCompleter("py").getProvider(); private CompletionProvider pycomp = new CodeCompleter("py").getProvider();
private AutoCompletion jsac = new AutoCompletion(jscomp); private AutoCompletion jsac = new AutoCompletion(jscomp);
private AutoCompletion pyac = new AutoCompletion(pycomp); private AutoCompletion pyac = new AutoCompletion(pycomp);
private String filename = ""; private File filedata;
/** /**
* Creates new form CodeEditor * Creates new form CodeEditor
@ -109,7 +109,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
formMouseClicked(evt); formMouseClicked(evt);
} }
}); });
jsac.install(codeBox); jsac.install(codeBox);
sp.setVisible(true); sp.setVisible(true);
codeBox.setVisible(true); codeBox.setVisible(true);
@ -435,10 +435,10 @@ public class CodeEditor extends javax.swing.JInternalFrame {
if (r == JFileChooser.APPROVE_OPTION) { if (r == JFileChooser.APPROVE_OPTION) {
try { try {
File f = fc.getSelectedFile(); File f = fc.getSelectedFile();
codeBox.setText(readFile(f.toString(), StandardCharsets.UTF_8)); codeBox.setText(FileUtils.readFile(f.toString()));
isSaved = true; isSaved = true;
filename = f.toString(); filedata = f;
lastSaved = codeBox.getText(); lastSaved = FileUtils.MD5(codeBox.getText());
setTitle("Editor - " + f.getName()); setTitle("Editor - " + f.getName());
} catch (IOException ex) { } catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this, JOptionPane.showInternalMessageDialog(this,
@ -455,8 +455,10 @@ public class CodeEditor extends javax.swing.JInternalFrame {
*/ */
public void openFileFromName(String file) { public void openFileFromName(String file) {
try { try {
Debug.println(file);
File f = new File(file); File f = new File(file);
openString(readFile(f.toString(), StandardCharsets.UTF_8), f.getName(), true); openString(FileUtils.readFile(f.getAbsolutePath()),
f.getAbsolutePath(), true);
} catch (IOException ex) { } catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this, JOptionPane.showInternalMessageDialog(this,
"Error: Cannot load file: " + ex.getMessage()); "Error: Cannot load file: " + ex.getMessage());
@ -472,8 +474,8 @@ public class CodeEditor extends javax.swing.JInternalFrame {
private void openString(String data, String file, boolean saved) { private void openString(String data, String file, boolean saved) {
codeBox.setText(data); codeBox.setText(data);
isSaved = saved; isSaved = saved;
lastSaved = codeBox.getText(); lastSaved = FileUtils.MD5(codeBox.getText());
setTitle("Editor - " + file); setTitle("Editor - " + (new File(file)).getName());
if (file.matches(".*\\.(js|mls|symt|syjs)")) { if (file.matches(".*\\.(js|mls|symt|syjs)")) {
javascriptOption.setSelected(true); javascriptOption.setSelected(true);
pythonOption.setSelected(false); pythonOption.setSelected(false);
@ -487,7 +489,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
jsac.uninstall(); jsac.uninstall();
pyac.install(codeBox); pyac.install(codeBox);
} }
filename = file; filedata = new File(file);
} }
private void saveMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuActionPerformed private void saveMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuActionPerformed
@ -495,31 +497,27 @@ public class CodeEditor extends javax.swing.JInternalFrame {
int r = fc.showSaveDialog(this); int r = fc.showSaveDialog(this);
if (r == JFileChooser.APPROVE_OPTION) { if (r == JFileChooser.APPROVE_OPTION) {
try { try {
saveFile(codeBox.getText(), addSaveExt(fc.getSelectedFile().toString())); filedata = FileUtils.getFileWithExtension(fc);
filename = fc.getSelectedFile().toString(); FileUtils.saveFile(codeBox.getText(), filedata.getAbsolutePath(), true);
isSaved = true;
lastSaved = FileUtils.MD5(codeBox.getText());
setTitle("Editor - "
+ FileUtils.getFileWithExtension(fc).getName());
} catch (IOException ex) { } catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this, "Error: Cannot save file: " + ex.getMessage()); JOptionPane.showInternalMessageDialog(this, "Error: Cannot save file: " + ex.getMessage());
} }
} }
} else { } else {
try { try {
saveFile(codeBox.getText(), addSaveExt(filename)); FileUtils.saveFile(codeBox.getText(), filedata.getAbsolutePath(), true);
} catch (IOException ex) { } catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this, "Error: Cannot save file: " + ex.getMessage()); JOptionPane.showInternalMessageDialog(this, "Error: Cannot save file: " + ex.getMessage());
} }
} }
Debug.println(filedata.toString());
Debug.println(filedata.getAbsolutePath());
}//GEN-LAST:event_saveMenuActionPerformed }//GEN-LAST:event_saveMenuActionPerformed
private String addSaveExt(String path) {
if (!path.matches(".*\\.(js|mls|symt|syjs|sypy|py)")) {
if (pythonOption.isSelected()) {
path += ".sypy";
} else {
path += ".syjs";
}
}
return path;
}
private void saveAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuActionPerformed private void saveAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuActionPerformed
isSaved = false; // Reset saved status, force dialog isSaved = false; // Reset saved status, force dialog
saveMenuActionPerformed(evt); saveMenuActionPerformed(evt);
@ -550,7 +548,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
execCode(lang); execCode(lang);
setRunning(false); setRunning(false);
} }
public void setRunning(boolean isRunning) { public void setRunning(boolean isRunning) {
final boolean running = isRunning; final boolean running = isRunning;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@ -679,20 +677,9 @@ public class CodeEditor extends javax.swing.JInternalFrame {
openString(text, name + "." + ext, false); openString(text, name + "." + ext, false);
} }
private void saveFile(String content, String path)
throws IOException {
try (PrintStream out = new PrintStream(new FileOutputStream(path))) {
out.print(content);
}
setTitle("Editor - " + (new File(path)).getName());
lastSaved = content;
isSaved = true;
MainGUI.addRecentFile(path);
}
@Override @Override
public void doDefaultCloseAction() { public void doDefaultCloseAction() {
if (lastSaved.equals(codeBox.getText())) { if (lastSaved.equals(FileUtils.MD5(codeBox.getText()))) {
dispose(); dispose();
} else { } else {
int p = JOptionPane.showInternalConfirmDialog(this, int p = JOptionPane.showInternalConfirmDialog(this,
@ -708,11 +695,6 @@ public class CodeEditor extends javax.swing.JInternalFrame {
} }
} }
private static String readFile(String path, Charset encoding)
throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton clearBtn; private javax.swing.JButton clearBtn;

View File

@ -0,0 +1,116 @@
/*
* Apocalypse Laboratories
* Open Source License
*
* Source code can be used for any purpose, as long as:
* - Compiled binaries are rebranded and trademarks are not
* visible by the end user at any time, except to give
* credit to Apocalypse Laboratories, such as by showing
* "Based on <product> by Apocalypse Laboratories" or a
* similar notice;
* - You do not use the code for evil;
* - Rebranded compiled applications have significant
* differences in functionality;
* - and you provide your modified source code for download,
* under the terms of the GNU LGPL v3 or a comparable
* license.
*
* Compiled binaries cannot be redistributed or mirrored,
* unless:
* - You have written permission from Apocalypse Laboratories;
* - Downloads are not available from Apocalypse Laboratories,
* not even behind a paywall or other blocking mechanism;
* - or you have received a multi-computer license, in which
* case you should take measures to prevent unauthorized
* downloads, such as preventing download access from the
* Internet.
*/
package net.apocalypselabs.symat;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* File Utilities.
*
* @author Skylar
*/
public class FileUtils {
/**
* Read a UTF-8 text file.
*
* @param path Where is the file?
* @return The file contents.
* @throws IOException
*/
public static String readFile(String path)
throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, StandardCharsets.UTF_8);
}
/**
* Returns the selected file from a JFileChooser, including the extension
* from the file filter.
*
* Credit to http://stackoverflow.com/users/964243/boann
*
* @param c The JFileChooser to extract from.
* @return duh.
*/
public static File getFileWithExtension(JFileChooser c) {
File file = c.getSelectedFile();
if (c.getFileFilter() instanceof FileNameExtensionFilter) {
String[] exts = ((FileNameExtensionFilter) c.getFileFilter()).getExtensions();
String nameLower = file.getName().toLowerCase();
for (String ext : exts) { // check if it already has a valid extension
if (nameLower.endsWith('.' + ext.toLowerCase())) {
return file; // if yes, return as-is
}
}
// if not, append the first extension from the selected filter
file = new File(file.toString() + '.' + exts[0]);
}
return file;
}
public static void saveFile(String content, String path, boolean addToRecent)
throws IOException {
try (PrintStream out = new PrintStream(new FileOutputStream(path))) {
out.print(content);
}
if (addToRecent) {
MainGUI.addRecentFile((new File(path)).getAbsolutePath());
}
}
/**
* Get an MD5 hash.
*
* http://stackoverflow.com/a/6565597/2534036
* @param md5 the text to hash.
* @return
*/
public static String MD5(String md5) {
try {
java.security.MessageDigest md =
java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
}
return null;
}
}

View File

@ -6,6 +6,36 @@
</Component> </Component>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1"> <Menu class="javax.swing.JMenuBar" name="jMenuBar1">
<SubComponents> <SubComponents>
<Menu class="javax.swing.JMenu" name="jMenu3">
<Properties>
<Property name="text" type="java.lang.String" value="File"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="exportHistoryBtn">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+S"/>
</Property>
<Property name="text" type="java.lang.String" value="Save history..."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exportHistoryBtnActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu4">
<Properties>
<Property name="text" type="java.lang.String" value="Edit"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem1">
<Properties>
<Property name="text" type="java.lang.String" value="Clear window"/>
</Properties>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="langMenu"> <Menu class="javax.swing.JMenu" name="langMenu">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Language"/> <Property name="text" type="java.lang.String" value="Language"/>

View File

@ -30,8 +30,14 @@ package net.apocalypselabs.symat;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.DefaultCaret; import javax.swing.text.DefaultCaret;
import org.fife.ui.autocomplete.AutoCompletion; import org.fife.ui.autocomplete.AutoCompletion;
import org.fife.ui.autocomplete.CompletionProvider; import org.fife.ui.autocomplete.CompletionProvider;
@ -44,10 +50,11 @@ public class Interpreter extends javax.swing.JInternalFrame {
private final CodeRunner cr; private final CodeRunner cr;
private String[] history = new String[10]; // Command history buffer private String[] history = new String[10]; // Command history buffer
private String commandsForExport = ""; // History for saving
private int historyIndex = 0; // For going back in time and keeping things straight private int historyIndex = 0; // For going back in time and keeping things straight
private String lang = "javascript"; private String lang = "javascript";
private Object ans = 0; private Object ans = 0;
private CompletionProvider jscomp = new CodeCompleter("js").getProvider(); private CompletionProvider jscomp = new CodeCompleter("js").getProvider();
private CompletionProvider pycomp = new CodeCompleter("py").getProvider(); private CompletionProvider pycomp = new CodeCompleter("py").getProvider();
private AutoCompletion jsac = new AutoCompletion(jscomp); private AutoCompletion jsac = new AutoCompletion(jscomp);
@ -115,6 +122,10 @@ public class Interpreter extends javax.swing.JInternalFrame {
runBtn = new javax.swing.JButton(); runBtn = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar(); jMenuBar1 = new javax.swing.JMenuBar();
jMenu3 = new javax.swing.JMenu();
exportHistoryBtn = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
langMenu = new javax.swing.JMenu(); langMenu = new javax.swing.JMenu();
jMenu1 = new javax.swing.JMenu(); jMenu1 = new javax.swing.JMenu();
javascriptMenu = new javax.swing.JRadioButtonMenuItem(); javascriptMenu = new javax.swing.JRadioButtonMenuItem();
@ -181,6 +192,26 @@ public class Interpreter extends javax.swing.JInternalFrame {
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText(">>"); jLabel1.setText(">>");
jMenu3.setText("File");
exportHistoryBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
exportHistoryBtn.setText("Save history...");
exportHistoryBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exportHistoryBtnActionPerformed(evt);
}
});
jMenu3.add(exportHistoryBtn);
jMenuBar1.add(jMenu3);
jMenu4.setText("Edit");
jMenuItem1.setText("Clear window");
jMenu4.add(jMenuItem1);
jMenuBar1.add(jMenu4);
langMenu.setText("Language"); langMenu.setText("Language");
jMenu1.setText("Switch"); jMenu1.setText("Switch");
@ -359,8 +390,34 @@ public class Interpreter extends javax.swing.JInternalFrame {
} }
}//GEN-LAST:event_fontBtnActionPerformed }//GEN-LAST:event_fontBtnActionPerformed
private void exportHistoryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportHistoryBtnActionPerformed
JFileChooser fc = new JFileChooser();
FileFilter filter;
if (javascriptMenu.isSelected()) {
filter = new FileNameExtensionFilter("SyMAT JavaScript (.syjs)", "syjs");
} else {
filter = new FileNameExtensionFilter("SyMAT Python (.sypy)", "sypy");
}
fc.setFileFilter(filter);
fc.addChoosableFileFilter(filter);
int result = fc.showSaveDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
try {
FileUtils.saveFile(commandsForExport,
FileUtils.getFileWithExtension(fc).toString(),
false);
} catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this,
"Error saving: "+ex.getMessage(),
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
}//GEN-LAST:event_exportHistoryBtnActionPerformed
private void doRunCode() { private void doRunCode() {
String code = inputBox.getText(); String code = inputBox.getText();
commandsForExport += code + "\n";
mainBox.append(" " + code + "\n"); mainBox.append(" " + code + "\n");
new EvalThread(code).start(); new EvalThread(code).start();
} }
@ -449,12 +506,16 @@ public class Interpreter extends javax.swing.JInternalFrame {
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem exportHistoryBtn;
private javax.swing.JMenuItem fontBtn; private javax.swing.JMenuItem fontBtn;
private javax.swing.JTextField inputBox; private javax.swing.JTextField inputBox;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JRadioButtonMenuItem javascriptMenu; private javax.swing.JRadioButtonMenuItem javascriptMenu;
private javax.swing.ButtonGroup langGroup; private javax.swing.ButtonGroup langGroup;

View File

@ -343,7 +343,7 @@
<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="recentItemsPanel" min="-2" max="-2" attributes="0"/> <Component id="recentItemsPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="184" max="32767" attributes="0"/> <EmptySpace pref="145" max="32767" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/> <Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -403,8 +403,8 @@
<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">
<Component id="recentItemsTitle" min="-2" max="-2" attributes="0"/> <Component id="recentItemsTitle" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="167" max="-2" attributes="0"/> <Component id="jScrollPane1" pref="206" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="recentFileBtn" min="-2" max="-2" attributes="0"/> <Component id="recentFileBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>

View File

@ -181,11 +181,14 @@ public class MainGUI extends javax.swing.JFrame {
neededLength++; neededLength++;
} }
} }
if (neededLength > 10) {
neededLength = 10;
}
KeyValListItem[] items = new KeyValListItem[neededLength]; KeyValListItem[] items = new KeyValListItem[neededLength];
int i = 0; int i = 0;
for (String f : fileList) { for (String f : fileList) {
File file = new File(f); File file = new File(f);
if (file.isFile()) { if (file.isFile() && i < neededLength) {
items[i] = new KeyValListItem(file.getName(), file.getPath()); items[i] = new KeyValListItem(file.getName(), file.getPath());
i++; i++;
} }
@ -202,6 +205,7 @@ public class MainGUI extends javax.swing.JFrame {
} }
public static void addRecentFile(String file) { public static void addRecentFile(String file) {
file = (new File(file)).getAbsolutePath();
String files = PrefStorage.getSetting("recentfiles"); String files = PrefStorage.getSetting("recentfiles");
String[] fileList = files.split("\n"); String[] fileList = files.split("\n");
for (int i = 0; i < fileList.length; i++) { for (int i = 0; i < fileList.length; i++) {
@ -500,8 +504,8 @@ public class MainGUI extends javax.swing.JFrame {
recentItemsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) recentItemsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(recentItemsPanelLayout.createSequentialGroup() .addGroup(recentItemsPanelLayout.createSequentialGroup()
.addComponent(recentItemsTitle) .addComponent(recentItemsTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(recentFileBtn) .addComponent(recentFileBtn)
.addContainerGap()) .addContainerGap())
@ -523,7 +527,7 @@ public class MainGUI extends javax.swing.JFrame {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPaneLayout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPaneLayout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(recentItemsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(recentItemsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 184, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 145, Short.MAX_VALUE)
.addComponent(jLabel2) .addComponent(jLabel2)
.addContainerGap()) .addContainerGap())
); );
@ -599,6 +603,7 @@ public class MainGUI extends javax.swing.JFrame {
return; return;
} }
CodeEditor edit = new CodeEditor(); CodeEditor edit = new CodeEditor();
Debug.println(file.getValue());
edit.openFileFromName(file.getValue()); edit.openFileFromName(file.getValue());
loadFrame(edit); loadFrame(edit);
}//GEN-LAST:event_recentFileBtnActionPerformed }//GEN-LAST:event_recentFileBtnActionPerformed

View File

@ -7,12 +7,15 @@
<Connection code="MainGUI.APP_NAME" type="code"/> <Connection code="MainGUI.APP_NAME" type="code"/>
</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="[204, 260]"/> <Dimension value="[400, 320]"/>
</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="[204, 260]"/> <Dimension value="[400, 320]"/>
</Property> </Property>
<Property name="undecorated" type="boolean" value="true"/> <Property name="undecorated" type="boolean" value="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[400, 320]"/>
</Property>
<Property name="resizable" type="boolean" value="false"/> <Property name="resizable" type="boolean" value="false"/>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
@ -32,48 +35,31 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,84,0,0,1,-112"/> <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,64,0,0,1,-112"/>
</AuxValues> </AuxValues>
<Layout> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<DimensionLayout dim="0"> <Property name="useNullLayout" type="boolean" value="true"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="progBar" max="32767" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="progBar" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JProgressBar" name="progBar"> <Component class="javax.swing.JLabel" name="dispLabel">
<Properties> <Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Dimension value="[32767, 20]"/> <Font name="Tahoma" size="18" style="0"/>
</Property> </Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="horizontalAlignment" type="int" value="0"/>
<Dimension value="[10, 20]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[146, 20]"/>
</Property>
<Property name="string" type="java.lang.String" value=""/>
<Property name="stringPainted" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<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">
<Image iconType="3" name="/net/apocalypselabs/symat/splash.gif"/> <Image iconType="3" name="/net/apocalypselabs/symat/splash.gif"/>
</Property> </Property>
<Property name="text" type="java.lang.String" value="&lt;html&gt;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="horizontalTextPosition" type="int" value="0"/>
</Properties> </Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="0" y="0" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component> </Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -27,23 +27,15 @@
*/ */
package net.apocalypselabs.symat; package net.apocalypselabs.symat;
import java.awt.Color;
import java.awt.Graphics2D;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JProgressBar;
import javax.swing.Painter;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import static net.apocalypselabs.symat.MainGUI.API_URL; import static net.apocalypselabs.symat.MainGUI.API_URL;
import static net.apocalypselabs.symat.MainGUI.APP_CODE; import static net.apocalypselabs.symat.MainGUI.APP_CODE;
import static net.apocalypselabs.symat.MainGUI.VERSION_NAME; import static net.apocalypselabs.symat.MainGUI.VERSION_NAME;
import static net.apocalypselabs.symat.MainGUI.loadFrame;
/** /**
* *
@ -56,36 +48,12 @@ public class SplashScreen extends javax.swing.JFrame {
*/ */
public SplashScreen() { public SplashScreen() {
initComponents(); initComponents();
UIDefaults defaults = new UIDefaults();
defaults.put("ProgressBar[Enabled].backgroundPainter", new ProgressPainter(false));
defaults.put("ProgressBar[Enabled].foregroundPainter", new ProgressPainter(true));
progBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
progBar.putClientProperty("Nimbus.Overrides", defaults);
setIconImage((new ImageIcon( setIconImage((new ImageIcon(
getClass().getResource("icon.png"))).getImage()); getClass().getResource("icon.png"))).getImage());
setLocationRelativeTo(null); setLocationRelativeTo(null);
} }
class ProgressPainter implements Painter<JProgressBar> {
private final Color color;
public ProgressPainter(boolean foreground) {
if (foreground) {
this.color = new Color(86, 161, 243);
} else {
this.color = new Color(59, 127, 243);
}
}
@Override
public void paint(Graphics2D gd, JProgressBar t, int width, int height) {
gd.setColor(color);
gd.fillRect(0, 0, width, height);
}
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always
@ -95,43 +63,30 @@ public class SplashScreen extends javax.swing.JFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
progBar = new javax.swing.JProgressBar(); dispLabel = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(MainGUI.APP_NAME); setTitle(MainGUI.APP_NAME);
setMaximumSize(new java.awt.Dimension(204, 260)); setMaximumSize(new java.awt.Dimension(400, 320));
setMinimumSize(new java.awt.Dimension(204, 260)); setMinimumSize(new java.awt.Dimension(400, 320));
setUndecorated(true); setUndecorated(true);
setPreferredSize(new java.awt.Dimension(400, 320));
setResizable(false); setResizable(false);
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);
} }
}); });
getContentPane().setLayout(null);
progBar.setMaximumSize(new java.awt.Dimension(32767, 20)); dispLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
progBar.setMinimumSize(new java.awt.Dimension(10, 20)); dispLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
progBar.setPreferredSize(new java.awt.Dimension(146, 20)); dispLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/splash.gif"))); // NOI18N
progBar.setString(""); dispLabel.setText("<html><br><br>&nbsp;&nbsp;&nbsp;");
progBar.setStringPainted(true); dispLabel.setToolTipText("");
dispLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/splash.gif"))); // NOI18N getContentPane().add(dispLabel);
dispLabel.setBounds(0, 0, 400, 320);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(progBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(0, 0, 0)
.addComponent(progBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
@ -147,11 +102,11 @@ public class SplashScreen extends javax.swing.JFrame {
@Override @Override
public void run() { public void run() {
setProgress(10, "Starting up..."); setProgress("Starting up...");
if (!MainGUI.skipPython) { if (!MainGUI.skipPython) {
// Python laggggsss when used for first time, this fixes the wait later. // Python laggggsss when used for first time, this fixes the wait later.
System.out.println("Warming up Python engine, to skip run with argument 'skippython'"); System.out.println("Warming up Python engine, to skip run with argument 'skippython'");
setProgress(15, "Initializing code engine..."); setProgress("Initializing code engine...");
try { try {
CodeRunner python = new CodeRunner(true); CodeRunner python = new CodeRunner(true);
} catch (Exception ex) { } catch (Exception ex) {
@ -161,17 +116,17 @@ public class SplashScreen extends javax.swing.JFrame {
if (!MainGUI.skipEditor) { if (!MainGUI.skipEditor) {
System.out.println("Preparing editor, to skip run with argument 'skipeditor'"); System.out.println("Preparing editor, to skip run with argument 'skipeditor'");
setProgress(60, "Preparing editor..."); setProgress("Preparing editor...");
// Get editor going too // Get editor going too
CodeEditor edit = new CodeEditor(); CodeEditor edit = new CodeEditor();
} }
setProgress(75, "Checking for updates..."); setProgress("Checking for updates...");
checkUpdates(); checkUpdates();
setProgress(85, "Loading main interface..."); setProgress("Loading main interface...");
new MainGUI().setVisible(true); new MainGUI().setVisible(true);
setProgress(100, "Done!"); setProgress("Done!");
dispose(); dispose();
} }
@ -208,26 +163,20 @@ public class SplashScreen extends javax.swing.JFrame {
} }
/** /**
* Set the progress bar. * Set the progress text.
*
* @param progress how full to make it (0 <= progress <= 100)
* @param label The String to put on the label. * @param label The String to put on the label.
*/ */
private void setProgress(int progress, String label) { private void setProgress(String label) {
final int prog = progress;
final String lbl = label; final String lbl = label;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
progBar.setIndeterminate(false); dispLabel.setText("<html><br><br>&nbsp;&nbsp;&nbsp;"+lbl);
progBar.setValue(prog);
progBar.setString(lbl);
} }
}); });
} }
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel5; private javax.swing.JLabel dispLabel;
private javax.swing.JProgressBar progBar;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }