Ejemplo n.º 1
0
 /** Remove all types from the menu. Then cycle through all available values, and add them. */
 public static void populateSpecialFieldMenu(JMenu menu, SpecialField field, JabRefFrame frame) {
   // menu.removeAll();
   menu.setText(field.getMenuString());
   menu.setIcon(field.getRepresentingIcon());
   for (SpecialFieldValue val : field.getValues()) {
     menu.add(val.getMenuAction(frame));
   }
 }
Ejemplo n.º 2
0
  private JMenu buildGroupMenu(BibtexEntry[] bes, boolean add, boolean move) {
    if (bes == null) {
      return null;
    }
    JMenu groupMenu = new JMenu();
    GroupTreeNode groups = metaData.getGroups();
    if (groups == null) {
      groupAddMenu.setEnabled(false);
      groupMoveMenu.setEnabled(false);
      groupRemoveMenu.setEnabled(false);
      return null;
    }

    /*groupAddMenu.setEnabled(true);
    groupMoveMenu.setEnabled(true);
    groupRemoveMenu.setEnabled(true);
    groupAddMenu.removeAll();
    groupMoveMenu.removeAll();
    groupRemoveMenu.removeAll();

    add(groupAddMenu);
    add(groupMoveMenu);
    add(groupRemoveMenu);

    groupAddMenu.setEnabled(false);
    groupMoveMenu.setEnabled(false);
    groupRemoveMenu.setEnabled(false);*/

    /*insertNodes(groupAddMenu,metaData.getGroups(),bes,true,false);
    insertNodes(groupMoveMenu,metaData.getGroups(),bes,true,true);
    insertNodes(groupRemoveMenu,metaData.getGroups(),bes,false,false);*/

    insertNodes(groupMenu, metaData.getGroups(), bes, add, move);

    return groupMenu;
  }
Ejemplo n.º 3
0
  /** @param move For add: if true, remove from previous groups */
  private void insertNodes(
      JMenu menu, GroupTreeNode node, BibtexEntry[] selection, boolean add, boolean move) {
    final AbstractAction action = getAction(node, selection, add, move);

    if (node.getChildCount() == 0) {
      JMenuItem menuItem = new JMenuItem(action);
      setGroupFontAndIcon(menuItem, node.getGroup());
      menu.add(menuItem);
      if (action.isEnabled()) {
        menu.setEnabled(true);
      }
      return;
    }

    JMenu submenu;
    if (node.getGroup() instanceof AllEntriesGroup) {
      for (int i = 0; i < node.getChildCount(); ++i) {
        insertNodes(menu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
      }
    } else {
      submenu = new JMenu('[' + node.getGroup().getName() + ']');
      setGroupFontAndIcon(submenu, node.getGroup());
      // setEnabled(true) is done above/below if at least one menu
      // entry (item or submenu) is enabled
      submenu.setEnabled(action.isEnabled());
      JMenuItem menuItem = new JMenuItem(action);
      setGroupFontAndIcon(menuItem, node.getGroup());
      submenu.add(menuItem);
      submenu.add(new Separator());
      for (int i = 0; i < node.getChildCount(); ++i) {
        insertNodes(submenu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
      }
      menu.add(submenu);
      if (submenu.isEnabled()) {
        menu.setEnabled(true);
      }
    }
  }
Ejemplo n.º 4
0
  public RightClickMenu(BasePanel panel_, MetaData metaData_) {
    panel = panel_;
    metaData = metaData_;

    // Are multiple entries selected?
    boolean multiple = panel.mainTable.getSelectedRowCount() > 1;

    // If only one entry is selected, get a reference to it for adapting the menu.
    BibtexEntry be = null;
    if (panel.mainTable.getSelectedRowCount() == 1) {
      be = panel.mainTable.getSelected().get(0);
    }

    addPopupMenuListener(this);

    add(
        new AbstractAction(Globals.lang("Copy"), GUIGlobals.getImage("copy")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("copy");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute copy", ex);
            }
          }
        });
    add(
        new AbstractAction(Globals.lang("Paste"), GUIGlobals.getImage("paste")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("paste");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute paste", ex);
            }
          }
        });
    add(
        new AbstractAction(Globals.lang("Cut"), GUIGlobals.getImage("cut")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("cut");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute cut", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Delete"), GUIGlobals.getImage("delete")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            /*SwingUtilities.invokeLater(new Runnable () {
            public void run() {*/
            try {
              panel.runCommand("delete");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute delete", ex);
            }
            /*}
            }); */
          }
        });
    addSeparator();

    add(
        new AbstractAction(Globals.lang("Export to clipboard")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("exportToClipboard");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute exportToClipboard", ex);
            }
          }
        });
    add(
        new AbstractAction(Globals.lang("Send as email")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("sendAsEmail");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute sendAsEmail", ex);
            }
          }
        });
    addSeparator();

    JMenu markSpecific = JabRefFrame.subMenu("Mark specific color");
    JabRefFrame frame = panel.frame;
    for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) {
      markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem());
    }

    if (multiple) {
      add(
          new AbstractAction(Globals.lang("Mark entries"), GUIGlobals.getImage("markEntries")) {

            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                panel.runCommand("markEntries");
              } catch (Throwable ex) {
                LOGGER.warn("Could not execute markEntries", ex);
              }
            }
          });

      add(markSpecific);

      add(
          new AbstractAction(Globals.lang("Unmark entries"), GUIGlobals.getImage("unmarkEntries")) {

            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                panel.runCommand("unmarkEntries");
              } catch (Throwable ex) {
                LOGGER.warn("Could not execute unmarkEntries", ex);
              }
            }
          });
      addSeparator();
    } else if (be != null) {
      String marked = be.getField(BibtexFields.MARKED);
      // We have to check for "" too as the marked field may be empty
      if (marked == null || marked.isEmpty()) {
        add(
            new AbstractAction(Globals.lang("Mark entry"), GUIGlobals.getImage("markEntries")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("markEntries");
                } catch (Throwable ex) {
                  LOGGER.warn("Could not execute markEntries", ex);
                }
              }
            });

        add(markSpecific);
      } else {
        add(markSpecific);
        add(
            new AbstractAction(Globals.lang("Unmark entry"), GUIGlobals.getImage("unmarkEntries")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("unmarkEntries");
                } catch (Throwable ex) {
                  LOGGER.warn("Could not execute unmarkEntries", ex);
                }
              }
            });
      }
      addSeparator();
    }

    if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) {
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) {
        JMenu rankingMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), panel.frame);
        add(rankingMenu);
      }

      // TODO: multiple handling for relevance and quality-assurance
      // if multiple values are selected ("if (multiple)"), two options (set / clear) should be
      // offered
      // if one value is selected either set or clear should be offered
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) {
        add(Relevance.getInstance().getValues().get(0).getMenuAction(panel.frame));
      }
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) {
        add(Quality.getInstance().getValues().get(0).getMenuAction(panel.frame));
      }
      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) {
        add(Printed.getInstance().getValues().get(0).getMenuAction(panel.frame));
      }

      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) {
        JMenu priorityMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), panel.frame);
        add(priorityMenu);
      }

      if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) {
        JMenu readStatusMenu = new JMenu();
        RightClickMenu.populateSpecialFieldMenu(
            readStatusMenu, ReadStatus.getInstance(), panel.frame);
        add(readStatusMenu);
      }

      addSeparator();
    }

    add(
        new AbstractAction(Globals.lang("Open folder"), GUIGlobals.getImage("openFolder")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("openFolder");
            } catch (Throwable ex) {
              LOGGER.warn("Could not open folder", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Open file"), GUIGlobals.getImage("openExternalFile")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("openExternalFile");
            } catch (Throwable ex) {
              LOGGER.warn("Could not open external file", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Attach file"), GUIGlobals.getImage("open")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("addFileLink");
            } catch (Throwable ex) {
              LOGGER.warn("Could not attach file", ex);
            }
          }
        });
    /*add(new AbstractAction(Globals.lang("Open PDF or PS"), GUIGlobals.getImage("openFile")) {
        public void actionPerformed(ActionEvent e) {
            try {
                panel.runCommand("openFile");
            } catch (Throwable ex) {}
        }
    });*/

    add(
        new AbstractAction(Globals.lang("Open URL or DOI"), GUIGlobals.getImage("www")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("openUrl");
            } catch (Throwable ex) {
              LOGGER.warn("Could not execute open URL", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Copy BibTeX key")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("copyKey");
            } catch (Throwable ex) {
              LOGGER.warn("Could not copy BibTex key", ex);
            }
          }
        });

    add(
        new AbstractAction(Globals.lang("Copy") + " \\cite{" + Globals.lang("BibTeX key") + '}') {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("copyCiteKey");
            } catch (Throwable ex) {
              LOGGER.warn("Could not copy cite key", ex);
            }
          }
        });

    addSeparator();
    populateTypeMenu();

    add(typeMenu);
    add(
        new AbstractAction(Globals.lang("Plain text import")) {

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              panel.runCommand("importPlainText");
            } catch (Throwable ex) {
              LOGGER.debug("Could not import plain text", ex);
            }
          }
        });

    add(JabRef.jrf.massSetField);
    add(JabRef.jrf.manageKeywords);

    addSeparator(); // for "add/move/remove to/from group" entries (appended here)

    groupAdd =
        new JMenuItem(
            new AbstractAction(Globals.lang("Add to group")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("addToGroup");

                  // BibtexEntry[] bes = panel.getSelectedEntries();
                  // JMenu groupMenu = buildGroupMenu(bes, true, false);

                } catch (Throwable ex) {
                  LOGGER.debug("Could not add to group", ex);
                }
              }
            });
    add(groupAdd);
    groupRemove =
        new JMenuItem(
            new AbstractAction(Globals.lang("Remove from group")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("removeFromGroup");
                } catch (Throwable ex) {
                  LOGGER.debug("Could not remove from group", ex);
                }
              }
            });
    add(groupRemove);

    JMenuItem groupMoveTo =
        add(
            new AbstractAction(Globals.lang("Move to group")) {

              @Override
              public void actionPerformed(ActionEvent e) {
                try {
                  panel.runCommand("moveToGroup");
                } catch (Throwable ex) {
                  LOGGER.debug("Could not execute move to group", ex);
                }
              }
            });
    add(groupMoveTo);

    floatMarked.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            Globals.prefs.putBoolean(
                JabRefPreferences.FLOAT_MARKED_ENTRIES, floatMarked.isSelected());
            panel.mainTable.refreshSorting(); // Bad remote access
          }
        });
  }
Ejemplo n.º 5
0
 /** Remove all types from the menu. Then cycle through all available types, and add them. */
 private void populateTypeMenu() {
   typeMenu.removeAll();
   for (String key : BibtexEntryType.getAllTypes()) {
     typeMenu.add(new ChangeTypeAction(BibtexEntryType.getType(key), panel));
   }
 }