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:sc.fiji.kappa.gui.KappaMenuBar.java

public void openImage(ImagePlus imp) {
    frame.setImageStack(imp);/*from   ww w .j ava  2s.c om*/

    // Splits the image into the R, G, and B channels, but only if the image is in
    // RGB color
    if (frame.getImageStack().getType() == ImagePlus.COLOR_RGB) {
        frame.setImageStackLayers(ChannelSplitter.splitRGB(frame.getImageStack().getImageStack(), true));
    }

    // Sets the displayed Image Stack to all the channels to begin with.
    frame.setDisplayedImageStack(frame.getImageStack());

    frame.getImageStack().setDisplayMode(IJ.COMPOSITE);

    frame.setMaxLayer(frame.getNFrames());
    frame.setMaxLayerDigits(Integer.toString(frame.getMaxLayer()).length());
    frame.getControlPanel().getCurrentLayerSlider().setValue(frame.getINIT_LAYER());
    frame.getControlPanel().getCurrentLayerSlider().setMaximum(frame.getMaxLayer());
    frame.getControlPanel().getCurrentLayerSlider().setMajorTickSpacing(frame.getNFrames() / 10);
    frame.getControlPanel().getCurrentLayerSlider().setPaintTicks(true);
    frame.getControlPanel().getCurrentLayerSlider().setEnabled(true);
    frame.getControlPanel().getScaleSlider().setEnabled(true);

    // Sets the maximum intensity depending on the bit depth of the image.
    if (frame.isImageRGBColor()) {
        frame.getInfoPanel().getDataThresholdSlider().setMaximum(256);
    } else {
        frame.getInfoPanel().getDataThresholdSlider()
                .setMaximum((int) (Math.pow(2, frame.getDisplayedImageStack().getBitDepth())));
    }

    // Reset channel buttons
    for (int i = 0; i < 3; i++) {
        frame.getControlPanel().getChannelButtons()[i].setEnabled(false);
        frame.getControlPanel().getChannelButtons()[i].setSelected(false);
    }

    // Sets the buttons to active and selected if the image type is a Color one.
    // Otherwise sets them to inactive
    if (frame.getImageStack().getNChannels() > 1) {
        for (int i = 0; i < frame.getImageStack().getNChannels(); i++) {
            frame.getControlPanel().getChannelButtons()[i].setEnabled(true);
            frame.getControlPanel().getChannelButtons()[i].setSelected(true);
        }
    }

    // Sets the scroll pane in the drawing panel to display the first layer of the
    // image now
    frame.setFrame(1);
    frame.setCurrImage(frame.getDisplayedImageStack().getBufferedImage());
    frame.getCurrImageLabel().setIcon(new ImageIcon(frame.getCurrImage()));
    frame.setThresholded(new boolean[frame.getCurrImage().getWidth()][frame.getCurrImage().getHeight()]);

    // Sets the maximum scale to a value that prevents a heap space error from
    // occuring.
    // We set the maximum image size to about 2000 x 2000 pixels = 4,000,000 pixels.
    int avgPixelDim = (frame.getCurrImage().getWidth() + frame.getCurrImage().getHeight()) / 2;
    frame.getControlPanel().getScaleSlider().setValue(ControlPanel.DEFAULT_SCALE);
    frame.getControlPanel().getScaleSlider()
            .setMaximum(Math.min(ControlPanel.MAX_SCALE, ControlPanel.MAX_AVG_PIXEL_DIM / avgPixelDim * 100));

    this.frame.updateThresholded();
    frame.getInfoPanel().getThresholdChannelsComboBox().setEnabled(true);
    frame.getInfoPanel().getThresholdSlider().setEnabled(true);
    frame.getInfoPanel().getRangeAveragingSpinner().setEnabled(true);
    frame.getInfoPanel().getBgCheckBox().setEnabled(true);
    frame.getInfoPanel().getApply().setEnabled(true);
    frame.getInfoPanel().getRevert().setEnabled(true);
    fit.setEnabled(true);

    // Enables view checkboxes
    getBoundingBoxMenu().setEnabled(true);
    getScaleCurvesMenu().setEnabled(true);
    getAntialiasingMenu().setEnabled(true);
    getTangentMenu().setEnabled(true);

    // Enables toolbar buttons and selects the direct selection tool
    frame.getToolPanel().enableAllButtons();

    // Enables Menu Items
    zoomIn.setEnabled(true);
    zoomOut.setEnabled(true);
    for (JMenuItem menuItem : toolMenuItems) {
        menuItem.setEnabled(true);
    }
    prevFrame.setEnabled(true);
    nextFrame.setEnabled(true);
    prevKeyframe.setEnabled(true);
    nextKeyframe.setEnabled(true);
    adjustBrightnessContrast.setEnabled(true);

    // Adds file name to the frame.
    this.frame.setTitle(KappaFrame.APPLICATION_NAME + "- " + imp.getTitle());

    // Load Kappa file if available
    if (imp.getOriginalFileInfo() != null) {
        String dirPath = imp.getOriginalFileInfo().directory;
        if (dirPath != null) {
            String kappaPath = FilenameUtils.removeExtension(imp.getOriginalFileInfo().fileName);
            kappaPath += ".kapp";
            File fullPath = new File(dirPath, kappaPath);
            if (fullPath.exists()) {
                loadCurveFile(fullPath);
            }
        }
    }
}

From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java

private JMenu createShortMenu() {
    JMenu shortMenu = new JMenu();
    addDarkModeCallback(b -> {/*from  www.j a v  a  2  s.com*/
        shortMenu.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE.brighter());
        shortMenu.setForeground(b ? Color.WHITE : OPENBST_BLUE);
    });
    shortMenu.setBackground(OPENBST_BLUE.brighter());
    shortMenu.setForeground(OPENBST_BLUE);
    shortMenu.setText(Lang.get("banner.title"));
    shortMenu.setIcon(new ImageIcon(Icons.getImage("Logo", 16)));
    JMenuItem label = new JMenuItem(Lang.get("menu.title"));
    label.setEnabled(false);
    shortMenu.add(label);
    shortMenu.addSeparator();
    shortMenu.add(
            new JMenuItem(new AbstractAction(Lang.get("menu.open"), new ImageIcon(Icons.getImage("Open", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    openStory(VisualsUtils.askForFile(OpenBSTGUI.this, Lang.get("file.title")));
                }
            }));

    shortMenu.addSeparator();

    shortMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.create"), new ImageIcon(Icons.getImage("Add Property", 16))) {
                private static final long serialVersionUID = 1L;

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

    JMenu additionalMenu = new JMenu(Lang.get("menu.advanced"));
    shortMenu.add(additionalMenu);

    additionalMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.package"), new ImageIcon(Icons.getImage("Open Archive", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    new PackageDialog(instance).setVisible(true);
                }
            }));
    additionalMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("langcheck"), new ImageIcon(Icons.getImage("LangCheck", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    final Map<String, String> languages = new Gson()
                            .fromJson(new InputStreamReader(
                                    OpenBST.class.getResourceAsStream(
                                            "/utybo/branchingstorytree/swing/lang/langs.json"),
                                    StandardCharsets.UTF_8), new TypeToken<Map<String, String>>() {
                                    }.getType());
                    languages.remove("en");
                    languages.remove("default");
                    JComboBox<String> jcb = new JComboBox<>(new Vector<>(languages.keySet()));
                    JPanel panel = new JPanel();
                    panel.add(new JLabel(Lang.get("langcheck.choose")));
                    panel.add(jcb);
                    int result = JOptionPane.showOptionDialog(OpenBSTGUI.this, panel, Lang.get("langcheck"),
                            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                    if (result == JOptionPane.OK_OPTION) {
                        Locale selected = new Locale((String) jcb.getSelectedItem());
                        if (!Lang.getMap().keySet().contains(selected)) {
                            try {
                                Lang.loadTranslationsFromFile(selected,
                                        OpenBST.class
                                                .getResourceAsStream("/utybo/branchingstorytree/swing/lang/"
                                                        + languages.get(jcb.getSelectedItem().toString())));
                            } catch (UnrespectedModelException | IOException e1) {
                                LOG.warn("Failed to load translation file", e1);
                            }
                        }
                        ArrayList<String> list = new ArrayList<>();
                        Lang.getLocaleMap(Locale.ENGLISH).forEach((k, v) -> {
                            if (!Lang.getLocaleMap(selected).containsKey(k)) {
                                list.add(k + "\n");
                            }
                        });
                        StringBuilder sb = new StringBuilder();
                        Collections.sort(list);
                        list.forEach(s -> sb.append(s));
                        JDialog dialog = new JDialog(OpenBSTGUI.this, Lang.get("langcheck"));
                        dialog.getContentPane().setLayout(new MigLayout());
                        dialog.getContentPane().add(new JLabel(Lang.get("langcheck.result")),
                                "pushx, growx, wrap");
                        JTextArea area = new JTextArea();
                        area.setLineWrap(true);
                        area.setWrapStyleWord(true);
                        area.setText(sb.toString());
                        area.setEditable(false);
                        area.setBorder(BorderFactory.createLoweredBevelBorder());
                        JScrollPane jsp = new JScrollPane(area);
                        jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                        dialog.getContentPane().add(jsp, "pushx, pushy, growx, growy");
                        dialog.setSize((int) (Icons.getScale() * 300), (int) (Icons.getScale() * 300));
                        dialog.setLocationRelativeTo(OpenBSTGUI.this);
                        dialog.setModalityType(ModalityType.APPLICATION_MODAL);
                        dialog.setVisible(true);
                    }
                }
            }));

    additionalMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.debug"), new ImageIcon(Icons.getImage("Code", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    DebugInfo.launch(OpenBSTGUI.this);
                }
            }));

    JMenu includedFiles = new JMenu("Included BST files");

    for (Entry<String, String> entry : OpenBST.getInternalFiles().entrySet()) {
        JMenuItem jmi = new JMenuItem(entry.getKey());
        jmi.addActionListener(ev -> {
            String path = "/bst/" + entry.getValue();
            InputStream is = OpenBSTGUI.class.getResourceAsStream(path);
            ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(OpenBSTGUI.this, "Extracting...",
                    is);
            new Thread(() -> {
                try {
                    File f = File.createTempFile("openbstinternal", ".bsp");
                    FileOutputStream fos = new FileOutputStream(f);
                    IOUtils.copy(pmis, fos);
                    openStory(f);
                } catch (final IOException e) {
                    LOG.error("IOException caught", e);
                    showException(Lang.get("file.error").replace("$e", e.getClass().getSimpleName())
                            .replace("$m", e.getMessage()), e);
                }

            }).start();

        });
        includedFiles.add(jmi);
    }
    additionalMenu.add(includedFiles);

    shortMenu.addSeparator();

    JMenu themesMenu = new JMenu(Lang.get("menu.themes"));
    shortMenu.add(themesMenu);
    themesMenu.setIcon(new ImageIcon(Icons.getImage("Color Wheel", 16)));
    ButtonGroup themesGroup = new ButtonGroup();
    JRadioButtonMenuItem jrbmi;

    jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.dark"));
    if (0 == selectedTheme) {
        jrbmi.setSelected(true);
    }
    jrbmi.addActionListener(e -> switchLaF(0, DARK_THEME));
    themesMenu.add(jrbmi);
    themesGroup.add(jrbmi);

    jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.light"));
    if (1 == selectedTheme) {
        jrbmi.setSelected(true);
    }
    jrbmi.addActionListener(e -> switchLaF(1, LIGHT_THEME));
    themesMenu.add(jrbmi);
    themesGroup.add(jrbmi);

    jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.debug"));
    if (2 == selectedTheme) {
        jrbmi.setSelected(true);
    }
    jrbmi.addActionListener(e -> switchLaF(2, DEBUG_THEME));
    themesMenu.add(jrbmi);
    themesGroup.add(jrbmi);

    JMenu additionalLightThemesMenu = new JMenu(Lang.get("menu.themes.morelight"));
    int j = 3;
    for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_LIGHT_THEMES.entrySet()) {
        int jf = j;
        jrbmi = new JRadioButtonMenuItem(entry.getKey());
        if (j == selectedTheme)
            jrbmi.setSelected(true);
        jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue()));
        additionalLightThemesMenu.add(jrbmi);
        themesGroup.add(jrbmi);
        j++;
    }
    themesMenu.add(additionalLightThemesMenu);

    JMenu additionalDarkThemesMenu = new JMenu(Lang.get("menu.themes.moredark"));
    for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_DARK_THEMES.entrySet()) {
        int jf = j;
        jrbmi = new JRadioButtonMenuItem(entry.getKey());
        if (j == selectedTheme)
            jrbmi.setSelected(true);
        jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue()));
        additionalDarkThemesMenu.add(jrbmi);
        themesGroup.add(jrbmi);
        j++;
    }
    themesMenu.add(additionalDarkThemesMenu);

    shortMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.about"), new ImageIcon(Icons.getImage("About", 16))) {
                /**
                 *
                 */
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    new AboutDialog(instance).setVisible(true);
                }
            }));

    return shortMenu;
}

From source file:view.WorkspacePanel.java

private void btnValidateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnValidateActionPerformed
    if (mainWindow.getOpenedFiles().size() > 1) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem m = null;
        ActionListener validateOne = new ActionListener() {
            @Override//w ww  .j  a va 2s. c o m
            public void actionPerformed(ActionEvent e) {
                if (!rightPanel.isVisible()) {
                    changeCard(CardEnum.VALIDATE_PANEL, true);
                    startValidationThread();
                } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) {
                    String msg = Bundle.getBundle().getString("yes");
                    Object[] options = { Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"),
                            Bundle.getBundle().getString("no") };
                    int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION,
                            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                    if (opt == JOptionPane.YES_OPTION) {
                        status = Status.READY;
                        changeCard(CardEnum.VALIDATE_PANEL, true);
                        startValidationThread();
                    }
                }
            }
        };
        ActionListener validateAll = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MultipleValidationDialog mvd = new MultipleValidationDialog(mainWindow, true,
                        mainWindow.getOpenedFiles());
                mvd.setLocationRelativeTo(null);
                mvd.setVisible(true);
            }
        };
        int numSigs = CCInstance.getInstance().getNumberOfSignatures(document.getDocumentLocation());
        if (numSigs == 0) {
            m = new JMenuItem(Bundle.getBundle().getString("notSigned"));
            m.addActionListener(validateOne);
            m.setEnabled(false);
            popup.add(m);
        } else {
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateOnlyThis"));
            m.addActionListener(validateOne);
            popup.add(m);
        }

        if (mainWindow.getSelectedOpenedFiles().size() > 1
                && mainWindow.getSelectedOpenedFiles().size() < mainWindow.getOpenedFiles().size()) {
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAllSelected"));
            m.addActionListener(validateAll);
            popup.add(m);
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll"));
            m.addActionListener(validateAll);
            popup.add(m);
        } else {
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll"));
            m.addActionListener(validateAll);
            popup.add(m);
        }

        popup.setLightWeightPopupEnabled(true);
        popup.show(btnValidate, 0, btnValidate.getHeight());

    } else if (!rightPanel.isVisible()) {
        changeCard(CardEnum.VALIDATE_PANEL, true);
        startValidationThread();
    } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) {
        String msg = Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1");
        Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") };
        int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        if (opt == JOptionPane.YES_OPTION) {
            status = Status.READY;
            changeCard(CardEnum.VALIDATE_PANEL, true);
            startValidationThread();
        } else {
            return;
        }
    }
    removeTempSignature();
}