Example usage for java.lang Character isWhitespace

List of usage examples for java.lang Character isWhitespace

Introduction

In this page you can find the example usage for java.lang Character isWhitespace.

Prototype

public static boolean isWhitespace(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is white space according to Java.

Usage

From source file:net.sf.jabref.importer.fileformat.BibtexParser.java

/**
 * Tries to restore the key/*from   w w w  .ja v a  2s  . c  o m*/
 *
 * @return rest of key on success, otherwise empty string
 * @throws IOException on Reader-Error
 */
private String fixKey() throws IOException {
    StringBuilder key = new StringBuilder();
    int lookaheadUsed = 0;
    char currentChar;

    // Find a char which ends key (','&&'\n') or entryfield ('='):
    do {
        currentChar = (char) read();
        key.append(currentChar);
        lookaheadUsed++;
    } while ((currentChar != ',') && (currentChar != '\n') && (currentChar != '=')
            && (lookaheadUsed < BibtexParser.LOOKAHEAD));

    // Consumed a char too much, back into reader and remove from key:
    unread(currentChar);
    key.deleteCharAt(key.length() - 1);

    // Restore if possible:
    switch (currentChar) {
    case '=':
        // Get entryfieldname, push it back and take rest as key
        key = key.reverse();

        boolean matchedAlpha = false;
        for (int i = 0; i < key.length(); i++) {
            currentChar = key.charAt(i);

            /// Skip spaces:
            if (!matchedAlpha && (currentChar == ' ')) {
                continue;
            }
            matchedAlpha = true;

            // Begin of entryfieldname (e.g. author) -> push back:
            unread(currentChar);
            if ((currentChar == ' ') || (currentChar == '\n')) {

                /*
                 * found whitespaces, entryfieldname completed -> key in
                 * keybuffer, skip whitespaces
                 */
                StringBuilder newKey = new StringBuilder();
                for (int j = i; j < key.length(); j++) {
                    currentChar = key.charAt(j);
                    if (!Character.isWhitespace(currentChar)) {
                        newKey.append(currentChar);
                    }
                }

                // Finished, now reverse newKey and remove whitespaces:
                parserResult.addWarning(
                        Localization.lang("Line %0: Found corrupted BibTeX key.", String.valueOf(line)));
                key = newKey.reverse();
            }
        }
        break;

    case ',':
        parserResult.addWarning(Localization.lang("Line %0: Found corrupted BibTeX key (contains whitespaces).",
                String.valueOf(line)));
        break;

    case '\n':
        parserResult.addWarning(Localization.lang("Line %0: Found corrupted BibTeX key (comma missing).",
                String.valueOf(line)));
        break;

    default:

        // No more lookahead, give up:
        unreadBuffer(key);
        return "";
    }

    return removeWhitespaces(key).toString();
}

From source file:com.playtech.portal.platform.common.util.Validator.java

/**
 * Returns <code>true</code> if the character is whitespace, meaning it is
 * either the <code>null</code> character '0' or whitespace according to
 * {@link Character#isWhitespace(char)}.
 *
 * @param  c the character to check//from  ww w .  java2 s  .  com
 * @return <code>true</code> if the character is whitespace;
 *         <code>false</code> otherwise
 */
public static boolean isWhitespace(char c) {
    int i = c;

    if ((i == 0) || Character.isWhitespace(c)) {
        return true;
    } else {
        return false;
    }
}

From source file:org.apache.commons.lang3.StringUtils.java

/**
 * <p>Strips any of a set of characters from the end of a String.</p>
 *
 * <p>A {@code null} input String returns {@code null}.
 * An empty string ("") input returns the empty string.</p>
 *
 * <p>If the stripChars String is {@code null}, whitespace is
 * stripped as defined by {@link Character#isWhitespace(char)}.</p>
 *
 * <pre>// ww  w. j  a  va 2s . co m
 * StringUtils.stripEnd(null, *)          = null
 * StringUtils.stripEnd("", *)            = ""
 * StringUtils.stripEnd("abc", "")        = "abc"
 * StringUtils.stripEnd("abc", null)      = "abc"
 * StringUtils.stripEnd("  abc", null)    = "  abc"
 * StringUtils.stripEnd("abc  ", null)    = "abc"
 * StringUtils.stripEnd(" abc ", null)    = " abc"
 * StringUtils.stripEnd("  abcyx", "xyz") = "  abc"
 * StringUtils.stripEnd("120.00", ".0")   = "12"
 * </pre>
 *
 * @param str  the String to remove characters from, may be null
 * @param stripChars  the set of characters to remove, null treated as whitespace
 * @return the stripped String, {@code null} if null String input
 */
public static String stripEnd(String str, String stripChars) {
    int end;
    if (str == null || (end = str.length()) == 0) {
        return str;
    }

    if (stripChars == null) {
        while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) {
            end--;
        }
    } else if (stripChars.length() == 0) {
        return str;
    } else {
        while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND) {
            end--;
        }
    }
    return str.substring(0, end);
}

From source file:bfile.util.StringUtils.java

/**
 * <p>Strips any of a set of characters from the start of a String.</p>
 *
 * <p>A {@code null} input String returns {@code null}.
 * An empty string ("") input returns the empty string.</p>
 *
 * <p>If the stripChars String is {@code null}, whitespace is
 * stripped as defined by {@link Character#isWhitespace(char)}.</p>
 *
 * <pre>/*from ww  w  . j a va2s.  c o m*/
 * StringUtils.stripStart(null, *)          = null
 * StringUtils.stripStart("", *)            = ""
 * StringUtils.stripStart("abc", "")        = "abc"
 * StringUtils.stripStart("abc", null)      = "abc"
 * StringUtils.stripStart("  abc", null)    = "abc"
 * StringUtils.stripStart("abc  ", null)    = "abc  "
 * StringUtils.stripStart(" abc ", null)    = "abc "
 * StringUtils.stripStart("yxabc  ", "xyz") = "abc  "
 * </pre>
 *
 * @param str  the String to remove characters from, may be null
 * @param stripChars  the characters to remove, null treated as whitespace
 * @return the stripped String, {@code null} if null String input
 */
public static String stripStart(final String str, final String stripChars) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    int start = 0;
    if (stripChars == null) {
        while (start != strLen && Character.isWhitespace(str.charAt(start))) {
            start++;
        }
    } else if (stripChars.isEmpty()) {
        return str;
    } else {
        while (start != strLen && stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND) {
            start++;
        }
    }
    return str.substring(start);
}

From source file:edu.virginia.speclab.juxta.author.model.JuxtaXMLParser.java

@Override
public void characters(char[] ch, int start, int length) {
    int mappedOffset = mapLineAndColumnToOffset(locator.getLineNumber(), locator.getColumnNumber());
    int lastLastXMLPosition = lastXMLPosition;
    if (insideEntity)
        // Let endEntity know how many translated characters
        // resulted from the entity. I've never see this
        // be anything other than 1, but I'm not going to assume that
        // it won't ever be 0 or 2, for instance.
        // In this case, endEndity() is going to handle modifying the offset
        // based on how large the entity is (in terms of absolute characters in
        // the source XML).
        charactersInsideEntity = length;
    else//from w  w w . ja v  a 2  s  . com
        lastXMLPosition = mappedOffset;

    current.setIsEmptyTag(false);

    for (int i = start; i < start + length; i++) {
        // Skip text inside excluded tags, and compress whitespace
        char character = ch[i];
        boolean isWhitespace = Character.isWhitespace(character);
        char characterFromSourceDocument = rawXMLText.charAt(lastLastXMLPosition + (i - start));

        if (!isWhitespace || !insideWhitespaceRun) {
            if (isWhitespace) {
                // normalize all whitespace to a space characer
                character = ' ';
            }

            // It's not clear that the !insideEntity part is necessary here
            if (characterFromSourceDocument == '&' && !insideEntity) {
                // we need to advance quickly through all of the characters that make up this
                // NCR. The XML Parser has already turned this into a
                // real unicode character for us, but will NOT trigger startEntity/endEntity
                // because it's a real jerk. So we have to do it ourselves. I quote:
                //
                // "Note also that the boundaries of character references (which are not really entities anyway) are not reported."
                // THANKS FOR THAT LESSON IN PEDANTISM, XML PARSER
                int j = 0;
                while (rawXMLText.charAt(lastLastXMLPosition + i - start + j++) != ';') {
                    skipCharacterFromSource();
                }
            }

            if (current.isExcluded()) {
                skipCharacterFromSource();
            } else {
                insertCharacterFromSource(character);
            }
        } else {
            skipCharacterFromSource();
        }

        if (!current.isExcluded()) {
            insideWhitespaceRun = isWhitespace;
        }
    }
}

From source file:net.sf.jabref.importer.fileformat.BibtexParser.java

/**
 * returns a new <code>StringBuilder</code> which corresponds to <code>toRemove</code> without whitespaces
 *
 * @param toRemove/*ww  w . ja  v  a2  s. com*/
 * @return
 */
private StringBuilder removeWhitespaces(StringBuilder toRemove) {
    StringBuilder result = new StringBuilder();
    char current;
    for (int i = 0; i < toRemove.length(); ++i) {
        current = toRemove.charAt(i);
        if (!Character.isWhitespace(current)) {
            result.append(current);
        }
    }
    return result;
}

From source file:com.asakusafw.runtime.io.csv.CsvParser.java

private boolean trimWhitespaces() {
    boolean trim = false;
    for (int i = lineBuffer.position(), n = lineBuffer.limit(); i < n; i++) {
        char c = lineBuffer.get(i);
        if (Character.isWhitespace(c)) {
            trim = true;// ww  w . j  a  v a2  s  .c o m
            lineBuffer.position(i + 1);
        } else {
            break;
        }
    }
    for (int i = lineBuffer.limit() - 1, n = lineBuffer.position(); i >= n; i--) {
        char c = lineBuffer.get(i);
        if (Character.isWhitespace(c)) {
            trim = true;
            lineBuffer.limit(i);
        } else {
            break;
        }
    }
    return trim;
}

From source file:UrlUtils.java

/**
 * Returns <tt>true</tt> if the specified string contains whitespace, <tt>false</tt> otherwise.
 *
 * @param s the string to check for whitespace
 * @return <tt>true</tt> if the specified string contains whitespace, <tt>false</tt> otherwise
 */// ww w  .ja  v a  2 s .  c  o m
public static boolean containsWhitespace(final String s) {
    for (final char c : s.toCharArray()) {
        if (Character.isWhitespace(c)) {
            return true;
        }
    }
    return false;
}

From source file:net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.java

protected Rectangle2D measureParagraphFragment(int measureIndex) {
    int endIndex = measureIndex;
    if (endIndex > paragraphPosition + 1) {
        char lastMeasureChar = paragraphText.charAt(endIndex - 1);
        if (Character.isWhitespace(lastMeasureChar)) {
            // exclude trailing white space from the text to measure.
            // use the previous break as limit, but always keep at least one character to measure.
            int preceding = paragraphBreakIterator.preceding(endIndex);
            if (preceding == BreakIterator.DONE || preceding <= paragraphPosition) {
                preceding = paragraphPosition + 1;
            }//from   w w  w .j  ava 2 s . c o  m

            do {
                --endIndex;
                lastMeasureChar = paragraphText.charAt(endIndex - 1);
            } while (endIndex > preceding && Character.isWhitespace(lastMeasureChar));
        }
    }

    // note that trailing white space will not be included in the advance
    Rectangle2D bounds = fontInfo.fontInfo.font.getStringBounds(paragraphText, paragraphPosition, endIndex,
            context.getFontRenderContext());

    // adding the measurement to the font info statistics
    fontInfo.recordMeasurement(bounds.getWidth() / (endIndex - paragraphPosition));

    if (logTrace) {
        log.trace("measured to index " + (endIndex + paragraphOffset) + " at width " + bounds.getWidth());
    }

    return bounds;
}

From source file:org.gumtree.vis.swt.PlotComposite.java

private void addListeners() {
    if (plot != null) {
        //         mouseWheelListener = new MouseWheelListener() {
        //// w  w w  .ja  v  a 2s.  co m
        //            @Override
        //            public void mouseScrolled(MouseEvent event) {
        //               JPanel panel = null;
        //               if (plot instanceof JPanel) {
        //                  panel = (JPanel) plot;
        //               }
        //               MouseWheelEvent awtEvent = org.gumtree.vis.listener.SWT_AWT.toMouseWheelEvent(
        //                     event, panel);
        //               plot.processMouseWheelEvent(awtEvent);
        //            }
        //         };
        //         addMouseWheelListener(mouseWheelListener);

        keyListener = new KeyListener() {

            boolean keyPressed = false;

            @Override
            public void keyReleased(KeyEvent event) {
                switch (event.keyCode) {
                case SWT.DEL:
                    plot.removeSelectedMask();
                    plot.removeSelectedText();
                    break;
                default:
                    break;
                }
                switch (event.character) {
                default:
                    break;
                }
                keyPressed = false;
            }

            @Override
            public void keyPressed(KeyEvent event) {
                switch (event.stateMask) {
                case SWT.CTRL:
                    if (event.keyCode == 'c' || event.keyCode == 'C') {
                        if (!keyPressed) {
                            plot.doCopy();
                        }
                    } else if (event.keyCode == 'z' || event.keyCode == 'Z' || event.keyCode == 'r'
                            || event.keyCode == 'R') {
                        if (!keyPressed) {
                            plot.restoreAutoBounds();
                        }
                    } else if (event.keyCode == 'p' || event.keyCode == 'P') {
                        if (!keyPressed) {
                            Thread newThread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    plot.createChartPrintJob();
                                }
                            });
                            newThread.start();
                        }
                    } else if (event.keyCode == 'e' || event.keyCode == 'E') {
                        if (!keyPressed) {
                            Thread newThread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        plot.doSaveAs();
                                    } catch (IOException e) {
                                        handleException(e);
                                    }
                                }
                            });
                            newThread.start();
                        }
                    }
                    keyPressed = true;
                    break;
                case SWT.ALT:
                    break;
                default:
                    switch (event.keyCode) {
                    case SWT.ARROW_UP:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() > 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newCursorIndex = cursorIndex;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex > charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i > 0) {
                                                if (cursorX <= lines[i - 1].length()) {
                                                    newCursorIndex = charCount - lines[i - 1].length() - 1
                                                            + cursorX;
                                                } else {
                                                    newCursorIndex = charCount - 1;
                                                }
                                                plot.setTextInputCursorIndex(newCursorIndex);
                                            }
                                            break;
                                        } else if (cursorIndex == charCount + lines[i].length() + 1) {
                                            newCursorIndex = charCount;
                                            plot.setTextInputCursorIndex(newCursorIndex);
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.ARROW_LEFT:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() > 0) {
                                    plot.setTextInputCursorIndex(plot.getTextInputCursorIndex() - 1);
                                }
                            }
                        }
                        break;
                    case SWT.ARROW_RIGHT:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() < plot.getTextInputContent().length()) {
                                    plot.setTextInputCursorIndex(plot.getTextInputCursorIndex() + 1);
                                }
                            }
                        }
                        break;
                    case SWT.ARROW_DOWN:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newCursorIndex = cursorIndex;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i < lines.length - 1) {
                                                if (cursorX <= lines[i + 1].length()) {
                                                    newCursorIndex = charCount + lines[i].length() + 1
                                                            + cursorX;
                                                } else {
                                                    newCursorIndex = charCount + lines[i].length() + 1
                                                            + lines[i + 1].length();
                                                }
                                                plot.setTextInputCursorIndex(newCursorIndex);
                                            }
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.ESC:
                        plot.cancelTextInput();
                    case SWT.SHIFT:
                        break;
                    case SWT.CTRL:
                        break;
                    case SWT.ALT:
                        break;
                    case SWT.F1:
                        break;
                    case SWT.F2:
                        break;
                    case SWT.F3:
                        break;
                    case SWT.F4:
                        break;
                    case SWT.F5:
                        break;
                    case SWT.F6:
                        break;
                    case SWT.F7:
                        break;
                    case SWT.F8:
                        break;
                    case SWT.F9:
                        break;
                    case SWT.F10:
                        break;
                    case SWT.F11:
                        break;
                    case SWT.F12:
                        break;
                    case SWT.PAGE_UP:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newLine = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i > 0) {
                                                newLine = i - 5;
                                                if (newLine < 0) {
                                                    newLine = 0;
                                                }
                                                jumpToPosition(newLine, cursorX);
                                            }
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.PAGE_DOWN:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newLine = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i < lines.length - 1) {
                                                newLine = i + 5;
                                                if (newLine >= lines.length) {
                                                    newLine = lines.length - 1;
                                                }
                                                jumpToPosition(newLine, cursorX);
                                            }
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.HOME:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int charCount = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex <= charCount + lines[i].length()) {
                                            plot.setTextInputCursorIndex(charCount);
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.END:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int charCount = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex <= charCount + lines[i].length()) {
                                            plot.setTextInputCursorIndex(charCount + lines[i].length());
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.BS:
                        if (plot.isCurrentlyInputtingText()) {
                            String inputText;
                            String textInputContent = plot.getTextInputContent();
                            int cursorIndex = plot.getTextInputCursorIndex();
                            int newIndex;
                            if (textInputContent == null || cursorIndex <= 0
                                    || textInputContent.length() == 0) {
                                return;
                            } else if (cursorIndex == 1) {
                                inputText = textInputContent.substring(1);
                                newIndex = 0;
                            } else if (cursorIndex < textInputContent.length()) {
                                newIndex = cursorIndex - 1;
                                inputText = textInputContent.substring(0, newIndex)
                                        + textInputContent.substring(cursorIndex);
                            } else {
                                inputText = textInputContent.substring(0, textInputContent.length() - 1);
                                newIndex = inputText.length();
                            }
                            plot.setTextInputContent(inputText);
                            plot.setTextInputCursorIndex(newIndex);
                        }
                        break;
                    case SWT.DEL:
                        if (plot.isCurrentlyInputtingText()) {
                            String inputText;
                            String textInputContent = plot.getTextInputContent();
                            int cursorIndex = plot.getTextInputCursorIndex();
                            int newIndex = cursorIndex;
                            if (textInputContent == null || textInputContent.length() == 0
                                    || cursorIndex >= textInputContent.length()) {
                                return;
                            } else if (cursorIndex == 0) {
                                inputText = textInputContent.substring(1);
                            } else {
                                inputText = textInputContent.substring(0, cursorIndex)
                                        + textInputContent.substring(cursorIndex + 1);
                            }
                            plot.setTextInputContent(inputText);
                            plot.setTextInputCursorIndex(newIndex);
                        }
                        break;
                    case SWT.CAPS_LOCK:
                        break;
                    case SWT.INSERT:
                        break;
                    case SWT.NUM_LOCK:
                        break;
                    case SWT.PRINT_SCREEN:
                        break;
                    case SWT.SCROLL_LOCK:
                        break;
                    case SWT.PAUSE:
                        break;
                    default:
                        if (plot.isCurrentlyInputtingText()) {
                            if (Character.isWhitespace(event.character) && event.keyCode != SWT.SPACE) {
                                if (event.keyCode == SWT.CR || event.keyCode == SWT.LF
                                        || event.keyCode == 16777296) {
                                    addStringToTextInput("\n", plot.getTextInputCursorIndex());
                                }
                            } else {
                                addStringToTextInput(String.valueOf(event.character),
                                        plot.getTextInputCursorIndex());
                            }
                        }
                        break;
                    }
                    plot.repaint();
                }
            }

        };
        addKeyListener(keyListener);

        final Composite composite = this;

        chartMouseListener = new ChartMouseListener() {

            @Override
            public void chartMouseMoved(ChartMouseEvent event) {

            }

            @Override
            public void chartMouseClicked(ChartMouseEvent event) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!composite.isDisposed() && !composite.isFocusControl()) {
                            composite.setFocus();
                        }
                    }
                });
            }
        };
        plot.addChartMouseListener(chartMouseListener);
    }
}