Search in sources :

Example 86 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class QueryResultComposite method makeLogResult.

/**
	 * Make the log result contents.
	 * 
	 * @param sqlStr String
	 * @param messageStr String
	 */
public void makeLogResult(String sqlStr, String messageStr) {
    resultTabFolder.setSelection(queryResultTabItem);
    SashForm tailSash = new SashForm(queryResultTabFolder, SWT.NONE);
    tailSash.SASH_WIDTH = SASH_WIDTH;
    tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    String text = messageStr;
    logMessagesArea = new StyledText(tailSash, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP);
    CommonUITool.registerCopyPasteContextMenu(logMessagesArea, false);
    logMessagesArea.setText(text);
    int splitLineLength = QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT.length();
    for (int sp = 0; ; ) {
        int redStringLength = splitLineLength;
        sp = text.indexOf(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT, sp);
        if (sp == -1) {
            break;
        }
        if (sp != 0) {
            int lastSp = text.lastIndexOf("\n", sp - 2);
            if (lastSp == -1) {
                redStringLength += sp;
                sp = 0;
            } else {
                redStringLength += (sp - lastSp);
                sp = lastSp + 1;
            }
        }
        boolean isErrorMsg = false;
        try {
            if (text.substring(sp, sp + redStringLength).indexOf(Messages.queryFail) != -1) {
                isErrorMsg = true;
            }
        } catch (Exception e) {
        }
        StyleRange eachStyle = new StyleRange();
        eachStyle.start = sp;
        eachStyle.length = redStringLength;
        eachStyle.fontStyle = SWT.NORMAL;
        eachStyle.foreground = Display.getDefault().getSystemColor(isErrorMsg ? SWT.COLOR_RED : SWT.COLOR_BLUE);
        logMessagesArea.setStyleRange(eachStyle);
        sp += redStringLength;
    }
    logResultTabItem = new CTabItem(queryResultTabFolder, SWT.NONE);
    logResultTabItem.setText(Messages.qedit_logsresult);
    logResultTabItem.setControl(tailSash);
    editor.getCombinedQueryComposite().getRecentlyUsedSQLComposite().refreshRecentlyUsedSQLList();
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) StyledText(org.eclipse.swt.custom.StyledText) StyleRange(org.eclipse.swt.custom.StyleRange) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point) ParamSetException(com.cubrid.common.ui.spi.util.paramSetter.ParamSetException) SQLException(java.sql.SQLException)

Example 87 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class QueryPlanComposite method updateStyledText.

private void updateStyledText(StyledText styledText) {
    final String[] titleString = { "Join graph segments (f indicates final):", "Join graph nodes:", "Join graph equivalence classes:", "Join graph edges:", "Join graph terms:", "Query plan:", "Query stmt:", "Query:", "Execution Plan:" };
    for (String find : titleString) {
        int sp = -1;
        int ep = 0;
        for (; ; ) {
            sp = styledText.getText().indexOf(find, ep);
            if (sp == -1) {
                break;
            }
            StyleRange eachStyle = new StyleRange();
            eachStyle.start = sp;
            eachStyle.length = find.length();
            eachStyle.fontStyle = SWT.BOLD;
            eachStyle.foreground = getDisplay().getSystemColor(SWT.COLOR_RED);
            styledText.setStyleRange(eachStyle);
            ep = sp + 1;
        }
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 88 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class ProductInfoDialog method findPreviousRange.

/**
	 * Find the previous range before the current selection.
	 * 
	 * @param text the StyledText
	 * @return the StyleRange
	 */
protected StyleRange findPreviousRange(StyledText text) {
    StyleRange[] ranges = text.getStyleRanges();
    int currentSelectionStart = text.getSelection().x;
    for (int i = ranges.length - 1; i > -1; i--) {
        if ((ranges[i].start + ranges[i].length - 1) < currentSelectionStart) {
            return ranges[i];
        }
    }
    return null;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Example 89 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class ProductInfoDialog method addListeners.

/**
	 * Adds listeners to the given styled text
	 * 
	 * @param styledText the StyledText object
	 */
protected void addListeners(StyledText styledText) {
    styledText.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (event.button != 1) {
                return;
            }
            mouseDown = true;
        }

        public void mouseUp(MouseEvent event) {
            mouseDown = false;
            StyledText text = (StyledText) event.widget;
            int offset = text.getCaretOffset();
            if (dragEvent) {
                // don't activate a link during a drag/mouse up operation
                dragEvent = false;
                if (item != null && item.isLinkAt(offset)) {
                    text.setCursor(handCursor);
                }
            } else if (item != null && item.isLinkAt(offset)) {
                text.setCursor(busyCursor);
                String url = item.getLinkAt(offset);
                if (StringUtil.isEmpty(url)) {
                    LOGGER.warn("The url is a null or empty string : {}.", url);
                } else {
                    openLink(url);
                }
                StyleRange selectionRange = getCurrentRange(text);
                if (selectionRange == null) {
                    LOGGER.warn("The selectionRange is a null.");
                } else {
                    text.setSelectionRange(selectionRange.start, selectionRange.length);
                    text.setCursor(null);
                }
            }
        }
    });
    styledText.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent event) {
            if (mouseDown) {
                if (!dragEvent) {
                    StyledText text = (StyledText) event.widget;
                    text.setCursor(null);
                }
                dragEvent = true;
                return;
            }
            StyledText text = (StyledText) event.widget;
            int offset = -1;
            try {
                offset = text.getOffsetAtLocation(new Point(event.x, event.y));
            } catch (IllegalArgumentException ex) {
                offset = -1;
            }
            if (offset == -1) {
                text.setCursor(null);
            } else if (item != null && item.isLinkAt(offset)) {
                text.setCursor(handCursor);
            } else {
                text.setCursor(null);
            }
        }
    });
    styledText.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            StyledText text = (StyledText) event.widget;
            switch(event.detail) {
                case SWT.TRAVERSE_ESCAPE:
                    event.doit = true;
                    break;
                case SWT.TRAVERSE_TAB_NEXT:
                    // Previously traverse out in the backward direction?
                    Point nextSelection = text.getSelection();
                    int charCount = text.getCharCount();
                    if ((nextSelection.x == charCount) && (nextSelection.y == charCount)) {
                        text.setSelection(0);
                    }
                    StyleRange nextRange = findNextRange(text);
                    if (nextRange == null) {
                        // Next time in start at beginning, also used by
                        // TRAVERSE_TAB_PREVIOUS to indicate we traversed out
                        // in the forward direction
                        text.setSelection(0);
                        event.doit = true;
                    } else {
                        text.setSelectionRange(nextRange.start, nextRange.length);
                        event.doit = true;
                        event.detail = SWT.TRAVERSE_NONE;
                    }
                    break;
                case SWT.TRAVERSE_TAB_PREVIOUS:
                    // Previously traverse out in the forward direction?
                    Point previousSelection = text.getSelection();
                    if ((previousSelection.x == 0) && (previousSelection.y == 0)) {
                        text.setSelection(text.getCharCount());
                    }
                    StyleRange previousRange = findPreviousRange(text);
                    if (previousRange == null) {
                        // Next time in start at the end, also used by
                        // TRAVERSE_TAB_NEXT to indicate we traversed out
                        // in the backward direction
                        text.setSelection(text.getCharCount());
                        event.doit = true;
                    } else {
                        text.setSelectionRange(previousRange.start, previousRange.length);
                        event.doit = true;
                        event.detail = SWT.TRAVERSE_NONE;
                    }
                    break;
                default:
                    break;
            }
        }
    });
    // Listen for Tab and Space to allow keyboard navigation
    styledText.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            StyledText text = (StyledText) event.widget;
            if (event.character == ' ' || event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                if (item == null) {
                    LOGGER.warn("AboutItem is a null.");
                    return;
                }
                // Be sure we are in the selection
                int offset = text.getSelection().x + 1;
                if (item.isLinkAt(offset)) {
                    text.setCursor(busyCursor);
                    String url = item.getLinkAt(offset);
                    if (StringUtil.isEmpty(url)) {
                        LOGGER.warn("The url is a null or empty string : {}.", url);
                    } else {
                        openLink(url);
                    }
                    StyleRange selectionRange = getCurrentRange(text);
                    if (selectionRange == null) {
                        LOGGER.warn("The selectionRange is a null.");
                    } else {
                        text.setSelectionRange(selectionRange.start, selectionRange.length);
                        text.setCursor(null);
                    }
                }
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) StyledText(org.eclipse.swt.custom.StyledText) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) StyleRange(org.eclipse.swt.custom.StyleRange) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point)

Example 90 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class ProductInfoDialog method findNextRange.

/**
	 * Find the next range after the current selection.
	 * 
	 * @param text the StyledText
	 * @return the StyleRange
	 */
protected StyleRange findNextRange(StyledText text) {
    StyleRange[] ranges = text.getStyleRanges();
    int currentSelectionEnd = text.getSelection().y;
    for (int i = 0; i < ranges.length; i++) {
        if (ranges[i].start >= currentSelectionEnd) {
            return ranges[i];
        }
    }
    return null;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Aggregations

StyleRange (org.eclipse.swt.custom.StyleRange)145 Point (org.eclipse.swt.graphics.Point)52 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)25 Color (org.eclipse.swt.graphics.Color)22 StyledText (org.eclipse.swt.custom.StyledText)13 Font (org.eclipse.swt.graphics.Font)10 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)10 Matcher (java.util.regex.Matcher)9 FontData (org.eclipse.swt.graphics.FontData)8 RGB (org.eclipse.swt.graphics.RGB)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 IOException (java.io.IOException)5 TextPresentation (org.eclipse.jface.text.TextPresentation)5 Image (org.eclipse.swt.graphics.Image)5 Control (org.eclipse.swt.widgets.Control)5 Position (org.eclipse.jface.text.Position)4 TextStyle (org.eclipse.swt.graphics.TextStyle)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3