File: RecentFileTrigger.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (61 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download | duplicates (4)
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
package tim.prune.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;

import tim.prune.App;
import tim.prune.UpdateMessageBroker;
import tim.prune.data.RecentFile;
import tim.prune.load.BabelLoadFromFile;

/**
 * Class to act as a trigger when a menu item for a recent file is clicked
 */
public class RecentFileTrigger implements ActionListener
{
	private final App _app;
	private final int _index;


	/**
	 * Constructor
	 * @param inApp App object
	 * @param inIndex menu index from 0
	 */
	public RecentFileTrigger(App inApp, int inIndex)
	{
		_app = inApp;
		_index = inIndex;
	}

	/**
	 * React to click on menu item
	 */
	public void actionPerformed(ActionEvent arg0)
	{
		RecentFile rf = _app.getConfig().getRecentFileList().getFile(_index);
		if (rf != null && rf.isValid())
		{
			if (rf.isRegularLoad())
			{
				// Trigger a regular file load
				ArrayList<File> dataFiles = new ArrayList<>();
				dataFiles.add(rf.getFile());
				_app.loadDataFiles(dataFiles);
			}
			else
			{
				// Trigger a load via gpsbabel
				new BabelLoadFromFile(_app).beginWithFile(rf.getFile());
			}
		}
		else
		{
			_app.showErrorMessage("function.open", "error.load.noread");
			_app.getConfig().getRecentFileList().verifyAll(); // Called on a file which no longer exists
			UpdateMessageBroker.informSubscribers();
		}
	}
}