From a8328a39f5d9558dabe16ac356fc4e08b790c8ec Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:23:45 -0400 Subject: [PATCH] Fixed bad palette references; set standard theme for screenshots --- .../AbstractScreenShotGenerator.java | 9 ++--- .../screenshot/GhidraScreenShotGenerator.java | 21 ++++++----- .../docking/test/AbstractDockingTest.java | 12 ++++--- .../main/java/docking/util/image/Callout.java | 20 +++++------ .../java/generic/test/AbstractGuiTest.java | 7 ++-- .../screenshot/RepositoryScreenShots.java | 36 ++++++------------- 6 files changed, 47 insertions(+), 58 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java b/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java index e53b9b562f..2d644bdfd6 100644 --- a/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java +++ b/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java @@ -15,8 +15,7 @@ */ package help.screenshot; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.awt.*; import java.awt.geom.GeneralPath; @@ -49,6 +48,8 @@ import docking.widgets.tree.GTree; import generic.test.AbstractGenericTest; import generic.theme.GThemeDefaults.Colors; import generic.theme.GThemeDefaults.Colors.Palette; +import generic.theme.ThemeManager; +import generic.theme.builtin.FlatLightTheme; import generic.util.image.ImageUtils; import ghidra.app.events.ProgramSelectionPluginEvent; import ghidra.app.plugin.core.analysis.AnalysisOptionsDialog; @@ -106,11 +107,11 @@ public abstract class AbstractScreenShotGenerator extends AbstractGhidraHeadedIn public Image image; public AbstractScreenShotGenerator() { - super(); - // this prevents test tool from appearing in the UI setInstanceField("allowTestTools", ToolUtils.class, Boolean.FALSE); setDockIcon(); + + ThemeManager.getInstance().setTheme(new FlatLightTheme()); } protected TestEnv newTestEnv() throws Exception { diff --git a/Ghidra/Features/Base/src/main/java/help/screenshot/GhidraScreenShotGenerator.java b/Ghidra/Features/Base/src/main/java/help/screenshot/GhidraScreenShotGenerator.java index fdbdfad5c0..6ccaf3d4ba 100644 --- a/Ghidra/Features/Base/src/main/java/help/screenshot/GhidraScreenShotGenerator.java +++ b/Ghidra/Features/Base/src/main/java/help/screenshot/GhidraScreenShotGenerator.java @@ -40,7 +40,7 @@ import ghidra.util.exception.AssertException; /** * Extend this class to create screen shot images for help. The name of the class determines the - * topic directory where the captured image will be stored. So if the class name is + * topic directory where the captured image will be stored. So if the class name is * XyzShreenShots, the resulting captured image will appear in help topic directly "Xyz", regardless * of which module has that topic. The test name will determine the name of the image file * that is generated. So if the test name is testHappyBirthday, the filename will be @@ -48,11 +48,10 @@ import ghidra.util.exception.AssertException; */ public abstract class GhidraScreenShotGenerator extends AbstractScreenShotGenerator { - private static final Color FG_COLOR_TEXT = Palette.getColor("color.palette.cornflowerblue"); + private static final Color FG_COLOR_TEXT = Palette.getColor("cornflowerblue"); private static final String CAPTURE = "Capture"; protected GhidraScreenShotGenerator() { - super(); } @Override @@ -73,7 +72,7 @@ public abstract class GhidraScreenShotGenerator extends AbstractScreenShotGenera } } - /** + /** * Generally, you shouldn't use this. This is only visible for those who do not directly * extend this class. */ @@ -189,10 +188,10 @@ public abstract class GhidraScreenShotGenerator extends AbstractScreenShotGenera } /** - * Call when you are finished generating a new image. This method will either show the - * newly created image or write it to disk, depending upon the value of + * Call when you are finished generating a new image. This method will either show the + * newly created image or write it to disk, depending upon the value of * {@link #SAVE_CREATED_IMAGE_FILE}, which is a system property. - * + * * @param helpTopic The help topic that contains the image * @param oldImageName The name of the image */ @@ -297,8 +296,8 @@ public abstract class GhidraScreenShotGenerator extends AbstractScreenShotGenera } /** - * @deprecated use instead {@link #finished(File, String)}. - * + * @deprecated use instead {@link #finished(File, String)}. + * * @param helpTopic The help topic that contains the image * @param oldImageName The name of the image */ @@ -308,8 +307,8 @@ public abstract class GhidraScreenShotGenerator extends AbstractScreenShotGenera } /** - * @deprecated use instead {@link #finished(File, String)}. - * + * @deprecated use instead {@link #finished(File, String)}. + * * @param helpTopic The help topic that contains the image * @param imageName The name of the image */ diff --git a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java index ee1586145f..224b43826f 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java @@ -1124,8 +1124,8 @@ public abstract class AbstractDockingTest extends AbstractGuiTest { String name) { Set ownerActions = tool.getDockingActionsByOwnerName(owner); return ownerActions.stream() - .filter(action -> action.getName().equals(name)) - .collect(Collectors.toSet()); + .filter(action -> action.getName().equals(name)) + .collect(Collectors.toSet()); } /** @@ -2217,7 +2217,9 @@ public abstract class AbstractDockingTest extends AbstractGuiTest { */ public static Image createScreenImage(Component c) throws AWTException { - yieldToSwing(); + if (!Swing.isSwingThread()) { + yieldToSwing(); + } Rectangle r = c.getBounds(); Point p = r.getLocation(); @@ -2234,7 +2236,9 @@ public abstract class AbstractDockingTest extends AbstractGuiTest { public static Image createRenderedImage(Component c) { - yieldToSwing(); + if (!Swing.isSwingThread()) { + yieldToSwing(); + } Image i = runSwing(() -> { try { diff --git a/Ghidra/Framework/Docking/src/main/java/docking/util/image/Callout.java b/Ghidra/Framework/Docking/src/main/java/docking/util/image/Callout.java index 5ee71aeda1..659ff09ea3 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/util/image/Callout.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/util/image/Callout.java @@ -26,7 +26,7 @@ import generic.util.image.ImageUtils; public class Callout { - private static final Color CALLOUT_SHAPE_COLOR = Palette.getColor("color.palette.palegreen"); + private static final Color CALLOUT_SHAPE_COLOR = Palette.getColor("palegreen"); private static final int CALLOUT_BORDER_PADDING = 20; public Image createCallout(CalloutComponentInfo calloutInfo) { @@ -128,7 +128,7 @@ public class Callout { // // This code creates a 'call out' image, which is a round, zoomed image of an area - // in the given image, as chosen by the client. Further, a cone shape will extend + // in the given image, as chosen by the client. Further, a cone shape will extend // from the client's chosen location to the callout image we create here. // @@ -141,9 +141,9 @@ public class Callout { int calloutWidth = calloutHeight; // square // - // Callout Distance (from original component). This is the location (relative to + // Callout Distance (from original component). This is the location (relative to // the original component) of the callout image (not the full shape). So, if the - // x distance was 10, then the callout image would start 10 pixels to the right of + // x distance was 10, then the callout image would start 10 pixels to the right of // the component. // double distanceX = calloutWidth * 1.5; @@ -163,7 +163,7 @@ public class Callout { // Also, since we have made the image bigger, we have to the component bounds, as // the callout image uses these bounds to know where to draw the callout. If we - // don't move them, then the padding will cause the callout to be drawn higher + // don't move them, then the padding will cause the callout to be drawn higher // by the amount of the padding. componentLocation.y += topPadding; componentBounds.setLocation(componentLocation.x, componentLocation.y); @@ -279,7 +279,7 @@ public class Callout { int cy = cLoc.y - calloutOrigin.y; Dimension cSize = calloutInfo.getSize(); -// TODO this shows how to correctly account for scaling in the Function Graph +// TODO this shows how to correctly account for scaling in the Function Graph // Dimension cSize2 = new Dimension(cSize); // double scale = .5d; // cSize2.width *= scale; @@ -297,13 +297,13 @@ public class Callout { RectangularShape shape) { // - // First draw the background circle that will sit beneath the image, to create a + // First draw the background circle that will sit beneath the image, to create a // ring around the image // g.setColor(CALLOUT_SHAPE_COLOR); g.fill(shape); - // + // // Now, make the image a bit smaller, so that the background is a ring around the image // int offset = 3; @@ -333,8 +333,8 @@ public class Callout { Point p1 = new Point((int) cr.getCenterX(), (int) cr.getCenterY()); Point p2 = new Point(sr.x + (sr.width / 2), sr.y + (sr.height / 2)); - // - // Calculate the tangents to the callout circle + // + // Calculate the tangents to the callout circle // int radius = sr.width / 2; int dx = p2.x - p1.x; diff --git a/Ghidra/Framework/Gui/src/main/java/generic/test/AbstractGuiTest.java b/Ghidra/Framework/Gui/src/main/java/generic/test/AbstractGuiTest.java index aec2c11bba..2e7bc58151 100644 --- a/Ghidra/Framework/Gui/src/main/java/generic/test/AbstractGuiTest.java +++ b/Ghidra/Framework/Gui/src/main/java/generic/test/AbstractGuiTest.java @@ -15,8 +15,7 @@ */ package generic.test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.awt.*; import java.awt.event.*; @@ -1110,8 +1109,8 @@ public class AbstractGuiTest extends AbstractGenericTest { if (expected.getRGB() == actual.getRGB()) { return; } - fail("Expected: [" + expected.getClass().getSimpleName() + "]" + expected + - ", but got: [" + actual.getClass().getSimpleName() + "]" + actual); + fail("Expected: [" + expected.getClass().getSimpleName() + "]" + expected + ", but got: [" + + actual.getClass().getSimpleName() + "]" + actual); } public static void printMemory() { diff --git a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/RepositoryScreenShots.java b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/RepositoryScreenShots.java index 74285df82b..abd9fe55c9 100644 --- a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/RepositoryScreenShots.java +++ b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/RepositoryScreenShots.java @@ -63,10 +63,6 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { protected MergeScreenShotGenerator mtfGenerator; static protected float DESCRIPTION_FONT_SIZE = (float) 14.0; - public RepositoryScreenShots() { - super(); - } - @Before @Override public void setUp() throws Exception { @@ -81,6 +77,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { @Override public void tearDown() throws Exception { mtfGenerator.showResults(); + closeAllWindows(); mtf.dispose(); } @@ -96,13 +93,6 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { mtfGenerator.setTool(mergeTool); } -// public void testMultiUser() throws Exception { -// GhidraScreenShotGenerator gssg = new GhidraScreenShotGenerator(getName()); -// gssg.setUp(); -// gssg.captureWindow(); -// -// } - @Test public void testMemoryConflict() throws Exception { mtf.initialize("WallaceSrc", new ProgramModifierListener() { @@ -2412,8 +2402,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { boolean commit = false; try { program.getExternalManager() - .setExternalPath("ADVAPI32.DLL", "//advapi32.dll", - true); + .setExternalPath("ADVAPI32.DLL", "//advapi32.dll", true); commit = true; } finally { @@ -2469,8 +2458,7 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { boolean commit = false; try { program.getExternalManager() - .setExternalPath("ADVAPI32.DLL", "//advapi32.dll", - true); + .setExternalPath("ADVAPI32.DLL", "//advapi32.dll", true); commit = true; } finally { @@ -2572,11 +2560,9 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { FrontEndTool frontEndTool = env.showFrontEndTool(); DomainFolder rootFolder = frontEndTool.getProject().getProjectData().getRootFolder(); TaskMonitor dummyMonitor = TaskMonitor.DUMMY; - DomainFile myTestArchiveDF = - env.restoreDataTypeArchive("MyTestArchive.gdt", rootFolder); - final DataTypeArchive myTestArchive = - (DataTypeArchiveDB) myTestArchiveDF.getDomainObject(this, true, false, - TaskMonitor.DUMMY); + DomainFile myTestArchiveDF = env.restoreDataTypeArchive("MyTestArchive.gdt", rootFolder); + final DataTypeArchive myTestArchive = (DataTypeArchiveDB) myTestArchiveDF + .getDomainObject(this, true, false, TaskMonitor.DUMMY); final CategoryPath sourceCatPath = new CategoryPath("/Category1/Category2/Category5"); final DataType floatStruct = @@ -2729,8 +2715,8 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { ExternalLocationIterator iter = extMgr.getExternalLocations(libName); while (iter.hasNext()) { ExternalLocation loc = iter.next(); - if (!((ExternalManagerDB) extMgr).removeExternalLocation( - loc.getExternalSpaceAddress())) { + if (!((ExternalManagerDB) extMgr) + .removeExternalLocation(loc.getExternalSpaceAddress())) { Assert.fail("Couldn't remove external location for library " + libName); } } @@ -2868,9 +2854,9 @@ public class RepositoryScreenShots extends AbstractListingMergeManagerTest { JScrollPane scrollPane = (JScrollPane) TestUtils.getInstanceField("scrollPane", latestScroller); JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar(); - horizontalScrollBar.setValue( - (horizontalScrollBar.getMinimum() + horizontalScrollBar.getMaximum() - - horizontalScrollBar.getVisibleAmount()) * percent / 100); + horizontalScrollBar + .setValue((horizontalScrollBar.getMinimum() + horizontalScrollBar.getMaximum() - + horizontalScrollBar.getVisibleAmount()) * percent / 100); }); waitForSwing(); }