use of javax.swing.text.BadLocationException in project binnavi by google.
the class ConsoleCodeDocument method setCurrentLine.
/**
* Insert a line in the text element containing the passed position skipping a number of character
* from the beginning of the element. The function of the skipping of characters is to "jump" over
* the prompt in the beginning of a line.
*
* @param pos the position from which to retrieve the element that contains it
* @param skip how many characters are skipped from the beginning of the element when inserting
* the string
* @param line the line to insert
*/
public void setCurrentLine(final int pos, final int skip, final String line) {
final Element element = getParagraphElement(pos);
final int start = element.getStartOffset();
final int end = element.getEndOffset();
try {
remove(start + skip, end - (start + skip + 1));
super.insertString(start + skip, line, normal);
} catch (final BadLocationException e) {
System.out.println("Bad location!");
e.printStackTrace();
}
}
use of javax.swing.text.BadLocationException in project binnavi by google.
the class ConsoleHelpers method getCurrentLine.
/**
* Get the text of the element containing the given position.
*
* @param pos the global document position at which to find the element containing it.
* @return the text contained within the element
*/
public String getCurrentLine(final int pos) {
final Element element = document.getParagraphElement(pos);
String line = "";
try {
line = document.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset());
} catch (final BadLocationException e) {
System.out.println("Bad location!");
e.printStackTrace();
}
return line;
}
use of javax.swing.text.BadLocationException 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.BadLocationException 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.BadLocationException 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);
}
Aggregations