- /**
- * Begin the function
- */
- public void begin()
- {
- if (_dialog == null)
- {
- _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
- _dialog.setLocationRelativeTo(_parentFrame);
- _dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- _dialog.getContentPane().add(makeDialogComponents());
- _dialog.pack();
- }
- enableOkButton();
- // TODO: Maybe set distance units according to current Config setting?
- final boolean hasTimestamps = _app.getTrackInfo().getTrack().hasData(Field.TIMESTAMP);
- _timeLimitRadio.setEnabled(hasTimestamps);
- _dialog.setVisible(true);
- }
-
- /**
- * Create dialog components
- * @return Panel containing all gui elements in dialog
- */
- private Component makeDialogComponents()
- {
- JPanel dialogPanel = new JPanel();
- dialogPanel.setLayout(new BorderLayout(5, 5));
-
- // Make radio buttons for three different options
- _distLimitRadio = new JRadioButton(I18nManager.getText("dialog.correlate.options.distancelimit") + ": ");
- _timeLimitRadio = new JRadioButton(I18nManager.getText("dialog.correlate.options.timelimit") + ": ");
- ButtonGroup radioGroup = new ButtonGroup();
- radioGroup.add(_distLimitRadio);
- radioGroup.add(_timeLimitRadio);
-
- // central panel for limits
- JPanel limitsPanel = new JPanel();
- limitsPanel.setLayout(new BoxLayout(limitsPanel, BoxLayout.Y_AXIS));
- limitsPanel.add(Box.createVerticalStrut(8));
- ChangeListener optionsChangedListener = new ChangeListener() {
- public void optionsChanged() {
- enableOkButton();
- }
- };
- // distance limits
- JPanel distLimitPanel = new JPanel();
- distLimitPanel.setLayout(new FlowLayout());
- _distLimitRadio.setSelected(true);
- _distLimitRadio.addItemListener(optionsChangedListener);
- distLimitPanel.add(_distLimitRadio);
- _distanceField = new WholeNumberField(3);
- _distanceField.addKeyListener(optionsChangedListener);
- distLimitPanel.add(_distanceField);
- String[] distUnitsOptions = {I18nManager.getText("units.kilometres"), I18nManager.getText("units.metres"),
- I18nManager.getText("units.miles")};
- _distUnitsDropdown = new JComboBox<String>(distUnitsOptions);
- _distUnitsDropdown.addItemListener(optionsChangedListener);
- distLimitPanel.add(_distUnitsDropdown);
- distLimitPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
- limitsPanel.add(distLimitPanel);
-
- // time limit panel
- JPanel timeLimitPanel = new JPanel();
- timeLimitPanel.setLayout(new FlowLayout());
- _timeLimitRadio.addItemListener(optionsChangedListener);
- timeLimitPanel.add(_timeLimitRadio);
- _limitHourField = new WholeNumberField(2);
- _limitHourField.addKeyListener(optionsChangedListener);
- timeLimitPanel.add(_limitHourField);
- timeLimitPanel.add(new JLabel(I18nManager.getText("dialog.correlate.options.offset.hours")));
- _limitMinField = new WholeNumberField(3);
- _limitMinField.addKeyListener(optionsChangedListener);
- timeLimitPanel.add(_limitMinField);
- timeLimitPanel.add(new JLabel(I18nManager.getText("units.minutes")));
- timeLimitPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
- limitsPanel.add(timeLimitPanel);
-
- dialogPanel.add(limitsPanel, BorderLayout.NORTH);
-
- // button panel at bottom
- JPanel buttonPanel = new JPanel();
- buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
- // OK button
- _okButton = new JButton(I18nManager.getText("button.ok"));
- _okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- performSplit();
- }
- });
- buttonPanel.add(_okButton);
- // Cancel button
- JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- _dialog.dispose();
- }
- });
- cancelButton.addKeyListener(new KeyAdapter() {
- public void keyPressed(KeyEvent inE) {
- if (inE.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
- }
- });
- buttonPanel.add(cancelButton);
- dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
- return dialogPanel;
- }
-
- /**
- * Enable or disable the OK button according to the inputs
- */
- private void enableOkButton()
- {
- boolean enabled = false;
- if (_distLimitRadio.isSelected()) {
- enabled = _distanceField.getValue() > 0;
- }
- else if (_timeLimitRadio.isSelected()) {
- enabled = _limitHourField.getValue() > 0 || _limitMinField.getValue() > 0;
- }
- _okButton.setEnabled(enabled);
-
- // Also enable/disable the other fields
- _distanceField.setEnabled(_distLimitRadio.isSelected());
- _distUnitsDropdown.setEnabled(_distLimitRadio.isSelected());
- _limitHourField.setEnabled(_timeLimitRadio.isSelected());
- _limitMinField.setEnabled(_timeLimitRadio.isSelected());
- }