]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/load/babel/FilterDefinition.java
84179080379c4cf1cfa833db3bf4ccf0a820fcb3
[GpsPrune.git] / tim / prune / load / babel / FilterDefinition.java
1 package tim.prune.load.babel;
2
3 import java.awt.event.KeyAdapter;
4 import java.awt.event.KeyEvent;
5 import java.awt.event.KeyListener;
6
7 import javax.swing.JPanel;
8 import javax.swing.SwingUtilities;
9
10 /**
11  * Superclass of all the filter definition panels, to be added in the cardset
12  * of the AddFilterDialog
13  */
14 public abstract class FilterDefinition extends JPanel
15 {
16         /** Parent dialog to inform of parameter changes */
17         private AddFilterDialog _parentDialog = null;
18         /** Listener for key presses on the parameter entry fields */
19         protected KeyListener _paramChangeListener = null;
20
21         /**
22          * Constructor
23          */
24         public FilterDefinition(AddFilterDialog inFilterDialog)
25         {
26                 _parentDialog = inFilterDialog;
27                 _paramChangeListener = new KeyAdapter() {
28                         public void keyTyped(KeyEvent arg0) {
29                                 SwingUtilities.invokeLater(new Runnable() {
30                                         public void run() {
31                                                 _parentDialog.filterParamsChanged();
32                                         }
33                                 });
34                         }
35                 };
36         }
37
38         /**
39          * @return true if the filter definition is valid
40          */
41         public abstract boolean isFilterValid();
42
43         /**
44          * @return filter definition to pass to gpsbabel
45          */
46         public String getString()
47         {
48                 return "-x " + getFilterName() + getParameters();
49         }
50
51         /** @return filter name */
52         protected abstract String getFilterName();
53
54         /** Construct the GUI elements and add them to the panel */
55         protected abstract void makePanelContents();
56
57         /** @return filter parameters */
58         protected abstract String getParameters();
59 }