Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-377 - Graphing - temporary fixes to mouse handling code until they are fixed in jungrapht

dragonmacher37ab855e1d84
diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtGraphMouse.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtGraphMouse.java
index 82bb0c8f53..b198d513b1 100644
--- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtGraphMouse.java
+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtGraphMouse.java
@@ -15,24 +15,24 @@
*/
package ghidra.graph.visualization.mouse;
+import java.awt.event.InputEvent;
+
import org.jungrapht.visualization.control.*;
import ghidra.graph.visualization.DefaultGraphDisplay;
import ghidra.service.graph.AttributedEdge;
import ghidra.service.graph.AttributedVertex;
-import java.awt.event.InputEvent;
-
/**
* Pluggable graph mouse for jungrapht
*/
-public class JgtPluggableGraphMouse extends DefaultGraphMouse<AttributedVertex, AttributedEdge> {
+public class JgtGraphMouse extends DefaultGraphMouse<AttributedVertex, AttributedEdge> {
private DefaultGraphDisplay graphDisplay;
// TODO we should not need the graph display for any mouse plugins, but the API is net yet
// robust enough to communicate fully without it
- public JgtPluggableGraphMouse(DefaultGraphDisplay graphDisplay) {
+ public JgtGraphMouse(DefaultGraphDisplay graphDisplay) {
super(DefaultGraphMouse.builder());
this.graphDisplay = graphDisplay;
}
@@ -50,7 +50,12 @@ public class JgtPluggableGraphMouse extends DefaultGraphMouse<AttributedVertex,
add(new JgtVertexFocusingPlugin<>(InputEvent.BUTTON1_DOWN_MASK, graphDisplay));
- add(new SelectingGraphMousePlugin<>());
+ //
+ // JUNGRAPHT CHANGE 1,2
+ //
+ // Note: this code can go away when we can turn off the picking square
+ add(new JgtSelectingGraphMousePlugin());
+ // add(new SelectingGraphMousePlugin<>());
add(new RegionSelectingGraphMousePlugin<>());
@@ -65,4 +70,5 @@ public class JgtPluggableGraphMouse extends DefaultGraphMouse<AttributedVertex,
setPluginsLoaded();
}
+
}
diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtSatelliteGraphMouse.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtSatelliteGraphMouse.java
new file mode 100644
index 0000000000..da8f9dab09
--- /dev/null
+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtSatelliteGraphMouse.java
@@ -0,0 +1,60 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.graph.visualization.mouse;
+
+import org.jungrapht.visualization.control.*;
+
+import ghidra.service.graph.AttributedEdge;
+import ghidra.service.graph.AttributedVertex;
+
+// Note: if the jungrapht API changes to fix '// JUNGRAPHT CHANGE 1' and '2', then this class
+// can be removed
+public class JgtSatelliteGraphMouse
+ extends DefaultSatelliteGraphMouse<AttributedVertex, AttributedEdge> {
+
+ @Override
+ public void loadPlugins() {
+ scalingPlugin =
+ new SatelliteScalingGraphMousePlugin(
+ new CrossoverScalingControl(),
+ scalingMask,
+ xAxisScalingMask,
+ yAxisScalingMask,
+ in,
+ out);
+
+ //
+ // JUNGRAPHT CHANGE 3
+ //
+ SelectingGraphMousePlugin<AttributedVertex, AttributedEdge> mySelectingPlugin =
+ new JgtSelectingGraphMousePlugin(singleSelectionMask, addSingleSelectionMask);
+ mySelectingPlugin.setLocked(true);
+ selectingPlugin = mySelectingPlugin;
+
+ regionSelectingPlugin =
+ RegionSelectingGraphMousePlugin.builder()
+ .regionSelectionMask(regionSelectionMask)
+ .addRegionSelectionMask(addRegionSelectionMask)
+ .regionSelectionCompleteMask(regionSelectionCompleteMask)
+ .addRegionSelectionCompleteMask(addRegionSelectionCompleteMask)
+ .build();
+ translatingPlugin = new SatelliteTranslatingGraphMousePlugin(translatingMask);
+ add(selectingPlugin);
+ add(regionSelectingPlugin);
+ add(translatingPlugin);
+ add(scalingPlugin);
+ }
+}
diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtSelectingGraphMousePlugin.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtSelectingGraphMousePlugin.java
new file mode 100644
index 0000000000..e2f15d4917
--- /dev/null
+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/mouse/JgtSelectingGraphMousePlugin.java
@@ -0,0 +1,111 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.graph.visualization.mouse;
+
+import java.awt.Graphics;
+import java.awt.event.MouseEvent;
+import java.awt.geom.Point2D;
+
+import org.jungrapht.visualization.VisualizationServer;
+import org.jungrapht.visualization.VisualizationServer.Paintable;
+import org.jungrapht.visualization.control.GraphElementAccessor;
+import org.jungrapht.visualization.control.SelectingGraphMousePlugin;
+import org.jungrapht.visualization.layout.model.LayoutModel;
+import org.jungrapht.visualization.selection.MutableSelectedState;
+import org.jungrapht.visualization.selection.ShapePickSupport;
+
+import ghidra.service.graph.AttributedEdge;
+import ghidra.service.graph.AttributedVertex;
+
+public class JgtSelectingGraphMousePlugin
+ extends SelectingGraphMousePlugin<AttributedVertex, AttributedEdge> {
+
+ private Paintable dummyPickFootprintPaintable = new Paintable() {
+ @Override
+ public void paint(Graphics g) {
+ // stub
+ }
+
+ @Override
+ public boolean useTransform() {
+ return false;
+ }
+ };
+
+ JgtSelectingGraphMousePlugin() {
+ super();
+
+ //
+ // JUNGRAPHT CHANGE 1
+ // turn off painting of the picking square
+ this.pickFootprintPaintable = dummyPickFootprintPaintable;
+ }
+
+ public JgtSelectingGraphMousePlugin(int singleSelectionMask, int addSingleSelectionMask) {
+ super(singleSelectionMask, addSingleSelectionMask);
+
+ //
+ // JUNGRAPHT CHANGE 1
+ // turn off painting of the picking square
+ this.pickFootprintPaintable = dummyPickFootprintPaintable;
+ }
+
+ // JUNGRAPHT CHANGE 2
+ @Override
+ protected boolean singleVertexSelection(
+ MouseEvent e, Point2D layoutPoint, boolean addToSelection) {
+ VisualizationServer<AttributedVertex, AttributedEdge> vv =
+ (VisualizationServer<AttributedVertex, AttributedEdge>) e.getSource();
+ GraphElementAccessor<AttributedVertex, AttributedEdge> pickSupport =
+ vv.getPickSupport();
+ MutableSelectedState<AttributedVertex> selectedVertexState =
+ vv.getSelectedVertexState();
+ LayoutModel<AttributedVertex> layoutModel = vv.getVisualizationModel().getLayoutModel();
+ if (pickSupport instanceof ShapePickSupport) {
+ ShapePickSupport<AttributedVertex, AttributedEdge> shapePickSupport =
+ (ShapePickSupport<AttributedVertex, AttributedEdge>) pickSupport;
+ vertex = shapePickSupport.getVertex(layoutModel, footprintRectangle);
+ }
+ else {
+ vertex = pickSupport.getVertex(layoutModel, layoutPoint.getX(), layoutPoint.getY());
+ }
+
+ if (vertex != null) {
+ if (!selectedVertexState.isSelected(vertex)) {
+ if (!addToSelection) {
+ selectedVertexState.clear();
+ }
+ selectedVertexState.select(vertex);
+ deselectedVertex = null;
+ }
+ else {
+ // If this vertex is still around in mouseReleased, it will be deselected
+ // If this vertex was pressed again in order to drag it, it will be set
+ // to null in the mouseDragged method
+
+ //
+ // JUNGRAPHT CHANGE 2 HERE
+ //
+ if (addToSelection) {
+ deselectedVertex = vertex;
+ }
+ }
+ e.consume();
+ return true;
+ }
+ return false;
+ }
+}