#797 and #801 Code Review and Cleanup. (#807)

Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
Denny Sheirer
2020-05-09 13:47:39 +00:00
committed by GitHub
parent 316cdb4068
commit 01146a5624
11 changed files with 126 additions and 131 deletions

View File

@@ -40,6 +40,8 @@ import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.util.Callback; import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
@@ -54,6 +56,7 @@ import java.net.SocketAddress;
@JacksonXmlRootElement(localName = "stream") @JacksonXmlRootElement(localName = "stream")
public abstract class BroadcastConfiguration public abstract class BroadcastConfiguration
{ {
private final static Logger mLog = LoggerFactory.getLogger(BroadcastConfiguration.class);
// Static unique channel identifier tracking // Static unique channel identifier tracking
private static int UNIQUE_ID = 0; private static int UNIQUE_ID = 0;
@@ -395,7 +398,7 @@ public abstract class BroadcastConfiguration
@JsonIgnore @JsonIgnore
public boolean isValid() public boolean isValid()
{ {
return validProperty().get(); return mValid.get();
} }
/** /**

View File

@@ -28,12 +28,15 @@ import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.util.Callback; 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 * Composite observable object that joins a broadcast configuration and (optional) constructed audio broadcaster
*/ */
public class ConfiguredBroadcast public class ConfiguredBroadcast
{ {
private final static Logger mLog = LoggerFactory.getLogger(ConfiguredBroadcast.class);
private BroadcastConfiguration mBroadcastConfiguration; private BroadcastConfiguration mBroadcastConfiguration;
private AbstractAudioBroadcaster mAudioBroadcaster; private AbstractAudioBroadcaster mAudioBroadcaster;
private ObjectProperty<BroadcastState> mBroadcastState = new SimpleObjectProperty<>(); private ObjectProperty<BroadcastState> mBroadcastState = new SimpleObjectProperty<>();

View File

@@ -164,13 +164,4 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
{ {
mBitRate = bitRate; mBitRate = bitRate;
} }
@Override
public boolean isValid()
{
return getName() != null && !getName().isEmpty() &&
getHost() != null && !getHost().isEmpty() &&
getPort() > 0 && getPort() < 65535 &&
getPassword() != null && !getPassword().isEmpty();
}
} }

View File

@@ -41,6 +41,7 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
public ShoutcastV2Configuration() public ShoutcastV2Configuration()
{ {
//No-arg JAXB constructor //No-arg JAXB constructor
this(BroadcastFormat.MP3);
} }
public ShoutcastV2Configuration(BroadcastFormat format) public ShoutcastV2Configuration(BroadcastFormat format)
@@ -203,13 +204,4 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
{ {
return mURL != null && !mURL.isEmpty(); return mURL != null && !mURL.isEmpty();
} }
@Override
public boolean isValid()
{
return super.isValid() && hasName() &&
getUserID() != null && !getUserID().isEmpty() &&
1 <= getStreamID() &&
getPassword() != null && !getPassword().isEmpty();
}
} }

View File

@@ -72,31 +72,27 @@ public class ChannelMetadataModel extends AbstractTableModel implements IChannel
{ {
if(preferenceType == PreferenceType.TALKGROUP_FORMAT) if(preferenceType == PreferenceType.TALKGROUP_FORMAT)
{ {
for(int row = 0; row < mChannelMetadata.size(); row++) EventQueue.invokeLater(() -> {
{ for(int row = 0; row < mChannelMetadata.size(); row++)
fireTableCellUpdated(row, COLUMN_USER_FROM); {
fireTableCellUpdated(row, COLUMN_USER_TO); fireTableCellUpdated(row, COLUMN_USER_FROM);
} fireTableCellUpdated(row, COLUMN_USER_TO);
}
});
} }
} }
public void add(Collection<ChannelMetadata> channelMetadatas, Channel channel) public void add(Collection<ChannelMetadata> channelMetadatas, Channel channel)
{ {
//Execute on the swing thread to avoid threading issues //Execute on the swing thread to avoid threading issues
EventQueue.invokeLater(new Runnable() EventQueue.invokeLater(() -> {
{ for(ChannelMetadata channelMetadata: channelMetadatas)
@Override
public void run()
{ {
for(ChannelMetadata channelMetadata: channelMetadatas) mChannelMetadata.add(channelMetadata);
{ mMetadataChannelMap.put(channelMetadata, channel);
mChannelMetadata.add(channelMetadata); int index = mChannelMetadata.indexOf(channelMetadata);
mMetadataChannelMap.put(channelMetadata, channel); fireTableRowsInserted(index, index);
int index = mChannelMetadata.indexOf(channelMetadata); channelMetadata.setUpdateEventListener(ChannelMetadataModel.this);
fireTableRowsInserted(index, index);
channelMetadata.setUpdateEventListener(ChannelMetadataModel.this);
}
} }
}); });
} }
@@ -104,15 +100,14 @@ public class ChannelMetadataModel extends AbstractTableModel implements IChannel
public void remove(ChannelMetadata channelMetadata) public void remove(ChannelMetadata channelMetadata)
{ {
//Execute on the swing thread to avoid threading issues //Execute on the swing thread to avoid threading issues
EventQueue.invokeLater(new Runnable() EventQueue.invokeLater(() -> {
{ channelMetadata.removeUpdateEventListener();
@Override int index = mChannelMetadata.indexOf(channelMetadata);
public void run() 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); fireTableRowsDeleted(index, index);
} }
}); });

View File

@@ -1,24 +1,22 @@
/* /*
* *****************************************************************************
* Copyright (C) 2014-2020 Dennis Sheirer
* *
* * ****************************************************************************** * This program is free software: you can redistribute it and/or modify
* * Copyright (C) 2014-2019 Dennis Sheirer * it under the terms of the GNU General Public License as published by
* * * the Free Software Foundation, either version 3 of the License, or
* * This program is free software: you can redistribute it and/or modify * (at your option) any later version.
* * 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/>
* * *****************************************************************************
* *
* 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.channel.metadata; package io.github.dsheirer.channel.metadata;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@@ -169,9 +167,6 @@ public class ChannelMetadataPanel extends JPanel implements ListSelectionListene
{ {
Channel selectedChannel = mChannelProcessingManager.getChannelMetadataModel() Channel selectedChannel = mChannelProcessingManager.getChannelMetadataModel()
.getChannelFromMetadata(selectedMetadata); .getChannelFromMetadata(selectedMetadata);
processingChain = mChannelProcessingManager.getProcessingChain(selectedChannel); processingChain = mChannelProcessingManager.getProcessingChain(selectedChannel);
} }
} }

View File

@@ -63,6 +63,7 @@ import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.preference.UserPreferences; import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.identifier.IntegerFormat; import io.github.dsheirer.preference.identifier.IntegerFormat;
import io.github.dsheirer.protocol.Protocol; import io.github.dsheirer.protocol.Protocol;
import javafx.application.Platform;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
@@ -768,28 +769,35 @@ public class AliasItemEditor extends Editor<Alias>
private void updateStreamViews() private void updateStreamViews()
{ {
getAvailableStreamsView().getItems().clear(); Platform.runLater(new Runnable()
getSelectedStreamsView().getItems().clear();
getAvailableStreamsView().setDisable(getItem() == null);
getSelectedStreamsView().setDisable(getItem() == null);
if(getItem() != null)
{ {
List<String> availableStreams = mPlaylistManager.getBroadcastModel().getBroadcastConfigurationNames(); @Override
public void run()
Set<BroadcastChannel> selectedChannels = getItem().getBroadcastChannels();
for(BroadcastChannel channel: selectedChannels)
{ {
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<String> availableStreams = mPlaylistManager.getBroadcastModel().getBroadcastConfigurationNames();
Set<BroadcastChannel> 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<String> getAvailableStreamsView() private ListView<String> getAvailableStreamsView()

View File

@@ -36,6 +36,8 @@ import io.github.dsheirer.record.config.RecordConfiguration;
import io.github.dsheirer.source.config.SourceConfigTuner; import io.github.dsheirer.source.config.SourceConfigTuner;
import io.github.dsheirer.source.config.SourceConfiguration; import io.github.dsheirer.source.config.SourceConfiguration;
import io.github.dsheirer.source.tuner.TunerModel; 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.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.FilteredList;
@@ -300,51 +302,62 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
mPlayButton.setOnAction((ActionEvent event) -> { mPlayButton.setOnAction((ActionEvent event) -> {
if(getItem() != null) if(getItem() != null)
{ {
if(getItem().processingProperty().get()) if(modifiedProperty().get())
{ {
try Alert alert = new Alert(Alert.AlertType.WARNING,
{ "Do you want to save these changes?", ButtonType.YES, ButtonType.NO);
mPlaylistManager.getChannelProcessingManager().stop(getItem()); alert.setTitle("Channel Configuration Modified");
} alert.setHeaderText("Channel configuration has unsaved changes");
catch(ChannelException ce) alert.initOwner((getPlayButton()).getScene().getWindow());
{ alert.showAndWait().ifPresent(buttonType -> {
mLog.error("Error stopping channel [" + getItem().getName() + "] - " + ce.getMessage()); if(buttonType == ButtonType.YES)
{
save();
}
});
}
Alert alert = new Alert(Alert.AlertType.ERROR, "Error: " + ce.getMessage(), ButtonType.OK); if(!getItem().processingProperty().get())
alert.setTitle("Channel Stop Error"); {
alert.setHeaderText("Can't stop channel"); ThreadPool.SCHEDULED.execute(() -> {
alert.initOwner((getPlayButton()).getScene().getWindow()); try
alert.showAndWait(); {
} 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 else
{ {
try ThreadPool.SCHEDULED.execute(() -> {
{ try
if(modifiedProperty().get())
{ {
Alert alert = new Alert(Alert.AlertType.WARNING, mPlaylistManager.getChannelProcessingManager().stop(getItem());
"Do you want to save these changes before play?", ButtonType.YES, ButtonType.NO); }
alert.setTitle("Channel Configuration Modified"); catch(ChannelException ce)
alert.setHeaderText("Channel configuration has unsaved changes"); {
alert.initOwner((getPlayButton()).getScene().getWindow()); mLog.error("Error stopping channel [" + getItem().getName() + "] - " + ce.getMessage());
alert.showAndWait().ifPresent(buttonType -> {
if(buttonType == ButtonType.YES) Platform.runLater(() -> {
{ Alert alert = new Alert(Alert.AlertType.ERROR, "Error: " + ce.getMessage(), ButtonType.OK);
save(); 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();
}
} }
} }
}); });

View File

@@ -75,7 +75,7 @@ public class LoginDialog extends Dialog<AuthorizationInformation>
{ {
mUserPreferences = userPreferences; mUserPreferences = userPreferences;
setTitle("Radio Reference Login"); setTitle("sdrtrunk - Radio Reference");
final DialogPane dialogPane = getDialogPane(); final DialogPane dialogPane = getDialogPane();
dialogPane.setContent(getGridPane()); dialogPane.setContent(getGridPane());
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

View File

@@ -323,14 +323,13 @@ public class SystemEditor extends VBox
private HBox mHBox; private HBox mHBox;
private Label mName; private Label mName;
private Label mProtocol; private Label mProtocol;
private Label mIdLabel;
private IconNode mIconNode; private IconNode mIconNode;
public SystemListCell() public SystemListCell()
{ {
mHBox = new HBox(); mHBox = new HBox();
mHBox.setSpacing(15); mHBox.setSpacing(15);
mHBox.setPadding(new Insets(0,30,0,0)); mHBox.setPadding(new Insets(0,15,0,0));
mHBox.setMaxWidth(Double.MAX_VALUE); mHBox.setMaxWidth(Double.MAX_VALUE);
mName = new Label(); mName = new Label();
mName.setMaxWidth(Double.MAX_VALUE); mName.setMaxWidth(Double.MAX_VALUE);
@@ -339,12 +338,9 @@ public class SystemEditor extends VBox
mProtocol.setMaxWidth(Double.MAX_VALUE); mProtocol.setMaxWidth(Double.MAX_VALUE);
mProtocol.setAlignment(Pos.CENTER_RIGHT); mProtocol.setAlignment(Pos.CENTER_RIGHT);
mProtocol.setContentDisplay(ContentDisplay.RIGHT); mProtocol.setContentDisplay(ContentDisplay.RIGHT);
mIdLabel = new Label();
mIdLabel.setAlignment(Pos.CENTER_RIGHT);
mIdLabel.setContentDisplay(ContentDisplay.RIGHT);
HBox.setHgrow(mName, Priority.ALWAYS); HBox.setHgrow(mName, Priority.ALWAYS);
HBox.setHgrow(mProtocol, Priority.ALWAYS); HBox.setHgrow(mProtocol, Priority.ALWAYS);
mHBox.getChildren().addAll(mName, mProtocol, mIdLabel); mHBox.getChildren().addAll(mName, mProtocol);
} }
@Override @Override
@@ -359,13 +355,11 @@ public class SystemEditor extends VBox
setGraphic(null); setGraphic(null);
mName.setText(null); mName.setText(null);
mProtocol.setText(null); mProtocol.setText(null);
mIdLabel.setText(null);
} }
else else
{ {
mName.setText(item.getName()); mName.setText(item.getName());
mProtocol.setText(getType(item)); mProtocol.setText(getType(item));
mIdLabel.setText("ID:" + item.getSystemId());
if(isSupported(item)) if(isSupported(item))
{ {

View File

@@ -52,6 +52,7 @@ 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.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@@ -383,10 +384,10 @@ public class PlaylistManager implements Listener<ChannelEvent>
PlaylistV2 playlist = new PlaylistV2(); PlaylistV2 playlist = new PlaylistV2();
playlist.setAliases(mAliasModel.getAliases()); playlist.setAliases(new ArrayList(mAliasModel.getAliases()));
playlist.setBroadcastConfigurations(mBroadcastModel.getBroadcastConfigurations()); playlist.setBroadcastConfigurations(new ArrayList(mBroadcastModel.getBroadcastConfigurations()));
playlist.setChannels(mChannelModel.getChannels()); playlist.setChannels(new ArrayList(mChannelModel.getChannels()));
playlist.setChannelMaps(mChannelMapModel.getChannelMaps()); playlist.setChannelMaps(new ArrayList(mChannelMapModel.getChannelMaps()));
playlist.setVersion(PLAYLIST_CURRENT_VERSION); playlist.setVersion(PLAYLIST_CURRENT_VERSION);
//Create a backup copy of the current playlist //Create a backup copy of the current playlist