mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-25 21:51:47 +00:00
Tests - fixed test failing due to invalid swing access
This commit is contained in:
parent
3c1e51d0c0
commit
d67659fc36
@ -26,28 +26,55 @@ import java.text.AttributedCharacterIterator;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
* Graphics used to render copied text data. This class is not a true graphics object, but is
|
||||
* instead used to grab text being painted so that clients can later use that text.
|
||||
*/
|
||||
public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
private static final Component COMPONENT = new JPanel();
|
||||
|
||||
private int transX;
|
||||
private int transY;
|
||||
private Shape clip;
|
||||
private StringBuilder buffer = new StringBuilder();
|
||||
private Font lastFont = new Font("SansSerif", Font.PLAIN, 12);
|
||||
private FontMetrics fontMetrics = getFontMetricsForFont(lastFont);
|
||||
private FontMetrics fontMetrics = createFontMetrics(lastFont);
|
||||
|
||||
private List<TextInfo> textInfos = new ArrayList<>();
|
||||
|
||||
@SuppressWarnings("deprecation") // Java still uses it, so we still use it
|
||||
private static FontMetrics getFontMetricsForFont(Font font) {
|
||||
return Toolkit.getDefaultToolkit().getFontMetrics(font);
|
||||
private Comparator<TextInfo> pointComparator = (o1, o2) -> {
|
||||
TextInfo t1 = o1;
|
||||
TextInfo t2 = o2;
|
||||
|
||||
int diff = t1.point.y - t2.point.y;
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
diff = t1.point.x - t2.point.x;
|
||||
|
||||
return diff;
|
||||
};
|
||||
|
||||
private Comparator<TextInfo> rowComparator = (o1, o2) -> {
|
||||
TextInfo t1 = o1;
|
||||
TextInfo t2 = o2;
|
||||
|
||||
int diff = t1.row - t2.row;
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
diff = t1.point.x - t2.point.x;
|
||||
|
||||
return diff;
|
||||
};
|
||||
|
||||
private static FontMetrics createFontMetrics(Font font) {
|
||||
BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
|
||||
Graphics g = image.getGraphics();
|
||||
FontMetrics fm = g.getFontMetrics(font);
|
||||
g.dispose();
|
||||
return fm;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,6 +98,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
newTextInfo.point = new Point(x + transX, y + transY);
|
||||
newTextInfo.text = str;
|
||||
newTextInfo.font = lastFont;
|
||||
newTextInfo.fontMetrics = fontMetrics;
|
||||
textInfos.add(newTextInfo);
|
||||
}
|
||||
|
||||
@ -89,34 +117,6 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
return;
|
||||
}
|
||||
|
||||
Comparator<TextInfo> pointComparator = (o1, o2) -> {
|
||||
TextInfo t1 = o1;
|
||||
TextInfo t2 = o2;
|
||||
|
||||
int diff = t1.point.y - t2.point.y;
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
diff = t1.point.x - t2.point.x;
|
||||
|
||||
return diff;
|
||||
};
|
||||
|
||||
Comparator<TextInfo> rowComparator = (o1, o2) -> {
|
||||
TextInfo t1 = o1;
|
||||
TextInfo t2 = o2;
|
||||
|
||||
int diff = t1.row - t2.row;
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
diff = t1.point.x - t2.point.x;
|
||||
|
||||
return diff;
|
||||
};
|
||||
|
||||
TextInfo[] sortedTextInfos = new TextInfo[textInfos.size()];
|
||||
textInfos.toArray(sortedTextInfos);
|
||||
|
||||
@ -156,7 +156,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
lastRow = sortedTextInfo.row;
|
||||
|
||||
//Insert spaces to account for distance past last field in row
|
||||
FontMetrics metrics = COMPONENT.getFontMetrics(sortedTextInfo.font);
|
||||
FontMetrics metrics = sortedTextInfo.fontMetrics;
|
||||
int spaceWidth = metrics.charWidth(' ');
|
||||
if (spaceWidth == 0) {
|
||||
// some environments report 0 for some fonts
|
||||
@ -231,7 +231,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
//==================================================================================================
|
||||
// Stubs
|
||||
//==================================================================================================
|
||||
//==================================================================================================
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
@ -387,7 +387,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
@Override
|
||||
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -419,7 +419,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
@Override
|
||||
public void setPaint(Paint paint) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -440,7 +440,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
@Override
|
||||
public void setRenderingHints(Map<?, ?> hints) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -456,22 +456,22 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
@Override
|
||||
public void translate(double tx, double ty) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(double theta) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(double theta, double x, double y) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scale(double sx, double sy) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -486,7 +486,7 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
|
||||
@Override
|
||||
public void setTransform(AffineTransform Tx) {
|
||||
// stub
|
||||
// stub
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -538,11 +538,11 @@ public class TextLayoutGraphics extends Graphics2D {
|
||||
}
|
||||
|
||||
class TextInfo {
|
||||
public String text;
|
||||
public Point point;
|
||||
public Font font;
|
||||
|
||||
public int row;
|
||||
String text;
|
||||
Font font;
|
||||
FontMetrics fontMetrics;
|
||||
Point point;
|
||||
int row;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
Loading…
Reference in New Issue
Block a user