mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-11 08:07:24 -05:00
Resolves issue with including icons in gradle build product. Updates
all icon handling code to use absolute path for bundled icons.
This commit is contained in:
@@ -29,10 +29,19 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sound.sampled.FloatControl;
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -44,10 +53,8 @@ public class AudioPanel extends JPanel implements Listener<AudioEvent>
|
||||
|
||||
private static final Logger mLog = LoggerFactory.getLogger(AudioPanel.class);
|
||||
|
||||
private static ImageIcon MUTED_ICON = IconManager.getScaledIcon(
|
||||
new ImageIcon("images/audio_muted.png"), 20);
|
||||
private static ImageIcon UNMUTED_ICON = IconManager.getScaledIcon(
|
||||
new ImageIcon("images/audio_unmuted.png"), 20);
|
||||
private static ImageIcon MUTED_ICON = IconManager.getScaledIcon("/images/audio_muted.png", 20);
|
||||
private static ImageIcon UNMUTED_ICON = IconManager.getScaledIcon("/images/audio_unmuted.png", 20);
|
||||
|
||||
private IconManager mIconManager;
|
||||
private SettingsManager mSettingsManager;
|
||||
|
||||
@@ -29,7 +29,7 @@ import io.github.dsheirer.util.ThreadPool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
@@ -519,7 +519,7 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
|
||||
|
||||
if(iconPath != null && mIconManager != null)
|
||||
{
|
||||
return mIconManager.getScaledIcon(new ImageIcon(iconPath), 14);
|
||||
return mIconManager.getScaledIcon(iconPath, 14);
|
||||
}
|
||||
break;
|
||||
case COLUMN_STREAM_NAME:
|
||||
|
||||
@@ -27,7 +27,12 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -227,7 +232,7 @@ public class BroadcastPanel extends JPanel implements ActionListener, ListSelect
|
||||
|
||||
public AddBroadcastConfigurationItem(BroadcastServerType type)
|
||||
{
|
||||
super(type.toString(), mIconManager.getScaledIcon(new ImageIcon(type.getIconPath()), 14));
|
||||
super(type.toString(), mIconManager.getScaledIcon(type.getIconPath(), 14));
|
||||
|
||||
mBroadcastServerType = type;
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ package io.github.dsheirer.audio.broadcast;
|
||||
|
||||
public enum BroadcastServerType
|
||||
{
|
||||
BROADCASTIFY("Broadcastify", "images/broadcastify.png"), //Icecast Server 2.3.2
|
||||
ICECAST_HTTP("Icecast 2 (v2.4+)", "images/icecast.png"),
|
||||
ICECAST_TCP("Icecast (v2.3)", "images/icecast.png"),
|
||||
SHOUTCAST_V1("Shoutcast v1.x", "images/shoutcast.png"),
|
||||
SHOUTCAST_V2("Shoutcast v2.x", "images/shoutcast.png"),
|
||||
BROADCASTIFY("Broadcastify", "/images/broadcastify.png"), //Icecast Server 2.3.2
|
||||
ICECAST_HTTP("Icecast 2 (v2.4+)", "/images/icecast.png"),
|
||||
ICECAST_TCP("Icecast (v2.3)", "/images/icecast.png"),
|
||||
SHOUTCAST_V1("Shoutcast v1.x", "/images/shoutcast.png"),
|
||||
SHOUTCAST_V2("Shoutcast v2.x", "/images/shoutcast.png"),
|
||||
UNKNOWN("Unknown", null);
|
||||
|
||||
private String mLabel;
|
||||
|
||||
@@ -31,10 +31,17 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -74,8 +81,7 @@ public class BroadcastifyConfigurationEditor extends BroadcastConfigurationEdito
|
||||
|
||||
JLabel channelLabel = new JLabel("Broadcastify Stream");
|
||||
|
||||
ImageIcon broadcastifyIcon = mIconManager.getScaledIcon(
|
||||
new ImageIcon(BroadcastServerType.BROADCASTIFY.getIconPath()), 25);
|
||||
ImageIcon broadcastifyIcon = mIconManager.getScaledIcon(BroadcastServerType.BROADCASTIFY.getIconPath(), 25);
|
||||
channelLabel.setIcon(broadcastifyIcon);
|
||||
add(channelLabel, "span, align center");
|
||||
|
||||
|
||||
@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -73,7 +79,7 @@ public class IcecastHTTPConfigurationEditor extends BroadcastConfigurationEditor
|
||||
|
||||
JLabel channelLabel = new JLabel("Icecast 2 (v2.4+) Stream");
|
||||
|
||||
ImageIcon icon = mIconManager.getScaledIcon(new ImageIcon(BroadcastServerType.ICECAST_HTTP.getIconPath()), 25);
|
||||
ImageIcon icon = mIconManager.getScaledIcon(BroadcastServerType.ICECAST_HTTP.getIconPath(), 25);
|
||||
channelLabel.setIcon(icon);
|
||||
|
||||
add(channelLabel, "span, align center");
|
||||
|
||||
@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -72,7 +78,7 @@ public class IcecastTCPConfigurationEditor extends BroadcastConfigurationEditor
|
||||
|
||||
JLabel channelLabel = new JLabel("Icecast (v2.3) Stream");
|
||||
|
||||
ImageIcon icon = mIconManager.getScaledIcon(new ImageIcon(BroadcastServerType.ICECAST_TCP.getIconPath()), 25);
|
||||
ImageIcon icon = mIconManager.getScaledIcon(BroadcastServerType.ICECAST_TCP.getIconPath(), 25);
|
||||
channelLabel.setIcon(icon);
|
||||
|
||||
add(channelLabel, "span, align center");
|
||||
|
||||
@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -71,7 +77,7 @@ public class ShoutcastV1ConfigurationEditor extends BroadcastConfigurationEditor
|
||||
|
||||
JLabel channelLabel = new JLabel("Shoutcast (v1.x) Stream");
|
||||
|
||||
ImageIcon icon = mIconManager.getScaledIcon(new ImageIcon(BroadcastServerType.SHOUTCAST_V1.getIconPath()), 25);
|
||||
ImageIcon icon = mIconManager.getScaledIcon(BroadcastServerType.SHOUTCAST_V1.getIconPath(), 25);
|
||||
channelLabel.setIcon(icon);
|
||||
|
||||
add(channelLabel, "span, align center");
|
||||
|
||||
@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -72,7 +78,7 @@ public class ShoutcastV2ConfigurationEditor extends BroadcastConfigurationEditor
|
||||
|
||||
JLabel channelLabel = new JLabel("Shoutcast (v2) Stream");
|
||||
|
||||
ImageIcon icon = mIconManager.getScaledIcon(new ImageIcon(BroadcastServerType.SHOUTCAST_V2.getIconPath()), 25);
|
||||
ImageIcon icon = mIconManager.getScaledIcon(BroadcastServerType.SHOUTCAST_V2.getIconPath(), 25);
|
||||
channelLabel.setIcon(icon);
|
||||
|
||||
add(channelLabel, "span, align center");
|
||||
|
||||
@@ -24,7 +24,8 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.net.URL;
|
||||
|
||||
@JacksonXmlRootElement(localName = "icon")
|
||||
public class Icon implements Comparable<Icon>
|
||||
@@ -80,7 +81,17 @@ public class Icon implements Comparable<Icon>
|
||||
{
|
||||
try
|
||||
{
|
||||
mImageIcon = new ImageIcon(mPath);
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -25,10 +25,12 @@ import io.github.dsheirer.util.ThreadPool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import java.awt.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -154,7 +156,7 @@ public class IconManager
|
||||
return mResizedIcons.get(scaledIconName);
|
||||
}
|
||||
|
||||
io.github.dsheirer.icon.Icon icon = getModel().getIcon(name);
|
||||
Icon icon = getModel().getIcon(name);
|
||||
|
||||
ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height);
|
||||
mResizedIcons.put(scaledIconName, scaledIcon);
|
||||
@@ -181,6 +183,19 @@ public class IconManager
|
||||
return new ImageIcon(scaledImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an icon and scales it to the specified height
|
||||
* @param path
|
||||
* @param height
|
||||
* @return
|
||||
*/
|
||||
public static ImageIcon getScaledIcon(String path, int height)
|
||||
{
|
||||
Icon icon = new Icon("", path);
|
||||
|
||||
return getScaledIcon(icon.getIcon(), height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Folder where icon, backup and lock files are stored
|
||||
*/
|
||||
@@ -359,26 +374,26 @@ public class IconManager
|
||||
{
|
||||
IconSet iconSet = new IconSet();
|
||||
|
||||
io.github.dsheirer.icon.Icon defaultIcon = new io.github.dsheirer.icon.Icon(IconTableModel.DEFAULT_ICON, "images/no_icon.png");
|
||||
Icon defaultIcon = new Icon(IconTableModel.DEFAULT_ICON, "images/no_icon.png");
|
||||
iconSet.add(defaultIcon);
|
||||
iconSet.setDefaultIcon(defaultIcon.getName());
|
||||
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Ambulance", "images/ambulance.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Block Truck", "images/concrete_block_truck.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("CWID", "images/cwid.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Dispatcher", "images/dispatcher.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Dump Truck", "images/dump_truck_red.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Fire Truck", "images/fire_truck.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Garbage Truck", "images/garbage_truck.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Loader", "images/loader.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Police", "images/police.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Propane Truck", "images/propane_truck.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Rescue Truck", "images/rescue_truck.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("School Bus", "images/school_bus.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Taxi", "images/taxi.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Train", "images/train.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Transport Bus", "images/opt_bus.png"));
|
||||
iconSet.add(new io.github.dsheirer.icon.Icon("Van", "images/van.png"));
|
||||
iconSet.add(new Icon("Ambulance", "images/ambulance.png"));
|
||||
iconSet.add(new Icon("Block Truck", "images/concrete_block_truck.png"));
|
||||
iconSet.add(new Icon("CWID", "images/cwid.png"));
|
||||
iconSet.add(new Icon("Dispatcher", "images/dispatcher.png"));
|
||||
iconSet.add(new Icon("Dump Truck", "images/dump_truck_red.png"));
|
||||
iconSet.add(new Icon("Fire Truck", "images/fire_truck.png"));
|
||||
iconSet.add(new Icon("Garbage Truck", "images/garbage_truck.png"));
|
||||
iconSet.add(new Icon("Loader", "images/loader.png"));
|
||||
iconSet.add(new Icon("Police", "images/police.png"));
|
||||
iconSet.add(new Icon("Propane Truck", "images/propane_truck.png"));
|
||||
iconSet.add(new Icon("Rescue Truck", "images/rescue_truck.png"));
|
||||
iconSet.add(new Icon("School Bus", "images/school_bus.png"));
|
||||
iconSet.add(new Icon("Taxi", "images/taxi.png"));
|
||||
iconSet.add(new Icon("Train", "images/train.png"));
|
||||
iconSet.add(new Icon("Transport Bus", "images/opt_bus.png"));
|
||||
iconSet.add(new Icon("Van", "images/van.png"));
|
||||
|
||||
return iconSet;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -32,10 +32,10 @@ public class IconTableModel extends AbstractTableModel
|
||||
public static final int COLUMN_IMAGE_ICON = 0;
|
||||
public static final int COLUMN_ICON_NAME = 1;
|
||||
|
||||
private io.github.dsheirer.icon.Icon mDefaultIcon;
|
||||
private Icon mDefaultIcon;
|
||||
|
||||
private Map<String,io.github.dsheirer.icon.Icon> mIconMap = new HashMap<>();
|
||||
private List<io.github.dsheirer.icon.Icon> mIcons = new ArrayList<>();
|
||||
private Map<String,Icon> mIconMap = new HashMap<>();
|
||||
private List<Icon> mIcons = new ArrayList<>();
|
||||
|
||||
public IconTableModel()
|
||||
{
|
||||
@@ -49,7 +49,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
|
||||
fireTableDataChanged();
|
||||
|
||||
for(io.github.dsheirer.icon.Icon icon: iconSet.getIcons())
|
||||
for(Icon icon: iconSet.getIcons())
|
||||
{
|
||||
add(icon);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
/**
|
||||
* Adds the icon to the model
|
||||
*/
|
||||
public void add(io.github.dsheirer.icon.Icon icon)
|
||||
public void add(Icon icon)
|
||||
{
|
||||
if(icon != null)
|
||||
{
|
||||
@@ -75,7 +75,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
/**
|
||||
* Removes the icon from the model
|
||||
*/
|
||||
public void remove(io.github.dsheirer.icon.Icon icon)
|
||||
public void remove(Icon icon)
|
||||
{
|
||||
if(icon != null && mIcons.contains(icon))
|
||||
{
|
||||
@@ -89,7 +89,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
|
||||
}
|
||||
|
||||
public io.github.dsheirer.icon.Icon get(int row)
|
||||
public Icon get(int row)
|
||||
{
|
||||
if(row < mIcons.size())
|
||||
{
|
||||
@@ -116,7 +116,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
{
|
||||
if(rowIndex < mIcons.size() && columnIndex < getColumnCount())
|
||||
{
|
||||
io.github.dsheirer.icon.Icon icon = get(rowIndex);
|
||||
Icon icon = get(rowIndex);
|
||||
|
||||
switch(columnIndex)
|
||||
{
|
||||
@@ -162,19 +162,19 @@ public class IconTableModel extends AbstractTableModel
|
||||
/**
|
||||
* Icons in an array - suitable for use in a JComboBox
|
||||
*/
|
||||
public io.github.dsheirer.icon.Icon[] getIconsAsArray()
|
||||
public Icon[] getIconsAsArray()
|
||||
{
|
||||
List<io.github.dsheirer.icon.Icon> icons = new ArrayList<>(mIconMap.values());
|
||||
List<Icon> icons = new ArrayList<>(mIconMap.values());
|
||||
|
||||
Collections.sort(icons);
|
||||
|
||||
return icons.toArray(new io.github.dsheirer.icon.Icon[icons.size()]);
|
||||
return icons.toArray(new Icon[icons.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current default icon
|
||||
*/
|
||||
public io.github.dsheirer.icon.Icon getDefaultIcon()
|
||||
public Icon getDefaultIcon()
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
/**
|
||||
* Indicates if the icon argument is the current default icon
|
||||
*/
|
||||
public boolean isDefaultIcon(io.github.dsheirer.icon.Icon icon)
|
||||
public boolean isDefaultIcon(Icon icon)
|
||||
{
|
||||
return icon == getDefaultIcon();
|
||||
}
|
||||
@@ -198,7 +198,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
return name != null && !name.isEmpty() && mIconMap.containsKey(name);
|
||||
}
|
||||
|
||||
public void setDefaultIcon(io.github.dsheirer.icon.Icon icon)
|
||||
public void setDefaultIcon(Icon icon)
|
||||
{
|
||||
if(icon != null)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
name = DEFAULT_ICON;
|
||||
}
|
||||
|
||||
io.github.dsheirer.icon.Icon defaultIcon = mIconMap.get(name);
|
||||
Icon defaultIcon = mIconMap.get(name);
|
||||
|
||||
if(defaultIcon != null)
|
||||
{
|
||||
@@ -231,7 +231,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultIcon = new io.github.dsheirer.icon.Icon(DEFAULT_ICON, "images/no_icon.png");
|
||||
defaultIcon = new Icon(DEFAULT_ICON, "images/no_icon.png");
|
||||
add(defaultIcon);
|
||||
setDefaultIcon(defaultIcon);
|
||||
}
|
||||
@@ -240,14 +240,14 @@ public class IconTableModel extends AbstractTableModel
|
||||
/**
|
||||
* Returns the named icon or the default icon if the named icon does not exist
|
||||
*/
|
||||
public io.github.dsheirer.icon.Icon getIcon(String name)
|
||||
public Icon getIcon(String name)
|
||||
{
|
||||
if(name == null || name.isEmpty())
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
|
||||
io.github.dsheirer.icon.Icon icon = mIconMap.get(name);
|
||||
Icon icon = mIconMap.get(name);
|
||||
|
||||
if(icon == null)
|
||||
{
|
||||
@@ -263,7 +263,7 @@ public class IconTableModel extends AbstractTableModel
|
||||
public IconSet getIconSet()
|
||||
{
|
||||
IconSet iconSet = new IconSet();
|
||||
iconSet.setIcons(new ArrayList<io.github.dsheirer.icon.Icon>(mIconMap.values()));
|
||||
iconSet.setIcons(new ArrayList<Icon>(mIconMap.values()));
|
||||
iconSet.setDefaultIcon(getDefaultIcon().getName());
|
||||
return iconSet;
|
||||
}
|
||||
|
||||
@@ -19,14 +19,20 @@ package io.github.dsheirer.map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import io.github.dsheirer.icon.Icon;
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
import io.github.dsheirer.settings.SettingType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.Image;
|
||||
import java.net.URL;
|
||||
|
||||
public class MapIcon extends Setting implements Comparable<MapIcon>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(MapIcon.class);
|
||||
|
||||
private static final int sMAX_IMAGE_DIMENSION = 48;
|
||||
private String mPath;
|
||||
private ImageIcon mImageIcon;
|
||||
@@ -100,42 +106,58 @@ public class MapIcon extends Setting implements Comparable<MapIcon>
|
||||
@JsonIgnore
|
||||
public ImageIcon getImageIcon()
|
||||
{
|
||||
if(mImageIcon == null)
|
||||
if(mImageIcon == null && mPath != null)
|
||||
{
|
||||
mImageIcon = new ImageIcon(mPath);
|
||||
|
||||
/**
|
||||
* If the image is too big, scale it down to max pixel size squared
|
||||
*/
|
||||
if(mImageIcon.getIconWidth() > sMAX_IMAGE_DIMENSION ||
|
||||
mImageIcon.getIconHeight() > sMAX_IMAGE_DIMENSION)
|
||||
try
|
||||
{
|
||||
/**
|
||||
* getScaled instance will correct any negative value to the
|
||||
* correct value, maintaining original aspect ratio. So, we
|
||||
* only scale the larger value, and allow the image class to
|
||||
* determine the correct value for the other measurement
|
||||
*/
|
||||
int height = -1;
|
||||
int width = -1;
|
||||
URL imageURL = Icon.class.getResource(mPath);
|
||||
|
||||
/**
|
||||
* Use the larger width or height value to determine the
|
||||
* scaling factor
|
||||
*/
|
||||
if(mImageIcon.getIconHeight() > mImageIcon.getIconWidth())
|
||||
if(imageURL == null && !mPath.startsWith("/"))
|
||||
{
|
||||
height = sMAX_IMAGE_DIMENSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = sMAX_IMAGE_DIMENSION;
|
||||
imageURL = (Icon.class.getResource("/" + mPath));
|
||||
}
|
||||
|
||||
mImageIcon = new ImageIcon(mImageIcon.getImage()
|
||||
.getScaledInstance(width, height, Image.SCALE_SMOOTH));
|
||||
if(imageURL != null)
|
||||
{
|
||||
mImageIcon = new ImageIcon(imageURL);
|
||||
|
||||
/**
|
||||
* If the image is too big, scale it down to max pixel size squared
|
||||
*/
|
||||
if(mImageIcon.getIconWidth() > sMAX_IMAGE_DIMENSION ||
|
||||
mImageIcon.getIconHeight() > sMAX_IMAGE_DIMENSION)
|
||||
{
|
||||
/**
|
||||
* getScaled instance will correct any negative value to the
|
||||
* correct value, maintaining original aspect ratio. So, we
|
||||
* only scale the larger value, and allow the image class to
|
||||
* determine the correct value for the other measurement
|
||||
*/
|
||||
int height = -1;
|
||||
int width = -1;
|
||||
|
||||
/**
|
||||
* Use the larger width or height value to determine the
|
||||
* scaling factor
|
||||
*/
|
||||
if(mImageIcon.getIconHeight() > mImageIcon.getIconWidth())
|
||||
{
|
||||
height = sMAX_IMAGE_DIMENSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = sMAX_IMAGE_DIMENSION;
|
||||
}
|
||||
|
||||
mImageIcon = new ImageIcon(mImageIcon.getImage()
|
||||
.getScaledInstance(width, height, Image.SCALE_SMOOTH));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Error loading Icon [" + mPath + "]", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mImageIcon;
|
||||
|
||||
@@ -20,14 +20,22 @@ import org.jdesktop.swingx.painter.Painter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.DesignMode;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -117,8 +125,13 @@ public class JXMapViewer extends JPanel implements DesignMode
|
||||
// make a dummy loading image
|
||||
try
|
||||
{
|
||||
ImageIcon imageIcon = new ImageIcon( "images/loading.png" );
|
||||
this.setLoadingImage( imageIcon.getImage() );
|
||||
URL imageURL = JXMapViewer.class.getResource("/images/loading.png");
|
||||
|
||||
if(imageURL != null)
|
||||
{
|
||||
ImageIcon imageIcon = new ImageIcon( imageURL );
|
||||
this.setLoadingImage( imageIcon.getImage() );
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user