GP-1831 - fixed potential NPE for plugin packages that do not specify an

icon
This commit is contained in:
dragonmacher 2022-03-15 12:59:23 -04:00
parent 21aa55cf2d
commit e2858eca97
2 changed files with 25 additions and 19 deletions

View file

@ -36,6 +36,8 @@ import ghidra.util.layout.VerticalLayout;
import resources.ResourceManager;
public class PluginManagerComponent extends JPanel implements Scrollable {
private static final Icon DEFAULT_ICON = ResourceManager.loadImage("images/plasma.png");
private final PluginTool tool;
private PluginConfigurationModel model;
private List<PluginPackageComponent> packageComponentList = new ArrayList<>();
@ -107,9 +109,9 @@ public class PluginManagerComponent extends JPanel implements Scrollable {
throw new AssertException("No checkbox found for " + pluginPackage);
}
//==================================================================================================
//=================================================================================================
// Inner Classes
//==================================================================================================
//=================================================================================================
private class PluginPackageComponent extends JPanel {
private final Color BG = Color.white;
@ -132,7 +134,7 @@ public class PluginManagerComponent extends JPanel implements Scrollable {
}
private void initizalizeCheckBoxSection() {
final JPanel checkboxPanel = new JPanel(new HorizontalLayout(0));
JPanel checkboxPanel = new JPanel(new HorizontalLayout(0));
checkboxPanel.setBackground(BG);
checkBox.addActionListener(
@ -146,8 +148,12 @@ public class PluginManagerComponent extends JPanel implements Scrollable {
checkboxPanel.add(checkBox);
checkboxPanel.add(Box.createHorizontalStrut(10));
final JLabel iconLabel =
new GIconLabel(ResourceManager.getScaledIcon(pluginPackage.getIcon(), 32, 32, 32));
Icon icon = pluginPackage.getIcon();
if (icon == null) {
icon = DEFAULT_ICON;
}
JLabel iconLabel =
new GIconLabel(ResourceManager.getScaledIcon(icon, 32, 32, 32));
iconLabel.setBackground(BG);
checkboxPanel.add(iconLabel);
@ -158,22 +164,22 @@ public class PluginManagerComponent extends JPanel implements Scrollable {
}
private void initializeLabelSection() {
final JPanel centerPanel = new JPanel(new GridBagLayout());
JPanel centerPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
centerPanel.setBackground(BG);
final JPanel labelPanel = new JPanel(new VerticalLayout(3));
JPanel labelPanel = new JPanel(new VerticalLayout(3));
labelPanel.setBackground(BG);
final GLabel nameLabel = new GLabel(pluginPackage.getName());
GLabel nameLabel = new GLabel(pluginPackage.getName());
nameLabel.setFont(nameLabel.getFont().deriveFont(18f));
nameLabel.setForeground(Color.BLACK);
labelPanel.add(nameLabel);
final HyperlinkComponent configureHyperlink = createConfigureHyperlink();
HyperlinkComponent configureHyperlink = createConfigureHyperlink();
labelPanel.add(configureHyperlink);
labelPanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 40));
@ -182,7 +188,7 @@ public class PluginManagerComponent extends JPanel implements Scrollable {
}
private HyperlinkComponent createConfigureHyperlink() {
final HyperlinkComponent configureHyperlink =
HyperlinkComponent configureHyperlink =
new HyperlinkComponent("<html> <a href=\"Configure\">Configure</a>");
configureHyperlink.addHyperlinkListener("Configure", e -> {
if (e.getEventType() == EventType.ACTIVATED) {
@ -193,14 +199,14 @@ public class PluginManagerComponent extends JPanel implements Scrollable {
return configureHyperlink;
}
private String enchanceDescription(final String text) {
private String enchanceDescription(String text) {
return String.format("<html><body style='width: 300px'>%s</body></html>", text);
}
private void initializeDescriptionSection() {
final String htmlDescription = enchanceDescription(pluginPackage.getDescription());
String htmlDescription = enchanceDescription(pluginPackage.getDescription());
final JLabel descriptionlabel = new GHtmlLabel(htmlDescription);
JLabel descriptionlabel = new GHtmlLabel(htmlDescription);
descriptionlabel.setForeground(Color.GRAY);
descriptionlabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
descriptionlabel.setVerticalAlignment(SwingConstants.TOP);