📄 swinggui.java
字号:
package jmathlib.ui.swing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
/**
* Stand-alone GUI for the JMathLib package.
*
* Some options may be given in the command line, by example:
* <kbd>localhost# java MathLib.UI.Swing.SwingGUI -width 320 -height 200</kbd>.
* <p>
* <b>Command line options</b>
* <table cellpadding="1" cellspacing="0" border="1">
* <tr><td><kbd>-height</kbd></td><td>The height of the main window</td>
* <tr><td><kbd>-width</kbd></td><td>The width of the main window</td>
* </table>
* @version 2.0
*/
public class SwingGUI extends JFrame {
final String appTitle = "JMathLib SwingGUI";
static final String DEAFULT_PROPERTIES = "jmathlib/ui/swing/SwingGUI.properties";
public static SwingGUI runningReference;
Console answer = new Console();
JLabel statusBar = new JLabel();
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu("File");
JMenu jMenu2 = new JMenu("Edit");
JMenu jMenu3 = new JMenu("Window");
JMenu jMenu4 = new JMenu("Help");
JMenu jMenu5 = new JMenu("Tools");
JMenuItem jMenuItem2 = new JMenuItem("New");
JMenuItem jMenuItem3 = new JMenuItem("Open");
JMenuItem jMenuItem4 = new JMenuItem("Save");
JMenuItem jMenuItem5 = new JMenuItem("Save as...");
JMenuItem jMenuItem14 = new JMenuItem("Update Manager");
JMenuItem jMenuItem1 = new JMenuItem("Exit");
JMenuItem jMenuItem10 = new JMenuItem("Cut");
JMenuItem jMenuItem11 = new JMenuItem("Copy");
JMenuItem jMenuItem12 = new JMenuItem("Paste");
JMenuItem jMenuItem13 = new JMenuItem("Select All");
JMenuItem jMenuItem15 = new JMenuItem("Search Path");
JMenuItem jMenuItem16 = new JMenuItem("Configuration");
JMenuItem jMenuItem9 = new JMenuItem("JMathLib Documentation");
JMenuItem jMenuItem8 = new JMenuItem("Functions Reference");
JMenuItem jMenuItem7 = new JMenuItem("Release Notes");
JMenuItem jMenuItem6 = new JMenuItem("About SwingGUI...");
JScrollPane jScrollPane1 = new JScrollPane();
JSplitPane splitter2;
JTabbedPane editors = new JTabbedPane(JTabbedPane.NORTH);
ArrayList editorFiles = new ArrayList();
JFileChooser jFileChooser1;
/**
*
* @param args
*/
public SwingGUI(String[] args) {
runningReference = this;
loadProperties();
argumentHandler(args);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Command-line parameter handler
* Takes control of the size of the main window (by now)
*/
private void argumentHandler(String[] args)
{
int width = -1;
int height = -1;
// Parse all the arguments (or parameters)
for (int i = 0; i < args.length; i++)
{
String s;
if (args[i].equals("-width"))
{
try {
s = args[i + 1];
width = Integer.valueOf(s).intValue();
if (width < 0) {
throw new NumberFormatException();
}
i++;
}
catch (NumberFormatException nfe)
{
System.out.println(args[i + 1] + ": " + System.getProperty("ERRMSG001"));
width = -1;
}
catch (ArrayIndexOutOfBoundsException aiobe)
{
System.out.println(args[i] + ": " + System.getProperty("ERRMSG003"));
width = -1;
}
}
else if (args[i].equals("-height"))
{
try
{
s = args[i + 1];
height = Integer.valueOf(s).intValue();
if (width < 0) {
throw new NumberFormatException();
}
i++;
}
catch (NumberFormatException nfe)
{
System.out.println(args[i + 1] + ": " + System.getProperty("ERRMSG001"));
height = -1;
}
catch (ArrayIndexOutOfBoundsException aiobe)
{
System.out.println(args[i] + ": " + System.getProperty("ERRMSG002"));
width = -1;
}
}
else
{
System.out.println(args[i] + ": " + System.getProperty("ERRMSG002"));
}
}
// Let's resize the window...
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
if (width == -1) {
width = (d.width * 85) / 100;
}
if (height == -1) {
height = (d.height * 85) / 100;
}
this.setSize(width, height);
}
/**
*
*/
private void close()
{
CommandHistoryManager.getDefaultInstance().writeSessionHistory();
ApplicationConfiguration.getInstance().writeConfiguration();
this.dispose();
System.exit(0);
}
/**
*
* @return
*/
private static String getJavaRuntimeVersion()
{
String jrv = System.getProperty("java.runtime.version");
return jrv.substring(0, 3);
}
/**
*
* @throws Exception
*/
private void jbInit() throws Exception
{
// JBUILDER DESIGN NOTE: It should be changed the initialization of
// ANSWER to the "new JTextArea" defintion
this.setJMenuBar(jMenuBar1);
// Get the size of the screen
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
// position the frame in the centre of the screen
this.setLocationRelativeTo(null);
/*
this.setLocation((d.width-getSize().width) / 2,
(d.height-getSize().height) / 2);
*/
this.setIconImage(new ImageIcon(System.getProperty("ICON_FILE")).getImage());
this.setTitle(appTitle);
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
this_windowClosing(e);
}
});
jMenu1.setText(System.getProperty("MENU1_TXT"));
jMenu1.setMnemonic(System.getProperty("MENU1_MNE").charAt(0));
jMenuItem1.setText(System.getProperty("MENUITEM1_TXT"));
jMenuItem1.setMnemonic(System.getProperty("MENUITEM1_MNE").charAt(0));
try {
String s = System.getProperty("MENUITEM1_KS");
if (!s.equals("")) {
int ksp = new Integer(s).intValue();
s = System.getProperty("MENUITEM1_KSM");
int ksmp;
if (!s.equals("")) {
ksmp = new Integer(s).intValue();
} else {
ksmp = 0;
}
KeyStroke ks = KeyStroke.getKeyStroke(ksp, ksmp);
jMenuItem1.setAccelerator(ks);
}
} catch (Exception e) {
e.printStackTrace();
}
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
});
jMenu4.setText(System.getProperty("MENU4_TXT"));
jMenu4.setMnemonic(System.getProperty("MENU4_MNE").charAt(0));
jMenuItem2.setText(System.getProperty("MENUITEM2_TXT"));
jMenuItem2.setMnemonic(System.getProperty("MENUITEM2_MNE").charAt(0));
try {
String s = System.getProperty("MENUITEM2_KS");
if (!s.equals("")) {
int ksp = new Integer(s).intValue();
s = System.getProperty("MENUITEM2_KSM");
int ksmp;
if (!s.equals("")) {
ksmp = new Integer(s).intValue();
} else {
ksmp = 0;
}
KeyStroke ks = KeyStroke.getKeyStroke(ksp, ksmp);
jMenuItem2.setAccelerator(ks);
}
} catch (Exception e) {
e.printStackTrace();
}
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem2_actionPerformed(e);
}
});
jMenuItem3.setText(System.getProperty("MENUITEM3_TXT"));
jMenuItem3.setMnemonic(System.getProperty("MENUITEM3_MNE").charAt(0));
try {
String s = System.getProperty("MENUITEM3_KS");
if (!s.equals("")) {
int ksp = new Integer(s).intValue();
s = System.getProperty("MENUITEM3_KSM");
int ksmp;
if (!s.equals("")) {
ksmp = new Integer(s).intValue();
} else {
ksmp = 0;
}
KeyStroke ks = KeyStroke.getKeyStroke(ksp, ksmp);
jMenuItem3.setAccelerator(ks);
}
} catch (Exception e) {
e.printStackTrace();
}
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem3_actionPerformed(e);
}
});
jMenuItem4.setText(System.getProperty("MENUITEM4_TXT"));
jMenuItem4.setMnemonic(System.getProperty("MENUITEM4_MNE").charAt(0));
try {
String s = System.getProperty("MENUITEM4_KS");
if (!s.equals("")) {
int ksp = new Integer(s).intValue();
s = System.getProperty("MENUITEM4_KSM");
int ksmp;
if (!s.equals("")) {
ksmp = new Integer(s).intValue();
} else {
ksmp = 0;
}
KeyStroke ks = KeyStroke.getKeyStroke(ksp, ksmp);
jMenuItem4.setAccelerator(ks);
}
} catch (Exception e) {
e.printStackTrace();
}
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem4_actionPerformed(e);
}
});
jMenuItem5.setText(System.getProperty("MENUITEM5_TXT"));
jMenuItem5.setMnemonic(System.getProperty("MENUITEM5_MNE").charAt(0));
try
{
String s = System.getProperty("MENUITEM5_KS");
if (!s.equals("")) {
int ksp = new Integer(s).intValue();
s = System.getProperty("MENUITEM5_KSM");
int ksmp;
if (!s.equals("")) {
ksmp = new Integer(s).intValue();
} else {
ksmp = 0;
}
KeyStroke ks = KeyStroke.getKeyStroke(ksp, ksmp);
jMenuItem5.setAccelerator(ks);
}
}
catch (Exception e)
{
e.printStackTrace();
}
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem5_actionPerformed(e);
}
});
jMenuItem6.setText(System.getProperty("MENUITEM6_TXT"));
jMenuItem6.setMnemonic(System.getProperty("MENUITEM6_MNE").charAt(0));
try {
String s = System.getProperty("MENUITEM6_KS");
if (!s.equals("")) {
int ksp = new Integer(s).intValue();
s = System.getProperty("MENUITEM6_KSM");
int ksmp;
if (!s.equals("")) {
ksmp = new Integer(s).intValue();
} else {
ksmp = 0;
}
KeyStroke ks = KeyStroke.getKeyStroke(ksp, ksmp);
jMenuItem6.setAccelerator(ks);
}
} catch (Exception e) {
e.printStackTrace();
}
jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem6_actionPerformed(e);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -