⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 databasemanagerswing.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                // (ulrivo): full size on screen with less than 640 width                if (d.width >= 640) {                    f.addSeparator();                } else {                    return;                }            } else {                JMenuItem item;                if (m[i] instanceof JMenuItem) {                    item = (JMenuItem) m[i];                } else if (m[i] instanceof String) {                    item = new JMenuItem(((String) m[i]).substring(1));                    char c = ((String) m[i]).charAt(0);                    if (c != '-') {                        KeyStroke key =                            KeyStroke.getKeyStroke(c, Event.CTRL_MASK);                        item.setAccelerator(key);                    }                } else {                    throw new RuntimeException(                        "Unexpected element for menu item creation: "                        + m[i].getClass().getName());                }                item.addActionListener(this);                f.add(item);            }        }    }    public void keyPressed(KeyEvent k) {}    public void keyReleased(KeyEvent k) {}    public void keyTyped(KeyEvent k) {        if (k.getKeyChar() == '\n' && k.isControlDown()) {            k.consume();            executeCurrentSQL();        }    }    Thread dummyThread = new Thread("dummy");    public void actionPerformed(ActionEvent ev) {        String s = ev.getActionCommand();        if (s == null) {            if (ev.getSource() instanceof JMenuItem) {                JMenuItem i;                s = ((JMenuItem) ev.getSource()).getText();            }        }        if (s == null) {}        else if (s.equals("Exit")) {            windowClosing(null);        } else if (s.equals("Transfer")) {            Transfer.work(null);        } else if (s.equals("Dump")) {            Transfer.work(new String[]{ "-d" });        } else if (s.equals("Restore")) {            Transfer.work(new String[]{ "-r" });        } else if (s.equals(LOGGING_BOX_TEXT)) {            JavaSystem.setLogToSystem(boxLogging.isSelected());        } else if (s.equals(AUTOREFRESH_BOX_TEXT)) {            autoRefresh = boxAutoRefresh.isSelected();            refreshTree();        } else if (s.equals("Refresh Tree")) {            refreshTree();        } else if (s.startsWith("#")) {            int i = Integer.parseInt(s.substring(1));            txtCommand.setText(sRecent[i]);        } else if (s.equals("Connect...")) {            Connection newCon = null;            try {                setWaiting("Connecting");                newCon = ConnectionDialogSwing.createConnection(fMain,                        "Connect");            } finally {                setWaiting(null);            }            connect(newCon);        } else if (s.equals(GRID_BOX_TEXT)) {            gridFormat = boxShowGrid.isSelected();            displayResults();        } else if (s.equals("Open Script...")) {            JFileChooser f = new JFileChooser(".");            f.setDialogTitle("Open Script...");            // (ulrivo): set default directory if set from command line            if (defDirectory != null) {                f.setCurrentDirectory(new File(defDirectory));            }            int option = f.showOpenDialog(fMain);            if (option == JFileChooser.APPROVE_OPTION) {                File file = f.getSelectedFile();                if (file != null) {                    StringBuffer buf = new StringBuffer();                    ifHuge = DatabaseManagerCommon.readFile(                        file.getAbsolutePath());                    if (4096 <= ifHuge.length()) {                        buf.append(                            "This huge file cannot be edited. Please execute\n");                        txtCommand.setText(buf.toString());                    } else {                        txtCommand.setText(ifHuge);                    }                }            }        } else if (s.equals("Save Script...")) {            JFileChooser f = new JFileChooser(".");            f.setDialogTitle("Save Script");            // (ulrivo): set default directory if set from command line            if (defDirectory != null) {                f.setCurrentDirectory(new File(defDirectory));            }            int option = f.showSaveDialog(fMain);            if (option == JFileChooser.APPROVE_OPTION) {                File file = f.getSelectedFile();                if (file != null) {                    DatabaseManagerCommon.writeFile(file.getAbsolutePath(),                                                    txtCommand.getText());                }            }        } else if (s.equals("Save Result...")) {            JFileChooser f = new JFileChooser(".");            f.setDialogTitle("Save Result...");            // (ulrivo): set default directory if set from command line            if (defDirectory != null) {                f.setCurrentDirectory(new File(defDirectory));            }            int option = f.showSaveDialog(fMain);            if (option == JFileChooser.APPROVE_OPTION) {                File file = f.getSelectedFile();                if (file != null) {                    showResultInText();                    DatabaseManagerCommon.writeFile(file.getAbsolutePath(),                                                    txtResult.getText());                }            }        } else if (s.equals(SHOWSYS_BOX_TEXT)) {            showSys = boxShowSys.isSelected();            try {                refreshTree();            } catch (Exception e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        } else if (s.equals(ROWCOUNTS_BOX_TEXT)) {            displayRowCounts = boxRowCounts.isSelected();            try {                refreshTree();            } catch (Exception e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        } else if (s.startsWith("LFMODE:")) {            setLF(s.substring("LFMODE:".length()));        } else if (s.equals("Set Fonts")) {            // Added: (weconsultants@users)            FontDialogSwing.CreatFontDialog(refForFontDialogSwing);        } else if (s.equals(AUTOCOMMIT_BOX_TEXT)) {            try {                cConn.setAutoCommit(boxAutoCommit.isSelected());            } catch (SQLException e) {                boxAutoCommit.setSelected(!boxAutoCommit.isSelected());                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        } else if (s.equals("Commit")) {            try {                cConn.commit();            } catch (SQLException e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        } else if (s.equals("Insert test data")) {            insertTestData();            refreshTree();        } else if (s.equals("Rollback")) {            try {                cConn.rollback();            } catch (SQLException e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        } else if (s.equals("Disable MaxRows")) {            try {                sStatement.setMaxRows(0);            } catch (SQLException e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        } else if (s.equals("Set MaxRows to 100")) {            try {                sStatement.setMaxRows(100);            } catch (SQLException e) {                CommonSwing.errorMessage(e);            }        } else if (s.equals("SELECT")) {            showHelp(DatabaseManagerCommon.selectHelp);        } else if (s.equals("INSERT")) {            showHelp(DatabaseManagerCommon.insertHelp);        } else if (s.equals("UPDATE")) {            showHelp(DatabaseManagerCommon.updateHelp);        } else if (s.equals("DELETE")) {            showHelp(DatabaseManagerCommon.deleteHelp);        } else if (s.equals("EXECUTE")) {            executeCurrentSQL();        } else if (s.equals("CREATE TABLE")) {            showHelp(DatabaseManagerCommon.createTableHelp);        } else if (s.equals("DROP TABLE")) {            showHelp(DatabaseManagerCommon.dropTableHelp);        } else if (s.equals("CREATE INDEX")) {            showHelp(DatabaseManagerCommon.createIndexHelp);        } else if (s.equals("DROP INDEX")) {            showHelp(DatabaseManagerCommon.dropIndexHelp);        } else if (s.equals("CHECKPOINT")) {            showHelp(DatabaseManagerCommon.checkpointHelp);        } else if (s.equals("SCRIPT")) {            showHelp(DatabaseManagerCommon.scriptHelp);        } else if (s.equals("SHUTDOWN")) {            showHelp(DatabaseManagerCommon.shutdownHelp);        } else if (s.equals("SET")) {            showHelp(DatabaseManagerCommon.setHelp);        } else if (s.equals("Test Script")) {            showHelp(DatabaseManagerCommon.testHelp);        } else if (s.equals(SHOWSCHEMAS_BOX_TEXT)) {            showSchemas = boxShowSchemas.isSelected();            refreshTree();        } else {            throw new RuntimeException("Unexpected action triggered: " + s);        }    }    private void displayResults() {        if (gridFormat) {            setResultsInGrid();        } else {            setResultsInText();        }    }    private void setResultsInGrid() {        pResult.removeAll();        pResult.add(gScrollPane, BorderLayout.CENTER);        pResult.doLayout();        gResult.fireTableChanged(null);        pResult.repaint();    }    private void setResultsInText() {        pResult.removeAll();        pResult.add(txtResultScroll, BorderLayout.CENTER);        pResult.doLayout();        showResultInText();        pResult.repaint();    }    private void showHelp(String[] help) {        txtCommand.setText(help[0]);        bHelp = true;        pResult.removeAll();        pResult.add(txtResultScroll, BorderLayout.CENTER);        pResult.doLayout();        txtResult.setText(help[1]);        pResult.repaint();        txtCommand.requestFocus();        txtCommand.setCaretPosition(help[0].length());    }    public void windowActivated(WindowEvent e) {}    public void windowDeactivated(WindowEvent e) {}    public void windowClosed(WindowEvent e) {}    public void windowDeiconified(WindowEvent e) {}    public void windowIconified(WindowEvent e) {}    public void windowOpened(WindowEvent e) {}    public void windowClosing(WindowEvent ev) {        try {            if (cConn != null) {                cConn.close();            }            if (prefs != null) {                prefs.autoRefresh   = autoRefresh;                prefs.showRowCounts = displayRowCounts;                prefs.showSysTables = showSys;                prefs.showSchemas   = showSchemas;                prefs.resultGrid    = gridFormat;                prefs.showTooltips  = showTooltips;                prefs.laf           = currentLAF;                prefs.store();            }        } catch (Exception e) {            //  Added: (weconsultants@users)            CommonSwing.errorMessage(e);        }        fMain.dispose();        if (bMustExit) {            System.exit(0);        }    }    private void clear() {        ifHuge = "";        txtCommand.setText(ifHuge);    }    private String busyText = null;    private void backgroundIt(Runnable r, String description) {        if (busyText != null) {            Toolkit.getDefaultToolkit().beep();            return;        }        // set Waiting mode here.  Inverse op must be called by final()        // in the Thread.run() of every background thread.        setWaiting(description);        SwingUtilities.invokeLater(r);    }    public void setWaiting(String description) {        busyText = description;        if (busyText == null) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -