mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-30 07:39:19 +08:00
Merge remote-tracking branch
'origin/GP-3779_fixing_DOT_graph_export--SQUASHED' (Closes #5678)
This commit is contained in:
+16
-1
@@ -17,7 +17,9 @@ package ghidra.graph.exporter;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jgrapht.nio.Attribute;
|
||||||
import org.jgrapht.nio.dimacs.DIMACSExporter;
|
import org.jgrapht.nio.dimacs.DIMACSExporter;
|
||||||
import org.jgrapht.nio.dimacs.DIMACSFormat;
|
import org.jgrapht.nio.dimacs.DIMACSFormat;
|
||||||
import org.jgrapht.nio.dot.DOTExporter;
|
import org.jgrapht.nio.dot.DOTExporter;
|
||||||
@@ -28,7 +30,6 @@ public class DotGraphExporter extends AbstractAttributedGraphExporter {
|
|||||||
|
|
||||||
protected DIMACSFormat dimacsFormat = DIMACSExporter.DEFAULT_DIMACS_FORMAT;
|
protected DIMACSFormat dimacsFormat = DIMACSExporter.DEFAULT_DIMACS_FORMAT;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportGraph(AttributedGraph graph, File file) throws IOException {
|
public void exportGraph(AttributedGraph graph, File file) throws IOException {
|
||||||
DOTExporter<AttributedVertex, AttributedEdge> exporter =
|
DOTExporter<AttributedVertex, AttributedEdge> exporter =
|
||||||
@@ -46,6 +47,20 @@ public class DotGraphExporter extends AbstractAttributedGraphExporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DOT graphs use a special attribute call "label" which we call "Name", so when
|
||||||
|
* exporting to DOT format, change the "Name" attribute to "label".
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, Attribute> getAttributes(Attributed attributed) {
|
||||||
|
Map<String, Attribute> attributes = super.getAttributes(attributed);
|
||||||
|
Attribute attribute = attributes.remove("Name");
|
||||||
|
if (attribute != null) {
|
||||||
|
attributes.put("label", attribute);
|
||||||
|
}
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFileExtension() {
|
public String getFileExtension() {
|
||||||
return "gf";
|
return "gf";
|
||||||
|
|||||||
+22
-17
@@ -93,30 +93,31 @@ public class AttributedToolTipInfo extends ToolTipInfo<Attributed> {
|
|||||||
private void addToolTipTextForVertex(StringBuilder buf, AttributedVertex vertex) {
|
private void addToolTipTextForVertex(StringBuilder buf, AttributedVertex vertex) {
|
||||||
String vertexType = vertex.getVertexType();
|
String vertexType = vertex.getVertexType();
|
||||||
|
|
||||||
buf.append("<H4>");
|
buf.append("<H3>");
|
||||||
String escapedText = HTMLUtilities.toLiteralHTML(vertex.getName(), 80);
|
String escapedText = HTMLUtilities.toLiteralHTML(vertex.getName(), 80);
|
||||||
buf.append(escapedText);
|
buf.append(escapedText);
|
||||||
|
buf.append("</H3><TABLE>");
|
||||||
if (vertexType != null) {
|
if (vertexType != null) {
|
||||||
buf.append("<br>");
|
appendAttribute(buf, "Type", vertexType);
|
||||||
buf.append("Type: " + vertexType);
|
|
||||||
}
|
}
|
||||||
buf.append("</H4>");
|
|
||||||
|
|
||||||
addAttributes(buf, AttributedVertex.NAME_KEY, AttributedVertex.VERTEX_TYPE_KEY);
|
addAttributes(buf, AttributedVertex.NAME_KEY, AttributedVertex.VERTEX_TYPE_KEY);
|
||||||
|
appendAttribute(buf, "Id", vertex.getId());
|
||||||
|
buf.append("</TABLE>");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToolTipTextForEdge(StringBuilder buf, AttributedEdge edge) {
|
private void addToolTipTextForEdge(StringBuilder buf, AttributedEdge edge) {
|
||||||
String edgeType = edge.getEdgeType();
|
String edgeType = edge.getEdgeType();
|
||||||
|
buf.append("<TABLE>");
|
||||||
if (edgeType != null) {
|
if (edgeType != null) {
|
||||||
buf.append("<H4>");
|
appendAttribute(buf, "Type", edgeType);
|
||||||
buf.append("Type: " + edgeType);
|
|
||||||
buf.append("</H4>");
|
|
||||||
}
|
}
|
||||||
addAttributes(buf, AttributedEdge.EDGE_TYPE_KEY);
|
addAttributes(buf, AttributedEdge.EDGE_TYPE_KEY);
|
||||||
|
appendAttribute(buf, "Id", edge.getId());
|
||||||
|
buf.append("</TABLE>");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAttributes(StringBuilder buf, String...excludedKeys) {
|
private void addAttributes(StringBuilder buf, String... excludedKeys) {
|
||||||
|
|
||||||
Set<Entry<String, String>> entries = graphObject.entrySet();
|
Set<Entry<String, String>> entries = graphObject.entrySet();
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : entries) {
|
for (Map.Entry<String, String> entry : entries) {
|
||||||
@@ -124,14 +125,18 @@ public class AttributedToolTipInfo extends ToolTipInfo<Attributed> {
|
|||||||
if (ArrayUtils.contains(excludedKeys, key)) {
|
if (ArrayUtils.contains(excludedKeys, key)) {
|
||||||
continue; // skip keys handled in header
|
continue; // skip keys handled in header
|
||||||
}
|
}
|
||||||
buf.append(key);
|
appendAttribute(buf, key, entry.getValue());
|
||||||
buf.append(": ");
|
|
||||||
String escapedText = HTMLUtilities.toLiteralHTML(entry.getValue(), 80);
|
|
||||||
String split = String.join("<br>", Splitter.on('\n').split(escapedText));
|
|
||||||
split = split.replaceAll("\\s", " ");
|
|
||||||
buf.append(split);
|
|
||||||
buf.append("<br>");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void appendAttribute(StringBuilder buf, String key, String value) {
|
||||||
|
buf.append("<TR><TD>");
|
||||||
|
buf.append(key);
|
||||||
|
buf.append(":</TD><TD>");
|
||||||
|
String escapedText = HTMLUtilities.toLiteralHTML(value, 80);
|
||||||
|
String split = String.join("<BR>", Splitter.on('\n').split(escapedText));
|
||||||
|
split = split.replaceAll("\\s", " ");
|
||||||
|
buf.append(split);
|
||||||
|
buf.append("</TD></TR>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -28,6 +28,7 @@ import java.util.function.Function;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jungrapht.visualization.RenderContext;
|
import org.jungrapht.visualization.RenderContext;
|
||||||
import org.jungrapht.visualization.VisualizationViewer;
|
import org.jungrapht.visualization.VisualizationViewer;
|
||||||
import org.jungrapht.visualization.decorators.*;
|
import org.jungrapht.visualization.decorators.*;
|
||||||
@@ -104,7 +105,11 @@ public class DefaultGraphRenderer implements GraphRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getVertexRenderedLabel(AttributedVertex v) {
|
private String getVertexRenderedLabel(AttributedVertex v) {
|
||||||
return HTMLUtilities.toLiteralHTML(v.toString(), 80);
|
String displayName = v.getName();
|
||||||
|
if (StringUtils.isBlank(displayName)) {
|
||||||
|
displayName = v.getId();
|
||||||
|
}
|
||||||
|
return HTMLUtilities.toLiteralHTML(displayName, 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -310,10 +315,8 @@ public class DefaultGraphRenderer implements GraphRenderer {
|
|||||||
|
|
||||||
graphics.setTransform(graphicsTransform); // restore the original transform
|
graphics.setTransform(graphicsTransform); // restore the original transform
|
||||||
graphics.dispose();
|
graphics.dispose();
|
||||||
Image scaledImage =
|
Image scaledImage = ImageUtils.createScaledImage(bufferedImage, iconWidth * ICON_ZOOM,
|
||||||
ImageUtils.createScaledImage(bufferedImage, iconWidth * ICON_ZOOM,
|
iconHeight * ICON_ZOOM, Image.SCALE_FAST);
|
||||||
iconHeight * ICON_ZOOM,
|
|
||||||
Image.SCALE_FAST);
|
|
||||||
ImageIcon imageIcon = new ImageIcon(scaledImage);
|
ImageIcon imageIcon = new ImageIcon(scaledImage);
|
||||||
return imageIcon;
|
return imageIcon;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user