use of javax.swing.text.BadLocationException in project android by JetBrains.
the class TraceViewPanel method createSearchField.
private SearchTextField createSearchField() {
SearchTextField stf = new SearchTextField(true);
stf.setOpaque(false);
stf.setEnabled(true);
Utils.setSmallerFont(stf);
stf.addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
searchTextChanged(getText(e));
}
private String getText(DocumentEvent e) {
try {
return e.getDocument().getText(0, e.getDocument().getLength());
} catch (BadLocationException e1) {
return "";
}
}
});
JTextField editorTextField = stf.getTextEditor();
editorTextField.setMinimumSize(new Dimension(JBUI.scale(200), -1));
editorTextField.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeSearchComponent();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
return stf;
}
use of javax.swing.text.BadLocationException in project android by JetBrains.
the class MergedManifestFixture method requireText.
public void requireText(@NotNull String expected, boolean wrap) {
try {
Document document = myInfoPane.target().getDocument();
String text = document.getText(0, document.getLength()).trim();
if (wrap) {
text = SdkUtils.wrap(text, 80, null);
}
assertEquals(expected, text);
} catch (BadLocationException ignore) {
}
}
use of javax.swing.text.BadLocationException 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) {
}
};
}
use of javax.swing.text.BadLocationException in project jdk8u_jdk by JetBrains.
the class TextComponentPrintable method calculateRowsMetrics.
/**
* Calculates rowsMetrics for the document. The result is stored
* in the {@code rowsMetrics}.
*
* Two steps process.
* First step is to find yStart and yEnd for the every document position.
* Second step is to merge all intersected segments ( [yStart, yEnd] ).
*/
private void calculateRowsMetrics() {
final int documentLength = printShell.getDocument().getLength();
List<IntegerSegment> documentMetrics = new ArrayList<IntegerSegment>(LIST_SIZE);
Rectangle rect;
for (int i = 0, previousY = -1, previousHeight = -1; i < documentLength; i++) {
try {
rect = printShell.modelToView(i);
if (rect != null) {
int y = (int) rect.getY();
int height = (int) rect.getHeight();
if (height != 0 && (y != previousY || height != previousHeight)) {
/*
* we do not store the same value as previous. in our
* documents it is often for consequent positons to have
* the same modelToView y and height.
*/
previousY = y;
previousHeight = height;
documentMetrics.add(new IntegerSegment(y, y + height - 1));
}
}
} catch (BadLocationException e) {
assert false;
}
}
/*
* Merge all intersected segments.
*/
Collections.sort(documentMetrics);
int yStart = Integer.MIN_VALUE;
int yEnd = Integer.MIN_VALUE;
for (IntegerSegment segment : documentMetrics) {
if (yEnd < segment.start) {
if (yEnd != Integer.MIN_VALUE) {
rowsMetrics.add(new IntegerSegment(yStart, yEnd));
}
yStart = segment.start;
yEnd = segment.end;
} else {
yEnd = segment.end;
}
}
if (yEnd != Integer.MIN_VALUE) {
rowsMetrics.add(new IntegerSegment(yStart, yEnd));
}
}
use of javax.swing.text.BadLocationException in project JMRI by JMRI.
the class CbusConsolePane method nextLine.
public void nextLine(String line, String decoded, String priorities, int filter) {
// handle display of traffic
// line is the traffic in 'normal form', decoded is the decoded,
// protocol specific, form
// Both should contain the same number of well-formed lines, e.g. end
// with \n
StringBuffer sbCan = new StringBuffer(80);
StringBuffer sbCbus = new StringBuffer(80);
final int filterIndex = filter;
log.debug("_filterFrame: " + _filterFrame + " filter: " + filter);
if (filterIndex >= 0) {
final Color filterColor = _filterFrame.getColor(filter);
cbusHighlightPainter = new cbusHighlightPainter(filterColor);
}
// display the timestamp if requested
if (timeCheckBox.isSelected()) {
sbCan.append(df.format(new Date())).append(": ");
sbCbus.append(df.format(new Date())).append(": ");
}
// display CBUS the priorities if requested
if (priCheckBox.isSelected()) {
sbCbus.append((priorities + " "));
}
if (filterIndex >= 0) {
sbCan.append(("Filter " + (filterIndex + 1) + ": "));
sbCbus.append(("Filter " + (filterIndex + 1) + ": "));
}
// display decoded data
sbCan.append(line);
sbCbus.append(decoded);
// synchronized( linesBufferCbus ) {
synchronized (linesBuffer) {
linesBuffer[CAN].append(sbCan.toString());
linesBuffer[CBUS].append(sbCbus.toString());
}
// if not frozen, display it in the Swing thread
if (!freezeButton.isSelected()) {
Runnable r = new Runnable() {
@Override
public void run() {
synchronized (linesBuffer) {
final int start = monTextPaneCbus.getText().length();
monTextPaneCan.append(linesBuffer[CAN].toString());
monTextPaneCbus.append(linesBuffer[CBUS].toString());
final int end = monTextPaneCbus.getText().length();
int LineCount = monTextPaneCan.getLineCount();
if (LineCount > MAX_LINES) {
LineCount -= MAX_LINES;
try {
int offset = monTextPaneCan.getLineStartOffset(LineCount);
monTextPaneCan.getDocument().remove(0, offset);
monTextPaneCbus.getDocument().remove(0, offset);
} catch (BadLocationException ex) {
}
}
try {
if (filterIndex >= 0) {
log.debug("Add highlight start: " + start + " end: " + end);
cbusHighlighter.addHighlight(start, end - 1, cbusHighlightPainter);
}
} catch (BadLocationException e) {
// do nothing
}
linesBuffer[CAN].setLength(0);
linesBuffer[CBUS].setLength(0);
}
}
};
javax.swing.SwingUtilities.invokeLater(r);
}
// if requested, log to a file.
if (logStream != null) {
String logLine = sbCbus.toString();
if (!newline.equals("\n")) {
// have to massage the line-ends
int j;
int lim = sbCbus.length();
// arbitrary guess at space
StringBuffer out = new StringBuffer(sbCbus.length() + 10);
for (j = 0; j < lim; j++) {
if (sbCbus.charAt(j) == '\n') {
out.append(newline);
} else {
out.append(sbCbus.charAt(j));
}
}
logLine = new String(out);
}
logStream.print(logLine);
}
}
Aggregations