📄 javaide.java
字号:
package org.loon.framework.ide.test;
/**
* <p>Title: LoonFramework</p>
* <p>Description:启动用类</p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: LoonFramework</p>
* @author chenpeng
* @email:ceponline@yahoo.com.cn
* @version 0.1
*/
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.loon.framework.ide.test.data.ConfigData;
import org.loon.framework.ide.test.dialog.ConfigDialog;
import org.loon.framework.ide.test.dialog.ErrorDialog;
import org.loon.framework.ide.test.dialog.FontDialog;
import org.loon.framework.ide.test.dialog.PreviewDialog;
import org.loon.framework.ide.test.dialog.SearchDialog;
import org.loon.framework.ide.test.dialog.VersionDialog;
public class JavaIDE extends JFrame implements ActionListener, WindowListener,
ChangeListener {
/**
*
*/
private static final long serialVersionUID = 1L;
Container contentPane;
static final Font LABEL_FONT = new Font("宋体", 0, 13);
JTabbedPane tabPane;
Vector vectorEdit;
JLabel labelState;
final String strMenu[] = { "文件", "编辑", "搜索", "生成", "设定", "帮助" };
final String strMenuNemonic[] = { "F", "E", "Q", "M", "S", "H" };
final int intMenuNemonic[] = { 70, 69, 83, 84, 67, 72 };
final String strItem[][] = {
{ "新文件", "新文件(类型选择)", "打开", "保存", "另存为", "保存为HTML格式", "关闭文档", "打印",
"退出" },
{ "光标上移", "光标下移", "剪切", "拷贝", "粘贴", "清除", "全选", "字体设定", "对齐" },
{ "查找", "替换" },
{ "编译文件", "启动Java Applcation", "启动Java Applet", "启动Javadoc" },
{ "参数设定", "风格转换" }, { "Java帮助文档", "作者blog", "关于" } };
final String strItemNemonic[][] = {
{ "N", "M", "O", "S", "A", "W", "C", "P", "X" },
{ "U", "R", "T", "C", "P", "L", "A", "F", "N" }, { "F", "H" },
{ "J", "1", "2", "D" }, { "C", "L" }, { "R", "H", "A" } };
final int intItemNemonic[][] = { { 78, 77, 79, 83, 65, 87, 67, 80, 88 },
{ 85, 82, 84, 67, 80, 76, 65, 70, 78 }, { 70, 72 },
{ 74, 49, 50, 68 }, { 67, 76 }, { 82, 72, 65 } };
final int intKeyStrokeCode[][] = { { 78, 77, 79, 83, 0, 0, 0, 80, 0 },
{ 90, 89, 88, 67, 86, 127, 65, 116, 117 }, { 70, 72 },
{ 74, 49, 50, 0 }, { 118, 119 }, { 120, 0, 0 } };
final int intKeyStrokeMode[][] = { { 2, 2, 2, 2, 0, 0, 0, 2, 0 },
{ 2, 2, 2, 2, 2, 0, 2, 0, 0 }, { 2, 2 }, { 2, 2, 2, 0 }, { 0, 0 },
{ 0, 0, 0 } };
JMenuBar menuBar;
JMenu menu[];
JMenuItem menuItem[][];
JPopupMenu popMenu;
JMenuItem popItem[];
final Icon iconMenu[];
final String strIconCommand[] = { "新文件", "新文件(类型选择)", "关闭文档", "保存", "另存为",
"保存为HTML格式", "查找", "替换", "编译文件", "启动Java Applcation",
"启动Java Applet" };
JButton buttonIcon[];
JToolBar toolBar;
JFileChooser fileChooser;
OpenFilter ff;
FontDialog fontDialog;
SearchDialog searchDialog;
ConfigDialog configDialog;
JOptionPane op;
static final int NAME = 0;
static final int PATH = 1;
ConfigData config;
static final String strMes[] = { "编译成功" };
public JavaIDE() throws Exception {
super("JavaIDE 0.1(由loonframework提供)");
tabPane = new JTabbedPane(3);
vectorEdit = new Vector(0, 1);
labelState = new JLabel();
menuBar = new JMenuBar();
popMenu = new JPopupMenu();
iconMenu = (new Icon[] { new ImageIcon(ImageSource.iconNew),
new ImageIcon(ImageSource.iconProto),
new ImageIcon(ImageSource.iconClose),
new ImageIcon(ImageSource.iconOpen),
new ImageIcon(ImageSource.iconSave),
new ImageIcon(ImageSource.iconSaveAs),
new ImageIcon(ImageSource.iconSearch),
new ImageIcon(ImageSource.iconChange),
new ImageIcon(ImageSource.iconCompile),
new ImageIcon(ImageSource.iconRun1),
new ImageIcon(ImageSource.iconRun2) });
buttonIcon = new JButton[iconMenu.length];
toolBar = new JToolBar();
ff = new OpenFilter();
op = new JOptionPane();
addWindowListener(this);
contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add("Center", tabPane);
contentPane.add("South", labelState);
contentPane.add("North", toolBar);
configDialog = new ConfigDialog(this);
config = configDialog.getConfigData();
fileChooser = new JFileChooser(config.getLastFolder());
LookAndFeel.lookCount = config.getLastLookAndFeel();
addNewElement();
labelState.setFont(LABEL_FONT);
menu = new JMenu[strMenu.length];
menuItem = new JMenuItem[strMenu.length][];
for (int i = 0; i < strMenu.length; i++) {
menu[i] = new JMenu(strMenu[i] + "(" + strMenuNemonic[i] + ")");
menu[i].setFont(new Font("宋体", 0, 13));
menu[i].setMnemonic(intMenuNemonic[i]);
menuBar.add(menu[i]);
menuItem[i] = new JMenuItem[strItem[i].length];
for (int j = 0; j < strItem[i].length; j++) {
menuItem[i][j] = new JMenuItem(strItem[i][j] + "("
+ strItemNemonic[i][j] + ")");
menuItem[i][j].setMnemonic(intItemNemonic[i][j]);
menuItem[i][j].addActionListener(this);
menuItem[i][j].setActionCommand(strItem[i][j]);
menuItem[i][j].setFont(new Font("宋体", 2, 13));
menu[i].add(menuItem[i][j]);
if (intKeyStrokeCode[i][j] != 0)
menuItem[i][j].setAccelerator(KeyStroke.getKeyStroke(
intKeyStrokeCode[i][j], intKeyStrokeMode[i][j]));
if (i == 0 && (j == 5 || j == 6 || j == 7))
menu[i].addSeparator();
if (i == 1 && (j == 1 || j == 6 || j == 7))
menu[i].addSeparator();
if (i == 3 && (j == 0 || j == 2))
menu[i].addSeparator();
if (i == 4 && j == 0)
menu[i].addSeparator();
if (i == 5 && j == 0)
menu[i].addSeparator();
}
}
setJMenuBar(menuBar);
for (int l = 0; l < iconMenu.length; l++) {
buttonIcon[l] = new JButton(iconMenu[l]);
buttonIcon[l].setActionCommand(strIconCommand[l]);
buttonIcon[l].setToolTipText(strIconCommand[l]);
buttonIcon[l].addActionListener(this);
buttonIcon[l].setFont(new Font("宋体", 2, 10));
toolBar.add(buttonIcon[l]);
if (l == 1 || l == 2 || l == 5 || l == 7 || l == 8)
toolBar.addSeparator();
}
setSize(config.getSizeX(), config.getSizeY());
setLocation(config.getLocationX(), config.getLocationY());
searchDialog = new SearchDialog(this);
setLookAndFeel();
java.awt.Image image = ImageSource.iconTitle;
setIconImage(image);
setVisible(true);
if (!(new File(config.getJavaPath())).exists()) {
JOptionPane.showMessageDialog(this, "没有找到JDK所在路径,请设定后操作。",
"JavaIDE : 提示", 1);
}
if (!(new File(config.getBrowserPath())).exists()) {
JOptionPane.showMessageDialog(this, "没有找到浏览器所在路径,请设定后操作。",
"JavaIDE : 提示", 1);
}
((Editor) vectorEdit.elementAt(0)).setCursor();
tabPane.addChangeListener(this);
}
public void stateChanged(ChangeEvent changeevent) {
int i = tabPane.getSelectedIndex();
if (i == -1) {
return;
} else {
catchFocus();
return;
}
}
public void windowClosing(WindowEvent windowevent) {
finalCheck();
}
public void windowOpened(WindowEvent windowevent) {
}
public void windowClosed(WindowEvent windowevent) {
}
public void windowIconified(WindowEvent windowevent) {
}
public void windowDeiconified(WindowEvent windowevent) {
}
public void windowActivated(WindowEvent windowevent) {
}
public void windowDeactivated(WindowEvent windowevent) {
}
public void actionPerformed(ActionEvent actionevent) {
String s = actionevent.getActionCommand();
String[] itemName = strItem[0];
if (s.equals(itemName[0])) {
addNewElement();
labelState.setText("新文件已打开");
}
if (s.equals(itemName[1])) {
openProtoType();
}
if (s.equals(itemName[2])) {
openFile();
}
if (s.equals(itemName[3])) {
overWrite();
}
if (s.equals(itemName[4])) {
saveAs();
}
if (s.equals(itemName[5])) {
saveAsHTML();
}
// 关闭
if (s.equals(itemName[6])) {
closeSheet();
}
if (s.equals(itemName[7])) {
String name = getCurrentEditor().getText();
if (name.equals("")) {
JOptionPane.showMessageDialog(this, "没有可以打印的文档!",
"JavaIDE : 打印", 1);
} else {
new PreviewDialog(this, name, new Font("System", 0, 10));
}
}
if (s.equals(itemName[8])) {
finalCheck();
}
itemName = strItem[1];
if (s.equals(itemName[0]))
getCurrentEditor().editorUndo();
if (s.equals(itemName[1]))
getCurrentEditor().editorRedo();
if (s.equals(itemName[2]))
getCurrentEditor().getJavaText().cut();
if (s.equals(itemName[3]))
getCurrentEditor().getJavaText().copy();
if (s.equals(itemName[4]))
getCurrentEditor().getJavaText().paste();
if (s.equals(itemName[5]))
getCurrentEditor().getJavaText().replaceSelection("");
if (s.equals(itemName[6]))
getCurrentEditor().selectAll();
if (s.equals(itemName[7])) {
fontDialog = new FontDialog(this, config.getLastFont());
fontDialog.setVisible(true);
Font font = fontDialog.getFontInfo();
if (font != null) {
config.setLastFont(font);
getCurrentEditor().setFontInfo(font);
labelState.setText("字体=" + font.getFontName() + ",大小="
+ font.getSize());
} else {
labelState.setText("取消字体设置");
}
}
if (s.equals(itemName[8])) {
Editor editor = getCurrentEditor();
JavaText javatext = editor.getJavaText();
javatext.deleteCode("\r");
new Reform(javatext, config.getTabSpace());
editor.setMark(javatext, config.getAllColor());
}
itemName = strItem[2];
if (s.equals(itemName[0])) {
Editor editor1 = getCurrentEditor();
if (editor1.getCurrentFile() == null)
editor1.deleteCode();
searchDialog.search(editor1.getJavaText());
}
if (s.equals(itemName[1])) {
Editor editor2 = getCurrentEditor();
if (editor2.getCurrentFile() == null)
editor2.deleteCode();
searchDialog.change(editor2.getJavaText());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -