#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:
Denny Sheirer
2020-05-06 08:08:05 +00:00
committed by GitHub
parent 2aff9ee817
commit 2723926f83
36 changed files with 1129 additions and 1051 deletions

View File

@@ -23,7 +23,7 @@ package io.github.dsheirer.audio.broadcast;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.alias.id.broadcast.BroadcastChannel; import io.github.dsheirer.alias.id.broadcast.BroadcastChannel;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.properties.SystemProperties; import io.github.dsheirer.properties.SystemProperties;
import io.github.dsheirer.sample.Broadcaster; import io.github.dsheirer.sample.Broadcaster;
@@ -76,7 +76,7 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
FXCollections.observableArrayList(ConfiguredBroadcast.extractor()); FXCollections.observableArrayList(ConfiguredBroadcast.extractor());
private List<AudioRecording> mRecordingQueue = new CopyOnWriteArrayList<>(); private List<AudioRecording> mRecordingQueue = new CopyOnWriteArrayList<>();
private Map<Integer,AbstractAudioBroadcaster> mBroadcasterMap = new HashMap<>(); private Map<Integer,AbstractAudioBroadcaster> mBroadcasterMap = new HashMap<>();
private IconManager mIconManager; private IconModel mIconModel;
private AliasModel mAliasModel; private AliasModel mAliasModel;
private Broadcaster<BroadcastEvent> mBroadcastEventBroadcaster = new Broadcaster<>(); private Broadcaster<BroadcastEvent> mBroadcastEventBroadcaster = new Broadcaster<>();
private BroadcastEventListener mBroadcastEventListener = new BroadcastEventListener(); private BroadcastEventListener mBroadcastEventListener = new BroadcastEventListener();
@@ -84,10 +84,10 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
/** /**
* Model for managing Broadcast configurations and any associated broadcaster instances. * Model for managing Broadcast configurations and any associated broadcaster instances.
*/ */
public BroadcastModel(AliasModel aliasModel, IconManager iconManager, UserPreferences userPreferences) public BroadcastModel(AliasModel aliasModel, IconModel iconModel, UserPreferences userPreferences)
{ {
mAliasModel = aliasModel; mAliasModel = aliasModel;
mIconManager = iconManager; mIconModel = iconModel;
//Monitor to remove temporary recording files that have been streamed by all audio broadcasters //Monitor to remove temporary recording files that have been streamed by all audio broadcasters
ThreadPool.SCHEDULED.scheduleAtFixedRate(new RecordingDeletionMonitor(), 15l, 15l, TimeUnit.SECONDS); ThreadPool.SCHEDULED.scheduleAtFixedRate(new RecordingDeletionMonitor(), 15l, 15l, TimeUnit.SECONDS);
@@ -579,9 +579,9 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
String iconPath = configuredBroadcast.getBroadcastConfiguration() String iconPath = configuredBroadcast.getBroadcastConfiguration()
.getBroadcastServerType().getIconPath(); .getBroadcastServerType().getIconPath();
if(iconPath != null && mIconManager != null) if(iconPath != null && mIconModel != null)
{ {
return mIconManager.getScaledIcon(iconPath, 14); return mIconModel.getScaledIcon(iconPath, 14);
} }
break; break;
case COLUMN_STREAM_NAME: case COLUMN_STREAM_NAME:

View File

@@ -26,7 +26,7 @@ import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.audio.AudioEvent; import io.github.dsheirer.audio.AudioEvent;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.identifier.Identifier; import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierClass; import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.IdentifierCollection; import io.github.dsheirer.identifier.IdentifierCollection;
@@ -73,7 +73,7 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
private Color mMutedColor; private Color mMutedColor;
private Color mValueColor; private Color mValueColor;
private IconManager mIconManager; private IconModel mIconModel;
private SettingsManager mSettingsManager; private SettingsManager mSettingsManager;
private UserPreferences mUserPreferences; private UserPreferences mUserPreferences;
private TalkgroupFormatPreference mTalkgroupFormatPreference; private TalkgroupFormatPreference mTalkgroupFormatPreference;
@@ -88,10 +88,10 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
private AliasModel mAliasModel; private AliasModel mAliasModel;
private Lock mLock = new ReentrantLock(); private Lock mLock = new ReentrantLock();
public AudioChannelPanel(IconManager iconManager, UserPreferences userPreferences, SettingsManager settingsManager, public AudioChannelPanel(IconModel iconModel, UserPreferences userPreferences, SettingsManager settingsManager,
AudioOutput audioOutput, AliasModel aliasModel) AudioOutput audioOutput, AliasModel aliasModel)
{ {
mIconManager = iconManager; mIconModel = iconModel;
mSettingsManager = settingsManager; mSettingsManager = settingsManager;
mSettingsManager.addListener(this); mSettingsManager.addListener(this);
mAliasModel = aliasModel; mAliasModel = aliasModel;
@@ -319,7 +319,7 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
identifier = "-----"; identifier = "-----";
} }
final ImageIcon icon = iconName != null ? mIconManager.getIcon(iconName, 18) : null; final ImageIcon icon = iconName != null ? mIconModel.getIcon(iconName, 18) : null;
final String identifierText = identifier; final String identifierText = identifier;
EventQueue.invokeLater(() -> { EventQueue.invokeLater(() -> {

View File

@@ -21,7 +21,7 @@ package io.github.dsheirer.audio.playback;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.audio.IAudioController; import io.github.dsheirer.audio.IAudioController;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.settings.SettingsManager; import io.github.dsheirer.settings.SettingsManager;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
@@ -36,7 +36,7 @@ public class AudioChannelsPanel extends JPanel
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public AudioChannelsPanel(IconManager iconManager, UserPreferences userPreferences, SettingsManager settingsManager, public AudioChannelsPanel(IconModel iconModel, UserPreferences userPreferences, SettingsManager settingsManager,
IAudioController controller, AliasModel aliasModel) IAudioController controller, AliasModel aliasModel)
{ {
setLayout(new MigLayout("insets 0 0 0 0", setLayout(new MigLayout("insets 0 0 0 0",
@@ -50,7 +50,7 @@ public class AudioChannelsPanel extends JPanel
for(int x = 0; x < outputs.size(); x++) for(int x = 0; x < outputs.size(); x++)
{ {
add(new AudioChannelPanel(iconManager, userPreferences, settingsManager, outputs.get(x), aliasModel)); add(new AudioChannelPanel(iconModel, userPreferences, settingsManager, outputs.get(x), aliasModel));
if(x < outputs.size() - 1) if(x < outputs.size() - 1)
{ {
@@ -63,7 +63,7 @@ public class AudioChannelsPanel extends JPanel
if(outputs.size() == 1) if(outputs.size() == 1)
{ {
addSeparator(); addSeparator();
add(new AudioChannelPanel(iconManager, userPreferences, settingsManager, null, aliasModel), "growx"); add(new AudioChannelPanel(iconModel, userPreferences, settingsManager, null, aliasModel), "growx");
} }
} }

View File

@@ -25,8 +25,8 @@ import io.github.dsheirer.audio.AudioException;
import io.github.dsheirer.audio.IAudioController; import io.github.dsheirer.audio.IAudioController;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.preference.PreferenceEditorType; import io.github.dsheirer.gui.preference.PreferenceEditorType;
import io.github.dsheirer.gui.preference.UserPreferenceEditorViewRequest; import io.github.dsheirer.gui.preference.ViewUserPreferenceEditorRequest;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.settings.SettingsManager; import io.github.dsheirer.settings.SettingsManager;
@@ -64,10 +64,10 @@ 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("images/audio_muted.png", 20); private static ImageIcon MUTED_ICON = IconModel.getScaledIcon("images/audio_muted.png", 20);
private static ImageIcon UNMUTED_ICON = IconManager.getScaledIcon("images/audio_unmuted.png", 20); private static ImageIcon UNMUTED_ICON = IconModel.getScaledIcon("images/audio_unmuted.png", 20);
private IconManager mIconManager; private IconModel mIconModel;
private SettingsManager mSettingsManager; private SettingsManager mSettingsManager;
private SourceManager mSourceManager; private SourceManager mSourceManager;
private IAudioController mController; private IAudioController mController;
@@ -77,10 +77,10 @@ public class AudioPanel extends JPanel implements Listener<AudioEvent>
private JButton mMuteButton; private JButton mMuteButton;
private AudioChannelsPanel mAudioChannelsPanel; private AudioChannelsPanel mAudioChannelsPanel;
public AudioPanel(IconManager iconManager, UserPreferences userPreferences, SettingsManager settingsManager, public AudioPanel(IconModel iconModel, UserPreferences userPreferences, SettingsManager settingsManager,
SourceManager sourceManager, IAudioController controller, AliasModel aliasModel) SourceManager sourceManager, IAudioController controller, AliasModel aliasModel)
{ {
mIconManager = iconManager; mIconModel = iconModel;
mSettingsManager = settingsManager; mSettingsManager = settingsManager;
mSourceManager = sourceManager; mSourceManager = sourceManager;
mController = controller; mController = controller;
@@ -101,7 +101,7 @@ public class AudioPanel extends JPanel implements Listener<AudioEvent>
mMuteButton.setBackground(getBackground()); mMuteButton.setBackground(getBackground());
add(mMuteButton); add(mMuteButton);
mAudioChannelsPanel = new AudioChannelsPanel(mIconManager, mUserPreferences, mSettingsManager, mController, mAliasModel); mAudioChannelsPanel = new AudioChannelsPanel(mIconModel, mUserPreferences, mSettingsManager, mController, mAliasModel);
add(mAudioChannelsPanel); add(mAudioChannelsPanel);
@@ -123,7 +123,7 @@ public class AudioPanel extends JPanel implements Listener<AudioEvent>
{ {
remove(mAudioChannelsPanel); remove(mAudioChannelsPanel);
mAudioChannelsPanel.dispose(); mAudioChannelsPanel.dispose();
mAudioChannelsPanel = new AudioChannelsPanel(mIconManager, mUserPreferences, mSettingsManager, mController, mAliasModel); mAudioChannelsPanel = new AudioChannelsPanel(mIconModel, mUserPreferences, mSettingsManager, mController, mAliasModel);
add(mAudioChannelsPanel); add(mAudioChannelsPanel);
mAudioChannelsPanel.repaint(); mAudioChannelsPanel.repaint();
revalidate(); revalidate();
@@ -183,7 +183,7 @@ public class AudioPanel extends JPanel implements Listener<AudioEvent>
@Override @Override
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
MyEventBus.getEventBus().post(new UserPreferenceEditorViewRequest(PreferenceEditorType.AUDIO_OUTPUT)); MyEventBus.getEventBus().post(new ViewUserPreferenceEditorRequest(PreferenceEditorType.AUDIO_OUTPUT));
} }
}); });
popup.add(outputMenu); popup.add(outputMenu);

View File

@@ -28,7 +28,7 @@ import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.controller.channel.ChannelModel; import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.ChannelProcessingManager; import io.github.dsheirer.controller.channel.ChannelProcessingManager;
import io.github.dsheirer.controller.channel.ChannelUtils; import io.github.dsheirer.controller.channel.ChannelUtils;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.identifier.Identifier; import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.configuration.FrequencyConfigurationIdentifier; import io.github.dsheirer.identifier.configuration.FrequencyConfigurationIdentifier;
import io.github.dsheirer.identifier.decoder.ChannelStateIdentifier; import io.github.dsheirer.identifier.decoder.ChannelStateIdentifier;
@@ -57,7 +57,6 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -66,7 +65,7 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
private static final String TABLE_PREFERENCE_KEY = "channel.metadata.panel"; private static final String TABLE_PREFERENCE_KEY = "channel.metadata.panel";
private ChannelModel mChannelModel; private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager; private ChannelProcessingManager mChannelProcessingManager;
private IconManager mIconManager; private IconModel mIconModel;
private UserPreferences mUserPreferences; private UserPreferences mUserPreferences;
private JTable mTable; private JTable mTable;
private Broadcaster<ProcessingChain> mSelectedProcessingChainBroadcaster = new Broadcaster<>(); private Broadcaster<ProcessingChain> mSelectedProcessingChainBroadcaster = new Broadcaster<>();
@@ -77,11 +76,11 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
/** /**
* Table view for currently decoding channel metadata * Table view for currently decoding channel metadata
*/ */
public ChannelMetadataPanel(PlaylistManager playlistManager, IconManager iconManager, UserPreferences userPreferences) public ChannelMetadataPanel(PlaylistManager playlistManager, IconModel iconModel, UserPreferences userPreferences)
{ {
mChannelModel = playlistManager.getChannelModel(); mChannelModel = playlistManager.getChannelModel();
mChannelProcessingManager = playlistManager.getChannelProcessingManager(); mChannelProcessingManager = playlistManager.getChannelProcessingManager();
mIconManager = iconManager; mIconModel = iconModel;
mUserPreferences = userPreferences; mUserPreferences = userPreferences;
init(); init();
} }
@@ -243,7 +242,7 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
if(!aliases.isEmpty()) if(!aliases.isEmpty())
{ {
label.setText(Joiner.on(", ").skipNulls().join(aliases)); label.setText(Joiner.on(", ").skipNulls().join(aliases));
label.setIcon(mIconManager.getIcon(aliases.get(0).getIconName(), IconManager.DEFAULT_ICON_SIZE)); label.setIcon(mIconModel.getIcon(aliases.get(0).getIconName(), IconModel.DEFAULT_ICON_SIZE));
label.setForeground(aliases.get(0).getDisplayColor()); label.setForeground(aliases.get(0).getDisplayColor());
} }
else else

View File

@@ -22,7 +22,7 @@ package io.github.dsheirer.channel.metadata;
import com.jidesoft.swing.JideSplitPane; import com.jidesoft.swing.JideSplitPane;
import com.jidesoft.swing.JideTabbedPane; import com.jidesoft.swing.JideTabbedPane;
import io.github.dsheirer.channel.details.ChannelDetailPanel; import io.github.dsheirer.channel.details.ChannelDetailPanel;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.module.decode.event.DecodeEventPanel; import io.github.dsheirer.module.decode.event.DecodeEventPanel;
import io.github.dsheirer.module.decode.event.MessageActivityPanel; import io.github.dsheirer.module.decode.event.MessageActivityPanel;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
@@ -43,12 +43,12 @@ public class NowPlayingPanel extends JPanel
* GUI panel that combines the currently decoding channels metadata table and viewers for channel details, * GUI panel that combines the currently decoding channels metadata table and viewers for channel details,
* messages, events, and spectral view. * messages, events, and spectral view.
*/ */
public NowPlayingPanel(PlaylistManager playlistManager, IconManager iconManager, UserPreferences userPreferences) public NowPlayingPanel(PlaylistManager playlistManager, IconModel iconModel, UserPreferences userPreferences)
{ {
mChannelDetailPanel = new ChannelDetailPanel(playlistManager.getChannelProcessingManager()); mChannelDetailPanel = new ChannelDetailPanel(playlistManager.getChannelProcessingManager());
mDecodeEventPanel = new DecodeEventPanel(iconManager, userPreferences, playlistManager.getAliasModel()); mDecodeEventPanel = new DecodeEventPanel(iconModel, userPreferences, playlistManager.getAliasModel());
mMessageActivityPanel = new MessageActivityPanel(userPreferences); mMessageActivityPanel = new MessageActivityPanel(userPreferences);
mChannelMetadataPanel = new ChannelMetadataPanel(playlistManager, iconManager, userPreferences); mChannelMetadataPanel = new ChannelMetadataPanel(playlistManager, iconModel, userPreferences);
init(); init();
} }

View File

@@ -24,7 +24,7 @@ import io.github.dsheirer.audio.playback.AudioPlaybackManager;
import io.github.dsheirer.channel.metadata.NowPlayingPanel; import io.github.dsheirer.channel.metadata.NowPlayingPanel;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.playlist.ViewPlaylistRequest; import io.github.dsheirer.gui.playlist.ViewPlaylistRequest;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.map.MapPanel; import io.github.dsheirer.map.MapPanel;
import io.github.dsheirer.map.MapService; import io.github.dsheirer.map.MapService;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
@@ -58,13 +58,13 @@ public class ControllerPanel extends JPanel
private JideTabbedPane mTabbedPane; private JideTabbedPane mTabbedPane;
public ControllerPanel(PlaylistManager playlistManager, AudioPlaybackManager audioPlaybackManager, public ControllerPanel(PlaylistManager playlistManager, AudioPlaybackManager audioPlaybackManager,
IconManager iconManager, MapService mapService, SettingsManager settingsManager, IconModel iconModel, MapService mapService, SettingsManager settingsManager,
SourceManager sourceManager, UserPreferences userPreferences) SourceManager sourceManager, UserPreferences userPreferences)
{ {
mAudioPanel = new AudioPanel(iconManager, userPreferences, settingsManager, sourceManager, audioPlaybackManager, mAudioPanel = new AudioPanel(iconModel, userPreferences, settingsManager, sourceManager, audioPlaybackManager,
playlistManager.getAliasModel()); playlistManager.getAliasModel());
mNowPlayingPanel = new NowPlayingPanel(playlistManager, iconManager, userPreferences); mNowPlayingPanel = new NowPlayingPanel(playlistManager, iconModel, userPreferences);
mMapPanel = new MapPanel(mapService, playlistManager.getAliasModel(), iconManager, settingsManager); mMapPanel = new MapPanel(mapService, playlistManager.getAliasModel(), iconModel, settingsManager);
mTunerManagerPanel = new TunerViewPanel(sourceManager.getTunerModel(), userPreferences); mTunerManagerPanel = new TunerViewPanel(sourceManager.getTunerModel(), userPreferences);
init(); init();

View File

@@ -27,15 +27,17 @@ import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.controller.channel.map.ChannelMap; import io.github.dsheirer.controller.channel.map.ChannelMap;
import io.github.dsheirer.controller.channel.map.ChannelRange; import io.github.dsheirer.controller.channel.map.ChannelRange;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.icon.IconManager;
import io.github.dsheirer.gui.icon.ViewIconManagerRequest;
import io.github.dsheirer.gui.playlist.PlaylistEditor; import io.github.dsheirer.gui.playlist.PlaylistEditor;
import io.github.dsheirer.gui.playlist.PlaylistEditorRequest; import io.github.dsheirer.gui.playlist.PlaylistEditorRequest;
import io.github.dsheirer.gui.playlist.ViewPlaylistRequest; import io.github.dsheirer.gui.playlist.ViewPlaylistRequest;
import io.github.dsheirer.gui.playlist.channelMap.ChannelMapEditor; import io.github.dsheirer.gui.playlist.channelMap.ChannelMapEditor;
import io.github.dsheirer.gui.playlist.channelMap.ChannelMapEditorViewRequest; import io.github.dsheirer.gui.playlist.channelMap.ViewChannelMapEditorRequest;
import io.github.dsheirer.gui.preference.PreferenceEditorType; import io.github.dsheirer.gui.preference.PreferenceEditorType;
import io.github.dsheirer.gui.preference.UserPreferenceEditorViewRequest;
import io.github.dsheirer.gui.preference.UserPreferencesEditor; import io.github.dsheirer.gui.preference.UserPreferencesEditor;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.gui.preference.ViewUserPreferenceEditorRequest;
import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.module.log.EventLogManager; import io.github.dsheirer.module.log.EventLogManager;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
@@ -61,20 +63,24 @@ public class JavaFxWindowManager extends Application
private final static Logger mLog = LoggerFactory.getLogger(JavaFxWindowManager.class); private final static Logger mLog = LoggerFactory.getLogger(JavaFxWindowManager.class);
public static final String CHANNEL_MAP_EDITOR = "channelmap"; public static final String CHANNEL_MAP_EDITOR = "channelmap";
public static final String ICON_MANAGER = "iconmanager";
public static final String PLAYLIST_EDITOR = "playlist"; public static final String PLAYLIST_EDITOR = "playlist";
public static final String USER_PREFERENCES_EDITOR = "preferences"; public static final String USER_PREFERENCES_EDITOR = "preferences";
public static final String STAGE_MONITOR_KEY_CHANNEL_MAP_EDITOR = "channel.map"; public static final String STAGE_MONITOR_KEY_CHANNEL_MAP_EDITOR = "channel.map";
public static final String STAGE_MONITOR_KEY_ICON_MANAGER_EDITOR = "icon.manager";
public static final String STAGE_MONITOR_KEY_PLAYLIST_EDITOR = "playlist"; public static final String STAGE_MONITOR_KEY_PLAYLIST_EDITOR = "playlist";
public static final String STAGE_MONITOR_KEY_USER_PREFERENCES_EDITOR = "user.preferences"; public static final String STAGE_MONITOR_KEY_USER_PREFERENCES_EDITOR = "user.preferences";
private JFXPanel mJFXPanel; private JFXPanel mJFXPanel;
private PlaylistManager mPlaylistManager;
private ChannelMapEditor mChannelMapEditor; private ChannelMapEditor mChannelMapEditor;
private IconManager mIconManager;
private PlaylistEditor mPlaylistEditor; private PlaylistEditor mPlaylistEditor;
private PlaylistManager mPlaylistManager;
private UserPreferences mUserPreferences; private UserPreferences mUserPreferences;
private UserPreferencesEditor mUserPreferencesEditor; private UserPreferencesEditor mUserPreferencesEditor;
private Stage mChannelMapStage; private Stage mChannelMapStage;
private Stage mIconManagerStage;
private Stage mPlaylistStage; private Stage mPlaylistStage;
private Stage mUserPreferencesStage; private Stage mUserPreferencesStage;
@@ -101,7 +107,7 @@ public class JavaFxWindowManager extends Application
SourceManager sourceManager = new SourceManager(tunerModel, new SettingsManager(tunerConfigurationModel), SourceManager sourceManager = new SourceManager(tunerModel, new SettingsManager(tunerConfigurationModel),
mUserPreferences); mUserPreferences);
EventLogManager eventLogManager = new EventLogManager(aliasModel, mUserPreferences); EventLogManager eventLogManager = new EventLogManager(aliasModel, mUserPreferences);
mPlaylistManager = new PlaylistManager(mUserPreferences, sourceManager, aliasModel, eventLogManager, new IconManager()); mPlaylistManager = new PlaylistManager(mUserPreferences, sourceManager, aliasModel, eventLogManager, new IconModel());
mPlaylistManager.init(); mPlaylistManager.init();
setup(); setup();
} }
@@ -151,6 +157,16 @@ public class JavaFxWindowManager extends Application
*/ */
public void shutdown() public void shutdown()
{ {
if(mChannelMapStage != null)
{
mUserPreferences.getJavaFxPreferences().unmonitor(mChannelMapStage);
}
if(mIconManagerStage != null)
{
mUserPreferences.getJavaFxPreferences().unmonitor(mIconManagerStage);
}
if(mPlaylistStage != null) if(mPlaylistStage != null)
{ {
mUserPreferences.getJavaFxPreferences().unmonitor(mPlaylistStage); mUserPreferences.getJavaFxPreferences().unmonitor(mPlaylistStage);
@@ -161,12 +177,32 @@ public class JavaFxWindowManager extends Application
mUserPreferences.getJavaFxPreferences().unmonitor(mUserPreferencesStage); mUserPreferences.getJavaFxPreferences().unmonitor(mUserPreferencesStage);
} }
if(mChannelMapStage != null) Platform.exit();
}
public Stage getIconManagerStage()
{
if(mIconManagerStage == null)
{ {
mUserPreferences.getJavaFxPreferences().unmonitor(mChannelMapStage); createJFXPanel();
Scene scene = new Scene(getIconManager(), 500, 500);
mIconManagerStage = new Stage();
mIconManagerStage.setTitle("sdrtrunk - Icon Manager");
mIconManagerStage.setScene(scene);
mUserPreferences.getJavaFxPreferences().monitor(mIconManagerStage, STAGE_MONITOR_KEY_ICON_MANAGER_EDITOR);
} }
Platform.exit(); return mIconManagerStage;
}
public IconManager getIconManager()
{
if(mIconManager == null)
{
mIconManager = new IconManager(mPlaylistManager.getIconModel());
}
return mIconManager;
} }
/** /**
@@ -256,7 +292,7 @@ public class JavaFxWindowManager extends Application
* Processes a user preferences editor request * Processes a user preferences editor request
*/ */
@Subscribe @Subscribe
public void process(final UserPreferenceEditorViewRequest request) public void process(final ViewUserPreferenceEditorRequest request)
{ {
execute(() -> { execute(() -> {
getUserPreferencesStage().show(); getUserPreferencesStage().show();
@@ -297,11 +333,22 @@ public class JavaFxWindowManager extends Application
return mChannelMapStage; return mChannelMapStage;
} }
@Subscribe
public void process(final ViewIconManagerRequest request)
{
mLog.debug("Processing view request");
execute(() -> {
getIconManagerStage().show();
getIconManagerStage().requestFocus();
getIconManagerStage().toFront();
});
}
/** /**
* Process a channel map editor request * Process a channel map editor request
*/ */
@Subscribe @Subscribe
public void process(final ChannelMapEditorViewRequest request) public void process(final ViewChannelMapEditorRequest request)
{ {
execute(() -> { execute(() -> {
getChannelMapStage().show(); getChannelMapStage().show();
@@ -344,7 +391,11 @@ public class JavaFxWindowManager extends Application
channelMap2.addRange(new ChannelRange(400,499,480000000, 25000)); channelMap2.addRange(new ChannelRange(400,499,480000000, 25000));
mPlaylistManager.getChannelMapModel().addChannelMap(channelMap2); mPlaylistManager.getChannelMapModel().addChannelMap(channelMap2);
valid = true; valid = true;
process(new ChannelMapEditorViewRequest()); process(new ViewChannelMapEditorRequest());
break;
case ICON_MANAGER:
valid = true;
process(new ViewIconManagerRequest());
break; break;
case PLAYLIST_EDITOR: case PLAYLIST_EDITOR:
valid = true; valid = true;
@@ -352,7 +403,7 @@ public class JavaFxWindowManager extends Application
break; break;
case USER_PREFERENCES_EDITOR: case USER_PREFERENCES_EDITOR:
valid = true; valid = true;
process(new UserPreferenceEditorViewRequest(PreferenceEditorType.DEFAULT)); process(new ViewUserPreferenceEditorRequest(PreferenceEditorType.DEFAULT));
break; break;
default: default:
break; break;
@@ -364,8 +415,8 @@ public class JavaFxWindowManager extends Application
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("An argument is required to launch JavaFX windows from this window manager. " + sb.append("An argument is required to launch JavaFX windows from this window manager. " +
"Valid options are:\n\tplaylist\tPlaylist Editor\n\tpreferences\tUser Preferences Editor\n\tchannelmap\t" + "Valid options are:\n\tchannelmap\tChannel Map Editor\n\ticonmanager\tIcon Manager\n\tplaylist\tPlaylist Editor\n" +
"Channel Map Editor\n"); "\tpreferences\tUser Preferences Editor\n");
sb.append("Supplied Argument(s): ").append(parameters.getRaw()); sb.append("Supplied Argument(s): ").append(parameters.getRaw());
mLog.error(sb.toString()); mLog.error(sb.toString());

View File

@@ -0,0 +1,30 @@
/*
* *****************************************************************************
* 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
* 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.gui;
/**
* Base class for all JavaFX window view and show requests
*/
public abstract class JavaFxWindowRequest
{
public JavaFxWindowRequest()
{
}
}

View File

@@ -30,9 +30,10 @@ import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.controller.channel.ChannelAutoStartFrame; import io.github.dsheirer.controller.channel.ChannelAutoStartFrame;
import io.github.dsheirer.controller.channel.ChannelSelectionManager; import io.github.dsheirer.controller.channel.ChannelSelectionManager;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.icon.ViewIconManagerRequest;
import io.github.dsheirer.gui.playlist.ViewPlaylistRequest; import io.github.dsheirer.gui.playlist.ViewPlaylistRequest;
import io.github.dsheirer.gui.preference.UserPreferenceEditorViewRequest; import io.github.dsheirer.gui.preference.ViewUserPreferenceEditorRequest;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.log.ApplicationLog; import io.github.dsheirer.log.ApplicationLog;
import io.github.dsheirer.map.MapService; import io.github.dsheirer.map.MapService;
import io.github.dsheirer.module.log.EventLogManager; import io.github.dsheirer.module.log.EventLogManager;
@@ -106,7 +107,7 @@ public class SDRTrunk implements Listener<TunerEvent>
private AudioStreamingManager mAudioStreamingManager; private AudioStreamingManager mAudioStreamingManager;
private BroadcastStatusPanel mBroadcastStatusPanel; private BroadcastStatusPanel mBroadcastStatusPanel;
private ControllerPanel mControllerPanel; private ControllerPanel mControllerPanel;
private IconManager mIconManager = new IconManager(); private IconModel mIconModel = new IconModel();
private PlaylistManager mPlaylistManager; private PlaylistManager mPlaylistManager;
private SourceManager mSourceManager; private SourceManager mSourceManager;
private SettingsManager mSettingsManager; private SettingsManager mSettingsManager;
@@ -166,7 +167,7 @@ public class SDRTrunk implements Listener<TunerEvent>
AliasModel aliasModel = new AliasModel(); AliasModel aliasModel = new AliasModel();
EventLogManager eventLogManager = new EventLogManager(aliasModel, mUserPreferences); EventLogManager eventLogManager = new EventLogManager(aliasModel, mUserPreferences);
mPlaylistManager = new PlaylistManager(mUserPreferences, mSourceManager, aliasModel, eventLogManager, mIconManager); mPlaylistManager = new PlaylistManager(mUserPreferences, mSourceManager, aliasModel, eventLogManager, mIconModel);
mJavaFxWindowManager = new JavaFxWindowManager(mUserPreferences, mPlaylistManager); mJavaFxWindowManager = new JavaFxWindowManager(mUserPreferences, mPlaylistManager);
new ChannelSelectionManager(mPlaylistManager.getChannelModel()); new ChannelSelectionManager(mPlaylistManager.getChannelModel());
@@ -183,10 +184,10 @@ public class SDRTrunk implements Listener<TunerEvent>
mPlaylistManager.getChannelProcessingManager().addAudioSegmentListener(mAudioRecordingManager); mPlaylistManager.getChannelProcessingManager().addAudioSegmentListener(mAudioRecordingManager);
mPlaylistManager.getChannelProcessingManager().addAudioSegmentListener(mAudioStreamingManager); mPlaylistManager.getChannelProcessingManager().addAudioSegmentListener(mAudioStreamingManager);
MapService mapService = new MapService(mIconManager); MapService mapService = new MapService(mIconModel);
mPlaylistManager.getChannelProcessingManager().addDecodeEventListener(mapService); mPlaylistManager.getChannelProcessingManager().addDecodeEventListener(mapService);
mControllerPanel = new ControllerPanel(mPlaylistManager, audioPlaybackManager, mIconManager, mapService, mControllerPanel = new ControllerPanel(mPlaylistManager, audioPlaybackManager, mIconModel, mapService,
mSettingsManager, mSourceManager, mUserPreferences); mSettingsManager, mSourceManager, mUserPreferences);
mSpectralPanel = new SpectralDisplayPanel(mPlaylistManager, mSettingsManager, tunerModel); mSpectralPanel = new SpectralDisplayPanel(mPlaylistManager, mSettingsManager, tunerModel);
@@ -331,11 +332,11 @@ public class SDRTrunk implements Listener<TunerEvent>
viewMenu.add(viewPlaylistItem); viewMenu.add(viewPlaylistItem);
JMenuItem preferencesItem = new JMenuItem("User Preferences"); JMenuItem preferencesItem = new JMenuItem("User Preferences");
preferencesItem.addActionListener(e -> MyEventBus.getEventBus().post(new UserPreferenceEditorViewRequest())); preferencesItem.addActionListener(e -> MyEventBus.getEventBus().post(new ViewUserPreferenceEditorRequest()));
viewMenu.add(preferencesItem); viewMenu.add(preferencesItem);
JMenuItem settingsMenu = new JMenuItem("Icon Manager"); JMenuItem settingsMenu = new JMenuItem("Icon Manager");
settingsMenu.addActionListener(arg0 -> mIconManager.showEditor(mMainGui)); settingsMenu.addActionListener(arg0 -> MyEventBus.getEventBus().post(new ViewIconManagerRequest()));
viewMenu.add(settingsMenu); viewMenu.add(settingsMenu);
JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings"); JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings");

View File

@@ -0,0 +1,574 @@
/*
* *****************************************************************************
* 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
* 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.gui.icon;
import io.github.dsheirer.gui.playlist.Editor;
import io.github.dsheirer.icon.Icon;
import io.github.dsheirer.icon.IconModel;
import javafx.beans.binding.Bindings;
import javafx.collections.transformation.SortedList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Accordion;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* GUI manager/editor for standard and custom icons used in sdrtrunk
*/
public class IconManager extends Editor<Icon>
{
private static final Logger mLog = LoggerFactory.getLogger(IconManager.class);
private IconModel mIconModel;
private TableView<Icon> mIconTableView;
private Button mAddButton;
private Button mEditButton;
private Button mDeleteButton;
private Button mSetAsDefaultButton;
private SortedList<Icon> mIconSortedList;
private GridPane mEditorPane;
private Button mSaveButton;
private Button mCancelButton;
private Button mFileButton;
private TextField mFilePathTextField;
private TextField mNameTextField;
private TitledPane mContentTitledPane;
private TitledPane mEditorTitledPane;
private Accordion mAccordion;
/**
* Constructs an instance
*/
public IconManager(IconModel iconModel)
{
mIconModel = iconModel;
getChildren().addAll(getAccordion());
}
private Accordion getAccordion()
{
if(mAccordion == null)
{
mAccordion = new Accordion();
mAccordion.getPanes().addAll(getContentTitledPane(), getEditorTitledPane());
mAccordion.setExpandedPane(getContentTitledPane());
}
return mAccordion;
}
private TitledPane getContentTitledPane()
{
if(mContentTitledPane == null)
{
mContentTitledPane = new TitledPane();
mContentTitledPane.setCollapsible(false);
VBox buttonsBox = new VBox();
buttonsBox.setSpacing(10);
buttonsBox.setPadding(new Insets(10,10,10,10));
buttonsBox.getChildren().addAll(getAddButton(), getEditButton(), getDeleteButton(), getSetAsDefaultButton());
HBox.setHgrow(getIconTableView(), Priority.ALWAYS);
HBox contentBox = new HBox();
contentBox.setPadding(new Insets(0,0,0,0));
contentBox.getChildren().addAll(getIconTableView(), buttonsBox);
mContentTitledPane.setContent(contentBox);
}
return mContentTitledPane;
}
private TitledPane getEditorTitledPane()
{
if(mEditorTitledPane == null)
{
mEditorTitledPane = new TitledPane();
mEditorTitledPane.setDisable(true);
mEditorTitledPane.setExpanded(false);
mEditorTitledPane.setContent(getEditorPane());
}
return mEditorTitledPane;
}
private SortedList<Icon> getIconSortedList()
{
if(mIconSortedList == null)
{
mIconSortedList = new SortedList<>(mIconModel.iconsProperty(), (o1, o2) -> {
if(o1.getName() == null && o2.getName() == null)
{
return 0;
}
if(o1.getName() == null)
{
return -1;
}
if(o2.getName() == null)
{
return 1;
}
return o1.getName().compareTo(o2.getName());
});
}
return mIconSortedList;
}
private TableView<Icon> getIconTableView()
{
if(mIconTableView == null)
{
mIconTableView = new TableView<>(getIconSortedList());
TableColumn<Icon,String> iconColumn = new TableColumn("Icon");
iconColumn.setCellValueFactory(new PropertyValueFactory<>("path"));
iconColumn.setCellFactory(new IconTableCellFactory());
TableColumn<Icon,String> nameColumn = new TableColumn<>("Name");
nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
TableColumn<Icon,Boolean> typeColumn = new TableColumn<>("Type");
typeColumn.setPrefWidth(100);
typeColumn.setCellValueFactory(new PropertyValueFactory<>("defaultIcon"));
typeColumn.setCellFactory(param -> {
TableCell tableCell = new TableCell<Icon,Boolean>()
{
@Override
protected void updateItem(Boolean item, boolean empty)
{
Icon icon = getTableRow() != null ? getTableRow().getItem() : null;
if(icon != null)
{
if(icon.getDefaultIcon())
{
setText("Default");
}
else if(icon.getStandardIcon())
{
setText("Standard");
}
else
{
setText("Custom");
}
}
else
{
setText(null);
}
}
};
return tableCell;
});
mIconTableView.getColumns().addAll(typeColumn, iconColumn, nameColumn);
mIconTableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
getDeleteButton().setDisable(newValue == null || newValue.getDefaultIcon() || newValue.getStandardIcon());
getEditButton().setDisable(newValue == null || newValue.getDefaultIcon() || newValue.getStandardIcon());
getSetAsDefaultButton().setDisable(newValue == null || newValue.getDefaultIcon());
});
}
return mIconTableView;
}
private void showEditor(boolean show)
{
if(show)
{
getEditorTitledPane().setText("Add or Edit an Icon");
getEditorTitledPane().setDisable(false);
getContentTitledPane().setCollapsible(true);
getAccordion().setExpandedPane(getEditorTitledPane());
getEditorTitledPane().setCollapsible(false);
getContentTitledPane().setDisable(true);
}
else
{
getEditorTitledPane().setText(null);
getContentTitledPane().setDisable(false);
getEditorTitledPane().setCollapsible(true);
getAccordion().setExpandedPane(getContentTitledPane());
getContentTitledPane().setCollapsible(false);
getEditorTitledPane().setDisable(true);
}
}
private Button getAddButton()
{
if(mAddButton == null)
{
mAddButton = new Button("Add");
mAddButton.setMaxWidth(Double.MAX_VALUE);
mAddButton.disableProperty().bind(getEditorPane().visibleProperty());
mAddButton.setOnAction(event -> {
setItem(null);
showEditor(true);
});
}
return mAddButton;
}
private Button getEditButton()
{
if(mEditButton == null)
{
mEditButton = new Button("Edit");
mEditButton.setDisable(true);
mEditButton.setMaxWidth(Double.MAX_VALUE);
mEditButton.setOnAction(event -> {
Icon selected = getIconTableView().getSelectionModel().getSelectedItem();
if(selected != null && !selected.standardIconProperty().get())
{
setItem(selected);
showEditor(true);
}
});
}
return mEditButton;
}
private Button getDeleteButton()
{
if(mDeleteButton == null)
{
mDeleteButton = new Button("Delete");
mDeleteButton.setDisable(true);
mDeleteButton.setMaxWidth(Double.MAX_VALUE);
mDeleteButton.setOnAction(event -> {
Icon selected = getIconTableView().getSelectionModel().getSelectedItem();
if(selected != null)
{
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Delete alias: " +
selected.getName() + "?", ButtonType.YES, ButtonType.NO);
alert.setTitle("Delete Alias");
alert.setHeaderText("Deleting Alias");
alert.showAndWait().ifPresent(buttonType -> {
if(buttonType == ButtonType.YES)
{
mIconModel.removeIcon(selected);
}
});
}
});
}
return mDeleteButton;
}
private Button getSetAsDefaultButton()
{
if(mSetAsDefaultButton == null)
{
mSetAsDefaultButton = new Button("Set As Default");
mSetAsDefaultButton.setDisable(true);
mSetAsDefaultButton.setMaxWidth(Double.MAX_VALUE);
mSetAsDefaultButton.setOnAction(event -> {
Icon selected = getIconTableView().getSelectionModel().getSelectedItem();
if(selected != null)
{
mIconModel.setDefaultIcon(selected);
}
});
}
return mSetAsDefaultButton;
}
@Override
public void save()
{
String name = getNameTextField().getText();
String path = getFilePathTextField().getText();
if(name == null || name.isEmpty())
{
Alert alert = new Alert(Alert.AlertType.ERROR, "Please assign a name for the icon", ButtonType.OK);
alert.setHeaderText("Name is required");
alert.setTitle("Save Icon");
alert.showAndWait();
return;
}
if(path == null || path.isEmpty() || !Files.exists(Path.of(path)))
{
Alert alert = new Alert(Alert.AlertType.ERROR, "Please select a picture file for the icon", ButtonType.OK);
alert.setHeaderText("File is required");
alert.setTitle("Save Icon");
alert.showAndWait();
return;
}
if(getItem() != null)
{
getItem().setName(name);
getItem().setPath(path);
}
else
{
Icon icon = new Icon();
icon.setName(name);
icon.setPath(path);
mIconModel.addIcon(icon);
}
showEditor(false);
modifiedProperty().set(false);
}
@Override
public void dispose()
{
}
@Override
public void setItem(Icon item)
{
super.setItem(item);
if(item != null)
{
getNameTextField().setText(item.getName());
getFilePathTextField().setText(item.getPath());
}
else
{
getNameTextField().setText(null);
getFilePathTextField().setText(null);
}
modifiedProperty().set(false);
}
private GridPane getEditorPane()
{
if(mEditorPane == null)
{
mEditorPane = new GridPane();
mEditorPane.setPadding(new Insets(10,10,10,10));
mEditorPane.setHgap(10);
mEditorPane.setVgap(10);
int row = 0;
Label nameLabel = new Label("Name");
GridPane.setConstraints(nameLabel, 0, row);
GridPane.setHalignment(nameLabel, HPos.RIGHT);
mEditorPane.getChildren().add(nameLabel);
GridPane.setConstraints(getNameTextField(), 1, row);
GridPane.setHgrow(getNameTextField(), Priority.ALWAYS);
mEditorPane.getChildren().add(getNameTextField());
GridPane.setConstraints(getSaveButton(), 2, row);
mEditorPane.getChildren().add(getSaveButton());
GridPane.setConstraints(getFileButton(), 0, ++row);
mEditorPane.getChildren().add(getFileButton());
GridPane.setHgrow(getFilePathTextField(), Priority.ALWAYS);
GridPane.setConstraints(getFilePathTextField(), 1, row);
mEditorPane.getChildren().add(getFilePathTextField());
GridPane.setConstraints(getCancelButton(), 2, row);
mEditorPane.getChildren().add(getCancelButton());
}
return mEditorPane;
}
private TextField getFilePathTextField()
{
if(mFilePathTextField == null)
{
mFilePathTextField = new TextField();
}
return mFilePathTextField;
}
private Button getFileButton()
{
if(mFileButton == null)
{
mFileButton = new Button("File");
mFileButton.setMaxWidth(Double.MAX_VALUE);
mFileButton.setOnAction(event -> {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Picture Files", "*.png", "*.tif", "*.tiff",
"*.gif", "*.jpg", "*.jpeg"),
new FileChooser.ExtensionFilter("All Files (*.*)", "*.*"));
if(getFilePathTextField().getText() != null)
{
try
{
Path path = Path.of(getFilePathTextField().getText());
if(path.toFile().exists())
{
fileChooser.setInitialDirectory(path.getParent().toFile());
fileChooser.setInitialFileName(path.getFileName().toString());
}
}
catch(Exception e)
{
mLog.error("Error assigning file text to file chooser");
}
}
File selected = fileChooser.showOpenDialog(getFileButton().getScene().getWindow());
if(selected != null)
{
getFilePathTextField().setText(selected.getAbsolutePath());
}
});
}
return mFileButton;
}
private TextField getNameTextField()
{
if(mNameTextField == null)
{
mNameTextField = new TextField();
}
return mNameTextField;
}
private Button getSaveButton()
{
if(mSaveButton == null)
{
mSaveButton = new Button("Save");
mSaveButton.setMaxWidth(Double.MAX_VALUE);
mSaveButton.setOnAction(event -> save());
mSaveButton.disableProperty().bind(Bindings.or(Bindings.isNull(getNameTextField().textProperty()),
Bindings.isNull(getFilePathTextField().textProperty())));
}
return mSaveButton;
}
private Button getCancelButton()
{
if(mCancelButton == null)
{
mCancelButton = new Button("Cancel");
mCancelButton.setMaxWidth(Double.MAX_VALUE);
mCancelButton.setOnAction(event -> showEditor(false));
}
return mCancelButton;
}
public class IconTableCellFactory implements Callback<TableColumn<Icon, String>, TableCell<Icon, String>>
{
@Override
public TableCell<Icon, String> call(TableColumn<Icon, String> param)
{
TableCell<Icon,String> tableCell = new TableCell<>()
{
@Override
protected void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);
setAlignment(Pos.CENTER);
if(empty)
{
setGraphic(null);
}
else
{
if(getTableRow() != null)
{
Icon icon = getTableRow().getItem();
if(icon != null)
{
try
{
if(icon.getPath().startsWith("images"))
{
Image image = new Image(icon.getPath(), 0, 16, true, true);
setGraphic(new ImageView(image));
}
else
{
Path path = Path.of(icon.getPath());
Image image = new Image(path.toUri().toString(), 0, 16, true, true);
setGraphic(new ImageView(image));
}
}
catch(Exception e)
{
mLog.error("Error loading image: " + (icon != null ? icon.getPath() : "null"), e);
}
}
else
{
setGraphic(null);
}
}
}
}
};
return tableCell;
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* *****************************************************************************
* 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
* 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.gui.icon;
import io.github.dsheirer.gui.JavaFxWindowRequest;
/**
* Request to view/show the Icon Manager
*/
public class ViewIconManagerRequest extends JavaFxWindowRequest
{
public ViewIconManagerRequest()
{
}
}

View File

@@ -23,6 +23,7 @@
package io.github.dsheirer.gui.playlist; package io.github.dsheirer.gui.playlist;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.icon.ViewIconManagerRequest;
import io.github.dsheirer.gui.playlist.alias.AliasEditor; import io.github.dsheirer.gui.playlist.alias.AliasEditor;
import io.github.dsheirer.gui.playlist.alias.AliasTabRequest; import io.github.dsheirer.gui.playlist.alias.AliasTabRequest;
import io.github.dsheirer.gui.playlist.channel.ChannelEditor; import io.github.dsheirer.gui.playlist.channel.ChannelEditor;
@@ -31,7 +32,7 @@ import io.github.dsheirer.gui.playlist.manager.PlaylistManagerEditor;
import io.github.dsheirer.gui.playlist.radioreference.RadioReferenceEditor; import io.github.dsheirer.gui.playlist.radioreference.RadioReferenceEditor;
import io.github.dsheirer.gui.playlist.streaming.StreamingEditor; import io.github.dsheirer.gui.playlist.streaming.StreamingEditor;
import io.github.dsheirer.gui.preference.PreferenceEditorType; import io.github.dsheirer.gui.preference.PreferenceEditorType;
import io.github.dsheirer.gui.preference.UserPreferenceEditorViewRequest; import io.github.dsheirer.gui.preference.ViewUserPreferenceEditorRequest;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.util.ThreadPool; import io.github.dsheirer.util.ThreadPool;
@@ -147,11 +148,18 @@ public class PlaylistEditor extends BorderPane
Menu viewMenu = new Menu("_View"); Menu viewMenu = new Menu("_View");
viewMenu.setAccelerator(new KeyCodeCombination(KeyCode.V, KeyCombination.ALT_ANY)); viewMenu.setAccelerator(new KeyCodeCombination(KeyCode.V, KeyCombination.ALT_ANY));
MenuItem iconManagerItem = new MenuItem("_Icon Manager");
iconManagerItem.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCombination.ALT_ANY));
iconManagerItem.setOnAction(event -> MyEventBus.getEventBus().post(new ViewIconManagerRequest()));
viewMenu.getItems().add(iconManagerItem);
MenuItem userPreferenceItem = new MenuItem("_User Preferences"); MenuItem userPreferenceItem = new MenuItem("_User Preferences");
userPreferenceItem.setAccelerator(new KeyCodeCombination(KeyCode.U, KeyCombination.ALT_ANY)); userPreferenceItem.setAccelerator(new KeyCodeCombination(KeyCode.U, KeyCombination.ALT_ANY));
userPreferenceItem.setOnAction(event -> MyEventBus.getEventBus() userPreferenceItem.setOnAction(event -> MyEventBus.getEventBus()
.post(new UserPreferenceEditorViewRequest(PreferenceEditorType.TALKGROUP_FORMAT))); .post(new ViewUserPreferenceEditorRequest(PreferenceEditorType.TALKGROUP_FORMAT)));
viewMenu.getItems().add(userPreferenceItem); viewMenu.getItems().add(userPreferenceItem);
mMenuBar.getMenus().add(viewMenu); mMenuBar.getMenus().add(viewMenu);
Menu screenShot = new Menu("_Screenshot"); Menu screenShot = new Menu("_Screenshot");

View File

@@ -23,7 +23,7 @@ import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.audio.broadcast.BroadcastModel; import io.github.dsheirer.audio.broadcast.BroadcastModel;
import io.github.dsheirer.controller.channel.map.ChannelMapModel; import io.github.dsheirer.controller.channel.map.ChannelMapModel;
import io.github.dsheirer.gui.JavaFxWindowManager; import io.github.dsheirer.gui.JavaFxWindowManager;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.module.log.EventLogManager; import io.github.dsheirer.module.log.EventLogManager;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
@@ -50,14 +50,14 @@ public class PlaylistEditorApplication extends Application
public PlaylistEditorApplication() public PlaylistEditorApplication()
{ {
AliasModel aliasModel = new AliasModel(); AliasModel aliasModel = new AliasModel();
BroadcastModel broadcastModel = new BroadcastModel(aliasModel, new IconManager(), mUserPreferences); BroadcastModel broadcastModel = new BroadcastModel(aliasModel, new IconModel(), mUserPreferences);
ChannelMapModel channelMapModel = new ChannelMapModel(); ChannelMapModel channelMapModel = new ChannelMapModel();
TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel(); TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel();
TunerModel tunerModel = new TunerModel(tunerConfigurationModel); TunerModel tunerModel = new TunerModel(tunerConfigurationModel);
SourceManager sourceManager = new SourceManager(tunerModel, new SettingsManager(tunerConfigurationModel), SourceManager sourceManager = new SourceManager(tunerModel, new SettingsManager(tunerConfigurationModel),
mUserPreferences); mUserPreferences);
EventLogManager eventLogManager = new EventLogManager(aliasModel, mUserPreferences); EventLogManager eventLogManager = new EventLogManager(aliasModel, mUserPreferences);
mPlaylistManager = new PlaylistManager(mUserPreferences, sourceManager, aliasModel, eventLogManager, new IconManager()); mPlaylistManager = new PlaylistManager(mUserPreferences, sourceManager, aliasModel, eventLogManager, new IconModel());
mPlaylistManager.init(); mPlaylistManager.init();
mJavaFxWindowManager = new JavaFxWindowManager(mUserPreferences, mPlaylistManager); mJavaFxWindowManager = new JavaFxWindowManager(mUserPreferences, mPlaylistManager);

View File

@@ -19,10 +19,12 @@
package io.github.dsheirer.gui.playlist; package io.github.dsheirer.gui.playlist;
import io.github.dsheirer.gui.JavaFxWindowRequest;
/** /**
* Request to view a facet of the playlist editor * Request to view a facet of the playlist editor
*/ */
public abstract class PlaylistEditorRequest public abstract class PlaylistEditorRequest extends JavaFxWindowRequest
{ {
public enum TabName {ALIAS, CHANNEL, PLAYLIST, RADIOREFERENCE, STREAM} public enum TabName {ALIAS, CHANNEL, PLAYLIST, RADIOREFERENCE, STREAM}

View File

@@ -777,7 +777,7 @@ public class AliasConfigurationEditor extends SplitPane
if(alias != null) if(alias != null)
{ {
Icon icon = mPlaylistManager.getIconManager().getModel().getIcon(alias.getIconName()); Icon icon = mPlaylistManager.getIconModel().getIcon(alias.getIconName());
try try
{ {

View File

@@ -103,6 +103,7 @@ import org.controlsfx.control.ToggleSwitch;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -249,7 +250,7 @@ public class AliasItemEditor extends Editor<Alias>
String iconName = alias.getIconName(); String iconName = alias.getIconName();
if(iconName != null) if(iconName != null)
{ {
icon = mPlaylistManager.getIconManager().getModel().getIcon(iconName); icon = mPlaylistManager.getIconModel().getIcon(iconName);
} }
getIconNodeComboBox().getSelectionModel().select(icon); getIconNodeComboBox().getSelectionModel().select(icon);
@@ -1040,7 +1041,7 @@ public class AliasItemEditor extends Editor<Alias>
mIconNodeComboBox = new ComboBox<>(); mIconNodeComboBox = new ComboBox<>();
mIconNodeComboBox.setMaxWidth(Double.MAX_VALUE); mIconNodeComboBox.setMaxWidth(Double.MAX_VALUE);
mIconNodeComboBox.setDisable(true); mIconNodeComboBox.setDisable(true);
mIconNodeComboBox.getItems().addAll(mPlaylistManager.getIconManager().getIcons()); mIconNodeComboBox.setItems(mPlaylistManager.getIconModel().iconsProperty());
mIconNodeComboBox.setCellFactory(new IconCellFactory()); mIconNodeComboBox.setCellFactory(new IconCellFactory());
mIconNodeComboBox.getSelectionModel().selectedItemProperty() mIconNodeComboBox.getSelectionModel().selectedItemProperty()
.addListener((observable, oldValue, newValue) -> modifiedProperty().set(true)); .addListener((observable, oldValue, newValue) -> modifiedProperty().set(true));
@@ -1573,17 +1574,24 @@ public class AliasItemEditor extends Editor<Alias>
String path = item.getPath(); String path = item.getPath();
if(path.startsWith("images")) try
{ {
try if(path.startsWith("images"))
{ {
Image image = new Image(path, 0, 20, true, true); Image image = new Image(path, 0, 20, true, true);
setGraphic(new ImageView(image)); setGraphic(new ImageView(image));
} }
catch(Exception e) else
{ {
Path filePath = Path.of(path);
Image image = new Image(filePath.toUri().toString(), 0, 16, true, true);
setGraphic(new ImageView(image));
} }
}
catch(Exception e)
{
mLog.error("Error loading icon for [" + item.getName() + "] path [" + item.getPath() + "]");
} }
} }
} }

View File

@@ -24,7 +24,7 @@ package io.github.dsheirer.gui.playlist.channel;
import io.github.dsheirer.controller.channel.map.ChannelMap; import io.github.dsheirer.controller.channel.map.ChannelMap;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.playlist.channelMap.ChannelMapEditorViewRequest; import io.github.dsheirer.gui.playlist.channelMap.ViewChannelMapEditorRequest;
import io.github.dsheirer.gui.playlist.eventlog.EventLogConfigurationEditor; import io.github.dsheirer.gui.playlist.eventlog.EventLogConfigurationEditor;
import io.github.dsheirer.gui.playlist.record.RecordConfigurationEditor; import io.github.dsheirer.gui.playlist.record.RecordConfigurationEditor;
import io.github.dsheirer.gui.playlist.source.FrequencyEditor; import io.github.dsheirer.gui.playlist.source.FrequencyEditor;
@@ -271,7 +271,7 @@ public class MPT1327ConfigurationEditor extends ChannelConfigurationEditor
channelMapName = getChannelMapComboBox().getSelectionModel().getSelectedItem().getName(); channelMapName = getChannelMapComboBox().getSelectionModel().getSelectedItem().getName();
} }
MyEventBus.getEventBus().post(new ChannelMapEditorViewRequest(channelMapName)); MyEventBus.getEventBus().post(new ViewChannelMapEditorRequest(channelMapName));
} }
}); });
} }

View File

@@ -802,7 +802,7 @@ public class ChannelMapEditor extends SplitPane
/** /**
* Processes a request to show/edit a channel map * Processes a request to show/edit a channel map
*/ */
public void process(ChannelMapEditorViewRequest request) public void process(ViewChannelMapEditorRequest request)
{ {
String channelMapName = request.getChannelMapName(); String channelMapName = request.getChannelMapName();

View File

@@ -19,10 +19,12 @@
package io.github.dsheirer.gui.playlist.channelMap; package io.github.dsheirer.gui.playlist.channelMap;
import io.github.dsheirer.gui.JavaFxWindowRequest;
/** /**
* Request to show the channel map editor * Request to show the channel map editor
*/ */
public class ChannelMapEditorViewRequest public class ViewChannelMapEditorRequest extends JavaFxWindowRequest
{ {
private String mChannelMapName; private String mChannelMapName;
@@ -30,7 +32,7 @@ public class ChannelMapEditorViewRequest
* Constructs an instance * Constructs an instance
* @param channelMapName to select once the editor is showing. * @param channelMapName to select once the editor is showing.
*/ */
public ChannelMapEditorViewRequest(String channelMapName) public ViewChannelMapEditorRequest(String channelMapName)
{ {
mChannelMapName = channelMapName; mChannelMapName = channelMapName;
} }
@@ -38,7 +40,7 @@ public class ChannelMapEditorViewRequest
/** /**
* Constructs an instance. * Constructs an instance.
*/ */
public ChannelMapEditorViewRequest() public ViewChannelMapEditorRequest()
{ {
} }

View File

@@ -45,8 +45,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map; import java.util.Map;
/** /**
@@ -94,7 +92,7 @@ public class UserPreferencesEditor extends BorderPane
/** /**
* Shows the editor specified in the request by scrolling the editor view tree to the selected item. * Shows the editor specified in the request by scrolling the editor view tree to the selected item.
*/ */
public void process(UserPreferenceEditorViewRequest request) public void process(ViewUserPreferenceEditorRequest request)
{ {
if(request.getPreferenceType() != null) if(request.getPreferenceType() != null)
{ {

View File

@@ -16,10 +16,12 @@
package io.github.dsheirer.gui.preference; package io.github.dsheirer.gui.preference;
import io.github.dsheirer.gui.JavaFxWindowRequest;
/** /**
* Request to launch the preferences editor and scroll to a specific editor view * Request to launch the preferences editor and scroll to a specific editor view
*/ */
public class UserPreferenceEditorViewRequest public class ViewUserPreferenceEditorRequest extends JavaFxWindowRequest
{ {
private PreferenceEditorType mPreferenceType; private PreferenceEditorType mPreferenceType;
@@ -27,7 +29,7 @@ public class UserPreferenceEditorViewRequest
* Request to show the preference editor and focus the specified editor type control * Request to show the preference editor and focus the specified editor type control
* @param preferenceEditorType to focus * @param preferenceEditorType to focus
*/ */
public UserPreferenceEditorViewRequest(PreferenceEditorType preferenceEditorType) public ViewUserPreferenceEditorRequest(PreferenceEditorType preferenceEditorType)
{ {
mPreferenceType = preferenceEditorType; mPreferenceType = preferenceEditorType;
} }
@@ -35,7 +37,7 @@ public class UserPreferenceEditorViewRequest
/** /**
* Request to simply show the preference editor without focusing any of the components * Request to simply show the preference editor without focusing any of the components
*/ */
public UserPreferenceEditorViewRequest() public ViewUserPreferenceEditorRequest()
{ {
} }

View File

@@ -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 * 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 * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* * ****************************************************************************
******************************************************************************/ */
package io.github.dsheirer.icon; package io.github.dsheirer.icon;
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 com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import java.net.URL; import java.net.URL;
import java.util.Objects;
@JacksonXmlRootElement(localName = "icon") @JacksonXmlRootElement(localName = "icon")
public class Icon implements Comparable<Icon> public class Icon implements Comparable<Icon>
{ {
private final static Logger mLog = LoggerFactory.getLogger(Icon.class); private final static Logger mLog = LoggerFactory.getLogger(Icon.class);
protected String mName; private StringProperty mName = new SimpleStringProperty();
private String mPath; private StringProperty mPath = new SimpleStringProperty();
private BooleanProperty mDefaultIcon = new SimpleBooleanProperty();
private BooleanProperty mStandardIcon = new SimpleBooleanProperty();
private ImageIcon mImageIcon; private ImageIcon mImageIcon;
/**
* JAXB constructor - do not use
*/
public Icon() public Icon()
{ {
//No-arg JAXB constructor //No-arg JAXB constructor
} }
/**
* Constructs an instance
* @param name for the icon
* @param path to the icon
*/
public Icon(String name, String path) public Icon(String name, String path)
{ {
mName = name; setName(name);
mPath = path; setPath(path);
} }
@JacksonXmlProperty(isAttribute = true, localName = "name") @JsonIgnore
public String getName() public StringProperty nameProperty()
{ {
return mName; return mName;
} }
public void setName(String name) @JsonIgnore
{ public StringProperty pathProperty()
mName = name;
}
public String toString()
{
return mName;
}
@JacksonXmlProperty(isAttribute = true, localName = "path")
public String getPath()
{ {
return mPath; 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) public void setPath(String path)
{ {
mPath = path; mPath.set(path);
} }
@JsonIgnore @JsonIgnore
@@ -81,17 +171,17 @@ public class Icon implements Comparable<Icon>
{ {
try try
{ {
if(!mPath.startsWith("images")) if(!getPath().startsWith("images"))
{ {
mImageIcon = new ImageIcon(mPath); mImageIcon = new ImageIcon(getPath());
} }
else 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) if(imageURL != null)
@@ -102,7 +192,7 @@ public class Icon implements Comparable<Icon>
} }
catch(Exception e) 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 @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 @Override
@@ -120,4 +253,13 @@ public class Icon implements Comparable<Icon>
if (!(o instanceof Icon)) return false; if (!(o instanceof Icon)) return false;
return compareTo((Icon) o) == 0; 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()};
}
} }

View File

@@ -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();
}
}

View File

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

View File

@@ -22,14 +22,15 @@ import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import io.github.dsheirer.properties.SystemProperties; import io.github.dsheirer.properties.SystemProperties;
import io.github.dsheirer.util.ThreadPool; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.ImageIcon; 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.awt.Image;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -37,101 +38,137 @@ import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; 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 int DEFAULT_ICON_SIZE = 12;
public static final String DEFAULT_ICON = "No Icon";
private Path mIconFolderPath; private Path mIconFolderPath;
private Path mIconFilePath; private Path mIconFilePath;
private Path mIconBackupFilePath; private Path mIconBackupFilePath;
private Path mIconLockFilePath; private Path mIconLockFilePath;
private IconEditor mIconEditor;
private IconTableModel mIconTableModel;
private AtomicBoolean mSavingIcons = new AtomicBoolean(); 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 Map<String,ImageIcon> mResizedIcons = new HashMap<>();
private Icon mDefaultIcon;
private IconSet mStandardIcons;
public IconManager() public IconModel()
{ {
} IconSet iconSet = load();
/** if(iconSet == null)
* Display the icon editor centered over the specified component.
*
* @param centerOnComponent to center the editor
*/
public void showEditor(Component centerOnComponent)
{
if(mIconEditor == 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(); if(iconSet.getDefaultIcon() != null && iconSet.getDefaultIcon().matches(icon.getName()))
}
else
{
EventQueue.invokeLater(new Runnable()
{ {
@Override icon.setDefaultIcon(true);
public void run() mDefaultIcon = icon;
{
mIconEditor.setVisible(true);
}
});
}
}
public IconTableModel getModel()
{
if(mIconTableModel == null)
{
IconSet loadedIcons = load();
boolean saveRequired = false;
if(loadedIcons == null)
{
loadedIcons = getDefaultIconSet();
saveRequired = true;
} }
mIconTableModel = new IconTableModel(loadedIcons); if(standardIcons.getIcons().contains(icon))
mIconTableModel.addTableModelListener(new TableModelListener()
{ {
@Override icon.setStandardIcon(true);
public void tableChanged(TableModelEvent e)
{
scheduleSave();
}
});
if(saveRequired)
{
scheduleSave();
} }
} }
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) if(name == null)
{ {
name = getModel().getDefaultIcon().getName(); name = getDefaultIcon().getName();
} }
String scaledIconName = name + height; String scaledIconName = name + height;
ImageIcon mapValue = mResizedIcons.get(scaledIconName); ImageIcon mapValue = mResizedIcons.get(scaledIconName);
if (mapValue != null) { if (mapValue != null)
{
return mapValue; return mapValue;
} }
Icon icon = getModel().getIcon(name); Icon icon = getIcon(name);
ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height); ImageIcon scaledIcon = getScaledIcon(icon.getIcon(), height);
@@ -270,7 +308,9 @@ public class IconManager
*/ */
private void save() 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 //Create a backup copy of the current playlist
if(Files.exists(getIconFilePath())) if(Files.exists(getIconFilePath()))
@@ -384,32 +424,35 @@ public class IconManager
/** /**
* Creates a default icon set * 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"); Icon defaultIcon = new Icon(DEFAULT_ICON, "images/no_icon.png");
iconSet.add(defaultIcon); mStandardIcons.add(defaultIcon);
iconSet.setDefaultIcon(defaultIcon.getName()); mStandardIcons.setDefaultIcon(defaultIcon.getName());
iconSet.add(new Icon("Ambulance", "images/ambulance.png")); mStandardIcons.add(new Icon("Ambulance", "images/ambulance.png"));
iconSet.add(new Icon("Block Truck", "images/concrete_block_truck.png")); mStandardIcons.add(new Icon("Block Truck", "images/concrete_block_truck.png"));
iconSet.add(new Icon("CWID", "images/cwid.png")); mStandardIcons.add(new Icon("CWID", "images/cwid.png"));
iconSet.add(new Icon("Dispatcher", "images/dispatcher.png")); mStandardIcons.add(new Icon("Dispatcher", "images/dispatcher.png"));
iconSet.add(new Icon("Dump Truck", "images/dump_truck_red.png")); mStandardIcons.add(new Icon("Dump Truck", "images/dump_truck_red.png"));
iconSet.add(new Icon("Fire Truck", "images/fire_truck.png")); mStandardIcons.add(new Icon("Fire Truck", "images/fire_truck.png"));
iconSet.add(new Icon("Garbage Truck", "images/garbage_truck.png")); mStandardIcons.add(new Icon("Garbage Truck", "images/garbage_truck.png"));
iconSet.add(new Icon("Loader", "images/loader.png")); mStandardIcons.add(new Icon("Loader", "images/loader.png"));
iconSet.add(new Icon("Police", "images/police.png")); mStandardIcons.add(new Icon("Police", "images/police.png"));
iconSet.add(new Icon("Propane Truck", "images/propane_truck.png")); mStandardIcons.add(new Icon("Propane Truck", "images/propane_truck.png"));
iconSet.add(new Icon("Rescue Truck", "images/rescue_truck.png")); mStandardIcons.add(new Icon("Rescue Truck", "images/rescue_truck.png"));
iconSet.add(new Icon("School Bus", "images/school_bus.png")); mStandardIcons.add(new Icon("School Bus", "images/school_bus.png"));
iconSet.add(new Icon("Taxi", "images/taxi.png")); mStandardIcons.add(new Icon("Taxi", "images/taxi.png"));
iconSet.add(new Icon("Train", "images/train.png")); mStandardIcons.add(new Icon("Train", "images/train.png"));
iconSet.add(new Icon("Transport Bus", "images/opt_bus.png")); mStandardIcons.add(new Icon("Transport Bus", "images/opt_bus.png"));
iconSet.add(new Icon("Van", "images/van.png")); mStandardIcons.add(new Icon("Van", "images/van.png"));
}
return iconSet; return mStandardIcons;
} }
/** /**

View File

@@ -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();
}
}

View File

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

View File

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

View File

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

View File

@@ -19,7 +19,7 @@
package io.github.dsheirer.map; package io.github.dsheirer.map;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.settings.MapViewSetting; import io.github.dsheirer.settings.MapViewSetting;
import io.github.dsheirer.settings.SettingsManager; import io.github.dsheirer.settings.SettingsManager;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
@@ -43,11 +43,11 @@ public class MapPanel extends JPanel implements IPlottableUpdateListener
private JXMapViewer mMapViewer = new JXMapViewer(); private JXMapViewer mMapViewer = new JXMapViewer();
private PlottableEntityPainter mMapPainter; private PlottableEntityPainter mMapPainter;
public MapPanel(MapService mapService, AliasModel aliasModel, IconManager iconManager, SettingsManager settingsManager) public MapPanel(MapService mapService, AliasModel aliasModel, IconModel iconModel, SettingsManager settingsManager)
{ {
mSettingsManager = settingsManager; mSettingsManager = settingsManager;
mMapService = mapService; mMapService = mapService;
mMapPainter = new PlottableEntityPainter(aliasModel, iconManager); mMapPainter = new PlottableEntityPainter(aliasModel, iconModel);
init(); init();
} }

View File

@@ -19,7 +19,7 @@
*/ */
package io.github.dsheirer.map; package io.github.dsheirer.map;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.identifier.Identifier; import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.module.decode.event.IDecodeEvent; import io.github.dsheirer.module.decode.event.IDecodeEvent;
import io.github.dsheirer.module.decode.event.PlottableDecodeEvent; import io.github.dsheirer.module.decode.event.PlottableDecodeEvent;
@@ -39,11 +39,11 @@ public class MapService implements Listener<IDecodeEvent>
private int mMaxHistory = 2; private int mMaxHistory = 2;
private List<IPlottableUpdateListener> mListeners = new ArrayList<IPlottableUpdateListener>(); private List<IPlottableUpdateListener> mListeners = new ArrayList<IPlottableUpdateListener>();
private Map<Identifier,PlottableEntityHistory> mEntityHistories = new HashMap<>(); private Map<Identifier,PlottableEntityHistory> mEntityHistories = new HashMap<>();
private IconManager mIconManager; private IconModel mIconModel;
public MapService(IconManager resourceManager) public MapService(IconModel resourceManager)
{ {
mIconManager = resourceManager; mIconModel = resourceManager;
} }
@Override @Override

View File

@@ -21,7 +21,7 @@
package io.github.dsheirer.map; package io.github.dsheirer.map;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import org.jdesktop.swingx.JXMapViewer; import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.painter.AbstractPainter; import org.jdesktop.swingx.painter.AbstractPainter;
@@ -36,9 +36,9 @@ public class PlottableEntityPainter extends AbstractPainter<JXMapViewer>
private PlottableEntityRenderer mRenderer; private PlottableEntityRenderer mRenderer;
private Set<PlottableEntityHistory> mEntities = new HashSet<>(); private Set<PlottableEntityHistory> mEntities = new HashSet<>();
public PlottableEntityPainter(AliasModel aliasModel, IconManager iconManager) public PlottableEntityPainter(AliasModel aliasModel, IconModel iconModel)
{ {
mRenderer = new PlottableEntityRenderer(aliasModel, iconManager); mRenderer = new PlottableEntityRenderer(aliasModel, iconModel);
setAntialiasing(true); setAntialiasing(true);
setCacheable(false); setCacheable(false);
} }

View File

@@ -22,7 +22,7 @@ package io.github.dsheirer.map;
import io.github.dsheirer.alias.Alias; import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.AliasList; import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import org.jdesktop.swingx.JXMapViewer; import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.GeoPosition; import org.jdesktop.swingx.mapviewer.GeoPosition;
@@ -38,12 +38,12 @@ import java.util.List;
public class PlottableEntityRenderer public class PlottableEntityRenderer
{ {
private AliasModel mAliasModel; private AliasModel mAliasModel;
private IconManager mIconManager; private IconModel mIconModel;
public PlottableEntityRenderer(AliasModel aliasModel, IconManager iconManager) public PlottableEntityRenderer(AliasModel aliasModel, IconModel iconModel)
{ {
mAliasModel = aliasModel; mAliasModel = aliasModel;
mIconManager = iconManager; mIconModel = iconModel;
} }
public void paintPlottableEntity(Graphics2D g, JXMapViewer viewer, PlottableEntityHistory entity, boolean antiAliasing) public void paintPlottableEntity(Graphics2D g, JXMapViewer viewer, PlottableEntityHistory entity, boolean antiAliasing)
@@ -118,7 +118,7 @@ public class PlottableEntityRenderer
private ImageIcon getIcon(Alias alias) private ImageIcon getIcon(Alias alias)
{ {
String iconName = (alias != null ? alias.getIconName() : null); String iconName = (alias != null ? alias.getIconName() : null);
return mIconManager.getIcon(iconName, IconManager.DEFAULT_ICON_SIZE); return mIconModel.getIcon(iconName, IconModel.DEFAULT_ICON_SIZE);
} }
private void paintIcon(Graphics2D graphics, Point2D point, ImageIcon icon) private void paintIcon(Graphics2D graphics, Point2D point, ImageIcon icon)

View File

@@ -28,7 +28,7 @@ import io.github.dsheirer.alias.AliasList;
import io.github.dsheirer.alias.AliasModel; import io.github.dsheirer.alias.AliasModel;
import io.github.dsheirer.channel.IChannelDescriptor; import io.github.dsheirer.channel.IChannelDescriptor;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.identifier.Form; import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.Identifier; import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierCollection; import io.github.dsheirer.identifier.IdentifierCollection;
@@ -66,21 +66,21 @@ public class DecodeEventPanel extends JPanel implements Listener<ProcessingChain
private JTableColumnWidthMonitor mTableColumnWidthMonitor; private JTableColumnWidthMonitor mTableColumnWidthMonitor;
private DecodeEventModel mEmptyDecodeEventModel; private DecodeEventModel mEmptyDecodeEventModel;
private JScrollPane mEmptyScroller; private JScrollPane mEmptyScroller;
private IconManager mIconManager; private IconModel mIconModel;
private AliasModel mAliasModel; private AliasModel mAliasModel;
private UserPreferences mUserPreferences; private UserPreferences mUserPreferences;
private TimestampCellRenderer mTimestampCellRenderer; private TimestampCellRenderer mTimestampCellRenderer;
/** /**
* View for call event table * View for call event table
* @param iconManager to display alias icons in table rows * @param iconModel to display alias icons in table rows
*/ */
public DecodeEventPanel(IconManager iconManager, UserPreferences userPreferences, AliasModel aliasModel) public DecodeEventPanel(IconModel iconModel, UserPreferences userPreferences, AliasModel aliasModel)
{ {
MyEventBus.getEventBus().register(this); MyEventBus.getEventBus().register(this);
setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]")); setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]"));
mIconManager = iconManager; mIconModel = iconModel;
mAliasModel = aliasModel; mAliasModel = aliasModel;
mUserPreferences = userPreferences; mUserPreferences = userPreferences;
mTimestampCellRenderer = new TimestampCellRenderer(); mTimestampCellRenderer = new TimestampCellRenderer();
@@ -270,7 +270,7 @@ public class DecodeEventPanel extends JPanel implements Listener<ProcessingChain
} }
sb.append(Joiner.on(", ").skipNulls().join(aliases)); sb.append(Joiner.on(", ").skipNulls().join(aliases));
color = aliases.get(0).getDisplayColor(); color = aliases.get(0).getDisplayColor();
icon = mIconManager.getIcon(aliases.get(0).getIconName(), IconManager.DEFAULT_ICON_SIZE); icon = mIconModel.getIcon(aliases.get(0).getIconName(), IconModel.DEFAULT_ICON_SIZE);
} }
} }

View File

@@ -33,7 +33,7 @@ import io.github.dsheirer.controller.channel.ChannelEvent;
import io.github.dsheirer.controller.channel.ChannelModel; import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.ChannelProcessingManager; import io.github.dsheirer.controller.channel.ChannelProcessingManager;
import io.github.dsheirer.controller.channel.map.ChannelMapModel; import io.github.dsheirer.controller.channel.map.ChannelMapModel;
import io.github.dsheirer.icon.IconManager; import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.module.log.EventLogManager; import io.github.dsheirer.module.log.EventLogManager;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.playlist.PlaylistPreference; import io.github.dsheirer.preference.playlist.PlaylistPreference;
@@ -67,7 +67,7 @@ public class PlaylistManager implements Listener<ChannelEvent>
private AliasModel mAliasModel; private AliasModel mAliasModel;
private ChannelMapModel mChannelMapModel = new ChannelMapModel(); private ChannelMapModel mChannelMapModel = new ChannelMapModel();
private IconManager mIconManager; private IconModel mIconModel;
private BroadcastModel mBroadcastModel; private BroadcastModel mBroadcastModel;
private ChannelModel mChannelModel; private ChannelModel mChannelModel;
@@ -90,14 +90,14 @@ public class PlaylistManager implements Listener<ChannelEvent>
* @param eventLogManager for event logging * @param eventLogManager for event logging
*/ */
public PlaylistManager(UserPreferences userPreferences, SourceManager sourceManager, AliasModel aliasModel, public PlaylistManager(UserPreferences userPreferences, SourceManager sourceManager, AliasModel aliasModel,
EventLogManager eventLogManager, IconManager iconManager) EventLogManager eventLogManager, IconModel iconModel)
{ {
mUserPreferences = userPreferences; mUserPreferences = userPreferences;
mSourceManager = sourceManager; mSourceManager = sourceManager;
mAliasModel = aliasModel; mAliasModel = aliasModel;
mIconManager = iconManager; mIconModel = iconModel;
mBroadcastModel = new BroadcastModel(mAliasModel, mIconManager, userPreferences); mBroadcastModel = new BroadcastModel(mAliasModel, mIconModel, userPreferences);
mRadioReference = new RadioReference(mUserPreferences); mRadioReference = new RadioReference(mUserPreferences);
mChannelModel = new ChannelModel(mAliasModel); mChannelModel = new ChannelModel(mAliasModel);
@@ -159,9 +159,9 @@ public class PlaylistManager implements Listener<ChannelEvent>
/** /**
* Icon manager * Icon manager
*/ */
public IconManager getIconManager() public IconModel getIconModel()
{ {
return mIconManager; return mIconModel;
} }
/** /**