Merge remote-tracking branch 'origin/GT-3019-dragonmacher-function-graph-edge-routing'

This commit is contained in:
Ryan Kurtz 2019-08-02 10:00:05 -04:00
commit 291abeb789
36 changed files with 1431 additions and 412 deletions

View file

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,15 +15,17 @@
*/
package docking.menu;
import javax.swing.Icon;
import ghidra.util.HelpLocation;
import ghidra.util.SystemUtilities;
import javax.swing.Icon;
/**
* Note: this class overrides the {@ #equals(Object)} method} and relies upon the <tt>equals</tt>
* Note: this class overrides the <tt>equals(Object)</tt> and relies upon the <tt>equals</tt>
* method of the <tt>userData</tt> object. Thus, if it is important that equals work for you in
* the non-standard identity way, then you must override <tt>equals</tt> in your user data obejcts.
* the non-standard identity way, then you must override <tt>equals</tt> in your user data objects.
*
* @param <T> the type of the action state
*/
public class ActionState<T> {
@ -32,55 +33,60 @@ public class ActionState<T> {
private final Icon icon;
private T userData;
private HelpLocation helpLocation;
public ActionState(String name, Icon icon, T userData) {
this.name = name;
this.icon = icon;
this.userData = userData;
this.userData = userData;
}
public String getName() {
return name;
}
public Icon getIcon() {
return icon;
}
public T getUserData() {
return userData;
}
public void setHelpLocation( HelpLocation helpLocation ) {
this.helpLocation = helpLocation;
}
public HelpLocation getHelpLocation() {
return helpLocation;
}
@Override
public boolean equals( Object other ) {
if ( other == null ) {
return false;
}
Class<? extends Object> otherClass = other.getClass();
if ( !getClass().equals( otherClass ) ) {
return false;
}
ActionState<?> otherState = (ActionState<?>) other;
if ( !SystemUtilities.isEqual( userData, otherState.userData ) ) {
return false;
}
return name.equals( otherState.name );
}
@Override
public int hashCode() {
return name.hashCode() + ((userData == null) ? 0 : userData.hashCode());
}
public void setHelpLocation(HelpLocation helpLocation) {
this.helpLocation = helpLocation;
}
public HelpLocation getHelpLocation() {
return helpLocation;
}
@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}
Class<? extends Object> otherClass = other.getClass();
if (!getClass().equals(otherClass)) {
return false;
}
ActionState<?> otherState = (ActionState<?>) other;
if (!SystemUtilities.isEqual(userData, otherState.userData)) {
return false;
}
return name.equals(otherState.name);
}
@Override
public int hashCode() {
return name.hashCode() + ((userData == null) ? 0 : userData.hashCode());
}
@Override
public String toString() {
return name + ": " + userData;
}
}

View file

@ -35,6 +35,11 @@ import resources.icons.EmptyIcon;
* drop-down icon that allows users to change the state of the button. Also, by default, as
* the user presses the button, it will execute the action corresponding to the current
* state.
*
* <p>Warning: if you use this action in a toolbar, then be sure to call the
* {@link #MultiStateDockingAction(String, String, boolean) correct constructor}. If you call
* another constructor, or pass false for this boolean above, your
* {@link #doActionPerformed(ActionContext)} method will get called twice.
*
* @param <T> the type of the user data
* @see MultiActionDockingAction
@ -56,10 +61,25 @@ public abstract class MultiStateDockingAction<T> extends DockingAction {
// stub for toolbar actions
};
/**
* Call this constructor with this action will not be added to a toolbar
*
* @param name the action name
* @param owner the owner
* @see #MultiStateDockingAction(String, String, boolean)
*/
public MultiStateDockingAction(String name, String owner) {
this(name, owner, false);
}
/**
* Use this constructor explicitly when this action is used in a toolbar, passing true
* for <code>isToolbarAction</code> (see the javadoc header note).
*
* @param name the action name
* @param owner the owner
* @param isToolbarAction true if this action is a toolbar action
*/
protected MultiStateDockingAction(String name, String owner, boolean isToolbarAction) {
super(name, owner);
multiActionGenerator = context -> getStateActions();
@ -87,6 +107,9 @@ public abstract class MultiStateDockingAction<T> extends DockingAction {
* <p>
* Also, if the parameter is true, then the button will behave like a button in terms of
* mouse feedback. If false, then the button will behave more like a label.
*
* @param doPerformAction true to call {@link #doActionPerformed(ActionContext)} when the
* user presses the button for this action (not the drop-down menu; see above)
*/
public void setPerformActionOnPrimaryButtonClick(boolean doPerformAction) {
performActionOnPrimaryButtonClick = doPerformAction;
@ -116,6 +139,8 @@ public abstract class MultiStateDockingAction<T> extends DockingAction {
* This is the callback to be overridden when the child wishes to respond to user button
* presses that are on the button and not the drop-down. This will only be called if
* {@link #performActionOnPrimaryButtonClick} is true.
*
* @param context the action context
*/
protected void doActionPerformed(ActionContext context) {
// override me to do work