setTitle(RouteConverter.getBundle().getString("complete-flight-plan-title"));
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonNextOrFinish);
buttonPrevious.addActionListener(new DialogAction(this) {
public void run() {
if (index > 0) {
index--;
updateView();
}
}
});
buttonNextOrFinish.addActionListener(new DialogAction(this) {
public void run() {
if (index < route.getPositionCount() - 1) {
index++;
updateView();
} else
close();
}
});
textFieldDescription.addKeyListener(new KeyAdapter() {
protected void update() {
getPosition().setDescription(textFieldDescription.getText());
validateModel();
}
});
textFieldIdentifier.addKeyListener(new KeyAdapter() {
protected void update() {
getPosition().setIdentifier(textFieldIdentifier.getText());
validateModel();
}
});
comboBoxCountryCode.setRenderer(new CountryCodeListCellRenderer());
comboBoxCountryCode.setModel(new DefaultComboBoxModel(CountryCode.values()));
comboBoxCountryCode.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
CountryCode countryCode = (CountryCode) e.getItem();
getPosition().setCountryCode(countryCode);
validateModel();
}
});
comboBoxWaypointType.setRenderer(new WaypointTypeListCellRenderer());
comboBoxWaypointType.setModel(new DefaultComboBoxModel(WaypointType.values()));
comboBoxWaypointType.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
WaypointType waypointType = (WaypointType) e.getItem();
getPosition().setWaypointType(waypointType);
validateModel();
}
});
updateView();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
close();
}
});
contentPane.registerKeyboardAction(new DialogAction(this) {
public void run() {
close();
}
}, getKeyStroke(VK_ESCAPE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}