Search in sources :

Example 36 with Document

use of javax.swing.text.Document in project gephi by gephi.

the class FileCompletionPopup method keyPressed.

/****** implementation of KeyListener of fileNameTextField ******/
@Override
public void keyPressed(KeyEvent e) {
    if (!isVisible()) {
        return;
    }
    int code = e.getKeyCode();
    switch(code) {
        case KeyEvent.VK_DOWN:
            setSelectNext();
            e.consume();
            break;
        case KeyEvent.VK_UP:
            setSelectPrevious();
            e.consume();
            break;
        case KeyEvent.VK_ESCAPE:
            setVisible(false);
            textField.requestFocus();
            e.consume();
            break;
    }
    if (isCompletionKey(code, textField)) {
        File file = (File) list.getSelectedValue();
        if (file != null) {
            if (file.equals(chooser.getCurrentDirectory())) {
                chooser.firePropertyChange(JFileChooser.DIRECTORY_CHANGED_PROPERTY, false, true);
            } else {
                chooser.setSelectedFiles(new File[] { file });
                chooser.setCurrentDirectory(file);
            }
            if (file.isDirectory()) {
                try {
                    Document doc = textField.getDocument();
                    doc.insertString(doc.getLength(), File.separator, null);
                } catch (BadLocationException ex) {
                    Logger.getLogger(getClass().getName()).log(Level.FINE, "Cannot append directory separator.", ex);
                }
            }
        }
        setVisible(false);
        textField.requestFocus();
        e.consume();
    }
}
Also used : Document(javax.swing.text.Document) File(java.io.File) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 37 with Document

use of javax.swing.text.Document in project android-classyshark by google.

the class DisplayArea method displaySharkey.

@Override
public void displaySharkey() {
    displayDataState = DisplayDataState.SHARKEY;
    clearText();
    style = jTextPane.addStyle("STYLE", null);
    Document doc = jTextPane.getStyledDocument();
    try {
        StyleConstants.setForeground(style, theme.getIdentifiersColor());
        StyleConstants.setFontSize(style, 13);
        StyleConstants.setFontFamily(style, "Menlo");
        doc.insertString(doc.getLength(), Doodle.get(), style);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    jTextPane.setDocument(doc);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 38 with Document

use of javax.swing.text.Document in project android-classyshark by google.

the class DisplayArea method displaySearchResults.

@Override
public void displaySearchResults(List<String> filteredClassNames, List<Translator.ELEMENT> displayedManifestSearchResultsTokens, String textFromTypingArea) {
    displayDataState = DisplayDataState.CLASSES_LIST;
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    clearText();
    Document doc = new DefaultStyledDocument();
    jTextPane.setDocument(doc);
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    fillTokensToDoc(displayedManifestSearchResultsTokens, doc, true);
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    int displayedClassLimit = 50;
    if (filteredClassNames.size() < displayedClassLimit) {
        displayedClassLimit = filteredClassNames.size();
    }
    for (int i = 0; i < displayedClassLimit; i++) {
        try {
            doc.insertString(doc.getLength(), filteredClassNames.get(i) + "\n", style);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    jTextPane.setDocument(doc);
    jTextPane.setCaretPosition(1);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 39 with Document

use of javax.swing.text.Document in project android-classyshark by google.

the class DisplayArea method displayClassNames.

@Override
public void displayClassNames(List<String> classNamesToShow, String inputText) {
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    if (classNamesToShow.size() > 50) {
        displayAllClassesNames(classNamesToShow);
        return;
    }
    displayDataState = DisplayDataState.CLASSES_LIST;
    clearText();
    int matchIndex;
    String beforeMatch = "";
    String match;
    String afterMatch = "";
    Document doc = jTextPane.getDocument();
    for (String className : classNamesToShow) {
        matchIndex = className.indexOf(inputText);
        if (matchIndex > -1) {
            beforeMatch = className.substring(0, matchIndex);
            match = className.substring(matchIndex, matchIndex + inputText.length());
            afterMatch = className.substring(matchIndex + inputText.length(), className.length());
        } else {
            // we are here by camel match
            // i.e. 2-3 letters that fits
            // to class name
            match = className;
        }
        try {
            doc.insertString(doc.getLength(), beforeMatch, style);
            StyleConstants.setBackground(style, theme.getSelectionBgColor());
            doc.insertString(doc.getLength(), match, style);
            StyleConstants.setBackground(style, theme.getBackgroundColor());
            doc.insertString(doc.getLength(), afterMatch + "\n", style);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    jTextPane.setDocument(doc);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 40 with Document

use of javax.swing.text.Document in project android-classyshark by google.

the class DisplayArea method calcScrollingPosition.

private int calcScrollingPosition(String textToFind) {
    int pos = 0;
    boolean found = false;
    textToFind = textToFind.trim();
    if (textToFind != null && textToFind.length() > 0) {
        Document document = jTextPane.getDocument();
        int findLength = textToFind.length();
        try {
            // Rest the search position if we're at the end of the document
            if (pos + findLength > document.getLength()) {
                pos = 0;
            }
            // While we haven't reached the end... "<=" Correction
            while (pos + findLength <= document.getLength()) {
                String match = document.getText(pos, findLength).toLowerCase();
                if (match.equalsIgnoreCase(textToFind)) {
                    found = true;
                    break;
                }
                pos++;
            }
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    }
    if (found) {
        return pos;
    } else {
        return 1;
    }
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

Document (javax.swing.text.Document)72 BadLocationException (javax.swing.text.BadLocationException)35 DocumentEvent (javax.swing.event.DocumentEvent)10 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)8 DocumentAdapter (com.intellij.ui.DocumentAdapter)7 HTMLDocument (javax.swing.text.html.HTMLDocument)7 ActionEvent (java.awt.event.ActionEvent)5 PlainDocument (javax.swing.text.PlainDocument)5 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)4 IOException (java.io.IOException)3 FieldPanel (com.intellij.ui.FieldPanel)2 CheckBox (com.intellij.util.ui.CheckBox)2 Color (java.awt.Color)2 NumberFormat (java.text.NumberFormat)2 ParseException (java.text.ParseException)2 AbstractAction (javax.swing.AbstractAction)2 DocumentListener (javax.swing.event.DocumentListener)2 AbstractDocument (javax.swing.text.AbstractDocument)2 Element (javax.swing.text.Element)2