3b4e6a2cfc94d2f9dcce47fa4bd7288f82f12bd6
[debian/jabref.git] / src / java / net / sf / jabref / AppearancePrefsTab.java
1 package net.sf.jabref;
2
3 import java.util.Vector;
4 import javax.swing.*;
5 import javax.swing.table.*;
6 import java.awt.*;
7 import java.awt.event.*;
8 import com.jgoodies.forms.layout.*;
9 import com.jgoodies.forms.factories.*;
10 import com.jgoodies.forms.builder.*;
11 import net.sf.jabref.gui.ColorSetupPanel;
12
13 class AppearancePrefsTab extends JPanel implements PrefsTab {
14
15     JabRefPreferences _prefs;
16     private JCheckBox colorCodes, antialias, overrideFonts;//, useCustomIconTheme;
17     private GridBagLayout gbl = new GridBagLayout();
18     private JButton fontButton = new JButton(Globals.lang("Set table font"));
19     private ColorSetupPanel colorPanel = new ColorSetupPanel();
20     private Font font = GUIGlobals.CURRENTFONT;
21     private int oldMenuFontSize;
22     private boolean oldOverrideFontSize;
23     private JTextField fontSize;//, customIconThemeFile;
24
25     /**
26      * Customization of appearance parameters.
27      *
28      * @param prefs a <code>JabRefPreferences</code> value
29      */
30     public AppearancePrefsTab(JabRefPreferences prefs) {
31         _prefs = prefs;
32          setLayout(new BorderLayout());
33
34         // Font sizes:
35         fontSize = new JTextField(5);
36
37
38         colorCodes = new JCheckBox(Globals.lang
39                    ("Color codes for required and optional fields"));
40         antialias = new JCheckBox(Globals.lang
41                   ("Use antialiasing font"));
42         overrideFonts = new JCheckBox(Globals.lang("Override default font settings"));
43
44         //useCustomIconTheme = new JCheckBox(Globals.lang("Use custom icon theme"));
45         //customIconThemeFile = new JTextField();
46         FormLayout layout = new FormLayout
47                 ("1dlu, 8dlu, left:pref, 4dlu, fill:pref, 4dlu, fill:60dlu, 4dlu, fill:pref",
48                         "");
49         DefaultFormBuilder builder = new DefaultFormBuilder(layout);
50         builder.setLeadingColumnOffset(2);
51         JLabel lab;
52         builder.appendSeparator(Globals.lang("General"));
53         JPanel p1 = new JPanel();
54         lab = new JLabel(Globals.lang("Menu and label font size") + ":");
55         p1.add(lab);
56         p1.add(fontSize);
57         builder.append(p1);
58         builder.nextLine();
59         builder.append(overrideFonts);
60         builder.nextLine();
61         builder.appendSeparator(Globals.lang("Table appearance"));
62         builder.append(antialias);
63         builder.nextLine();
64         builder.append(colorCodes);
65         builder.nextLine();
66         builder.append(fontButton);
67         builder.nextLine();
68         builder.append(colorPanel);
69         /*builder.appendSeparator(Globals.lang("Custom icon theme"));
70         builder.append(useCustomIconTheme);
71         builder.nextLine();
72         JPanel p2 = new JPanel();
73         lab = new JLabel(Globals.lang("Custom icon theme file")+":");
74         p2.add(lab);
75         p2.add(customIconThemeFile);
76         BrowseAction browse = new BrowseAction(null, customIconThemeFile, false);
77         JButton browseBut = new JButton(Globals.lang("Browse"));
78         browseBut.addActionListener(browse);
79         p2.add(browseBut);
80         builder.append(p2);
81           */
82
83     JPanel upper = new JPanel(),
84         sort = new JPanel(),
85         namesp = new JPanel(),
86             iconCol = new JPanel();
87     upper.setLayout(gbl);
88     sort.setLayout(gbl);
89         namesp.setLayout(gbl);
90         iconCol.setLayout(gbl);
91
92
93     overrideFonts.addActionListener(new ActionListener() {
94         public void actionPerformed(ActionEvent e) {
95             fontSize.setEnabled(overrideFonts.isSelected());
96         }
97     });
98
99     fontButton.addActionListener(new ActionListener() {
100         public void actionPerformed(ActionEvent e) {
101             // JDialog dl = new EntryCustomizationDialog(ths);
102             Font f=new FontSelectorDialog
103                 (null, GUIGlobals.CURRENTFONT).getSelectedFont();
104             if(f==null)
105                 return;
106             else
107                 font = f;
108         }
109         });
110     /*menuFontButton.addActionListener(new ActionListener() {
111          public void actionPerformed(ActionEvent e) {
112              Font f=new FontSelectorDialog
113                  (null, menuFont).getSelectedFont();
114              if(f==null)
115                  return;
116              else
117                  menuFont = f;
118          }
119          });*/
120
121     JPanel pan = builder.getPanel();
122     pan.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
123     add(pan, BorderLayout.CENTER);
124     }
125
126     public void setValues() {
127         colorCodes.setSelected(_prefs.getBoolean("tableColorCodesOn"));
128         antialias.setSelected(_prefs.getBoolean("antialias"));
129         fontSize.setText("" + _prefs.getInt("menuFontSize"));
130         oldMenuFontSize = _prefs.getInt("menuFontSize");
131         overrideFonts.setSelected(_prefs.getBoolean("overrideDefaultFonts"));
132         oldOverrideFontSize = overrideFonts.isSelected();
133         fontSize.setEnabled(overrideFonts.isSelected());
134         //useCustomIconTheme.setSelected(_prefs.getBoolean("useCustomIconTheme"));
135         //customIconThemeFile.setText(_prefs.get("customIconThemeFile"));
136         colorPanel.setValues();
137     }
138
139     /**
140      * Store changes to table preferences. This method is called when
141      * the user clicks Ok.
142      *
143      */
144     public void storeSettings() {
145
146         _prefs.putBoolean("tableColorCodesOn", colorCodes.isSelected());
147         _prefs.putBoolean("antialias", antialias.isSelected());
148         _prefs.put("fontFamily", font.getFamily());
149         _prefs.putInt("fontStyle", font.getStyle());
150         _prefs.putInt("fontSize", font.getSize());
151         _prefs.putBoolean("overrideDefaultFonts", overrideFonts.isSelected());
152         GUIGlobals.CURRENTFONT = font;
153         colorPanel.storeSettings();
154         try {
155             int size = Integer.parseInt(fontSize.getText());
156             if ((overrideFonts.isSelected() != oldOverrideFontSize) ||
157                     (size != oldMenuFontSize)) {
158                 _prefs.putInt("menuFontSize", size);
159                 JOptionPane.showMessageDialog(null, Globals.lang("You have changed the menu and label font size. "
160                         + "You must restart JabRef for this to come into effect."), Globals.lang("Changed font settings"),
161                         JOptionPane.WARNING_MESSAGE);
162             }
163
164         } catch (NumberFormatException ex) {
165             ex.printStackTrace();
166         }
167     }
168
169     public boolean readyToClose() {
170         try {
171             // Test if font size is a number:
172             int size = Integer.parseInt(fontSize.getText());
173
174         } catch (NumberFormatException ex) {
175             JOptionPane.showMessageDialog
176                     (null, Globals.lang("You must enter an integer value in the text field for") + " '" +
177                             Globals.lang("Menu and label font size") + "'", Globals.lang("Changed font settings"),
178                             JOptionPane.ERROR_MESSAGE);
179             return false;
180         }
181         return true;
182
183     }
184
185 }