GT-2698 - fix for tests so Swing isn't dragged in

This commit is contained in:
dev747368 2019-04-23 16:23:24 -04:00
parent 5764e7174e
commit c7ce28e94c
22 changed files with 132 additions and 108 deletions

View File

@ -22,8 +22,8 @@ import java.util.*;
import javax.swing.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import docking.DockingUtils;
import docking.ToolTipManager;
import docking.widgets.GComponent;
import ghidra.program.model.listing.Group;
import resources.ResourceManager;
@ -87,7 +87,7 @@ class DnDTreeCellRenderer extends DefaultTreeCellRenderer {
* @param enable true to enable HTML rendering; false to disable it
*/
public void setHTMLRenderingEnabled(boolean enable) {
putClientProperty(DockingUtils.HTML_DISABLE_STRING, !enable);
putClientProperty(GComponent.HTML_DISABLE_STRING, !enable);
}
void setSelectionForDrag(Color color) {

View File

@ -24,9 +24,9 @@ import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import docking.DockingUtils;
import docking.widgets.button.GRadioButton;
import docking.widgets.label.GLabel;
import docking.widgets.list.GList;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
@ -61,7 +61,7 @@ public class ChooseAddressSetEditorPanel extends JPanel {
private JButton removeRangeButton;
private JPanel bottomButtons;
private AddressSetListModel listModel;
private JList<AddressRange> list;
private GList<AddressRange> list;
private Set<ChangeListener> listeners = new HashSet<>();
public ChooseAddressSetEditorPanel(final PluginTool tool, final String name,
@ -235,8 +235,7 @@ public class ChooseAddressSetEditorPanel extends JPanel {
headerPanel.add(buttonPanel, BorderLayout.EAST);
listModel = new AddressSetListModel(myCurrentAddressSet.toList());
list = new JList<>(listModel);
DockingUtils.turnOffHTMLRendering(list);
list = new GList<>(listModel);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override

View File

@ -21,12 +21,13 @@ import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import docking.menu.DockingMenuItemUI;
import docking.widgets.GComponent;
public class DockingMenuItem extends JMenuItem {
public DockingMenuItem() {
setUI(DockingMenuItemUI.createUI(this));
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
@Override

View File

@ -27,8 +27,6 @@ import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.undo.UndoableEdit;
import org.apache.commons.lang3.StringUtils;
import docking.widgets.button.GRadioButton;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.checkbox.GHtmlCheckBox;
@ -41,9 +39,7 @@ import docking.widgets.table.GTableCellRenderer;
import docking.widgets.tree.support.GTreeRenderer;
import ghidra.docking.util.DockingWindowsLookAndFeelUtils;
import ghidra.util.HTMLUtilities;
import ghidra.util.Msg;
import resources.ResourceManager;
import utilities.util.reflection.ReflectionUtilities;
/**
* <h1>Notes about how to use HTML safely:</h1>
@ -97,9 +93,6 @@ import utilities.util.reflection.ReflectionUtilities;
* </table>
*/
public class DockingUtils {
// taken from BasicHTML.htmlDisable, which is private
public static final String HTML_DISABLE_STRING = "html.disable";
private static final int ICON_SIZE = 16;
/** System dependent mask for the Ctrl key */
@ -139,55 +132,6 @@ public class DockingUtils {
return separator;
}
/**
* Helper function that logs a warning about a string text that looks like it has HTML text.
* <p>
* Use this when working with a string in a label that has already disabled HTML rendering.
* <p>
* @param text string to test for HTML and warn about
*/
public static void warnAboutHtmlText(String text) {
// #ifdef still_finding_html_labels_in_our_huge_codebase
if (StringUtils.startsWithIgnoreCase(text, "<html>")) {
Msg.warn(GLabel.class, "HTML text detected in non-HTML component: " + text,
ReflectionUtilities.createJavaFilteredThrowable());
}
// #endif
}
/**
* Turns off the HTML rendering in the specified component.
*
* @param comp the thing
*/
public static void turnOffHTMLRendering(JComponent comp) {
comp.putClientProperty(HTML_DISABLE_STRING, true);
}
/**
* Turns off the HTML rendering in the specified component and its current cell renderer.
*
* @param list the list
*/
public static void turnOffHTMLRendering(JList<?> list) {
turnOffHTMLRendering((JComponent) list);
if (list.getCellRenderer() instanceof JComponent) {
turnOffHTMLRendering((JComponent) list.getCellRenderer());
}
}
/**
* Turns off the HTML rendering in the specified component and its current renderer.
*
* @param cb the combobox
*/
public static void turnOffHTMLRendering(JComboBox<?> cb) {
turnOffHTMLRendering((JComponent) cb);
if (cb.getRenderer() instanceof JComponent) {
turnOffHTMLRendering((JComponent) cb.getRenderer());
}
}
public static Icon scaleIconAsNeeded(Icon icon) {
if (icon == null) {
return null;

View File

@ -21,7 +21,6 @@ import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.border.Border;
import docking.DockingUtils;
import docking.widgets.label.GDHtmlLabel;
/**
@ -82,7 +81,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
* @param enable true to enable HTML rendering; false to disable it
*/
public void setHTMLRenderingEnabled(boolean enable) {
putClientProperty(DockingUtils.HTML_DISABLE_STRING, !enable);
putClientProperty(GComponent.HTML_DISABLE_STRING, !enable);
}
public void setShouldAlternateRowBackgroundColors(boolean alternate) {

View File

@ -26,7 +26,6 @@ import javax.swing.event.*;
import org.apache.commons.lang3.StringUtils;
import docking.DockingUtils;
import docking.widgets.label.GDLabel;
import generic.util.WindowUtilities;
import ghidra.util.StringUtilities;
@ -132,7 +131,7 @@ public class DropDownTextField<T> extends JTextField {
}
private void init(int updateMinDelay) {
DockingUtils.turnOffHTMLRendering(list);
GComponent.turnOffHTMLRendering(list);
updateManager = new SwingUpdateManager(updateMinDelay, DEFAULT_MAX_UPDATE_DELAY,
"Drop Down Selection Text Field Update Manager", () -> {
if (pendingTextUpdate == null) {

View File

@ -0,0 +1,79 @@
/* ###
* 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 docking.widgets;
import javax.swing.*;
import org.apache.commons.lang3.StringUtils;
import docking.widgets.label.GLabel;
import ghidra.util.Msg;
import utilities.util.reflection.ReflectionUtilities;
public interface GComponent {
// taken from BasicHTML.htmlDisable, which is private
public static final String HTML_DISABLE_STRING = "html.disable";
/**
* Helper function that logs a warning about a string text that looks like it has HTML text.
* <p>
* Use this when working with a string in a label that has already disabled HTML rendering.
* <p>
* @param text string to test for HTML and warn about
*/
public static void warnAboutHtmlText(String text) {
// #ifdef still_finding_html_labels_in_our_huge_codebase
if (StringUtils.startsWithIgnoreCase(text, "<html>")) {
Msg.warn(GLabel.class, "HTML text detected in non-HTML component: " + text,
ReflectionUtilities.createJavaFilteredThrowable());
}
// #endif
}
/**
* Turns off the HTML rendering in the specified component.
*
* @param comp the thing
*/
public static void turnOffHTMLRendering(JComponent comp) {
comp.putClientProperty(HTML_DISABLE_STRING, true);
}
/**
* Turns off the HTML rendering in the specified component and its current cell renderer.
*
* @param list the list
*/
public static void turnOffHTMLRendering(JList<?> list) {
turnOffHTMLRendering((JComponent) list);
if (list.getCellRenderer() instanceof JComponent) {
turnOffHTMLRendering((JComponent) list.getCellRenderer());
}
}
/**
* Turns off the HTML rendering in the specified component and its current renderer.
*
* @param cb the combobox
*/
public static void turnOffHTMLRendering(JComboBox<?> cb) {
turnOffHTMLRendering((JComponent) cb);
if (cb.getRenderer() instanceof JComponent) {
turnOffHTMLRendering((JComponent) cb.getRenderer());
}
}
}

View File

@ -17,13 +17,13 @@ package docking.widgets.button;
import javax.swing.*;
import docking.DockingUtils;
import docking.widgets.GComponent;
/**
* A {@link JRadioButton} that disables HTML rendering.
*
*/
public class GRadioButton extends JRadioButton {
public class GRadioButton extends JRadioButton implements GComponent {
/**
* Creates a blank radio button with HTML rendering disabled.
@ -113,6 +113,6 @@ public class GRadioButton extends JRadioButton {
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
}

View File

@ -17,7 +17,7 @@ package docking.widgets.checkbox;
import javax.swing.*;
import docking.DockingUtils;
import docking.widgets.GComponent;
/**
* A {@link JCheckBox} that has HTML rendering disabled.
@ -29,7 +29,7 @@ import docking.DockingUtils;
* <tr><td>{@link GHtmlCheckBox}</td><td>YES</td><td>HTML allowed JCheckBox</td></tr>
* </table>
*/
public class GCheckBox extends JCheckBox {
public class GCheckBox extends JCheckBox implements GComponent {
/**
* Creates a check box with no text or icon, with HTML rendering disabled.
@ -133,7 +133,7 @@ public class GCheckBox extends JCheckBox {
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
/**
@ -145,7 +145,7 @@ public class GCheckBox extends JCheckBox {
*/
@Override
public void setText(String text) {
DockingUtils.warnAboutHtmlText(text);
GComponent.warnAboutHtmlText(text);
super.setText(text);
}
}

View File

@ -17,6 +17,8 @@ package docking.widgets.checkbox;
import javax.swing.*;
import docking.widgets.GComponent;
/**
* A {@link JCheckBox} that allows HTML rendering.
* <p>
@ -27,7 +29,7 @@ import javax.swing.*;
* <tr><td>{@link GHtmlCheckBox}</td><td>YES</td><td>HTML allowed JCheckBox</td></tr>
* </table>
*/
public class GHtmlCheckBox extends JCheckBox {
public class GHtmlCheckBox extends JCheckBox implements GComponent {
/**
* Creates a check box with no text or icon, with HTML rendering allowed.

View File

@ -20,14 +20,14 @@ import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import docking.DockingUtils;
import docking.widgets.GComponent;
/**
* A {@link JComboBox} that disables HTML rendering.
*
* @param <E> the type of the elements of this combo box
*/
public class GComboBox<E> extends JComboBox<E> {
public class GComboBox<E> extends JComboBox<E> implements GComponent {
/**
* Creates an empty combobox with a default data model.
@ -77,7 +77,7 @@ public class GComboBox<E> extends JComboBox<E> {
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
}

View File

@ -26,7 +26,7 @@ import javax.swing.event.DocumentListener;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.text.*;
import docking.DockingUtils;
import docking.widgets.GComponent;
/**
* GhidraComboBox adds the following features:
@ -56,7 +56,7 @@ import docking.DockingUtils;
* focus) in that you end up changing the button's internal state(by calling
* setEnabled(true or false)) in the middle of the button press.
*/
public class GhidraComboBox<E> extends JComboBox<E> {
public class GhidraComboBox<E> extends JComboBox<E> implements GComponent {
private ArrayList<ActionListener> listeners = new ArrayList<>();
private ArrayList<DocumentListener> docListeners = new ArrayList<>();
private boolean setSelectedFlag = false;
@ -102,7 +102,7 @@ public class GhidraComboBox<E> extends JComboBox<E> {
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
@Override

View File

@ -17,6 +17,7 @@ package docking.widgets.label;
import javax.swing.*;
import docking.widgets.GComponent;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.checkbox.GHtmlCheckBox;
@ -36,7 +37,7 @@ import docking.widgets.checkbox.GHtmlCheckBox;
* <tr><td>{@link GHtmlCheckBox}</td><td></td><td>YES</td><td>Html checkbox</td></tr>
* </table>
*/
public class GDHtmlLabel extends JLabel {
public class GDHtmlLabel extends JLabel implements GComponent {
/**
* Creates a label with no image and no text, with {@link SwingConstants#LEADING} horizontal

View File

@ -17,7 +17,7 @@ package docking.widgets.label;
import javax.swing.*;
import docking.DockingUtils;
import docking.widgets.GComponent;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.checkbox.GHtmlCheckBox;
@ -37,7 +37,7 @@ import docking.widgets.checkbox.GHtmlCheckBox;
* <tr><td>{@link GHtmlCheckBox}</td><td></td><td>YES</td><td>Html checkbox</td></tr>
* </table>
*/
public class GDLabel extends JLabel {
public class GDLabel extends JLabel implements GComponent {
/**
* Creates a label with no image and no text, with {@link SwingConstants#LEADING} horizontal
@ -106,12 +106,12 @@ public class GDLabel extends JLabel {
@Override
public void setText(String text) {
DockingUtils.warnAboutHtmlText(text);
GComponent.warnAboutHtmlText(text);
super.setText(text);
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
}

View File

@ -19,6 +19,7 @@ import javax.swing.*;
import org.apache.commons.lang3.StringUtils;
import docking.widgets.GComponent;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.checkbox.GHtmlCheckBox;
import ghidra.util.Msg;
@ -40,7 +41,7 @@ import utilities.util.reflection.ReflectionUtilities;
* <tr><td>{@link GHtmlCheckBox}</td><td></td><td>YES</td><td>Html checkbox</td></tr>
* </table>
*/
public class GHtmlLabel extends JLabel {
public class GHtmlLabel extends JLabel implements GComponent {
/**
* Creates a immutable label with no image and no text, with {@link SwingConstants#LEADING} horizontal

View File

@ -19,6 +19,7 @@ import javax.swing.*;
import org.apache.commons.lang3.StringUtils;
import docking.widgets.GComponent;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.checkbox.GHtmlCheckBox;
import ghidra.util.Msg;
@ -40,7 +41,7 @@ import utilities.util.reflection.ReflectionUtilities;
* <tr><td>{@link GHtmlCheckBox}</td><td></td><td>YES</td><td>Html checkbox</td></tr>
* </table>
*/
public class GIconLabel extends GLabel {
public class GIconLabel extends GLabel implements GComponent {
/**
* Creates a immutable label with no image and no text, with {@link SwingConstants#LEADING} horizontal

View File

@ -19,7 +19,7 @@ import javax.swing.*;
import org.apache.commons.lang3.StringUtils;
import docking.DockingUtils;
import docking.widgets.GComponent;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.checkbox.GHtmlCheckBox;
import ghidra.util.Msg;
@ -41,7 +41,7 @@ import utilities.util.reflection.ReflectionUtilities;
* <tr><td>{@link GHtmlCheckBox}</td><td></td><td>YES</td><td>Html checkbox</td></tr>
* </table>
*/
public class GLabel extends JLabel {
public class GLabel extends JLabel implements GComponent {
/**
* Creates a immutable label with no image and no text, with {@link SwingConstants#LEADING} horizontal
@ -132,7 +132,7 @@ public class GLabel extends JLabel {
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
/**
@ -155,7 +155,7 @@ public class GLabel extends JLabel {
ReflectionUtilities.createJavaFilteredThrowable());
return;
}
DockingUtils.warnAboutHtmlText(text);
GComponent.warnAboutHtmlText(text);
super.setText(text);
}

View File

@ -22,7 +22,7 @@ import javax.swing.ListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import docking.DockingUtils;
import docking.widgets.GComponent;
import docking.widgets.table.GTable;
/**
@ -35,7 +35,7 @@ import docking.widgets.table.GTable;
* <p>
*
*/
public class GList<T> extends JList<T> {
public class GList<T> extends JList<T> implements GComponent {
private static final long serialVersionUID = 1L;
/**The timeout for the auto-lookup feature*/
@ -84,7 +84,7 @@ public class GList<T> extends JList<T> {
}
private void init() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {

View File

@ -20,7 +20,7 @@ import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.table.TableCellRenderer;
import docking.DockingUtils;
import docking.widgets.GComponent;
public class DefaultTableCellRendererWrapper extends GTableCellRenderer {
@ -44,7 +44,7 @@ public class DefaultTableCellRendererWrapper extends GTableCellRenderer {
@Override
public void setHTMLRenderingEnabled(boolean enable) {
if (renderer instanceof JComponent) {
((JComponent) renderer).putClientProperty(DockingUtils.HTML_DISABLE_STRING, !enable);
((JComponent) renderer).putClientProperty(GComponent.HTML_DISABLE_STRING, !enable);
}
super.setHTMLRenderingEnabled(enable);
}

View File

@ -21,11 +21,11 @@ import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import docking.DockingUtils;
import docking.widgets.GComponent;
import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
public class GTreeRenderer extends DefaultTreeCellRenderer {
public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent {
private static final long serialVersionUID = 1L;
private static final Color VALID_DROP_TARGET_COLOR = new Color(200, 200, 255);
private static final int DEFAULT_MIN_ICON_WIDTH = 22;
@ -38,7 +38,7 @@ public class GTreeRenderer extends DefaultTreeCellRenderer {
private int minIconWidth = DEFAULT_MIN_ICON_WIDTH;
public GTreeRenderer() {
DockingUtils.turnOffHTMLRendering(this);
GComponent.turnOffHTMLRendering(this);
}
/**

View File

@ -26,10 +26,10 @@ import javax.swing.*;
import javax.swing.event.*;
import docking.DialogComponentProvider;
import docking.DockingUtils;
import docking.widgets.button.GRadioButton;
import docking.widgets.label.GDLabel;
import docking.widgets.label.GLabel;
import docking.widgets.list.GList;
import ghidra.framework.client.*;
import ghidra.framework.model.ServerInfo;
import ghidra.framework.protocol.ghidra.GhidraURL;
@ -55,7 +55,7 @@ class RepositoryChooser extends DialogComponentProvider {
private ServerInfoComponent serverInfoComponent;
private JButton queryButton;
private JList<String> nameList;
private GList<String> nameList;
private DefaultListModel<String> listModel;
private JTextField urlTextField;
@ -104,8 +104,7 @@ class RepositoryChooser extends DialogComponentProvider {
lowerPanel.add(label, BorderLayout.NORTH);
listModel = new DefaultListModel<>();
nameList = new JList<>(listModel);
DockingUtils.turnOffHTMLRendering(nameList);
nameList = new GList<>(listModel);
nameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
nameList.addListSelectionListener(new ListSelectionListener() {
@Override

View File

@ -22,9 +22,9 @@ import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.*;
import docking.DockingUtils;
import docking.widgets.button.GRadioButton;
import docking.widgets.label.GDLabel;
import docking.widgets.list.GList;
import docking.wizard.*;
import ghidra.app.util.GenericHelpTopics;
import ghidra.util.HelpLocation;
@ -42,7 +42,7 @@ public class RepositoryPanel extends AbstractWizardJPanel {
private JRadioButton existingRepButton;
private JRadioButton createRepButton;
private ButtonGroup buttonGroup;
private JList<String> nameList;
private GList<String> nameList;
private DefaultListModel<String> listModel;
private JTextField nameField;
private JLabel nameLabel;
@ -161,8 +161,7 @@ public class RepositoryPanel extends AbstractWizardJPanel {
for (String repositoryName : repositoryNames) {
listModel.addElement(repositoryName);
}
nameList = new JList<>(listModel);
DockingUtils.turnOffHTMLRendering(nameList);
nameList = new GList<>(listModel);
nameList.setEnabled(existingRepButton.isSelected());
JScrollPane sp = new JScrollPane(nameList);
innerPanel.add(sp);