Пример #1
0
  /** Set the dynamic contents of "Add to group ..." submenu. */
  @Override
  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    BibtexEntry[] bes = panel.getSelectedEntries();
    panel.storeCurrentEdit();
    GroupTreeNode groups = panel.metaData().getGroups();
    if (groups == null) {
      groupAdd.setEnabled(false);
      groupRemove.setEnabled(false);
    } else {
      groupAdd.setEnabled(true);
      groupRemove.setEnabled(true);
    }

    addSeparator();
    floatMarked.setSelected(Globals.prefs.getBoolean(JabRefPreferences.FLOAT_MARKED_ENTRIES));
    add(floatMarked);
  }
Пример #2
0
  public void run() {

    if (!goOn) return;

    for (int i = 0; i < entries.length; i++) {

      BibtexEntry entry = entries[i];

      // Make a list of all PDFs linked from this entry:
      List<File> files = new ArrayList<File>();

      // First check the (legacy) "pdf" field:
      String pdf = entry.getField("pdf");
      String dir = panel.metaData().getFileDirectory("pdf");
      File f = Util.expandFilename(pdf, new String[] {dir, "."});
      if (f != null) files.add(f);

      // Then check the "file" field:
      dir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
      String field = entry.getField(GUIGlobals.FILE_FIELD);
      if (field != null) {
        FileListTableModel tm = new FileListTableModel();
        tm.setContent(field);
        for (int j = 0; j < tm.getRowCount(); j++) {
          FileListEntry flEntry = tm.getEntry(j);
          if ((flEntry.getType() != null)
              && (flEntry.getType().getName().toLowerCase().equals("pdf"))) {
            f = Util.expandFilename(flEntry.getLink(), new String[] {dir, "."});
            if (f != null) files.add(f);
          }
        }
      }

      optDiag.progressArea.append(entry.getCiteKey() + "\n");

      if (files.size() == 0) {
        skipped++;
        optDiag.progressArea.append("  " + Globals.lang("Skipped - No PDF linked") + ".\n");
      } else
        for (File file : files) {
          if (!file.exists()) {
            skipped++;
            optDiag.progressArea.append(
                "  " + Globals.lang("Skipped - PDF does not exist") + ":\n");
            optDiag.progressArea.append("    " + file.getPath() + "\n");

          } else {
            try {
              XMPUtil.writeXMP(file, entry, database);
              optDiag.progressArea.append("  " + Globals.lang("Ok") + ".\n");
              entriesChanged++;
            } catch (Exception e) {
              optDiag.progressArea.append(
                  "  " + Globals.lang("Error while writing") + " '" + file.getPath() + "':\n");
              optDiag.progressArea.append("    " + e.getLocalizedMessage() + "\n");
              errors++;
            }
          }
        }

      if (optDiag.canceled) {
        optDiag.progressArea.append("\n" + Globals.lang("Operation canceled.\n"));
        break;
      }
    }
    optDiag.progressArea.append(
        "\n"
            + Globals.lang(
                "Finished writing XMP for %0 file (%1 skipped, %2 errors).",
                String.valueOf(entriesChanged), String.valueOf(skipped), String.valueOf(errors)));
    optDiag.done();
  }
  void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) {

    InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = panel.getActionMap();

    im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", parent.prevEntryAction);
    im.put(Globals.prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", parent.nextEntryAction);

    im.put(Globals.prefs.getKey("Entry editor, store field"), "store");
    am.put("store", parent.storeFieldAction);
    im.put(Globals.prefs.getKey("Entry editor, next panel"), "right");
    im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("left", parent.switchLeftAction);
    im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left");
    im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("right", parent.switchRightAction);
    im.put(Globals.prefs.getKey("Help"), "help");
    am.put("help", parent.helpAction);
    im.put(Globals.prefs.getKey("Save database"), "save");
    am.put("save", parent.saveDatabaseAction);
    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", parent.frame.nextTab);
    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", parent.frame.prevTab);

    panel.setName(title);
    // String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref";
    String colSpec =
        "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, "
            + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref";
    StringBuffer sb = new StringBuffer();
    int rows = (int) Math.ceil((double) fields.length / 2.0);
    for (int i = 0; i < rows; i++) {
      sb.append("fill:pref:grow, ");
    }
    if (addKeyField) sb.append("4dlu, fill:pref");
    else if (sb.length() >= 2) sb.delete(sb.length() - 2, sb.length());
    String rowSpec = sb.toString();

    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel);

    for (int i = 0; i < fields.length; i++) {
      // Create the text area:
      int editorType = BibtexFields.getEditorType(fields[i]);

      final FieldEditor ta;
      if (editorType == GUIGlobals.FILE_LIST_EDITOR)
        ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent);
      else ta = new FieldTextArea(fields[i], null);
      // ta.addUndoableEditListener(bPanel.undoListener);

      JComponent ex = parent.getExtra(fields[i], ta);

      // Add autocompleter listener, if required for this field:
      AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]);
      AutoCompleteListener acl = null;
      if (autoComp != null) {
        acl = new AutoCompleteListener(autoComp);
      }
      setupJTextComponent(ta.getTextComponent(), acl);
      ta.setAutoCompleteListener(acl);

      // Store the editor for later reference:
      editors.put(fields[i], ta);
      if (i == 0) activeField = ta;
      // System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i]));
      // ta.getPane().setPreferredSize(new Dimension(100,
      //        (int)(50.0*BibtexFields.getFieldWeight(fields[i]))));
      builder.append(ta.getLabel());
      if (ex == null) builder.append(ta.getPane(), 3);
      else {
        builder.append(ta.getPane());
        JPanel pan = new JPanel();
        pan.setLayout(new BorderLayout());
        pan.add(ex, BorderLayout.NORTH);
        builder.append(pan);
      }
      if (i % 2 == 1) builder.nextLine();
    }

    // Add the edit field for Bibtex-key.
    if (addKeyField) {
      final FieldTextField tf =
          new FieldTextField(
              BibtexFields.KEY_FIELD, parent.getEntry().getField(BibtexFields.KEY_FIELD), true);
      // tf.addUndoableEditListener(bPanel.undoListener);
      setupJTextComponent(tf, null);

      editors.put("bibtexkey", tf);
      /*
       * If the key field is the only field, we should have only one
       * editor, and this one should be set as active initially:
       */
      if (editors.size() == 1) activeField = tf;
      builder.nextLine();
      builder.append(tf.getLabel());
      builder.append(tf, 3);
    }
  }
Пример #4
0
 public void update() {
   // pdfURL = new URL("http://geog-www.sbs.ohio-state.edu/faculty/bmark/abbott_etal_ppp03.pdf");
   if (result.url != null) {
     // System.out.println("PDF URL: "+result.url);
     String bibtexKey = entry.getCiteKey();
     String fileDir = basePanel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
     if (fileDir == null) {
       // TODO: error message if file dir not defined
       // JOptionPane.showMessageDialog(frame, Globals.lang);
       return;
     }
     DownloadExternalFile def =
         new DownloadExternalFile(basePanel.frame(), basePanel.metaData(), bibtexKey);
     try {
       def.download(
           result.url,
           new DownloadExternalFile.DownloadCallback() {
             public void downloadComplete(FileListEntry file) {
               System.out.println("finished");
               FileListTableModel tm = new FileListTableModel();
               String oldValue = entry.getField(GUIGlobals.FILE_FIELD);
               tm.setContent(oldValue);
               tm.addEntry(tm.getRowCount(), file);
               String newValue = tm.getStringRepresentation();
               UndoableFieldChange edit =
                   new UndoableFieldChange(entry, GUIGlobals.FILE_FIELD, oldValue, newValue);
               entry.setField(GUIGlobals.FILE_FIELD, newValue);
               basePanel.undoManager.addEdit(edit);
               basePanel.markBaseChanged();
             }
           });
     } catch (IOException e) {
       e.printStackTrace();
     }
     basePanel.output(Globals.lang("Finished downloading full text document"));
   } else {
     String message = null;
     switch (result.status) {
       case FindFullText.UNKNOWN_DOMAIN:
         message =
             Globals.lang(
                 "Unable to find full text article. No search algorithm "
                     + "defined for the '%0' web site.",
                 result.host);
         break;
       case FindFullText.WRONG_MIME_TYPE:
         message =
             Globals.lang(
                 "Found pdf link, but received the wrong MIME type. "
                     + "This could indicate that you don't have access to the fulltext article.");
         break;
       case FindFullText.LINK_NOT_FOUND:
         message = Globals.lang("Unable to find full text document in the linked web page.");
         break;
       case FindFullText.IO_EXCEPTION:
         message = Globals.lang("Connection error when trying to find full text document.");
         break;
       case FindFullText.NO_URLS_DEFINED:
         message = Globals.lang("This entry provides no URL or DOI links.");
         break;
     }
     basePanel.output(Globals.lang("Full text article download failed"));
     JOptionPane.showMessageDialog(
         basePanel.frame(),
         message,
         Globals.lang("Full text article download failed"),
         JOptionPane.ERROR_MESSAGE);
   }
 }