super(RouteConverter.getInstance().getFrame(), "options");
setTitle(RouteConverter.getBundle().getString("options-title"));
setContentPane(contentPane);
getRootPane().setDefaultButton(buttonClose);
final RouteConverter r = RouteConverter.getInstance();
ComboBoxModel<Locale> localeModel = new DefaultComboBoxModel<>(new Locale[]{
ARABIA, CHINA, CZECH, GERMANY, US, SPAIN, FRANCE, CROATIA,
ITALY, NEDERLANDS, POLAND, RUSSIA, SLOVAKIA, SERBIA, ROOT
});
localeModel.setSelectedItem(Application.getInstance().getLocale());
comboBoxLocale.setModel(localeModel);
comboBoxLocale.setRenderer(new LocaleListCellRenderer());
comboBoxLocale.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
Locale locale = (Locale) e.getItem();
Application.getInstance().setLocale(locale);
}
});
textFieldBabelPath.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
BabelFormat.setBabelPathPreference(textFieldBabelPath.getText());
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
textFieldBabelPath.setText(BabelFormat.getBabelPathPreference());
buttonChooseBabelPath.addActionListener(new FrameAction() {
public void run() {
chooseBabelPath();
}
});
new CheckBoxPreferencesSynchronizer(checkBoxAutomaticUpdateCheck, getPreferences(), AUTOMATIC_UPDATE_CHECK_PREFERENCE, true);
new CheckBoxPreferencesSynchronizer(checkBoxRecenterAfterZooming, getPreferences(), RECENTER_AFTER_ZOOMING_PREFERENCE, false);
checkBoxRecenterAfterZooming.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
r.setRecenterAfterZooming(checkBoxRecenterAfterZooming.isSelected());
}
});
new CheckBoxPreferencesSynchronizer(checkBoxShowCoordinates, getPreferences(), SHOW_COORDINATES_PREFERENCE, false);
checkBoxShowCoordinates.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
r.setShowCoordinates(checkBoxShowCoordinates.isSelected());
}
});
new CheckBoxPreferencesSynchronizer(checkBoxShowWaypointDescription, getPreferences(), SHOW_WAYPOINT_DESCRIPTION_PREFERENCE, false);
checkBoxShowWaypointDescription.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
r.setShowWaypointDescription(checkBoxShowWaypointDescription.isSelected());
}
});
DefaultComboBoxModel<RoutingService> routingServiceModel = new DefaultComboBoxModel<>();
for (RoutingService service : r.getRoutingServiceFacade().getRoutingServices())
routingServiceModel.addElement(service);
routingServiceModel.setSelectedItem(r.getRoutingServiceFacade().getRoutingService());
comboBoxRoutingService.setModel(routingServiceModel);
comboBoxRoutingService.setRenderer(new RoutingServiceListCellRenderer());
comboBoxRoutingService.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
RoutingService service = RoutingService.class.cast(e.getItem());
r.getRoutingServiceFacade().setRoutingService(service);
handleRoutingServiceUpdate();
}
});
textFieldRoutingServicePath.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
r.getRoutingServiceFacade().getRoutingService().setPath(textFieldRoutingServicePath.getText());
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
buttonChooseRoutingServicePath.addActionListener(new FrameAction() {
public void run() {
chooseRoutingServicePath();
}
});
handleRoutingServiceUpdate();
comboboxTravelMode.setRenderer(new TravelModeListCellRenderer());
comboboxTravelMode.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
TravelMode travelMode = (TravelMode) e.getItem();
r.getRoutingServiceFacade().setTravelMode(travelMode);
}
});
checkBoxAvoidFerries.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
r.getRoutingServiceFacade().setAvoidFerries(checkBoxAvoidFerries.isSelected());
}
});
checkBoxAvoidHighways.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
r.getRoutingServiceFacade().setAvoidHighways(checkBoxAvoidHighways.isSelected());
}
});
checkBoxAvoidTolls.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
r.getRoutingServiceFacade().setAvoidTolls(checkBoxAvoidTolls.isSelected());
}
});
ComboBoxModel<NumberPattern> numberPatternModel = new DefaultComboBoxModel<>(new NumberPattern[]{
Description_Only, Number_Only, Number_Directly_Followed_By_Description, Number_Space_Then_Description
});
numberPatternModel.setSelectedItem(r.getNumberPatternPreference());
comboboxNumberPattern.setModel(numberPatternModel);
comboboxNumberPattern.setRenderer(new NumberPatternListCellRenderer());
comboboxNumberPattern.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
NumberPattern numberPattern = NumberPattern.class.cast(e.getItem());
r.setNumberPatternPreference(numberPattern);
}
});
DefaultComboBoxModel<ElevationService> elevationServiceModel = new DefaultComboBoxModel<>();
for (ElevationService service : r.getElevationServiceFacade().getElevationServices())
elevationServiceModel.addElement(service);
elevationServiceModel.setSelectedItem(r.getElevationServiceFacade().getElevationService());
comboBoxElevationService.setModel(elevationServiceModel);
comboBoxElevationService.setRenderer(new ElevationServiceListCellRenderer());
comboBoxElevationService.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
ElevationService service = ElevationService.class.cast(e.getItem());
r.getElevationServiceFacade().setElevationService(service);
handleElevationServiceUpdate();
}
});
textFieldElevationServicePath.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
r.getElevationServiceFacade().getElevationService().setPath(textFieldElevationServicePath.getText());
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
buttonChooseElevationServicePath.addActionListener(new FrameAction() {
public void run() {
chooseElevationServicePath();
}
});
handleElevationServiceUpdate();
ComboBoxModel<UnitSystem> unitSystemModel = new DefaultComboBoxModel<>(new UnitSystem[]{
Metric, Statute, Nautic
});
unitSystemModel.setSelectedItem(r.getUnitSystemModel().getUnitSystem());
comboBoxUnitSystem.setModel(unitSystemModel);
comboBoxUnitSystem.setRenderer(new UnitSystemListCellRenderer());
comboBoxUnitSystem.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
UnitSystem unitSystem = UnitSystem.class.cast(e.getItem());
r.getUnitSystemModel().setUnitSystem(unitSystem);
}
});
ComboBoxModel<DegreeFormat> degreeFormatModel = new DefaultComboBoxModel<>(new DegreeFormat[]{
Degrees, Degrees_Minutes, Degrees_Minutes_Seconds
});
degreeFormatModel.setSelectedItem(r.getUnitSystemModel().getDegreeFormat());
comboBoxDegreeFormat.setModel(degreeFormatModel);
comboBoxDegreeFormat.setRenderer(new DegreeFormatListCellRenderer());
comboBoxDegreeFormat.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
DegreeFormat degreeFormat = DegreeFormat.class.cast(e.getItem());
r.getUnitSystemModel().setDegreeFormat(degreeFormat);
}
});
ComboBoxModel<String> timeZoneModel = new DefaultComboBoxModel<>(getTimeZoneIds());
timeZoneModel.setSelectedItem(r.getTimeZonePreference());
comboBoxTimeZone.setModel(timeZoneModel);
comboBoxTimeZone.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != SELECTED)
return;
String timeZoneId = String.valueOf(e.getItem());
r.setTimeZonePreference(timeZoneId);
}
});
buttonClose.addActionListener(new DialogAction(this) {
public void run() {