~ubuntu-branches/ubuntu/natty/jabref/natty

« back to all changes in this revision

Viewing changes to src/java/net/sf/jabref/EntryEditorTab.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2007-11-16 18:38:18 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071116183818-20x934jdsju14618
Tags: 2.3-2
* Add /usr/lib/jvm/java-7-icedtea to wrapper script. Doesn't work on
  Debian yet but helps Ubuntu users (TODO: add dependency on
  icedtea-java7-jre (not yet in Debian)).
* Reformat wrapper script.
* debian/rules: re-arrange targets and their dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
50
47
 
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;
53
53
 
54
54
/**
55
55
 * A single tab displayed in the EntryEditor holding several FieldEditors.
56
56
 * 
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) $)
59
59
 * 
60
60
 */
61
61
public class EntryEditorTab {
72
72
 
73
73
        private Component firstComponent;
74
74
 
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]);
78
79
                else
80
81
 
81
82
                this.parent = parent;
82
83
 
83
 
                newSetupPanel(addKeyField, name);
 
84
                setupPanel(frame, panel, addKeyField, name);
84
85
 
85
86
                /*
86
87
                 * The following line makes sure focus cycles inside tab instead of
90
91
        }
91
92
 
92
93
 
93
 
    void newSetupPanel(boolean addKeyField, String title) {
 
94
    void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) {
94
95
        
95
96
        InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED);
96
97
                ActionMap am = panel.getActionMap();
132
133
        String rowSpec = sb.toString();
133
134
 
134
135
        DefaultFormBuilder builder = new DefaultFormBuilder
135
 
                (panel, new FormLayout(colSpec, rowSpec));
 
136
                (new FormLayout(colSpec, rowSpec), panel);
136
137
 
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]);
 
141
 
 
142
            final FieldEditor ta;
 
143
            if (editorType == GUIGlobals.FILE_LIST_EDITOR)
 
144
                ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
 
145
            else
 
146
                ta = new FieldTextArea(fields[i], null);
 
147
 
140
148
            JComponent ex = parent.getExtra(fields[i], ta);
141
 
            setupJTextComponent(ta);
 
149
            setupJTextComponent(ta.getTextComponent());
 
150
 
 
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));
 
155
            }
142
156
 
143
157
            // Store the editor for later reference:
144
158
            editors.put(fields[i], ta);
179
193
                }
180
194
    }
181
195
 
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;
187
 
 
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);
192
 
                        
193
 
                        if (firstComponent == null){
194
 
                                firstComponent = ex;
195
 
                        }
196
 
                        
197
 
                        setupJTextComponent(ta);
198
 
 
199
 
                        // Store the editor for later reference:
200
 
                        editors.put(fields[i], ta);
201
 
                        if (i == 0)
202
 
                                activeField = ta;
203
 
 
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;
208
 
                        con.gridwidth = 1;
209
 
                        con.weightx = 0;
210
 
                        con.weighty = 0;
211
 
                        con.anchor = GridBagConstraints.NORTH;
212
 
                        con.fill = GridBagConstraints.BOTH;
213
 
                        gbl.setConstraints(ta.getLabel(), con);
214
 
                        panel.add(ta.getLabel());
215
 
 
216
 
                        // The field itself:
217
 
                        con.fill = GridBagConstraints.BOTH;
218
 
                        con.weightx = 1;
219
 
                        con.weighty = BibtexFields.getFieldWeight(fields[i]);
220
 
                        totalWeight += con.weighty;
221
 
                        // The gridwidth depends on whether we will add an extra component
222
 
                        // to the right:
223
 
                        if (ex != null)
224
 
                                con.gridwidth = 1;
225
 
                        else
226
 
                                con.gridwidth = GridBagConstraints.REMAINDER;
227
 
                        gbl.setConstraints(ta.getPane(), con);
228
 
                        panel.add(ta.getPane());
229
 
 
230
 
                        // Possibly an extra component:
231
 
                        if (ex != null) {
232
 
                                con.gridwidth = GridBagConstraints.REMAINDER;
233
 
                                con.anchor = GridBagConstraints.NORTH;
234
 
                                con.fill = GridBagConstraints.HORIZONTAL;
235
 
                                con.weightx = 0;
236
 
                                gbl.setConstraints(ex, con);
237
 
                                panel.add(ex);
238
 
                        }
239
 
                        panel.setName(title);
240
 
                }
241
 
 
242
 
                // Add the edit field for Bibtex-key.
243
 
                if (addKeyField) {
244
 
                        con.insets.top += 25;
245
 
                        con.insets.bottom = 10;
246
 
                        con.gridwidth = 1;
247
 
                        con.weighty = 0;
248
 
                        con.weightx = 0;
249
 
                        con.fill = GridBagConstraints.HORIZONTAL;
250
 
                        con.anchor = GridBagConstraints.SOUTHWEST;
251
 
 
252
 
                        final FieldTextField tf = new FieldTextField(BibtexFields.KEY_FIELD, (String) parent
253
 
                                .getEntry().getField(BibtexFields.KEY_FIELD), true);
254
 
                        setupJTextComponent(tf);
255
 
 
256
 
                        editors.put("bibtexkey", tf);
257
 
                        /*
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:
260
 
                         */
261
 
                        if (editors.size() == 1)
262
 
                                activeField = tf;
263
 
 
264
 
                        gbl.setConstraints(tf.getLabel(), con);
265
 
                        panel.add(tf.getLabel());
266
 
                        con.gridwidth = GridBagConstraints.REMAINDER;
267
 
                        con.weightx = 1;
268
 
 
269
 
                        gbl.setConstraints(tf, con);
270
 
                        panel.add(tf);
271
 
                }
272
 
        }
273
196
 
274
197
        BibtexEntry entry;
275
198
 
390
313
         * 
391
314
         * @param component
392
315
         */
393
 
        public void setupJTextComponent(final JTextComponent component) {
 
316
        public void setupJTextComponent(final JComponent component) {
394
317
 
395
318
                component.addFocusListener(fieldListener);
396
319
 
433
356
                } catch (Throwable t) {
434
357
                        System.err.println(t);
435
358
                }
436
 
        }
 
359
 
 
360
    }
437
361
 
438
362
        /*
439
363
         * Focus listener that fires the storeFieldAction when a FieldTextArea loses
492
416
                }
493
417
 
494
418
                public void focusLost(FocusEvent e) {
495
 
                        synchronized (this) {
 
419
            synchronized (this) {
496
420
                                if (c != null) {
497
421
                                        c.getDocument().removeDocumentListener(d);
498
422
                                        c = null;