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