File: RecentFileTrigger.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 (62 lines) | stat: -rw-r--r-- 1,413 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
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.config.Config;
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 App _app = null;
	private int _index = 0;


	/**
	 * 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 = Config.getRecentFileList().getFile(_index);
		if (rf != null && rf.isValid())
		{
			if (rf.isRegularLoad())
			{
				// Trigger a regular file load
				ArrayList<File> dataFiles = new ArrayList<File>();
				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");
			Config.getRecentFileList().verifyAll(); // Called on a file which no longer exists
			UpdateMessageBroker.informSubscribers();
		}
	}
}