mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-4574 - Minor refactor of drag and drop interfaces
This commit is contained in:
@@ -15,6 +15,13 @@
|
||||
*/
|
||||
package ghidra.feature.vt.gui.duallisting;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.dnd.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import docking.dnd.*;
|
||||
import ghidra.app.util.viewer.listingpanel.ListingCodeComparisonPanel;
|
||||
import ghidra.app.util.viewer.listingpanel.ListingPanel;
|
||||
import ghidra.feature.vt.api.main.*;
|
||||
@@ -26,14 +33,6 @@ import ghidra.program.util.ProgramLocation;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.SystemUtilities;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.dnd.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import docking.dnd.*;
|
||||
|
||||
public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
|
||||
private final int SOURCE = 0; // left side
|
||||
@@ -52,7 +51,8 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
private DropTgtAdapter dropTargetAdapter;
|
||||
private DataFlavor[] acceptableFlavors; // data flavors that are valid.
|
||||
|
||||
public VTDualListingDragNDropHandler(VTController controller, ListingCodeComparisonPanel dualListingPanel) {
|
||||
public VTDualListingDragNDropHandler(VTController controller,
|
||||
ListingCodeComparisonPanel dualListingPanel) {
|
||||
this.controller = controller;
|
||||
this.dualListingPanel = dualListingPanel;
|
||||
listingPanels[SOURCE] = dualListingPanel.getLeftPanel();
|
||||
@@ -79,9 +79,8 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
// set up the destination fieldPanel as a drop target that accepts mark-up items.
|
||||
dropTargetAdapter =
|
||||
new DropTgtAdapter(this, DnDConstants.ACTION_COPY_OR_MOVE, acceptableFlavors);
|
||||
dropTarget =
|
||||
new DropTarget(listingPanels[DESTINATION].getFieldPanel(),
|
||||
DnDConstants.ACTION_COPY_OR_MOVE, dropTargetAdapter, true);
|
||||
dropTarget = new DropTarget(listingPanels[DESTINATION].getFieldPanel(),
|
||||
DnDConstants.ACTION_COPY_OR_MOVE, dropTargetAdapter, true);
|
||||
dropTarget.setActive(true);
|
||||
}
|
||||
|
||||
@@ -106,9 +105,8 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
}
|
||||
Point p = e.getDragOrigin();
|
||||
ProgramLocation programLocation = listingPanels[SOURCE].getProgramLocation(p);
|
||||
VTMarkupItem markupItem =
|
||||
controller.getCurrentMarkupForLocation(programLocation,
|
||||
dualListingPanel.getLeftProgram());
|
||||
VTMarkupItem markupItem = controller.getCurrentMarkupForLocation(programLocation,
|
||||
dualListingPanel.getLeftProgram());
|
||||
if (markupItem == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -122,11 +120,6 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
return status == VTMarkupItemDestinationAddressEditStatus.EDITABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragCanceled(DragSourceDropEvent event) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transferable getTransferable(Point p) {
|
||||
if (!listingPanels[SOURCE].contains(p)) {
|
||||
@@ -134,25 +127,14 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
}
|
||||
|
||||
ProgramLocation programLocation = listingPanels[SOURCE].getProgramLocation(p);
|
||||
VTMarkupItem markupItem =
|
||||
controller.getCurrentMarkupForLocation(programLocation,
|
||||
dualListingPanel.getLeftProgram());
|
||||
VTMarkupItem markupItem = controller.getCurrentMarkupForLocation(programLocation,
|
||||
dualListingPanel.getLeftProgram());
|
||||
if (markupItem == null) {
|
||||
return null;
|
||||
}
|
||||
return new VTMarkupItemTransferable(markupItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragUnderFeedback(boolean ok, DropTargetDragEvent e) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoDragUnderFeedback() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDropOk(DropTargetDragEvent e) {
|
||||
return true;
|
||||
@@ -175,9 +157,9 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
if ((markupItem.getStatus() == VTMarkupItemStatus.SAME) &&
|
||||
(SystemUtilities.isEqual(markupItem.getDestinationAddress(), newDestinationAddress))) {
|
||||
// Dropped at expected address and already the same there.
|
||||
Msg.showInfo(getClass(), dualListingPanel, "Already The Same",
|
||||
markupType.getDisplayName() +
|
||||
" was dropped at its expected\ndestination where the value is already the same.");
|
||||
Msg.showInfo(getClass(), dualListingPanel, "Already The Same", markupType
|
||||
.getDisplayName() +
|
||||
" was dropped at its expected\ndestination where the value is already the same.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,15 +172,9 @@ public class VTDualListingDragNDropHandler implements Draggable, Droppable {
|
||||
// newDestinationAddress);
|
||||
|
||||
// Use the following if you want to set the address and apply the markup item using the default action.
|
||||
ApplyMarkupAtDestinationAddressTask task =
|
||||
new ApplyMarkupAtDestinationAddressTask(controller.getSession(), arrayList,
|
||||
newDestinationAddress, controller.getOptions());
|
||||
ApplyMarkupAtDestinationAddressTask task = new ApplyMarkupAtDestinationAddressTask(
|
||||
controller.getSession(), arrayList, newDestinationAddress, controller.getOptions());
|
||||
|
||||
controller.runVTTask(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move() {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user