void windowMenu_menuSelected(MenuEvent e) { // <<TODO:MAINTAINABILITY>> This algorithm is not robust. It assumes // the Window // menu has exactly one "regular" menu item (newWindowMenuItem). [Jon // Aquino] if (windowMenu.getItemCount() > 0 && windowMenu.getItem(0) != null && windowMenu .getItem(0) .getText() .equals(AbstractPlugIn.createName(CloneWindowPlugIn.class))) { JMenuItem newWindowMenuItem = windowMenu.getItem(0); windowMenu.removeAll(); windowMenu.add(newWindowMenuItem); windowMenu.addSeparator(); } else { // ezLink doesn't have a Clone Window menu [Jon Aquino] windowMenu.removeAll(); } // final TaskComponent[] frames = (TaskComponent[]) desktopPane.getAllFrames(); final JInternalFrame[] frames = desktopPane.getAllFrames(); for (int i = 0; i < frames.length; i++) { JMenuItem menuItem = new JMenuItem(); // Increase truncation threshold from 20 to 40, for eziLink [Jon // Aquino] menuItem.setText(GUIUtil.truncateString(frames[i].getTitle(), 40)); associate(menuItem, frames[i]); windowMenu.add(menuItem); } if (windowMenu.getItemCount() == 0) { // For ezLink [Jon Aquino] windowMenu.add(new JMenuItem("(No Windows)")); } }
/** * initialize the symbols menu * * @param m menu */ public void initSymbolsMenu(JMenu m) { m.removeAll(); for (int i = 0; i < glyphs.size(); i++) { final MetSymbol metSymbol = (MetSymbol) glyphs.get(i); JMenuItem mi = GuiUtils.makeMenuItem(metSymbol.getLabel(), this, "showProperties", metSymbol); mi.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { highlightedMetSymbol = null; StationModelCanvas.this.repaint(); } public void mouseReleased(MouseEvent e) { highlightedMetSymbol = null; StationModelCanvas.this.repaint(); } public void mouseEntered(MouseEvent e) { highlightedMetSymbol = metSymbol; StationModelCanvas.this.repaint(); } public void mouseExited(MouseEvent e) { highlightedMetSymbol = null; StationModelCanvas.this.repaint(); } }); m.add(mi); } }
private void resetMarks() { interpToMark.removeAll(); shiftToMark.removeAll(); Iterator marks = mediator.getMarkerModel().getLabels().iterator(); boolean hasMark = false; while (marks.hasNext()) { String mark = (String) marks.next(); if (!ChronicleViewer.CURR_FRAME_LABEL.equals(mark)) { JMenuItem mi = new JMenuItem(mark); mi.addActionListener(itmAction); interpToMark.add(mi); mi = new JMenuItem(mark); mi.addActionListener(stmAction); shiftToMark.add(mi); hasMark = true; } } shiftToMark.setEnabled(hasMark); interpToMark.setEnabled(hasMark); }
/** Make the view menu */ private void makeStationModelMenu() { stationModelMenu.removeAll(); List symbols = smm.getResources(); List items = new ArrayList(); ObjectListener listener = new ObjectListener(null) { public void actionPerformed(ActionEvent ae) { if (!okToChange()) { return; } setStationModel((StationModel) theObject, true); } }; GuiUtils.makeMenu(stationModelMenu, makeStationModelMenuItems(symbols, listener, smm)); }
public void refreshSerialPortList() { String[] serialPortList = SerialPortList.getPortNames(); portMenu.removeAll(); portMenu.add(refreshItem); JMenuItem menuItem; for (String serialPort : serialPortList) { menuItem = new JMenuItem(serialPort); menuItem.addActionListener(e -> onSerialPortClicked(e.getActionCommand())); portMenu.add(menuItem); } }
/** Make the file menu */ private void makeFileMenu() { fileMenu.removeAll(); fileMenu.add(makeMenuItem("New", 'n', GuiUtils.CMD_NEW)); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Save", 's', GuiUtils.CMD_SAVE)); fileMenu.add(makeMenuItem("Save As...", GuiUtils.CMD_SAVEAS)); fileMenu.add(makeMenuItem("Rename...", GuiUtils.CMD_RENAME)); fileMenu.addSeparator(); JMenuItem removeMenuItem = makeMenuItem("Remove", GuiUtils.CMD_REMOVE); removeMenuItem.setEnabled(smm.isUsers(stationModel)); fileMenu.add(removeMenuItem); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Import...", GuiUtils.CMD_IMPORT)); fileMenu.add(makeMenuItem("Export...", GuiUtils.CMD_EXPORT)); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Close", GuiUtils.CMD_CLOSE)); }
/** * Creates an {@link OtrContactMenu} for each {@link Contact} contained in the * <tt>metaContact</tt>. * * @param metaContact The {@link MetaContact} this {@link OtrMetaContactMenu} refers to. */ private void createOtrContactMenus(MetaContact metaContact) { JMenu menu = getMenu(); // Remove any existing OtrContactMenu items. menu.removeAll(); // Create the new OtrContactMenu items. if (metaContact != null) { Iterator<Contact> contacts = metaContact.getContacts(); if (metaContact.getContactCount() == 1) { new OtrContactMenu(contacts.next(), inMacOSXScreenMenuBar, menu, false); } else while (contacts.hasNext()) { new OtrContactMenu(contacts.next(), inMacOSXScreenMenuBar, menu, true); } } }
@Override public void run() { if (androidMode.getSDK() == null) return; final Devices devices = Devices.getInstance(); java.util.List<Device> deviceList = devices.findMultiple(false); Device selectedDevice = devices.getSelectedDevice(); if (deviceList.size() == 0) { // if (deviceMenu.getItem(0).isEnabled()) { if (0 < deviceMenu.getItemCount()) { deviceMenu.removeAll(); JMenuItem noDevicesItem = new JMenuItem("No connected devices"); noDevicesItem.setEnabled(false); deviceMenu.add(noDevicesItem); } devices.setSelectedDevice(null); } else { deviceMenu.removeAll(); if (selectedDevice == null) { selectedDevice = deviceList.get(0); devices.setSelectedDevice(selectedDevice); } else { // check if selected device is still connected boolean found = false; for (Device device : deviceList) { if (device.equals(selectedDevice)) { found = true; break; } } if (!found) { selectedDevice = deviceList.get(0); devices.setSelectedDevice(selectedDevice); } } for (final Device device : deviceList) { final JCheckBoxMenuItem deviceItem = new JCheckBoxMenuItem(device.getName()); deviceItem.setEnabled(true); if (device.equals(selectedDevice)) deviceItem.setState(true); // prevent checkboxmenuitem automatic state changing onclick deviceItem.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (device.equals(devices.getSelectedDevice())) deviceItem.setState(true); else deviceItem.setState(false); } }); deviceItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { devices.setSelectedDevice(device); for (int i = 0; i < deviceMenu.getItemCount(); i++) { ((JCheckBoxMenuItem) deviceMenu.getItem(i)).setState(false); } deviceItem.setState(true); } }); deviceMenu.add(deviceItem); } } }
private void updateSdkMenu(final JMenu sdkMenu) { try { ArrayList<AndroidSDK.SDKTarget> targets = androidMode.getSDK().getAvailableSdkTargets(); if (targets.size() != 0) sdkMenu.removeAll(); AndroidSDK.SDKTarget lowestTargetAvailable = null; JCheckBoxMenuItem lowestTargetMenuItem = null; String savedTargetVersion = Preferences.get("android.sdk.version"); boolean savedTargetSet = false; for (final AndroidSDK.SDKTarget target : targets) { if (target.version < 11) { // We do not support API level less than 11 continue; } final JCheckBoxMenuItem item = new JCheckBoxMenuItem("API " + target.name + " (" + target.version + ")"); if (savedTargetSet == false && (lowestTargetAvailable == null || lowestTargetAvailable.version > target.version)) { lowestTargetAvailable = target; lowestTargetMenuItem = item; } if (Integer.toString(target.version).equals(savedTargetVersion)) { AndroidBuild.setSdkTarget(target, sketch); item.setState(true); savedTargetSet = true; } item.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (target.name.equals(AndroidBuild.sdkName)) item.setState(true); else item.setState(false); } }); item.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AndroidBuild.setSdkTarget(target, sketch); for (int i = 0; i < sdkMenu.getItemCount(); i++) { ((JCheckBoxMenuItem) sdkMenu.getItem(i)).setState(false); } item.setState(true); } }); sdkMenu.add(item); } if (!savedTargetSet) { AndroidBuild.setSdkTarget(lowestTargetAvailable, sketch); lowestTargetMenuItem.setState(true); } } catch (IOException e) { e.printStackTrace(); } }
public void clear() { items.clear(); jMenu.removeAll(); }
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); } } }
/** * 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); } } }
/** 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)); } }