~ubuntu-branches/ubuntu/trusty/jabref/trusty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2009-12-01 18:52:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20091201185251-08e2unpn1jl8ijq8
Tags: 2.6~beta2-1
* Remove alternative dependency on sun-java5-jre which was removed from the
  archive. Also adjust README.Debian and /usr/bin/jabref.
* New upstream beta release:
  - fixes "allow to disable (re)storing of current tab for entries"
    (closes: #447767)
  - thanks again to Philip Rinn for his help with the upgrade
* debian/copyright: add new developer.
* Refresh patches 01_free_javac.patch and 06_BibtexEntry.patch.
* Adjust debian/jabref.links and debian/jabref.install to new jar file.
* Simplify debian/jabref.dirs.
* Add a presubj fragment for reportbug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
import net.sf.jabref.gui.date.DatePickerButton;
54
54
import net.sf.jabref.imports.BibtexParser;
55
55
import net.sf.jabref.labelPattern.LabelPatternUtil;
56
 
import net.sf.jabref.undo.NamedCompound;
57
 
import net.sf.jabref.undo.UndoableFieldChange;
58
 
import net.sf.jabref.undo.UndoableKeyChange;
59
 
import net.sf.jabref.undo.UndoableRemoveEntry;
 
56
import net.sf.jabref.undo.*;
 
57
import com.jgoodies.looks.Options;
 
58
import com.jgoodies.looks.HeaderStyle;
60
59
 
61
60
/**
62
61
 * GUI component that allows editing of the fields of a BibtexEntry (i.e. the
101
100
    // The action which generates a bibtexkey for this entry.
102
101
    public GenerateKeyAction generateKeyAction;
103
102
 
 
103
    public AutoSetFileAction autoLink = new AutoSetFileAction();
 
104
 
104
105
    public AbstractAction writeXmp;
105
106
 
106
107
    SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction();
247
248
    }
248
249
 
249
250
    private void setupToolBar() {
 
251
        JPanel leftPan = new JPanel();
 
252
        leftPan.setLayout(new BorderLayout());
250
253
        tlb = new JToolBar(JToolBar.VERTICAL);
 
254
        //tlb.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
 
255
        tlb.setBorder(null);
 
256
        tlb.setRollover(true);
251
257
 
252
258
        tlb.setMargin(new Insets(0, 0, 0, 2));
253
259
 
262
268
        am.put("store", storeFieldAction);
263
269
        im.put(prefs.getKey("Autogenerate BibTeX keys"), "generateKey");
264
270
        am.put("generateKey", generateKeyAction);
 
271
        im.put(prefs.getKey("Automatically link files"), "autoLink");
 
272
        am.put("autoLink", autoLink);
265
273
        im.put(prefs.getKey("Entry editor, previous entry"), "prev");
266
274
        am.put("prev", prevEntryAction);
267
275
        im.put(prefs.getKey("Entry editor, next entry"), "next");
275
283
 
276
284
        tlb.setFloatable(false);
277
285
 
 
286
        // Add actions (and thus buttons)
 
287
        JButton closeBut = new JButton(closeAction);
 
288
        closeBut.setText(null);
 
289
        closeBut.setBorder(null);
 
290
        leftPan.add(closeBut, BorderLayout.NORTH);
 
291
 
278
292
        // Create type-label
279
293
        typeLabel = new TypeLabel(entry.getType().getName());
280
 
        
281
 
        // Add actions (and thus buttons)
282
 
        tlb.add(closeAction);
 
294
        leftPan.add(typeLabel, BorderLayout.CENTER);
283
295
 
284
 
        tlb.add(typeLabel);
 
296
        //tlb.add(typeL);
285
297
 
286
298
        tlb.addSeparator();
287
299
        
288
300
        tlb.add(generateKeyAction);
 
301
        tlb.add(autoLink);
289
302
 
290
303
        tlb.add(writeXmp);
291
304
 
304
317
        for (int i = 0; i < comps.length; i++)
305
318
            ((JComponent) comps[i]).setOpaque(false);
306
319
 
307
 
        add(tlb, BorderLayout.WEST);
 
320
        leftPan.add(tlb, BorderLayout.SOUTH);
 
321
        add(leftPan, BorderLayout.WEST);
308
322
    }
309
323
 
310
324
    /**
386
400
        } else if (panel.metaData.getData(Globals.SELECTOR_META_PREFIX + ed.getFieldName()) != null) {
387
401
            FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, ed,
388
402
                panel.metaData, storeFieldAction, false,
389
 
                (ed.getFieldName().equals("author") ? " and " : ", "));
 
403
                ((ed.getFieldName().equals("author") || ed.getFieldName().equals("editor")) ? " and " : ", "));
390
404
            contentSelectors.add(ws);
391
405
 
392
406
            return ws;
720
734
            // oldKey = entry.getCiteKey(),
721
735
            newKey = nu.getCiteKey();
722
736
            boolean anyChanged = false;
 
737
            boolean changedType = false;
723
738
            boolean duplicateWarning = false;
724
739
            boolean emptyWarning = newKey == null || newKey.equals("");
725
740
 
755
770
                }
756
771
            }
757
772
 
 
773
            // See if the user has changed the entry type:
 
774
            if (nu.getType() != entry.getType()) {
 
775
                compound.addEdit(new UndoableChangeType(entry,
 
776
                      entry.getType(), nu.getType()));
 
777
                entry.setType(nu.getType());
 
778
                anyChanged = true;
 
779
                changedType = true;
 
780
            }
758
781
            compound.end();
759
782
 
760
783
            if (!anyChanged)
776
799
            }
777
800
 
778
801
            lastSourceStringAccepted = source.getText();
779
 
            updateAllFields();
780
 
            lastSourceAccepted = true;
781
 
            updateSource = true;
782
 
 
 
802
            if (!changedType) {
 
803
                updateAllFields();
 
804
                lastSourceAccepted = true;
 
805
                updateSource = true;
 
806
            }
 
807
            else {
 
808
                panel.updateEntryEditorIfShowing();
 
809
            }
783
810
            // TODO: does updating work properly after source stored?
784
811
            // panel.tableModel.remap();
785
812
            // panel.entryTable.repaint();
873
900
    }
874
901
 
875
902
 
876
 
    private class TypeLabel extends JPanel {
877
 
        private String label;
 
903
    private class TypeLabel extends JLabel {
878
904
        public TypeLabel(String type) {
879
 
            label = type;
 
905
            super(type+" ");
 
906
            setUI(new VerticalLabelUI(false));
 
907
            setForeground(GUIGlobals.validFieldColor);
 
908
            setHorizontalAlignment(RIGHT);
 
909
            setFont(GUIGlobals.typeNameFont);
880
910
            addMouseListener(new MouseAdapter() {
881
911
                public void mouseClicked(MouseEvent e) {
882
912
                    boolean ctrlClick = prefs.getBoolean("ctrlClick");
895
925
            });
896
926
        }
897
927
 
898
 
        public void paint(Graphics g) {
 
928
        public void paintComponent(Graphics g) {
899
929
            Graphics2D g2 = (Graphics2D) g;
900
 
            g2.setColor(GUIGlobals.validFieldColor);
901
 
            g2.setFont(GUIGlobals.typeNameFont);
902
 
            FontMetrics fm = g2.getFontMetrics();
903
 
            int width = fm.stringWidth(label);
 
930
            //g2.setColor(GUIGlobals.validFieldColor);
 
931
            //g2.setFont(GUIGlobals.typeNameFont);
 
932
            //FontMetrics fm = g2.getFontMetrics();
 
933
            //int width = fm.stringWidth(label);
904
934
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
905
 
            g2.rotate(-Math.PI / 2, 0, 0);
906
 
            g2.drawString(label, -width - 7, 28);
 
935
            super.paintComponent(g2);
 
936
            //g2.rotate(-Math.PI / 2, 0, 0);
 
937
            //g2.drawString(label, -width - 7, 28);
907
938
        }
908
939
    }
909
940
 
1397
1428
    }
1398
1429
 
1399
1430
 
 
1431
    class AutoSetFileAction extends AbstractAction {
 
1432
        public AutoSetFileAction() {
 
1433
            putValue(SMALL_ICON, GUIGlobals.getImage("autoGroup"));
 
1434
            putValue(SHORT_DESCRIPTION, Globals.lang("Automatically set file links for this entry")
 
1435
                    +" (Alt-F)");
 
1436
        }
 
1437
 
 
1438
        public void actionPerformed(ActionEvent event) {
 
1439
            JDialog diag = new JDialog(frame, true);
 
1440
            final FileListTableModel tableModel = new FileListTableModel();
 
1441
            tableModel.setContent(entry.getField(GUIGlobals.FILE_FIELD));
 
1442
            FileListEditor.autoSetLinks(entry, tableModel, panel.metaData(), new ActionListener() {
 
1443
                public void actionPerformed(ActionEvent e) {
 
1444
                    if (e.getID() > 0) {
 
1445
                        entry.setField(GUIGlobals.FILE_FIELD, tableModel.getStringRepresentation());
 
1446
                        frame.output(Globals.lang("Finished autosetting external links."));
 
1447
                    }
 
1448
                    else frame.output(Globals.lang("Finished autosetting external links.")
 
1449
                        +" "+Globals.lang("No files found."));
 
1450
                }
 
1451
            }, diag);
 
1452
        }
 
1453
    }
1400
1454
}