mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Resolves issues with NPE handling and loading external icons.
This commit is contained in:
@@ -81,16 +81,23 @@ public class Icon implements Comparable<Icon>
|
||||
{
|
||||
try
|
||||
{
|
||||
URL imageURL = Icon.class.getResource(mPath);
|
||||
|
||||
if(imageURL == null && !mPath.startsWith("/"))
|
||||
if(mPath.startsWith("/"))
|
||||
{
|
||||
imageURL = (Icon.class.getResource("/" + mPath));
|
||||
mImageIcon = new ImageIcon(mPath);
|
||||
}
|
||||
|
||||
if(imageURL != null)
|
||||
else
|
||||
{
|
||||
mImageIcon = new ImageIcon(imageURL);
|
||||
URL imageURL = Icon.class.getResource(mPath);
|
||||
|
||||
if(imageURL == null && !mPath.startsWith("/"))
|
||||
{
|
||||
imageURL = (Icon.class.getResource("/" + mPath));
|
||||
}
|
||||
|
||||
if(imageURL != null)
|
||||
{
|
||||
mImageIcon = new ImageIcon(imageURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
|
||||
@@ -129,7 +129,7 @@ public class IconManager
|
||||
/**
|
||||
* All icons in a sorted array
|
||||
*/
|
||||
public io.github.dsheirer.icon.Icon[] getIcons()
|
||||
public Icon[] getIcons()
|
||||
{
|
||||
return getModel().getIconsAsArray();
|
||||
}
|
||||
@@ -159,7 +159,11 @@ public class IconManager
|
||||
Icon icon = getModel().getIcon(name);
|
||||
|
||||
ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height);
|
||||
mResizedIcons.put(scaledIconName, scaledIcon);
|
||||
|
||||
if(scaledIcon != null)
|
||||
{
|
||||
mResizedIcons.put(scaledIconName, scaledIcon);
|
||||
}
|
||||
|
||||
return scaledIcon;
|
||||
}
|
||||
@@ -173,14 +177,19 @@ public class IconManager
|
||||
*/
|
||||
public static ImageIcon getScaledIcon(ImageIcon original, int height)
|
||||
{
|
||||
double scale = (double) original.getIconHeight() / (double) height;
|
||||
if(original != null)
|
||||
{
|
||||
double scale = (double) original.getIconHeight() / (double) height;
|
||||
|
||||
int scaledWidth = (int) ((double) original.getIconWidth() / scale);
|
||||
int scaledWidth = (int) ((double) original.getIconWidth() / scale);
|
||||
|
||||
Image scaledImage = original.getImage().getScaledInstance(scaledWidth,
|
||||
height, java.awt.Image.SCALE_SMOOTH);
|
||||
Image scaledImage = original.getImage().getScaledInstance(scaledWidth,
|
||||
height, java.awt.Image.SCALE_SMOOTH);
|
||||
|
||||
return new ImageIcon(scaledImage);
|
||||
return new ImageIcon(scaledImage);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,9 +200,14 @@ public class IconManager
|
||||
*/
|
||||
public static ImageIcon getScaledIcon(String path, int height)
|
||||
{
|
||||
Icon icon = new Icon("", path);
|
||||
if(path != null)
|
||||
{
|
||||
Icon icon = new Icon("", path);
|
||||
|
||||
return getScaledIcon(icon.getIcon(), height);
|
||||
return getScaledIcon(icon.getIcon(), height);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,10 +20,16 @@ package io.github.dsheirer.icon;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
@@ -119,7 +125,7 @@ public class IconSelector extends JDialog implements DocumentListener
|
||||
String name = mNameText.getText();
|
||||
String path = mFileLabel.getText();
|
||||
|
||||
io.github.dsheirer.icon.Icon icon = new io.github.dsheirer.icon.Icon(name, path);
|
||||
Icon icon = new Icon(name, path);
|
||||
mIconTableModel.add(icon);
|
||||
|
||||
IconSelector.this.dispose();
|
||||
|
||||
Reference in New Issue
Block a user