use of javax.swing.text.Document in project intellij-community by JetBrains.
the class BaseInspection method prepareNumberEditor.
protected JFormattedTextField prepareNumberEditor(@NonNls final String fieldName) {
final NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
final JFormattedTextField valueField = new JFormattedTextField(formatter);
Object value = ReflectionUtil.getField(getClass(), this, null, fieldName);
valueField.setValue(value);
valueField.setColumns(2);
// hack to work around text field becoming unusably small sometimes when using GridBagLayout
valueField.setMinimumSize(valueField.getPreferredSize());
UIUtil.fixFormattedField(valueField);
final Document document = valueField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent evt) {
try {
valueField.commitEdit();
final Number number = (Number) valueField.getValue();
ReflectionUtil.setField(BaseInspection.this.getClass(), BaseInspection.this, int.class, fieldName, number.intValue());
} catch (ParseException e) {
// No luck this time. Will update the field when correct value is entered.
}
}
});
return valueField;
}
use of javax.swing.text.Document in project intellij-community by JetBrains.
the class IpnbEditablePanel method getText.
public String getText(int from) {
if (myEditing && myEditableTextArea != null) {
final Document document = myEditableTextArea.getDocument();
final int to = document.getLength();
return getText(from, to);
}
return null;
}
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 joda-time by JodaOrg.
the class AgeCalculator method addTopArea.
private void addTopArea(Container container) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(fixedHeight(new JLabel("Birthdate")));
panel.add(Box.createHorizontalStrut(10));
final JTextField birthdateField = new JTextField(iBirthdateStr + ' ');
Document doc = birthdateField.getDocument();
doc.addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
update(e);
}
public void removeUpdate(DocumentEvent e) {
update(e);
}
public void changedUpdate(DocumentEvent e) {
update(e);
}
private void update(DocumentEvent e) {
iBirthdateStr = birthdateField.getText();
updateResults();
}
});
panel.add(fixedHeight(birthdateField));
panel.add(Box.createHorizontalStrut(10));
Object[] ids = DateTimeZone.getAvailableIDs().toArray();
final JComboBox zoneSelector = new JComboBox(ids);
zoneSelector.setSelectedItem(DateTimeZone.getDefault().getID());
panel.add(fixedSize(zoneSelector));
zoneSelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = (String) zoneSelector.getSelectedItem();
iChronology = ISOChronology.getInstance(DateTimeZone.forID(id));
updateResults();
}
});
container.add(fixedHeight(panel));
}
use of javax.swing.text.Document in project ACS by ACS-Community.
the class FeedbackArea method append.
protected void append(String feedback) {
Document doc = outputArea.getDocument();
if (doc == null) {
return;
}
try {
doc.insertString(doc.getLength(), feedback, null);
} catch (BadLocationException exc) {
}
int newCaretPosition = outputArea.getCaretPosition();
int newLength = doc.getLength();
int tooMuch = Math.max(newLength - maxLength, 0);
if (newLength > maxLength) {
newCaretPosition -= (newLength - maxLength);
}
int caretPosition;
if (!scrollLock)
caretPosition = doc.getLength() - tooMuch;
else {
if (newCaretPosition >= 0)
caretPosition = newCaretPosition;
else
caretPosition = 0;
}
outputArea.setCaretPosition(caretPosition);
if (newLength > maxLength) {
try {
doc.remove(0, newLength - maxLength);
} catch (BadLocationException exc1) {
}
}
}
Aggregations