Exemplo n.º 1
0
  /**
   * Add button for fetching by ISBN
   *
   * @param fieldEditor
   * @param panel
   * @return
   */
  public static Optional<JComponent> getEprintExtraComponent(
      BasePanel panel, EntryEditor entryEditor, FieldEditor fieldEditor) {
    // fetch bibtex data
    JButton fetchButton =
        new JButton(
            Localization.lang(
                "Get BibTeX data from %0", FieldName.getDisplayName(FieldName.EPRINT)));
    fetchButton.setEnabled(false);
    fetchButton.addActionListener(
        actionEvent -> {
          BibEntry entry = entryEditor.getEntry();
          new FetchAndMergeEntry(entry, panel, FieldName.EPRINT);
        });

    // enable/disable button
    JTextComponent eprint = (JTextComponent) fieldEditor;

    eprint
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              @Override
              public void changedUpdate(DocumentEvent documentEvent) {
                checkEprint();
              }

              @Override
              public void insertUpdate(DocumentEvent documentEvent) {
                checkEprint();
              }

              @Override
              public void removeUpdate(DocumentEvent documentEvent) {
                checkEprint();
              }

              private void checkEprint() {
                if ((eprint.getText() == null) || eprint.getText().trim().isEmpty()) {
                  fetchButton.setEnabled(false);
                } else {
                  fetchButton.setEnabled(true);
                }
              }
            });

    return Optional.of(fetchButton);
  }
Exemplo n.º 2
0
  /**
   * Add button for fetching by ISBN
   *
   * @param fieldEditor
   * @param panel
   * @return
   */
  public static Optional<JComponent> getIsbnExtraComponent(
      BasePanel panel, EntryEditor entryEditor, FieldEditor fieldEditor) {
    // fetch bibtex data
    JButton fetchButton =
        new JButton(
            Localization.lang("Get BibTeX data from %0", FieldName.getDisplayName(FieldName.ISBN)));
    fetchButton.setEnabled(false);
    fetchButton.addActionListener(
        actionEvent -> {
          BibEntry entry = entryEditor.getEntry();
          new FetchAndMergeEntry(entry, panel, FieldName.ISBN);
        });

    // enable/disable button
    JTextComponent isbn = (JTextComponent) fieldEditor;

    isbn.getDocument()
        .addDocumentListener(
            new DocumentListener() {

              @Override
              public void changedUpdate(DocumentEvent documentEvent) {
                checkIsbn();
              }

              @Override
              public void insertUpdate(DocumentEvent documentEvent) {
                checkIsbn();
              }

              @Override
              public void removeUpdate(DocumentEvent documentEvent) {
                checkIsbn();
              }

              private void checkIsbn() {
                ISBN isbnString = new ISBN(isbn.getText());
                if (isbnString.isValidFormat()) {
                  fetchButton.setEnabled(true);
                } else {
                  fetchButton.setEnabled(false);
                }
              }
            });

    return Optional.of(fetchButton);
  }
Exemplo n.º 3
0
  /**
   * Set up a mouse listener for opening an external viewer and fetching by DOI
   *
   * @param fieldEditor
   * @param panel
   * @return
   */
  public static Optional<JComponent> getDoiExtraComponent(
      BasePanel panel, EntryEditor entryEditor, FieldEditor fieldEditor) {
    JPanel controls = new JPanel();
    controls.setLayout(new BorderLayout());
    // open doi link
    JButton button = new JButton(Localization.lang("Open"));
    button.setEnabled(false);
    button.addActionListener(
        actionEvent -> {
          try {
            JabRefDesktop.openExternalViewer(
                panel.getBibDatabaseContext(), fieldEditor.getText(), fieldEditor.getFieldName());
          } catch (IOException ex) {
            panel.output(Localization.lang("Unable to open link."));
          }
        });
    // lookup doi
    JButton doiButton = new JButton(Localization.lang("Lookup DOI"));
    doiButton.addActionListener(
        actionEvent -> {
          Optional<DOI> doi = DOI.fromBibEntry(entryEditor.getEntry());
          if (doi.isPresent()) {
            entryEditor.getEntry().setField(FieldName.DOI, doi.get().getDOI());
          } else {
            panel
                .frame()
                .setStatus(
                    Localization.lang("No %0 found", FieldName.getDisplayName(FieldName.DOI)));
          }
        });
    // fetch bibtex data
    JButton fetchButton =
        new JButton(
            Localization.lang("Get BibTeX data from %0", FieldName.getDisplayName(FieldName.DOI)));
    fetchButton.setEnabled(false);
    fetchButton.addActionListener(
        actionEvent -> {
          BibEntry entry = entryEditor.getEntry();
          new FetchAndMergeEntry(entry, panel, FieldName.DOI);
        });

    controls.add(button, BorderLayout.NORTH);
    controls.add(doiButton, BorderLayout.CENTER);
    controls.add(fetchButton, BorderLayout.SOUTH);

    // enable/disable button
    JTextComponent doi = (JTextComponent) fieldEditor;

    doi.getDocument()
        .addDocumentListener(
            new DocumentListener() {
              @Override
              public void changedUpdate(DocumentEvent documentEvent) {
                checkDoi();
              }

              @Override
              public void insertUpdate(DocumentEvent documentEvent) {
                checkDoi();
              }

              @Override
              public void removeUpdate(DocumentEvent documentEvent) {
                checkDoi();
              }

              private void checkDoi() {
                Optional<DOI> doiUrl = DOI.build(doi.getText());
                if (doiUrl.isPresent()) {
                  button.setEnabled(true);
                  fetchButton.setEnabled(true);
                } else {
                  button.setEnabled(false);
                  fetchButton.setEnabled(false);
                }
              }
            });

    return Optional.of(controls);
  }