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:
Denny
2017-12-26 07:13:15 -05:00
parent 42aec490bd
commit 3d9044802e
61 changed files with 211 additions and 108 deletions

View File

@@ -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;