setAction ( )源码实例Demo

javax.swing.JCheckBoxMenuItem#setAction ( )源码实例Demo

下面列出了javax.swing.JCheckBoxMenuItem#setAction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rcrs-server   文件: ScenarioEditor.java
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);
}
 
源代码2 项目: rcrs-server   文件: GMLEditor.java
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);
}
 
源代码3 项目: settlers-remake   文件: EditorFrame.java
/**
 * 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;
}
 
源代码4 项目: openAGV   文件: ViewPluginPanelsMenu.java
/**
 * 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);
  }
}
 
源代码5 项目: scelight   文件: BoolSettingAction.java
/**
 * 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;
}
 
源代码6 项目: scelight   文件: BoolSettingAction.java
/**
 * 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;
}
 
源代码7 项目: DiskBrowser   文件: DataPanel.java
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));
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。