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();
}
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations