package org.crazyit.mysql.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import org.crazyit.mysql.object.GlobalContext;
import org.crazyit.mysql.object.ViewObject;
import org.crazyit.mysql.object.list.AbstractData;
import org.crazyit.mysql.object.list.ProcedureData;
import org.crazyit.mysql.object.list.TableData;
import org.crazyit.mysql.object.list.ViewData;
import org.crazyit.mysql.object.tree.ConnectionNode;
import org.crazyit.mysql.object.tree.Database;
import org.crazyit.mysql.object.tree.ProcedureNode;
import org.crazyit.mysql.object.tree.RootNode;
import org.crazyit.mysql.object.tree.ServerConnection;
import org.crazyit.mysql.object.tree.TableNode;
import org.crazyit.mysql.object.tree.ViewNode;
import org.crazyit.mysql.ui.list.ListCellRenderer;
import org.crazyit.mysql.ui.tree.TreeCellRenderer;
import org.crazyit.mysql.ui.tree.TreeListener;
import org.crazyit.mysql.util.MySQLUtil;
/**
* 管理器的主界面
*
* @author yangenxiong yangenxiong2009@gmail.com
* @version 1.0
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br>Copyright (C), 2009-2010, yangenxiong
* <br>This program is protected by copyright laws.
*/
@SuppressWarnings("serial")
public class MainFrame extends JFrame {
//主界面的分隔Pane
private JSplitPane mainPane;
//树的JScrollPane
private JScrollPane treePane;
//主界面的连接树, 树的第一层子节点是各个连接,第二层子节点是该连接下的数据库列表,
//第三层子节点是表、视图等
private JTree tree;
//树的Model
private DefaultTreeModel treeModel;
//JList的JScrollPane
private JScrollPane dataPane;
//表、视图等存放的JList
private JList dataList;
//空的数据
private Object[] emptyData = new Object[]{};
//工具栏
private JToolBar toolBar = new JToolBar();
//新连接界面
private ConnectionFrame connectionFrame;
//新建数据库界面
private DatabaseFrame databaseFrame;
//新连接
private Action newConnection = new AbstractAction("新连接", new ImageIcon("images/connection.gif")) {
public void actionPerformed(ActionEvent e) {
newConnection();
}
};
//表
private Action table = new AbstractAction("表", new ImageIcon("images/table.gif")) {
public void actionPerformed(ActionEvent e) {
viewTables();
}
};
//视图
private Action view = new AbstractAction("视图", new ImageIcon("images/view.gif")) {
public void actionPerformed(ActionEvent e) {
viewViews();
}
};
//存储过程
private Action procedure = new AbstractAction("存储过程", new ImageIcon("images/procedure.gif")) {
public void actionPerformed(ActionEvent e) {
viewProcedures();
}
};
//查询
private Action query = new AbstractAction("查询", new ImageIcon("images/query.gif")) {
public void actionPerformed(ActionEvent e) {
query();
}
};
//弹出菜单
JPopupMenu menu = new JPopupMenu();
//表的菜单
private JMenuItem addTableItem = new JMenuItem("新建表", new ImageIcon("images/add-table.gif"));
private JMenuItem editTableItem = new JMenuItem("编辑表", new ImageIcon("images/edit-table.gif"));
private JMenuItem deleteTableItem = new JMenuItem("删除表", new ImageIcon("images/delete-table.gif"));
private JMenuItem dumpTableItem = new JMenuItem("导出表", null);
private JMenuItem refresh = new JMenuItem("刷 新", new ImageIcon("images/refresh.gif"));
//视图菜单
private JMenuItem addViewItem = new JMenuItem("新建视图", new ImageIcon("images/add-view.gif"));
private JMenuItem editViewItem = new JMenuItem("编辑视图", new ImageIcon("images/edit-view.gif"));
private JMenuItem dropViewItem = new JMenuItem("删除视图", new ImageIcon("images/delete-view.gif"));
//存储过程菜单
private JMenuItem addProcedureItem = new JMenuItem("新建存储过程", new ImageIcon("images/add-procedure.gif"));
private JMenuItem editProcedureItem = new JMenuItem("编辑存储过程", new ImageIcon("images/edit-procedure.gif"));
private JMenuItem dropProcedureItem = new JMenuItem("删除存储过程", new ImageIcon("images/delete-procedure.gif"));
//树的弹出菜单
JPopupMenu treeMenu = new JPopupMenu();
private JMenuItem closeConnection = new JMenuItem("关闭连接", null);
private JMenuItem removeConnection = new JMenuItem("删除连接", null);
private JMenuItem closeDatabase = new JMenuItem("关闭数据库", null);
private JMenuItem newDatabase = new JMenuItem("新建数据库", null);
private JMenuItem removeDatabase = new JMenuItem("删除数据库", null);
private JMenuItem executeSQLFile = new JMenuItem("执行SQL文件", null);
private JMenuItem dumpSQLFile = new JMenuItem("导出SQL文件", null);
//全局上下文对象
private GlobalContext ctx;
//当前列表前所显示数据种类
private ViewObject currentView;
public MainFrame(GlobalContext ctx) {
this.ctx = ctx;
//初始化树对象
createTree();
this.treePane = new JScrollPane(this.tree);
//初始化表、视图的JList
this.dataList = createList();
this.dataPane = new JScrollPane(dataList);
this.dataPane.setPreferredSize(new Dimension(600, 400));
this.mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.treePane,
this.dataPane);
this.mainPane.setDividerLocation(170);
this.add(this.mainPane);
//创建工具栏
createToolBar();
this.add(this.toolBar, BorderLayout.NORTH);
this.setLocation(150, 100);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("MySQL管理器");
//初始化各个界面
this.connectionFrame = new ConnectionFrame(this.ctx, this);
initMenuItemListeners();
}
//初始化右键菜单
private void initMenuItemListeners() {
this.addTableItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
newTable();
}
});
this.editTableItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
editTable();
}
});
this.deleteTableItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dropTable();
}
});
this.dumpTableItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dumpTable();
}
});
this.addViewItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
newView();
}
});
this.editViewItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
editView();
}
});
this.dropViewItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dropView();
}
});
this.addProcedureItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
newProcedure();
}
});
this.editProcedureItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
editProcedure();
}
});
this.dropProcedureItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dropProcedure();
}
});
this.refresh.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
refreshDataList();
}
});
this.closeConnection.addActionListener(new ActionListener(){
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
疯狂Java讲义 第3版 源码 (2637个子文件)
1315031945734 0B
command.bat 22B
package-list.baiduyun.downloading.cfg 0B
AbstractApplicationContext.class 8KB
PropertyHandlerImpl.class 7KB
BlobTest.class 6KB
SwingComponent.class 6KB
ElementReaderImpl.class 6KB
JOptionPaneTest.class 5KB
ElementReaderTest.class 5KB
BeanCreatorImpl.class 4KB
MyTextPane.class 4KB
JFormattedTextFieldTest.class 4KB
PropertyHandlerTest.class 4KB
TableModelTest.class 4KB
AdjustingWidth.class 4KB
LoginFrame.class 4KB
ListTest.class 4KB
CopyImage.class 4KB
GetPostTest.class 4KB
AttributeViewTest.class 4KB
DatabaseMetaDataTest.class 4KB
LanTalk.class 4KB
CompileClassLoader.class 4KB
JInternalFrameTest.class 4KB
JSpinnerTest.class 4KB
JTabbedPaneTest.class 3KB
ExecuteSQL.class 3KB
ExtendedObjectPoolFactory.class 3KB
PreparedStatementTest.class 3KB
HibernateAnnotationProcessor.class 3KB
AIOClient.class 3KB
XmlApplicationContextTest.class 3KB
MathTest.class 3KB
JSliderTest.class 3KB
WaitingLayerUI.class 3KB
NServer.class 3KB
CachedRowSetPage.class 3KB
ClassTest.class 3KB
DropTargetTest$ImageDropTargetListener.class 3KB
ShowHand.class 3KB
ResultSetTest.class 3KB
Client.class 3KB
PinBall.class 3KB
HandDraw.class 3KB
SyntaxFormatter.class 3KB
ComUtil.class 3KB
NonRegularWindow.class 3KB
TableCellEditorTest.class 3KB
HandDraw.class 3KB
MulticastSocketTest.class 3KB
AIOServer$1.class 3KB
CopySerializable.class 3KB
EditJTree.class 3KB
ImageViewer.class 3KB
ServerThread.class 3KB
AcceptHandler$1.class 3KB
Gobang.class 3KB
PropertyHandlerObject1.class 3KB
QueryExecutor.class 3KB
JdbcRowSetTest.class 3KB
DefaultTableModelTest.class 3KB
BeanCreatorTest.class 3KB
CopyPerson.class 3KB
DefaultProxySelectorTest.class 3KB
CachedRowSetTest.class 3KB
JFormattedTextFieldTest2.class 3KB
JToolBarTest.class 3KB
ChangeAllCellRender.class 3KB
Account.class 2KB
ListModelTest.class 2KB
DefaultListModelTest.class 2KB
SimpleMenu.class 2KB
RowSetFactoryTest.class 2KB
ObjectPoolFactory.class 2KB
ExecuteDML.class 2KB
ComUtil$ReadBroad.class 2KB
LoginFrame.class 2KB
PopupMenuTest.class 2KB
JTextPaneTest.class 2KB
ImageCellEditor.class 2KB
TableModelTest$1.class 2KB
ComparableOperatorTest.class 2KB
CallableStatementTest.class 2KB
BorderTest.class 2KB
ExtendsDefaultTreeCellRenderer.class 2KB
TransactionTest.class 2KB
QueryExecutor$ExceListener.class 2KB
JOptionPaneTest$ShowAction.class 2KB
SplitPaneTest.class 2KB
DateFormatTest.class 2KB
ConnMySql.class 2KB
ImageCellRenderer.class 2KB
SpotlightLayerUI.class 2KB
ImageCellRenderer.class 2KB
TableCellRendererTest.class 2KB
ProxyTest.class 2KB
ExecuteDDL.class 2KB
SelectJTree.class 2KB
NClient$ClientThread.class 2KB
共 2637 条
- 1
- 2
- 3
- 4
- 5
- 6
- 27
资源评论
- weixin_408359652018-03-31很好,是原版代码
- 奋斗的小龟2018-04-08是原版代码,但是不是第三版代码!
elzza
- 粉丝: 26
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功