bd932b3c630103272b1619e56931702190cf285b
[debian/jabref.git] / src / java / net / sf / jabref / ExternalProgramsTab.java
1 package net.sf.jabref;
2
3 import javax.swing.*;
4 import javax.swing.table.*;
5 import java.awt.*;
6 import java.awt.event.*;
7 import java.io.File;
8
9 class ExternalProgramsTab extends JPanel implements PrefsTab {
10
11     JabRefPreferences _prefs;
12     private GridBagLayout gbl = new GridBagLayout();
13     private GridBagConstraints con = new GridBagConstraints();
14     JTextField
15         pdf, ps, html, lyx;
16
17     public ExternalProgramsTab (JabRefPreferences prefs) {
18         _prefs = prefs;
19
20         pdf = new JTextField(_prefs.get("pdfviewer"), 30);
21         ps = new JTextField(_prefs.get("psviewer"), 30);
22         html = new JTextField(_prefs.get("htmlviewer"), 30);
23         lyx = new JTextField(_prefs.get("lyxpipe"), 30);
24
25         /*setBorder(BorderFactory.createTitledBorder
26                   (BorderFactory.createEtchedBorder(),
27                   Globals.lang("Paths to external programs")));*/
28         JLabel lab;
29         setLayout(gbl);
30         con.weightx = 0;
31         con.insets = new Insets(10, 10, 10, 10);
32         con.fill = GridBagConstraints.HORIZONTAL;
33         lab = new JLabel(Globals.lang("Path to PDF viewer")+":");
34         gbl.setConstraints(lab, con);
35         add(lab);
36         con.weightx = 1;
37         gbl.setConstraints(pdf, con);
38         add(pdf);
39         con.weightx = 0;
40         con.gridwidth = GridBagConstraints.REMAINDER;
41         JButton browse = new JButton(Globals.lang("Browse"));
42         browse.addActionListener(new BrowseAction(pdf));
43         gbl.setConstraints(browse, con);
44         add(browse);
45         con.gridwidth = 1;
46         con.fill = GridBagConstraints.HORIZONTAL;
47         lab = new JLabel(Globals.lang("Path to PS viewer")+":");
48         gbl.setConstraints(lab, con);
49         add(lab);
50         con.weightx = 1;
51         gbl.setConstraints(ps, con);
52         add(ps);
53         con.weightx = 0;
54         con.gridwidth = GridBagConstraints.REMAINDER;
55         browse = new JButton(Globals.lang("Browse"));
56         browse.addActionListener(new BrowseAction(ps));
57         gbl.setConstraints(browse, con);
58         add(browse);
59         con.gridwidth = 1;
60         lab = new JLabel(Globals.lang("Path to HTML viewer")+":");
61         gbl.setConstraints(lab, con);
62         add(lab);
63         con.weightx = 1;
64         gbl.setConstraints(html, con);
65         add(html);
66         con.gridwidth = GridBagConstraints.REMAINDER;
67         con.weightx = 0;
68         browse = new JButton(Globals.lang("Browse"));
69         browse.addActionListener(new BrowseAction(html));
70         gbl.setConstraints(browse, con);
71         add(browse);
72         con.gridwidth = 1;
73         con.fill = GridBagConstraints.HORIZONTAL;
74         lab = new JLabel(Globals.lang("Path to LyX pipe")+":");
75         gbl.setConstraints(lab, con);
76         add(lab);
77         con.weightx = 1;
78         gbl.setConstraints(lyx, con);
79         add(lyx);
80         con.weightx = 0;
81         browse = new JButton(Globals.lang("Browse"));
82         browse.addActionListener(new BrowseAction(lyx));
83         gbl.setConstraints(browse, con);
84         add(browse);
85
86     }
87
88   /**
89    * Action used to produce a "Browse" button for one of the text fields.
90    */
91   class BrowseAction extends AbstractAction {
92       JTextField comp;
93       public BrowseAction(JTextField tc) {
94         super(Globals.lang("Browse"));
95         comp = tc;
96       }
97       public void actionPerformed(ActionEvent e) {
98         JabRefFileChooser chooser = new JabRefFileChooser(new File(comp.getText()));
99         //chooser.addChoosableFileFilter(new OpenFileFilter()); //nb nov2
100         int returnVal = chooser.showOpenDialog(null);
101         if (returnVal == JFileChooser.APPROVE_OPTION) {
102           File newFile = chooser.getSelectedFile();
103           comp.setText(newFile.getPath());
104         }
105       }
106     }
107
108     public void setValues() {
109
110     }
111
112     /**
113      * Store changes to table preferences. This method is called when
114      * the user clicks Ok.
115      *
116      */
117     public void storeSettings() {
118
119         // We should maybe do some checking on the validity of the contents?
120
121         _prefs.put("pdfviewer", pdf.getText());
122         _prefs.put("psviewer", ps.getText());
123         _prefs.put("htmlviewer", html.getText());
124         _prefs.put("lyxpipe", lyx.getText());
125     }
126
127     public boolean readyToClose() {
128         return true;
129     }
130
131 }
132
133
134