use of javax.swing.text.Document in project Spark by igniterealtime.
the class ChatInputEditor method insertText.
/**
* Inserts text into the current document at the current caret position.
*
* @param text the text to insert
* @throws BadLocationException if the location is not available for insertion.
*/
public void insertText(String text) throws BadLocationException {
final Document doc = getDocument();
doc.insertString(this.getCaret().getDot(), text, null);
}
use of javax.swing.text.Document in project Spark by igniterealtime.
the class HorizontalLineEntry method addTo.
@Override
protected void addTo(ChatArea chatArea) throws BadLocationException {
final Document doc = chatArea.getDocument();
chatArea.insertComponent(new JSeparator());
doc.insertString(doc.getLength(), "\n", null);
// Enabling the 'setCaretPosition' line below causes Spark to freeze (often, not always) when trying to print the subject of a chatroom that's just being loaded.
// chatArea.setCaretPosition( doc.getLength() );
}
use of javax.swing.text.Document in project processing by processing.
the class DetailPanel method setSelectionStyle.
static void setSelectionStyle(JTextPane textPane, boolean selected) {
Document doc = textPane.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument html = (HTMLDocument) doc;
StyleSheet styleSheet = html.getStyleSheet();
if (selected) {
styleSheet.addRule("a { text-decoration:underline } ");
} else {
styleSheet.addRule("a { text-decoration:none }");
}
}
}
use of javax.swing.text.Document in project groovy by apache.
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 android by JetBrains.
the class SelectionEditors method createDocumentListener.
/**
* Create a document listener that will update the {@link MockupViewPanel} selection
* when the attached document is updated.
*
* @return the new document listener
*/
private DocumentListener createDocumentListener() {
return new DocumentListener() {
private void processChange(@NotNull DocumentEvent e) {
if (myBoundsUpdating) {
return;
}
try {
Document document = e.getDocument();
int value;
if (document.getLength() <= 0) {
value = 0;
} else {
value = Integer.parseInt(document.getText(0, document.getLength()));
}
SelectionLayer selectionLayer = myMockupViewPanel.getSelectionLayer();
Rectangle selection = selectionLayer.getSelection();
if (document == myBoundsDocuments[W]) {
selectionLayer.setSelection(selection.x, selection.y, value, selection.height);
} else if (document == myBoundsDocuments[H]) {
selectionLayer.setSelection(selection.x, selection.y, selection.width, value);
} else if (document == myBoundsDocuments[X]) {
selectionLayer.setSelection(value, selection.y, selection.width, selection.height);
} else if (document == myBoundsDocuments[Y]) {
selectionLayer.setSelection(selection.x, value, selection.width, selection.height);
}
} catch (BadLocationException | NumberFormatException ex) {
// Do nothing
}
}
@Override
public void insertUpdate(DocumentEvent e) {
processChange(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
processChange(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
};
}
Aggregations