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

📄 sqlsyntaxdocument.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            start = matcher.start();            end = matcher.end();            realStart = start + startOffset;            realEnd = end + startOffset;                       applyStyle = true;                        // if this is a string mather add to the cache            if (matcherType == STRING_MATCH) {                stringTokens.add(new Token(realStart, realEnd));            }            // compare against string cache to apply            else if (matcherType == SINGLE_LINE_COMMENT_MATCH) {                if (stringTokenCount > 0) {                    /*                    Log.debug("text: " +text);                    Log.debug("length: " +text.length());                    Log.debug("string tokens: "+stringTokenCount);                    Log.debug("start: " +startOffset);                    Log.debug("realStart: " + realStart +                             " realEnd: "+realEnd);                    */                    // check we are not within a string literal                    for (int i = 0; i < stringTokenCount; i++) {                        Token token = stringTokens.get(i);                        int tokenStart = token.getStartIndex();                        int tokenEnd = token.getEndIndex();                        if (realStart > tokenEnd) {                            continue;                        }                        //Log.debug(token);                        if (realStart < tokenStart) {                            applyStyle = true;                            break;                        }                        if (realStart > tokenStart && realStart < tokenEnd) {                            // set the end to the end of the string                            // token for the matcher reset                            end = token.getEndIndex() - startOffset;                            applyStyle = false;                            break;                        }                                            }                }            }                        if (applyStyle) {                setCharacterAttributes(realStart,                                        end - start,                                        style,                                       replace);            }            matcherStart = end + 1;            if (matcherStart > length) {                break;            }        }        matcher.reset(Constants.EMPTY);    }    public void replace(int offset, int length,                         String text, AttributeSet attrs)      throws BadLocationException {        int textLength = text.length();                  //Log.debug("replace");        if ((length == 0) && (text == null || textLength == 0)) {            return;        }        // if text is selected - ie. length > 0        // and it is a TAB and we have a text component         if ((length > 0) && (textLength > 0) &&                 (text.charAt(0) == Constants.TAB_CHAR) &&                 (textComponent != null)) {            int selectionStart = textComponent.getSelectionStart();            int selectionEnd = textComponent.getSelectionEnd();            int start = rootElement.getElementIndex(selectionStart);            int end = rootElement.getElementIndex(selectionEnd-1);            for (int i = start; i <= end; i++) {                Element line = rootElement.getElement(i);                int startOffset = line.getStartOffset();                try {                    insertString(startOffset, text, attrs);                }                catch(BadLocationException badLocExc) {                    badLocExc.printStackTrace();                }            }            textComponent.setSelectionStart(                            rootElement.getElement(start).getStartOffset());            textComponent.setSelectionEnd(                            rootElement.getElement(end).getEndOffset());            return;        }        if (attrs == null) {            attrs = styles[WORD];        }        super.replace(offset, length, text, attrs);    }    /**     * Shifts the text at start to end left one TAB character. The      * specified region will be selected/reselected if specified.      *     * @param selectionStart - the start offset     * @param selectionEnd - the end offset     */    public void shiftTabEvent(int selectionStart, int selectionEnd) {        shiftTabEvent(selectionStart, selectionEnd, true);    }        /**     * Shifts the text at start to end left one TAB character. The      * specified region will be selected/reselected if specified.      *     * @param selectionStart - the start offset     * @param selectionEnd - the end offset     * @param reselect - whether to select the region when done     */    public void shiftTabEvent(int selectionStart, int selectionEnd, boolean reselect) {        if (textComponent == null) {            return;        }        int minusOffset = tabsToSpaces ? QueryEditorSettings.getTabSize() : 1;        int start = rootElement.getElementIndex(selectionStart);        int end = rootElement.getElementIndex(selectionEnd-1);        for (int i = start; i <= end; i++) {            Element line = rootElement.getElement(i);            int startOffset = line.getStartOffset();            int endOffset = line.getEndOffset();            int removeCharCount = 0;            if (startOffset == endOffset - 1) {                continue;            }            try {                char[] chars = getText(startOffset, minusOffset).toCharArray();                for (int j = 0; j < chars.length; j++) {                    if ((Character.isWhitespace(chars[j])) &&                             (chars[j] != Constants.NEW_LINE_CHAR)) {                        removeCharCount++;                    }                    else if (j == 0) {                        break;                    }                }                super.remove(startOffset, removeCharCount);            }            catch(BadLocationException badLocExc) {}        }        if (reselect) {            textComponent.setSelectionStart(                            rootElement.getElement(start).getStartOffset());            textComponent.setSelectionEnd(                            rootElement.getElement(end).getEndOffset());        }    }    private Style[] styles;    private void initStyles(boolean reset) {        styles = new Style[typeNames.length];        Font font = QueryEditorSettings.getEditorFont();        int fontSize =  font.getSize();        String fontFamily = font.getName();        SyntaxStyle[] syntaxStyles = QueryEditorSettings.getSyntaxStyles();                for (int i = 0; i < syntaxStyles.length; i++) {            changeStyle(syntaxStyles[i].getType(),                        syntaxStyles[i].getForeground(),                        syntaxStyles[i].getFontStyle(),                        syntaxStyles[i].getBackground(),                        fontFamily,                         fontSize);        }    }    public void changeStyle(int type, Color fcolor,                             int fontStyle, Color bcolor,                            String fontFamily, int fontSize) {        Style style = addStyle(typeNames[type], null);        if (fcolor != null) {            StyleConstants.setForeground(style, fcolor);        }        if (bcolor != null) {            StyleConstants.setBackground(style, bcolor);        }        StyleConstants.setFontSize(style, fontSize);        StyleConstants.setFontFamily(style, fontFamily);        switch (fontStyle) {            case 0:                StyleConstants.setItalic(style, false);                StyleConstants.setBold(style, false);                break;            case 1:                StyleConstants.setBold(style, true);                break;            case 2:                StyleConstants.setItalic(style, true);                break;            default:                StyleConstants.setItalic(style, false);                StyleConstants.setBold(style, false);              }        styles[type] = style;    }    /**    * Change the style of a particular type of token.    */    public void changeStyle (int type, Color color) {        Style style = addStyle(typeNames[type], null);        if (color != null) {            StyleConstants.setForeground(style, color);        }        styles[type] = style;    }    /**     * Change the style of a particular type of token, including adding bold or     * italic using a third argument of <code>Font.BOLD</code> or     * <code>Font.ITALIC</code> or the bitwise union     * <code>Font.BOLD|Font.ITALIC</code>.     */    public void changeStyle(int type, Color color,                             int fontStyle, Color bcolor) {        Style style = addStyle(typeNames[type], null);        StyleConstants.setForeground(style, color);                if (bcolor != null) {            StyleConstants.setBackground(style, bcolor);        }        switch (fontStyle) {            case 0:                StyleConstants.setItalic(style, false);                StyleConstants.setBold(style, false);                break;            case 1:                StyleConstants.setBold(style, true);                break;            case 2:                StyleConstants.setItalic(style, true);                break;            default:                StyleConstants.setItalic(style, false);                StyleConstants.setBold(style, false);              }        styles[type] = style;    }    /**     * Sets the SQL keywords to be applied to this document.     *     * @param keywords - the keywords list     * @param reset     */    public void setSQLKeywords(List<String> keywords, boolean reset) {        StringBuffer sb = new StringBuffer("\\b(?:");        // the last start char        char lastFirstChar = 0;        // we are trying to achieve the following regex        // where the first char of each group is the same char         // as in: t(?:his|hat) as opposed to (?:this|that)                for (int i = 0, k = keywords.size(), n = k - 1; i < k; i++) {            String _keyword = keywords.get(i).trim();                        char firstChar = _keyword.charAt(0);            if (firstChar == lastFirstChar) {                sb.append("|");                sb.append(_keyword.substring(1));            }            else {                if (i > 0) {                    sb.append(")|");                }                sb.append(firstChar);                sb.append("(?:");                sb.append(_keyword.substring(1));                lastFirstChar = firstChar;            }        }        sb.append("))\\b");                Matcher matcher = Pattern.compile(                            sb.toString(),                             Pattern.CASE_INSENSITIVE).matcher(Constants.EMPTY);        matchers[KEYWORD_MATCH] = new TokenMatcher(KEYWORD, styles[KEYWORD], matcher);    }    public int getInsertMode() {        return insertMode;    }    public void setInsertMode(int insertMode) {        this.insertMode = insertMode;    }    }

⌨️ 快捷键说明

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