Merge remote-tracking branch 'origin/GP-4108-dragonmacher-menu-icons-when-disabled'

This commit is contained in:
Ryan Kurtz 2023-12-15 17:01:30 -05:00
commit e99731c67d
7 changed files with 30 additions and 24 deletions

View file

@ -303,7 +303,11 @@ public abstract class DockingAction implements DockingActionIf {
String text = menuData.getMenuItemName(); String text = menuData.getMenuItemName();
String trimmed = StringUtilities.trimMiddle(text, 50); String trimmed = StringUtilities.trimMiddle(text, 50);
menuItem.setText(trimmed); menuItem.setText(trimmed);
menuItem.setIcon(menuData.getMenuIcon()); Icon icon = menuData.getMenuIcon();
menuItem.setIcon(icon);
if (icon != null) {
menuItem.setDisabledIcon(ResourceManager.getDisabledIcon(icon));
}
menuItem.setMnemonic(menuData.getMnemonic()); menuItem.setMnemonic(menuData.getMnemonic());
} }
else { else {

View file

@ -15,16 +15,15 @@
*/ */
package docking.menu; package docking.menu;
import javax.swing.*; import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.UIManager;
import javax.swing.plaf.MenuItemUI; import javax.swing.plaf.MenuItemUI;
/** /**
* Overrides the painting behavior of the BasicCheckBoxMenuItemUI * Overrides the painting behavior of the BasicCheckBoxMenuItemUI
*/ */
public class DockingCheckboxMenuItemUI extends DockingMenuItemUI { public class DockingCheckboxMenuItemUI extends DockingMenuItemUI {
public static ComponentUI createUI(JComponent c) { public static DockingCheckboxMenuItemUI createUI(JComponent c) {
DockingCheckboxMenuItemUI result = new DockingCheckboxMenuItemUI(); DockingCheckboxMenuItemUI result = new DockingCheckboxMenuItemUI();
result.ui = (MenuItemUI) UIManager.getDefaults().getUI(c); result.ui = (MenuItemUI) UIManager.getDefaults().getUI(c);
return result; return result;

View file

@ -28,24 +28,23 @@ import java.util.Map;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.MenuItemUI; import javax.swing.plaf.MenuItemUI;
import docking.util.GraphicsUtils; import docking.util.GraphicsUtils;
/** /**
* This class exists to make menu items display content with proper alignment whether or not * This class exists to make menu items display content with proper alignment whether or not
* they are displaying an icon. That is, this class will introduce padding for absent icons * they are displaying an icon. That is, this class will introduce padding for absent icons
* within menu items so that the item lines up with those items that do contain icons. * within menu items so that the item lines up with those items that do contain icons.
* <p> * <p>
* This class has an additional feature that allows clients to display menu item content in a * This class has an additional feature that allows clients to display menu item content in a
* tabular fashion. A menu item using this UI can contain some combination of the of the following * tabular fashion. A menu item using this UI can contain some combination of the of the following
* items, in the given order: * items, in the given order:
* <pre> * <pre>
* [Checkbox][Icon][Menu Item Content][Menu Pull-right/Accelerator Text] * [Checkbox][Icon][Menu Item Content][Menu Pull-right/Accelerator Text]
* </pre> * </pre>
* To display the <b>Menu Item Content</b> in a tabular fashion, use the <code>'\t'</code> character * To display the <b>Menu Item Content</b> in a tabular fashion, use the <code>'\t'</code> character
* to delimit the data into columns. This class will align all menu items in the given menu * to delimit the data into columns. This class will align all menu items in the given menu
* based upon the largest number of columns in the group and the largest width for each column. * based upon the largest number of columns in the group and the largest width for each column.
*/ */
public class DockingMenuItemUI extends MenuItemUI { public class DockingMenuItemUI extends MenuItemUI {
@ -57,7 +56,7 @@ public class DockingMenuItemUI extends MenuItemUI {
protected MenuItemUI ui; protected MenuItemUI ui;
public static ComponentUI createUI(JComponent c) { public static DockingMenuItemUI createUI(JComponent c) {
DockingMenuItemUI result = new DockingMenuItemUI(); DockingMenuItemUI result = new DockingMenuItemUI();
result.ui = (MenuItemUI) UIManager.getDefaults().getUI(c); result.ui = (MenuItemUI) UIManager.getDefaults().getUI(c);
return result; return result;
@ -170,7 +169,7 @@ public class DockingMenuItemUI extends MenuItemUI {
} }
public static class MenuTabulator { public static class MenuTabulator {
private ArrayList<Integer> columns = new ArrayList<Integer>(); private ArrayList<Integer> columns = new ArrayList<>();
public static MenuTabulator tabulate(JMenuItem c) { public static MenuTabulator tabulate(JMenuItem c) {
MenuTabulator tabulator = get(c); MenuTabulator tabulator = get(c);

View file

@ -15,12 +15,12 @@
*/ */
package docking.menu; package docking.menu;
import javax.swing.*; import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.UIManager;
import javax.swing.plaf.MenuItemUI; import javax.swing.plaf.MenuItemUI;
public class DockingMenuUI extends DockingMenuItemUI { public class DockingMenuUI extends DockingMenuItemUI {
public static ComponentUI createUI(JComponent c) { public static DockingMenuUI createUI(JComponent c) {
DockingMenuUI result = new DockingMenuUI(); DockingMenuUI result = new DockingMenuUI();
result.ui = (MenuItemUI) UIManager.getDefaults().getUI(c); result.ui = (MenuItemUI) UIManager.getDefaults().getUI(c);
return result; return result;

View file

@ -20,8 +20,7 @@ import java.awt.event.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import javax.swing.ButtonModel; import javax.swing.*;
import javax.swing.JMenuItem;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import docking.ActionContext; import docking.ActionContext;
@ -29,6 +28,7 @@ import docking.DefaultActionContext;
import docking.action.*; import docking.action.*;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.StringUtilities; import ghidra.util.StringUtilities;
import resources.ResourceManager;
/** /**
* Class to manage a JMenuItem for an action. Handles property changes in the action * Class to manage a JMenuItem for an action. Handles property changes in the action
@ -184,7 +184,11 @@ class MenuItemManager implements ManagedMenuItem, PropertyChangeListener, Action
String text = menuData.getMenuItemName(); String text = menuData.getMenuItemName();
String trimmed = StringUtilities.trimMiddle(text, 50); String trimmed = StringUtilities.trimMiddle(text, 50);
menuItem.setText(trimmed); menuItem.setText(trimmed);
menuItem.setIcon(menuData.getMenuIcon()); Icon menuIcon = menuData.getMenuIcon();
menuItem.setIcon(menuIcon);
if (menuIcon != null) {
menuItem.setDisabledIcon(ResourceManager.getDisabledIcon(menuIcon));
}
menuItem.setMnemonic(menuData.getMnemonic()); menuItem.setMnemonic(menuData.getMnemonic());
menuItem.revalidate(); menuItem.revalidate();
} }

View file

@ -164,10 +164,10 @@ public class MultipleActionDockingToolbarButton extends EmptyBorderButton {
// 1) show a popup if it was not showing // 1) show a popup if it was not showing
// 2) hide the popup if it was showing // 2) hide the popup if it was showing
// //
// Case 2 requires timestamps. Java will close the popup as the button is clicked. This // Case 2 requires timestamps. Java will close the popup as the button is clicked. This
// means that when we are told to show the popup as the result of a click, the popup will // means that when we are told to show the popup as the result of a click, the popup will
// never be showing. To work around this, we track the elapsed time since last click. If // never be showing. To work around this, we track the elapsed time since last click. If
// the period is too short, then we assume Java closed the popup when the click happened // the period is too short, then we assume Java closed the popup when the click happened
//and thus we should ignore it. //and thus we should ignore it.
// //
long elapsedTime = System.currentTimeMillis() - popupLastClosedTime; long elapsedTime = System.currentTimeMillis() - popupLastClosedTime;
@ -197,7 +197,7 @@ public class MultipleActionDockingToolbarButton extends EmptyBorderButton {
} }
// a custom Ghidra UI that handles alignment issues and allows for tabulating presentation // a custom Ghidra UI that handles alignment issues and allows for tabulating presentation
item.setUI((DockingMenuItemUI) DockingMenuItemUI.createUI(item)); item.setUI(DockingMenuItemUI.createUI(item));
final DockingActionIf delegateAction = dockingAction; final DockingActionIf delegateAction = dockingAction;
item.addActionListener(e -> { item.addActionListener(e -> {
ActionContext context = getActionContext(); ActionContext context = getActionContext();

View file

@ -1401,8 +1401,8 @@ public class ClipboardPluginTest extends AbstractGhidraHeadedIntegrationTest {
Point point = wrapper.getStartMouseDragLocation(); Point point = wrapper.getStartMouseDragLocation();
int startX = point.x; int startX = point.x;
int startY = point.y; int startY = point.y;
Point endPoint = wrapper.getEndMouseDragLocation(); Point endPoint = wrapper.getEndMouseDragLocation();
int endX = endPoint.x; int endX = endPoint.x;
int endY = endPoint.y; int endY = endPoint.y;