Skip to content
New issue

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

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

Already on GitHub? # to your account

Retain menus when check boxes are clicked #893

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/amidst/gui/main/menu/Menus.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ private static <T> JRadioButtonMenuItem radio(
}

public static JCheckBoxMenuItem checkbox(JMenu menu, Setting<Boolean> setting, String text) {
return checkbox(menu, setting, new JCheckBoxMenuItem(text));
return checkbox(menu, setting, new ModifiedCheckBoxItem(text));
}

public static JCheckBoxMenuItem checkbox(JMenu menu, Setting<Boolean> setting, String text, ImageIcon icon) {
return checkbox(menu, setting, new JCheckBoxMenuItem(text, icon));
return checkbox(menu, setting, new ModifiedCheckBoxItem(text, icon));
}

public static JCheckBoxMenuItem checkbox(
JMenu menu,
Setting<Boolean> setting,
String text,
MenuShortcut menuShortcut) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(text);
JCheckBoxMenuItem menuItem = new ModifiedCheckBoxItem(text);
menuItem.setAccelerator(menuShortcut.getKeyStroke());
return checkbox(menu, setting, menuItem);
}
Expand All @@ -110,7 +110,7 @@ public static JCheckBoxMenuItem checkbox(
String text,
ImageIcon icon,
MenuShortcut menuShortcut) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(text, icon);
JCheckBoxMenuItem menuItem = new ModifiedCheckBoxItem(text, icon);
menuItem.setAccelerator(menuShortcut.getKeyStroke());
return checkbox(menu, setting, menuItem);
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/amidst/gui/main/menu/ModifiedCheckBoxItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package amidst.gui.main.menu;

import java.awt.event.MouseEvent;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;

public class ModifiedCheckBoxItem extends JCheckBoxMenuItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name isn't descriptive at all, making it hard to guess what this class does when reading the code.

This should be renamed to a more descriptive name (maybe StickyCheckBoxItem?), with a small comment to explain what it does.

private static final long serialVersionUID = -3691709624298884014L;

public ModifiedCheckBoxItem() {
}

public ModifiedCheckBoxItem(Icon icon) {
super(icon);
}

public ModifiedCheckBoxItem(String text) {
super(text);
}

public ModifiedCheckBoxItem(Action a) {
super(a);
}

public ModifiedCheckBoxItem(String text, Icon icon) {
super(text, icon);
}

public ModifiedCheckBoxItem(String text, boolean b) {
super(text, b);
}

public ModifiedCheckBoxItem(String text, Icon icon, boolean b) {
super(text, icon, b);
}

@Override
protected void processMouseEvent(MouseEvent evt) {
if (evt.getID() == MouseEvent.MOUSE_RELEASED) {
if (contains(evt.getPoint())) {
doClick();
setArmed(true);
}
} else {
super.processMouseEvent(evt);
}
}
}