04f35de3b069d30a58b0b794479629f9fbe66dea
[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.Action;
8 import javax.swing.BorderFactory;
9 import javax.swing.JButton;
10 import javax.swing.JCheckBox;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JTextField;
14
15 import com.jgoodies.forms.builder.DefaultFormBuilder;
16 import com.jgoodies.forms.layout.FormLayout;
17
18 public class ExternalTab extends JPanel implements PrefsTab {
19
20         JabRefPreferences _prefs;
21
22         JabRefFrame _frame;
23
24         // private JComboBox language = new
25         // JComboBox(GUIGlobals.LANGUAGES.keySet().toArray());
26         JTextField pdfDir, regExpTextField, psDir, pdf, ps, html, lyx, winEdt, citeCommand;
27
28         ItemListener regExpListener;
29
30         JCheckBox useRegExpComboBox;
31
32         public ExternalTab(JabRefFrame frame, JabRefPreferences prefs, HelpDialog helpDialog) {
33                 _prefs = prefs;
34                 _frame = frame;
35                 setLayout(new BorderLayout());
36
37                 psDir = new JTextField(30);
38                 pdfDir = 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                 citeCommand = new JTextField(30);
45
46                 regExpTextField = new JTextField(30);
47
48                 useRegExpComboBox = new JCheckBox(Globals.lang("Use Regular Expression Search"));
49                 regExpListener = new ItemListener() {
50                         public void itemStateChanged(ItemEvent e) {
51                                 regExpTextField.setEditable(useRegExpComboBox.isSelected());
52                                 if (useRegExpComboBox.isSelected()) {
53                                         regExpTextField.setText(Globals.prefs
54                                                 .get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY));
55                                 } else {
56                                         Globals.prefs.put(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY,
57                                                 regExpTextField.getText());
58                                         regExpTextField.setText(Globals.prefs
59                                                 .get(JabRefPreferences.DEFAULT_REG_EXP_SEARCH_EXPRESSION_KEY));
60                                 }
61                         }
62                 };
63                 useRegExpComboBox.addItemListener(regExpListener);
64
65                 BrowseAction browse;
66
67                 FormLayout layout = new FormLayout(
68                         "1dlu, 8dlu, left:pref, 4dlu, fill:200dlu, 4dlu, fill:pref",// 4dlu,
69                                                                                                                                                 // left:pref,
70                                                                                                                                                 // 4dlu",
71                         "");
72
73                 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
74
75                 builder.appendSeparator(Globals.lang("PDF and PS links"));
76                 JPanel pan = new JPanel();
77                 builder.append(pan);
78                 JLabel lab = new JLabel(Globals.lang("Main PDF directory") + ":");
79                 builder.append(lab);
80                 builder.append(pdfDir);
81                 browse = new BrowseAction(_frame, pdfDir, true);
82                 builder.append(new JButton(browse));
83                 builder.nextLine();
84
85                 pan = new JPanel();
86                 builder.append(pan);
87                 lab = new JLabel(Globals.lang("Main PS directory") + ":");
88                 builder.append(lab);
89                 builder.append(psDir);
90                 browse = new BrowseAction(_frame, psDir, true);
91                 builder.append(new JButton(browse));
92                 builder.nextLine();
93
94                 builder.append(new JPanel());
95                 builder.append(useRegExpComboBox);
96                 builder.append(regExpTextField);
97                 HelpAction helpAction = new HelpAction(helpDialog, GUIGlobals.regularExpressionSearchHelp,
98                         Globals.lang("Help on Regular Expression Search"), GUIGlobals.getIconUrl("helpSmall"));
99                 builder.append(helpAction.getIconButton());
100                 builder.nextLine();
101
102                 builder.appendSeparator(Globals.lang("External programs"));
103
104                 builder.nextLine();
105                 lab = new JLabel(Globals.lang("Path to PDF viewer") + ":");
106                 builder.append(pan);
107                 builder.append(lab);
108                 builder.append(pdf);
109                 browse = new BrowseAction(_frame, pdf, false);
110                 if (Globals.ON_WIN)
111                         browse.setEnabled(false);
112                 builder.append(new JButton(browse));
113                 builder.nextLine();
114                 lab = new JLabel(Globals.lang("Path to PS viewer") + ":");
115                 builder.append(pan);
116                 builder.append(lab);
117                 builder.append(ps);
118                 browse = new BrowseAction(_frame, ps, false);
119                 if (Globals.ON_WIN)
120                         browse.setEnabled(false);
121                 builder.append(new JButton(browse));
122                 builder.nextLine();
123                 lab = new JLabel(Globals.lang("Path to HTML viewer") + ":");
124                 builder.append(pan);
125                 builder.append(lab);
126                 builder.append(html);
127                 browse = new BrowseAction(_frame, html, false);
128                 if (Globals.ON_WIN)
129                         browse.setEnabled(false);
130                 builder.append(new JButton(browse));
131                 builder.nextLine();
132                 lab = new JLabel(Globals.lang("Path to LyX pipe") + ":");
133                 builder.append(pan);
134                 builder.append(lab);
135                 builder.append(lyx);
136                 browse = new BrowseAction(_frame, lyx, false);
137                 builder.append(new JButton(browse));
138                 builder.nextLine();
139                 lab = new JLabel(Globals.lang("Path to WinEdt.exe") + ":");
140                 builder.append(pan);
141                 builder.append(lab);
142                 builder.append(winEdt);
143                 browse = new BrowseAction(_frame, winEdt, false);
144                 builder.append(new JButton(browse));
145                 builder.nextLine();
146                 builder.append(pan);
147                 builder.append(Globals.lang("Cite command (for Emacs/WinEdt)") + ":");
148                 builder.append(citeCommand);
149                 // builder.appendSeparator();
150
151                 pan = builder.getPanel();
152                 pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
153                 add(pan, BorderLayout.CENTER);
154         }
155
156         public void setValues() {
157                 pdfDir.setText(_prefs.get("pdfDirectory"));
158                 psDir.setText(_prefs.get("psDirectory"));
159                 if (!Globals.ON_WIN) {
160                         pdf.setText(_prefs.get("pdfviewer"));
161                         ps.setText(_prefs.get("psviewer"));
162                         html.setText(_prefs.get("htmlviewer"));
163                 } else {
164                         pdf.setText(Globals.lang("Uses default application"));
165                         ps.setText(Globals.lang("Uses default application"));
166                         html.setText(Globals.lang("Uses default application"));
167                         pdf.setEnabled(false);
168                         ps.setEnabled(false);
169                         html.setEnabled(false);
170                 }
171
172                 lyx.setText(_prefs.get("lyxpipe"));
173                 winEdt.setText(_prefs.get("winEdtPath"));
174                 citeCommand.setText(_prefs.get("citeCommand"));
175
176                 regExpTextField.setText(_prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY));
177                 useRegExpComboBox.setSelected(_prefs.getBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY));
178                 regExpListener.itemStateChanged(null);
179         }
180
181         public void storeSettings() {
182
183                 _prefs.putBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY, useRegExpComboBox.isSelected());
184                 if (useRegExpComboBox.isSelected()) {
185                         _prefs.put(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY, regExpTextField.getText());
186                 }
187
188                 // We should maybe do some checking on the validity of the contents?
189                 _prefs.put("pdfDirectory", pdfDir.getText());
190                 _prefs.put("psDirectory", psDir.getText());
191                 _prefs.put("pdfviewer", pdf.getText());
192                 _prefs.put("psviewer", ps.getText());
193                 _prefs.put("htmlviewer", html.getText());
194                 _prefs.put("lyxpipe", lyx.getText());
195                 _prefs.put("winEdtPath", winEdt.getText());
196                 _prefs.put("citeCommand", citeCommand.getText());
197         }
198
199         public boolean readyToClose() {
200                 return true;
201         }
202
203 }