fc7b8967be91a145983554bb9cee9ea829dda31f
[debian/jabref.git] / src / java / net / sf / jabref / ExternalTab.java
1 package net.sf.jabref;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.Iterator;
7 import java.io.File;
8
9 import com.jgoodies.forms.layout.*;
10 import com.jgoodies.forms.factories.*;
11 import com.jgoodies.forms.builder.*;
12
13 public class ExternalTab extends JPanel implements PrefsTab {
14
15     JabRefPreferences _prefs;
16     JabRefFrame _frame;
17     //private JComboBox language = new JComboBox(GUIGlobals.LANGUAGES.keySet().toArray());
18     JTextField pdfDir, psDir, pdf, ps, html, lyx, winEdt, citeCommand;
19
20     //private HelpAction ownerHelp, pdfHelp;
21
22
23     public ExternalTab(JabRefFrame frame, JabRefPreferences prefs) {
24         _prefs = prefs;
25         _frame = frame;
26         setLayout(new BorderLayout());
27
28         //pdfHelp = new HelpAction(frame.helpDiag, GUIGlobals.pdfHelp,
29         //        "Help", GUIGlobals.helpSmallIconFile);
30
31         psDir = new JTextField(30);
32         pdfDir = new JTextField(30);
33         pdf = new JTextField(30);
34         ps = new JTextField(30);
35         html = new JTextField(30);
36         lyx = new JTextField(30);
37         winEdt = new JTextField(30);
38         citeCommand = new JTextField(30);
39         BrowseAction browse;
40
41         FormLayout layout = new FormLayout
42                 ("1dlu, 8dlu, left:pref, 4dlu, fill:200dlu, 4dlu, fill:pref",// 4dlu, left:pref, 4dlu",
43                         "");
44
45         DefaultFormBuilder builder = new DefaultFormBuilder(layout);
46
47         builder.appendSeparator(Globals.lang("PDF links"));
48         JPanel pan = new JPanel();
49         builder.append(pan);
50         JLabel lab = new JLabel(Globals.lang("Main PDF directory") + ":");
51         builder.append(lab);
52         builder.append(pdfDir);
53         browse = new BrowseAction(pdfDir, true);
54         builder.append(new JButton(browse));
55         builder.nextLine();
56         builder.appendSeparator(Globals.lang("PS links"));
57         pan = new JPanel();
58         builder.append(pan);
59         lab = new JLabel(Globals.lang("Main PS directory") + ":");
60         builder.append(lab);
61         builder.append(psDir);
62         browse = new BrowseAction(psDir, true);
63         builder.append(new JButton(browse));
64         builder.nextLine();
65         builder.appendSeparator(Globals.lang("External programs"));
66
67
68         builder.nextLine();
69         lab = new JLabel(Globals.lang("Path to PDF viewer") + ":");
70         builder.append(pan);
71         builder.append(lab);
72         builder.append(pdf);
73         browse = new BrowseAction(pdf, false);
74         if (Globals.ON_WIN)
75             browse.setEnabled(false);
76         builder.append(new JButton(browse));
77         builder.nextLine();
78         lab = new JLabel(Globals.lang("Path to PS viewer") + ":");
79         builder.append(pan);
80         builder.append(lab);
81         builder.append(ps);
82         browse = new BrowseAction(ps, false);
83         if (Globals.ON_WIN)
84             browse.setEnabled(false);
85         builder.append(new JButton(browse));
86         builder.nextLine();
87         lab = new JLabel(Globals.lang("Path to HTML viewer") + ":");
88         builder.append(pan);
89         builder.append(lab);
90         builder.append(html);
91         browse = new BrowseAction(html, false);
92         if (Globals.ON_WIN)
93             browse.setEnabled(false);
94         builder.append(new JButton(browse));
95         builder.nextLine();
96         lab = new JLabel(Globals.lang("Path to LyX pipe") + ":");
97         builder.append(pan);
98         builder.append(lab);
99         builder.append(lyx);
100         browse = new BrowseAction(lyx, false);
101         builder.append(new JButton(browse));
102         builder.nextLine();
103         lab = new JLabel(Globals.lang("Path to WinEdt.exe") + ":");
104         builder.append(pan);
105         builder.append(lab);
106         builder.append(winEdt);
107         browse = new BrowseAction(winEdt, false);
108         builder.append(new JButton(browse));
109         builder.nextLine();
110         builder.append(pan);
111         builder.append(Globals.lang("Cite command (for Emacs/WinEdt)")+":");
112         builder.append(citeCommand);
113         //builder.appendSeparator();
114
115         pan = builder.getPanel();
116         pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
117         add(pan, BorderLayout.CENTER);
118     }
119
120     /**
121      * Action used to produce a "Browse" button for one of the text fields.
122      */
123     class BrowseAction extends AbstractAction {
124         JTextField comp;
125         boolean dir;
126
127         public BrowseAction(JTextField tc, boolean dir) {
128             super(Globals.lang("Browse"));
129             this.dir = dir;
130             comp = tc;
131         }
132
133         public void actionPerformed(ActionEvent e) {
134             String chosen = null;
135             if (dir)
136                 chosen = Globals.getNewDir(_frame, _prefs, new File(comp.getText()), Globals.NONE,
137                         JFileChooser.OPEN_DIALOG, false);
138             else
139                 chosen = Globals.getNewFile(_frame, _prefs, new File(comp.getText()), Globals.NONE,
140                         JFileChooser.OPEN_DIALOG, false);
141             if (chosen != null) {
142                 File newFile = new File(chosen);
143                 comp.setText(newFile.getPath());
144             }
145         }
146     }
147
148     public void setValues() {
149         pdfDir.setText(_prefs.get("pdfDirectory"));
150         psDir.setText(_prefs.get("psDirectory"));
151         if (!Globals.ON_WIN) {
152             pdf.setText(_prefs.get("pdfviewer"));
153             ps.setText(_prefs.get("psviewer"));
154             html.setText(_prefs.get("htmlviewer"));
155         } else {
156             pdf.setText(Globals.lang("Uses default application"));
157             ps.setText(Globals.lang("Uses default application"));
158             html.setText(Globals.lang("Uses default application"));
159             pdf.setEnabled(false);
160             ps.setEnabled(false);
161             html.setEnabled(false);
162         }
163
164         lyx.setText(_prefs.get("lyxpipe"));
165         winEdt.setText(_prefs.get("winEdtPath"));
166         citeCommand.setText(_prefs.get("citeCommand"));
167     }
168
169     public void storeSettings() {
170
171         // We should maybe do some checking on the validity of the contents?
172         _prefs.put("pdfDirectory", pdfDir.getText());
173         _prefs.put("psDirectory", psDir.getText());
174         _prefs.put("pdfviewer", pdf.getText());
175         _prefs.put("psviewer", ps.getText());
176         _prefs.put("htmlviewer", html.getText());
177         _prefs.put("lyxpipe", lyx.getText());
178         _prefs.put("winEdtPath", winEdt.getText());
179         _prefs.put("citeCommand", citeCommand.getText());
180     }
181
182     public boolean readyToClose() {
183         return true;
184     }
185
186 }