use of javax.swing.text.Document in project antlrworks by antlr.
the class AutoCompletionMenu method completePartialWord.
public void completePartialWord(String word) {
try {
Document doc = getTextComponent().getDocument();
doc.remove(insertionStartIndex, insertionEndIndex - insertionStartIndex);
doc.insertString(insertionStartIndex, word, null);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
use of javax.swing.text.Document in project android-classyshark by google.
the class DisplayArea method displayClass.
// TODO add here logic fo highlighter
// TODO by adding flag to Translator.ELEMENT
@Override
public void displayClass(List<Translator.ELEMENT> elements, String key) {
displayDataState = DisplayDataState.INSIDE_CLASS;
clearText();
StyleConstants.setFontSize(style, 18);
StyleConstants.setBackground(style, theme.getBackgroundColor());
Document doc = new DefaultStyledDocument();
fillTokensToDoc(elements, doc, false);
StyleConstants.setForeground(style, theme.getIdentifiersColor());
jTextPane.setDocument(doc);
int i = calcScrollingPosition(key);
jTextPane.setCaretPosition(i);
}
use of javax.swing.text.Document in project android-classyshark by google.
the class DisplayArea method displayClass.
@Override
public void displayClass(String classString) {
displayDataState = DisplayDataState.INSIDE_CLASS;
try {
String currentText = jTextPane.getDocument().getText(0, jTextPane.getDocument().getLength());
if (currentText.equals(getOneColorFormattedOutput(classString))) {
return;
}
} catch (BadLocationException e) {
e.printStackTrace();
}
clearText();
StyleConstants.setFontSize(style, 18);
Document doc = new DefaultStyledDocument();
try {
doc.insertString(doc.getLength(), getOneColorFormattedOutput(classString), style);
} catch (BadLocationException e) {
e.printStackTrace();
}
jTextPane.setDocument(doc);
jTextPane.setCaretPosition(1);
}
use of javax.swing.text.Document in project groovy-core by groovy.
the class FindReplaceUtility method findNext.
/**
* Find and select the next searchable matching text.
*
* @param reverse look forwards or backwards
* @param pos the starting index to start finding from
* @return the location of the next selected, or -1 if not found
*/
private static int findNext(boolean reverse, int pos) {
boolean backwards = IS_BACKWARDS_CHECKBOX.isSelected();
backwards = backwards ? !reverse : reverse;
String pattern = (String) FIND_FIELD.getSelectedItem();
if (pattern != null && pattern.length() > 0) {
try {
Document doc = textComponent.getDocument();
doc.getText(0, doc.getLength(), SEGMENT);
} catch (Exception e) {
// should NEVER reach here
e.printStackTrace();
}
pos += textComponent.getSelectedText() == null ? (backwards ? -1 : 1) : 0;
char first = backwards ? pattern.charAt(pattern.length() - 1) : pattern.charAt(0);
char oppFirst = Character.isUpperCase(first) ? Character.toLowerCase(first) : Character.toUpperCase(first);
int start = pos;
boolean wrapped = WRAP_SEARCH_CHECKBOX.isSelected();
int end = backwards ? 0 : SEGMENT.getEndIndex();
pos += backwards ? -1 : 1;
int length = textComponent.getDocument().getLength();
if (pos > length) {
pos = wrapped ? 0 : length;
}
boolean found = false;
while (!found && (backwards ? pos > end : pos < end)) {
found = !MATCH_CASE_CHECKBOX.isSelected() && SEGMENT.array[pos] == oppFirst;
found = found ? found : SEGMENT.array[pos] == first;
if (found) {
pos += backwards ? -(pattern.length() - 1) : 0;
for (int i = 0; found && i < pattern.length(); i++) {
char c = pattern.charAt(i);
found = SEGMENT.array[pos + i] == c;
if (!MATCH_CASE_CHECKBOX.isSelected() && !found) {
c = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);
found = SEGMENT.array[pos + i] == c;
}
}
}
if (!found) {
pos += backwards ? -1 : 1;
if (pos == end && wrapped) {
pos = backwards ? SEGMENT.getEndIndex() : 0;
end = start;
wrapped = false;
}
}
}
pos = found ? pos : -1;
}
return pos;
}
use of javax.swing.text.Document in project OpenAM by OpenRock.
the class TableJPanel method clearAll.
public void clearAll() {
testsjTable.setEnabled(false);
TestsTableModel model = (TestsTableModel) testsjTable.getModel();
model.removeAll();
Document doc = messagejEditorPane.getDocument();
try {
doc.remove(0, doc.getLength());
} catch (Exception ex) {
//ex.printStackTrace();
System.out.println("Exception in TableJPanel :" + ex.getMessage());
}
testsjTable.setEnabled(true);
}
Aggregations