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

📄 queryeditortextpane.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                if (i == chars.length - 1 || wasSpaceChar) {                    if (end == -1) {                        end = i;                    }                    break;                }                                else if (end != -1) {                    if(chars[i + 1] == Constants.NEW_LINE_CHAR) {                        break;                    }                    else if (Character.isSpaceChar(chars[i + 1])) {                        wasSpaceChar = true;                        i++;                    }                }            }            else if (!Character.isSpaceChar(chars[i])) {                end = i;                wasSpaceChar = false;            }        }        //Log.debug("start: " + start + " end: " + end);                String query = text.substring(start, end + 1);        //Log.debug(query);        if ((MiscUtils.isNull(query) && start != 0) ||                start == end) {            return getQueryAt(start);        }                return query;    }    // ----------------------------------------    // DocumentListener implementation    // ----------------------------------------        /**     * Does nothing.     */    public void changedUpdate(DocumentEvent e) {}    /**     * Notifies the parent QueryPanel that the text content     * has changed and resets the line number border panel.     *     * @param the event object     */    public void insertUpdate(DocumentEvent e) {        editorPanel.setContentChanged(true);        lineBorder.resetExecutingLine();    }    /**     * Notifies the parent QueryPanel that the text content     * has changed and resets the line number border panel.     *     * @param the event object     */    public void removeUpdate(DocumentEvent e) {        insertUpdate(e);    }    // ----------------------------------------        /**     * Resets the executing line within the line      * number border panel.     */    public void resetExecutingLine() {        lineBorder.resetExecutingLine();    }        /**     * Executes the query determined to be around the current      * cursor position using the database connection object      * specified.     *     * @param the database connection object to execute the query     */    public void executeSQLAtCursor(DatabaseConnection dc) {        String query = getQueryAt(getCaretPosition());        if (MiscUtils.isNull(query)) {            return;        }        int index = getText().indexOf(query);        if (query.charAt(0) == Constants.NEW_LINE_CHAR) {            index++;        }        lineBorder.setExecutingLine(getRowAt(index));        lineBorder.repaint();        editorPanel.executeSQLQuery(dc, query);    }    /**     * Returns the text as contained within the editor's     * text panel.     *     * @return the editor's text     */    public String getQueryAreaText() {        return getText();    }    /**      * Overrides <code>processKeyEvent</code> to additional process events.      */    protected void processKeyEvent(KeyEvent e) {                if (e.getID() == KeyEvent.KEY_PRESSED) {            int keyCode = e.getKeyCode();            // add the processing for SHIFT-TAB            if (e.isShiftDown() && keyCode == KeyEvent.VK_TAB) {                addUndoEdit();                int currentPosition = getCurrentPosition();                int selectionStart = getSelectionStart();                int selectionEnd = getSelectionEnd();                                if (selectionStart == selectionEnd) {                                        int newPosition = currentPosition - QueryEditorSettings.getTabSize();                    int currentRowPosition = getCurrentRowStart();                    if (!isAtStartOfRow()) {                                                if (newPosition < 0) {                            setCaretPosition(0);                        }                                                else if (newPosition < currentRowPosition) {                            setCaretPosition(currentRowPosition);                        }                                                else {                            setCaretPosition(newPosition);                        }                    }                }                else {                    document.shiftTabEvent(selectionStart, selectionEnd);                }                            }            // toggle insert mode on the document            else if (keyCode == KeyEvent.VK_INSERT) {                int insertMode = document.getInsertMode();                if (insertMode == QueryEditorConstants.INSERT_MODE) {                    document.setInsertMode(QueryEditorConstants.OVERWRITE_MODE);                    editorPanel.getStatusBar().setInsertionMode("OVR");                }                 else {                    document.setInsertMode(QueryEditorConstants.INSERT_MODE);                    editorPanel.getStatusBar().setInsertionMode("INS");                                    }                ((EditorCaret)getCaret()).modeChanged();            }        }        super.processKeyEvent(e);                updateLineBorder();    }    /** the last element count for line border updates */    private int lastElementCount;    /**     * Updates the line border values.     */    private void updateLineBorder() {        int elementCount = document.getDefaultRootElement().getElementCount();        if (elementCount != lastElementCount) {            lineBorder.setRowCount(elementCount);            lastElementCount = elementCount;        }            }        /**     * Cuts the editor's selected text.     */    public void cut() {        addUndoEdit();        super.cut();    }        /**     * Pastes any previously copied/cut text into the      * editor at the cursor or mouse pointer position.     */    public void paste() {        addUndoEdit();        super.paste();    }            /**     * Returns true if an undo operation would be      * successful now, false otherwise.     */    protected boolean canUndo() {        return undoManager.canUndo();    }    /**     * Completes a compound edit and adds an      * undoable edit to the undo manager.     */    protected void addUndoEdit() {        undoManager.addUndoEdit();    }        /**     * Executes the undo action.     */    public void undo() {        undoManager.undo();        updateLineBorder();    }        /**     * Executes the redo action.     */    public void redo() {        undoManager.redo();        updateLineBorder();    }    // ----------------------------------------    // FocusListener implementation    // ----------------------------------------        /**     * Updates the state of undo/redo ona focus gain.     */    public void focusGained(FocusEvent e) {        if (e.getSource() != this && editorPanel != null) {            editorPanel.focusGained();        }    }    /**     * Updates the state of undo/redo on a focus lost.     */    public void focusLost(FocusEvent e) {        if (editorPanel != null) {            editorPanel.focusLost();        }    }    // ----------------------------------------        private int currentRow = 0;    private int currentPosition = 0;    /**     * Returns the row number at the specified position.     *     * @param position - the position     */    protected int getRowAt(int position) {        Element map = getElementMap();        return map.getElementIndex(position);            }    /**     * Called when the caret position is updated.     *     * @param e the caret event     */    public void caretUpdate(CaretEvent ce) {        super.caretUpdate(ce);        currentPosition = getCaretPosition();        Element map = getElementMap();        int row = map.getElementIndex(currentPosition);        if (currentRow != row) {            currentRow = row;            //lineBorder.setRowCount(map.getElementCount());        }        Element lineElem = map.getElement(row);        int col = currentPosition - lineElem.getStartOffset();        editorPanel.getStatusBar().setCaretPosition(row + 1, col + 1);        repaint();    }    protected boolean isAtStartOfRow() {        return currentPosition == getRowPosition(currentRow);    }    /**     * Returns the start offset of the current row.     *     * @return the current row start offset     */    protected int getCurrentRowStart() {        return getElementMap().getElement(currentRow).getStartOffset();    }    /**     * Returns the end offset of the current row.     *     * @return the current row end offset     */    protected int getCurrentRowEnd() {        return getElementMap().getElement(currentRow).getEndOffset();    }    /**     * Returns the start offset of the specified row.     *     * @param row - the row     * @return the start offset of row     */    protected int getRowStartOffset(int row) {        try {            return getElementMap().getElement(row).getStartOffset();        } catch (Exception e) { // where row passed is dumb value            return -1;        }    }    /**     * Returns the end offset of the specified row.     *     * @param row - the row     * @return the end offset of row     */    protected int getRowEndOffset(int row) {        try {            return getElementMap().getElement(row).getEndOffset();        } catch (Exception e) { // where row passed is dumb value            return -1;        }    }        /**     * Returns the start offset of the specified row.     *     * @param row - a row in the editor     * @return the start offset of row     */    protected int getRowPosition(int row) {        try {            return getElementMap().getElement(row).getStartOffset();        }        catch (NullPointerException nullExc) {            return -1;        }    }    /**     * Returns the document's root element     */    protected Element getElementMap() {        return getDocument().getDefaultRootElement();    }    /**     * Returns the current caret position.     */    protected int getCurrentPosition() {        return currentPosition;    }    /**     * Returns the row number of the current cursor position.     *     * @return the current caret row number     */    protected int getCurrentCursorRow() {        return currentRow;    }        class EditorCaret extends DefaultCaret {        void modeChanged() {            repaint();        }                public void paint(Graphics g) {            if(document.getInsertMode() == QueryEditorConstants.INSERT_MODE) {                super.paint(g);                return;            }            JTextComponent comp = getComponent();            char c;            int dot = getDot();            Rectangle r = null;            try {                r = comp.modelToView(dot);                if(r == null) {                   return;                }                c = comp.getText(dot, 1).charAt(0);            }             catch(BadLocationException e) {                return;            }            // erase provious caret            if ((x != r.x) || (y != r.y)) {                repaint();                x = r.x;                y = r.y;                height = r.height;            }            g.setColor(comp.getCaretColor());            g.setXORMode(comp.getBackground());            width = g.getFontMetrics().charWidth(c);            if (c == '\t' || c == '\n') {                width = g.getFontMetrics().charWidth('W');            }            if (isVisible()) {                g.fillRect(r.x, r.y, width, r.height);            }        }    }    }

⌨️ 快捷键说明

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