public void mouseClicked(MouseEvent e) {
   if (e.isPopupTrigger()) {
     processPopupTrigger(e);
     return;
   }
   // if (e.)
   final int col = entryTable.columnAtPoint(e.getPoint()),
       row = entryTable.rowAtPoint(e.getPoint());
   if (col < PAD) {
     BibtexEntry entry = sortedEntries.get(row);
     BasePanel p = entryHome.get(entry);
     switch (col) {
       case FILE_COL:
         Object o = entry.getField(GUIGlobals.FILE_FIELD);
         if (o != null) {
           FileListTableModel tableModel = new FileListTableModel();
           tableModel.setContent((String) o);
           if (tableModel.getRowCount() == 0) return;
           FileListEntry fl = tableModel.getEntry(0);
           (new ExternalFileMenuItem(
                   frame, entry, "", fl.getLink(), null, p.metaData(), fl.getType()))
               .actionPerformed(null);
         }
         break;
       case URL_COL:
         Object link = entry.getField("url");
         try {
           if (link != null) Util.openExternalViewer(p.metaData(), (String) link, "url");
         } catch (IOException ex) {
           ex.printStackTrace();
         }
         break;
     }
   }
 }
    /**
     * If the user has signalled the opening of a context menu, the event gets redirected to this
     * method. Here we open a file link menu if the user is pointing at a file link icon. Otherwise
     * a general context menu should be shown.
     *
     * @param e The triggering mouse event.
     */
    public void processPopupTrigger(MouseEvent e) {
      BibtexEntry entry = sortedEntries.get(entryTable.rowAtPoint(e.getPoint()));
      BasePanel p = entryHome.get(entry);
      int col = entryTable.columnAtPoint(e.getPoint());
      JPopupMenu menu = new JPopupMenu();
      int count = 0;

      if (col == FILE_COL) {
        // We use a FileListTableModel to parse the field content:
        Object o = entry.getField(GUIGlobals.FILE_FIELD);
        FileListTableModel fileList = new FileListTableModel();
        fileList.setContent((String) o);
        // If there are one or more links, open the first one:
        for (int i = 0; i < fileList.getRowCount(); i++) {
          FileListEntry flEntry = fileList.getEntry(i);
          String description = flEntry.getDescription();
          if ((description == null) || (description.trim().length() == 0))
            description = flEntry.getLink();
          menu.add(
              new ExternalFileMenuItem(
                  p.frame(),
                  entry,
                  description,
                  flEntry.getLink(),
                  flEntry.getType().getIcon(),
                  p.metaData(),
                  flEntry.getType()));
          count++;
        }
      }

      if (count > 0) menu.show(entryTable, e.getX(), e.getY());
    }
Exemplo n.º 3
0
 @Override
 public void update() {
   if (cancelled) {
     frame.unblock();
     return;
   }
   if (unsuccessfulRenames > 0) { // Rename failed for at least one entry
     JOptionPane.showMessageDialog(
         frame,
         Localization.lang(
             "File rename failed for %0 entries.", Integer.toString(unsuccessfulRenames)),
         Localization.lang("Autogenerate PDF Names"),
         JOptionPane.INFORMATION_MESSAGE);
   }
   if (modifiedEntriesCount > 0) {
     panel.updateEntryEditorIfShowing();
     panel.markBaseChanged();
   }
   String message;
   switch (modifiedEntriesCount) {
     case 0:
       message = Localization.lang("No entry needed a clean up");
       break;
     case 1:
       message = Localization.lang("One entry needed a clean up");
       break;
     default:
       message =
           Localization.lang(
               "%0 entries needed a clean up", Integer.toString(modifiedEntriesCount));
       break;
   }
   panel.output(message);
   frame.unblock();
 }
Exemplo n.º 4
0
  @Override
  public void actionPerformed(ActionEvent e) {
    BasePanel bp = frame.basePanel();
    if (bp == null) {
      return;
    }
    BibtexEntry[] entries = bp.getSelectedEntries();
    // Lazy creation of the dialog:
    if (diag == null) {
      createDialog();
    }
    cancelled = true;
    prepareDialog(entries.length > 0);
    Util.placeDialog(diag, frame);
    diag.setVisible(true);
    if (cancelled) {
      return;
    }

    Collection<BibtexEntry> entryList;
    // If all entries should be treated, change the entries array:
    if (all.isSelected()) {
      entryList = bp.database().getEntries();
    } else {
      entryList = Arrays.asList(entries);
    }
    String toSet = text.getText();
    if (toSet.isEmpty()) {
      toSet = null;
    }
    String[] fields = getFieldNames(field.getText().trim().toLowerCase());
    NamedCompound ce = new NamedCompound(Globals.lang("Set field"));
    if (rename.isSelected()) {
      if (fields.length > 1) {
        // TODO: message: can only rename a single field
      } else {
        ce.addEdit(
            Util.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected()));
      }
    } else {
      for (String field1 : fields) {
        ce.addEdit(
            Util.massSetField(
                entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected()));
      }
    }
    ce.end();
    bp.undoManager.addEdit(ce);
    bp.markBaseChanged();
  }
  /**
   * Cycle through all databases, and make sure everything is updated with the new type
   * customization. This includes making sure all entries have a valid type, that no obsolete entry
   * editors are around, and that the right-click menus' change type menu is up-to-date.
   */
  private void updateTypesForEntries(String typeName) {
    if (frame.getTabbedPane().getTabCount() == 0) {
      return;
    }
    for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
      BasePanel bp = (BasePanel) frame.getTabbedPane().getComponentAt(i);

      // Invalidate associated cached entry editor
      bp.entryEditors.remove(typeName);

      for (BibtexEntry entry : bp.database().getEntries()) {
        entry.updateType();
      }
    }
  }
Exemplo n.º 6
0
 @Override
 public void run() {
   for (int i = 0; i < databases; i++) {
     if (i < frame.getTabbedPane().getTabCount()) {
       // System.out.println("Base "+i);
       BasePanel panel = frame.baseAt(i);
       if (panel.getFile() == null) {
         frame.showBaseAt(i);
       }
       panel.runCommand("save");
       // TODO: can we find out whether the save was actually done or not?
       saved++;
     }
   }
 }
Exemplo n.º 7
0
 private void doMakePathsRelative(BibtexEntry entry, NamedCompound ce) {
   String oldValue = entry.getField(Globals.FILE_FIELD);
   if (oldValue == null) {
     return;
   }
   FileListTableModel flModel = new FileListTableModel();
   flModel.setContent(oldValue);
   if (flModel.getRowCount() == 0) {
     return;
   }
   boolean changed = false;
   for (int i = 0; i < flModel.getRowCount(); i++) {
     FileListEntry flEntry = flModel.getEntry(i);
     String oldFileName = flEntry.getLink();
     String newFileName =
         FileUtil.shortenFileName(
                 new File(oldFileName), panel.metaData().getFileDirectory(Globals.FILE_FIELD))
             .toString();
     if (!oldFileName.equals(newFileName)) {
       flEntry.setLink(newFileName);
       changed = true;
     }
   }
   if (changed) {
     String newValue = flModel.getStringRepresentation();
     assert (!oldValue.equals(newValue));
     entry.setField(Globals.FILE_FIELD, newValue);
     ce.addEdit(new UndoableFieldChange(entry, Globals.FILE_FIELD, oldValue, newValue));
   }
 }
Exemplo n.º 8
0
  public void init() {

    // Get entries and check if it makes sense to perform this operation
    entries = panel.getSelectedEntries();

    if (entries.length == 0) {

      database = panel.getDatabase();
      entries = database.getEntries().toArray(new BibtexEntry[] {});

      if (entries.length == 0) {

        JOptionPane.showMessageDialog(
            panel,
            Globals.lang("This operation requires at least one entry."),
            Globals.lang("Write XMP-metadata"),
            JOptionPane.ERROR_MESSAGE);
        goOn = false;
        return;

      } else {

        int response =
            JOptionPane.showConfirmDialog(
                panel,
                Globals.lang("Write XMP-metadata for all PDFs in current database?"),
                Globals.lang("Write XMP-metadata"),
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if (response != JOptionPane.YES_OPTION) {
          goOn = false;
          return;
        }
      }
    }

    errors = entriesChanged = skipped = 0;

    if (optDiag == null) {
      optDiag = new OptionsDialog(panel.frame().getFrame());
    }
    optDiag.open();

    panel.output(Globals.lang("Writing XMP metadata..."));
  }
Exemplo n.º 9
0
  public void update() {
    if (!goOn) return;

    panel.output(
        Globals.lang(
            "Finished writing XMP for %0 file (%1 skipped, %2 errors).",
            String.valueOf(entriesChanged), String.valueOf(skipped), String.valueOf(errors)));
  }
 public void listChanged(ListEvent<BibtexEntry> listEvent) {
   if (listEvent.getSourceList().size() == 1) {
     BibtexEntry entry = listEvent.getSourceList().get(0);
     // Find out which BasePanel the selected entry belongs to:
     BasePanel p = entryHome.get(entry);
     // Update the preview's metadata reference:
     preview.setMetaData(p.metaData());
     // Update the preview's entry:
     preview.setEntry(entry);
     contentPane.setDividerLocation(0.5f);
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             preview.scrollRectToVisible(toRect);
           }
         });
   }
 }
Exemplo n.º 11
0
 @Override
 public void init() {
   cancelled = false;
   modifiedEntriesCount = 0;
   int numSelected = panel.getSelectedEntries().length;
   if (numSelected == 0) { // None selected. Inform the user to select entries first.
     JOptionPane.showMessageDialog(
         frame,
         Localization.lang("First select entries to clean up."),
         Localization.lang("Cleanup entry"),
         JOptionPane.INFORMATION_MESSAGE);
     cancelled = true;
     return;
   }
   frame.block();
   panel.output(
       Localization.lang("Doing a cleanup for %0 entries...", Integer.toString(numSelected)));
 }
Exemplo n.º 12
0
  /**
   * This method performs the actual changes.
   *
   * @param panel
   * @param pr
   * @param fileDir The path to the file directory to set, or null if it should not be set.
   */
  private void makeChanges(
      BasePanel panel,
      ParserResult pr,
      boolean upgradePrefs,
      boolean upgradeDatabase,
      String fileDir) {

    if (upgradeDatabase) {
      // Update file links links in the database:
      NamedCompound ce =
          Util.upgradePdfPsToFile(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR);
      panel.undoManager.addEdit(ce);
      panel.markBaseChanged();
    }

    if (fileDir != null) {
      Globals.prefs.put(GUIGlobals.FILE_FIELD + "Directory", fileDir);
    }

    if (upgradePrefs) {
      // Exchange table columns:
      Globals.prefs.putBoolean(JabRefPreferences.PDF_COLUMN, Boolean.FALSE);
      Globals.prefs.putBoolean(JabRefPreferences.FILE_COLUMN, Boolean.TRUE);

      // Modify General fields if necessary:
      // If we don't find the file field, insert it at the bottom of the first tab:
      if (!showsFileInGenFields()) {
        String gfs = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "0");
        // System.out.println(gfs);
        StringBuilder sb = new StringBuilder(gfs);
        if (gfs.length() > 0) {
          sb.append(";");
        }
        sb.append(GUIGlobals.FILE_FIELD);
        Globals.prefs.put(JabRefPreferences.CUSTOM_TAB_FIELDS + "0", sb.toString());
        Globals.prefs.updateEntryEditorTabList();
        panel.frame().removeCachedEntryEditors();
      }
      panel.frame().setupAllTables();
    }
  }
Exemplo n.º 13
0
  public void run() {
    // net.sf.jabref.journals.JournalList.downloadJournalList(frame);

    BibtexEntry[] entries = panel.getSelectedEntries();
    if (entries == null) return;
    NamedCompound ce = new NamedCompound("Abbreviate journal names");
    int count = 0;
    for (BibtexEntry entry : entries) {
      if (Globals.journalAbbrev.abbreviate(panel.database(), entry, "journal", ce, iso)) count++;
      if (Globals.journalAbbrev.abbreviate(panel.database(), entry, "journaltitle", ce, iso))
        count++;
    }
    if (count > 0) {
      ce.end();
      panel.undoManager.addEdit(ce);
      panel.markBaseChanged();
      message = Globals.lang("Abbreviated %0 journal names.", String.valueOf(count));
    } else {
      message = Globals.lang("No journal names could be abbreviated.");
    }
  }
    public void mousePressed(MouseEvent e) {
      if (e.isPopupTrigger()) {
        processPopupTrigger(e);
        return;
      }

      // First find the row on which the user has clicked.
      final int row = entryTable.rowAtPoint(e.getPoint());

      // A double click on an entry should highlight the entry in its BasePanel:
      if (e.getClickCount() == 2) {
        // Get the selected entry:
        BibtexEntry toShow = model.getElementAt(row);
        // Look up which BasePanel it belongs to:
        BasePanel p = entryHome.get(toShow);
        // Show the correct tab in the main window:
        frame.showBasePanel(p);
        // Highlight the entry:
        p.highlightEntry(toShow);
      }
    }
Exemplo n.º 15
0
 public CleanUpAction(BasePanel panel) {
   this.panel = panel;
   this.frame = panel.frame();
   initOptionsPanel();
 }
Exemplo n.º 16
0
 public void init() {
   //  new FieldWeightDialog(frame).setVisible(true);
   panel.output("Abbreviating...");
 }
Exemplo n.º 17
0
  @Override
  public void run() {
    BasePanel panel = frame.basePanel();
    if (panel == null) {
      return;
    }
    if (panel.getSelectedEntries().length == 0) {
      message = Localization.lang("No entries selected.");
      getCallBack().update();
      return;
    }

    Map<String, IExportFormat> m = ExportFormats.getExportFormats();
    IExportFormat[] formats = new ExportFormat[m.size()];
    String[] array = new String[formats.length];

    int piv = 0;
    for (IExportFormat format : m.values()) {
      formats[piv] = format;
      array[piv] = format.getDisplayName();
      piv++;
    }

    JList list = new JList(array);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.setSelectionInterval(0, 0);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    int answer =
        JOptionPane.showOptionDialog(
            frame,
            list,
            Localization.lang("Select format"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            new String[] {Localization.lang("Ok"), Localization.lang("Cancel")},
            Localization.lang("Ok"));

    if (answer == JOptionPane.NO_OPTION) {
      return;
    }

    IExportFormat format = formats[list.getSelectedIndex()];

    // Set the global variable for this database's file directory before exporting,
    // so formatters can resolve linked files correctly.
    // (This is an ugly hack!)
    Globals.prefs.fileDirForDatabase =
        frame.basePanel().metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
    // Also store the database's file in a global variable:
    Globals.prefs.databaseFile = frame.basePanel().metaData().getFile();

    /*final boolean custom = (list.getSelectedIndex() >= Globals.STANDARD_EXPORT_COUNT);
    String dir = null;
    if (custom) {
        int index = list.getSelectedIndex() - Globals.STANDARD_EXPORT_COUNT;
        dir = (String) (Globals.prefs.customExports.getElementAt(index)[1]);
        File f = new File(dir);
        lfName = f.getName();
        lfName = lfName.substring(0, lfName.indexOf("."));
        // Remove file name - we want the directory only.
        dir = f.getParent() + System.getProperty("file.separator");
    }
    final String format = lfName,
            directory = dir;
    */
    File tmp = null;
    Reader reader = null;
    try {
      // To simplify the exporter API we simply do a normal export to a temporary
      // file, and read the contents afterwards:
      tmp = File.createTempFile("jabrefCb", ".tmp");
      tmp.deleteOnExit();
      BibtexEntry[] bes = panel.getSelectedEntries();
      HashSet<String> entries = new HashSet<String>(bes.length);
      for (BibtexEntry be : bes) {
        entries.add(be.getId());
      }

      // Write to file:
      format.performExport(database, panel.metaData(), tmp.getPath(), panel.getEncoding(), entries);
      // Read the file and put the contents on the clipboard:
      StringBuilder sb = new StringBuilder();
      reader = new InputStreamReader(new FileInputStream(tmp), panel.getEncoding());
      int s;
      while ((s = reader.read()) != -1) {
        sb.append((char) s);
      }
      ClipboardOwner owner =
          new ClipboardOwner() {

            @Override
            public void lostOwnership(Clipboard clipboard, Transferable content) {}
          };
      // StringSelection ss = new StringSelection(sw.toString());
      RtfSelection rs = new RtfSelection(sb.toString());
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner);
      message = Localization.lang("Entries exported to clipboard") + ": " + bes.length;

    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
      message = Localization.lang("Error exporting to clipboard");
    } finally {
      // Clean up:
      if (tmp != null) {
        tmp.delete();
      }
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Exemplo n.º 18
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);
   }
 }
Exemplo n.º 19
0
 public void run() {
   entry = basePanel.getSelectedEntries()[0];
   FindFullText fft = new FindFullText();
   result = fft.findFullText(entry);
 }
Exemplo n.º 20
0
  private void doRenamePDFs(BibtexEntry entry, NamedCompound ce) {
    // Extract the path
    String oldValue = entry.getField(Globals.FILE_FIELD);
    if (oldValue == null) {
      return;
    }
    FileListTableModel flModel = new FileListTableModel();
    flModel.setContent(oldValue);
    if (flModel.getRowCount() == 0) {
      return;
    }
    boolean changed = false;

    for (int i = 0; i < flModel.getRowCount(); i++) {
      String realOldFilename = flModel.getEntry(i).getLink();

      if (cleanUpRenamePDFonlyRelativePaths.isSelected()
          && (new File(realOldFilename).isAbsolute())) {
        continue;
      }

      String newFilename = Util.getLinkedFileName(panel.database(), entry);
      // String oldFilename = bes.getField(GUIGlobals.FILE_FIELD); // would have to be stored for
      // undoing purposes

      // Add extension to newFilename
      newFilename = newFilename + "." + flModel.getEntry(i).getType().getExtension();

      // get new Filename with path
      // Create new Path based on old Path and new filename
      File expandedOldFile =
          FileUtil.expandFilename(
              realOldFilename, panel.metaData().getFileDirectory(Globals.FILE_FIELD));
      if (expandedOldFile.getParent() == null) {
        // something went wrong. Just skip this entry
        continue;
      }
      String newPath =
          expandedOldFile
              .getParent()
              .concat(System.getProperty("file.separator"))
              .concat(newFilename);

      if (new File(newPath).exists()) {
        // we do not overwrite files
        // TODO: we could check here if the newPath file is linked with the current entry. And if
        // not, we could add a link
        continue;
      }

      // do rename
      boolean renameSuccessful = FileUtil.renameFile(expandedOldFile.toString(), newPath);

      if (renameSuccessful) {
        changed = true;

        // Change the path for this entry
        String description = flModel.getEntry(i).getDescription();
        ExternalFileType type = flModel.getEntry(i).getType();
        flModel.removeEntry(i);

        // we cannot use "newPath" to generate a FileListEntry as newPath is absolute, but we want
        // to keep relative paths whenever possible
        File parent = (new File(realOldFilename)).getParentFile();
        String newFileEntryFileName;
        if (parent == null) {
          newFileEntryFileName = newFilename;
        } else {
          newFileEntryFileName =
              parent.toString().concat(System.getProperty("file.separator")).concat(newFilename);
        }
        flModel.addEntry(i, new FileListEntry(description, newFileEntryFileName, type));
      } else {
        unsuccessfulRenames++;
      }
    }

    if (changed) {
      String newValue = flModel.getStringRepresentation();
      assert (!oldValue.equals(newValue));
      entry.setField(Globals.FILE_FIELD, newValue);
      // we put an undo of the field content here
      // the file is not being renamed back, which leads to inconsistencies
      // if we put a null undo object here, the change by "doMakePathsRelative" would overwrite the
      // field value nevertheless.
      ce.addEdit(new UndoableFieldChange(entry, Globals.FILE_FIELD, oldValue, newValue));
    }
  }
Exemplo n.º 21
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();
  }
Exemplo n.º 22
0
 public void update() {
   panel.output(message);
 }
Exemplo n.º 23
0
  @Override
  public void run() {
    if (cancelled) {
      return;
    }
    int choice = showCleanUpDialog();
    if (choice != JOptionPane.OK_OPTION) {
      cancelled = true;
      return;
    }
    storeSettings();
    boolean choiceCleanUpSuperscripts = cleanUpSuperscripts.isSelected();
    boolean choiceCleanUpDOI = cleanUpDOI.isSelected();
    boolean choiceCleanUpMonth = cleanUpMonth.isSelected();
    boolean choiceCleanUpPageNumbers = cleanUpPageNumbers.isSelected();
    boolean choiceCleanUpDate = cleanUpDate.isSelected();
    boolean choiceCleanUpUpgradeExternalLinks = cleanUpUpgradeExternalLinks.isSelected();
    boolean choiceMakePathsRelative = cleanUpMakePathsRelative.isSelected();
    boolean choiceRenamePDF = cleanUpRenamePDF.isSelected();
    boolean choiceConvertHTML = cleanUpHTML.isSelected();
    boolean choiceConvertCase = cleanUpCase.isSelected();
    boolean choiceConvertLaTeX = cleanUpLaTeX.isSelected();
    boolean choiceConvertUnits = cleanUpUnits.isSelected();
    boolean choiceConvertUnicode = cleanUpUnicode.isSelected();
    boolean choiceConvertToBiblatex = cleanUpBibLatex.isSelected();

    if (choiceRenamePDF && Globals.prefs.getBoolean(CleanUpAction.AKS_AUTO_NAMING_PDFS_AGAIN)) {
      CheckBoxMessage cbm =
          new CheckBoxMessage(
              Localization.lang("Auto-generating PDF-Names does not support undo. Continue?"),
              Localization.lang("Disable this confirmation dialog"),
              false);
      int answer =
          JOptionPane.showConfirmDialog(
              frame, cbm, Localization.lang("Autogenerate PDF Names"), JOptionPane.YES_NO_OPTION);
      if (cbm.isSelected()) {
        Globals.prefs.putBoolean(CleanUpAction.AKS_AUTO_NAMING_PDFS_AGAIN, false);
      }
      if (answer == JOptionPane.NO_OPTION) {
        cancelled = true;
        return;
      }
    }

    // first upgrade the external links
    // we have to use it separately as the Utils function generates a separate Named Compound
    if (choiceCleanUpUpgradeExternalLinks) {
      NamedCompound ce =
          Util.upgradePdfPsToFile(
              Arrays.asList(panel.getSelectedEntries()), new String[] {"pdf", "ps"});
      if (ce.hasEdits()) {
        panel.undoManager.addEdit(ce);
        panel.markBaseChanged();
        panel.updateEntryEditorIfShowing();
        panel.output(Localization.lang("Upgraded links."));
      }
    }

    for (BibtexEntry entry : panel.getSelectedEntries()) {
      // undo granularity is on entry level
      NamedCompound ce = new NamedCompound(Localization.lang("Cleanup entry"));

      if (choiceCleanUpSuperscripts) {
        doCleanUpSuperscripts(entry, ce);
      }
      if (choiceCleanUpDOI) {
        doCleanUpDOI(entry, ce);
      }
      if (choiceCleanUpMonth) {
        doCleanUpMonth(entry, ce);
      }
      if (choiceCleanUpPageNumbers) {
        doCleanUpPageNumbers(entry, ce);
      }
      if (choiceCleanUpDate) {
        doCleanUpDate(entry, ce);
      }

      fixWrongFileEntries(entry, ce);
      if (choiceMakePathsRelative) {
        doMakePathsRelative(entry, ce);
      }
      if (choiceRenamePDF) {
        doRenamePDFs(entry, ce);
      }
      if (choiceConvertHTML) {
        doConvertHTML(entry, ce);
      }
      if (choiceConvertUnits) {
        doConvertUnits(entry, ce);
      }
      if (choiceConvertCase) {
        doConvertCase(entry, ce);
      }
      if (choiceConvertLaTeX) {
        doConvertLaTeX(entry, ce);
      }
      if (choiceConvertUnicode) {
        doConvertUnicode(entry, ce);
      }
      if (choiceConvertToBiblatex) {
        convertToBiblatex(entry, ce);
      }

      ce.end();
      if (ce.hasEdits()) {
        modifiedEntriesCount++;
        panel.undoManager.addEdit(ce);
      }
    }
  }
Exemplo n.º 24
0
  /**
   * This method presents a dialog box explaining and offering to make the changes. If the user
   * confirms, the changes are performed.
   *
   * @param panel
   * @param pr
   */
  @Override
  public void performAction(BasePanel panel, ParserResult pr) {
    // Find out which actions should be offered:
    // Only offer to change Preferences if file column is not already visible:
    boolean offerChangeSettings =
        !Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN) || !showsFileInGenFields();
    // Only offer to upgrade links if the pdf/ps fields are used:
    boolean offerChangeDatabase =
        linksFound(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR);
    // If the "file" directory is not set, offer to migrate pdf/ps dir:
    boolean offerSetFileDir =
        !Globals.prefs.hasKey(GUIGlobals.FILE_FIELD + "Directory")
            && (Globals.prefs.hasKey("pdfDirectory") || Globals.prefs.hasKey("psDirectory"));

    if (!offerChangeDatabase && !offerChangeSettings && !offerSetFileDir) {
      return; // Nothing to do, just return.
    }

    JCheckBox changeSettings =
        new JCheckBox(
            Globals.lang("Change table column and General fields settings to use the new feature"),
            offerChangeSettings);
    JCheckBox changeDatabase =
        new JCheckBox(
            Globals.lang("Upgrade old external file links to use the new feature"),
            offerChangeDatabase);
    JCheckBox setFileDir =
        new JCheckBox(Globals.lang("Set main external file directory") + ":", offerSetFileDir);
    JTextField fileDir = new JTextField(30);
    JCheckBox doNotShowDialog =
        new JCheckBox(Globals.lang("Do not show these options in the future"), false);

    JPanel message = new JPanel();
    DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref", ""), message);
    // Keep the formatting of these lines. Otherwise, strings have to be translated again.
    // See updated JabRef_en.properties modifications by python syncLang.py -s -u
    b.append(
        new JLabel(
            "<html>"
                + Globals.lang("This database was written using an older version of JabRef.")
                + "<br>"
                + Globals.lang(
                    "The current version features a new way of handling links to external files.<br>To take advantage of this, your links must be changed into the new format, and<br>JabRef must be configured to show the new links.")
                + "<p>"
                + Globals.lang("Do you want JabRef to do the following operations?")
                + "</html>"));
    b.nextLine();
    if (offerChangeSettings) {
      b.append(changeSettings);
      b.nextLine();
    }
    if (offerChangeDatabase) {
      b.append(changeDatabase);
      b.nextLine();
    }
    if (offerSetFileDir) {
      if (Globals.prefs.hasKey("pdfDirectory")) {
        fileDir.setText(Globals.prefs.get("pdfDirectory"));
      } else {
        fileDir.setText(Globals.prefs.get("psDirectory"));
      }
      JPanel pan = new JPanel();
      pan.add(setFileDir);
      pan.add(fileDir);
      JButton browse = new JButton(Globals.lang("Browse"));
      browse.addActionListener(BrowseAction.buildForDir(fileDir));
      pan.add(browse);
      b.append(pan);
      b.nextLine();
    }
    b.append("");
    b.nextLine();
    b.append(doNotShowDialog);

    int answer =
        JOptionPane.showConfirmDialog(
            panel.frame(), message, Globals.lang("Upgrade file"), JOptionPane.YES_NO_OPTION);
    if (doNotShowDialog.isSelected()) {
      Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
    }

    if (answer == JOptionPane.YES_OPTION) {
      makeChanges(
          panel,
          pr,
          changeSettings.isSelected(),
          changeDatabase.isSelected(),
          setFileDir.isSelected() ? fileDir.getText() : null);
    }
  }
Exemplo n.º 25
0
  private BibtexEntry createNewEntry() {

    // Find out what type is wanted.
    EntryTypeDialog etd = new EntryTypeDialog(frame);
    // We want to center the dialog, to make it look nicer.
    Util.placeDialog(etd, frame);
    etd.setVisible(true);
    BibtexEntryType type = etd.getChoice();

    if (type != null) { // Only if the dialog was not cancelled.
      String id = Util.createNeutralId();
      final BibtexEntry be = new BibtexEntry(id, type);
      try {
        panel.database().insertEntry(be);

        // Set owner/timestamp if options are enabled:
        ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>();
        list.add(be);
        Util.setAutomaticFields(list, true, true, false);

        // Create an UndoableInsertEntry object.
        panel.undoManager.addEdit(new UndoableInsertEntry(panel.database(), be, panel));
        panel.output(
            Globals.lang("Added new")
                + " '"
                + type.getName().toLowerCase()
                + "' "
                + Globals.lang("entry")
                + ".");

        // We are going to select the new entry. Before that, make sure that we are in
        // show-entry mode. If we aren't already in that mode, enter the WILL_SHOW_EDITOR
        // mode which makes sure the selection will trigger display of the entry editor
        // and adjustment of the splitter.
        if (panel.getMode() != panel.SHOWING_EDITOR) {
          panel.setMode(panel.WILL_SHOW_EDITOR);
        }

        /*int row = entryTable.findEntry(be);
        if (row >= 0)
            // Selects the entry. The selection listener will open the editor.
             if (row >= 0) {
                try{
                    entryTable.setRowSelectionInterval(row, row);
                }catch(IllegalArgumentException e){
                    System.out.println("RowCount: " + entryTable.getRowCount());
                }

                //entryTable.setActiveRow(row);
                entryTable.ensureVisible(row);
             }
        else {
            // The entry is not visible in the table, perhaps due to a filtering search
            // or group selection. Show the entry editor anyway:
            panel.showEntry(be);
        }   */
        panel.showEntry(be);
        panel.markBaseChanged(); // The database just changed.
        new FocusRequester(panel.getEntryEditor(be));
        return be;
      } catch (KeyCollisionException ex) {
        Util.pr(ex.getMessage());
      }
    }
    return null;
  }
Exemplo n.º 26
0
  @Override
  public void actionPerformed(ActionEvent evt) {
    final BibtexEntry[] entries = m_panel.getSelectedEntries();
    final Vector<GroupTreeNode> removeGroupsNodes =
        new Vector<GroupTreeNode>(); // used only when moving

    if (m_move) {
      // collect warnings for removal
      Enumeration<GroupTreeNode> e = ((GroupTreeNode) m_node.getRoot()).preorderEnumeration();
      GroupTreeNode node;
      while (e.hasMoreElements()) {
        node = e.nextElement();
        if (!node.getGroup().supportsRemove()) {
          continue;
        }
        for (BibtexEntry entry : entries) {
          if (node.getGroup().contains(entry)) {
            removeGroupsNodes.add(node);
          }
        }
      }
      // warning for all groups from which the entries are removed, and
      // for the one to which they are added! hence the magical +1
      AbstractGroup[] groups = new AbstractGroup[removeGroupsNodes.size() + 1];
      for (int i = 0; i < removeGroupsNodes.size(); ++i) {
        groups[i] = removeGroupsNodes.elementAt(i).getGroup();
      }
      groups[groups.length - 1] = m_node.getGroup();
      if (!Util.warnAssignmentSideEffects(
          groups, entries, m_panel.getDatabase(), m_panel.frame())) {
        return; // user aborted operation
      }
    } else {
      // warn if assignment has undesired side effects (modifies a field != keywords)
      if (!Util.warnAssignmentSideEffects(
          new AbstractGroup[] {m_node.getGroup()},
          entries,
          m_panel.getDatabase(),
          m_panel.frame())) {
        return; // user aborted operation
      }
    }

    // if an editor is showing, its fields must be updated
    // after the assignment, and before that, the current
    // edit has to be stored:
    m_panel.storeCurrentEdit();

    NamedCompound undoAll = new NamedCompound(Globals.lang("change assignment of entries"));

    if (m_move) {
      // first remove
      for (int i = 0; i < removeGroupsNodes.size(); ++i) {
        GroupTreeNode node = removeGroupsNodes.elementAt(i);
        if (node.getGroup().containsAny(entries)) {
          undoAll.addEdit(node.removeFromGroup(entries));
        }
      }
      // then add
      AbstractUndoableEdit undoAdd = m_node.addToGroup(entries);
      if (undoAdd != null) {
        undoAll.addEdit(undoAdd);
      }
    } else {
      AbstractUndoableEdit undoAdd = m_node.addToGroup(entries);
      if (undoAdd == null) {
        return; // no changed made
      }
      undoAll.addEdit(undoAdd);
    }

    undoAll.end();

    m_panel.undoManager.addEdit(undoAll);
    m_panel.markBaseChanged();
    m_panel.updateEntryEditorIfShowing();
    m_panel.getGroupSelector().valueChanged(null);
  }
Exemplo n.º 27
0
  private boolean importPdfFiles(List<String> fileNames) {
    if (panel == null) return false;
    for (String fileName : fileNames) {
      List<BibtexEntry> xmpEntriesInFile = readXmpEntries(fileName);
      ImportDialog importDialog = new ImportDialog(dropRow, fileName);
      if (!hasXmpEntries(xmpEntriesInFile)) {
        importDialog.getRadioButtonXmp().setEnabled(false);
      }
      Tools.centerRelativeToWindow(importDialog, frame);
      importDialog.showDialog();
      if (importDialog.getResult() == JOptionPane.OK_OPTION) {
        if (importDialog.getRadioButtonXmp().isSelected()) {
          // SplDatabaseChangeListener dataListener = new SplDatabaseChangeListener(frame, panel,
          // entryTable, fileName);
          // panel.database().addDatabaseChangeListener(dataListener);
          ImportMenuItem importer = new ImportMenuItem(frame, (entryTable == null));
          importer.automatedImport(new String[] {fileName});

        } else if (importDialog.getRadioButtonMrDlib().isSelected()) {
          MetaDataListDialog metaDataListDialog = new MetaDataListDialog(fileName, true);
          Tools.centerRelativeToWindow(metaDataListDialog, frame);
          metaDataListDialog.showDialog();
          XmlDocuments documents = metaDataListDialog.getXmlDocuments();
          if (documents != null
              && documents.getDocuments() != null
              && documents.getDocuments().size() > 0
              && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) {
            int selected = metaDataListDialog.getTableMetadata().getSelectedRow();
            if (selected > -1 && selected < documents.getDocuments().size()) {
              XmlDocument document = documents.getDocuments().get(selected);
              String id = Util.createNeutralId();
              BibtexEntry entry = new BibtexEntry(id);
              if (fieldExists(document.getType())) {
                BibtexEntryType type = BibtexEntryType.getStandardType(document.getType());
                if (type == null) {
                  type = BibtexEntryType.ARTICLE;
                }
                entry.setType(type);
              } else {
                entry.setType(BibtexEntryType.ARTICLE);
              }
              ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>();
              list.add(entry);
              Util.setAutomaticFields(list, true, true, false);
              insertFields(entry.getRequiredFields(), entry, document);
              insertFields(entry.getGeneralFields(), entry, document);
              insertFields(entry.getOptionalFields(), entry, document);
              panel.database().insertEntry(entry);
              DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
              dfh.linkPdfToEntry(fileName, entryTable, entry);
              LabelPatternUtil.makeLabel(Globals.prefs.getKeyPattern(), panel.database(), entry);
            } else {
              createNewBlankEntry(fileName);
            }
          } else if (metaDataListDialog.getResult() == JOptionPane.CANCEL_OPTION) {
            continue;
          } else if (metaDataListDialog.getResult() == JOptionPane.NO_OPTION) {
            createNewBlankEntry(fileName);
          } else if (documents == null
              || documents.getDocuments() == null
              || documents.getDocuments().size() <= 0
                  && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) {
            createNewBlankEntry(fileName);
          }
        } else if (importDialog.getRadioButtonNoMeta().isSelected()) {
          createNewBlankEntry(fileName);
        } else if (importDialog.getRadioButtonUpdateEmptyFields().isSelected()) {
          MetaDataListDialog metaDataListDialog = new MetaDataListDialog(fileName, false);
          Tools.centerRelativeToWindow(metaDataListDialog, frame);
          metaDataListDialog.showDialog();
          XmlDocuments documents = metaDataListDialog.getXmlDocuments();
          if (documents != null
              && documents.getDocuments() != null
              && documents.getDocuments().size() > 0
              && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) {
            int selected = metaDataListDialog.getTableMetadata().getSelectedRow();
            if (selected > -1 && selected < documents.getDocuments().size()) {
              XmlDocument document = documents.getDocuments().get(selected);
              BibtexEntry entry = entryTable.getEntryAt(dropRow);
              if (fieldExists(document.getType())) {
                BibtexEntryType type = BibtexEntryType.getStandardType(document.getType());
                if (type != null) {
                  entry.setType(type);
                }
              }
              insertFields(entry.getRequiredFields(), entry, document);
              insertFields(entry.getGeneralFields(), entry, document);
              insertFields(entry.getOptionalFields(), entry, document);

              DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
              dfh.linkPdfToEntry(fileName, entryTable, dropRow);
            }
          }
        } else if (importDialog.getRadioButtononlyAttachPDF().isSelected()) {
          DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
          dfh.linkPdfToEntry(fileName, entryTable, dropRow);
        }
      }
    }
    return true;
  }
Exemplo n.º 28
0
 public void init() throws Throwable {
   basePanel.output(Globals.lang("Looking for full text document..."));
 }