e5cb9b3ef674282b1486dca3087ca2a733fd2419
[debian/jabref.git] / src / java / net / sf / jabref / PreviewPrefsTab.java
1 package net.sf.jabref;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6
7 public class PreviewPrefsTab extends JPanel implements PrefsTab {
8
9         JabRefPreferences _prefs;
10
11         JabRefFrame _frame;
12
13         JPanel pan = new JPanel();
14
15         GridBagLayout gbl = new GridBagLayout();
16
17         GridBagConstraints con = new GridBagConstraints();
18
19         JTextArea layout1 = new JTextArea("", 1, 1), layout2 = new JTextArea("", 1, 1);
20
21         JButton def1 = new JButton(Globals.lang("Default")),
22                 def2 = new JButton(Globals.lang("Default")), test1 = new JButton(Globals.lang("Test")),
23                 test2 = new JButton(Globals.lang("Test")), help;
24
25         JPanel p1 = new JPanel(), p2 = new JPanel();
26
27         JScrollPane sp1 = new JScrollPane(layout1), sp2 = new JScrollPane(layout2);
28
29         private static BibtexEntry entry;
30
31         public PreviewPrefsTab(JabRefPreferences prefs) {
32                 _prefs = prefs;
33
34                 p1.setLayout(gbl);
35                 p2.setLayout(gbl);
36
37                 setLayout(gbl);
38                 JLabel lab;
39                 lab = new JLabel(Globals.lang("Preview") + " 1");
40                 con.anchor = GridBagConstraints.WEST;
41                 con.gridwidth = GridBagConstraints.REMAINDER;
42                 con.fill = GridBagConstraints.BOTH;
43                 con.weightx = 1;
44                 con.weighty = 0;
45                 con.insets = new Insets(2, 2, 2, 2);
46                 gbl.setConstraints(lab, con);
47                 // p1.add(lab);
48                 con.weighty = 1;
49                 gbl.setConstraints(sp1, con);
50                 p1.add(sp1);
51                 con.weighty = 0;
52                 con.gridwidth = 1;
53                 con.weightx = 0;
54                 con.fill = GridBagConstraints.NONE;
55                 con.anchor = GridBagConstraints.WEST;
56                 gbl.setConstraints(test1, con);
57                 p1.add(test1);
58                 gbl.setConstraints(def1, con);
59                 p1.add(def1);
60                 con.gridwidth = GridBagConstraints.REMAINDER;
61                 JPanel pan = new JPanel();
62                 con.weightx = 1;
63                 gbl.setConstraints(pan, con);
64                 p1.add(pan);
65                 lab = new JLabel(Globals.lang("Preview") + " 2");
66                 gbl.setConstraints(lab, con);
67                 // p2.add(lab);
68                 con.weighty = 1;
69                 con.fill = GridBagConstraints.BOTH;
70                 gbl.setConstraints(sp2, con);
71                 p2.add(sp2);
72                 con.weighty = 0;
73                 con.weightx = 0;
74                 con.fill = GridBagConstraints.NONE;
75                 con.gridwidth = 1;
76                 gbl.setConstraints(test2, con);
77                 p2.add(test2);
78                 gbl.setConstraints(def2, con);
79                 p2.add(def2);
80                 con.gridwidth = 1;
81                 pan = new JPanel();
82                 con.weightx = 1;
83                 gbl.setConstraints(pan, con);
84                 p2.add(pan);
85
86                 { // Help Button
87                         HelpAction helpAction = new HelpAction(Globals.helpDiag, GUIGlobals.previewHelp,
88                                 Globals.lang("Help on Preview Settings"), GUIGlobals.getIconUrl("helpSmall"));
89                         JButton help = helpAction.getIconButton();
90                         con.weightx = 0;
91                         con.gridwidth = GridBagConstraints.REMAINDER;
92                         gbl.setConstraints(help, con);
93                         p2.add(help);
94                 }
95
96                 con.weightx = 1;
97                 con.weighty = 0;
98                 con.fill = GridBagConstraints.BOTH;
99                 con.gridwidth = GridBagConstraints.REMAINDER;
100                 lab = new JLabel(Globals.lang("Preview") + " 1");
101                 gbl.setConstraints(lab, con);
102                 add(lab);
103                 con.weighty = 1;
104                 gbl.setConstraints(p1, con);
105                 add(p1);
106                 lab = new JLabel(Globals.lang("Preview") + " 2");
107                 con.weighty = 0;
108                 JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
109                 gbl.setConstraints(sep, con);
110                 add(sep);
111                 gbl.setConstraints(lab, con);
112                 add(lab);
113                 con.weighty = 1;
114                 gbl.setConstraints(p2, con);
115                 add(p2);
116
117                 def1.addActionListener(new ActionListener() {
118                         public void actionPerformed(ActionEvent e) {
119                                 String tmp = layout1.getText().replaceAll("\n", "__NEWLINE__");
120                                 _prefs.remove("preview0");
121                                 layout1.setText(_prefs.get("preview0").replaceAll("__NEWLINE__", "\n"));
122                                 _prefs.put("preview0", tmp);
123                         }
124                 });
125                 def2.addActionListener(new ActionListener() {
126                         public void actionPerformed(ActionEvent e) {
127                                 String tmp = layout2.getText().replaceAll("\n", "__NEWLINE__");
128                                 _prefs.remove("preview1");
129                                 layout2.setText(_prefs.get("preview1").replaceAll("__NEWLINE__", "\n"));
130                                 _prefs.put("preview1", tmp);
131                         }
132                 });
133
134                 test1.addActionListener(new ActionListener() {
135                         public void actionPerformed(ActionEvent e) {
136                                 getTestEntry();
137                                 PreviewPanel testPanel = new PreviewPanel(entry, new MetaData(), layout1.getText());
138                                 testPanel.setPreferredSize(new Dimension(800, 350));
139                                 JOptionPane.showMessageDialog(null, testPanel, Globals.lang("Preview"),
140                                         JOptionPane.PLAIN_MESSAGE);
141                         }
142                 });
143
144                 test2.addActionListener(new ActionListener() {
145                         public void actionPerformed(ActionEvent e) {
146                                 getTestEntry();
147                                 PreviewPanel testPanel = new PreviewPanel(entry, new MetaData(), layout2.getText());
148                                 testPanel.setPreferredSize(new Dimension(800, 350));
149                                 JOptionPane.showMessageDialog(null, new JScrollPane(testPanel), Globals
150                                         .lang("Preview"), JOptionPane.PLAIN_MESSAGE);
151                         }
152                 });
153         }
154
155         public static BibtexEntry getTestEntry() {
156                 if (entry != null)
157                         return entry;
158                 entry = new BibtexEntry(Util.createNeutralId(), BibtexEntryType.getType("article"));
159                 entry.setField(BibtexFields.KEY_FIELD, "conceicao1997");
160                 entry
161                         .setField(
162                                 "author",
163                                 "L. E. C. Conceic{\\~a}o and T. van der Meeren and J. A. J. Verreth and M. S. Evjen and D. F. Houlihan and H. J. Fyhn");
164                 entry
165                         .setField(
166                                 "title",
167                                 "Amino acid metabolism and protein turnover in larval turbot (Scophthalmus maximus) fed natural zooplankton or Artemia");
168                 entry.setField("year", "1997");
169                 entry.setField("journal", "Marine Biology");
170                 entry.setField("month", "January");
171                 entry.setField("number", "2");
172                 entry.setField("volume", "123");
173                 entry.setField("pdf", "conceicao1997.pdf");
174                 entry.setField("pages", "255--265");
175                 entry.setField("keywords", "energetics, artemia, metabolism, amino acid, turbot");
176                 entry.setField("url",
177                         "http://ejournals.ebsco.com/direct.asp?ArticleID=TYY4NT82XA9H7R8PFPPV");
178                 entry
179                         .setField(
180                                 "abstract",
181                                 "Abstract The present paper studied the influence of different food regimes "
182                                         + "on the free amino acid (FAA) pool, the rate of protein turnover, the flux of amino acids, and "
183                                         + "their relation to growth of larval turbot (Scophthalmus maximus L.) from first feeding until "
184                                         + "metamorphosis. The amino acid profile of protein was stable during the larval period although "
185                                         + "some small, but significant, differences were found. Turbot larvae had proteins which were rich "
186                                         + "in leucine and aspartate, and poor in glutamate, suggesting a high leucine requirement. The "
187                                         + "profile of the FAA pool was highly variable and quite different from the amino acid profile in "
188                                         + "protein. The proportion of essential FAA decreased with development. High contents of free tyrosine "
189                                         + "and phenylalanine were found on Day 3, while free taurine was present at high levels throughout "
190                                         + "the experimental period. Larval growth rates were positively correlated with taurine levels, "
191                                         + "suggesting a dietary dependency for taurine and/or sulphur amino acids.\n\nReduced growth rates in "
192                                         + "Artemia-fed larvae were associated with lower levels of free methionine, indicating that this diet "
193                                         + "is deficient in methionine for turbot larvae. Leucine might also be limiting turbot growth as the "
194                                         + "different diet organisms had lower levels of this amino acid in the free pool than was found in the "
195                                         + "larval protein. A previously presented model was used to describe the flux of amino acids in growing "
196                                         + "turbot larvae. The FAA pool was found to be small and variable. It was estimated that the daily dietary "
197                                         + "amino acid intake might be up to ten times the larval FAA pool. In addition, protein synthesis and "
198                                         + "protein degradation might daily remove and return, respectively, the equivalent of up to 20 and 10 "
199                                         + "times the size of the FAA pool. In an early phase (Day 11) high growth rates were associated with a "
200                                         + "relatively low protein turnover, while at a later stage (Day 17), a much higher turnover was observed.");
201                 return entry;
202         }
203
204         public void setValues() {
205                 layout1.setText(_prefs.get("preview0").replaceAll("__NEWLINE__", "\n"));
206                 layout2.setText(_prefs.get("preview1").replaceAll("__NEWLINE__", "\n"));
207         }
208
209         public void storeSettings() {
210                 _prefs.put("preview0", layout1.getText().replaceAll("\n", "__NEWLINE__"));
211                 _prefs.put("preview1", layout2.getText().replaceAll("\n", "__NEWLINE__"));
212         }
213
214         public boolean readyToClose() {
215                 return true;
216         }
217
218 }