28
28
import java.awt.BorderLayout;
29
29
import java.awt.Component;
30
30
import java.awt.Dimension;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.awt.Insets;
34
31
import java.awt.KeyboardFocusManager;
35
32
import java.awt.event.FocusEvent;
36
33
import java.awt.event.FocusListener;
51
48
import com.jgoodies.forms.builder.DefaultFormBuilder;
52
49
import com.jgoodies.forms.layout.FormLayout;
50
import net.sf.jabref.gui.AutoCompleter;
51
import net.sf.jabref.gui.AutoCompleteListener;
52
import net.sf.jabref.gui.FileListEditor;
55
55
* A single tab displayed in the EntryEditor holding several FieldEditors.
57
* @author $Author: coezbek $
58
* @version $Revision: 1.19 $ ($Date: 2006/11/12 01:41:55 $)
57
* @author $Author: mortenalver $
58
* @version $Revision: 2421 $ ($Date: 2007-10-09 10:27:21 +0200 (Tue, 09 Oct 2007) $)
61
61
public class EntryEditorTab {
73
73
private Component firstComponent;
75
public EntryEditorTab(List fields, EntryEditor parent, boolean addKeyField, String name) {
75
public EntryEditorTab(JabRefFrame frame, BasePanel panel, List fields, EntryEditor parent,
76
boolean addKeyField, String name) {
76
77
if (fields != null)
77
78
this.fields = (String[]) fields.toArray(new String[0]);
132
133
String rowSpec = sb.toString();
134
135
DefaultFormBuilder builder = new DefaultFormBuilder
135
(panel, new FormLayout(colSpec, rowSpec));
136
(new FormLayout(colSpec, rowSpec), panel);
137
138
for (int i = 0; i < fields.length; i++) {
138
139
// Create the text area:
139
final FieldTextArea ta = new FieldTextArea(fields[i], null);
140
int editorType = BibtexFields.getEditorType(fields[i]);
142
final FieldEditor ta;
143
if (editorType == GUIGlobals.FILE_LIST_EDITOR)
144
ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
146
ta = new FieldTextArea(fields[i], null);
140
148
JComponent ex = parent.getExtra(fields[i], ta);
141
setupJTextComponent(ta);
149
setupJTextComponent(ta.getTextComponent());
151
// Add autocompleter listener, if required for this field:
152
AutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]);
153
if (autoComp != null) {
154
ta.getTextComponent().addKeyListener(new AutoCompleteListener(autoComp));
143
157
// Store the editor for later reference:
144
158
editors.put(fields[i], ta);
182
void setupPanel(boolean addKeyField, String title) {
183
GridBagLayout gbl = new GridBagLayout();
184
GridBagConstraints con = new GridBagConstraints();
185
panel.setLayout(gbl);
186
double totalWeight = 0;
188
for (int i = 0; i < fields.length; i++) {
189
// Create the text area:
190
final FieldTextArea ta = new FieldTextArea(fields[i], null);
191
JComponent ex = parent.getExtra(fields[i], ta);
193
if (firstComponent == null){
197
setupJTextComponent(ta);
199
// Store the editor for later reference:
200
editors.put(fields[i], ta);
204
// The label for this field:
205
con.insets = new Insets(5, 5, 0, 0);
206
con.anchor = GridBagConstraints.WEST;
207
con.fill = GridBagConstraints.BOTH;
211
con.anchor = GridBagConstraints.NORTH;
212
con.fill = GridBagConstraints.BOTH;
213
gbl.setConstraints(ta.getLabel(), con);
214
panel.add(ta.getLabel());
217
con.fill = GridBagConstraints.BOTH;
219
con.weighty = BibtexFields.getFieldWeight(fields[i]);
220
totalWeight += con.weighty;
221
// The gridwidth depends on whether we will add an extra component
226
con.gridwidth = GridBagConstraints.REMAINDER;
227
gbl.setConstraints(ta.getPane(), con);
228
panel.add(ta.getPane());
230
// Possibly an extra component:
232
con.gridwidth = GridBagConstraints.REMAINDER;
233
con.anchor = GridBagConstraints.NORTH;
234
con.fill = GridBagConstraints.HORIZONTAL;
236
gbl.setConstraints(ex, con);
239
panel.setName(title);
242
// Add the edit field for Bibtex-key.
244
con.insets.top += 25;
245
con.insets.bottom = 10;
249
con.fill = GridBagConstraints.HORIZONTAL;
250
con.anchor = GridBagConstraints.SOUTHWEST;
252
final FieldTextField tf = new FieldTextField(BibtexFields.KEY_FIELD, (String) parent
253
.getEntry().getField(BibtexFields.KEY_FIELD), true);
254
setupJTextComponent(tf);
256
editors.put("bibtexkey", tf);
258
* If the key field is the only field, we should have only one
259
* editor, and this one should be set as active initially:
261
if (editors.size() == 1)
264
gbl.setConstraints(tf.getLabel(), con);
265
panel.add(tf.getLabel());
266
con.gridwidth = GridBagConstraints.REMAINDER;
269
gbl.setConstraints(tf, con);
274
197
BibtexEntry entry;