use of javax.swing.text.Document in project intellij-community by JetBrains.
the class HtmlUnknownTagInspection method createOptionsPanel.
@NotNull
protected static JComponent createOptionsPanel(@NotNull final HtmlUnknownElementInspection inspection) {
final JPanel result = new JPanel(new BorderLayout());
final JPanel internalPanel = new JPanel(new BorderLayout());
result.add(internalPanel, BorderLayout.NORTH);
final Ref<FieldPanel> panelRef = new Ref<>();
final FieldPanel additionalAttributesPanel = new FieldPanel(null, null, new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Messages.showTextAreaDialog(panelRef.get().getTextField(), StringUtil.wordsToBeginFromUpperCase(inspection.getPanelTitle()), inspection.getClass().getSimpleName(), s -> reparseProperties(s), strings -> StringUtil.join(strings, ","));
}
}, null);
((JButton) additionalAttributesPanel.getComponent(1)).setIcon(PlatformIcons.OPEN_EDIT_DIALOG_ICON);
panelRef.set(additionalAttributesPanel);
additionalAttributesPanel.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
final Document document = e.getDocument();
try {
final String text = document.getText(0, document.getLength());
if (text != null) {
inspection.updateAdditionalEntries(text.trim());
}
} catch (BadLocationException e1) {
inspection.getLogger().error(e1);
}
}
});
final JCheckBox checkBox = new JCheckBox(inspection.getCheckboxTitle());
checkBox.setSelected(inspection.isCustomValuesEnabled());
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean b = checkBox.isSelected();
if (b != inspection.isCustomValuesEnabled()) {
inspection.enableCustomValues(b);
additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
}
}
});
internalPanel.add(checkBox, BorderLayout.NORTH);
internalPanel.add(additionalAttributesPanel, BorderLayout.CENTER);
additionalAttributesPanel.setPreferredSize(new Dimension(150, additionalAttributesPanel.getPreferredSize().height));
additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
additionalAttributesPanel.setText(inspection.getAdditionalEntries());
return result;
}
use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.
the class TextComponentPrintable method releaseReadLock.
/**
* Tries to release document's readlock
*
* Note: Not to be called on the EDT.
*/
private void releaseReadLock() {
assert !SwingUtilities.isEventDispatchThread();
Document document = textComponentToPrint.getDocument();
if (document instanceof AbstractDocument) {
try {
((AbstractDocument) document).readUnlock();
needReadLock = true;
} catch (Error ignore) {
// readUnlock() might throw StateInvariantError
}
}
}
use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.
the class TextComponentPrintable method acquireReadLock.
/**
* Tries to acquire document's readLock if it was released
* in releaseReadLock() method.
*
* Note: Not to be called on the EDT.
*/
private void acquireReadLock() {
assert !SwingUtilities.isEventDispatchThread();
if (needReadLock) {
try {
/*
* wait until all the EDT events are processed
* some of the document changes are asynchronous
* we need to make sure we get the lock after those changes
*/
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
}
});
} catch (InterruptedException ignore) {
} catch (java.lang.reflect.InvocationTargetException ignore) {
}
Document document = textComponentToPrint.getDocument();
((AbstractDocument) document).readLock();
needReadLock = false;
}
}
use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.
the class ElementTreePanel method setEditor.
/**
* Resets the JTextComponent to <code>editor</code>. This will update
* the tree accordingly.
*/
public void setEditor(JTextComponent editor) {
if (this.editor == editor) {
return;
}
if (this.editor != null) {
Document oldDoc = this.editor.getDocument();
oldDoc.removeDocumentListener(this);
this.editor.removePropertyChangeListener(this);
this.editor.removeCaretListener(this);
}
this.editor = editor;
if (editor == null) {
treeModel = null;
tree.setModel(null);
} else {
Document newDoc = editor.getDocument();
newDoc.addDocumentListener(this);
editor.addPropertyChangeListener(this);
editor.addCaretListener(this);
treeModel = new ElementTreeModel(newDoc);
tree.setModel(treeModel);
}
}
use of javax.swing.text.Document in project suite by stupidsing.
the class EditorPane method replaceLines.
private void replaceLines(Fun<Segment, String> fun) throws BadLocationException {
Document document = getDocument();
int length = document.getLength();
int ss = getSelectionStart();
int se = max(ss, getSelectionEnd() - 1);
while (0 < ss && document.getText(ss, 1).charAt(0) != 10) ss--;
while (se < length && document.getText(se, 1).charAt(0) != 10) se++;
// do not include first and last LFs
int start = document.getText(ss, 1).charAt(0) == 10 ? ss + 1 : ss;
int end = se;
replace(document, start, end, fun);
}
Aggregations