From 41f4e2cdde48f4f283f7b5a744eccbe3a48697e7 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Tue, 2 Apr 2019 13:05:40 -0400 Subject: [PATCH] GT-2716 - review fixes --- .../viewer/field/FieldHighlightFactory.java | 18 +++++-------- .../app/util/viewer/options/OptionsGui.java | 3 ++- .../plugin/core/byteviewer/FieldFactory.java | 2 +- .../core/byteviewer/IndexFieldFactory.java | 6 ++--- .../decompiler/component/DecompilerPanel.java | 7 ----- .../internal/TestBigLayoutModel.java | 27 +++++-------------- .../fieldpanel/support/HighlightFactory.java | 14 +--------- .../fieldpanel/FlowLayoutTextFieldTest.java | 9 +++---- .../VerticalLayoutTextFieldTest.java | 9 +++---- 9 files changed, 26 insertions(+), 69 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FieldHighlightFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FieldHighlightFactory.java index c46721d71e..7f340dc38f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FieldHighlightFactory.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FieldHighlightFactory.java @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +15,7 @@ */ package ghidra.app.util.viewer.field; +import docking.widgets.fieldpanel.field.Field; import docking.widgets.fieldpanel.support.Highlight; import docking.widgets.fieldpanel.support.HighlightFactory; import ghidra.app.util.HighlightProvider; @@ -30,26 +30,22 @@ public class FieldHighlightFactory implements HighlightFactory { private HighlightProvider provider; private Class fieldFactoryClass; private Object obj; - + /** * Constructs a new FieldHighlightFactory. * @param provider the HighlightProvider that will actually compute the highlights. * @param fieldFactoryClass the class of the field factory that generated the field to be rendered. * @param obj the object that holds the information that will be rendered (usually a code unit) */ - public FieldHighlightFactory(HighlightProvider provider, Class fieldFactoryClass, Object obj) { + public FieldHighlightFactory(HighlightProvider provider, + Class fieldFactoryClass, Object obj) { this.provider = provider; this.fieldFactoryClass = fieldFactoryClass; this.obj = obj; } - - /** - * Returns the highlights for the given text. - * @param text the text to be considered for highlighting. - * @return an array of highlights to be rendered. - */ - public Highlight[] getHighlights(String text, int cursorTextOffset) { + + @Override + public Highlight[] getHighlights(Field field, String text, int cursorTextOffset) { return provider.getHighlights(text, obj, fieldFactoryClass, cursorTextOffset); } - } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/options/OptionsGui.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/options/OptionsGui.java index 0ef35c6d47..4d58561dec 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/options/OptionsGui.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/options/OptionsGui.java @@ -51,7 +51,8 @@ public class OptionsGui extends JPanel { private static final Color DARK_ORANGE = new Color(255, 128, 0); private static final Color DARK_RED = new Color(130, 0, 75); private static final Highlight[] NO_HIGHLIGHTS = new Highlight[0]; - private static final HighlightFactory hlFactory = (text, cursorTextOffset) -> NO_HIGHLIGHTS; + private static final HighlightFactory hlFactory = + (field, text, cursorTextOffset) -> NO_HIGHLIGHTS; public static final ScreenElement COMMENT_AUTO = new ScreenElement("Comment, Automatic", Color.LIGHT_GRAY); diff --git a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/FieldFactory.java b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/FieldFactory.java index b821e8b3c9..81ed547bfb 100644 --- a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/FieldFactory.java +++ b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/FieldFactory.java @@ -213,7 +213,7 @@ class FieldFactory { } @Override - public Highlight[] getHighlights(String text, int cursorTextOffset) { + public Highlight[] getHighlights(Field field, String text, int cursorTextOffset) { return provider.getHighlights(text, null, null, -1); } } diff --git a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/IndexFieldFactory.java b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/IndexFieldFactory.java index bd828d425e..cb7ae28d6c 100644 --- a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/IndexFieldFactory.java +++ b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/IndexFieldFactory.java @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +15,6 @@ */ package ghidra.app.plugin.core.byteviewer; -import ghidra.app.plugin.core.format.ByteBlockInfo; - import java.awt.Color; import java.awt.FontMetrics; import java.math.BigInteger; @@ -26,6 +23,7 @@ import docking.widgets.fieldpanel.field.Field; import docking.widgets.fieldpanel.field.SimpleTextField; import docking.widgets.fieldpanel.support.Highlight; import docking.widgets.fieldpanel.support.HighlightFactory; +import ghidra.app.plugin.core.format.ByteBlockInfo; /** * Implementation for the index/address field. @@ -145,7 +143,7 @@ class IndexFieldFactory { } @Override - public Highlight[] getHighlights(String text, int cursorTextOffset) { + public Highlight[] getHighlights(Field field, String text, int cursorTextOffset) { return NO_HIGHLIGHTS; } } diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java index d178ad955a..9ab2bc8802 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -702,12 +701,6 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field class SearchHighlightFactory implements HighlightFactory { - @Override - public Highlight[] getHighlights(String text, int cursorTextOffset) { - // the search highlight needs the Field in order to work correctly - return new Highlight[0]; - } - @Override public Highlight[] getHighlights(Field field, String text, int cursorTextOffset) { if (currentSearchLocation == null) { diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/TestBigLayoutModel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/TestBigLayoutModel.java index 371314727f..c2803615ea 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/TestBigLayoutModel.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/TestBigLayoutModel.java @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +16,6 @@ package docking.widgets.fieldpanel.internal; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.math.BigInteger; import java.util.ArrayList; @@ -33,11 +30,8 @@ import docking.widgets.indexedscrollpane.IndexedScrollPane; public class TestBigLayoutModel implements LayoutModel { private static final Highlight[] NO_HIGHLIGHTS = new Highlight[0]; - private static final HighlightFactory hlFactory = new HighlightFactory() { - public Highlight[] getHighlights(String text, int cursorTextOffset) { - return NO_HIGHLIGHTS; - } - }; + private static final HighlightFactory hlFactory = + (field, text, cursorTextOffset) -> NO_HIGHLIGHTS; ArrayList listeners = new ArrayList(); FontMetrics fm; @@ -86,15 +80,13 @@ public class TestBigLayoutModel implements LayoutModel { if (index.compareTo(numIndexes) >= 0) { return null; } - String text = - name + ": This is line " + index + - " More text to make line longer abcdefghijklmnopqrstuvwxyzabcdefghijk"; + String text = name + ": This is line " + index + + " More text to make line longer abcdefghijklmnopqrstuvwxyzabcdefghijk"; FieldElement fe1 = new TextFieldElement(new AttributedString(text, Color.BLACK, fm), 0, 0); FieldElement fe2 = new TextFieldElement(new AttributedString("More text", Color.BLACK, fm), 0, 0); - SingleRowLayout layout = - new SingleRowLayout(new ClippingTextField(20, 300, fe1, hlFactory), - new ClippingTextField(330, 100, fe2, hlFactory)); + SingleRowLayout layout = new SingleRowLayout(new ClippingTextField(20, 300, fe1, hlFactory), + new ClippingTextField(330, 100, fe2, hlFactory)); if (index.intValue() >= startBigSizes && index.intValue() <= endBigSizes) { layout.insertSpaceAbove(30); @@ -143,12 +135,7 @@ public class TestBigLayoutModel implements LayoutModel { contentPane.setLayout(new BorderLayout()); contentPane.add(scrollPanel); JButton button = new JButton("Hit Me"); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - model.updateData(1000, 2000); - } - }); + button.addActionListener(e -> model.updateData(1000, 2000)); contentPane.add(button, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/support/HighlightFactory.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/support/HighlightFactory.java index 4a97453560..8ac6c85d17 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/support/HighlightFactory.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/support/HighlightFactory.java @@ -19,16 +19,6 @@ import docking.widgets.fieldpanel.field.Field; public interface HighlightFactory { - /** - * Returns the highlights for the given text - * - * @param text the text to be considered for highlighting - * @param cursorTextOffset the position in the given text of the cursor. A -1 indicates the - * cursor is not in this field. - * @return an array of highlights to be rendered - */ - public Highlight[] getHighlights(String text, int cursorTextOffset); - /** * Returns the highlights for the given text * @@ -38,7 +28,5 @@ public interface HighlightFactory { * cursor is not in this field. * @return an array of highlights to be rendered */ - public default Highlight[] getHighlights(Field field, String text, int cursorTextOffset) { - return getHighlights(text, cursorTextOffset); - } + public Highlight[] getHighlights(Field field, String text, int cursorTextOffset); } diff --git a/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/FlowLayoutTextFieldTest.java b/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/FlowLayoutTextFieldTest.java index 675ec2b03f..604bd46201 100644 --- a/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/FlowLayoutTextFieldTest.java +++ b/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/FlowLayoutTextFieldTest.java @@ -15,7 +15,7 @@ */ package docking.widgets.fieldpanel; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.awt.*; @@ -40,11 +40,8 @@ public class FlowLayoutTextFieldTest extends AbstractGenericTest { @Before public void setUp() throws Exception { - HighlightFactory factory = new HighlightFactory() { - @Override - public Highlight[] getHighlights(String text, int cursorTextOffset) { - return new Highlight[] { new Highlight(4, 4, Color.YELLOW) }; - } + HighlightFactory factory = (field, text, cursorTextOffset) -> { + return new Highlight[] { new Highlight(4, 4, Color.YELLOW) }; }; Font font = new Font("Times New Roman", 0, 14); diff --git a/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/VerticalLayoutTextFieldTest.java b/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/VerticalLayoutTextFieldTest.java index 6d77b473e9..dacf10ab15 100644 --- a/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/VerticalLayoutTextFieldTest.java +++ b/Ghidra/Framework/Docking/src/test/java/docking/widgets/fieldpanel/VerticalLayoutTextFieldTest.java @@ -15,7 +15,7 @@ */ package docking.widgets.fieldpanel; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.awt.*; @@ -40,11 +40,8 @@ public class VerticalLayoutTextFieldTest extends AbstractGenericTest { @Before public void setUp() throws Exception { - HighlightFactory factory = new HighlightFactory() { - @Override - public Highlight[] getHighlights(String text, int cursorTextOffset) { - return new Highlight[] { new Highlight(4, 4, Color.YELLOW) }; - } + HighlightFactory factory = (field, text, cursorTextOffset) -> { + return new Highlight[] { new Highlight(4, 4, Color.YELLOW) }; }; Font font = new Font("Times New Roman", 0, 14);