Ghidra is a software reverse engineering (SRE) framework
GP-6366 - Fix for filter field sometimes not getting painted
dragonmacherf518be46382a
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filter/FilterTextField.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filter/FilterTextField.javaindex ac306cfb1a..b88d507630 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filter/FilterTextField.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filter/FilterTextField.java@@ -28,6 +28,7 @@ import generic.theme.GThemeDefaults.Colors;import ghidra.util.SystemUtilities;import ghidra.util.datastruct.WeakDataStructureFactory;import ghidra.util.datastruct.WeakSet;+import ghidra.util.layout.AbstractLayoutManager;import utility.function.Callback;/**@@ -101,34 +102,13 @@ public class FilterTextField extends JPanel {textField.getDocument().addDocumentListener(new FilterDocumentListener());textField.addActionListener(e -> notifyEnterPressed());- layeredPane = new JLayeredPane() {- @Override- public Dimension getPreferredSize() {- Insets insets = getInsets();- Dimension ps = textField.getPreferredSize();- ps.width += insets.left + insets.right;- ps.height += insets.top + insets.bottom;- return ps;- }- };+ layeredPane = new JLayeredPane();+ layeredPane.setLayout(new FilterFieldLayoutManager());layeredPane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));layeredPane.add(textField, BASE_COMPONENT_LAYER);layeredPane.add(clearLabel, HOVER_COMPONENT_LAYER);clearLabel.setVisible(false);- layeredPane.addComponentListener(new ComponentAdapter() {- @Override- public void componentResized(java.awt.event.ComponentEvent e) {- Dimension preferredSize = layeredPane.getSize();- Insets insets = layeredPane.getInsets();- int x = insets.left;- int y = insets.top;- int width = preferredSize.width - insets.right - x;- int height = preferredSize.height - (insets.top + insets.bottom);- textField.setBounds(x, y, width, height);- }- });-add(layeredPane, BorderLayout.NORTH);DockingUtils.installUndoRedo(textField);@@ -407,6 +387,33 @@ public class FilterTextField extends JPanel {// Inner Classes//==================================================================================================+ /**+ * A simple layout manager to size and position the text field within this widget. The manager+ * does not update the clear button, as that manages its own bounds.+ */+ private class FilterFieldLayoutManager extends AbstractLayoutManager {++ @Override+ public void layoutContainer(Container parent) {+ Dimension d = parent.getSize();+ Insets insets = parent.getInsets();+ int width = d.width - insets.left - insets.right;+ int x = insets.left;+ int y = insets.top;+ int height = d.height - (insets.top + insets.bottom);+ textField.setBounds(x, y, width, height);+ }++ @Override+ public Dimension preferredLayoutSize(Container parent) {+ Insets insets = parent.getInsets();+ Dimension ps = textField.getPreferredSize();+ ps.width += insets.left + insets.right;+ ps.height += insets.top + insets.bottom;+ return ps;+ }+ }+private class TraversalKeyListener extends KeyAdapter {private final Component component;diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/AbstractLayoutManager.java b/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/AbstractLayoutManager.javanew file mode 100644index 0000000000..d7bb60fb90--- /dev/null+++ b/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/AbstractLayoutManager.java@@ -0,0 +1,40 @@+/* ###+ * 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.util.layout;++import java.awt.*;++/**+ * An abstract {@link LayoutManager} that stubs out typically unused methods and defaults the+ * minimum size to the preferred size.+ */+public abstract class AbstractLayoutManager implements LayoutManager {++ @Override+ public Dimension minimumLayoutSize(Container parent) {+ return preferredLayoutSize(parent);+ }++ @Override+ public void addLayoutComponent(String name, Component comp) {+ // stub+ }++ @Override+ public void removeLayoutComponent(Component comp) {+ // stub+ }+}diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/ColumnLayout.java b/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/ColumnLayout.javaindex 91f62f3051..5f4815a74f 100644--- a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/ColumnLayout.java+++ b/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/ColumnLayout.java@@ -4,9 +4,9 @@* 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.@@ -32,7 +32,7 @@ public class ColumnLayout implements LayoutManager {* Constructs a new ColumnLayout* @param hgap the gap (in pixels) between columns* @param vgap the gap (in pixels) between rows- * @param preferredNumCols the prefered number of columns to use in the layout.+ * @param preferredNumCols the preferred number of columns to use in the layout.*/public ColumnLayout(int hgap, int vgap, int preferredNumCols) {this.hgap = hgap;diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/RowColumnLayout.java b/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/RowColumnLayout.javadeleted file mode 100644index b2e225f90f..0000000000--- a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/RowColumnLayout.java+++ /dev/null@@ -1,182 +0,0 @@-/* ###- * 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.util.layout;--import java.awt.*;--/**- * This layout arranges components in rows, putting as many components as possible on a- * row and using as many rows as necessary. All components are sized the same, the largest width- * and the largest height of all components. The components prefer to be layout as close to- * a square as possible.- */-public class RowColumnLayout implements LayoutManager {- public static final int ROW = 0;- public static final int COLUMN = 1;- public static final int LEFT_TO_RIGHT = 0;- public static final int TOP_TO_BOTTOM = 1;- private int vgap;- private int hgap;- private int compWidth;- private int compHeight;- private int orientation;- private int maxSize;- private int fillOrder;-- /**- * Constructs a new RowColumnLayout- * @param hgap the gap (in pixels) between columns- * @param vgap the gap (in pixels) between rows- * @param orientation either ROW or COLUMN. If ROW, components are layed out- * in rows up to prefered width, using as many rows a necessary. If COLUMN, components are layed out- * in columns up to the prefered height, using as many columns as necessary.- * @param maxSize- */- public RowColumnLayout(int hgap, int vgap, int orientation, int maxSize) {- this.hgap = hgap;- this.vgap = vgap;- this.orientation = orientation;- this.maxSize = maxSize;- this.fillOrder = LEFT_TO_RIGHT;- }-- /**- * @see LayoutManager#addLayoutComponent(String, Component)- */- @Override- public void addLayoutComponent(String name, Component comp) {- }-- /**- * @see LayoutManager#removeLayoutComponent(Component)- */- @Override- public void removeLayoutComponent(Component comp) {- }-- /**- * @see LayoutManager#preferredLayoutSize(Container)- */- @Override- public Dimension preferredLayoutSize(Container parent) {- Insets insets = parent.getInsets();- int n = parent.getComponentCount();- computeComponentSize(parent);-- int numRows = 1;- int numCols = 1;-- if (orientation == ROW) {- int width = Math.max(maxSize - insets.left - insets.right, compWidth);- numCols = (width + hgap) / (compWidth + hgap);- numRows = (n + numCols - 1) / numCols;- numCols = (n + numRows - 1) / numRows;- }- else {- int height = Math.max(maxSize - insets.top - insets.bottom, compHeight);- numRows = (height + vgap) / (compHeight + vgap);- numCols = (n + numRows - 1) / numRows;- numRows = (n + numCols - 1) / numCols;- }-- int height = numRows * compHeight + (numRows - 1) * vgap;- int width = numCols * compWidth + (numCols - 1) * hgap;- Dimension d = new Dimension(width + insets.left + insets.right + 2,- height + insets.top + insets.bottom + 2);-- return d;- }-- /**- * @see LayoutManager#minimumLayoutSize(Container)- */- @Override- public Dimension minimumLayoutSize(Container parent) {- Insets insets = parent.getInsets();- return new Dimension(compWidth + insets.left + insets.right,- compHeight + insets.top + insets.bottom);- }-- /**- * @see LayoutManager#layoutContainer(Container)- */- @Override- public void layoutContainer(Container parent) {-- computeComponentSize(parent);- int n = parent.getComponentCount();- Dimension d = parent.getSize();- Insets insets = parent.getInsets();- int parentWidth = d.width - insets.left - insets.right;- int parentHeight = d.height - insets.top - insets.bottom;-- int numRows = 1;- int numCols = 1;- if (orientation == ROW) {- numCols = (parentWidth + hgap) / (compWidth + hgap);- if (numCols < 1) {- numCols = 1;- }- numRows = (n + numCols - 1) / numCols;- numCols = (n + numRows - 1) / numRows;- }- else {- numRows = (parentHeight + vgap) / (compHeight + vgap);- if (numRows < 1) {- numRows = 1;- }- numCols = (n + numRows - 1) / numRows;- numRows = (n + numCols - 1) / numCols;- }--// int left = insets.left + (parentWidth - numCols*compWidth- (numCols-1)*hgap)/2;-// int top = insets.top + (parentHeight - numRows*compHeight - (numRows-1)*vgap)/2;- int left = insets.left;- int top = insets.top;-- for (int i = 0; i < numRows; i++) {- for (int j = 0; j < numCols; j++) {- int x = left + j * (compWidth + hgap);- int y = top + i * (compHeight + vgap);- int k = fillOrder == LEFT_TO_RIGHT ? i * numCols + j : j * numRows + i;- if (k < n) {- Component c = parent.getComponent(k);- c.setBounds(x, y, compWidth, compHeight);- }- }- }- }-- private void computeComponentSize(Container parent) {- int n = parent.getComponentCount();- compWidth = 0;- compHeight = 0;-- for (int i = 0; i < n; i++) {- Component c = parent.getComponent(i);- Dimension d = c.getPreferredSize();- compWidth = Math.max(compWidth, d.width);- compHeight = Math.max(compHeight, d.height);- }- }-- /**- * @param maxSize- */- public void setMaxSize(int maxSize) {- this.maxSize = maxSize;- }-}diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/RowLayout.java b/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/RowLayout.javadeleted file mode 100644index 347b641ea2..0000000000--- a/Ghidra/Framework/Gui/src/main/java/ghidra/util/layout/RowLayout.java+++ /dev/null@@ -1,131 +0,0 @@-/* ###- * 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.util.layout;--import java.awt.*;--/**- * This layout arranges components in rows, putting as many components as possible on a- * row and using as many rows as necessary.- */-public class RowLayout implements LayoutManager {- private int vgap;- private int hgap;- private int compWidth;- private int compHeight;- private int preferredNumRows;-- /**- * Constructs a new RowLayout- * @param hgap the gap (in pixels) between columns- * @param vgap the gap (in pixels) between rows- * @param preferredNumRows the prefered number of rows to use in the layout.- */- public RowLayout(int hgap, int vgap, int preferredNumRows) {- this.hgap = hgap;- this.vgap = vgap;- this.preferredNumRows = preferredNumRows;- }-- /**- * @see LayoutManager#addLayoutComponent(String, Component)- */- @Override- public void addLayoutComponent(String name, Component comp) {- }-- /**- * @see LayoutManager#removeLayoutComponent(Component)- */- @Override- public void removeLayoutComponent(Component comp) {- }-- /**- * @see LayoutManager#preferredLayoutSize(Container)- */- @Override- public Dimension preferredLayoutSize(Container parent) {- Insets insets = parent.getInsets();- int n = parent.getComponentCount();- computeComponentSize(parent);-- int numCols = (n + preferredNumRows - 1) / preferredNumRows;- int numRows = (n + numCols - 1) / numCols;-- int height = numRows * compHeight + (numRows - 1) * vgap;- int width = numCols * compWidth + (numCols - 1) * hgap;- Dimension d = new Dimension(width + insets.left + insets.right + 2,- height + insets.top + insets.bottom + 2);-- return d;- }-- /**- * @see LayoutManager#minimumLayoutSize(Container)- */- @Override- public Dimension minimumLayoutSize(Container parent) {- Insets insets = parent.getInsets();- return new Dimension(compWidth + insets.left + insets.right,- compHeight + insets.top + insets.bottom);- }-- /**- * @see LayoutManager#layoutContainer(Container)- */- @Override- public void layoutContainer(Container parent) {-- computeComponentSize(parent);- int n = parent.getComponentCount();- Dimension d = parent.getSize();- Insets insets = parent.getInsets();- int parentWidth = d.width - insets.left - insets.right;- //int parentHeight = d.height - insets.top - insets.bottom;-- int maxCols = (parentWidth + hgap) / (compWidth + hgap);- int numRows = (n + maxCols - 1) / maxCols;- int numCols = (n + numRows - 1) / numRows;- int left = insets.left + (parentWidth - numCols * compWidth - (numCols - 1) * hgap) / 2;- int top = insets.top;-- for (int i = 0; i < numRows; i++) {- for (int j = 0; j < numCols; j++) {- int x = left + j * (compWidth + hgap);- int y = top + i * (compHeight + vgap);- int k = i * numCols + j;- if (k < n) {- Component c = parent.getComponent(k);- c.setBounds(x, y, compWidth, compHeight);- }- }- }- }-- private void computeComponentSize(Container parent) {- int n = parent.getComponentCount();- compWidth = 0;- compHeight = 0;-- for (int i = 0; i < n; i++) {- Component c = parent.getComponent(i);- Dimension d = c.getPreferredSize();- compWidth = Math.max(compWidth, d.width);- compHeight = Math.max(compHeight, d.height);- }- }-}diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/XRefFieldLocation.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/XRefFieldLocation.javaindex 52b1194523..16ed596c5a 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/XRefFieldLocation.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/XRefFieldLocation.java@@ -4,9 +4,9 @@* 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.@@ -52,7 +52,7 @@ public class XRefFieldLocation extends CodeUnitLocation {}/**- * Returns the index of the XREF in the list.+ * {@return the index of the XREF in the list.}*/public int getIndex() {return getColumn();@@ -60,7 +60,7 @@ public class XRefFieldLocation extends CodeUnitLocation {@Overridepublic String toString() {- return super.toString() + ", reAddr=" + refAddr;+ return super.toString() + ", refAddr=" + refAddr;}}