Пример #1
0
 public void notifyGenomeServerReachable(boolean reachable) {
   if (loadFromServerMenuItem != null) {
     loadFromServerMenuItem.setEnabled(reachable);
     String tooltip = reachable ? LOAD_GENOME_SERVER_TOOLTIP : CANNOT_LOAD_GENOME_SERVER_TOOLTIP;
     loadFromServerMenuItem.setToolTipText(tooltip);
   }
 }
Пример #2
0
  private JMenu createExtrasMenu() {

    List<JComponent> menuItems = new ArrayList<JComponent>();

    MenuAction menuAction = null;

    final JCheckBoxMenuItem exomeModeItem = new JCheckBoxMenuItem("Exome mode");
    exomeModeItem.setSelected(FrameManager.isExomeMode());
    exomeModeItem.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            FrameManager.setExomeMode(exomeModeItem.isSelected(), true);
            igv.resetFrames();
          }
        });
    menuItems.add(exomeModeItem);
    menuItems.add(new JSeparator());

    // Preferences reset
    menuAction = new ResetPreferencesAction("Reset Preferences", IGV.getInstance());
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuItems.add(new JSeparator());

    menuAction =
        new MenuAction("Variant list ...  *EXPERIMENTAL*") {
          @Override
          public void actionPerformed(ActionEvent e) {
            VariantListManager.openNavigator(IGV.getMainFrame());
          }
        };
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuItems.add(new JSeparator());

    // Set frame dimensions
    menuAction =
        new MenuAction("Set window dimensions", null, KeyEvent.VK_C) {

          @Override
          public void actionPerformed(ActionEvent e) {
            String value = JOptionPane.showInputDialog("Enter dimensions, e.g. 800x400");
            if (value != null) {
              String[] vals = value.split("x");
              if (vals.length == 2) {
                int w = Integer.parseInt(vals[0]);
                int h = Integer.parseInt(vals[1]);
                IGV.getMainFrame().setSize(w, h);
              }
            }
          }
        };
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    // Save entire window
    menuAction =
        new MenuAction("Save Screenshot ...", null, KeyEvent.VK_A) {

          @Override
          public void actionPerformed(ActionEvent e) {
            IGV.getInstance().saveImage(IGV.getInstance().getContentPane());
          }
        };

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

    menuAction = new ExportTrackNamesMenuAction("Export track names...", IGV.getInstance());
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction =
        new MenuAction("Scatter Plot ...") {
          @Override
          public void actionPerformed(ActionEvent e) {
            final ReferenceFrame defaultFrame = FrameManager.getDefaultFrame();
            String chr = defaultFrame.getChrName();
            int start = (int) defaultFrame.getOrigin();
            int end = (int) defaultFrame.getEnd();
            int zoom = defaultFrame.getZoom();
            ScatterPlotUtils.openPlot(chr, start, end, zoom);
          }
        };
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    MenuAction extrasMenuAction = new MenuAction("Extras");
    JMenu menu = MenuAndToolbarUtils.createMenu(menuItems, extrasMenuAction);

    //
    JMenu lfMenu = new JMenu("L&F");
    LookAndFeel lf = UIManager.getLookAndFeel();
    for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {

      final String lfName = info.getName();
      JMenuItem cb = new JMenuItem(lfName);
      // cb.setSelected(info.getClassName().equals(lf.getClass().getName());
      cb.addActionListener(
          new AbstractAction() {

            public void actionPerformed(ActionEvent actionEvent) {
              for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {

                if (lfName.equals(info.getName())) {
                  try {
                    UIManager.setLookAndFeel(info.getClassName());
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  break;
                }
              }
            }
          });
      lfMenu.add(cb);
    }
    menu.add(lfMenu);

    menu.setVisible(false);

    return menu;
  }
Пример #3
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);
      }
    }
  }
Пример #4
0
  private JMenu createViewMenu() {

    List<JComponent> menuItems = new ArrayList<JComponent>();
    MenuAction menuAction = null;

    // Preferences
    menuAction =
        new MenuAction("Preferences...", null, KeyEvent.VK_P) {
          @Override
          public void actionPerformed(ActionEvent e) {
            UIUtilities.invokeOnEventThread(
                new Runnable() {
                  public void run() {
                    IGV.getInstance().doViewPreferences();
                  }
                });
          }
        };
    menuAction.setToolTipText(PREFERENCE_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction =
        new MenuAction("Color Legends ...", null, KeyEvent.VK_H) {
          @Override
          public void actionPerformed(ActionEvent e) {
            (new LegendDialog(IGV.getMainFrame())).setVisible(true);
          }
        };
    menuAction.setToolTipText(SHOW_HEATMAP_LEGEND_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuItems.add(new JSeparator());

    menuAction =
        new MenuAction("Show Name Panel", null, KeyEvent.VK_A) {
          @Override
          public void actionPerformed(ActionEvent e) {

            JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) e.getSource();
            if (menuItem.isSelected()) {
              IGV.getInstance().getMainPanel().expandNamePanel();
            } else {
              IGV.getInstance().getMainPanel().collapseNamePanel();
            }
            IGV.getInstance().doRefresh();
          }
        };
    boolean isShowing = IGV.getInstance().getMainPanel().isExpanded();
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem();
    menuItem.setSelected(isShowing);
    menuItem.setAction(menuAction);
    menuItems.add(menuItem);

    JMenuItem panelWidthmenuItem = new JMenuItem();
    menuAction =
        new MenuAction("Set Name Panel Width...", null, KeyEvent.VK_A) {
          @Override
          public void actionPerformed(ActionEvent e) {
            MainPanel mainPanel = IGV.getInstance().getMainPanel();
            String currentValue = String.valueOf(mainPanel.getNamePanelWidth());
            String newValue =
                MessageUtils.showInputDialog("Enter track name panel width: ", currentValue);
            if (newValue != null) {
              try {
                Integer w = Integer.parseInt(newValue);
                if (w <= 0 || w == 1000) throw new NumberFormatException();
                PreferenceManager.getInstance().put(PreferenceManager.NAME_PANEL_WIDTH, newValue);
                mainPanel.setNamePanelWidth(w);
              } catch (NumberFormatException ex) {
                MessageUtils.showErrorMessage(
                    "Error: value must be a positive integer < 1000.", ex);
              }
            }
          }
        };
    panelWidthmenuItem.setAction(menuAction);
    menuItems.add(panelWidthmenuItem);

    // Hide or Show the attribute panels
    boolean isShow =
        PreferenceManager.getInstance().getAsBoolean(PreferenceManager.SHOW_ATTRIBUTE_VIEWS_KEY);
    IGV.getInstance().doShowAttributeDisplay(isShow); // <= WEIRD doing IGV.getInstance() here!

    menuAction =
        new MenuAction("Show Attribute Display", null, KeyEvent.VK_A) {
          @Override
          public void actionPerformed(ActionEvent e) {

            JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) e.getSource();
            PreferenceManager.getInstance().setShowAttributeView(menuItem.getState());
            IGV.getInstance().getMainPanel().invalidate();
            IGV.getInstance().doRefresh();
          }
        };
    menuItem = MenuAndToolbarUtils.createMenuItem(menuAction, isShow);
    menuItems.add(menuItem);

    menuAction =
        new MenuAction("Select Attributes to Show...", null, KeyEvent.VK_S) {

          @Override
          public void actionPerformed(ActionEvent e) {
            IGV.getInstance().doSelectDisplayableAttribute();
          }
        };
    menuAction.setToolTipText(SELECT_DISPLAYABLE_ATTRIBUTES_TOOLTIP);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuAction =
        new MenuAction("Show Header Panel", null, KeyEvent.VK_A) {
          @Override
          public void actionPerformed(ActionEvent e) {

            JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) e.getSource();
            if (menuItem.isSelected()) {
              IGV.getInstance().getMainPanel().restoreHeader();
            } else {
              IGV.getInstance().getMainPanel().removeHeader();
            }
            IGV.getInstance().doRefresh();
          }
        };
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction, true));

    menuItems.add(new JSeparator());
    menuAction =
        new MenuAction("Reorder Panels...", null, KeyEvent.VK_S) {

          @Override
          public void actionPerformed(ActionEvent e) {
            ReorderPanelsDialog dlg = new ReorderPanelsDialog(IGV.getMainFrame());
            dlg.setVisible(true);
          }
        };
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    menuItems.add(new JSeparator());
    menuItems.add(new HistoryMenu("Go to"));

    // Add to IGVPanel menu
    MenuAction dataMenuAction = new MenuAction("View", null, KeyEvent.VK_V);
    viewMenu = MenuAndToolbarUtils.createMenu(menuItems, dataMenuAction);
    return viewMenu;
  }
Пример #5
0
  /**
   * Generate the "tools" menu. This is imperative, it is written to field {@code toolsMenu}. Reason
   * being, when we add (TODO remove) a new tool, we need to refresh just this menu
   */
  void refreshToolsMenu() {
    List<JComponent> menuItems = new ArrayList<JComponent>(10);

    // batch script
    MenuAction menuAction = new RunScriptMenuAction("Run Batch Script...", KeyEvent.VK_X, igv);
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    // igvtools
    // menuItems.add(new JSeparator());
    menuAction =
        new SortTracksMenuAction("Run igvtools...", KeyEvent.VK_T, igv) {
          @Override
          public void actionPerformed(ActionEvent e) {
            IgvToolsGui.launch(false, igv.getGenomeManager().getGenomeId());
          }
        };
    menuItems.add(MenuAndToolbarUtils.createMenuItem(menuAction));

    List<JComponent> otherToolMenus = igv.getOtherToolMenus();
    if (otherToolMenus.size() > 0) {
      for (JComponent entry : otherToolMenus) {
        menuItems.add(entry);
      }
    }
    // menuItems.add(new JSeparator());

    // -------------------------------------//
    // "Add tool" option, for loading cli_plugin from someplace else
    JMenuItem addTool = new JMenuItem("Add Tool...");
    addTool.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            File pluginFi = FileDialogUtils.chooseFile("Select cli_plugin .xml spec");
            if (pluginFi == null) return;

            try {
              PluginSpecReader.addCustomPlugin(pluginFi.getAbsolutePath());
              refreshToolsMenu();
            } catch (IOException e1) {
              MessageUtils.showErrorMessage("Error loading custom cli_plugin", e1);
            }
          }
        });
    // menuItems.add(addTool);
    // menuItems.add(new JSeparator());

    // -------------------------------------//

    for (final PluginSpecReader pluginSpecReader : PluginSpecReader.getPlugins()) {
      for (final PluginSpecReader.Tool tool : pluginSpecReader.getTools()) {
        final String toolName = tool.name;
        boolean toolVisible = tool.visible;
        JMenuItem toolMenu;

        if (toolVisible) {

          final String toolPath = pluginSpecReader.getToolPath(tool);
          final String tool_url = tool.toolUrl;
          boolean isValid = PluginSpecReader.isToolPathValid(toolPath);

          ActionListener invalidActionListener =
              new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                  String msg = String.format("%s executable not found at %s", toolName, toolPath);
                  if (tool_url != null) {
                    msg += "<br/>See " + tool_url + " to install";
                  }
                  MessageUtils.showMessage(msg);
                }
              };

          toolMenu = new JMenu(toolName);
          // Kind of overlaps with the side-pull menu, doesn't look great
          // toolMenu.setToolTipText(tool.getAttribute("description"));
          for (final PluginSpecReader.Command command : tool.commandList) {
            final String cmdName = command.name;
            JMenuItem cmdItem = new JMenuItem(cmdName);
            toolMenu.add(cmdItem);
            if (isValid || toolPath == null) {
              cmdItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      RunPlugin runPlugin = null;
                      try {
                        runPlugin =
                            new RunPlugin(IGV.getMainFrame(), pluginSpecReader, tool, command);
                      } catch (IllegalStateException e1) {
                        MessageUtils.showErrorMessage(e1.getMessage(), e1);
                        return;
                      }
                      runPlugin.setVisible(true);
                    }
                  });
              cmdItem.setEnabled(true);
            } else {
              cmdItem.setEnabled(false);
            }
          }
          // Hack so we can have a tool which is just general command line stuff
          // Don't let the user change the path in that case
          if (tool.defaultPath != null) {
            JMenuItem setPathItem = new JMenuItem(String.format("Set path to %s...", toolName));
            setPathItem.addActionListener(
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    (new SetPluginPathDialog(IGV.getMainFrame(), pluginSpecReader, tool))
                        .setVisible(true);
                    refreshToolsMenu();
                  }
                });
            toolMenu.add(setPathItem);
          }
          menuItems.add(toolMenu);
        }
      }
    }
    // -------------------------------------//

    // -----------SQL DB Tools--------------//
    boolean showDBEditor = Globals.isDevelopment();
    if (showDBEditor) {
      JMenu sqlDBProfileEditor = new JMenu("SQL DB Profile Editor");
      JMenuItem createNewProfile = new JMenuItem("Create New Profile");
      createNewProfile.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              File file =
                  FileDialogUtils.chooseFile(
                      "Save DB Profile", DirectoryManager.getUserDirectory(), FileDialogUtils.SAVE);
              if (file != null) {
                DBProfileEditor editor =
                    new DBProfileEditor(IGV.getMainFrame(), file.getAbsolutePath());
                editor.setVisible(true);
              }
            }
          });
      JMenuItem editExistingProfile = new JMenuItem("Edit Existing Profile");
      editExistingProfile.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              File file = FileDialogUtils.chooseFile("Select .dbxml database profile");
              if (file != null) {
                if (!file.exists()) {}

                DBProfileEditor editor =
                    new DBProfileEditor(IGV.getMainFrame(), file.getAbsolutePath());
                editor.setVisible(true);
              }
            }
          });
      sqlDBProfileEditor.add(createNewProfile);
      sqlDBProfileEditor.add(editExistingProfile);
      menuItems.add(sqlDBProfileEditor);
    }

    // -------------------------------------//

    // DataTrack Math------------------------//
    if (Globals.isDevelopment()) {
      JMenuItem combineDataItem = new JMenuItem("Combine Data Tracks");
      combineDataItem.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              CombinedDataSourceDialog dialog = new CombinedDataSourceDialog(IGV.getMainFrame());
              dialog.setVisible(true);
            }
          });
      menuItems.add(combineDataItem);
    }

    // -------------------------------------//

    MenuAction toolsMenuAction = new MenuAction("Tools", null);
    if (toolsMenu == null) {
      toolsMenu = MenuAndToolbarUtils.createMenu(menuItems, toolsMenuAction);
      toolsMenu.setName("Tools");
    } else {
      toolsMenu.removeAll();
      for (JComponent item : menuItems) {
        toolsMenu.add(item);
      }
    }
  }