Compare commits

...

7 Commits

Author SHA1 Message Date
Denny
336669f1d5 Updates build version to 0.3.3 beta 3 2018-01-01 07:26:42 -05:00
Denny Sheirer
46cf7f4193 Merge pull request #309 from DSheirer/308-icon-manager-npe
308 IconManager throws NPE when loading external icons
2018-01-01 07:25:29 -05:00
Denny
e9aeb09011 Resolves issues with NPE handling and loading external icons. 2018-01-01 07:24:37 -05:00
Denny
c7f00ea124 Updates version to 0.3.3 beta 2 2017-12-26 07:19:06 -05:00
Denny Sheirer
1759f4a804 Merge pull request #306 from DSheirer/305-gradle-icons-missing
305 Icons missing from gradle build
2017-12-26 07:17:12 -05:00
Denny
3d9044802e Resolves issue with including icons in gradle build product. Updates
all icon handling code to use absolute path for bundled icons.
2017-12-26 07:13:15 -05:00
Denny
42aec490bd Updates build version and changelog. 2017-12-25 07:42:56 -05:00
64 changed files with 251 additions and 120 deletions

View File

@@ -1,5 +1,6 @@
0.4.0 ........ (in progress) 0.3.3 20171225
- Changes build system from ant to gradle. Thanks to: Roman Tsypuk https://github.com/tsypuk - Changes build system from ant to gradle. Thanks to: Roman Tsypuk https://github.com/tsypuk
- Adds LIST and ID3 metadata to wav audio recordings
0.3.2 20171105 0.3.2 20171105
- Resolves issue with tuner frequency adjustments that was causing channel processing - Resolves issue with tuner frequency adjustments that was causing channel processing

View File

@@ -15,7 +15,7 @@ repositories {
mavenCentral() mavenCentral()
} }
version = '0.3.2' version = '0.3.3-beta.3'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
sourceSets { sourceSets {

View File

@@ -29,10 +29,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.sound.sampled.FloatControl; 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.ChangeEvent;
import javax.swing.event.ChangeListener; 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.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseEvent; 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 final Logger mLog = LoggerFactory.getLogger(AudioPanel.class);
private static ImageIcon MUTED_ICON = IconManager.getScaledIcon( private static ImageIcon MUTED_ICON = IconManager.getScaledIcon("/images/audio_muted.png", 20);
new ImageIcon("images/audio_muted.png"), 20); private static ImageIcon UNMUTED_ICON = IconManager.getScaledIcon("/images/audio_unmuted.png", 20);
private static ImageIcon UNMUTED_ICON = IconManager.getScaledIcon(
new ImageIcon("images/audio_unmuted.png"), 20);
private IconManager mIconManager; private IconManager mIconManager;
private SettingsManager mSettingsManager; private SettingsManager mSettingsManager;

View File

@@ -29,7 +29,7 @@ import io.github.dsheirer.util.ThreadPool;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import java.io.IOException; import java.io.IOException;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
@@ -519,7 +519,7 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
if(iconPath != null && mIconManager != null) if(iconPath != null && mIconManager != null)
{ {
return mIconManager.getScaledIcon(new ImageIcon(iconPath), 14); return mIconManager.getScaledIcon(iconPath, 14);
} }
break; break;
case COLUMN_STREAM_NAME: case COLUMN_STREAM_NAME:

View File

@@ -27,7 +27,12 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@@ -227,7 +232,7 @@ public class BroadcastPanel extends JPanel implements ActionListener, ListSelect
public AddBroadcastConfigurationItem(BroadcastServerType type) public AddBroadcastConfigurationItem(BroadcastServerType type)
{ {
super(type.toString(), mIconManager.getScaledIcon(new ImageIcon(type.getIconPath()), 14)); super(type.toString(), mIconManager.getScaledIcon(type.getIconPath(), 14));
mBroadcastServerType = type; mBroadcastServerType = type;

View File

@@ -20,11 +20,11 @@ package io.github.dsheirer.audio.broadcast;
public enum BroadcastServerType public enum BroadcastServerType
{ {
BROADCASTIFY("Broadcastify", "images/broadcastify.png"), //Icecast Server 2.3.2 BROADCASTIFY("Broadcastify", "/images/broadcastify.png"), //Icecast Server 2.3.2
ICECAST_HTTP("Icecast 2 (v2.4+)", "images/icecast.png"), ICECAST_HTTP("Icecast 2 (v2.4+)", "/images/icecast.png"),
ICECAST_TCP("Icecast (v2.3)", "images/icecast.png"), ICECAST_TCP("Icecast (v2.3)", "/images/icecast.png"),
SHOUTCAST_V1("Shoutcast v1.x", "images/shoutcast.png"), SHOUTCAST_V1("Shoutcast v1.x", "/images/shoutcast.png"),
SHOUTCAST_V2("Shoutcast v2.x", "images/shoutcast.png"), SHOUTCAST_V2("Shoutcast v2.x", "/images/shoutcast.png"),
UNKNOWN("Unknown", null); UNKNOWN("Unknown", null);
private String mLabel; private String mLabel;

View File

@@ -31,10 +31,17 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ChangeEvent;
import javax.swing.event.ChangeListener; 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.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -74,8 +81,7 @@ public class BroadcastifyConfigurationEditor extends BroadcastConfigurationEdito
JLabel channelLabel = new JLabel("Broadcastify Stream"); JLabel channelLabel = new JLabel("Broadcastify Stream");
ImageIcon broadcastifyIcon = mIconManager.getScaledIcon( ImageIcon broadcastifyIcon = mIconManager.getScaledIcon(BroadcastServerType.BROADCASTIFY.getIconPath(), 25);
new ImageIcon(BroadcastServerType.BROADCASTIFY.getIconPath()), 25);
channelLabel.setIcon(broadcastifyIcon); channelLabel.setIcon(broadcastifyIcon);
add(channelLabel, "span, align center"); add(channelLabel, "span, align center");

View File

@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.*; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -73,7 +79,7 @@ public class IcecastHTTPConfigurationEditor extends BroadcastConfigurationEditor
JLabel channelLabel = new JLabel("Icecast 2 (v2.4+) Stream"); 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); channelLabel.setIcon(icon);
add(channelLabel, "span, align center"); add(channelLabel, "span, align center");

View File

@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.*; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -72,7 +78,7 @@ public class IcecastTCPConfigurationEditor extends BroadcastConfigurationEditor
JLabel channelLabel = new JLabel("Icecast (v2.3) Stream"); 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); channelLabel.setIcon(icon);
add(channelLabel, "span, align center"); add(channelLabel, "span, align center");

View File

@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.*; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -71,7 +77,7 @@ public class ShoutcastV1ConfigurationEditor extends BroadcastConfigurationEditor
JLabel channelLabel = new JLabel("Shoutcast (v1.x) Stream"); 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); channelLabel.setIcon(icon);
add(channelLabel, "span, align center"); add(channelLabel, "span, align center");

View File

@@ -29,10 +29,16 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.*; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -72,7 +78,7 @@ public class ShoutcastV2ConfigurationEditor extends BroadcastConfigurationEditor
JLabel channelLabel = new JLabel("Shoutcast (v2) Stream"); 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); channelLabel.setIcon(icon);
add(channelLabel, "span, align center"); add(channelLabel, "span, align center");

View File

@@ -24,7 +24,8 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.ImageIcon;
import java.net.URL;
@JacksonXmlRootElement(localName = "icon") @JacksonXmlRootElement(localName = "icon")
public class Icon implements Comparable<Icon> public class Icon implements Comparable<Icon>
@@ -80,7 +81,24 @@ public class Icon implements Comparable<Icon>
{ {
try try
{ {
mImageIcon = new ImageIcon(mPath); if(mPath.startsWith("/"))
{
mImageIcon = new ImageIcon(mPath);
}
else
{
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) catch(Exception e)
{ {

View File

@@ -25,10 +25,12 @@ import io.github.dsheirer.util.ThreadPool;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.ImageIcon;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@@ -127,7 +129,7 @@ public class IconManager
/** /**
* All icons in a sorted array * All icons in a sorted array
*/ */
public io.github.dsheirer.icon.Icon[] getIcons() public Icon[] getIcons()
{ {
return getModel().getIconsAsArray(); return getModel().getIconsAsArray();
} }
@@ -154,10 +156,14 @@ public class IconManager
return mResizedIcons.get(scaledIconName); return mResizedIcons.get(scaledIconName);
} }
io.github.dsheirer.icon.Icon icon = getModel().getIcon(name); Icon icon = getModel().getIcon(name);
ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height); ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height);
mResizedIcons.put(scaledIconName, scaledIcon);
if(scaledIcon != null)
{
mResizedIcons.put(scaledIconName, scaledIcon);
}
return scaledIcon; return scaledIcon;
} }
@@ -171,14 +177,37 @@ public class IconManager
*/ */
public static ImageIcon getScaledIcon(ImageIcon original, int height) 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, Image scaledImage = original.getImage().getScaledInstance(scaledWidth,
height, java.awt.Image.SCALE_SMOOTH); height, java.awt.Image.SCALE_SMOOTH);
return new ImageIcon(scaledImage); return new ImageIcon(scaledImage);
}
return null;
}
/**
* Constructs an icon and scales it to the specified height
* @param path
* @param height
* @return
*/
public static ImageIcon getScaledIcon(String path, int height)
{
if(path != null)
{
Icon icon = new Icon("", path);
return getScaledIcon(icon.getIcon(), height);
}
return null;
} }
/** /**
@@ -359,26 +388,26 @@ public class IconManager
{ {
IconSet iconSet = new IconSet(); 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.add(defaultIcon);
iconSet.setDefaultIcon(defaultIcon.getName()); iconSet.setDefaultIcon(defaultIcon.getName());
iconSet.add(new io.github.dsheirer.icon.Icon("Ambulance", "images/ambulance.png")); iconSet.add(new Icon("Ambulance", "images/ambulance.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Block Truck", "images/concrete_block_truck.png")); iconSet.add(new Icon("Block Truck", "images/concrete_block_truck.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("CWID", "images/cwid.png")); iconSet.add(new Icon("CWID", "images/cwid.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Dispatcher", "images/dispatcher.png")); iconSet.add(new Icon("Dispatcher", "images/dispatcher.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Dump Truck", "images/dump_truck_red.png")); iconSet.add(new 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 Icon("Fire Truck", "images/fire_truck.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Garbage Truck", "images/garbage_truck.png")); iconSet.add(new Icon("Garbage Truck", "images/garbage_truck.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Loader", "images/loader.png")); iconSet.add(new Icon("Loader", "images/loader.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Police", "images/police.png")); iconSet.add(new Icon("Police", "images/police.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Propane Truck", "images/propane_truck.png")); iconSet.add(new Icon("Propane Truck", "images/propane_truck.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Rescue Truck", "images/rescue_truck.png")); iconSet.add(new Icon("Rescue Truck", "images/rescue_truck.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("School Bus", "images/school_bus.png")); iconSet.add(new Icon("School Bus", "images/school_bus.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Taxi", "images/taxi.png")); iconSet.add(new Icon("Taxi", "images/taxi.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Train", "images/train.png")); iconSet.add(new Icon("Train", "images/train.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Transport Bus", "images/opt_bus.png")); iconSet.add(new Icon("Transport Bus", "images/opt_bus.png"));
iconSet.add(new io.github.dsheirer.icon.Icon("Van", "images/van.png")); iconSet.add(new Icon("Van", "images/van.png"));
return iconSet; return iconSet;
} }

View File

@@ -20,10 +20,16 @@ package io.github.dsheirer.icon;
import net.miginfocom.swing.MigLayout; 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.DocumentEvent;
import javax.swing.event.DocumentListener; 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.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
@@ -119,7 +125,7 @@ public class IconSelector extends JDialog implements DocumentListener
String name = mNameText.getText(); String name = mNameText.getText();
String path = mFileLabel.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); mIconTableModel.add(icon);
IconSelector.this.dispose(); IconSelector.this.dispose();

View File

@@ -18,7 +18,7 @@
******************************************************************************/ ******************************************************************************/
package io.github.dsheirer.icon; package io.github.dsheirer.icon;
import javax.swing.*; import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; 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_IMAGE_ICON = 0;
public static final int COLUMN_ICON_NAME = 1; 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 Map<String,Icon> mIconMap = new HashMap<>();
private List<io.github.dsheirer.icon.Icon> mIcons = new ArrayList<>(); private List<Icon> mIcons = new ArrayList<>();
public IconTableModel() public IconTableModel()
{ {
@@ -49,7 +49,7 @@ public class IconTableModel extends AbstractTableModel
fireTableDataChanged(); fireTableDataChanged();
for(io.github.dsheirer.icon.Icon icon: iconSet.getIcons()) for(Icon icon: iconSet.getIcons())
{ {
add(icon); add(icon);
} }
@@ -60,7 +60,7 @@ public class IconTableModel extends AbstractTableModel
/** /**
* Adds the icon to the model * Adds the icon to the model
*/ */
public void add(io.github.dsheirer.icon.Icon icon) public void add(Icon icon)
{ {
if(icon != null) if(icon != null)
{ {
@@ -75,7 +75,7 @@ public class IconTableModel extends AbstractTableModel
/** /**
* Removes the icon from the model * 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)) 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()) if(row < mIcons.size())
{ {
@@ -116,7 +116,7 @@ public class IconTableModel extends AbstractTableModel
{ {
if(rowIndex < mIcons.size() && columnIndex < getColumnCount()) if(rowIndex < mIcons.size() && columnIndex < getColumnCount())
{ {
io.github.dsheirer.icon.Icon icon = get(rowIndex); Icon icon = get(rowIndex);
switch(columnIndex) switch(columnIndex)
{ {
@@ -162,19 +162,19 @@ public class IconTableModel extends AbstractTableModel
/** /**
* Icons in an array - suitable for use in a JComboBox * 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); 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 * Returns the current default icon
*/ */
public io.github.dsheirer.icon.Icon getDefaultIcon() public Icon getDefaultIcon()
{ {
return mDefaultIcon; return mDefaultIcon;
} }
@@ -182,7 +182,7 @@ public class IconTableModel extends AbstractTableModel
/** /**
* Indicates if the icon argument is the current default icon * 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(); return icon == getDefaultIcon();
} }
@@ -198,7 +198,7 @@ public class IconTableModel extends AbstractTableModel
return name != null && !name.isEmpty() && mIconMap.containsKey(name); 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) if(icon != null)
{ {
@@ -223,7 +223,7 @@ public class IconTableModel extends AbstractTableModel
name = DEFAULT_ICON; name = DEFAULT_ICON;
} }
io.github.dsheirer.icon.Icon defaultIcon = mIconMap.get(name); Icon defaultIcon = mIconMap.get(name);
if(defaultIcon != null) if(defaultIcon != null)
{ {
@@ -231,7 +231,7 @@ public class IconTableModel extends AbstractTableModel
} }
else 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); add(defaultIcon);
setDefaultIcon(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 * 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()) if(name == null || name.isEmpty())
{ {
return mDefaultIcon; return mDefaultIcon;
} }
io.github.dsheirer.icon.Icon icon = mIconMap.get(name); Icon icon = mIconMap.get(name);
if(icon == null) if(icon == null)
{ {
@@ -263,7 +263,7 @@ public class IconTableModel extends AbstractTableModel
public IconSet getIconSet() public IconSet getIconSet()
{ {
IconSet iconSet = new IconSet(); 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()); iconSet.setDefaultIcon(getDefaultIcon().getName());
return iconSet; return iconSet;
} }

View File

@@ -19,14 +19,20 @@ package io.github.dsheirer.map;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; 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.Setting;
import io.github.dsheirer.settings.SettingType; import io.github.dsheirer.settings.SettingType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.ImageIcon;
import java.awt.*; import java.awt.Image;
import java.net.URL;
public class MapIcon extends Setting implements Comparable<MapIcon> 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 static final int sMAX_IMAGE_DIMENSION = 48;
private String mPath; private String mPath;
private ImageIcon mImageIcon; private ImageIcon mImageIcon;
@@ -100,42 +106,58 @@ public class MapIcon extends Setting implements Comparable<MapIcon>
@JsonIgnore @JsonIgnore
public ImageIcon getImageIcon() public ImageIcon getImageIcon()
{ {
if(mImageIcon == null) if(mImageIcon == null && mPath != null)
{ {
mImageIcon = new ImageIcon(mPath); try
/**
* 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)
{ {
/** URL imageURL = Icon.class.getResource(mPath);
* 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;
/** if(imageURL == null && !mPath.startsWith("/"))
* Use the larger width or height value to determine the
* scaling factor
*/
if(mImageIcon.getIconHeight() > mImageIcon.getIconWidth())
{ {
height = sMAX_IMAGE_DIMENSION; imageURL = (Icon.class.getResource("/" + mPath));
}
else
{
width = sMAX_IMAGE_DIMENSION;
} }
mImageIcon = new ImageIcon(mImageIcon.getImage() if(imageURL != null)
.getScaledInstance(width, height, Image.SCALE_SMOOTH)); {
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; return mImageIcon;

View File

@@ -20,14 +20,22 @@ import org.jdesktop.swingx.painter.Painter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.ImageIcon;
import java.awt.*; 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.Point2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.beans.DesignMode; import java.beans.DesignMode;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.net.URL;
import java.util.Set; import java.util.Set;
/** /**
@@ -117,8 +125,13 @@ public class JXMapViewer extends JPanel implements DesignMode
// make a dummy loading image // make a dummy loading image
try try
{ {
ImageIcon imageIcon = new ImageIcon( "images/loading.png" ); URL imageURL = JXMapViewer.class.getResource("/images/loading.png");
this.setLoadingImage( imageIcon.getImage() );
if(imageURL != null)
{
ImageIcon imageIcon = new ImageIcon( imageURL );
this.setLoadingImage( imageIcon.getImage() );
}
} }
catch (Throwable ex) catch (Throwable ex)
{ {

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 90 KiB

View File

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 152 B

View File

Before

Width:  |  Height:  |  Size: 498 B

After

Width:  |  Height:  |  Size: 498 B

View File

Before

Width:  |  Height:  |  Size: 522 B

After

Width:  |  Height:  |  Size: 522 B

View File

Before

Width:  |  Height:  |  Size: 495 B

After

Width:  |  Height:  |  Size: 495 B

View File

Before

Width:  |  Height:  |  Size: 456 B

After

Width:  |  Height:  |  Size: 456 B

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 504 B

After

Width:  |  Height:  |  Size: 504 B

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 592 B

After

Width:  |  Height:  |  Size: 592 B

View File

Before

Width:  |  Height:  |  Size: 403 B

After

Width:  |  Height:  |  Size: 403 B

View File

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 654 B

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 520 B

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

View File

Before

Width:  |  Height:  |  Size: 378 B

After

Width:  |  Height:  |  Size: 378 B

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View File

Before

Width:  |  Height:  |  Size: 413 B

After

Width:  |  Height:  |  Size: 413 B

View File

Before

Width:  |  Height:  |  Size: 405 B

After

Width:  |  Height:  |  Size: 405 B

View File

Before

Width:  |  Height:  |  Size: 435 B

After

Width:  |  Height:  |  Size: 435 B

View File

Before

Width:  |  Height:  |  Size: 743 B

After

Width:  |  Height:  |  Size: 743 B

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 470 B

After

Width:  |  Height:  |  Size: 470 B

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 493 B

After

Width:  |  Height:  |  Size: 493 B

View File

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 462 B

View File

Before

Width:  |  Height:  |  Size: 443 B

After

Width:  |  Height:  |  Size: 443 B

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 460 B

After

Width:  |  Height:  |  Size: 460 B

View File

Before

Width:  |  Height:  |  Size: 644 B

After

Width:  |  Height:  |  Size: 644 B

View File

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB