]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/save/PointTypeSelector.java
Version 9, February 2010
[GpsPrune.git] / tim / prune / save / PointTypeSelector.java
1 package tim.prune.save;
2
3 import java.awt.BorderLayout;
4 import java.awt.GridLayout;
5
6 import javax.swing.BorderFactory;
7 import javax.swing.JCheckBox;
8 import javax.swing.JLabel;
9 import javax.swing.JPanel;
10 import javax.swing.border.EtchedBorder;
11
12 import tim.prune.I18nManager;
13 import tim.prune.data.TrackInfo;
14
15 /**
16  * GUI element to allow the selection of point types for saving,
17  * including checkboxes for track points, waypoints, photo points
18  * and also a checkbox for the current selection
19  */
20 public class PointTypeSelector extends JPanel
21 {
22         /** Array of checkboxes */
23         private JCheckBox[] _checkboxes = new JCheckBox[4];
24
25
26         /**
27          * Constructor
28          */
29         public PointTypeSelector()
30         {
31                 createComponents();
32                 setBorder(BorderFactory.createCompoundBorder(
33                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(4, 4, 4, 4))
34                 );
35         }
36
37         /**
38          * Create the GUI components
39          */
40         private void createComponents()
41         {
42                 setLayout(new BorderLayout());
43                 // Need label to explain what it is
44                 add(new JLabel(I18nManager.getText("dialog.pointtype.desc")), BorderLayout.NORTH);
45                 // panel for the checkboxes
46                 JPanel gridPanel = new JPanel();
47                 gridPanel.setLayout(new GridLayout(0, 3, 15, 3));
48                 final String[] keys = {"track", "waypoint", "photo"};
49                 for (int i=0; i<3; i++)
50                 {
51                         _checkboxes[i] = new JCheckBox(I18nManager.getText("dialog.pointtype." + keys[i]));
52                         _checkboxes[i].setSelected(true);
53                         gridPanel.add(_checkboxes[i]);
54                 }
55                 add(gridPanel, BorderLayout.CENTER);
56                 _checkboxes[3] = new JCheckBox(I18nManager.getText("dialog.pointtype.selection"));
57                 add(_checkboxes[3], BorderLayout.SOUTH);
58         }
59
60         /**
61          * Initialize the checkboxes from the given data
62          * @param inTrackInfo TrackInfo object
63          */
64         public void init(TrackInfo inTrackInfo)
65         {
66                 // Get whether track has track points, waypoints, photos
67                 boolean[] flags = {inTrackInfo.getTrack().hasTrackPoints(),
68                                 inTrackInfo.getTrack().hasWaypoints(),
69                                 inTrackInfo.getPhotoList().getNumPhotos() > 0
70                 };
71                 // Enable or disable checkboxes according to data present
72                 for (int i=0; i<3; i++)
73                 {
74                         if (flags[i]) {
75                                 _checkboxes[i].setEnabled(true);
76                         }
77                         else {
78                                 _checkboxes[i].setSelected(false);
79                                 _checkboxes[i].setEnabled(false);
80                         }
81                 }
82                 _checkboxes[3].setEnabled(inTrackInfo.getSelection().hasRangeSelected());
83                 _checkboxes[3].setSelected(false);
84         }
85
86         /**
87          * @return true if trackpoints selected
88          */
89         public boolean getTrackpointsSelected()
90         {
91                 return _checkboxes[0].isSelected();
92         }
93
94         /**
95          * @return true if waypoints selected
96          */
97         public boolean getWaypointsSelected()
98         {
99                 return _checkboxes[1].isSelected();
100         }
101
102         /**
103          * @return true if photo points selected
104          */
105         public boolean getPhotopointsSelected()
106         {
107                 return _checkboxes[2].isSelected();
108         }
109
110         /**
111          * @return true if only the current selection should be saved
112          */
113         public boolean getJustSelection()
114         {
115                 return _checkboxes[3].isSelected();
116         }
117
118         /**
119          * @return true if at least one type selected
120          */
121         public boolean getAnythingSelected()
122         {
123                 return getTrackpointsSelected() || getWaypointsSelected()
124                         || getPhotopointsSelected();
125         }
126 }