1 package tim.prune.function;
3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.awt.GridLayout;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
9 import javax.swing.BorderFactory;
10 import javax.swing.JButton;
11 import javax.swing.JDialog;
12 import javax.swing.JLabel;
13 import javax.swing.JPanel;
14 import javax.swing.JTextField;
15 import javax.swing.SwingConstants;
18 import tim.prune.ExternalTools;
19 import tim.prune.GenericFunction;
20 import tim.prune.I18nManager;
21 import tim.prune.config.Config;
24 * Function to set the paths for the external programs (eg gnuplot)
26 public class SetPathsFunction extends GenericFunction
28 /** dialog object, cached */
29 private JDialog _dialog = null;
31 private JTextField[] _editFields = null;
33 private JLabel[] _installedLabels = null;
35 private static final String[] CONFIG_KEYS = {Config.KEY_GPSBABEL_PATH, Config.KEY_GNUPLOT_PATH, Config.KEY_EXIFTOOL_PATH};
37 private static final String[] LABEL_KEYS = {"gpsbabel", "gnuplot", "exiftool"};
38 /** Number of entries */
39 private static final int NUM_KEYS = CONFIG_KEYS.length;
42 * Constructor from superclass
43 * @param inApp app object
45 public SetPathsFunction(App inApp)
51 * @return key for function name
53 public String getNameKey()
55 return "function.setpaths";
66 _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
67 _dialog.setLocationRelativeTo(_parentFrame);
68 _dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
69 _dialog.getContentPane().add(makeDialogComponents());
74 _dialog.setVisible(true);
79 * Make the dialog components
80 * @return panel containing gui elements
82 private JPanel makeDialogComponents()
84 JPanel dialogPanel = new JPanel();
85 dialogPanel.setLayout(new BorderLayout());
86 dialogPanel.add(new JLabel(I18nManager.getText("dialog.setpaths.intro")), BorderLayout.NORTH);
88 // Main panel with edit boxes for paths
89 JPanel mainPanel = new JPanel();
90 mainPanel.setLayout(new GridLayout(NUM_KEYS+1, 3, 10, 1));
91 mainPanel.add(new JLabel(" "));
92 mainPanel.add(new JLabel(" "));
93 mainPanel.add(new JLabel(I18nManager.getText("dialog.setpaths.found")));
94 _editFields = new JTextField[NUM_KEYS];
95 _installedLabels = new JLabel[NUM_KEYS];
96 for (int i=0; i<NUM_KEYS; i++)
98 JLabel label = new JLabel(I18nManager.getText("dialog.saveconfig.prune." + LABEL_KEYS[i] + "path"));
99 label.setHorizontalAlignment(SwingConstants.RIGHT);
100 mainPanel.add(label);
101 String configVal = Config.getConfigString(CONFIG_KEYS[i]);
102 if (configVal == null) {configVal = "";}
103 _editFields[i] = new JTextField(configVal);
104 mainPanel.add(_editFields[i]);
105 _installedLabels[i] = new JLabel("...");
106 mainPanel.add(_installedLabels[i]);
108 dialogPanel.add(mainPanel, BorderLayout.CENTER);
110 // button panel at bottom
111 JPanel buttonPanel = new JPanel();
112 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
113 JButton checkButton = new JButton(I18nManager.getText("button.check"));
114 checkButton.addActionListener(new ActionListener() {
115 public void actionPerformed(ActionEvent e)
120 buttonPanel.add(checkButton);
121 JButton okButton = new JButton(I18nManager.getText("button.ok"));
122 ActionListener okListener = new ActionListener() {
123 public void actionPerformed(ActionEvent e)
128 okButton.addActionListener(okListener);
129 buttonPanel.add(okButton);
130 JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
131 cancelButton.addActionListener(new ActionListener() {
132 public void actionPerformed(ActionEvent e)
137 buttonPanel.add(cancelButton);
138 dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
139 dialogPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 15));
144 * Check all the programs to see if they're installed
146 private void checkPaths()
148 String yesText = I18nManager.getText("dialog.about.yes");
149 String noText = I18nManager.getText("dialog.about.no");
150 for (int i=0; i<NUM_KEYS; i++)
152 String command = _editFields[i].getText();
153 _installedLabels[i].setText(" " + (ExternalTools.isToolInstalled(i, command)?yesText:noText));
158 * Set the given paths in the configuration and exit
160 private void finish()
162 for (int i=0; i<NUM_KEYS; i++)
164 String val = _editFields[i].getText();
165 // TODO: Check path values?
166 Config.setConfigString(CONFIG_KEYS[i], val);