357 lines
15 KiB
Java
Raw Normal View History

2014-12-06 21:07:02 -07:00
/*
* 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.
2014-11-30 00:34:17 -07:00
*/
package net.apocalypselabs.symat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
/**
*
* @author Skylar
*/
public class MainGUI extends javax.swing.JFrame {
public static final String APP_NAME = "SyMAT 0.6";
public static final double APP_CODE = 0.6;
public static String argfile = "";
2014-11-30 00:34:17 -07:00
/**
* Creates new form MainGUI
*/
public MainGUI() {
initComponents();
setIconImage((new ImageIcon(getClass().getResource("icon.png"))).getImage());
setLocationRelativeTo(null);
try {
URL url = new URL("http://symat.aplabs.us/version.txt");
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
br.close();
is.close();
double version = Double.parseDouble(line);
if (version > APP_CODE) {
if (PrefStorage.getSetting("update-ignore").equals(APP_CODE + "|" + version)) {
2014-11-30 00:34:17 -07:00
System.err.println("An update was found, but has been ignored by the user.");
} else {
loadFrame(new Update(version));
}
}
} catch (IOException | NumberFormatException e) {
System.err.println("Fail: Cannot check update server. \n"
+ " Assuming local copy up-to-date.");
}
// Open shell unless prog was run with argument
if (argfile.equals("")) {
Interpreter sh = new Interpreter();
loadFrame(sh);
} else {
CodeEditor ed = new CodeEditor();
loadFrame(ed);
ed.openFileFromString(argfile);
argfile = "";
2014-11-30 00:34:17 -07:00
}
}
private static String namemark() {
String nbsp = "";
for (int i = 0; i < 8; i++) {
nbsp += "&nbsp;";
}
return "<html>"
+ nbsp
+ "<span style=\"color: gray; font-size: 130%;\"><i>"
+ APP_NAME
+ "</i></span>&nbsp;&nbsp;";
}
2014-11-30 00:34:17 -07:00
/**
* 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
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
2014-11-30 00:34:17 -07:00
mainPane = new javax.swing.JDesktopPane();
tabs = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
2014-11-30 00:34:17 -07:00
shellBtn = new javax.swing.JButton();
editorBtn = new javax.swing.JButton();
graphBtn = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
helpBtn = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
2014-11-30 00:34:17 -07:00
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(APP_NAME);
addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentShown(java.awt.event.ComponentEvent evt) {
formComponentShown(evt);
}
});
mainPane.setBackground(new java.awt.Color(204, 204, 204));
javax.swing.GroupLayout mainPaneLayout = new javax.swing.GroupLayout(mainPane);
mainPane.setLayout(mainPaneLayout);
mainPaneLayout.setHorizontalGroup(
mainPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
2014-11-30 00:34:17 -07:00
);
mainPaneLayout.setVerticalGroup(
mainPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 407, Short.MAX_VALUE)
2014-11-30 00:34:17 -07:00
);
shellBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/shell.png"))); // NOI18N
shellBtn.setText("Shell");
shellBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
2014-11-30 00:34:17 -07:00
shellBtn.setFocusable(false);
shellBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
shellBtn.setOpaque(false);
shellBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
shellBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
shellBtnActionPerformed(evt);
}
});
editorBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/editor.png"))); // NOI18N
editorBtn.setText("Editor");
editorBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
2014-11-30 00:34:17 -07:00
editorBtn.setFocusable(false);
editorBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
editorBtn.setOpaque(false);
editorBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
editorBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editorBtnActionPerformed(evt);
}
});
graphBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/graph.png"))); // NOI18N
graphBtn.setText("Graph");
graphBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
2014-11-30 00:34:17 -07:00
graphBtn.setFocusable(false);
graphBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
graphBtn.setOpaque(false);
graphBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
graphBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
graphBtnActionPerformed(evt);
}
});
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel1.setText(namemark());
jLabel1.setFocusable(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(shellBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editorBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(graphBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(shellBtn)
.addComponent(editorBtn))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(graphBtn))
);
tabs.addTab("Apps", jPanel1);
2014-11-30 00:34:17 -07:00
helpBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/help.png"))); // NOI18N
helpBtn.setText("Help");
helpBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
2014-11-30 00:34:17 -07:00
helpBtn.setFocusable(false);
helpBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
helpBtn.setOpaque(false);
helpBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
helpBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
helpBtnActionPerformed(evt);
}
});
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel3.setText(namemark());
jLabel3.setFocusable(false);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(helpBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 630, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(helpBtn)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
);
tabs.addTab("Tools", jPanel2);
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel2.setText(namemark());
jLabel2.setFocusable(false);
tabs.addTab("Settings", jLabel2);
2014-11-30 00:34:17 -07:00
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mainPane)
.addComponent(tabs)
2014-11-30 00:34:17 -07:00
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
2014-11-30 00:34:17 -07:00
.addComponent(mainPane))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void shellBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shellBtnActionPerformed
Interpreter i = new Interpreter();
loadFrame(i);
}//GEN-LAST:event_shellBtnActionPerformed
private void editorBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editorBtnActionPerformed
CodeEditor e = new CodeEditor();
loadFrame(e);
}//GEN-LAST:event_editorBtnActionPerformed
private void graphBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphBtnActionPerformed
Graph g = new Graph();
loadFrame(g);
}//GEN-LAST:event_graphBtnActionPerformed
private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
setLocationRelativeTo(null);
}//GEN-LAST:event_formComponentShown
2014-11-30 00:34:17 -07:00
private void helpBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpBtnActionPerformed
Help h = new Help();
loadFrame(h);
}//GEN-LAST:event_helpBtnActionPerformed
public static void loadFrame(JInternalFrame frame) {
mainPane.add(frame);
frame.setLocation(
(mainPane.getWidth() / 2) - (frame.getWidth() / 2),
(mainPane.getHeight() / 2) - (frame.getHeight() / 2));
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new MainGUI().setVisible(true);
}
});
// Trigger open passed script file
if (args.length == 1) {
argfile = args[0];
}
2014-11-30 00:34:17 -07:00
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton editorBtn;
private javax.swing.JButton graphBtn;
private javax.swing.JButton helpBtn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
2014-11-30 00:34:17 -07:00
public static javax.swing.JDesktopPane mainPane;
private javax.swing.JButton shellBtn;
private javax.swing.JTabbedPane tabs;
2014-11-30 00:34:17 -07:00
// End of variables declaration//GEN-END:variables
}