Example usage for javax.swing JMenuItem setEnabled

List of usage examples for javax.swing JMenuItem setEnabled

Introduction

In this page you can find the example usage for javax.swing JMenuItem setEnabled.

Prototype

@BeanProperty(preferred = true, description = "The enabled state of the component.")
public void setEnabled(boolean b) 

Source Link

Document

Enables or disables the menu item.

Usage

From source file:processing.app.Base.java

public void rebuildExamplesMenu(JMenu menu) {
    if (menu == null) {
        return;//from   w  w w.  j a  va  2 s  . co m
    }

    menu.removeAll();

    // Add examples from distribution "example" folder
    JMenuItem label = new JMenuItem(tr("Built-in Examples"));
    label.setEnabled(false);
    menu.add(label);
    boolean found = addSketches(menu, BaseNoGui.getExamplesFolder());
    if (found) {
        menu.addSeparator();
    }

    // Libraries can come from 4 locations: collect info about all four
    String boardId = null;
    String referencedPlatformName = null;
    String myArch = null;
    TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
    if (targetPlatform != null) {
        myArch = targetPlatform.getId();
        boardId = BaseNoGui.getTargetBoard().getName();
        String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino");
        if (core.contains(":")) {
            String refcore = core.split(":")[0];
            TargetPlatform referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch);
            if (referencedPlatform != null) {
                referencedPlatformName = referencedPlatform.getPreferences().get("name");
            }
        }
    }

    // Divide the libraries into 7 lists, corresponding to the 4 locations
    // with the retired IDE libs further divided into their own list, and
    // any incompatible sketchbook libs further divided into their own list.
    // The 7th list of "other" libraries should always be empty, but serves
    // as a safety feature to prevent any library from vanishing.
    LibraryList allLibraries = BaseNoGui.librariesIndexer.getInstalledLibraries();
    LibraryList ideLibs = new LibraryList();
    LibraryList retiredIdeLibs = new LibraryList();
    LibraryList platformLibs = new LibraryList();
    LibraryList referencedPlatformLibs = new LibraryList();
    LibraryList sketchbookLibs = new LibraryList();
    LibraryList sketchbookIncompatibleLibs = new LibraryList();
    LibraryList otherLibs = new LibraryList();
    for (UserLibrary lib : allLibraries) {
        // Get the library's location - used for sorting into categories
        Location location = lib.getLocation();
        // Is this library compatible?
        List<String> arch = lib.getArchitectures();
        boolean compatible;
        if (myArch == null || arch == null || arch.contains("*")) {
            compatible = true;
        } else {
            compatible = arch.contains(myArch);
        }
        // IDE Libaries (including retired)
        if (location == Location.IDE_BUILTIN) {
            if (compatible) {
                // only compatible IDE libs are shown
                if (lib.getTypes().contains("Retired")) {
                    retiredIdeLibs.add(lib);
                } else {
                    ideLibs.add(lib);
                }
            }
            // Platform Libraries
        } else if (location == Location.CORE) {
            // all platform libs are assumed to be compatible
            platformLibs.add(lib);
            // Referenced Platform Libraries
        } else if (location == Location.REFERENCED_CORE) {
            // all referenced platform libs are assumed to be compatible
            referencedPlatformLibs.add(lib);
            // Sketchbook Libraries (including incompatible)
        } else if (location == Location.SKETCHBOOK) {
            if (compatible) {
                // libraries promoted from sketchbook (behave as builtin)
                if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")
                        && lib.getArchitectures().contains("*")) {
                    ideLibs.add(lib);
                } else {
                    sketchbookLibs.add(lib);
                }
            } else {
                sketchbookIncompatibleLibs.add(lib);
            }
            // Other libraries of unknown type (should never occur)
        } else {
            otherLibs.add(lib);
        }
    }

    // Add examples from libraries
    if (!ideLibs.isEmpty()) {
        ideLibs.sort();
        label = new JMenuItem(tr("Examples for any board"));
        label.setEnabled(false);
        menu.add(label);
    }
    for (UserLibrary lib : ideLibs) {
        addSketchesSubmenu(menu, lib);
    }

    if (!retiredIdeLibs.isEmpty()) {
        retiredIdeLibs.sort();
        JMenu retired = new JMenu(tr("RETIRED"));
        menu.add(retired);
        for (UserLibrary lib : retiredIdeLibs) {
            addSketchesSubmenu(retired, lib);
        }
    }

    if (!platformLibs.isEmpty()) {
        menu.addSeparator();
        platformLibs.sort();
        label = new JMenuItem(I18n.format(tr("Examples for {0}"), boardId));
        label.setEnabled(false);
        menu.add(label);
        for (UserLibrary lib : platformLibs) {
            addSketchesSubmenu(menu, lib);
        }
    }

    if (!referencedPlatformLibs.isEmpty()) {
        menu.addSeparator();
        referencedPlatformLibs.sort();
        label = new JMenuItem(I18n.format(tr("Examples for {0}"), referencedPlatformName));
        label.setEnabled(false);
        menu.add(label);
        for (UserLibrary lib : referencedPlatformLibs) {
            addSketchesSubmenu(menu, lib);
        }
    }

    if (!sketchbookLibs.isEmpty()) {
        menu.addSeparator();
        sketchbookLibs.sort();
        label = new JMenuItem(tr("Examples from Custom Libraries"));
        label.setEnabled(false);
        menu.add(label);
        for (UserLibrary lib : sketchbookLibs) {
            addSketchesSubmenu(menu, lib);
        }
    }

    if (!sketchbookIncompatibleLibs.isEmpty()) {
        sketchbookIncompatibleLibs.sort();
        JMenu incompatible = new JMenu(tr("INCOMPATIBLE"));
        menu.add(incompatible);
        for (UserLibrary lib : sketchbookIncompatibleLibs) {
            addSketchesSubmenu(incompatible, lib);
        }
    }

    if (!otherLibs.isEmpty()) {
        menu.addSeparator();
        otherLibs.sort();
        label = new JMenuItem(tr("Examples from Other Libraries"));
        label.setEnabled(false);
        menu.add(label);
        for (UserLibrary lib : otherLibs) {
            addSketchesSubmenu(menu, lib);
        }
    }
}

From source file:processing.app.Base.java

public void rebuildBoardsMenu() throws Exception {
    boardsCustomMenus = new LinkedList<>();

    // The first custom menu is the "Board" selection submenu
    JMenu boardMenu = new JMenu(tr("Board"));
    boardMenu.putClientProperty("removeOnWindowDeactivation", true);
    MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);

    boardMenu.add(new JMenuItem(new AbstractAction(tr("Boards Manager...")) {
        public void actionPerformed(ActionEvent actionevent) {
            String filterText = "";
            String dropdownItem = "";
            if (actionevent instanceof Event) {
                filterText = ((Event) actionevent).getPayload().get("filterText").toString();
                dropdownItem = ((Event) actionevent).getPayload().get("dropdownItem").toString();
            }//  w ww  .ja v  a  2s .c  om
            try {
                openBoardsManager(filterText, dropdownItem);
            } catch (Exception e) {
                //TODO show error
                e.printStackTrace();
            }
        }
    }));
    boardsCustomMenus.add(boardMenu);

    // If there are no platforms installed we are done
    if (BaseNoGui.packages.size() == 0)
        return;

    // Separate "Install boards..." command from installed boards
    boardMenu.add(new JSeparator());

    // Generate custom menus for all platforms
    Set<String> customMenusTitles = new LinkedHashSet<>();
    for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
        for (TargetPlatform targetPlatform : targetPackage.platforms()) {
            customMenusTitles.addAll(targetPlatform.getCustomMenus().values());
        }
    }
    for (String customMenuTitle : customMenusTitles) {
        JMenu customMenu = new JMenu(tr(customMenuTitle));
        customMenu.putClientProperty("removeOnWindowDeactivation", true);
        boardsCustomMenus.add(customMenu);
    }

    List<JMenuItem> menuItemsToClickAfterStartup = new LinkedList<>();

    ButtonGroup boardsButtonGroup = new ButtonGroup();
    Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>();

    // Cycle through all packages
    boolean first = true;
    for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
        // For every package cycle through all platform
        for (TargetPlatform targetPlatform : targetPackage.platforms()) {

            // Add a separator from the previous platform
            if (!first)
                boardMenu.add(new JSeparator());
            first = false;

            // Add a title for each platform
            String platformLabel = targetPlatform.getPreferences().get("name");
            if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) {
                JMenuItem menuLabel = new JMenuItem(tr(platformLabel));
                menuLabel.setEnabled(false);
                boardMenu.add(menuLabel);
            }

            // Cycle through all boards of this platform
            for (TargetBoard board : targetPlatform.getBoards().values()) {
                if (board.getPreferences().get("hide") != null)
                    continue;
                JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup,
                        buttonGroupsMap, board, targetPlatform, targetPackage);
                boardMenu.add(item);
                boardsButtonGroup.add(item);
            }
        }
    }

    if (menuItemsToClickAfterStartup.isEmpty()) {
        menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu));
    }

    for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) {
        menuItemToClick.setSelected(true);
        menuItemToClick.getAction().actionPerformed(new ActionEvent(this, -1, ""));
    }
}

From source file:processing.app.Editor.java

protected void buildSketchMenu(JMenu sketchMenu) {
    sketchMenu.removeAll();//from  w w  w . j  a v a  2  s  .c o m

    JMenuItem item = newJMenuItem(_("Verify / Compile"), 'R');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleRun(false, Editor.this.presentHandler, Editor.this.runHandler);
        }
    });
    sketchMenu.add(item);

    item = newJMenuItem(_("Upload"), 'U');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleExport(false);
        }
    });
    sketchMenu.add(item);

    item = newJMenuItemShift(_("Upload Using Programmer"), 'U');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleExport(true);
        }
    });
    sketchMenu.add(item);

    item = newJMenuItemAlt(_("Export compiled Binary"), 'S');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleRun(false, new ShouldSaveReadOnly(), Editor.this.presentAndSaveHandler,
                    Editor.this.runAndSaveHandler);
        }
    });
    sketchMenu.add(item);

    //    item = new JMenuItem("Stop");
    //    item.addActionListener(new ActionListener() {
    //        public void actionPerformed(ActionEvent e) {
    //          handleStop();
    //        }
    //      });
    //    sketchMenu.add(item);

    sketchMenu.addSeparator();

    item = newJMenuItem(_("Show Sketch Folder"), 'K');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.openFolder(sketch.getFolder());
        }
    });
    sketchMenu.add(item);
    item.setEnabled(Base.openFolderAvailable());

    if (importMenu == null) {
        importMenu = new JMenu(_("Include Library"));
        MenuScroller.setScrollerFor(importMenu);
        base.rebuildImportMenu(importMenu);
    }
    sketchMenu.add(importMenu);

    item = new JMenuItem(_("Add File..."));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            sketch.handleAddFile();
        }
    });
    sketchMenu.add(item);
}

From source file:processing.app.Editor.java

protected void populatePortMenu() {
    serialMenu.removeAll();//from w  ww.  j ava 2s  .c  o  m

    String selectedPort = PreferencesData.get("serial.port");

    List<BoardPort> ports = Base.getDiscoveryManager().discovery();

    ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));

    Collections.sort(ports, new Comparator<BoardPort>() {
        @Override
        public int compare(BoardPort o1, BoardPort o2) {
            return BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol())
                    - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol());
        }
    });

    String lastProtocol = null;
    String lastProtocolTranslated;
    for (BoardPort port : ports) {
        if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
            if (lastProtocol != null) {
                serialMenu.addSeparator();
            }
            lastProtocol = port.getProtocol();

            if (BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()) != -1) {
                lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS
                        .get(BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()));
            } else {
                lastProtocolTranslated = port.getProtocol();
            }
            JMenuItem lastProtocolMenuItem = new JMenuItem(_(lastProtocolTranslated));
            lastProtocolMenuItem.setEnabled(false);
            serialMenu.add(lastProtocolMenuItem);
        }
        String address = port.getAddress();
        String label = port.getLabel();

        JCheckBoxMenuItem item = new JCheckBoxMenuItem(label, address.equals(selectedPort));
        item.addActionListener(new SerialMenuListener(address));
        serialMenu.add(item);
    }

    serialMenu.setEnabled(serialMenu.getMenuComponentCount() > 0);
}

From source file:processing.app.Editor.java

protected JMenu buildHelpMenu() {
    // To deal with a Mac OS X 10.5 bug, add an extra space after the name
    // so that the OS doesn't try to insert its slow help menu.
    JMenu menu = new JMenu(_("Help"));
    JMenuItem item;

    /*//w  w w  .  j  av a 2  s  . co m
    // testing internal web server to serve up docs from a zip file
    item = new JMenuItem("Web Server Test");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          //WebServer ws = new WebServer();
          SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      try {
        int port = WebServer.launch("/Users/fry/coconut/processing/build/shared/reference.zip");
        Base.openURL("http://127.0.0.1:" + port + "/reference/setup_.html");
            
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
          });
        }
      });
    menu.add(item);
    */

    /*
    item = new JMenuItem("Browser Test");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          //Base.openURL("http://processing.org/learning/gettingstarted/");
          //JFrame browserFrame = new JFrame("Browser");
          BrowserStartup bs = new BrowserStartup("jar:file:/Users/fry/coconut/processing/build/shared/reference.zip!/reference/setup_.html");
          bs.initUI();
          bs.launch();
        }
      });
    menu.add(item);
    */

    item = new JMenuItem(_("Getting Started"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showArduinoGettingStarted();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Environment"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showEnvironment();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Troubleshooting"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showTroubleshooting();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Reference"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showReference();
        }
    });
    menu.add(item);

    menu.addSeparator();

    item = new JMenuItem(_("Galileo Help"));
    item.setEnabled(false);
    menu.add(item);

    item = new JMenuItem(_("Getting Started"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showReference("reference/Galileo_help_files", "ArduinoIDE_guide_galileo");
        }
    });
    menu.add(item);
    item = new JMenuItem(_("Troubleshooting"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showReference("reference/Galileo_help_files", "Guide_Troubleshooting_Galileo");
            ;
        }
    });
    menu.add(item);

    menu.addSeparator();

    item = new JMenuItem(_("Edison Help"));
    item.setEnabled(false);
    menu.add(item);

    item = new JMenuItem(_("Getting Started"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showReference("reference/Edison_help_files", "ArduinoIDE_guide_edison");
        }
    });
    menu.add(item);
    item = new JMenuItem(_("Troubleshooting"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showReference("reference/Edison_help_files", "Guide_Troubleshooting_Edison");
            ;
        }
    });
    menu.add(item);

    menu.addSeparator();

    item = newJMenuItemShift(_("Find in Reference"), 'F');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //          if (textarea.isSelectionActive()) {
            //            handleFindReference();
            //          }
            handleFindReference();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Frequently Asked Questions"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.showFAQ();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Visit Arduino.cc"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.openURL(_("http://www.arduino.cc/"));
        }
    });
    menu.add(item);

    // macosx already has its own about menu
    if (!OSUtils.isMacOS()) {
        menu.addSeparator();
        item = new JMenuItem(_("About Arduino"));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                base.handleAbout();
            }
        });
        menu.add(item);
    }

    return menu;
}

From source file:processing.app.Editor.java

protected void configurePopupMenu(final SketchTextArea textarea) {

    JPopupMenu menu = textarea.getPopupMenu();

    menu.addSeparator();//from w  w  w.j a  va2 s  . co m

    JMenuItem item = createToolMenuItem("cc.arduino.packages.formatter.AStyle");
    item.setName("menuToolsAutoFormat");

    menu.add(item);

    item = newJMenuItem(_("Comment/Uncomment"), '/');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleCommentUncomment();
        }
    });
    menu.add(item);

    item = newJMenuItem(_("Increase Indent"), ']');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(true);
        }
    });
    menu.add(item);

    item = newJMenuItem(_("Decrease Indent"), '[');
    item.setName("menuDecreaseIndent");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(false);
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Copy for Forum"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleDiscourseCopy();
        }
    });
    menu.add(item);

    item = new JMenuItem(_("Copy as HTML"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleHTMLCopy();
        }
    });
    menu.add(item);

    final JMenuItem referenceItem = new JMenuItem(_("Find in Reference"));
    referenceItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleFindReference();
        }
    });
    menu.add(referenceItem);

    final JMenuItem openURLItem = new JMenuItem(_("Open URL"));
    openURLItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.openURL(e.getActionCommand());
        }
    });
    menu.add(openURLItem);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            String referenceFile = base.getPdeKeywords().getReference(getCurrentKeyword());
            referenceItem.setEnabled(referenceFile != null);

            int offset = textarea.getCaretPosition();
            org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset);
            if (token != null && token.isHyperlink()) {
                openURLItem.setEnabled(true);
                openURLItem.setActionCommand(token.getLexeme());
            } else {
                openURLItem.setEnabled(false);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

}

From source file:processing.app.EditorTab.java

private void configurePopupMenu(final SketchTextArea textarea) {

    JPopupMenu menu = textarea.getPopupMenu();

    menu.addSeparator();//  w w w .ja v  a  2s.co m

    JMenuItem item = editor.createToolMenuItem("cc.arduino.packages.formatter.AStyle");
    if (item == null) {
        throw new NullPointerException("Tool cc.arduino.packages.formatter.AStyle unavailable");
    }
    item.setName("menuToolsAutoFormat");

    menu.add(item);

    item = new JMenuItem(tr("Comment/Uncomment"), '/');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleCommentUncomment();
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Increase Indent"), ']');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(true);
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Decrease Indent"), '[');
    item.setName("menuDecreaseIndent");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleIndentOutdent(false);
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Copy for Forum"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleDiscourseCopy();
        }
    });
    menu.add(item);

    item = new JMenuItem(tr("Copy as HTML"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleHTMLCopy();
        }
    });
    menu.add(item);

    final JMenuItem referenceItem = new JMenuItem(tr("Find in Reference"));
    referenceItem.addActionListener(editor::handleFindReference);
    menu.add(referenceItem);

    final JMenuItem openURLItem = new JMenuItem(tr("Open URL"));
    openURLItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Base.openURL(e.getActionCommand());
        }
    });
    menu.add(openURLItem);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            String referenceFile = editor.base.getPdeKeywords().getReference(getCurrentKeyword());
            referenceItem.setEnabled(referenceFile != null);

            int offset = textarea.getCaretPosition();
            org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset);
            if (token != null && token.isHyperlink()) {
                openURLItem.setEnabled(true);
                openURLItem.setActionCommand(token.getLexeme());
            } else {
                openURLItem.setEnabled(false);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

}

From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerUtil.java

/**
 * Creates a {@link MouseListener} to open the selected log folder in MRA.
 * /*from   w w  w  .  jav  a 2s  .  c  o m*/
 * @param worker
 * @param logFolderList
 * @return
 */
static MouseAdapter createOpenLogInMRAMouseListener(LogsDownloaderWorker worker,
        LogFolderInfoList logFolderList) {
    return new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                // Test if log can be opened in MRA, and open it

                final String baseFxPath = worker.getDirBaseToStoreFiles() + "/" + worker.getLogLabel() + "/"
                        + logFolderList.getSelectedValue() + "/";
                File logFolder = new File(baseFxPath);
                LogValidity isLogOkForOpening = LogUtils.isValidLSFSource(logFolder);

                JPopupMenu popup = new JPopupMenu();
                JMenuItem jm = popup.add(I18n.text("Open this log in MRA"));
                if (isLogOkForOpening == LogValidity.VALID) {
                    File log = LogUtils.getValidLogFileFromLogFolder(logFolder);
                    jm.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            Thread t = new Thread(
                                    LogsDownloaderWorker.class.getSimpleName() + " :: MRA Openner") {
                                public void run() {
                                    JFrame mra = new NeptusMRA();
                                    mra.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

                                    ((NeptusMRA) mra).getMraFilesHandler().openLog(log);
                                };
                            };
                            t.setDaemon(true);
                            t.start();
                        }
                    });
                } else {
                    jm.setEnabled(false);
                }

                popup.show((Component) e.getSource(), e.getX(), e.getY());
            }
        }
    };
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionDatabase(TreePath selPath, DBBrowserNode selectedNode, MouseEvent e) {
    if (e.getClickCount() == 2) {
        return;/* w ww  .  ja  v a2 s.  c o m*/
    }
    boolean connected = false;
    String name = selectedNode.getDBObject().getName();
    DataSourceManager manager = DefaultDataSourceManager.getInstance();
    DataSource ds = manager.getDataSource(name);
    if (ds.getStatus() == DataSourceType.CONNECTED) {
        connected = true;
    } else {
        connected = false;
    }

    // try to create source directory (may not exists if we copy datasource.xml)
    (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator
            + FileReportPersistence.QUERIES_FOLDER)).mkdirs();
    (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator
            + FileReportPersistence.REPORTS_FOLDER)).mkdirs();
    (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator
            + FileReportPersistence.CHARTS_FOLDER)).mkdirs();

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(new DataSourceConnectAction(instance, selPath));
    popupMenu.add(menuItem);
    if (connected) {
        menuItem.setEnabled(false);
    } else {
        menuItem.setEnabled(true);
    }

    JMenuItem menuItem2 = new JMenuItem(new DataSourceDisconnectAction(instance, selectedNode));
    popupMenu.add(menuItem2);
    if (connected) {
        menuItem2.setEnabled(true);
    } else {
        menuItem2.setEnabled(false);
    }

    JMenuItem menuItem5 = new JMenuItem(new DataSourceViewInfoAction(selectedNode));
    popupMenu.add(menuItem5);

    JMenuItem menuItem3 = new JMenuItem(new DataSourceEditAction(instance, selectedNode));
    popupMenu.add(menuItem3);
    if (connected) {
        menuItem3.setEnabled(false);
    } else {
        menuItem3.setEnabled(true);
    }

    JMenuItem menuItem4 = new JMenuItem(new DataSourceDeleteAction(instance, selectedNode));
    popupMenu.add(menuItem4);
    if (connected) {
        menuItem4.setEnabled(false);
    } else {
        menuItem4.setEnabled(true);
    }

    if (!DefaultDataSourceManager.memoryDataSources()) {
        JMenuItem menuItem6 = new JMenuItem(new DataSourceSchemaSelectionAction(instance, selectedNode));
        popupMenu.add(menuItem6);
    }

    popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
}

From source file:savant.view.swing.FrameCommandBar.java

/**
 * Create Tools menu for commandBar.  This is common to all track types.
 *///from  www  .jav  a2  s. c  om
private JMenu createToolsMenu() {
    JMenu menu = new JMenu("Tools");
    JMenuItem item = new JCheckBoxMenuItem("Lock X Axis");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            graphPane.setLocked(!graphPane.isLocked());
        }
    });
    menu.add(item);

    // TODO: experimental feature which doesn't quite work yet
    final JMenuItem itemy = new JCheckBoxMenuItem("Lock Y Axis");
    itemy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Trying to locking Y max: " + !itemy.isSelected());
            graphPane.setYMaxLocked(itemy.isSelected());
        }
    });
    //menu.add(itemy);

    item = new JMenuItem("Copy URL to Clipboard");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Toolkit.getDefaultToolkit().getSystemClipboard()
                    .setContents(new StringSelection(mainTrack.getDataSource().getURI().toString()), null);
        }
    });
    menu.add(item);

    DataFormat df = mainTrack.getDataFormat();
    if (df == DataFormat.SEQUENCE) {
        menu.add(new JSeparator());
        JMenuItem copyItem = new JMenuItem("Copy Sequence to Clipboard");
        copyItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    LocationController lc = LocationController.getInstance();
                    byte[] seq = ((SequenceTrack) mainTrack).getSequence(lc.getReferenceName(), lc.getRange());
                    Toolkit.getDefaultToolkit().getSystemClipboard()
                            .setContents(new StringSelection(new String(seq)), null);
                } catch (Throwable x) {
                    LOG.error(x);
                    DialogUtils.displayError("Unable to copy sequence to clipboard.");
                }
            }
        });
        menu.add(copyItem);

        setAsGenomeButton = new JCheckBoxMenuItem("Set as Genome");
        setAsGenomeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Genome newGenome = Genome.createFromTrack(mainTrack);
                GenomeController.getInstance().setGenome(newGenome);
            }
        });
        menu.add(setAsGenomeButton);
        menu.addMenuListener(new MenuAdapter() {
            @Override
            public void menuSelected(MenuEvent me) {
                Track seqTrack = (Track) GenomeController.getInstance().getGenome().getSequenceTrack();
                if (seqTrack == mainTrack) {
                    setAsGenomeButton.setSelected(true);
                    setAsGenomeButton.setEnabled(false);
                    setAsGenomeButton.setToolTipText("This track is already the reference sequence");
                } else {
                    setAsGenomeButton.setSelected(false);
                    setAsGenomeButton.setEnabled(true);
                    setAsGenomeButton.setToolTipText("Use this track as the reference sequence");
                }
            }
        });
    } else if (df == DataFormat.ALIGNMENT) {
        menu.add(new JSeparator());

        item = new JMenuItem("Filter...");
        item.setToolTipText("Control how records are filtered");

        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new BAMFilterDialog(DialogUtils.getMainWindow(), (BAMTrack) mainTrack).setVisible(true);
            }
        });
        menu.add(item);
    } else if (df == DataFormat.RICH_INTERVAL) {
        menu.add(new JSeparator());

        final JMenuItem bookmarkAll = new JMenuItem("Bookmark All Features");
        bookmarkAll.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DataSource ds = (DataSource) mainTrack.getDataSource();
                if (DialogUtils.askYesNo("Bookmark All Features ",
                        String.format("This will create %d bookmarks.  Are you sure you want to do this?",
                                ds.getDictionaryCount())) == DialogUtils.YES) {
                    ds.addDictionaryToBookmarks();
                    Savant.getInstance().displayBookmarksPanel();
                }
            }
        });
        menu.add(bookmarkAll);

        menu.addMenuListener(new MenuAdapter() {
            @Override
            public void menuSelected(MenuEvent me) {
                bookmarkAll.setEnabled(mainTrack.getDataSource() instanceof DataSource
                        && ((DataSource) mainTrack.getDataSource()).getDictionaryCount() > 0);
            }
        });
    }
    return menu;
}