コード例 #1
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
 @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();
 }
コード例 #2
0
ファイル: SearchManager2.java プロジェクト: steog88/jabref
    @Override
    public void run() {
      if (!searchAllBases.isSelected()) {
        // Search only the current database:
        for (BibtexEntry entry : panel.getDatabase().getEntries()) {

          boolean hit = rule.applyRule(searchTerm, entry) > 0;
          entry.setSearchHit(hit);
          if (hit) {
            hits++;
          }
        }
      } else {
        // Search all databases:
        for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
          BasePanel p = frame.baseAt(i);
          for (BibtexEntry entry : p.getDatabase().getEntries()) {

            boolean hit = rule.applyRule(searchTerm, entry) > 0;
            entry.setSearchHit(hit);
            if (hit) {
              hits++;
            }
          }
        }
      }
    }
コード例 #3
0
ファイル: SearchManager2.java プロジェクト: steog88/jabref
 @Override
 public void setActiveBasePanel(BasePanel panel) {
   super.setActiveBasePanel(panel);
   if (panel != null) {
     escape.setEnabled(panel.isShowingFloatSearch() || panel.isShowingFilterSearch());
   } else {
     escape.setEnabled(false);
   }
 }
コード例 #4
0
  private void applyChanges() {
    boolean changedFieldSet = false; // Watch if we need to rebuild entry editors

    // First remove the mappings for fields that have been deleted.
    // If these were re-added, they will be added below, so it doesn't
    // cause any harm to remove them here.
    for (String fieldName : removedFields) {
      metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName);
      changedFieldSet = true;
    }

    // Cycle through all fields that we have created listmodels for:
    for (String fieldName : wordListModels.keySet()) {
      // For each field name, store the values:
      if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) {
        continue;
      }
      DefaultListModel<String> lm = wordListModels.get(fieldName);
      int start = 0;
      // Avoid storing the <new word> marker if it is there:
      if (!lm.isEmpty()) {
        while ((start < lm.size()) && lm.get(start).equals(WORD_FIRSTLINE_TEXT)) {
          start++;
        }
      }
      Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName);
      boolean bNewField = false;
      if (data == null) {
        bNewField = true;
        data = new Vector<>();
        changedFieldSet = true;

      } else {
        data.clear();
      }
      for (int wrd = start; wrd < lm.size(); wrd++) {
        String word = lm.get(wrd);
        data.add(word);
      }
      if (bNewField) {
        metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data);
      }
    }

    // System.out.println("TODO: remove metadata for removed selector field.");
    panel.markNonUndoableBaseChanged();

    // Update all selectors in the current BasePanel.
    if (changedFieldSet) {
      panel.rebuildAllEntryEditors();
    } else {
      panel.updateAllContentSelectors();
    }
    panel.getAutoCompleters().addContentSelectorValuesToAutoCompleters(panel.metaData);
  }
コード例 #5
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();
  }
コード例 #6
0
  /**
   * 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();
      }
    }
  }
コード例 #7
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++;
     }
   }
 }
コード例 #8
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
 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));
   }
 }
コード例 #9
0
ファイル: RightClickMenu.java プロジェクト: tnoz/jabref
  /** 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);
  }
コード例 #10
0
ファイル: WriteXMPAction.java プロジェクト: GeorgLink/Desktop
  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..."));
  }
コード例 #11
0
ファイル: WriteXMPAction.java プロジェクト: GeorgLink/Desktop
  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)));
  }
コード例 #12
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
 @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)));
 }
コード例 #13
0
ファイル: CorrectedPanel.java プロジェクト: craftoid/jbead
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   setHints(g);
   symbolfont = SymbolFont.get(gridy);
   offsetx = getOffsetX();
   left = getLeft();
   paintBeads(g);
 }
コード例 #14
0
ファイル: DbImportAction.java プロジェクト: DevFactory/jabref
 // run third, on EDT:
 @Override
 public void update() {
   if (databases == null) {
     return;
   }
   for (DBImporterResult res : databases) {
     database = res.getDatabase();
     metaData = res.getMetaData();
     if (database != null) {
       BasePanel pan =
           frame.addTab(database, null, metaData, Globals.prefs.getDefaultEncoding(), true);
       pan.getBibDatabaseContext().getMetaData().setDBStrings(dbs);
       frame.setTabTitle(pan, res.getName() + "(Imported)", "Imported DB");
       pan.markBaseChanged();
     }
   }
   frame.output(
       Localization.lang(
           "Imported %0 databases successfully", Integer.toString(databases.size())));
 }
コード例 #15
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();
    }
  }
コード例 #16
0
    @Override
    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() {

              @Override
              public void run() {
                preview.scrollRectToVisible(toRect);
              }
            });
      }
    }
コード例 #17
0
 @Override
 public void mouseClicked(MouseEvent e) {
   if (e.isPopupTrigger()) {
     processPopupTrigger(e);
     return;
   }
   // if (e.)
   final int col = entryTable.columnAtPoint(e.getPoint());
   final int 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(Globals.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) {
             JabRefDesktop.openExternalViewer(p.metaData(), (String) link, "url");
           }
         } catch (IOException ex) {
           ex.printStackTrace();
         }
         break;
     }
   }
 }
コード例 #18
0
    @Override
    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);
      }
    }
コード例 #19
0
    /**
     * 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(Globals.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().isEmpty())) {
            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());
      }
    }
コード例 #20
0
ファイル: PreviewPanel.java プロジェクト: chochreiner/jabref
  /**
   * @param panel (may be null) If not given no toolbar is shown on the right hand side.
   * @param databaseContext (may be null) Used for resolving pdf directories for links.
   * @param layoutFile (must be given) Used for layout
   */
  public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, String layoutFile) {
    super(new BorderLayout(), true);

    this.databaseContext = Optional.ofNullable(databaseContext);
    this.layoutFile = Objects.requireNonNull(layoutFile);
    updateLayout();

    this.closeAction = new CloseAction();
    this.printAction = new PrintAction();
    this.copyPreviewAction = new CopyPreviewAction();

    this.basePanel = Optional.ofNullable(panel);

    createPreviewPane();

    if (panel != null) {
      // dropped files handler only created for main window
      // not for Windows as like the search results window
      this.previewPane.setTransferHandler(
          new PreviewPanelTransferHandler(
              panel.frame(), this, this.previewPane.getTransferHandler()));
    }

    // Set up scroll pane for preview pane
    scrollPane =
        new JScrollPane(
            previewPane,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(null);

    /*
     * If we have been given a panel and the preference option
     * previewPrintButton is set, show the tool bar
     */
    if (this.basePanel.isPresent()
        && JabRefPreferences.getInstance().getBoolean(JabRefPreferences.PREVIEW_PRINT_BUTTON)) {
      add(createToolBar(), BorderLayout.LINE_START);
    }

    add(scrollPane, BorderLayout.CENTER);

    this.createKeyBindings();
  }
コード例 #21
0
 /**
  * Used for updating an existing Dialog
  *
  * @param panel the panel to read the data from
  */
 public void setPanel(BasePanel panel) {
   this.panel = panel;
   this.metaData = panel.metaData();
   AbstractLabelPattern keypatterns = metaData.getLabelPattern();
   labelPatternPanel.setValues(keypatterns);
 }
コード例 #22
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
  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));
    }
  }
コード例 #23
0
ファイル: SearchManager2.java プロジェクト: steog88/jabref
    @Override
    public void update() {
      panel.output(Globals.lang("Searched database. Number of hits") + ": " + hits);

      // Show the result in the chosen way:
      if (searchAllBases.isSelected()) {
        // Search all databases. This means we need to use the search results dialog.
        // Turn off other search mode, if activated:
        if (startedFloatSearch) {
          panel.mainTable.stopShowingFloatSearch();
          startedFloatSearch = false;
        }
        if (startedFilterSearch) {
          panel.stopShowingSearchResults();
          startedFilterSearch = false;
        }
        // Make sure the search dialog is instantiated and cleared:
        instantiateSearchDialog();
        searchDialog.clear();
        for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
          BasePanel p = frame.baseAt(i);
          for (BibtexEntry entry : p.getDatabase().getEntries()) {
            if (entry.isSearchHit()) {
              searchDialog.addEntry(entry, p);
            }
          }
        }
        searchDialog.selectFirstEntry();
        searchDialog.setVisible(true);
      } else if (showResultsInDialog.isSelected()) {
        // Turn off other search mode, if activated:
        if (startedFloatSearch) {
          panel.mainTable.stopShowingFloatSearch();
          startedFloatSearch = false;
        }
        if (startedFilterSearch) {
          panel.stopShowingSearchResults();
          startedFilterSearch = false;
        }
        // Make sure the search dialog is instantiated and cleared:
        instantiateSearchDialog();
        searchDialog.clear();
        for (BibtexEntry entry : panel.getDatabase().getEntries()) {
          if (entry.isSearchHit()) {
            searchDialog.addEntry(entry, panel);
          }
        }
        searchDialog.selectFirstEntry();
        searchDialog.setVisible(true);
      } else if (hideSearch.isSelected()) {
        // Filtering search - removes non-hits from the table:
        if (startedFloatSearch) {
          panel.mainTable.stopShowingFloatSearch();
          startedFloatSearch = false;
        }
        startedFilterSearch = true;
        panel.setSearchMatcher(new SearchMatcher());

      } else {
        // Float search - floats hits to the top of the table:
        if (startedFilterSearch) {
          panel.stopShowingSearchResults();
          startedFilterSearch = false;
        }
        startedFloatSearch = true;
        panel.mainTable.showFloatSearch(new SearchMatcher());
      }

      // Afterwards, select all text in the search field.
      searchField.select(0, searchField.getText().length());
    }
コード例 #24
0
  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);
    }
  }
コード例 #25
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
  @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);
      }
    }
  }
コード例 #26
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
 public CleanUpAction(BasePanel panel) {
   this.panel = panel;
   this.frame = panel.frame();
   initOptionsPanel();
 }
コード例 #27
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);
    }
  }
コード例 #28
0
ファイル: WriteXMPAction.java プロジェクト: GeorgLink/Desktop
  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();
  }
コード例 #29
0
ファイル: PdfImporter.java プロジェクト: kifetew/SWAT
  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;
  }
コード例 #30
0
ファイル: PdfImporter.java プロジェクト: kifetew/SWAT
  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;
  }