コード例 #1
0
 /**
  * Return a dropdown list with the month names for fields with EXTRA_MONTH
  *
  * @param fieldEditor
  * @param entryEditor
  * @param type
  * @return
  */
 public static Optional<JComponent> getMonthExtraComponent(
     FieldEditor fieldEditor, EntryEditor entryEditor, BibDatabaseMode type) {
   final String[] options = new String[13];
   options[0] = Localization.lang("Select");
   for (int i = 1; i <= 12; i++) {
     options[i] = MonthUtil.getMonthByNumber(i).fullName;
   }
   JComboBox<String> month = new JComboBox<>(options);
   month.addActionListener(
       actionEvent -> {
         int monthnumber = month.getSelectedIndex();
         if (monthnumber >= 1) {
           if (type == BibDatabaseMode.BIBLATEX) {
             fieldEditor.setText(String.valueOf(monthnumber));
           } else {
             fieldEditor.setText(MonthUtil.getMonthByNumber(monthnumber).bibtexFormat);
           }
         } else {
           fieldEditor.setText("");
         }
         entryEditor.updateField(fieldEditor);
         month.setSelectedIndex(0);
       });
   return Optional.of(month);
 }
コード例 #2
0
 public void focusLost(FocusEvent e) {
   synchronized (this) {
     if (c != null) {
       c.getDocument().removeDocumentListener(d);
       c = null;
       d = null;
     }
   }
   if (!e.isTemporary()) parent.updateField(e.getSource());
 }
コード例 #3
0
 /**
  * Return a dropdown list containing Yes and No for fields with EXTRA_YES_NO
  *
  * @param fieldEditor
  * @param entryEditor
  * @return
  */
 public static Optional<JComponent> getYesNoExtraComponent(
     FieldEditor fieldEditor, EntryEditor entryEditor) {
   final String[] options = {"", "Yes", "No"};
   JComboBox<String> yesno = new JComboBox<>(options);
   yesno.addActionListener(
       actionEvent -> {
         fieldEditor.setText(((String) yesno.getSelectedItem()).toLowerCase());
         entryEditor.updateField(fieldEditor);
       });
   return Optional.of(yesno);
 }
コード例 #4
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);
  }
コード例 #5
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);
  }
コード例 #6
0
 /**
  * Return a dropdown list with the gender alternatives for fields with GENDER
  *
  * @param fieldEditor
  * @param entryEditor
  * @return
  */
 public static Optional<JComponent> getGenderExtraComponent(
     FieldEditor fieldEditor, EntryEditor entryEditor) {
   final String[] optionValues = {"", "sf", "sm", "sp", "pf", "pm", "pn", "pp"};
   final String[] optionDescriptions = {
     Localization.lang("Select"),
     Localization.lang("Female name"),
     Localization.lang("Male name"),
     Localization.lang("Neuter name"),
     Localization.lang("Female names"),
     Localization.lang("Male names"),
     Localization.lang("Neuter names"),
     Localization.lang("Mixed names")
   };
   JComboBox<String> gender = new JComboBox<>(optionDescriptions);
   gender.addActionListener(
       actionEvent -> {
         fieldEditor.setText(optionValues[gender.getSelectedIndex()]);
         entryEditor.updateField(fieldEditor);
       });
   return Optional.of(gender);
 }
コード例 #7
0
 /**
  * Return a dropdown list with the alternatives for pagination type fields
  *
  * @param fieldEditor
  * @param entryEditor
  * @return
  */
 public static Optional<JComponent> getPaginationExtraComponent(
     FieldEditor fieldEditor, EntryEditor entryEditor) {
   final String[] optionValues = {
     "", "page", "column", "line", "verse", "section", "paragraph", "none"
   };
   final String[] optionDescriptions = {
     Localization.lang("Select"),
     Localization.lang("Page"),
     Localization.lang("Column"),
     Localization.lang("Line"),
     Localization.lang("Verse"),
     Localization.lang("Section"),
     Localization.lang("Paragraph"),
     Localization.lang("None")
   };
   JComboBox<String> pagination = new JComboBox<>(optionDescriptions);
   pagination.addActionListener(
       actionEvent -> {
         fieldEditor.setText(optionValues[pagination.getSelectedIndex()]);
         entryEditor.updateField(fieldEditor);
       });
   return Optional.of(pagination);
 }
コード例 #8
0
 /**
  * Return a dropdown list with the alternatives for editor type fields
  *
  * @param fieldEditor
  * @param entryEditor
  * @return
  */
 public static Optional<JComponent> getEditorTypeExtraComponent(
     FieldEditor fieldEditor, EntryEditor entryEditor) {
   final String[] optionValues = {
     "", "editor", "compiler", "founder", "continuator", "redactor", "reviser", "collaborator"
   };
   final String[] optionDescriptions = {
     Localization.lang("Select"),
     Localization.lang("Editor"),
     Localization.lang("Compiler"),
     Localization.lang("Founder"),
     Localization.lang("Continuator"),
     Localization.lang("Redactor"),
     Localization.lang("Reviser"),
     Localization.lang("Collaborator")
   };
   JComboBox<String> editorType = new JComboBox<>(optionDescriptions);
   editorType.addActionListener(
       actionEvent -> {
         fieldEditor.setText(optionValues[editorType.getSelectedIndex()]);
         entryEditor.updateField(fieldEditor);
       });
   return Optional.of(editorType);
 }
コード例 #9
0
ファイル: MoveFileAction.java プロジェクト: kifetew/SWAT
  public void actionPerformed(ActionEvent event) {
    int selected = editor.getSelectedRow();
    if (selected == -1) return;
    FileListEntry flEntry = editor.getTableModel().getEntry(selected);
    // Check if the current file exists:
    String ln = flEntry.getLink();
    boolean httpLink = ln.toLowerCase().startsWith("http");
    if (httpLink) {
      // TODO: notify that this operation cannot be done on remote links

    }

    // Get an absolute path representation:
    String dir = frame.basePanel().metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
    if ((dir == null) || (dir.trim().length() == 0) || !(new File(dir)).exists()) {
      JOptionPane.showMessageDialog(
          frame,
          Globals.lang("File_directory_is_not_set_or_does_not_exist!"),
          Globals.lang("Move/Rename file"),
          JOptionPane.ERROR_MESSAGE);
      return;
    }
    File file = new File(ln);
    if (!file.isAbsolute()) {
      file = Util.expandFilename(ln, new String[] {dir});
    }
    if ((file != null) && file.exists()) {
      // Ok, we found the file. Now get a new name:
      String extension = null;
      if (flEntry.getType() != null) extension = "." + flEntry.getType().getExtension();

      File newFile = null;
      boolean repeat = true;
      while (repeat) {
        repeat = false;
        String chosenFile;
        if (toFileDir) {
          String suggName = eEditor.getEntry().getCiteKey() + extension;
          CheckBoxMessage cbm =
              new CheckBoxMessage(
                  Globals.lang("Move file to file directory?"),
                  Globals.lang("Rename to '%0'", suggName),
                  Globals.prefs.getBoolean("renameOnMoveFileToFileDir"));
          int answer;
          // Only ask about renaming file if the file doesn't have the proper name already:
          if (!suggName.equals(file.getName()))
            answer =
                JOptionPane.showConfirmDialog(
                    frame, cbm, Globals.lang("Move/Rename file"), JOptionPane.YES_NO_OPTION);
          else
            answer =
                JOptionPane.showConfirmDialog(
                    frame,
                    Globals.lang("Move file to file directory?"),
                    Globals.lang("Move/Rename file"),
                    JOptionPane.YES_NO_OPTION);
          if (answer != JOptionPane.YES_OPTION) return;
          Globals.prefs.putBoolean("renameOnMoveFileToFileDir", cbm.isSelected());
          StringBuilder sb = new StringBuilder(dir);
          if (!dir.endsWith(File.separator)) sb.append(File.separator);
          if (cbm.isSelected()) {
            // Rename:
            sb.append(suggName);
          } else {
            // Do not rename:
            sb.append(file.getName());
          }
          chosenFile = sb.toString();
        } else {
          chosenFile =
              FileDialogs.getNewFile(frame, file, extension, JFileChooser.SAVE_DIALOG, false);
        }
        if (chosenFile == null) {
          return; // cancelled
        }
        newFile = new File(chosenFile);
        // Check if the file already exists:
        if (newFile.exists()
            && (JOptionPane.showConfirmDialog(
                    frame,
                    "'" + newFile.getName() + "' " + Globals.lang("exists. Overwrite file?"),
                    Globals.lang("Move/Rename file"),
                    JOptionPane.OK_CANCEL_OPTION)
                != JOptionPane.OK_OPTION)) {
          if (!toFileDir) repeat = true;
          else return;
        }
      }

      if (!newFile.equals(file)) {
        try {
          boolean success = file.renameTo(newFile);
          if (!success) {
            success = Util.copyFile(file, newFile, true);
          }
          if (success) {
            // Remove the original file:
            file.delete();
            // Relativise path, if possible.
            String canPath = (new File(dir)).getCanonicalPath();
            if (newFile.getCanonicalPath().startsWith(canPath)) {
              if ((newFile.getCanonicalPath().length() > canPath.length())
                  && (newFile.getCanonicalPath().charAt(canPath.length()) == File.separatorChar))
                flEntry.setLink(newFile.getCanonicalPath().substring(1 + canPath.length()));
              else flEntry.setLink(newFile.getCanonicalPath().substring(canPath.length()));

            } else flEntry.setLink(newFile.getCanonicalPath());
            eEditor.updateField(editor);
            JOptionPane.showMessageDialog(
                frame,
                Globals.lang("File moved"),
                Globals.lang("Move/Rename file"),
                JOptionPane.INFORMATION_MESSAGE);
          } else {
            JOptionPane.showMessageDialog(
                frame,
                Globals.lang("Move file failed"),
                Globals.lang("Move/Rename file"),
                JOptionPane.ERROR_MESSAGE);
          }

        } catch (SecurityException ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              frame,
              Globals.lang("Could not move file") + ": " + ex.getMessage(),
              Globals.lang("Move/Rename file"),
              JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              frame,
              Globals.lang("Could not move file") + ": " + ex.getMessage(),
              Globals.lang("Move/Rename file"),
              JOptionPane.ERROR_MESSAGE);
        }
      }
    } else {

      // File doesn't exist, so we can't move it.
      JOptionPane.showMessageDialog(
          frame,
          Globals.lang("Could not find file '%0'.", flEntry.getLink()),
          Globals.lang("File not found"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #10
0
 /**
  * Return a dropdown list with the alternatives for pagination type fields
  *
  * @param fieldEditor
  * @param entryEditor
  * @return
  */
 public static Optional<JComponent> getTypeExtraComponent(
     FieldEditor fieldEditor, EntryEditor entryEditor, boolean isPatent) {
   String[] optionValues;
   String[] optionDescriptions;
   if (isPatent) {
     optionValues =
         new String[] {
           "",
           "patent",
           "patentde",
           "patenteu",
           "patentfr",
           "patentuk",
           "patentus",
           "patreq",
           "patreqde",
           "patreqeu",
           "patreqfr",
           "patrequk",
           "patrequs"
         };
     optionDescriptions =
         new String[] {
           Localization.lang("Select"),
           Localization.lang("Patent"),
           Localization.lang("German patent"),
           Localization.lang("European patent"),
           Localization.lang("French patent"),
           Localization.lang("British patent"),
           Localization.lang("U.S. patent"),
           Localization.lang("Patent request"),
           Localization.lang("German patent request"),
           Localization.lang("European patent request"),
           Localization.lang("French patent request"),
           Localization.lang("British patent request"),
           Localization.lang("U.S. patent request")
         };
   } else {
     optionValues =
         new String[] {
           "",
           "mathesis",
           "phdthesis",
           "candthesis",
           "techreport",
           "resreport",
           "software",
           "datacd",
           "audiocd"
         };
     optionDescriptions =
         new String[] {
           Localization.lang("Select"),
           Localization.lang("Master's thesis"),
           Localization.lang("PhD thesis"),
           Localization.lang("Candidate thesis"),
           Localization.lang("Technical report"),
           Localization.lang("Research report"),
           Localization.lang("Software"),
           Localization.lang("Data CD"),
           Localization.lang("Audio CD")
         };
   }
   JComboBox<String> type = new JComboBox<>(optionDescriptions);
   type.addActionListener(
       actionEvent -> {
         fieldEditor.setText(optionValues[type.getSelectedIndex()]);
         entryEditor.updateField(fieldEditor);
       });
   return Optional.of(type);
 }
コード例 #11
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);
  }
コード例 #12
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);
    }
  }