📄 mysqlplusframe.java
字号:
package com.jimw.mysqlplus;
import java.io.*;
import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class MySqlPlusFrame extends JFrame {
private Container container;
private JMenuBar menuBar;
private JDesktopPane desktop;
private JTextField statusBar;
private FileDialog fileDialog;
private HashMap cfgMap,toolBtnMap,menuMap;
private Icon commitUpIcon = new ImageIcon("./resources/autocommit_up.gif");
private Icon commitDownIcon = new ImageIcon("./resources/autocommit_down.gif");
private ConfigDBDlg cfgDlg = null;
private HistoryListDlg listDlg = null;
static HashMap internalFrameMap = new HashMap();
static int activeWindow = 0;
static String[] command = null;
static String[] keyWords = null;
static String[] function = null;
public void setActiveWindow(int num) {
activeWindow = num;
InternalFrame frame = (InternalFrame)internalFrameMap.get(new Integer(num));
if (frame != null) {
if ( frame.getAutoCommitflag() )
((JButton)toolBtnMap.get("commit")).setIcon(commitDownIcon);
else
((JButton)toolBtnMap.get("commit")).setIcon(commitUpIcon);
}
}
public void removeWindow(int num) {
internalFrameMap.remove(new Integer(num));
}
public MySqlPlusFrame() {
super("MySqlPlus");
final int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 );
loadConfig();
loadKeyWord();
container = getContentPane();
container.setLayout(new BorderLayout());
buildMenus();
buildToolBar();
buildContent();
setButtonEnable();
// buildStatusBar();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
quit();
}});
this.addKeyListener(new MyKeyAdapter());
}
protected void buildToolBar() {
JToolBar toolBar =new JToolBar();
toolBtnMap = new HashMap();
JButton newBtn = new JButton(new ImageIcon("./resources/new.gif"));
newBtn.setToolTipText("New");
newBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
newDocument();
}});
toolBtnMap.put("new",newBtn);
JButton openBtn = new JButton(new ImageIcon("./resources/open.gif"));
openBtn.setEnabled(false);
openBtn.setToolTipText("Open...");
openBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
openFile();
}});
toolBtnMap.put("open",openBtn);
JButton saveBtn = new JButton(new ImageIcon("./resources/save.gif"));
saveBtn.setEnabled(false);
saveBtn.setToolTipText("Save...");
saveBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
saveFile();
}});
toolBtnMap.put("save",saveBtn);
JButton executeBtn = new JButton(new ImageIcon("./resources/execute.gif"));
executeBtn.setEnabled(false);
executeBtn.setToolTipText("Execute...");
executeBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
execute();
}});
toolBtnMap.put("execute",executeBtn);
JButton historyListBtn = new JButton(new ImageIcon("./resources/sqlhistory.gif"));
historyListBtn.setEnabled(false);
historyListBtn.setToolTipText("History Command List...");
historyListBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
showHistoryList();
}});
toolBtnMap.put("history",historyListBtn);
JButton commitBtn = new JButton(commitUpIcon);
commitBtn.setEnabled(false);
commitBtn.setToolTipText("Auto Commit...");
commitBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
autoCommit();
}});
toolBtnMap.put("commit",commitBtn);
toolBar.add(newBtn);
toolBar.add(openBtn);
toolBar.add(saveBtn);
toolBar.addSeparator();
toolBar.add(executeBtn);
toolBar.add(historyListBtn);
toolBar.addSeparator();
toolBar.add(commitBtn);
container.add(toolBar,BorderLayout.NORTH);
}
protected void buildContent() {
desktop = new JDesktopPane();
container.add(desktop,BorderLayout.CENTER);
// setContentPane(desktop);
}
protected void buildStatusBar() {
statusBar = new JTextField();
statusBar.setEditable(false);
container.add(statusBar,BorderLayout.SOUTH);
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu run = buildRunMenu();
JMenu window = buildWindowMenu();
JMenu help = buildHelpMenu();
menuBar.add(file);
menuBar.add(run);
menuBar.add(window);
menuBar.add(help);
setJMenuBar(menuBar);
}
protected JMenu buildFileMenu() {
menuMap = new HashMap();
JMenu file = new JMenu("File");
JMenuItem newItem = new JMenuItem("New");
JMenuItem openItem = new JMenuItem("Open...");
JMenuItem saveItem = new JMenuItem("Save...");
JMenuItem configItem = new JMenuItem("Config DB...");
JMenuItem quitItem = new JMenuItem("Quit");
menuMap.put("new",newItem);
menuMap.put("open",openItem);
menuMap.put("save",saveItem);
newItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newDocument();
}});
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openFile();
}});
saveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveFile();
}});
configItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
configDB();
}});
quitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
quit();
}});
file.add(newItem);
file.add(openItem);
file.add(saveItem);
file.addSeparator();
file.add(configItem);
file.addSeparator();
file.add(quitItem);
return file;
}
protected JMenu buildRunMenu() {
JMenu run = new JMenu("Run");
JMenuItem executeItem = new JMenuItem("Execute");
JMenuItem historyListItem = new JMenuItem("History command list...");
menuMap.put("execute",executeItem);
menuMap.put("history",historyListItem);
executeItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
execute();
}});
historyListItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showHistoryList();
}});
run.add(executeItem);
run.addSeparator();
run.add(historyListItem);
return run;
}
protected JMenu buildWindowMenu() {
JMenu window = new JMenu("Window");
JMenuItem restoreItem = new JMenuItem("Restore Window");
JMenuItem cascadeItem = new JMenuItem("Cascade Window");
JMenuItem tileItem = new JMenuItem("Tile Window");
// restoreItem.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// restoreWindow();
// }});
//
restoreItem.setEnabled(false);
cascadeItem.setEnabled(false);
tileItem.setEnabled(false);
window.add(restoreItem);
window.add(cascadeItem);
window.add(tileItem);
return window;
}
protected JMenu buildHelpMenu() {
JMenu help = new JMenu("Help");
JMenuItem aboutItem = new JMenuItem("About...");
aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
helpBtn_actionPerformed(e);
}});
help.add(aboutItem);
return help;
}
public void quit() {
System.out.println("Quit System.....");
try {
Set keySet = internalFrameMap.keySet();
//System.out.println("Set = " + keySet.toString());
Iterator iterator = keySet.iterator();
while (iterator.hasNext()) {
Integer key = (Integer)iterator.next();
//System.out.println("key = " + key.toString());
((InternalFrame)internalFrameMap.get(key)).quit();
internalFrameMap.remove(key);
}
} catch (Exception ex) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -