Example #1
0
  void createFileMenu() {

    List<JComponent> menuItems = new ArrayList<JComponent>();
    MenuAction menuAction = null;
    // We disable certain load items when there is no genome.
    boolean genomeLoaded = GenomeManager.getInstance().getCurrentGenome() != null;

    menuItems.add(new JSeparator());

    // Load menu items
    menuAction = new LoadFilesMenuAction("Load from File...", KeyEvent.VK_L, igv);
    menuAction.setToolTipText(UIConstants.LOAD_TRACKS_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction = new LoadFromURLMenuAction(LoadFromURLMenuAction.LOAD_FROM_URL, KeyEvent.VK_U, igv);
    menuAction.setToolTipText(UIConstants.LOAD_TRACKS_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction = new LoadFromServerAction("Load from Server...", KeyEvent.VK_S, igv);
    menuAction.setToolTipText(UIConstants.LOAD_SERVER_DATA_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction = new LoadFromURLMenuAction(LoadFromURLMenuAction.LOAD_FROM_DAS, KeyEvent.VK_D, igv);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.DB_ENABLED)) {
      menuAction = new LoadFromDatabaseAction("Load from Database...", 0, igv);
      menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));
    }

    String genomeId = IGV.getInstance().getGenomeManager().getGenomeId();
    if (EncodeFileBrowser.genomeSupported(genomeId)) {
      menuAction = new BrowseEncodeAction("Load from ENCODE...", KeyEvent.VK_E, igv);
      menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));
    }

    // Disable loading if no genome loaded. Something of an edge case
    if (!genomeLoaded) {
      for (JComponent menuItem : menuItems) {
        menuItem.setEnabled(false);
      }
    }

    menuItems.add(new JSeparator());

    // Session menu items
    menuAction = new NewSessionMenuAction("New Session...", KeyEvent.VK_N, igv);
    menuAction.setToolTipText(UIConstants.NEW_SESSION_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction = new OpenSessionMenuAction("Open Session...", KeyEvent.VK_O, igv);
    menuAction.setToolTipText(UIConstants.RESTORE_SESSION_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction = new SaveSessionMenuAction("Save Session...", KeyEvent.VK_V, igv);
    menuAction.setToolTipText(UIConstants.SAVE_SESSION_TOOLTIP);
    JMenuItem saveSessionItem = MenuAndToolbarUtils.createMenuItem(menuAction);
    menuItems.add(saveSessionItem);
    saveSessionItem.setEnabled(genomeLoaded);

    menuItems.add(new JSeparator());

    // ***** Snapshots
    // Snapshot Application
    menuAction =
        new MenuAction("Save Image ...", null, KeyEvent.VK_A) {
          @Override
          public void actionPerformed(ActionEvent e) {
            igv.saveImage(igv.getMainPanel());
          }
        };

    menuAction.setToolTipText(SAVE_IMAGE_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    // TODO -- change "Exit" to "Close" for BioClipse
    menuItems.add(new JSeparator()); // Exit
    menuAction =
        new MenuAction("Exit", null, KeyEvent.VK_X) {

          @Override
          public void actionPerformed(ActionEvent e) {
            doExitApplication();
          }
        };

    menuAction.setToolTipText(EXIT_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    // Empty the recent sessions list before we start to do
    // anything with it
    igv.getRecentSessionList().clear();

    // Retrieve the stored session paths
    String recentSessions = PreferenceManager.getInstance().getRecentSessions();
    if (recentSessions != null) {
      String[] sessions = recentSessions.split(";");
      for (String sessionPath : sessions) {
        if (!igv.getRecentSessionList().contains(sessionPath)) {
          igv.getRecentSessionList().add(sessionPath);
        }
      }
    }

    if (!IGV.getInstance().getRecentSessionList().isEmpty()) {

      menuItems.add(new JSeparator());

      // Now add menu items
      for (final String session : IGV.getInstance().getRecentSessionList()) {
        OpenSessionMenuAction osMenuAction =
            new OpenSessionMenuAction(session, session, IGV.getInstance());
        menuItems.add(MenuAndToolbarUtils.createMenuItem(osMenuAction));
      }
    }

    MenuAction fileMenuAction = new MenuAction("File", null, KeyEvent.VK_F);
    if (fileMenu == null) {
      fileMenu = MenuAndToolbarUtils.createMenu(menuItems, fileMenuAction);
    } else {
      fileMenu.removeAll();
      for (JComponent item : menuItems) {
        fileMenu.add(item);
      }
    }
  }