コード例 #1
0
  public boolean openLink() {
    frame.output(Localization.lang("External viewer called") + ".");
    try {
      ExternalFileType type = fileType;
      if (this.fileType == null) {
        if (this.fieldName == null) {
          // We don't already know the file type, so we try to deduce it from the extension:
          File file = new File(link);
          // We try to check the extension for the file:
          String name = file.getName();
          int pos = name.indexOf('.');
          String extension =
              (pos >= 0) && (pos < (name.length() - 1))
                  ? name.substring(pos + 1).trim().toLowerCase()
                  : null;
          // Now we know the extension, check if it is one we know about:
          type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension);
          fileType = type;
        } else {
          JabRefDesktop.openExternalViewer(
              frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData(), link, fieldName);
          return true;
        }
      }

      if (type instanceof UnknownExternalFileType) {
        return JabRefDesktop.openExternalFileUnknown(
            frame, entry, metaData, link, (UnknownExternalFileType) type);
      } else {
        return JabRefDesktop.openExternalFileAnyFormat(metaData, link, type);
      }

    } catch (IOException e1) {
      // See if we should show an error message concerning the application to open the
      // link with. We check if the file type is set, and if the file type has a non-empty
      // application link. If that link is referred by the error message, we can assume
      // that the problem is in the open-with-application setting:
      if ((fileType != null)
          && (fileType.getOpenWith() != null)
          && !fileType.getOpenWith().isEmpty()
          && e1.getMessage().contains(fileType.getOpenWith())) {

        JOptionPane.showMessageDialog(
            frame,
            Localization.lang(
                "Unable to open link. "
                    + "The application '%0' associated with the file type '%1' could not be called.",
                fileType.getOpenWith(), fileType.getName()),
            Localization.lang("Could not open link"),
            JOptionPane.ERROR_MESSAGE);
        return false;
      }

      LOGGER.warn("Unable to open link", e1);
    }
    return false;
  }
コード例 #2
0
ファイル: PreviewPanel.java プロジェクト: chochreiner/jabref
  private void createPreviewPane() {
    previewPane =
        new JEditorPane() {
          @Override
          public Dimension getPreferredScrollableViewportSize() {
            return getPreferredSize();
          }
        };
    previewPane.setMargin(new Insets(3, 3, 3, 3));

    previewPane.setComponentPopupMenu(createPopupMenu());

    previewPane.setEditable(false);
    previewPane.setDragEnabled(
        true); // this has an effect only, if no custom transfer handler is registered. We keep the
               // statement if the transfer handler is removed.
    previewPane.setContentType("text/html");
    previewPane.addHyperlinkListener(
        hyperlinkEvent -> {
          if ((hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
              && PreviewPanel.this.databaseContext.isPresent()) {
            try {
              String address = hyperlinkEvent.getURL().toString();
              JabRefDesktop.openExternalViewer(
                  PreviewPanel.this.databaseContext.get(), address, "url");
            } catch (IOException e) {
              LOGGER.warn("Could not open external viewer", e);
            }
          }
        });
  }
コード例 #3
0
ファイル: DonateAction.java プロジェクト: pseudoacacia/jabref
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     JabRefDesktop.openBrowser(DONATION_LINK);
   } catch (IOException ex) {
     LOGGER.warn("Could not open browser", ex);
     JabRef.jrf.getCurrentBasePanel().output(Localization.lang("Could not open browser."));
   }
 }
コード例 #4
0
  /**
   * Set up a mouse listener for opening an external viewer for with with EXTRA_EXTERNAL
   *
   * @param fieldEditor
   * @param panel
   * @return
   */
  public static Optional<JComponent> getExternalExtraComponent(
      BasePanel panel, FieldEditor fieldEditor) {
    JPanel controls = new JPanel();
    controls.setLayout(new BorderLayout());
    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."));
          }
        });

    controls.add(button, BorderLayout.SOUTH);

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

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

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

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

              private void checkUrl() {
                if (URLUtil.isURL(url.getText())) {
                  button.setEnabled(true);
                } else {
                  button.setEnabled(false);
                }
              }
            });

    return Optional.of(controls);
  }
コード例 #5
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;
     }
   }
 }
コード例 #6
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);
  }