Example usage for javax.swing JCheckBoxMenuItem setSelected

List of usage examples for javax.swing JCheckBoxMenuItem setSelected

Introduction

In this page you can find the example usage for javax.swing JCheckBoxMenuItem setSelected.

Prototype

public void setSelected(boolean b) 

Source Link

Document

Sets the state of the button.

Usage

From source file:edu.ku.brc.af.core.SchemaI18NService.java

/**
 * Checks (selects) the MenuItem of the current locale.
 *///from  ww  w  . j a  v  a 2  s  . c  om
public void checkCurrentLocaleMenu() {
    for (JCheckBoxMenuItem cbmi : localeMenuItems) {
        if (cbmi.getText().equals(currentLocale.getDisplayName())) {
            cbmi.setSelected(true);
        } else {
            cbmi.setSelected(false);
        }
    }
}

From source file:com.sshtools.appframework.api.ui.ActionBuilder.java

protected void rebuildContextMenu(Collection<AppAction> enabledActions) {
    contextMenu.invalidate();// www.  j a v a 2 s . c  o  m

    // Build the context menu action list
    List<AppAction> contextMenuActions = new ArrayList<AppAction>();
    contextMenu.removeAll();
    for (AppAction action : enabledActions) {
        if (Boolean.TRUE.equals(action.getValue(AppAction.ON_CONTEXT_MENU))) {
            contextMenuActions.add(action);
        }
    }
    log.debug("There are " + contextMenuActions.size() + " on the context menu");
    Collections.sort(contextMenuActions, new ContextActionComparator());

    // Build the context menu
    Integer grp = null;
    for (AppAction action : contextMenuActions) {
        if ((grp != null) && !grp.equals(action.getValue(AppAction.CONTEXT_MENU_GROUP))) {
            contextMenu.addSeparator();
        }
        if (Boolean.TRUE.equals(action.getValue(AppAction.IS_TOGGLE_BUTTON))) {
            final JCheckBoxMenuItem item = new JCheckBoxMenuItem(action);
            action.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals(AppAction.IS_SELECTED)) {
                        item.setSelected(((Boolean) evt.getNewValue()).booleanValue());
                    }
                }
            });
            contextMenu.add(item);
            item.setSelected(Boolean.TRUE.equals(action.getValue(AppAction.IS_SELECTED)));
        } else {
            contextMenu.add(action);
        }
        grp = (Integer) action.getValue(AppAction.CONTEXT_MENU_GROUP);
    }
    contextMenu.validate();
    contextMenu.repaint();
}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

private JPopupMenu getColumnMenu() {
    JPopupMenu columnMenu = new JPopupMenu();
    DefaultTableModel model = (DefaultTableModel) getModel();

    for (int i = 0; i < model.getColumnCount(); i++) {
        final String columnName = model.getColumnName(i);
        // Get the column object by name. Using an index may not return the column object if the column is hidden
        TableColumnExt column = getColumnExt(columnName);

        // Create the menu item
        final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName);
        // Show or hide the checkbox
        menuItem.setSelected(column.isVisible());

        menuItem.addActionListener(new ActionListener() {
            @Override/*from   w  w w.  ja  va2s .  c  o  m*/
            public void actionPerformed(ActionEvent evt) {
                TableColumnExt column = getColumnExt(menuItem.getText());
                // Determine whether to show or hide the selected column
                boolean enable = !column.isVisible();
                // Do not hide a column if it is the last remaining visible column              
                if (enable || getColumnCount() > 1) {
                    column.setVisible(enable);
                    saveColumnOrder();
                }
            }
        });

        columnMenu.add(menuItem);
    }

    columnMenu.addSeparator();

    JMenuItem menuItem = new JMenuItem("Restore Default");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            restoreDefaultColumnPreferences();

        }

    });
    columnMenu.add(menuItem);

    return columnMenu;
}

From source file:de.hstsoft.sdeep.view.MainWindow.java

private void createUI() {
    mapView = new MapView();
    getContentPane().add(mapView, BorderLayout.CENTER);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*  w ww. j av a  2 s  .  c o m*/

    JMenu mnFile = new JMenu("File");
    menuBar.add(mnFile);

    JMenuItem mntmOpenSaveGame = new JMenuItem("Open Savegame");
    mntmOpenSaveGame.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            openFileChooser();
        }
    });
    mnFile.add(mntmOpenSaveGame);

    mnFile.addSeparator();

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    mnFile.add(mntmExit);

    JMenu mnView = new JMenu("View");
    menuBar.add(mnView);

    final JCheckBoxMenuItem menuItemShowinfo = new JCheckBoxMenuItem("ShowInfo");
    menuItemShowinfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showInfo = menuItemShowinfo.isSelected();
            mapView.setShowInfo(showInfo);
        }
    });
    menuItemShowinfo.setSelected(mapView.isShowInfo());
    mnView.add(menuItemShowinfo);

    final JCheckBoxMenuItem menuItemShowgrid = new JCheckBoxMenuItem("ShowGrid");
    menuItemShowgrid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showGrid = menuItemShowgrid.isSelected();
            mapView.setShowGrid(showGrid);
        }
    });
    menuItemShowgrid.setSelected(mapView.isShowGrid());
    mnView.add(menuItemShowgrid);

    final JCheckBoxMenuItem menuItemNotes = new JCheckBoxMenuItem("ShowNotes");
    menuItemNotes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showNotes = menuItemNotes.isSelected();
            mapView.setShowNotes(showNotes);
        }
    });
    menuItemNotes.setSelected(mapView.isShowNotes());
    mnView.add(menuItemNotes);

    final JCheckBoxMenuItem menuItemAnimals = new JCheckBoxMenuItem("ShowAnimals");
    menuItemAnimals.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showAnimals = menuItemAnimals.isSelected();
            mapView.setShowAnimals(showAnimals);
        }
    });
    menuItemAnimals.setSelected(mapView.isShowAnimals());
    mnView.add(menuItemAnimals);

    mnView.addSeparator();

    menuItemFileWatcher = new JCheckBoxMenuItem("Auto refresh");
    menuItemFileWatcher.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean enabled = menuItemFileWatcher.isSelected();
            toggleAutoRefresh(enabled);
        }
    });
    mnView.add(menuItemFileWatcher);

    mnView.addSeparator();

    JMenuItem menuItemResetView = new JMenuItem("Reset view");
    menuItemResetView.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            mapView.resetView();
        }
    });
    mnView.add(menuItemResetView);

    JMenu mnInfo = new JMenu("Info");
    menuBar.add(mnInfo);

    JMenuItem mntmInfo = new JMenuItem("About");
    mntmInfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showInfo();
        }
    });
    mnInfo.add(mntmInfo);

}

From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.java

@SuppressWarnings("serial")
private JMenuBar createMenu() {
    JMenuBar menuBar = new JMenuBar();

    // the file menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.add(this.saveGraphImageAction);
    menuBar.add(fileMenu);//  w  w w.ja  v a 2s  .co  m

    // the tools menu
    JMenu toolsMenu = new JMenu("Tools");
    JMenuItem configureGraphItem = new JMenuItem("Configure Graph...");
    configureGraphItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ResidualPlotPanel.this.chartConfigurationDialog.setVisible(true);
        }
    });
    toolsMenu.add(configureGraphItem);
    toolsMenu.addSeparator();

    toolsMenu.add(new AbstractAction("Zoom Out") {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ResidualPlotPanel.this.autoRangeChart();
        }
    });
    toolsMenu.addSeparator();

    JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point");
    showTooltipCheckbox.setSelected(true);
    this.showTooltip = true;
    showTooltipCheckbox.addItemListener(new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            ResidualPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED;
            ResidualPlotPanel.this.clearProbePopup();
        }
    });
    toolsMenu.add(showTooltipCheckbox);
    menuBar.add(toolsMenu);

    // the help menu
    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Help...",
            new ImageIcon(ResidualPlotAction.class.getResource("/images/action/help-16x16.png")));
    helpMenuItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            Maanova.getInstance().showHelp("residual-plot", ResidualPlotPanel.this);
        }
    });
    helpMenu.add(helpMenuItem);
    menuBar.add(helpMenu);

    return menuBar;
}

From source file:org.jax.maanova.madata.gui.ArrayScatterPlotPanel.java

@SuppressWarnings("serial")
private JMenuBar createMenu() {
    JMenuBar menuBar = new JMenuBar();

    // the file menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.add(this.saveGraphImageAction);
    menuBar.add(fileMenu);/*from w ww .jav  a2 s  .  com*/

    // the tools menu
    JMenu toolsMenu = new JMenu("Tools");
    JMenuItem configureGraphItem = new JMenuItem("Configure Graph...");
    configureGraphItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ArrayScatterPlotPanel.this.chartConfigurationDialog.setVisible(true);
        }
    });
    toolsMenu.add(configureGraphItem);
    toolsMenu.addSeparator();

    toolsMenu.add(new AbstractAction("Zoom Out") {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ArrayScatterPlotPanel.this.autoRangeChart();
        }
    });

    JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point");
    showTooltipCheckbox.setSelected(true);
    this.showTooltip = true;
    showTooltipCheckbox.addItemListener(new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            ArrayScatterPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED;
            ArrayScatterPlotPanel.this.clearProbePopup();
        }
    });
    toolsMenu.add(showTooltipCheckbox);
    menuBar.add(toolsMenu);

    // the help menu
    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Help...");
    Icon helpIcon = new ImageIcon(ArrayScatterPlotPanel.class.getResource("/images/action/help-16x16.png"));
    helpMenuItem.setIcon(helpIcon);
    helpMenuItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            Maanova.getInstance().showHelp("array-scatter-plot", ArrayScatterPlotPanel.this);
        }
    });
    helpMenu.add(helpMenuItem);
    menuBar.add(helpMenu);

    return menuBar;
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initOHLCSeries(int datasetNumber, XYDataset dataset, SeriesDefinitionVO seriesDefinition) {

    BarDefinitionVO barDefinition = (BarDefinitionVO) seriesDefinition;
    OHLCSeriesCollection ohlcSeriesCollection = (OHLCSeriesCollection) dataset;
    ohlcSeriesCollection.setXPosition(TimePeriodAnchor.START);

    // create the TimeSeries
    OHLCSeries series = new OHLCSeries(barDefinition.getLabel());
    ohlcSeriesCollection.addSeries(series);
    this.bars.put(barDefinition.getSecurityId(), series);

    // get the seriesNumber & color
    final int seriesNumber = ohlcSeriesCollection.getSeriesCount() - 1;

    // configure the renderer
    final CandlestickRenderer renderer = (CandlestickRenderer) getPlot().getRenderer(datasetNumber);
    renderer.setSeriesPaint(seriesNumber, getColor(barDefinition.getColor()));
    renderer.setSeriesVisible(seriesNumber, seriesDefinition.isSelected());
    renderer.setAutoWidthMethod(HideableCandlestickRenderer.WIDTHMETHOD_SMALLEST);

    // add the menu item
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel());
    menuItem.setSelected(seriesDefinition.isSelected());
    menuItem.addActionListener(new ActionListener() {
        @Override/*from w w  w.ja  va 2  s.  c o  m*/
        public void actionPerformed(ActionEvent e) {
            resetAxis();
            renderer.setSeriesVisible(seriesNumber, ((JCheckBoxMenuItem) e.getSource()).isSelected(), true);
            initAxis();
        }
    });
    this.getPopupMenu().add(menuItem);
}

From source file:cl.almejo.vsim.gui.SimWindow.java

private JMenuItem newCheckboxMenuItem(WindowAction action, char mnemonic, boolean selected) {
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(action);
    menuItem.setMnemonic(mnemonic);/*from w  w  w  .j  ava2 s. c o m*/
    menuItem.setSelected(selected);
    return menuItem;
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initTimeSeries(int datasetNumber, XYDataset dataset, SeriesDefinitionVO seriesDefinition) {

    IndicatorDefinitionVO indicatorDefinition = (IndicatorDefinitionVO) seriesDefinition;
    TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) dataset;

    // create the TimeSeries
    TimeSeries series = new TimeSeries(indicatorDefinition.getLabel());
    timeSeriesCollection.addSeries(series);
    this.indicators.put(indicatorDefinition.getName(), series);

    // get the seriesNumber & color
    final int seriesNumber = timeSeriesCollection.getSeriesCount() - 1;

    // configure the renderer
    final XYItemRenderer renderer = getPlot().getRenderer(datasetNumber);
    renderer.setSeriesPaint(seriesNumber, getColor(indicatorDefinition.getColor()));
    renderer.setSeriesVisible(seriesNumber, seriesDefinition.isSelected());
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

    if (seriesDefinition.isDashed()) {
        renderer.setSeriesStroke(seriesNumber, new BasicStroke(0.5f, BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f));
    } else {/*  ww  w. ja  v  a 2 s. c o  m*/
        renderer.setSeriesStroke(seriesNumber, new BasicStroke(0.5f));
    }

    // add the menu item
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel());
    menuItem.setSelected(seriesDefinition.isSelected());
    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetAxis();
            renderer.setSeriesVisible(seriesNumber, ((JCheckBoxMenuItem) e.getSource()).isSelected());
            initAxis();
        }
    });
    this.getPopupMenu().add(menuItem);
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initMarker(SeriesDefinitionVO seriesDefinition) {

    final MarkerDefinitionVO markerDefinition = (MarkerDefinitionVO) seriesDefinition;

    final Marker marker;
    if (markerDefinition.isInterval()) {
        marker = new IntervalMarker(0, 0);
        marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); // position of the label
        marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); // position of the text within the label
    } else {/*from w w w. j ava2s .co m*/
        marker = new ValueMarker(0);
        marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    }

    marker.setPaint(getColor(markerDefinition.getColor()));
    marker.setLabel(markerDefinition.getLabel());
    marker.setLabelFont(new Font("SansSerif", 0, 9));

    if (seriesDefinition.isDashed()) {
        marker.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                new float[] { 5.0f }, 0.0f));
    } else {
        marker.setStroke(new BasicStroke(1.0f));
    }

    getPlot().addRangeMarker(marker, markerDefinition.isInterval() ? Layer.BACKGROUND : Layer.FOREGROUND);

    this.markers.put(markerDefinition.getName(), marker);
    this.markersSelectionStatus.put(markerDefinition.getName(), seriesDefinition.isSelected());

    // add the menu item
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel());
    menuItem.setSelected(seriesDefinition.isSelected());
    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetAxis();
            boolean selected = ((JCheckBoxMenuItem) e.getSource()).isSelected();
            ChartTab.this.markersSelectionStatus.put(markerDefinition.getName(), selected);
            if (selected) {
                if (marker instanceof ValueMarker) {
                    marker.setAlpha(1.0f);
                } else {
                    marker.setAlpha(0.5f);
                }
            } else {
                marker.setAlpha(0);
            }
            initAxis();
        }
    });
    this.getPopupMenu().add(menuItem);
}