List<String> inputHistory = new LinkedList<>(Main.pref.getCollection("projection.custom.value.history", samples));
Collections.reverse(inputHistory);
cbInput.setPossibleItems(inputHistory);
cbInput.setText(initialText == null ? "" : initialText);
final HtmlPanel errorsPanel = new HtmlPanel();
errorsPanel.setVisible(false);
final JLabel valStatus = new JLabel();
valStatus.setVisible(false);
final AbstractTextComponentValidator val = new AbstractTextComponentValidator(input, false, false, false) {
private String error;
@Override
public void validate() {
if (!isValid()) {
feedbackInvalid(tr("Invalid projection configuration: {0}",error));
} else {
feedbackValid(tr("Projection configuration is valid."));
}
listener.actionPerformed(null);
}
@Override
public final boolean isValid() {
try {
CustomProjection test = new CustomProjection();
test.update(input.getText());
} catch (ProjectionConfigurationException ex) {
error = ex.getMessage();
valStatus.setIcon(ImageProvider.get("data", "error.png"));
valStatus.setVisible(true);
errorsPanel.setText(error);
errorsPanel.setVisible(true);
return false;
}
errorsPanel.setVisible(false);
valStatus.setIcon(ImageProvider.get("misc", "green_check.png"));
valStatus.setVisible(true);
return true;
}