File: PointTypeSelector.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (144 lines) | stat: -rw-r--r-- 3,734 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package tim.prune.save;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import tim.prune.I18nManager;
import tim.prune.data.TrackInfo;

/**
 * GUI element to allow the selection of point types for saving,
 * including checkboxes for track points, waypoints, photo points, audio points
 * and also a checkbox for the current selection
 */
public class PointTypeSelector extends JPanel
{
	/** Array of checkboxes */
	private JCheckBox[] _checkboxes = new JCheckBox[5];
	/** Grid panel for top row */
	private JPanel _gridPanel = null;


	/**
	 * Constructor
	 */
	public PointTypeSelector()
	{
		createComponents();
		setBorder(BorderFactory.createCompoundBorder(
			BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(4, 4, 4, 4))
		);
	}

	/**
	 * Create the GUI components
	 */
	private void createComponents()
	{
		setLayout(new BorderLayout());
		add(new JLabel(I18nManager.getText("dialog.pointtype.desc")), BorderLayout.NORTH);
		// panel for the checkboxes
		_gridPanel = new JPanel();
		_gridPanel.setLayout(new GridLayout(0, 3, 15, 3));
		final String[] keys = {"track", "waypoint", "photo", "audio"};
		for (int i=0; i<4; i++)
		{
			_checkboxes[i] = new JCheckBox(I18nManager.getText("dialog.pointtype." + keys[i]));
			_checkboxes[i].setSelected(true);
			if (i<3) {_gridPanel.add(_checkboxes[i]);}
		}
		add(_gridPanel, BorderLayout.CENTER);
		_checkboxes[4] = new JCheckBox(I18nManager.getText("dialog.pointtype.selection"));
		add(_checkboxes[4], BorderLayout.SOUTH);
	}


	/**
	 * Initialize the checkboxes from the given data
	 * @param inTrackInfo TrackInfo object
	 */
	public void init(TrackInfo inTrackInfo)
	{
		// Get whether track has track points, waypoints, photos
		boolean[] dataFlags = {inTrackInfo.getTrack().hasTrackPoints(),
				inTrackInfo.getTrack().hasWaypoints(),
				inTrackInfo.getPhotoList().getNumPhotos() > 0,
				inTrackInfo.getAudioList().getNumAudios() > 0
		};
		// Rearrange grid to just show the appropriate entries
		final boolean[] showFlags = {true, true, dataFlags[2] || !dataFlags[3], dataFlags[3]};
		_gridPanel.removeAll();
		for (int i=0; i<4; i++) {
			if (showFlags[i]) {_gridPanel.add(_checkboxes[i]);}
		}
		// Enable or disable checkboxes according to data present
		for (int i=0; i<4; i++)
		{
			if (dataFlags[i]) {
				if (!_checkboxes[i].isEnabled()) {_checkboxes[i].setSelected(true);}
				_checkboxes[i].setEnabled(true);
			}
			else {
				_checkboxes[i].setSelected(false);
				_checkboxes[i].setEnabled(false);
			}
		}
		_checkboxes[4].setEnabled(inTrackInfo.getSelection().hasRangeSelected());
		_checkboxes[4].setSelected(false);
	}

	/**
	 * @return true if trackpoints selected
	 */
	public boolean getTrackpointsSelected()
	{
		return _checkboxes[0].isSelected();
	}

	/**
	 * @return true if waypoints selected
	 */
	public boolean getWaypointsSelected()
	{
		return _checkboxes[1].isSelected();
	}

	/**
	 * @return true if photo points selected
	 */
	public boolean getPhotopointsSelected()
	{
		return _checkboxes[2].isSelected();
	}

	/**
	 * @return true if audio points selected
	 */
	public boolean getAudiopointsSelected()
	{
		return _checkboxes[3].isSelected();
	}

	/**
	 * @return true if only the current selection should be saved
	 */
	public boolean getJustSelection()
	{
		return _checkboxes[4].isSelected();
	}

	/**
	 * @return true if at least one type selected
	 */
	public boolean getAnythingSelected()
	{
		return getTrackpointsSelected() || getWaypointsSelected()
			|| getPhotopointsSelected() || getAudiopointsSelected();
	}
}