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(3, 3, 10, 1));
91 _editFields = new JTextField[NUM_KEYS];
92 _installedLabels = new JLabel[NUM_KEYS];
93 for (int i=0; i<NUM_KEYS; i++)
95 JLabel label = new JLabel(I18nManager.getText("dialog.saveconfig.prune." + LABEL_KEYS[i] + "path"));
96 label.setHorizontalAlignment(SwingConstants.RIGHT);
98 String configVal = Config.getConfigString(CONFIG_KEYS[i]);
99 if (configVal == null) {configVal = "";}
100 _editFields[i] = new JTextField(configVal);
101 mainPanel.add(_editFields[i]);
102 _installedLabels[i] = new JLabel("...");
103 mainPanel.add(_installedLabels[i]);
105 dialogPanel.add(mainPanel, BorderLayout.CENTER);
107 // button panel at bottom
108 JPanel buttonPanel = new JPanel();
109 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
110 JButton checkButton = new JButton(I18nManager.getText("button.check"));
111 checkButton.addActionListener(new ActionListener() {
112 public void actionPerformed(ActionEvent e)
117 buttonPanel.add(checkButton);
118 JButton okButton = new JButton(I18nManager.getText("button.ok"));
119 ActionListener okListener = new ActionListener() {
120 public void actionPerformed(ActionEvent e)
125 okButton.addActionListener(okListener);
126 buttonPanel.add(okButton);
127 JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
128 cancelButton.addActionListener(new ActionListener() {
129 public void actionPerformed(ActionEvent e)
134 buttonPanel.add(cancelButton);
135 dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
136 dialogPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 15));
141 * Check all the programs to see if they're installed
143 private void checkPaths()
145 String yesText = I18nManager.getText("dialog.about.yes");
146 String noText = I18nManager.getText("dialog.about.no");
147 for (int i=0; i<NUM_KEYS; i++)
149 String command = _editFields[i].getText();
150 _installedLabels[i].setText(ExternalTools.isToolInstalled(i, command)?yesText:noText);
155 * Set the given paths in the configuration and exit
157 private void finish()
159 for (int i=0; i<NUM_KEYS; i++)
161 String val = _editFields[i].getText();
162 // TODO: Check path values?
163 Config.setConfigString(CONFIG_KEYS[i], val);