Java Code Examples for javax.swing.JCheckBoxMenuItem#setAction()

The following examples show how to use javax.swing.JCheckBoxMenuItem#setAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScenarioEditor.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) {
    final JToggleButton toggle = new JToggleButton();
    final JCheckBoxMenuItem check = new JCheckBoxMenuItem();
    Action action = new AbstractAction(t.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (currentTool != null) {
                    currentTool.deactivate();
                }
                currentTool = t;
                toggle.setSelected(true);
                check.setSelected(true);
                currentTool.activate();
            }
        };
    toggle.setAction(action);
    check.setAction(action);
    menu.add(check);
    toolbar.add(toggle);
    menuGroup.add(check);
    toolbarGroup.add(toggle);
}
 
Example 2
Source File: GMLEditor.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) {
    final JToggleButton toggle = new JToggleButton();
    final JCheckBoxMenuItem check = new JCheckBoxMenuItem();
    Action action = new AbstractAction(t.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (currentTool != null) {
                    currentTool.deactivate();
                }
                currentTool = t;
                toggle.setSelected(true);
                check.setSelected(true);
                currentTool.activate();
            }
        };
    toggle.setAction(action);
    check.setAction(action);
    menu.add(check);
    if (toolbar != null) {
        toolbar.add(toggle);
        toolbarGroup.add(toggle);
    }
    menuGroup.add(check);
}
 
Example 3
Source File: EditorFrame.java    From settlers-remake with MIT License 6 votes vote down vote up
/**
 * Create a checkbox menu item
 * 
 * @param action
 *            The target action
 * 
 * @return JMenuItem
 */
private JMenuItem createCheckboxMenuItemForAction(final Action action) {
	final JCheckBoxMenuItem it = new JCheckBoxMenuItem();
	it.setAction(action);
	it.addChangeListener(e -> {
		Object oldValue = action.getValue(EditorFrame.CHECKBOX_VALUE);

		if (oldValue != null && oldValue.equals(it.isSelected())) {
			return;
		}

		action.putValue(EditorFrame.CHECKBOX_VALUE, it.isSelected());
		action.actionPerformed(new ActionEvent(it, 0, "changed"));
	});
	action.addPropertyChangeListener(evt -> {
		if (EditorFrame.CHECKBOX_VALUE.equals(evt.getPropertyName())) {
			Boolean checked = (Boolean) evt.getNewValue();
			if (it.isSelected() != checked) {
				it.setSelected(checked);
			}
		}
	});
	return it;
}
 
Example 4
Source File: ViewPluginPanelsMenu.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
 * Removes/adds plugin panels depending on the <code>OperationMode</code>.
 *
 * @param operationMode The operation mode.
 */
private void evaluatePluginPanels(OperationMode operationMode) {
  Kernel.State kernelState = OperationMode.equivalent(operationMode);
  if (kernelState == null) {
    return;
  }

  removeAll();

  SortedSet<PluggablePanelFactory> factories = new TreeSet<>((factory1, factory2) -> {
    return factory1.getPanelDescription().compareTo(factory2.getPanelDescription());
  });
  factories.addAll(panelRegistry.getFactories());

  for (final PluggablePanelFactory factory : factories) {
    if (factory.providesPanel(kernelState)) {
      String title = factory.getPanelDescription();
      final JCheckBoxMenuItem utilMenuItem = new JCheckBoxMenuItem();
      utilMenuItem.setAction(new AddPluginPanelAction(view, factory));
      utilMenuItem.setText(title);
      dockingManager.addPropertyChangeListener(new PluginPanelPropertyHandler(utilMenuItem));
      add(utilMenuItem);
    }
  }
  // If the menu is empty, add a single disabled menu item to it that explains
  // to the user that no plugin panels are available.
  if (getMenuComponentCount() == 0) {
    JMenuItem dummyItem = new JMenuItem(BUNDLE.getString("viewPluginPanelsMenu.menuItem_none.text"));
    dummyItem.setEnabled(false);
    add(dummyItem);
  }
}
 
Example 5
Source File: BoolSettingAction.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Overrides {@link XAction#addToMenu(JMenu)} to add a {@link JCheckBoxMenuItem} instead of a {@link JMenuItem}.
 */
@Override
public JMenuItem addToMenu( final JMenu menu ) {
	final JCheckBoxMenuItem mi = new JCheckBoxMenuItem();
	
	menu.add( mi );
	mi.setAction( this );
	mi.setToolTipText( null ); // We don't want tool tip on menu items...
	
	return mi;
}
 
Example 6
Source File: BoolSettingAction.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Overrides {@link XAction#addToMenu(JPopupMenu)} to add a {@link JCheckBoxMenuItem} instead of a {@link JMenuItem}.
 */
@Override
public JMenuItem addToMenu( final JPopupMenu menu ) {
	final JCheckBoxMenuItem mi = new JCheckBoxMenuItem();
	
	menu.add( mi );
	mi.setAction( this );
	mi.setToolTipText( null ); // We don't want tool tip on menu items...
	
	return mi;
}
 
Example 7
Source File: DataPanel.java    From DiskBrowser with GNU General Public License v3.0 4 votes vote down vote up
public DataPanel (MenuHandler mh)
// ---------------------------------------------------------------------------------//
{
  this.menuHandler = mh;
  setTabPlacement (SwingConstants.BOTTOM);

  formattedText = new JTextArea (10, TEXT_WIDTH);
  formattedPane = setPanel (formattedText, "Formatted");
  //    formattedText.setLineWrap (prefs.getBoolean (MenuHandler.PREFS_LINE_WRAP, true));
  formattedText.setText ("Please use the 'File->Set HOME folder...' command to "
      + "\ntell DiskBrowser where your Apple disks are located."
      + "\n\nTo see the contents of a disk in more detail, double-click"
      + "\nthe disk. You will then be able to select individual files to "
      + "view completely.");

  hexText = new JTextArea (10, TEXT_WIDTH);
  setPanel (hexText, "Hex dump");

  disassemblyText = new JTextArea (10, TEXT_WIDTH);
  setPanel (disassemblyText, "Disassembly");

  imagePanel = new ImagePanel ();
  imagePane =
      new JScrollPane (imagePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
          ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

  imagePane.setBorder (null);

  imagePane.getVerticalScrollBar ().setUnitIncrement (50);
  imagePane.getHorizontalScrollBar ().setUnitIncrement (25);

  addChangeListener (new ChangeListener ()
  {
    @Override
    public void stateChanged (ChangeEvent e)
    {
      switch (getSelectedIndex ())
      {
        case 0:
          if (!formattedTextValid)
          {
            if (currentDataSource == null)
              formattedText.setText ("");
            else
              setText (formattedText, currentDataSource.getText ());
            formattedTextValid = true;
          }
          break;
        case 1:
          if (!hexTextValid)
          {
            if (currentDataSource == null)
              hexText.setText ("");
            else
              setText (hexText, currentDataSource.getHexDump ());
            hexTextValid = true;
          }
          break;
        case 2:
          if (!assemblerTextValid)
          {
            if (currentDataSource == null)
              disassemblyText.setText ("");
            else
              setText (disassemblyText, currentDataSource.getAssembler ());
            assemblerTextValid = true;
          }
          break;
        default:
          System.out.println ("Invalid index selected in DataPanel");
      }
    }
  });

  LineWrapAction lineWrapAction = new LineWrapAction ();
  menuHandler.lineWrapItem.setAction (lineWrapAction);
  lineWrapAction.addListener (formattedText);

  menuHandler.colourQuirksItem.setAction (new ColourQuirksAction (this));
  menuHandler.monochromeItem.setAction (new MonochromeAction (this));
  menuHandler.debuggingItem.setAction (new DebuggingAction (this));

  // fill in the placeholders created by the MenuHandler
  List<Palette> palettes = HiResImage.getPalettes ();
  ButtonGroup buttonGroup = menuHandler.paletteGroup;
  Enumeration<AbstractButton> enumeration = buttonGroup.getElements ();
  int ndx = 0;
  while (enumeration.hasMoreElements ())
  {
    JCheckBoxMenuItem item = (JCheckBoxMenuItem) enumeration.nextElement ();
    item.setAction (new PaletteAction (this, palettes.get (ndx++)));
  }
  menuHandler.nextPaletteItem.setAction (new NextPaletteAction (this, buttonGroup));
  menuHandler.prevPaletteItem.setAction (new PreviousPaletteAction (this, buttonGroup));
}