import java.awt.Dimension;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.Desktop;
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.JTextArea;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.ToolTipManager;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JComboBox;
import javax.swing.KeyStroke;
import javax.swing.JFileChooser;
import javax.swing.JToggleButton;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.Action;
import javax.swing.AbstractAction;
import javax.swing.JToolBar;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyledDocument;
import javax.swing.text.BadLocationException;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.ListSelectionModel;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeExpansionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.net.URISyntaxException;
import java.net.URI;
public class MainFrame {
//虚拟桌面的宽度和高度
private final int DESKTOP_WIDTH = 480;
private final int DESKTOP_HEIGHT = 360;
//窗体之间的距离
private final int FRAME_DISTANCE = 30;
//保存下一个窗口的坐标
private int nextFrameX;
private int nextFrameY;
private int width = DESKTOP_WIDTH / 2;
private int height = DESKTOP_HEIGHT / 2;
//累加创建的内部窗口次数
private int count = 1;
//获取系统剪贴板
private Clipboard clipboard =
Toolkit.getDefaultToolkit().getSystemClipboard();
private JFrame frame = new JFrame();
private JMenuBar mb = new JMenuBar();
private JMenu file = new JMenu("文件(F)");
private JMenu edit = new JMenu("编辑(E)");
private JMenu search = new JMenu("搜索(X)");
private JMenu view = new JMenu("视图(V)");
private JMenu database = new JMenu("数据库(U)");
private JMenu setting = new JMenu("设置(S)");
private JMenu style = new JMenu("风格(M)");
private JMenu help = new JMenu("帮助(H)");
//--------------------文件菜单子项----------------------
private JMenuItem build = new JMenuItem("新建(N)", 'N');
private JMenuItem open = new JMenuItem("打开(O)...", 'O');
private JMenuItem save = new JMenuItem("保存(S)", 'S');
private JMenuItem saveAs = new JMenuItem("另存为(A)...", 'A');
private JMenuItem pageSetting = new JMenuItem("页面设置(U)...", 'U');
private JMenuItem print = new JMenuItem("打印(P)...", 'P');
private JMenuItem exit = new JMenuItem("退出(X)", 'X');
//-------------------------------------------------------
//--------------------编辑菜单子项----------------------
private JMenuItem undo = new JMenuItem("撤消(U)", 'U');
private JMenuItem cut = new JMenuItem("剪切(T)", 'T');
private JMenuItem copy = new JMenuItem("复制(C)", 'C');
private JMenuItem paste = new JMenuItem("粘贴(P)", 'P');
private JMenuItem delete = new JMenuItem("删除(L)", 'L');
private JMenuItem allSelect = new JMenuItem("全选(A)", 'A');
//-------------------------------------------------------
//--------------------搜索菜单子项----------------------
private JMenuItem find = new JMenuItem("查找(F)", 'F');
private JMenuItem replace = new JMenuItem("替换(W)", 'W');
private JMenuItem findNext = new JMenuItem("查找下一个(X)", 'X');
private JMenuItem turn = new JMenuItem("转到(G)...", 'G');
//-------------------------------------------------------
//--------------------视图菜单子项----------------------
private ButtonGroup viewButtonGroup = new ButtonGroup();
private JCheckBoxMenuItem objectBrowseItem =
new JCheckBoxMenuItem("对象浏览器(F6)", false);
private JCheckBoxMenuItem sqlEditerItem =
new JCheckBoxMenuItem("SQL编辑器(F7)", true);
private JMenuItem refresh = new JMenuItem("刷新(Y)");
private JMenuItem allRefresh = new JMenuItem("全部更新(Z)");
//---------------------------------------------------------
//--------------------数据库菜单子项--------------------
private JMenu newBuildMenu = new JMenu("新建(M)");
private JMenu dataDeleteMenu = new JMenu("删除(N)");
private JMenu fieldMenu = new JMenu("属性(O)");
private JMenuItem insertData = new JMenuItem("插入记录(P)", 'P');
private JMenuItem deleteData = new JMenuItem("删除记录(Q)", 'Q');
private JMenuItem runSQLCmd = new JMenuItem("运行(U)");
private JMenuItem clearData = new JMenuItem("清空(W)", 'W');
private JCheckBoxMenuItem autoCommit = new JCheckBoxMenuItem("自动提交(X)", false);
private JMenuItem commitItem = new JMenuItem("提交(Y)", 'Y');
private JMenuItem rollbackItem = new JMenuItem("回滚(Z)", 'Z');
private JMenuItem createDBItem = new JMenuItem("创建数据库(O)", 'O');
private JMenuItem dropDBItem = new JMenuItem("删除数据库(D)", 'D');
private JMenuItem viewDBItem = new JMenuItem("查看数据库信息(V)", 'V');
private JMenuItem createTableItem = new JMenuItem("创建表(T)", 'T');
private JMenuItem insertTableItem = new JMenuItem("插入数据(I)", 'I');
private JMenuItem renameTableItem = new JMenuItem("重命名表(R)", 'R');
private JMenuItem dropTableItem = new JMenuItem("删除表(D)", 'D');
private JMenuItem clearTableItem = new JMenuItem("清空表数据(C)", 'C');
private JMenuItem viewTableItem = new JMenuItem("查看表数据(V)", 'V');
//-------------------------------------------------------
//--------------------设置菜单子项----------------------
//-------------------------------------------------------
//--------------------帮助菜单子项----------------------
private JMenuItem title = new JMenuItem("帮助主题(H)", 'H');
//-------------------------------------------------------
//--------------------风格菜单子项-----------------------
//组合菜单项
private ButtonGroup flavorGroup = new ButtonGroup();
//三个单选按钮,用于设定窗体风格
private JCheckBoxMenuItem windows = new JCheckBoxMenuItem("Windows风格", true);
private JCheckBoxMenuItem metal = new JCheckBoxMenuItem("Metal风格");
private JCheckBoxMenuItem motif = new JCheckBoxMenuItem("Motif风格");
//--------------------------------------------------------
private JPopupMenu databasePop = new JPopupMenu();
private JPopupMenu tablePop = new JPopupMenu();
private JPopupMen