mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 00:57:31 -05:00
#778 Updates Icon Manager to JavaFX. Resolves issue with displaying custom icons in alias editor. (#796)
Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2020 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -14,64 +14,154 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.util.Callback;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
|
||||
@JacksonXmlRootElement(localName = "icon")
|
||||
public class Icon implements Comparable<Icon>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(Icon.class);
|
||||
|
||||
protected String mName;
|
||||
private String mPath;
|
||||
private StringProperty mName = new SimpleStringProperty();
|
||||
private StringProperty mPath = new SimpleStringProperty();
|
||||
private BooleanProperty mDefaultIcon = new SimpleBooleanProperty();
|
||||
private BooleanProperty mStandardIcon = new SimpleBooleanProperty();
|
||||
private ImageIcon mImageIcon;
|
||||
|
||||
/**
|
||||
* JAXB constructor - do not use
|
||||
*/
|
||||
public Icon()
|
||||
{
|
||||
//No-arg JAXB constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param name for the icon
|
||||
* @param path to the icon
|
||||
*/
|
||||
public Icon(String name, String path)
|
||||
{
|
||||
mName = name;
|
||||
mPath = path;
|
||||
setName(name);
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "name")
|
||||
public String getName()
|
||||
@JsonIgnore
|
||||
public StringProperty nameProperty()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "path")
|
||||
public String getPath()
|
||||
@JsonIgnore
|
||||
public StringProperty pathProperty()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public BooleanProperty defaultIconProperty()
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public BooleanProperty standardIconProperty()
|
||||
{
|
||||
return mStandardIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the icon
|
||||
*/
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "name")
|
||||
public String getName()
|
||||
{
|
||||
return mName.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the icon
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
mName.set(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this is a standard icon
|
||||
*/
|
||||
@JsonIgnore
|
||||
public boolean getStandardIcon()
|
||||
{
|
||||
return mStandardIcon.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or flags this icon as a standard icon indicating that it should not be deleted
|
||||
*/
|
||||
void setStandardIcon(boolean standardIcon)
|
||||
{
|
||||
mStandardIcon.set(standardIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this icon is the default icon
|
||||
*/
|
||||
@JsonIgnore
|
||||
public boolean getDefaultIcon()
|
||||
{
|
||||
return mDefaultIcon.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default icon state.
|
||||
*
|
||||
* Note: uniqueness of default flag is only enforced through the icon model and package private access
|
||||
*/
|
||||
void setDefaultIcon(boolean defaultIcon)
|
||||
{
|
||||
mDefaultIcon.set(defaultIcon);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to the icon
|
||||
*/
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "path")
|
||||
public String getPath()
|
||||
{
|
||||
return mPath.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the icon
|
||||
*/
|
||||
public void setPath(String path)
|
||||
{
|
||||
mPath = path;
|
||||
mPath.set(path);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@@ -81,17 +171,17 @@ public class Icon implements Comparable<Icon>
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!mPath.startsWith("images"))
|
||||
if(!getPath().startsWith("images"))
|
||||
{
|
||||
mImageIcon = new ImageIcon(mPath);
|
||||
mImageIcon = new ImageIcon(getPath());
|
||||
}
|
||||
else
|
||||
{
|
||||
URL imageURL = Icon.class.getResource(mPath);
|
||||
URL imageURL = Icon.class.getResource(getPath());
|
||||
|
||||
if(imageURL == null && !mPath.startsWith("/"))
|
||||
if(imageURL == null && !getPath().startsWith("/"))
|
||||
{
|
||||
imageURL = (Icon.class.getResource("/" + mPath));
|
||||
imageURL = (Icon.class.getResource("/" + getPath()));
|
||||
}
|
||||
|
||||
if(imageURL != null)
|
||||
@@ -102,7 +192,7 @@ public class Icon implements Comparable<Icon>
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Error loading Icon [" + mPath + "]", e);
|
||||
mLog.error("Error loading Icon [" + getPath() + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +200,52 @@ public class Icon implements Comparable<Icon>
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Icon otherIcon)
|
||||
public int compareTo(Icon other)
|
||||
{
|
||||
return getName().compareTo(otherIcon.getName());
|
||||
if(other == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if(hashCode() == other.hashCode())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(getName() != null && other.getName() != null)
|
||||
{
|
||||
if(getName().contentEquals(other.getName()))
|
||||
{
|
||||
if(getPath() != null && other.getPath() != null)
|
||||
{
|
||||
return getPath().compareTo(other.getPath());
|
||||
}
|
||||
else if(getPath() != null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return getName().compareTo(other.getName());
|
||||
}
|
||||
}
|
||||
else if(getName() != null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(getName(), getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,4 +253,13 @@ public class Icon implements Comparable<Icon>
|
||||
if (!(o instanceof Icon)) return false;
|
||||
return compareTo((Icon) o) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an observable property extractor for use with observable lists to detect changes internal to this object.
|
||||
*/
|
||||
@JsonIgnore
|
||||
public static Callback<Icon,Observable[]> extractor()
|
||||
{
|
||||
return (Icon i) -> new Observable[] {i.nameProperty(), i.pathProperty(), i.standardIconProperty(), i.defaultIconProperty()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class IconEditor extends JFrame implements ActionListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger mLog = LoggerFactory.getLogger(IconEditor.class);
|
||||
private static final String ADD = "Add";
|
||||
private static final String DEFAULT = "Set Default";
|
||||
private static final String DELETE = "Delete";
|
||||
|
||||
private JButton mAddButton;
|
||||
private JButton mDeleteButton;
|
||||
private JButton mDefaultButton;
|
||||
private JTable mIconTable;
|
||||
private IconManager mIconManager;
|
||||
|
||||
public IconEditor(IconManager model)
|
||||
{
|
||||
mIconManager = model;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setTitle("Icon Manager");
|
||||
setSize(400, 400);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new MigLayout("", "[grow,fill]", "[grow,fill]"));
|
||||
|
||||
/**
|
||||
* Editor Panel
|
||||
*/
|
||||
JPanel editorPanel = new JPanel();
|
||||
editorPanel.setLayout(new MigLayout("insets 1 1 1 1", "[grow,fill][grow,fill][grow,fill]", "[grow,fill][]"));
|
||||
|
||||
mIconTable = new JTable(mIconManager.getModel());
|
||||
IconTableCellRenderer renderer = new IconTableCellRenderer(mIconManager);
|
||||
mIconTable.getColumnModel().getColumn(IconTableModel.COLUMN_IMAGE_ICON).setCellRenderer(renderer);
|
||||
mIconTable.setAutoCreateRowSorter(true);
|
||||
mIconTable.getRowSorter().toggleSortOrder(IconTableModel.COLUMN_ICON_NAME);
|
||||
mIconTable.setRowHeight(36);
|
||||
mIconTable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
|
||||
{
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e)
|
||||
{
|
||||
checkButtons();
|
||||
}
|
||||
});
|
||||
editorPanel.add(new JScrollPane(mIconTable), "span");
|
||||
|
||||
mAddButton = new JButton(ADD);
|
||||
mAddButton.addActionListener(this);
|
||||
editorPanel.add(mAddButton);
|
||||
|
||||
mDeleteButton = new JButton(DELETE);
|
||||
mDeleteButton.addActionListener(this);
|
||||
mDeleteButton.setEnabled(false);
|
||||
editorPanel.add(mDeleteButton);
|
||||
|
||||
mDefaultButton = new JButton(DEFAULT);
|
||||
mDefaultButton.addActionListener(this);
|
||||
mDefaultButton.setEnabled(false);
|
||||
editorPanel.add(mDefaultButton, "wrap");
|
||||
|
||||
add(editorPanel);
|
||||
}
|
||||
|
||||
private void checkButtons()
|
||||
{
|
||||
io.github.dsheirer.icon.Icon selected = getSelectedIcon();
|
||||
|
||||
mDefaultButton.setEnabled(selected != null && selected != mIconManager.getModel().getDefaultIcon());
|
||||
mDeleteButton.setEnabled(selected != null && selected != mIconManager.getModel().getDefaultIcon());
|
||||
}
|
||||
|
||||
private io.github.dsheirer.icon.Icon getSelectedIcon()
|
||||
{
|
||||
int selectedViewRow = mIconTable.getSelectedRow();
|
||||
|
||||
if(selectedViewRow >= 0)
|
||||
{
|
||||
int selectedModelRow = mIconTable.convertRowIndexToModel(mIconTable.getSelectedRow());
|
||||
|
||||
if(selectedModelRow >= 0)
|
||||
{
|
||||
return mIconManager.getModel().get(selectedModelRow);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
io.github.dsheirer.icon.Icon selected = getSelectedIcon();
|
||||
|
||||
switch(e.getActionCommand())
|
||||
{
|
||||
case ADD:
|
||||
IconSelector iconSelector = new IconSelector(this, mIconManager.getModel());
|
||||
iconSelector.setVisible(true);
|
||||
break;
|
||||
case DELETE:
|
||||
if(selected != null)
|
||||
{
|
||||
int choice = JOptionPane.showConfirmDialog(IconEditor.this,
|
||||
"Are you sure you want to delete this icon?", "Delete Icon?", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if(choice == JOptionPane.YES_OPTION)
|
||||
{
|
||||
mIconManager.getModel().remove(selected);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DEFAULT:
|
||||
if(selected != null)
|
||||
{
|
||||
mIconManager.getModel().setDefaultIcon(selected);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
checkButtons();
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class IconListCellRenderer extends JLabel implements ListCellRenderer<io.github.dsheirer.icon.Icon>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IconManager mIconManager;
|
||||
|
||||
public IconListCellRenderer(IconManager iconManager)
|
||||
{
|
||||
mIconManager = iconManager;
|
||||
setOpaque(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<? extends io.github.dsheirer.icon.Icon> list, io.github.dsheirer.icon.Icon icon, int index,
|
||||
boolean isSelected, boolean cellHasFocus)
|
||||
{
|
||||
//Get a scaled version of the icon
|
||||
setIcon(mIconManager.getIcon(icon.getName(), 24));
|
||||
|
||||
if(mIconManager.getModel().isDefaultIcon(icon))
|
||||
{
|
||||
setText(icon.getName() + " (default)");
|
||||
}
|
||||
else
|
||||
{
|
||||
setText(icon.getName());
|
||||
}
|
||||
|
||||
if(isSelected)
|
||||
{
|
||||
setBackground(list.getSelectionBackground());
|
||||
setForeground(list.getSelectionForeground());
|
||||
}
|
||||
else
|
||||
{
|
||||
setBackground(list.getBackground());
|
||||
setForeground(list.getForeground());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,15 @@ import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import io.github.dsheirer.properties.SystemProperties;
|
||||
import io.github.dsheirer.util.ThreadPool;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -37,101 +38,137 @@ import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class IconManager
|
||||
public class IconModel
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(IconManager.class);
|
||||
private final static Logger mLog = LoggerFactory.getLogger(IconModel.class);
|
||||
public static final int DEFAULT_ICON_SIZE = 12;
|
||||
public static final String DEFAULT_ICON = "No Icon";
|
||||
|
||||
private Path mIconFolderPath;
|
||||
private Path mIconFilePath;
|
||||
private Path mIconBackupFilePath;
|
||||
private Path mIconLockFilePath;
|
||||
|
||||
private IconEditor mIconEditor;
|
||||
private IconTableModel mIconTableModel;
|
||||
private AtomicBoolean mSavingIcons = new AtomicBoolean();
|
||||
|
||||
private ObservableList<Icon> mIcons = FXCollections.observableArrayList(Icon.extractor());
|
||||
private StringProperty mDefaultIconName = new SimpleStringProperty();
|
||||
private Map<String,ImageIcon> mResizedIcons = new HashMap<>();
|
||||
private Icon mDefaultIcon;
|
||||
private IconSet mStandardIcons;
|
||||
|
||||
public IconManager()
|
||||
public IconModel()
|
||||
{
|
||||
}
|
||||
IconSet iconSet = load();
|
||||
|
||||
/**
|
||||
* Display the icon editor centered over the specified component.
|
||||
*
|
||||
* @param centerOnComponent to center the editor
|
||||
*/
|
||||
public void showEditor(Component centerOnComponent)
|
||||
{
|
||||
if(mIconEditor == null)
|
||||
if(iconSet == null)
|
||||
{
|
||||
mIconEditor = new IconEditor(this);
|
||||
iconSet = getStandardIconSet();
|
||||
}
|
||||
|
||||
mIconEditor.setLocationRelativeTo(centerOnComponent);
|
||||
IconSet standardIcons = getStandardIconSet();
|
||||
|
||||
if(mIconEditor.isVisible())
|
||||
mIcons.addAll(iconSet.getIcons());
|
||||
|
||||
for(Icon icon: mIcons)
|
||||
{
|
||||
mIconEditor.requestFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
if(iconSet.getDefaultIcon() != null && iconSet.getDefaultIcon().matches(icon.getName()))
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mIconEditor.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public IconTableModel getModel()
|
||||
{
|
||||
if(mIconTableModel == null)
|
||||
{
|
||||
IconSet loadedIcons = load();
|
||||
|
||||
boolean saveRequired = false;
|
||||
|
||||
if(loadedIcons == null)
|
||||
{
|
||||
loadedIcons = getDefaultIconSet();
|
||||
saveRequired = true;
|
||||
icon.setDefaultIcon(true);
|
||||
mDefaultIcon = icon;
|
||||
}
|
||||
|
||||
mIconTableModel = new IconTableModel(loadedIcons);
|
||||
mIconTableModel.addTableModelListener(new TableModelListener()
|
||||
if(standardIcons.getIcons().contains(icon))
|
||||
{
|
||||
@Override
|
||||
public void tableChanged(TableModelEvent e)
|
||||
{
|
||||
scheduleSave();
|
||||
}
|
||||
});
|
||||
|
||||
if(saveRequired)
|
||||
{
|
||||
scheduleSave();
|
||||
icon.setStandardIcon(true);
|
||||
}
|
||||
}
|
||||
|
||||
return mIconTableModel;
|
||||
if(mDefaultIcon == null && !mIcons.isEmpty())
|
||||
{
|
||||
setDefaultIcon(mIcons.get(0));
|
||||
}
|
||||
|
||||
//Add a change detection listener to schedule saves when the list changes.
|
||||
mIcons.addListener((ListChangeListener<Icon>)c -> scheduleSave());
|
||||
}
|
||||
|
||||
/**
|
||||
* All icons in a sorted array
|
||||
* Adds the icon to this model
|
||||
*/
|
||||
public Icon[] getIcons()
|
||||
public void addIcon(Icon icon)
|
||||
{
|
||||
return getModel().getIconsAsArray();
|
||||
if(icon != null && !mIcons.contains(icon))
|
||||
{
|
||||
mIcons.add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the icon from this model
|
||||
*/
|
||||
public void removeIcon(Icon icon)
|
||||
{
|
||||
if(icon != null && !icon.getStandardIcon() && !icon.getDefaultIcon())
|
||||
{
|
||||
mIcons.remove(icon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default icon
|
||||
*/
|
||||
public void setDefaultIcon(Icon icon)
|
||||
{
|
||||
if(icon != null)
|
||||
{
|
||||
if(mDefaultIcon != null)
|
||||
{
|
||||
mDefaultIcon.setDefaultIcon(false);
|
||||
}
|
||||
|
||||
mDefaultIcon = icon;
|
||||
mDefaultIcon.setDefaultIcon(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup an icon by name.
|
||||
* @param iconName to lookup
|
||||
* @return icon if found, or the default icon
|
||||
*/
|
||||
public Icon getIcon(String iconName)
|
||||
{
|
||||
if(iconName != null)
|
||||
{
|
||||
for(Icon icon: iconsProperty())
|
||||
{
|
||||
if(icon.getName() != null && icon.getName().contentEquals(iconName))
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getDefaultIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Current set of icons managed by this model
|
||||
*/
|
||||
public ObservableList<Icon> iconsProperty()
|
||||
{
|
||||
return mIcons;
|
||||
}
|
||||
|
||||
public Icon getDefaultIcon()
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,17 +183,18 @@ public class IconManager
|
||||
{
|
||||
if(name == null)
|
||||
{
|
||||
name = getModel().getDefaultIcon().getName();
|
||||
name = getDefaultIcon().getName();
|
||||
}
|
||||
|
||||
String scaledIconName = name + height;
|
||||
|
||||
ImageIcon mapValue = mResizedIcons.get(scaledIconName);
|
||||
if (mapValue != null) {
|
||||
if (mapValue != null)
|
||||
{
|
||||
return mapValue;
|
||||
}
|
||||
|
||||
Icon icon = getModel().getIcon(name);
|
||||
Icon icon = getIcon(name);
|
||||
|
||||
ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height);
|
||||
|
||||
@@ -270,7 +308,9 @@ public class IconManager
|
||||
*/
|
||||
private void save()
|
||||
{
|
||||
IconSet iconSet = getModel().getIconSet();
|
||||
IconSet iconSet = new IconSet();
|
||||
iconSet.setDefaultIcon(getDefaultIcon().getName());
|
||||
iconSet.setIcons(new ArrayList<>(mIcons));
|
||||
|
||||
//Create a backup copy of the current playlist
|
||||
if(Files.exists(getIconFilePath()))
|
||||
@@ -384,32 +424,35 @@ public class IconManager
|
||||
/**
|
||||
* Creates a default icon set
|
||||
*/
|
||||
private IconSet getDefaultIconSet()
|
||||
private IconSet getStandardIconSet()
|
||||
{
|
||||
IconSet iconSet = new IconSet();
|
||||
if(mStandardIcons == null)
|
||||
{
|
||||
mStandardIcons = new IconSet();
|
||||
|
||||
Icon defaultIcon = new Icon(IconTableModel.DEFAULT_ICON, "images/no_icon.png");
|
||||
iconSet.add(defaultIcon);
|
||||
iconSet.setDefaultIcon(defaultIcon.getName());
|
||||
Icon defaultIcon = new Icon(DEFAULT_ICON, "images/no_icon.png");
|
||||
mStandardIcons.add(defaultIcon);
|
||||
mStandardIcons.setDefaultIcon(defaultIcon.getName());
|
||||
|
||||
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"));
|
||||
mStandardIcons.add(new Icon("Ambulance", "images/ambulance.png"));
|
||||
mStandardIcons.add(new Icon("Block Truck", "images/concrete_block_truck.png"));
|
||||
mStandardIcons.add(new Icon("CWID", "images/cwid.png"));
|
||||
mStandardIcons.add(new Icon("Dispatcher", "images/dispatcher.png"));
|
||||
mStandardIcons.add(new Icon("Dump Truck", "images/dump_truck_red.png"));
|
||||
mStandardIcons.add(new Icon("Fire Truck", "images/fire_truck.png"));
|
||||
mStandardIcons.add(new Icon("Garbage Truck", "images/garbage_truck.png"));
|
||||
mStandardIcons.add(new Icon("Loader", "images/loader.png"));
|
||||
mStandardIcons.add(new Icon("Police", "images/police.png"));
|
||||
mStandardIcons.add(new Icon("Propane Truck", "images/propane_truck.png"));
|
||||
mStandardIcons.add(new Icon("Rescue Truck", "images/rescue_truck.png"));
|
||||
mStandardIcons.add(new Icon("School Bus", "images/school_bus.png"));
|
||||
mStandardIcons.add(new Icon("Taxi", "images/taxi.png"));
|
||||
mStandardIcons.add(new Icon("Train", "images/train.png"));
|
||||
mStandardIcons.add(new Icon("Transport Bus", "images/opt_bus.png"));
|
||||
mStandardIcons.add(new Icon("Van", "images/van.png"));
|
||||
}
|
||||
|
||||
return iconSet;
|
||||
return mStandardIcons;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,179 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
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.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
public class IconSelector extends JDialog implements DocumentListener
|
||||
{
|
||||
private IconTableModel mIconTableModel;
|
||||
private JTextField mNameText;
|
||||
private JTextField mFileLabel;
|
||||
private JButton mFileChooserButton;
|
||||
private JButton mOKButton;
|
||||
private JButton mCancelButton;
|
||||
|
||||
/**
|
||||
* Window for selecting an Icon to add to the Icon Model
|
||||
*
|
||||
* @param owner for this modal dialog
|
||||
* @param iconTableModel to receive the added/selected icon
|
||||
*/
|
||||
public IconSelector(Frame owner, IconTableModel iconTableModel)
|
||||
{
|
||||
super(owner, "Add Icon", true);
|
||||
|
||||
mIconTableModel = iconTableModel;
|
||||
|
||||
init();
|
||||
|
||||
setLocationRelativeTo(owner);
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setSize(250, 170);
|
||||
|
||||
JPanel contentPanel = new JPanel();
|
||||
contentPanel.setPreferredSize(new Dimension(250, 170));
|
||||
contentPanel.setLayout(new MigLayout("insets 1 1 1 1", "[align right][align left,grow,fill]", "[][][][grow,fill][]"));
|
||||
|
||||
contentPanel.add(new JLabel("Name"));
|
||||
|
||||
mNameText = new JTextField();
|
||||
mNameText.getDocument().addDocumentListener(this);
|
||||
contentPanel.add(mNameText, "wrap");
|
||||
|
||||
contentPanel.add(new JLabel("File"));
|
||||
|
||||
mFileLabel = new JTextField();
|
||||
mFileLabel.setEnabled(false);
|
||||
contentPanel.add(mFileLabel, "wrap");
|
||||
|
||||
mFileChooserButton = new JButton("Select File ...");
|
||||
mFileChooserButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
|
||||
// fileChooser.setSelectedFile(null);
|
||||
|
||||
//Add a custom file filter and disable the default
|
||||
fileChooser.addChoosableFileFilter(new ImageFilter());
|
||||
fileChooser.setAcceptAllFileFilterUsed(false);
|
||||
|
||||
int returnVal = fileChooser.showDialog(IconSelector.this, "Select");
|
||||
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
File file = fileChooser.getSelectedFile();
|
||||
|
||||
if(file != null)
|
||||
{
|
||||
mFileLabel.setText(file.getAbsolutePath());
|
||||
checkButtons();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
contentPanel.add(mFileChooserButton, "span,align center");
|
||||
|
||||
contentPanel.add(new JLabel(), "wrap");
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new MigLayout("", "[grow,fill][grow,fill]", "[]"));
|
||||
|
||||
mOKButton = new JButton("OK");
|
||||
mOKButton.setEnabled(false);
|
||||
mOKButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String name = mNameText.getText();
|
||||
String path = mFileLabel.getText();
|
||||
|
||||
Icon icon = new Icon(name, path);
|
||||
mIconTableModel.add(icon);
|
||||
|
||||
IconSelector.this.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
mCancelButton = new JButton("Cancel");
|
||||
mCancelButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
IconSelector.this.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
buttonPanel.add(mOKButton);
|
||||
buttonPanel.add(mCancelButton);
|
||||
|
||||
contentPanel.add(buttonPanel, "span,grow");
|
||||
|
||||
add(contentPanel);
|
||||
}
|
||||
|
||||
private void checkButtons()
|
||||
{
|
||||
String name = mNameText.getText();
|
||||
String path = mFileLabel.getText();
|
||||
|
||||
mOKButton.setEnabled(name != null && path != null && !path.isEmpty() && !mIconTableModel.hasIcon(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
checkButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
checkButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
checkButtons();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
|
||||
public class IconTableCellRenderer extends JLabel implements TableCellRenderer
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(IconTableCellRenderer.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IconManager mIconManager;
|
||||
|
||||
public IconTableCellRenderer(IconManager iconManager)
|
||||
{
|
||||
mIconManager = iconManager;
|
||||
setOpaque(true);
|
||||
setHorizontalAlignment(JLabel.CENTER);
|
||||
setPreferredSize(new Dimension(40,34));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
||||
int row, int column)
|
||||
{
|
||||
if(value instanceof ImageIcon)
|
||||
{
|
||||
//Get a scaled version of the icon
|
||||
setIcon(mIconManager.getScaledIcon((ImageIcon)value, 24));
|
||||
}
|
||||
else
|
||||
{
|
||||
setIcon(null);
|
||||
}
|
||||
|
||||
if(isSelected)
|
||||
{
|
||||
setBackground(table.getSelectionBackground());
|
||||
setForeground(table.getSelectionForeground());
|
||||
}
|
||||
else
|
||||
{
|
||||
setBackground(table.getBackground());
|
||||
setForeground(table.getForeground());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class IconTableModel extends AbstractTableModel
|
||||
{
|
||||
public static final String DEFAULT_ICON = "No Icon";
|
||||
public static final int COLUMN_IMAGE_ICON = 0;
|
||||
public static final int COLUMN_ICON_NAME = 1;
|
||||
|
||||
private Icon mDefaultIcon;
|
||||
|
||||
private Map<String,Icon> mIconMap = new HashMap<>();
|
||||
private List<Icon> mIcons = new ArrayList<>();
|
||||
|
||||
public IconTableModel()
|
||||
{
|
||||
setDefaultIcon(DEFAULT_ICON);
|
||||
}
|
||||
|
||||
public IconTableModel(IconSet iconSet)
|
||||
{
|
||||
mIconMap.clear();
|
||||
mIcons.clear();
|
||||
|
||||
fireTableDataChanged();
|
||||
|
||||
for(Icon icon: iconSet.getIcons())
|
||||
{
|
||||
add(icon);
|
||||
}
|
||||
|
||||
setDefaultIcon(iconSet.getDefaultIcon());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the icon to the model
|
||||
*/
|
||||
public void add(Icon icon)
|
||||
{
|
||||
if(icon != null)
|
||||
{
|
||||
mIcons.add(icon);
|
||||
mIconMap.put(icon.getName(), icon);
|
||||
|
||||
int index = mIcons.indexOf(icon);
|
||||
fireTableRowsInserted(index, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the icon from the model
|
||||
*/
|
||||
public void remove(Icon icon)
|
||||
{
|
||||
if(icon != null && mIcons.contains(icon))
|
||||
{
|
||||
int index = mIcons.indexOf(icon);
|
||||
|
||||
mIcons.remove(icon);
|
||||
mIconMap.remove(icon.getName());
|
||||
|
||||
fireTableRowsDeleted(index, index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Icon get(int row)
|
||||
{
|
||||
if(row < mIcons.size())
|
||||
{
|
||||
return mIcons.get(row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount()
|
||||
{
|
||||
return mIcons.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex)
|
||||
{
|
||||
if(rowIndex < mIcons.size() && columnIndex < getColumnCount())
|
||||
{
|
||||
Icon icon = get(rowIndex);
|
||||
|
||||
switch(columnIndex)
|
||||
{
|
||||
case COLUMN_IMAGE_ICON:
|
||||
return icon.getIcon();
|
||||
case COLUMN_ICON_NAME:
|
||||
if(rowIndex == mIcons.indexOf(getDefaultIcon()))
|
||||
{
|
||||
return icon.getName() + " (default)";
|
||||
}
|
||||
else
|
||||
{
|
||||
return icon.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column)
|
||||
{
|
||||
if(column == COLUMN_ICON_NAME)
|
||||
{
|
||||
return "Name";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int columnIndex)
|
||||
{
|
||||
if(columnIndex == COLUMN_IMAGE_ICON)
|
||||
{
|
||||
return ImageIcon.class;
|
||||
}
|
||||
|
||||
return String.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icons in an array - suitable for use in a JComboBox
|
||||
*/
|
||||
public Icon[] getIconsAsArray()
|
||||
{
|
||||
List<Icon> icons = new ArrayList<>(mIconMap.values());
|
||||
|
||||
Collections.sort(icons);
|
||||
|
||||
return icons.toArray(new Icon[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current default icon
|
||||
*/
|
||||
public Icon getDefaultIcon()
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the icon argument is the current default icon
|
||||
*/
|
||||
public boolean isDefaultIcon(Icon icon)
|
||||
{
|
||||
return icon == getDefaultIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this model contains an icon with the specified name
|
||||
*
|
||||
* @param name to check
|
||||
* @return true if name is not null and not empty and the internal map contains an icon matching name
|
||||
*/
|
||||
public boolean hasIcon(String name)
|
||||
{
|
||||
return name != null && !name.isEmpty() && mIconMap.containsKey(name);
|
||||
}
|
||||
|
||||
public void setDefaultIcon(Icon icon)
|
||||
{
|
||||
if(icon != null)
|
||||
{
|
||||
int currentIndex = mIcons.indexOf(getDefaultIcon());
|
||||
|
||||
mDefaultIcon = icon;
|
||||
|
||||
int newIndex = mIcons.indexOf(icon);
|
||||
|
||||
fireTableCellUpdated(currentIndex, COLUMN_ICON_NAME);
|
||||
fireTableCellUpdated(newIndex, COLUMN_ICON_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default icon to the icon with the specified name, or to a default icon of the named icon does not exist
|
||||
*/
|
||||
public void setDefaultIcon(String name)
|
||||
{
|
||||
if(name == null)
|
||||
{
|
||||
name = DEFAULT_ICON;
|
||||
}
|
||||
|
||||
Icon defaultIcon = mIconMap.get(name);
|
||||
|
||||
if(defaultIcon != null)
|
||||
{
|
||||
setDefaultIcon(defaultIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultIcon = new Icon(DEFAULT_ICON, "images/no_icon.png");
|
||||
add(defaultIcon);
|
||||
setDefaultIcon(defaultIcon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the named icon or the default icon if the named icon does not exist
|
||||
*/
|
||||
public Icon getIcon(String name)
|
||||
{
|
||||
if(name == null || name.isEmpty())
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
|
||||
Icon icon = mIconMap.get(name);
|
||||
|
||||
if(icon == null)
|
||||
{
|
||||
icon = mDefaultIcon;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new icon set from a snapshot of the icons contained in this model
|
||||
*/
|
||||
public IconSet getIconSet()
|
||||
{
|
||||
IconSet iconSet = new IconSet();
|
||||
iconSet.setIcons(new ArrayList<Icon>(mIconMap.values()));
|
||||
iconSet.setDefaultIcon(getDefaultIcon().getName());
|
||||
return iconSet;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.icon;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import java.io.File;
|
||||
|
||||
public class ImageFilter extends FileFilter
|
||||
{
|
||||
//Accept all directories and all gif, jpg, tiff, or png files.
|
||||
public boolean accept(File f)
|
||||
{
|
||||
if(f.isDirectory())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String extension = getExtension(f);
|
||||
|
||||
if(extension != null)
|
||||
{
|
||||
if(extension.equals("tiff") ||
|
||||
extension.equals("tif") ||
|
||||
extension.equals("gif") ||
|
||||
extension.equals("jpeg") ||
|
||||
extension.equals("jpg") ||
|
||||
extension.equals("png"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//The description of this filter
|
||||
public String getDescription()
|
||||
{
|
||||
return "Images (*.gif,*.jpg,*.png.";
|
||||
}
|
||||
|
||||
public String getExtension(File f)
|
||||
{
|
||||
String ext = null;
|
||||
String s = f.getName();
|
||||
int i = s.lastIndexOf('.');
|
||||
|
||||
if(i > 0 && i < s.length() - 1)
|
||||
{
|
||||
ext = s.substring(i + 1).toLowerCase();
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user