#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.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();
}
/**

View File

@@ -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<BroadcastState> mBroadcastState = new SimpleObjectProperty<>();

View File

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

View File

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

View File

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

View File

@@ -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 <http://www.gnu.org/licenses/>
* * *****************************************************************************
* 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.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);
}
}

View File

@@ -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<Alias>
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<String> availableStreams = mPlaylistManager.getBroadcastModel().getBroadcastConfigurationNames();
Set<BroadcastChannel> 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<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()

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

View File

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

View File

@@ -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))
{

View File

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