From 01146a5624b9631a63853c2971fa84c864a4a750 Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Sat, 9 May 2020 13:47:39 +0000 Subject: [PATCH] #797 and #801 Code Review and Cleanup. (#807) Co-authored-by: Denny --- .../broadcast/BroadcastConfiguration.java | 5 +- .../audio/broadcast/ConfiguredBroadcast.java | 3 + .../v1/ShoutcastV1Configuration.java | 9 -- .../v2/ShoutcastV2Configuration.java | 10 +-- .../metadata/ChannelMetadataModel.java | 47 +++++----- .../metadata/ChannelMetadataPanel.java | 33 +++---- .../gui/playlist/alias/AliasItemEditor.java | 42 +++++---- .../channel/ChannelConfigurationEditor.java | 87 +++++++++++-------- .../playlist/radioreference/LoginDialog.java | 2 +- .../playlist/radioreference/SystemEditor.java | 10 +-- .../dsheirer/playlist/PlaylistManager.java | 9 +- 11 files changed, 126 insertions(+), 131 deletions(-) diff --git a/src/main/java/io/github/dsheirer/audio/broadcast/BroadcastConfiguration.java b/src/main/java/io/github/dsheirer/audio/broadcast/BroadcastConfiguration.java index f2ee82b8..674d897a 100644 --- a/src/main/java/io/github/dsheirer/audio/broadcast/BroadcastConfiguration.java +++ b/src/main/java/io/github/dsheirer/audio/broadcast/BroadcastConfiguration.java @@ -40,6 +40,8 @@ import javafx.beans.property.SimpleLongProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.util.Callback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -54,6 +56,7 @@ import java.net.SocketAddress; @JacksonXmlRootElement(localName = "stream") public abstract class BroadcastConfiguration { + private final static Logger mLog = LoggerFactory.getLogger(BroadcastConfiguration.class); // Static unique channel identifier tracking private static int UNIQUE_ID = 0; @@ -395,7 +398,7 @@ public abstract class BroadcastConfiguration @JsonIgnore public boolean isValid() { - return validProperty().get(); + return mValid.get(); } /** diff --git a/src/main/java/io/github/dsheirer/audio/broadcast/ConfiguredBroadcast.java b/src/main/java/io/github/dsheirer/audio/broadcast/ConfiguredBroadcast.java index 96a8a0ce..c1f4869b 100644 --- a/src/main/java/io/github/dsheirer/audio/broadcast/ConfiguredBroadcast.java +++ b/src/main/java/io/github/dsheirer/audio/broadcast/ConfiguredBroadcast.java @@ -28,12 +28,15 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.StringProperty; import javafx.util.Callback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Composite observable object that joins a broadcast configuration and (optional) constructed audio broadcaster */ public class ConfiguredBroadcast { + private final static Logger mLog = LoggerFactory.getLogger(ConfiguredBroadcast.class); private BroadcastConfiguration mBroadcastConfiguration; private AbstractAudioBroadcaster mAudioBroadcaster; private ObjectProperty mBroadcastState = new SimpleObjectProperty<>(); diff --git a/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v1/ShoutcastV1Configuration.java b/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v1/ShoutcastV1Configuration.java index 6c0cfba5..90875cad 100644 --- a/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v1/ShoutcastV1Configuration.java +++ b/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v1/ShoutcastV1Configuration.java @@ -164,13 +164,4 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration { mBitRate = bitRate; } - - @Override - public boolean isValid() - { - return getName() != null && !getName().isEmpty() && - getHost() != null && !getHost().isEmpty() && - getPort() > 0 && getPort() < 65535 && - getPassword() != null && !getPassword().isEmpty(); - } } diff --git a/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v2/ShoutcastV2Configuration.java b/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v2/ShoutcastV2Configuration.java index 5e832970..e32ffae1 100644 --- a/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v2/ShoutcastV2Configuration.java +++ b/src/main/java/io/github/dsheirer/audio/broadcast/shoutcast/v2/ShoutcastV2Configuration.java @@ -41,6 +41,7 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration public ShoutcastV2Configuration() { //No-arg JAXB constructor + this(BroadcastFormat.MP3); } public ShoutcastV2Configuration(BroadcastFormat format) @@ -203,13 +204,4 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration { return mURL != null && !mURL.isEmpty(); } - - @Override - public boolean isValid() - { - return super.isValid() && hasName() && - getUserID() != null && !getUserID().isEmpty() && - 1 <= getStreamID() && - getPassword() != null && !getPassword().isEmpty(); - } } diff --git a/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataModel.java b/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataModel.java index 2577c267..2b142889 100644 --- a/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataModel.java +++ b/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataModel.java @@ -72,31 +72,27 @@ public class ChannelMetadataModel extends AbstractTableModel implements IChannel { if(preferenceType == PreferenceType.TALKGROUP_FORMAT) { - for(int row = 0; row < mChannelMetadata.size(); row++) - { - fireTableCellUpdated(row, COLUMN_USER_FROM); - fireTableCellUpdated(row, COLUMN_USER_TO); - } + EventQueue.invokeLater(() -> { + for(int row = 0; row < mChannelMetadata.size(); row++) + { + fireTableCellUpdated(row, COLUMN_USER_FROM); + fireTableCellUpdated(row, COLUMN_USER_TO); + } + }); } } - public void add(Collection channelMetadatas, Channel channel) { //Execute on the swing thread to avoid threading issues - EventQueue.invokeLater(new Runnable() - { - @Override - public void run() + EventQueue.invokeLater(() -> { + for(ChannelMetadata channelMetadata: channelMetadatas) { - for(ChannelMetadata channelMetadata: channelMetadatas) - { - mChannelMetadata.add(channelMetadata); - mMetadataChannelMap.put(channelMetadata, channel); - int index = mChannelMetadata.indexOf(channelMetadata); - fireTableRowsInserted(index, index); - channelMetadata.setUpdateEventListener(ChannelMetadataModel.this); - } + mChannelMetadata.add(channelMetadata); + mMetadataChannelMap.put(channelMetadata, channel); + int index = mChannelMetadata.indexOf(channelMetadata); + fireTableRowsInserted(index, index); + channelMetadata.setUpdateEventListener(ChannelMetadataModel.this); } }); } @@ -104,15 +100,14 @@ public class ChannelMetadataModel extends AbstractTableModel implements IChannel public void remove(ChannelMetadata channelMetadata) { //Execute on the swing thread to avoid threading issues - EventQueue.invokeLater(new Runnable() - { - @Override - public void run() + EventQueue.invokeLater(() -> { + channelMetadata.removeUpdateEventListener(); + int index = mChannelMetadata.indexOf(channelMetadata); + mChannelMetadata.remove(channelMetadata); + mMetadataChannelMap.remove(channelMetadata); + + if(index >= 0) { - channelMetadata.removeUpdateEventListener(); - int index = mChannelMetadata.indexOf(channelMetadata); - mChannelMetadata.remove(channelMetadata); - mMetadataChannelMap.remove(channelMetadata); fireTableRowsDeleted(index, index); } }); diff --git a/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataPanel.java b/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataPanel.java index 270392bb..4043c540 100644 --- a/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataPanel.java +++ b/src/main/java/io/github/dsheirer/channel/metadata/ChannelMetadataPanel.java @@ -1,24 +1,22 @@ /* + * ***************************************************************************** + * Copyright (C) 2014-2020 Dennis Sheirer * - * * ****************************************************************************** - * * Copyright (C) 2014-2019 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 - * * ***************************************************************************** + * 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 + * **************************************************************************** */ + package io.github.dsheirer.channel.metadata; import com.google.common.base.Joiner; @@ -169,9 +167,6 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene { Channel selectedChannel = mChannelProcessingManager.getChannelMetadataModel() .getChannelFromMetadata(selectedMetadata); - - - processingChain = mChannelProcessingManager.getProcessingChain(selectedChannel); } } diff --git a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasItemEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasItemEditor.java index 46a9b251..b10d5540 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasItemEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasItemEditor.java @@ -63,6 +63,7 @@ import io.github.dsheirer.preference.PreferenceType; import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.identifier.IntegerFormat; import io.github.dsheirer.protocol.Protocol; +import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -768,28 +769,35 @@ public class AliasItemEditor extends Editor private void updateStreamViews() { - getAvailableStreamsView().getItems().clear(); - getSelectedStreamsView().getItems().clear(); - getAvailableStreamsView().setDisable(getItem() == null); - getSelectedStreamsView().setDisable(getItem() == null); - - if(getItem() != null) + Platform.runLater(new Runnable() { - List availableStreams = mPlaylistManager.getBroadcastModel().getBroadcastConfigurationNames(); - - Set selectedChannels = getItem().getBroadcastChannels(); - - for(BroadcastChannel channel: selectedChannels) + @Override + public void run() { - if(availableStreams.contains(channel.getChannelName())) + getAvailableStreamsView().getItems().clear(); + getSelectedStreamsView().getItems().clear(); + getAvailableStreamsView().setDisable(getItem() == null); + getSelectedStreamsView().setDisable(getItem() == null); + + if(getItem() != null) { - availableStreams.remove(channel.getChannelName()); + List availableStreams = mPlaylistManager.getBroadcastModel().getBroadcastConfigurationNames(); + + Set selectedChannels = getItem().getBroadcastChannels(); + + for(BroadcastChannel channel: selectedChannels) + { + if(availableStreams.contains(channel.getChannelName())) + { + availableStreams.remove(channel.getChannelName()); + } + } + + getSelectedStreamsView().getItems().addAll(selectedChannels); + getAvailableStreamsView().getItems().addAll(availableStreams); } } - - getSelectedStreamsView().getItems().addAll(selectedChannels); - getAvailableStreamsView().getItems().addAll(availableStreams); - } + }); } private ListView getAvailableStreamsView() diff --git a/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelConfigurationEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelConfigurationEditor.java index ae39a60b..0ef6a417 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelConfigurationEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelConfigurationEditor.java @@ -36,6 +36,8 @@ import io.github.dsheirer.record.config.RecordConfiguration; import io.github.dsheirer.source.config.SourceConfigTuner; import io.github.dsheirer.source.config.SourceConfiguration; import io.github.dsheirer.source.tuner.TunerModel; +import io.github.dsheirer.util.ThreadPool; +import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.transformation.FilteredList; @@ -300,51 +302,62 @@ public abstract class ChannelConfigurationEditor extends Editor mPlayButton.setOnAction((ActionEvent event) -> { if(getItem() != null) { - if(getItem().processingProperty().get()) + if(modifiedProperty().get()) { - try - { - mPlaylistManager.getChannelProcessingManager().stop(getItem()); - } - catch(ChannelException ce) - { - mLog.error("Error stopping channel [" + getItem().getName() + "] - " + ce.getMessage()); + Alert alert = new Alert(Alert.AlertType.WARNING, + "Do you want to save these changes?", ButtonType.YES, ButtonType.NO); + alert.setTitle("Channel Configuration Modified"); + alert.setHeaderText("Channel configuration has unsaved changes"); + alert.initOwner((getPlayButton()).getScene().getWindow()); + alert.showAndWait().ifPresent(buttonType -> { + if(buttonType == ButtonType.YES) + { + save(); + } + }); + } - Alert alert = new Alert(Alert.AlertType.ERROR, "Error: " + ce.getMessage(), ButtonType.OK); - alert.setTitle("Channel Stop Error"); - alert.setHeaderText("Can't stop channel"); - alert.initOwner((getPlayButton()).getScene().getWindow()); - alert.showAndWait(); - } + if(!getItem().processingProperty().get()) + { + ThreadPool.SCHEDULED.execute(() -> { + try + { + mPlaylistManager.getChannelProcessingManager().start(getItem()); + } + catch(ChannelException ce) + { + mLog.error("Error starting channel [" + getItem().getName() + "] - " + ce.getMessage()); + + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.ERROR, "Error: " + ce.getMessage(), ButtonType.OK); + alert.setTitle("Channel Play Error"); + alert.setHeaderText("Can't play channel"); + alert.initOwner((getPlayButton()).getScene().getWindow()); + alert.showAndWait(); + }); + } + }); } else { - try - { - if(modifiedProperty().get()) + ThreadPool.SCHEDULED.execute(() -> { + try { - Alert alert = new Alert(Alert.AlertType.WARNING, - "Do you want to save these changes before play?", ButtonType.YES, ButtonType.NO); - alert.setTitle("Channel Configuration Modified"); - alert.setHeaderText("Channel configuration has unsaved changes"); - alert.initOwner((getPlayButton()).getScene().getWindow()); - alert.showAndWait().ifPresent(buttonType -> { - if(buttonType == ButtonType.YES) - { - save(); - } + mPlaylistManager.getChannelProcessingManager().stop(getItem()); + } + catch(ChannelException ce) + { + mLog.error("Error stopping channel [" + getItem().getName() + "] - " + ce.getMessage()); + + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.ERROR, "Error: " + ce.getMessage(), ButtonType.OK); + alert.setTitle("Channel Stop Error"); + alert.setHeaderText("Can't stop channel"); + alert.initOwner((getPlayButton()).getScene().getWindow()); + alert.showAndWait(); }); } - mPlaylistManager.getChannelProcessingManager().start(getItem()); - } - catch(ChannelException ce) - { - Alert alert = new Alert(Alert.AlertType.ERROR, "Error: " + ce.getMessage(), ButtonType.OK); - alert.setTitle("Channel Play Error"); - alert.setHeaderText("Can't play channel"); - alert.initOwner((getPlayButton()).getScene().getWindow()); - alert.showAndWait(); - } + }); } } }); diff --git a/src/main/java/io/github/dsheirer/gui/playlist/radioreference/LoginDialog.java b/src/main/java/io/github/dsheirer/gui/playlist/radioreference/LoginDialog.java index 919fdb5b..ed081631 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/radioreference/LoginDialog.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/radioreference/LoginDialog.java @@ -75,7 +75,7 @@ public class LoginDialog extends Dialog { mUserPreferences = userPreferences; - setTitle("Radio Reference Login"); + setTitle("sdrtrunk - Radio Reference"); final DialogPane dialogPane = getDialogPane(); dialogPane.setContent(getGridPane()); dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); diff --git a/src/main/java/io/github/dsheirer/gui/playlist/radioreference/SystemEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/radioreference/SystemEditor.java index 2cd36ac1..4590d66b 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/radioreference/SystemEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/radioreference/SystemEditor.java @@ -323,14 +323,13 @@ public class SystemEditor extends VBox private HBox mHBox; private Label mName; private Label mProtocol; - private Label mIdLabel; private IconNode mIconNode; public SystemListCell() { mHBox = new HBox(); mHBox.setSpacing(15); - mHBox.setPadding(new Insets(0,30,0,0)); + mHBox.setPadding(new Insets(0,15,0,0)); mHBox.setMaxWidth(Double.MAX_VALUE); mName = new Label(); mName.setMaxWidth(Double.MAX_VALUE); @@ -339,12 +338,9 @@ public class SystemEditor extends VBox mProtocol.setMaxWidth(Double.MAX_VALUE); mProtocol.setAlignment(Pos.CENTER_RIGHT); mProtocol.setContentDisplay(ContentDisplay.RIGHT); - mIdLabel = new Label(); - mIdLabel.setAlignment(Pos.CENTER_RIGHT); - mIdLabel.setContentDisplay(ContentDisplay.RIGHT); HBox.setHgrow(mName, Priority.ALWAYS); HBox.setHgrow(mProtocol, Priority.ALWAYS); - mHBox.getChildren().addAll(mName, mProtocol, mIdLabel); + mHBox.getChildren().addAll(mName, mProtocol); } @Override @@ -359,13 +355,11 @@ public class SystemEditor extends VBox setGraphic(null); mName.setText(null); mProtocol.setText(null); - mIdLabel.setText(null); } else { mName.setText(item.getName()); mProtocol.setText(getType(item)); - mIdLabel.setText("ID:" + item.getSystemId()); if(isSupported(item)) { diff --git a/src/main/java/io/github/dsheirer/playlist/PlaylistManager.java b/src/main/java/io/github/dsheirer/playlist/PlaylistManager.java index 1e883f69..14d0278a 100644 --- a/src/main/java/io/github/dsheirer/playlist/PlaylistManager.java +++ b/src/main/java/io/github/dsheirer/playlist/PlaylistManager.java @@ -52,6 +52,7 @@ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -383,10 +384,10 @@ public class PlaylistManager implements Listener PlaylistV2 playlist = new PlaylistV2(); - playlist.setAliases(mAliasModel.getAliases()); - playlist.setBroadcastConfigurations(mBroadcastModel.getBroadcastConfigurations()); - playlist.setChannels(mChannelModel.getChannels()); - playlist.setChannelMaps(mChannelMapModel.getChannelMaps()); + playlist.setAliases(new ArrayList(mAliasModel.getAliases())); + playlist.setBroadcastConfigurations(new ArrayList(mBroadcastModel.getBroadcastConfigurations())); + playlist.setChannels(new ArrayList(mChannelModel.getChannels())); + playlist.setChannelMaps(new ArrayList(mChannelMapModel.getChannelMaps())); playlist.setVersion(PLAYLIST_CURRENT_VERSION); //Create a backup copy of the current playlist