use of javax.swing.text.Document in project intellij-community by JetBrains.
the class FileTextFieldImpl method processChosenFromCompletion.
private void processChosenFromCompletion(boolean nameOnly) {
final LookupFile file = getSelectedFileFromCompletionPopup();
if (file == null)
return;
if (nameOnly) {
try {
final Document doc = myPathTextField.getDocument();
int caretPos = myPathTextField.getCaretPosition();
if (myFinder.getSeparator().equals(doc.getText(caretPos, 1))) {
for (; caretPos < doc.getLength(); caretPos++) {
final String eachChar = doc.getText(caretPos, 1);
if (!myFinder.getSeparator().equals(eachChar))
break;
}
}
int start = caretPos > 0 ? caretPos - 1 : caretPos;
while (start >= 0) {
final String each = doc.getText(start, 1);
if (myFinder.getSeparator().equals(each)) {
start++;
break;
}
start--;
}
int end = start < caretPos ? caretPos : start;
while (end <= doc.getLength()) {
final String each = doc.getText(end, 1);
if (myFinder.getSeparator().equals(each)) {
break;
}
end++;
}
if (end > doc.getLength()) {
end = doc.getLength();
}
if (start > end || start < 0 || end > doc.getLength()) {
setTextToFile(file);
} else {
replacePathComponent(file, caretPos, start, end);
}
} catch (BadLocationException e) {
LOG.error(e);
}
} else {
setTextToFile(file);
}
}
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 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) {
}
}
}
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 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;
}
Aggregations