import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import tim.prune.data.Field;
import tim.prune.data.Latitude;
import tim.prune.data.Longitude;
+import tim.prune.data.Unit;
+import tim.prune.data.UnitSetLibrary;
import tim.prune.gui.GuiGridLayout;
/**
private JTextField _nameField = null;
private JTextField _coordField = null;
private JButton _okButton = null;
- private JComboBox _altUnitsDropDown;
+ private JComboBox<String> _altUnitsDropDown;
/**
// MAYBE: Paste clipboard into the edit field
_coordField.setText("");
_nameField.setText("");
- boolean metric = Config.getConfigBoolean(Config.KEY_METRIC_UNITS);
- _altUnitsDropDown.setSelectedIndex(metric?0:1);
+ boolean useMetres = (Config.getUnitSet().getAltitudeUnit() == UnitSetLibrary.UNITS_METRES);
+ _altUnitsDropDown.setSelectedIndex(useMetres?0:1);
enableOK();
_dialog.setVisible(true);
}
// Listeners to enable/disable ok button
KeyAdapter keyListener = new KeyAdapter() {
/** Key released */
- public void keyReleased(KeyEvent arg0) {
+ public void keyReleased(KeyEvent inE) {
enableOK();
+ if (inE.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ _dialog.dispose();
+ }
}
};
MouseAdapter mouseListener = new MouseAdapter() {
- public void mouseReleased(java.awt.event.MouseEvent arg0) {
+ public void mouseReleased(MouseEvent inE) {
enableOK();
};
};
formatLabel.setHorizontalAlignment(SwingConstants.RIGHT);
grid.add(formatLabel);
final String[] altunits = {I18nManager.getText("units.metres"), I18nManager.getText("units.feet")};
- _altUnitsDropDown = new JComboBox(altunits);
+ _altUnitsDropDown = new JComboBox<String>(altunits);
grid.add(_altUnitsDropDown);
// Waypoint name
JLabel nameLabel = new JLabel(I18nManager.getText("dialog.pointnameedit.name"));
ActionListener okListener = new ActionListener() {
public void actionPerformed(ActionEvent e)
{
- finish();
+ if (_okButton.isEnabled()) {finish();}
}
};
_okButton.addActionListener(okListener);
private void enableOK()
{
String text = _coordField.getText();
- _okButton.setEnabled(text != null && text.length() > 10
+ _okButton.setEnabled(text != null && text.length() > 6
&& (text.indexOf(' ') >= 0 || text.indexOf(',') >= 0));
}
if (inValue3 != null)
{
// Look at altitude units dropdown
- final Altitude.Format altFormat = (_altUnitsDropDown.getSelectedIndex()==0?
- Altitude.Format.METRES:Altitude.Format.FEET);
- alt = new Altitude(inValue3, altFormat);
+ final Unit altUnit = (_altUnitsDropDown.getSelectedIndex()==0?
+ UnitSetLibrary.UNITS_METRES : UnitSetLibrary.UNITS_FEET);
+ alt = new Altitude(inValue3, altUnit);
if (!alt.isValid()) {alt = null;}
}
// See if value1 can be lat and value2 lon: