Пример #1
0
  /**
   * Unabbreviate the journal name of the given entry.
   *
   * @param entry The entry to be treated.
   * @param fieldName The field name (e.g. "journal")
   * @param ce If the entry is changed, add an edit to this compound.
   * @return true if the entry was changed, false otherwise.
   */
  public boolean unabbreviate(
      BibDatabase database, BibEntry entry, String fieldName, CompoundEdit ce) {
    if (!entry.hasField(fieldName)) {
      return false;
    }
    String text = entry.getFieldOptional(fieldName).get();
    String origText = text;
    if (database != null) {
      text = database.resolveForStrings(text);
    }

    if (!journalAbbreviationRepository.isKnownName(text)) {
      return false; // cannot do anything if it is not known
    }

    if (!journalAbbreviationRepository.isAbbreviatedName(text)) {
      return false; // cannot unabbreviate unabbreviated name.
    }

    Abbreviation abbreviation =
        journalAbbreviationRepository.getAbbreviation(text).get(); // must be here
    String newText = abbreviation.getName();
    entry.setField(fieldName, newText);
    ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText));
    return true;
  }
  private void setupUserTable() {
    JournalAbbreviationRepository userAbbr = new JournalAbbreviationRepository();
    String filename = personalFile.getText();
    if (!"".equals(filename) && new File(filename).exists()) {
      try {
        userAbbr.readJournalListFromFile(new File(filename));
      } catch (FileNotFoundException e) {
        LOGGER.warn("Problem reading abbreviation file", e);
      }
    }

    tableModel.setJournals(userAbbr.getAbbreviations());
    userTable = new JTable(tableModel);
    userTable.addMouseListener(tableModel.getMouseListener());
    userPanel.add(new JScrollPane(userTable), BorderLayout.CENTER);
  }
Пример #3
0
  /**
   * Add controls for switching between abbreviated and full journal names. If this field also has a
   * FieldContentSelector, we need to combine these.
   *
   * @param panel
   * @param editor
   * @param entry
   * @param storeFieldAction
   * @return
   */
  public static Optional<JComponent> getJournalExtraComponent(
      JabRefFrame frame,
      BasePanel panel,
      FieldEditor editor,
      BibEntry entry,
      Set<FieldContentSelector> contentSelectors,
      StoreFieldAction storeFieldAction) {
    JPanel controls = new JPanel();
    controls.setLayout(new BorderLayout());
    if (!panel
        .getBibDatabaseContext()
        .getMetaData()
        .getContentSelectorValuesForField(editor.getFieldName())
        .isEmpty()) {
      FieldContentSelector ws =
          new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false, ", ");
      contentSelectors.add(ws);
      controls.add(ws, BorderLayout.NORTH);
    }

    // Button to toggle abbreviated/full journal names
    JButton button = new JButton(Localization.lang("Toggle abbreviation"));
    button.setToolTipText(ABBREVIATION_TOOLTIP_TEXT);
    button.addActionListener(
        actionEvent -> {
          String text = editor.getText();
          JournalAbbreviationRepository abbreviationRepository =
              Globals.journalAbbreviationLoader.getRepository(
                  Globals.prefs.getJournalAbbreviationPreferences());
          if (abbreviationRepository.isKnownName(text)) {
            String s = abbreviationRepository.getNextAbbreviation(text).orElse(text);

            if (s != null) {
              editor.setText(s);
              storeFieldAction.actionPerformed(new ActionEvent(editor, 0, ""));
              panel
                  .getUndoManager()
                  .addEdit(new UndoableFieldChange(entry, editor.getFieldName(), text, s));
            }
          }
        });

    controls.add(button, BorderLayout.SOUTH);
    return Optional.of(controls);
  }