a544ad5fe38e02b82a5e5ce41aee77d4c30450eb
[debian/jabref.git] / src / java / net / sf / jabref / ExternalTab.java
1 package net.sf.jabref;
2
3 import java.awt.BorderLayout;
4 import java.awt.event.ItemEvent;
5 import java.awt.event.ItemListener;
6
7 import javax.swing.*;
8
9 import net.sf.jabref.external.ExternalFileTypeEditor;
10
11 import com.jgoodies.forms.builder.DefaultFormBuilder;
12 import com.jgoodies.forms.layout.FormLayout;
13
14 public class ExternalTab extends JPanel implements PrefsTab {
15
16         JabRefPreferences _prefs;
17
18         JabRefFrame _frame;
19
20         JTextField pdfDir, regExpTextField, fileDir, psDir, pdf, ps, html, lyx, winEdt, led,
21         citeCommand, vim, vimServer;
22
23     JButton editFileTypes;
24     ItemListener regExpListener;
25
26         JCheckBox useRegExpComboBox;
27     JRadioButton matchExactKeyOnly = new JRadioButton(Globals.lang("Autolink only files that match the BibTeX key")),
28         matchStartsWithKey = new JRadioButton(Globals.lang("Autolink files with names starting with the BibTeX key"));
29
30     public ExternalTab(JabRefFrame frame, PrefsDialog3 prefsDiag, JabRefPreferences prefs,
31                        HelpDialog helpDialog) {
32                 _prefs = prefs;
33                 _frame = frame;
34                 setLayout(new BorderLayout());
35
36                 psDir = new JTextField(30);
37                 pdfDir = new JTextField(30);
38         fileDir = new JTextField(30);
39         pdf = new JTextField(30);
40                 ps = new JTextField(30);
41                 html = new JTextField(30);
42                 lyx = new JTextField(30);
43                 winEdt = new JTextField(30);
44                 vim = new JTextField(30);
45                 vimServer = new JTextField(30);
46         citeCommand = new JTextField(30);
47         led = new JTextField(30);
48         editFileTypes = new JButton(Globals.lang("Manage external file types"));
49
50         regExpTextField = new JTextField(30);
51         useRegExpComboBox = new JCheckBox(Globals.lang("Use Regular Expression Search"));
52                 regExpListener = new ItemListener() {
53                         public void itemStateChanged(ItemEvent e) {
54                                 regExpTextField.setEditable(useRegExpComboBox.isSelected());
55                                 if (useRegExpComboBox.isSelected()) {
56                                         regExpTextField.setText(Globals.prefs
57                                                 .get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY));
58                                 } else {
59                                         Globals.prefs.put(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY,
60                                                 regExpTextField.getText());
61                                         regExpTextField.setText(Globals.prefs
62                                                 .get(JabRefPreferences.DEFAULT_REG_EXP_SEARCH_EXPRESSION_KEY));
63                                 }
64                         }
65                 };
66                 useRegExpComboBox.addItemListener(regExpListener);
67
68         editFileTypes.addActionListener(ExternalFileTypeEditor.getAction(prefsDiag));
69
70         ButtonGroup bg = new ButtonGroup();
71         bg.add(matchExactKeyOnly);
72         bg.add(matchStartsWithKey);
73
74         BrowseAction browse;
75
76                 FormLayout layout = new FormLayout(
77                         "1dlu, 8dlu, left:pref, 4dlu, fill:170dlu, 4dlu, fill:pref","");
78
79                 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
80
81                 builder.appendSeparator(Globals.lang("External file links"));
82                 JPanel pan = new JPanel();
83                 builder.append(pan);
84                 /**
85                  * Fix for [ 1749613 ] About translation
86                  * 
87                  * https://sourceforge.net/tracker/index.php?func=detail&aid=1749613&group_id=92314&atid=600306
88                  * 
89                  * Cannot really use %0 to refer to the file type, since this ruins translation.
90                  */
91                 JLabel lab = new JLabel(Globals.lang("Main file directory") + ":");
92                 builder.append(lab);
93                 builder.append(fileDir);
94                 browse = new BrowseAction(_frame, fileDir, true);
95                 builder.append(new JButton(browse));
96                 builder.nextLine();
97
98         pan = new JPanel();
99                 builder.append(pan);
100                 lab = new JLabel(Globals.lang("Main PDF directory") + ":");
101                 builder.append(lab);
102                 builder.append(pdfDir);
103                 browse = new BrowseAction(_frame, pdfDir, true);
104                 builder.append(new JButton(browse));
105                 builder.nextLine();
106
107         pan = new JPanel();
108                 builder.append(pan);
109                 lab = new JLabel(Globals.lang("Main PS directory") + ":");
110                 builder.append(lab);
111                 builder.append(psDir);
112                 browse = new BrowseAction(_frame, psDir, true);
113                 builder.append(new JButton(browse));
114                 builder.nextLine();
115
116                 builder.append(new JPanel());
117         builder.append(matchStartsWithKey, 3);
118         builder.nextLine();
119         builder.append(new JPanel());
120         builder.append(matchExactKeyOnly, 3);
121         //builder.append(useRegExpComboBox);
122                 //builder.append(regExpTextField);
123                 /*HelpAction helpAction = new HelpAction(helpDialog, GUIGlobals.regularExpressionSearchHelp,
124                         Globals.lang("Help on Regular Expression Search"), GUIGlobals.getIconUrl("helpSmall"));
125                 builder.append(helpAction.getIconButton());*/
126                 builder.nextLine();
127
128                 builder.appendSeparator(Globals.lang("External programs"));
129
130                 /*builder.nextLine();
131                 lab = new JLabel(Globals.lang("Path to PDF viewer") + ":");
132                 builder.append(pan);
133                 builder.append(lab);
134                 builder.append(pdf);
135                 browse = new BrowseAction(_frame, pdf, false);
136                 if (Globals.ON_WIN)
137                         browse.setEnabled(false);
138                 builder.append(new JButton(browse));
139                 builder.nextLine();
140                 lab = new JLabel(Globals.lang("Path to PS viewer") + ":");
141                 builder.append(pan);
142                 builder.append(lab);
143                 builder.append(ps);
144                 browse = new BrowseAction(_frame, ps, false);
145                 if (Globals.ON_WIN)
146                         browse.setEnabled(false);
147                 builder.append(new JButton(browse));
148                 */
149                 builder.nextLine();
150                 lab = new JLabel(Globals.lang("Path to HTML viewer") + ":");
151                 builder.append(pan);
152                 builder.append(lab);
153                 builder.append(html);
154                 browse = new BrowseAction(_frame, html, false);
155                 if (Globals.ON_WIN)
156                         browse.setEnabled(false);
157                 builder.append(new JButton(browse));
158                 builder.nextLine();
159                 lab = new JLabel(Globals.lang("Path to LyX pipe") + ":");
160                 builder.append(pan);
161                 builder.append(lab);
162                 builder.append(lyx);
163                 browse = new BrowseAction(_frame, lyx, false);
164                 builder.append(new JButton(browse));
165                 builder.nextLine();
166                 lab = new JLabel(Globals.lang("Path to WinEdt.exe") + ":");
167                 builder.append(pan);
168                 builder.append(lab);
169                 builder.append(winEdt);
170                 browse = new BrowseAction(_frame, winEdt, false);
171                 builder.append(new JButton(browse));
172                 builder.nextLine();
173         lab = new JLabel(Globals.lang("Path to LatexEditor (LEd.exe)") + ":");
174         builder.append(pan);
175         builder.append(lab);
176         builder.append(led);
177         browse = new BrowseAction(_frame, led, false);
178         builder.append(new JButton(browse));
179         builder.nextLine();
180         builder.append(pan);
181         lab = new JLabel(Globals.lang("Path to Vim") + ":");
182                 builder.append(lab);
183                 builder.append(vim);
184                 browse = new BrowseAction(_frame, vim, false);
185                 builder.append(new JButton(browse));
186                 builder.nextLine();
187                 lab = new JLabel(Globals.lang("Vim Server Name") + ":");
188                 builder.append(pan);
189                 builder.append(lab);
190                 builder.append(vimServer);
191                 browse = new BrowseAction(_frame, vimServer, false);
192                 builder.append(new JButton(browse));
193                 builder.nextLine();
194         builder.append(pan);
195
196                 builder.append(Globals.lang("Cite command (for Emacs/WinEdt)") + ":");
197                 builder.append(citeCommand);
198                 // builder.appendSeparator();
199
200         builder.nextLine();
201         builder.append(pan);
202         builder.append(editFileTypes);
203         
204         pan = builder.getPanel();
205                 pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
206                 add(pan, BorderLayout.CENTER);
207
208     }
209
210         public void setValues() {
211                 pdfDir.setText(_prefs.get("pdfDirectory"));
212                 psDir.setText(_prefs.get("psDirectory"));
213         fileDir.setText(_prefs.get(GUIGlobals.FILE_FIELD+"Directory"));
214         if (!Globals.ON_WIN) {
215                         pdf.setText(_prefs.get("pdfviewer"));
216                         ps.setText(_prefs.get("psviewer"));
217                         html.setText(_prefs.get("htmlviewer"));
218                 } else {
219                         pdf.setText(Globals.lang("Uses default application"));
220                         ps.setText(Globals.lang("Uses default application"));
221                         html.setText(Globals.lang("Uses default application"));
222                         pdf.setEnabled(false);
223                         ps.setEnabled(false);
224                         html.setEnabled(false);
225                 }
226
227                 lyx.setText(_prefs.get("lyxpipe"));
228                 winEdt.setText(_prefs.get("winEdtPath"));
229         vim.setText(_prefs.get("vim"));
230                 vimServer.setText(_prefs.get("vimServer"));
231         led.setText(_prefs.get("latexEditorPath"));
232         citeCommand.setText(_prefs.get("citeCommand"));
233
234                 regExpTextField.setText(_prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY));
235                 useRegExpComboBox.setSelected(_prefs.getBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY));
236                 regExpListener.itemStateChanged(null);
237
238         if (_prefs.getBoolean("autolinkExactKeyOnly"))
239             matchExactKeyOnly.setSelected(true);
240         else
241             matchStartsWithKey.setSelected(true);
242     }
243
244         public void storeSettings() {
245
246                 _prefs.putBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY, useRegExpComboBox.isSelected());
247                 if (useRegExpComboBox.isSelected()) {
248                         _prefs.put(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY, regExpTextField.getText());
249                 }
250
251                 // We should maybe do some checking on the validity of the contents?
252                 _prefs.put("pdfDirectory", pdfDir.getText());
253                 _prefs.put("psDirectory", psDir.getText());
254         _prefs.put(GUIGlobals.FILE_FIELD+"Directory", fileDir.getText());
255         _prefs.put("pdfviewer", pdf.getText());
256                 _prefs.put("psviewer", ps.getText());
257                 _prefs.put("htmlviewer", html.getText());
258                 _prefs.put("lyxpipe", lyx.getText());
259                 _prefs.put("winEdtPath", winEdt.getText());
260         _prefs.put("vim", vim.getText());
261         _prefs.put("vimServer", vimServer.getText());
262         _prefs.put("latexEditorPath", led.getText());
263         _prefs.put("citeCommand", citeCommand.getText());
264         _prefs.putBoolean("autolinkExactKeyOnly", matchExactKeyOnly.isSelected());
265     }
266
267         public boolean readyToClose() {
268                 return true;
269         }
270
271         public String getTabName() {
272                 return Globals.lang("External programs");
273         }
274 }