Exemplo n.º 1
0
  public void initPopupMenu() {
    super.initPopupMenu();
    if (getPopupMenu() != null) {
      JMenu otherDataSourcesMenu = new JMenu("Other Data Sources");
      getPopupMenu().add(otherDataSourcesMenu);
      JMenuItem mi;
      mi = new JMenuItem("Show Level Lists");
      ShowLevelListAction showLevelList = new ShowLevelListAction("Show Level List");
      mi.setAction(showLevelList);
      getPopupMenu().add(mi);

      mi = new JMenuItem("Add Level Lists");
      AddLevelListAction addLevelList = new AddLevelListAction("Add Level List");
      mi.setAction(addLevelList);
      getPopupMenu().add(mi);

      mi = new JMenuItem("OMIM");
      mi.setActionCommand("goto OMIM");
      otherDataSourcesMenu.add(mi);
      mi = new JMenuItem("PubMed");
      mi.setActionCommand("goto PubMed");
      otherDataSourcesMenu.add(mi);
      mi = new JMenuItem("NCI Thesaurus");
      mi.setActionCommand("goto NCI Thesaurus Advice");
      otherDataSourcesMenu.add(mi);
      otherDataSourcesMenu.setOpaque(true);
      getPopupMenu().setOpaque(true);
      getPopupMenu().setLightWeightPopupEnabled(true);
    }
  }
Exemplo n.º 2
0
  public void populateMenu(JMenu menu, int flags) {
    if (flags == (Plugin.MENU_TOOLS | Plugin.MENU_MID)) {
      Sketch sketch = editor.getSketch();
      JMenuItem item = new JMenu("Program Bootloader");
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              run();
            }
          });
      menu.add(item);

      PropertyFile props = sketch.mergeAllProperties();
      String blProgs = props.get("bootloader.upload");
      if (blProgs == null) {
        JMenuItem sub = new JMenuItem("No bootloader programmer defined!");
        item.add(sub);
        return;
      }
      String[] progs = blProgs.split("::");
      for (String prog : progs) {
        JMenuItem sub = new JMenuItem(sketch.parseString(props.get("upload." + prog + ".name")));
        sub.setActionCommand(prog);
        sub.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                doProgram(e.getActionCommand());
              }
            });
        item.add(sub);
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Set up the menu bar.
   *
   * @return The JMenuBar we set up.
   */
  private JMenuBar setupMenuBar() {
    JMenuBar menuBar = new JMenuBar();

    /* File */
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    /* File -> Open CSV */
    JMenuItem miFileOpenCSV =
        new JMenuItem(
            new AbstractAction("Open CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD);
                fd.setVisible(true);
                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file.
                loadFile(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("loading file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    System.err.println("Loading file: " + input);
                    loadFile((File) input, DarwinCSV.FILE_CSV_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileOpenCSV);

    /* File -> Open CSV without UI */
    JMenuItem miFileOpenCSVnoUI =
        new JMenuItem(
            new AbstractAction("Open CSV without UI") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file
                loadFile(null);

                loadFile(file, DarwinCSV.FILE_CSV_DELIMITED);
              }
            });
    fileMenu.add(miFileOpenCSVnoUI);

    /* File -> Open tab-delimited */
    JMenuItem miFileOpenTab =
        new JMenuItem(
            new AbstractAction("Open tab-delimited") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(
                        mainFrame, "Open Darwin tab-delimited file ...", FileDialog.LOAD);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file
                loadFile(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("loading file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    loadFile((File) input, DarwinCSV.FILE_TAB_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileOpenTab);

    /* File -> Save CSV */
    JMenuItem miFileSave =
        new JMenuItem(
            new AbstractAction("Save as CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Save Darwin CSV file ...", FileDialog.SAVE);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // SwingWorker MAGIC!
                new MainFrameWorker("saving CSV file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    currentCSV.saveToFile((File) input, DarwinCSV.FILE_CSV_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileSave);

    /* File -> Exit */
    JMenuItem miFileExit =
        new JMenuItem(
            new AbstractAction("Exit") {
              @Override
              public void actionPerformed(ActionEvent e) {
                mainFrame.setVisible(false);
                mainFrame.dispose();
              }
            });
    fileMenu.add(miFileExit);

    /* Match */
    JMenu matchMenu = new JMenu("Match");
    menuBar.add(matchMenu);

    /* Match -> Against CSV */
    JMenuItem miMatchCSV =
        new JMenuItem(
            new AbstractAction("Match against CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(
                        mainFrame, "Open Darwin CSV file for matching ...", FileDialog.LOAD);
                fd.setVisible(true);

                if (fd.getFile() == null) return;

                File file = new File(fd.getFile());
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                }

                // Clear out old match against.
                matchAgainst(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("matching against file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    matchAgainst(new DarwinCSV((File) input, DarwinCSV.FILE_CSV_DELIMITED));

                    return null;
                  }
                }.execute();
              }
            });
    matchMenu.add(miMatchCSV);

    /* Match -> Against ITIS */
    JMenuItem miMatchITIS =
        new JMenuItem(
            new AbstractAction("Match against ITIS") {
              @Override
              public void actionPerformed(ActionEvent e) {
                DarwinCSV csv = DownloadITIS.getIt(mainFrame);
                matchAgainst(csv);
                table.repaint();
              }
            });
    matchMenu.add(miMatchITIS);

    /* TaxonID */
    JMenu taxonIDMenu = new JMenu("TaxonIDs");
    menuBar.add(taxonIDMenu);

    /* TaxonID -> Treat TaxonIDs as ... */
    JMenu treatTaxonIDsAs = new JMenu("Treat TaxonIDs as ...");
    taxonIDMenu.add(treatTaxonIDsAs);

    /* TaxonID -> Treat -> ITIS TSNs */
    JCheckBoxMenuItem miITIS_TSNs =
        new JCheckBoxMenuItem(
            new AbstractAction("ITIS TSNs") {
              @Override
              public void actionPerformed(ActionEvent e) {
                // Don't let the user unselect this.
                ((JCheckBoxMenuItem) e.getSource()).setSelected(true);
              }
            });
    miITIS_TSNs.setSelected(true);
    treatTaxonIDsAs.add(miITIS_TSNs);

    /* TaxonID -> Create family column */
    JMenuItem miTaxonID_createFamily =
        new JMenuItem(
            new AbstractAction("Create family column") {
              @Override
              public void actionPerformed(ActionEvent e) {
                /*
                if(currentCSV == null)
                	return;

                if(currentMatch == null)
                	return;

                int col = getJTable().getSelectedColumn();
                if(col == -1)
                	return;

                RowIndex rowIndex = currentCSV.getRowIndex();

                String colName = rowIndex.getColumnName(col);
                if(rowIndex.hasColumn(colName + "_family")) {
                	// TODO MessageBox
                	return;
                }

                if(Name.class.isAssignableFrom(currentCSV.getRowIndex().getColumnClass(col))) {
                	// A name class! Make a new column!
                	currentCSV.getRowIndex().setColumnClass(colName + "_family", String.class);
                	currentCSV.getRowIndex().createNewColumn(colName + "_family", col + 1, colName, new MapOperation() {
                		@Override
                		public Object mapTo(Object value) {
                			return "family";
                		}
                	});

                	// Repaint the table.
                	getJTable().repaint();
                }
                */
              }
            });
    taxonIDMenu.add(miTaxonID_createFamily);

    /* Help */
    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    /* Help -> Memory information */
    JMenuItem miHelpMemory =
        new JMenuItem(
            new AbstractAction("Memory information") {
              @Override
              public void actionPerformed(ActionEvent e) {
                System.gc();

                MessageBox.messageBox(
                    mainFrame,
                    "Memory information",
                    "Maximum memory: "
                        + Runtime.getRuntime().maxMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Total memory: "
                        + Runtime.getRuntime().totalMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Used memory: "
                        + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())
                            / (1024 * 1024)
                        + " MB\n"
                        + "Free memory: "
                        + Runtime.getRuntime().freeMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Available memory: "
                        + (Runtime.getRuntime().maxMemory()
                                - Runtime.getRuntime().totalMemory()
                                + Runtime.getRuntime().freeMemory())
                            / (1024 * 1024)
                        + " MB");
              }
            });
    helpMenu.add(miHelpMemory);

    return menuBar;
  }