1 package tim.prune.function.compress;
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.event.ActionListener;
7 import javax.swing.BorderFactory;
8 import javax.swing.JCheckBox;
9 import javax.swing.JPanel;
11 import tim.prune.I18nManager;
12 import tim.prune.data.Track;
15 * Abstract class to act as an algorithm for track compression
17 public abstract class CompressionAlgorithm
19 protected JCheckBox _activateCheckBox = null;
20 protected SummaryLabel _summaryLabel = null;
21 protected Track _track = null;
22 protected TrackDetails _trackDetails = null;
26 * Constructor giving Track
27 * @param inTrack track object to use for compression
28 * @param inDetails track details object
29 * @param inListener listener to be informed of activation clicks
31 public CompressionAlgorithm(Track inTrack, TrackDetails inDetails,
32 ActionListener inListener)
35 _trackDetails = inDetails;
36 _activateCheckBox = new JCheckBox(I18nManager.getText(getTitleTextKey()));
37 _activateCheckBox.setSelected(false);
38 _activateCheckBox.addActionListener(inListener);
43 * @return true if this algorithm has been activated
45 public boolean isActivated()
47 return _activateCheckBox.isSelected();
52 * @return JPanel containing gui components
54 public JPanel getGuiComponents()
56 JPanel panel = new JPanel();
57 panel.setBorder(BorderFactory.createTitledBorder(""));
58 panel.setLayout(new BorderLayout());
59 panel.add(_activateCheckBox, BorderLayout.NORTH);
60 Component specifics = getSpecificGuiComponents();
61 if (specifics != null) {
62 panel.add(specifics, BorderLayout.CENTER);
64 // Add label at bottom
65 _summaryLabel = new SummaryLabel(_track);
66 panel.add(_summaryLabel, BorderLayout.SOUTH);
71 * Preview the algorithm by counting the number of points deleted
72 * @param inFlags array of deletion flags from previous algorithms
73 * @return number of points to be deleted by this algorithm
75 public int preview(boolean[] inFlags)
80 // Run the compression and set the deletion flags
81 numDeleted = compress(inFlags);
82 _summaryLabel.setValue(numDeleted);
85 _summaryLabel.clearValue();
92 * @return key to use for title text of algorithm
94 protected abstract String getTitleTextKey();
97 * @return gui components controlling algorithm (if any)
99 protected abstract Component getSpecificGuiComponents();
102 * Perform the compression and set the results in the given array
103 * @param inFlags deletion flags from previous algorithms
104 * @return number of points deleted by this algorithm
106 protected abstract int compress(boolean[] inFlags);