X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2FRearrangeFunction.java;fp=src%2Ftim%2Fprune%2Ffunction%2FRearrangeFunction.java;h=01cd1d106e2936686492375146ca43b62d7eb910;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/RearrangeFunction.java b/src/tim/prune/function/RearrangeFunction.java new file mode 100644 index 0000000..01cd1d1 --- /dev/null +++ b/src/tim/prune/function/RearrangeFunction.java @@ -0,0 +1,207 @@ +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