use of javax.swing.text.Document in project Botnak by Gocnak.
the class ListenerURL method mouseReleased.
@Override
public void mouseReleased(MouseEvent e) {
JTextPane editor = (JTextPane) e.getSource();
Point pt = new Point(e.getX(), e.getY());
int pos = editor.viewToModel(pt);
if (pos >= 0) {
Document doc = editor.getDocument();
if (doc instanceof DefaultStyledDocument) {
DefaultStyledDocument hdoc = (DefaultStyledDocument) doc;
Element el = hdoc.getCharacterElement(pos);
AttributeSet a = el.getAttributes();
String href = (String) a.getAttribute(HTML.Attribute.HREF);
if (href != null) {
Utils.openWebPage(href);
}
}
}
}
use of javax.swing.text.Document in project intellij-community by JetBrains.
the class ActionTracer method afterActionPerformed.
@Override
public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
StringBuilder out = new StringBuilder(String.format("%1$tF %1$tT,%1$tL ", System.currentTimeMillis()));
final ActionManager actionManager = ActionManager.getInstance();
final String id = actionManager.getId(action);
out.append("id=").append(id);
if (id != null) {
out.append("; shortcuts:");
final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(id);
for (int i = 0; i < shortcuts.length; i++) {
Shortcut shortcut = shortcuts[i];
out.append(shortcut);
if (i < shortcuts.length - 1) {
out.append(",");
}
}
}
out.append("; class: ").append(action.getClass().getName());
out.append("\n");
final Document doc = myText.getDocument();
try {
doc.insertString(doc.getLength(), out.toString(), null);
SwingUtilities.invokeLater(() -> {
final int y = (int) myText.getBounds().getMaxY();
myText.scrollRectToVisible(new Rectangle(0, y, myText.getBounds().width, 0));
});
} catch (BadLocationException e) {
LOG.error(e);
}
}
use of javax.swing.text.Document in project intellij-community by JetBrains.
the class SingleIntegerFieldOptionsPanel method setupIntegerFieldTrackingValue.
/**
* Sets integer number format to JFormattedTextField instance,
* sets value of JFormattedTextField instance to object's field value,
* synchronizes object's field value with the value of JFormattedTextField instance.
*
* @param textField JFormattedTextField instance
* @param owner an object whose field is synchronized with {@code textField}
* @param property object's field name for synchronization
*/
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField, final InspectionProfileEntry owner, final String property) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
textField.setValue(getPropertyValue(owner, property));
final Document document = textField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
textField.commitEdit();
setPropertyValue(owner, property, ((Number) textField.getValue()).intValue());
} catch (ParseException e1) {
// No luck this time
}
}
});
}
use of javax.swing.text.Document in project intellij-community by JetBrains.
the class FileTextFieldImpl method replacePathComponent.
/**
* Replace the path component under the caret with the file selected from the completion list.
*
* @param file the selected file.
* @param caretPos
* @param start the start offset of the path component under the caret.
* @param end the end offset of the path component under the caret.
* @throws BadLocationException
*/
private void replacePathComponent(LookupFile file, int caretPos, int start, int end) throws BadLocationException {
final Document doc = myPathTextField.getDocument();
myPathTextField.setSelectionStart(0);
myPathTextField.setSelectionEnd(0);
final String name = file.getName();
boolean toRemoveExistingName;
String prefix = "";
if (caretPos >= start) {
prefix = doc.getText(start, caretPos - start);
if (prefix.length() == 0) {
prefix = doc.getText(start, end - start);
}
if (SystemInfo.isFileSystemCaseSensitive) {
toRemoveExistingName = name.startsWith(prefix) && prefix.length() > 0;
} else {
toRemoveExistingName = StringUtil.toUpperCase(name).startsWith(StringUtil.toUpperCase(prefix)) && prefix.length() > 0;
}
} else {
toRemoveExistingName = true;
}
int newPos;
if (toRemoveExistingName) {
doc.remove(start, end - start);
doc.insertString(start, name, doc.getDefaultRootElement().getAttributes());
newPos = start + name.length();
} else {
doc.insertString(caretPos, name, doc.getDefaultRootElement().getAttributes());
newPos = caretPos + name.length();
}
if (file.isDirectory()) {
if (!myFinder.getSeparator().equals(doc.getText(newPos, 1))) {
doc.insertString(newPos, myFinder.getSeparator(), doc.getDefaultRootElement().getAttributes());
newPos++;
}
}
if (newPos < doc.getLength()) {
if (myFinder.getSeparator().equals(doc.getText(newPos, 1))) {
newPos++;
}
}
myPathTextField.setCaretPosition(newPos);
}
use of javax.swing.text.Document in project intellij-community by JetBrains.
the class IfCanBeSwitchInspection method createOptionsPanel.
@Override
public JComponent createOptionsPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final JLabel label = new JLabel(InspectionGadgetsBundle.message("if.can.be.switch.minimum.branch.option"));
final NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
final JFormattedTextField valueField = new JFormattedTextField(formatter);
valueField.setValue(Integer.valueOf(minimumBranches));
valueField.setColumns(2);
final Document document = valueField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
valueField.commitEdit();
minimumBranches = ((Number) valueField.getValue()).intValue();
} catch (ParseException ignore) {
// No luck this time
}
}
});
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets.bottom = 4;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.BASELINE_LEADING;
constraints.fill = GridBagConstraints.NONE;
constraints.insets.right = 10;
panel.add(label, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.weightx = 1.0;
constraints.insets.right = 0;
panel.add(valueField, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 2;
final CheckBox checkBox1 = new CheckBox(InspectionGadgetsBundle.message("if.can.be.switch.int.option"), this, "suggestIntSwitches");
panel.add(checkBox1, constraints);
constraints.gridy = 2;
final CheckBox checkBox2 = new CheckBox(InspectionGadgetsBundle.message("if.can.be.switch.enum.option"), this, "suggestEnumSwitches");
panel.add(checkBox2, constraints);
constraints.gridy = 3;
constraints.weighty = 1.0;
final CheckBox checkBox3 = new CheckBox(InspectionGadgetsBundle.message("if.can.be.switch.null.safe.option"), this, "onlySuggestNullSafe");
panel.add(checkBox3, constraints);
return panel;
}
Aggregations