javafx.scene.control.RadioMenuItem Java Examples

The following examples show how to use javafx.scene.control.RadioMenuItem. 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: GraphEditorDemoController.java    From graph-editor with Eclipse Public License 1.0 7 votes vote down vote up
/**
 * Initializes the list of zoom options.
 */
private void initializeZoomOptions() {

    final ToggleGroup toggleGroup = new ToggleGroup();

    for (int i = 1; i <= 5; i++) {

        final RadioMenuItem zoomOption = new RadioMenuItem();
        final double zoomFactor = i;

        zoomOption.setText(i + "00%");
        zoomOption.setOnAction(event -> setZoomFactor(zoomFactor));

        toggleGroup.getToggles().add(zoomOption);
        zoomOptions.getItems().add(zoomOption);

        if (i == 1) {
            zoomOption.setSelected(true);
        }
    }
}
 
Example #2
Source File: CircuitSim.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int getCurrentClockSpeed() {
	for(MenuItem menuItem : frequenciesMenu.getItems()) {
		RadioMenuItem clockItem = (RadioMenuItem)menuItem;
		if(clockItem.isSelected()) {
			String text = clockItem.getText();
			int space = text.indexOf(' ');
			if(space == -1) {
				throw new IllegalStateException("What did you do...");
			}
			
			return Integer.parseInt(text.substring(0, space));
		}
	}
	
	throw new IllegalStateException("This can't happen lol");
}
 
Example #3
Source File: CheckItemBuilt.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
public static CheckItemBuilt check(String name, boolean checked) {
    RadioMenuItem item = new RadioMenuItem() {
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            MenuItem i = (MenuItem) o;

            return !(getText() != null ? !getText().equals(i.getText()) : i.getText() != null);

        }

        @Override
        public int hashCode() {
            return getText() != null ? getText().hashCode() : 0;
        }
    };
    item.setMnemonicParsing(false);
    item.setSelected(checked);
    item.setText(name);
    final CheckItemBuilt checkItemBuilt = new CheckItemBuilt(item);
    return checkItemBuilt;
}
 
Example #4
Source File: XPathRuleEditorController.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initialiseVersionSelection() {
    ToggleGroup xpathVersionToggleGroup = new ToggleGroup();

    List<String> versionItems = new ArrayList<>();
    versionItems.add(XPathRuleQuery.XPATH_1_0);
    versionItems.add(XPathRuleQuery.XPATH_1_0_COMPATIBILITY);
    versionItems.add(XPathRuleQuery.XPATH_2_0);

    versionItems.forEach(v -> {
        RadioMenuItem item = new RadioMenuItem("XPath " + v);
        item.setUserData(v);
        item.setToggleGroup(xpathVersionToggleGroup);
        xpathVersionMenuButton.getItems().add(item);
    });

    xpathVersionUIProperty = DesignerUtil.mapToggleGroupToUserData(xpathVersionToggleGroup, DesignerUtil::defaultXPathVersion);

    xpathVersionProperty().setValue(XPathRuleQuery.XPATH_2_0);
}
 
Example #5
Source File: DataPlot.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @param menu Menu to update
 *  @param devices Devices for which to create menu entries
 *  @param device Currently selected device
 *  @param action Action to perform when menu item is selected
 */
private void updateDeviceMenus(final MenuButton menu, final List<String> devices, final String device, final Consumer<String> action)
{
    final ToggleGroup group = new ToggleGroup();
    final List<MenuItem> items = new ArrayList<>(devices.size());
    for (String dev : devices)
    {
        final RadioMenuItem item = new RadioMenuItem(dev);
        item.setToggleGroup(group);
        if (dev.equals(device))
            item.setSelected(true);
        item.setOnAction(event -> action.accept(dev));
        items.add(item);
    }
    menu.getItems().setAll(items);
}
 
Example #6
Source File: DataPlot.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @param infos Info from {@link ScanInfoModel} */
private void updateScans(final List<ScanInfo> infos)
{
    final ToggleGroup group = new ToggleGroup();
    final List<MenuItem> names = new ArrayList<>(infos.size());

    final ScanDataReader safe_reader = reader;
    final long scan_id = safe_reader != null ? safe_reader.getScanId() : -1;
    for (ScanInfo info : infos)
    {
        final String label = MessageFormat.format(Messages.scan_name_id_fmt, info.getName(), info.getId());
        final RadioMenuItem item = new RadioMenuItem(label);
        item.setToggleGroup(group);
        if (scan_id == info.getId())
            item.setSelected(true);
        item.setOnAction(event -> selectScan(info.getId(), label));
        names.add(item);
    }
    Platform.runLater(() -> scan_selector.getItems().setAll(names));
}
 
Example #7
Source File: JavaFXContextMenuElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean marathon_select(String value) {
    String[] items = value.split("\\>\\>");
    ObservableList<MenuItem> children = contextMenu.getItems();
    List<MenuItem> menuItems = new ArrayList<>();
    for (String item : items) {
        getChidernMenuItem(children, item, menuItems);
    }
    menuItems.stream().forEach((menu) -> {
        if (menu instanceof CheckMenuItem) {
            CheckMenuItem checkMenuItem = (CheckMenuItem) menu;
            checkMenuItem.setSelected(!checkMenuItem.isSelected());
        } else if (menu instanceof RadioMenuItem) {
            RadioMenuItem radioMenuItem = (RadioMenuItem) menu;
            radioMenuItem.setSelected(!isSelected());
        }
        menu.fire();
    });
    contextMenu.hide();
    return true;
}
 
Example #8
Source File: JavaFXMenuBarElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean marathon_select(String value) {
    MenuBar menuBar = (MenuBar) node;
    ObservableList<Menu> menus = menuBar.getMenus();
    String[] items = value.split("\\>\\>");
    Menu parentMenu = getParentMenu(menus, items[0]);
    List<MenuItem> menuItems = new ArrayList<>();
    for (int i = 1; i < items.length; i++) {
        getChidernMenuItem(parentMenu, items[i], menuItems);
    }
    parentMenu.fire();
    menuItems.stream().forEach((menu) -> {
        if (menu instanceof CheckMenuItem) {
            CheckMenuItem checkMenuItem = (CheckMenuItem) menu;
            checkMenuItem.setSelected(!checkMenuItem.isSelected());
        } else if (menu instanceof RadioMenuItem) {
            RadioMenuItem radioMenuItem = (RadioMenuItem) menu;
            radioMenuItem.setSelected(!isSelected());
        }
        Platform.runLater(() -> menu.fire());
    });
    return true;
}
 
Example #9
Source File: DataPlot.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Update drop-downs for devices based on current 'devices', 'x_device', 'y_devices' */
private void updateToolbar()
{
    // Select the current scan in list of scan menu items
    for (MenuItem scan_sel : scan_selector.getItems())
        if (scan_sel.getText().endsWith("#" + reader.getScanId()))
                ((RadioMenuItem)scan_sel).setSelected(true);

    final List<String> devices = scan_devices.get();

    // Update devices for X Axis
    updateDeviceMenus(x_device_selector, devices, x_device, this::selectXDevice);

    int i = y_device_selectors.size();
    while (i > y_devices.size())
        y_device_selectors.remove(--i);
    while (i < y_devices.size())
    {
        final MenuButton y_device_selector = new MenuButton("Value " + (1 + i++));
        y_device_selector.setTooltip(new Tooltip("Select device for value axis"));
        y_device_selectors.add(y_device_selector);
    }

    updateDeviceMenus(add_y_device, devices, null, dev -> addYDevice(dev));

    // Update devices for Values
    for (i=0; i<y_device_selectors.size(); ++i)
    {
        final int index = i;
        updateDeviceMenus(y_device_selectors.get(i), devices, y_devices.get(i),
                          dev -> selectYDevice(index, dev));
    }

    final ObservableList<Node> items = toolbar.getItems();
    items.remove(3,  items.size());
    items.addAll(y_device_selectors);
    items.add(add_y_device);
    if (y_devices.size() > 1)
        items.add(remove_y_device);
}
 
Example #10
Source File: FontManagerType1.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
private RadioMenuItem setMenuItem (Menu menu, ToggleGroup toggleGroup, String itemName,
    String selectedItemName, boolean disable)
{
  RadioMenuItem item = new RadioMenuItem (itemName);
  item.setToggleGroup (toggleGroup);
  menu.getItems ().add (item);
  if (itemName.equals (selectedItemName))
    item.setSelected (true);
  item.setDisable (disable);
  item.setUserData (itemName);
  item.setOnAction (e -> selectFont ());
  return item;
}
 
Example #11
Source File: FxAction.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public void attach(MenuItem m)
{
	m.setOnAction(this);
	m.disableProperty().bind(disabledProperty());

	if(m instanceof CheckMenuItem)
	{
		((CheckMenuItem)m).selectedProperty().bindBidirectional(selectedProperty());
	}
	else if(m instanceof RadioMenuItem)
	{
		((RadioMenuItem)m).selectedProperty().bindBidirectional(selectedProperty());
	}
}
 
Example #12
Source File: JFXMenuRadioItem.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public JFXMenuRadioItem(JFXMenuItemContainer parent) {
	super(new RadioMenuItem(), parent);
}
 
Example #13
Source File: JFXMenuRadioItem.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean isChecked() {
	return ((RadioMenuItem) this.getControl()).isSelected();
}
 
Example #14
Source File: JFXMenuRadioItem.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setChecked(boolean checked) {
	((RadioMenuItem) this.getControl()).setSelected(checked);
}
 
Example #15
Source File: CheckItemBuilt.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
public CheckItemBuilt(RadioMenuItem menuItem) {
    this.menuItem = menuItem;
}
 
Example #16
Source File: CheckItemBuilt.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
public RadioMenuItem build() {
    return menuItem;
}
 
Example #17
Source File: MainMenuController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
protected void checkLanguage() {
    List<MenuItem> items = new ArrayList();
    items.addAll(settingsMenu.getItems());
    int pos1 = items.indexOf(englishMenuItem);
    int pos2 = items.indexOf(manageLanguagesMenuItem);
    for (int i = pos2 - 1; i > pos1; --i) {
        items.remove(i);
    }
    List<String> languages = ConfigTools.languages();
    if (languages != null && !languages.isEmpty()) {
        String lang = AppVariables.getLanguage();
        for (int i = 0; i < languages.size(); ++i) {
            final String name = languages.get(i);
            RadioMenuItem langItem = new RadioMenuItem(name);
            langItem.setToggleGroup(langGroup);
            langItem.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
                    if (isSettingValues) {
                        return;
                    }
                    AppVariables.setLanguage(name);
                    refresh();
                }
            });
            items.add(pos1 + 1 + i, langItem);
            if (name.equals(lang)) {
                isSettingValues = true;
                langItem.setSelected(true);
                isSettingValues = false;
            }
        }
    }
    settingsMenu.getItems().clear();
    settingsMenu.getItems().addAll(items);
    if (AppVariables.currentBundle == CommonValues.BundleZhCN) {
        chineseMenuItem.setSelected(true);
    } else if (AppVariables.currentBundle == CommonValues.BundleEnUS) {
        englishMenuItem.setSelected(true);
    }

}