Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8237505: RadioMenuItem in ToggleGroup: deselected on accelerator #1002

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -175,7 +175,12 @@ private static void doAcceleratorInstall(final List<? extends MenuItem> items, f
}
if (!menuitem.isDisable()) {
if (menuitem instanceof RadioMenuItem) {
((RadioMenuItem)menuitem).setSelected(!((RadioMenuItem)menuitem).isSelected());
if(((RadioMenuItem)menuitem).getToggleGroup() == null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: this group insists on adding spaces after "if" and before "{"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a pattern variable here to get rid of all the casts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code to address above comments

((RadioMenuItem)menuitem).setSelected(!((RadioMenuItem)menuitem).isSelected());
}
else {
((RadioMenuItem)menuitem).setSelected(true);
}
}
else if (menuitem instanceof CheckMenuItem) {
((CheckMenuItem)menuitem).setSelected(!((CheckMenuItem)menuitem).isSelected());
Expand Down
Expand Up @@ -28,6 +28,9 @@
import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.*;

import test.com.sun.javafx.pgstub.StubToolkit;
import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
import test.com.sun.javafx.scene.control.infrastructure.KeyModifier;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;
import com.sun.javafx.tk.Toolkit;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
Expand All @@ -36,8 +39,13 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyCode;
import javafx.scene.shape.Rectangle;
import static org.junit.Assert.*;

Expand Down Expand Up @@ -296,4 +304,26 @@ public class RadioMenuItemTest {
assertTrue(b1.isSelected());
assertFalse(result8189677);
}

@Test public void testRadioMenuItemSelectionOnAccelerator() {
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Submenu");
menuBar.getMenus().add(menu);

ToggleGroup group = new ToggleGroup();
RadioMenuItem radioMenuItem = new RadioMenuItem("ONE");
radioMenuItem.setToggleGroup(group);
radioMenuItem.setAccelerator(KeyCombination.valueOf("alt+1"));
menu.getItems().add(radioMenuItem);

StageLoader s = new StageLoader(menuBar);
Scene scene = s.getStage().getScene();
KeyEventFirer keyboard = new KeyEventFirer(radioMenuItem, scene);

keyboard.doKeyPress(KeyCode.DIGIT1, KeyModifier.ALT);
assertTrue(radioMenuItem.isSelected());

keyboard.doKeyPress(KeyCode.DIGIT1, KeyModifier.ALT);
assertTrue(radioMenuItem.isSelected());
}
}