package tim.prune.function; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import tim.prune.App; import tim.prune.GenericFunction; import tim.prune.I18nManager; import tim.prune.data.sort.SortMode; /** * Abstract superclass for the functions which rearrange points, * such as waypoints or photo points */ public abstract class RearrangeFunction extends GenericFunction { /** Function dialog */ private JDialog _dialog = null; /** Radio buttons for start/end/nearest */ private JRadioButton[] _positionRadios = null; /** Radio buttons for sorting */ private JRadioButton[] _sortRadios = null; /** Is the "nearest" option available? */ private boolean _nearestAvailable = false; /** Enumeration for rearrange commands */ protected enum Rearrange { /** Rearrange all waypoints to start */ TO_START, /** Rearrange all waypoints to end */ TO_END, /** Rearrange each waypoint to nearest track point */ TO_NEAREST } /** * Constructor * @param inApp app object * @param isNearestAvailable true if nearest option is visible */ public RearrangeFunction(App inApp, boolean isNearestAvailable) { super(inApp); _nearestAvailable = isNearestAvailable; } /** * Begin the function by showing the dialog */ public void begin() { // Make dialog window 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(); } // If sorting by time isn't available, then disable radio button _sortRadios[2].setEnabled(isSortByTimeAllowed()); // Show dialog _dialog.setVisible(true); } /** * Create dialog components * @return Panel containing all gui elements in dialog */ private JPanel makeDialogComponents() { JPanel dialogPanel = new JPanel(); dialogPanel.setLayout(new BorderLayout()); JLabel descLabel = new JLabel(I18nManager.getText(getDescriptionKey())); descLabel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); dialogPanel.add(descLabel, BorderLayout.NORTH); // Radios for position (start / end / nearest) _positionRadios = new JRadioButton[3]; final String[] posNames = {"tostart", "toend", "tonearest"}; ButtonGroup posGroup = new ButtonGroup(); JPanel posPanel = new JPanel(); posPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); for (int i=0; i