protected void addNewInterval(final Interval interval, JPanel intervalsPanel) {
// intervals.add(interval);
JPanel intervalPanel = new JPanel();
intervalPanel.setLayout(new GridBagLayout());
DocumentNumber fromDoc = new DocumentNumber();
fromDoc.setAllowFloatValues(true);
fromDoc.setAllowNegativeValues(true);
final JTextField fromTextField = new JTextField(fromDoc, interval.getFrom() + "", 15);
fromTextField.setBorder(new TitledBorder("From"));
fromTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
String text = fromTextField.getText();
updateValue(interval, text);
}
@Override
public void insertUpdate(DocumentEvent e) {
String text = fromTextField.getText();
updateValue(interval, text);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
protected void updateValue(final Interval interval, String text) {
try {
if (!text.isEmpty()) {
double value = Double.parseDouble(text.trim());
if (value != interval.getTo()) {
interval.setFrom(value);
fireEditionStateChanged(true);
} else {
displayError("Min and max values for interval trajectory shall be different");
fireEditionStateChanged(false);
}
}
} catch (NumberFormatException e1) {
displayError("Illegal value for trajectory interval min boundary: " + text);
}
}
});
DocumentNumber toDoc = new DocumentNumber();
toDoc.setAllowFloatValues(true);
toDoc.setAllowNegativeValues(true);
final JTextField toTextField = new JTextField(toDoc, interval.getTo() + "", 15);
toTextField.setBorder(new TitledBorder("To"));
toTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
String text = toTextField.getText();
updateValue(interval, text);
}
@Override
public void insertUpdate(DocumentEvent e) {
String text = toTextField.getText();
updateValue(interval, text);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
protected void updateValue(final Interval interval, String text) {
try {
if (!text.isEmpty()) {
double value = Double.parseDouble(text.trim());
if (value != interval.getFrom()) {
interval.setTo(value);
fireEditionStateChanged(true);
} else {
displayError("Min and max values for interval trajectory shall be different");
fireEditionStateChanged(false);
}
}
} catch (NumberFormatException e1) {
displayError("Illegal value for trajectory interval max boundary: " + text);
}
}
});
DocumentNumber nbAcqDoc = new DocumentNumber();
nbAcqDoc.setAllowFloatValues(false);
nbAcqDoc.setAllowNegativeValues(false);
final JTextField nbAcqTextField = new JTextField(nbAcqDoc, interval.getNbAcq() + "", 15);
nbAcqTextField.setBorder(new TitledBorder("Acquisition points count"));
nbAcqTextField.getDocument().addDocumentListener(new DocumentListener() {