#829 Integrates JMBE Creator with new user preferences editor for auto-downloading and compiling the JMBE library from within sdrtrunk. (#844)

Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
Denny Sheirer
2020-06-07 08:04:57 -04:00
committed by GitHub
parent a1e8c761ef
commit b22177ee17
29 changed files with 2260 additions and 77 deletions

View File

@@ -22,17 +22,28 @@ package io.github.dsheirer.gui.preference.decoder;
import com.google.common.eventbus.Subscribe;
import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.jmbe.JmbeCreator;
import io.github.dsheirer.jmbe.JmbeEditorRequest;
import io.github.dsheirer.jmbe.github.GitHub;
import io.github.dsheirer.jmbe.github.Release;
import io.github.dsheirer.jmbe.github.Version;
import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.decoder.JmbeLibraryPreference;
import io.github.dsheirer.util.ThreadPool;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import org.slf4j.Logger;
@@ -45,27 +56,64 @@ import java.nio.file.Path;
/**
* Preference settings for decoders
*/
public class JmbeLibraryPreferenceEditor extends HBox
public class JmbeLibraryPreferenceEditor extends VBox
{
private final static Logger mLog = LoggerFactory.getLogger(JmbeLibraryPreferenceEditor.class);
private static final String PATH_NOT_SET = "(not set)";
private JmbeLibraryPreference mJmbeLibraryPreference;
private static final String CREATE_LIBRARY = "Create Library";
private static final String CHECK_FOR_UPDATE = "Check For Library Update";
private static final String LIBRARY_NOT_SETUP = "None. Click Select or Create Library button to setup.";
private UserPreferences mUserPreferences;
private GridPane mEditorPane;
private Label mJmbeLibraryLabel;
private Button mPathToJmbeLibraryButton;
private Button mPathToJmbeLibraryResetButton;
private Label mJmbeVersionLabel;
private Label mPathToJmbeLibraryLabel;
private Button mSelectButton;
private Button mResetButton;
private Button mCreateButton;
private HBox mButtonsBox;
private CheckBox mAlertUserWhenMissingCheckBox;
public JmbeLibraryPreferenceEditor(UserPreferences userPreferences)
{
mJmbeLibraryPreference = userPreferences.getJmbeLibraryPreference();
mUserPreferences = userPreferences;
//Register to receive directory preference update notifications so we can update the path labels
MyEventBus.getEventBus().register(this);
HBox.setHgrow(getEditorPane(), Priority.ALWAYS);
getChildren().add(getEditorPane());
setPadding(new Insets(10,10,10,10));
setSpacing(10);
getChildren().addAll(getEditorPane(), getButtonsBox(), getAlertUserWhenMissingCheckBox());
}
private CheckBox getAlertUserWhenMissingCheckBox()
{
if(mAlertUserWhenMissingCheckBox == null)
{
mAlertUserWhenMissingCheckBox = new CheckBox("Alert when decoder requires missing JMBE library");
mAlertUserWhenMissingCheckBox.setSelected(mUserPreferences.getJmbeLibraryPreference()
.getAlertIfMissingLibraryRequired());
mAlertUserWhenMissingCheckBox.setOnAction(event -> {
boolean alert = mAlertUserWhenMissingCheckBox.isSelected();
mUserPreferences.getJmbeLibraryPreference().setAlertIfMissingLibraryRequired(alert);
});
}
return mAlertUserWhenMissingCheckBox;
}
private HBox getButtonsBox()
{
if(mButtonsBox == null)
{
mButtonsBox = new HBox();
mButtonsBox.setSpacing(10);
mButtonsBox.getChildren().addAll(getCreateButton(), getSelectButton(), getResetButton());
}
return mButtonsBox;
}
private GridPane getEditorPane()
@@ -73,85 +121,206 @@ public class JmbeLibraryPreferenceEditor extends HBox
if(mEditorPane == null)
{
mEditorPane = new GridPane();
mEditorPane.setPadding(new Insets(10, 10, 10, 10));
mEditorPane.setVgap(10);
mEditorPane.setHgap(10);
int row = 0;
GridPane.setMargin(getJmbeLibraryLabel(), new Insets(0, 10, 0, 0));
mEditorPane.add(getJmbeLibraryLabel(), 0, row);
mEditorPane.add(getJmbeLibraryLabel(), 0, row, 2, 1);
Label versionLabel = new Label("Current Version:");
GridPane.setHalignment(versionLabel, HPos.RIGHT);
mEditorPane.add(versionLabel, 0, ++row);
mEditorPane.add(getJmbeVersionLabel(), 1, row);
Label fileLabel = new Label("File:");
GridPane.setHalignment(fileLabel, HPos.RIGHT);
mEditorPane.add(fileLabel, 0, ++row);
GridPane.setMargin(getPathToJmbeLibraryLabel(), new Insets(0, 10, 0, 0));
mEditorPane.add(getPathToJmbeLibraryLabel(), 1, row);
GridPane.setMargin(getPathToJmbeLibraryButton(), new Insets(2, 10, 2, 0));
mEditorPane.add(getPathToJmbeLibraryButton(), 2, row);
GridPane.setMargin(getPathToJmbeLibraryResetButton(), new Insets(2, 0, 2, 0));
mEditorPane.add(getPathToJmbeLibraryResetButton(), 3, row++);
}
return mEditorPane;
}
private Button getCreateButton()
{
if(mCreateButton == null)
{
mCreateButton = new Button();
mCreateButton.setText(mUserPreferences.getJmbeLibraryPreference()
.getPathJmbeLibrary() != null ? CHECK_FOR_UPDATE : CREATE_LIBRARY);
mCreateButton.setOnAction(event -> checkForUpdatedLibrary());
}
return mCreateButton;
}
/**
* Checks for availability of an updated JMBE library
*/
private void checkForUpdatedLibrary()
{
ThreadPool.SCHEDULED.execute(() -> {
try
{
Version current = mUserPreferences.getJmbeLibraryPreference().getCurrentVersion();
final Release release = GitHub.getLatestRelease(JmbeCreator.GITHUB_JMBE_RELEASES_URL);
mLog.info("Checking for JMBE Library Updates ...");
mLog.info("Current: " + (current != null ? current.toString() : "empty"));
final boolean canUpdate = (release != null) && ((current == null) ||
(release.getVersion().compareTo(current) > 0));
if(release != null)
{
mLog.info("Available: " + release.getVersion().toString());
}
if(canUpdate)
{
mLog.info("JMBE Library update is available");
}
else
{
mLog.info("No JMBE library update is available at this time");
}
Platform.runLater(new Runnable()
{
@Override
public void run()
{
try
{
if(canUpdate)
{
String content = "JMBE library version " + release.getVersion().toString() +
" is available. Would you like to download the latest source code and " +
"create an updated JMBE library?";
Alert alert = new Alert(Alert.AlertType.INFORMATION, content, ButtonType.YES, ButtonType.NO);
alert.setResizable(true);
//Workaroud for dialog sizing issue on Windows
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.setTitle("JMBE Library Update Check");
alert.setHeaderText("Update is available");
alert.initOwner(getCreateButton().getScene().getWindow());
alert.showAndWait().ifPresent(buttonType -> {
if(buttonType == ButtonType.YES)
{
mLog.info("Posting JMBE editor request to event bus");
MyEventBus.getEventBus().post(new JmbeEditorRequest(release));
}
});
}
else
{
Alert alert = new Alert(Alert.AlertType.INFORMATION,
"No JMBE library update is available.", ButtonType.OK);
alert.setTitle("JMBE Library Update Check");
if(release != null)
{
alert.setHeaderText("No update available");
}
else
{
alert.setHeaderText("Unable to determine latest release version. Check network connection");
}
alert.initOwner(getCreateButton().getScene().getWindow());
alert.showAndWait();
}
}
catch(Throwable t)
{
mLog.error("Error during JavaFX portion of create library");
}
}
});
}
catch(Throwable t)
{
mLog.error("Error during create library", t);
}
});
}
private Label getJmbeLibraryLabel()
{
if(mJmbeLibraryLabel == null)
{
mJmbeLibraryLabel = new Label("JMBE Audio Library:");
mJmbeLibraryLabel = new Label("JMBE Audio Library");
}
return mJmbeLibraryLabel;
}
private Button getPathToJmbeLibraryButton()
private Label getJmbeVersionLabel()
{
if(mPathToJmbeLibraryButton == null)
if(mJmbeVersionLabel == null)
{
mPathToJmbeLibraryButton = new Button("Change...");
mPathToJmbeLibraryButton.setOnAction(new EventHandler<ActionEvent>()
mJmbeVersionLabel = new Label();
Version version = mUserPreferences.getJmbeLibraryPreference().getCurrentVersion();
if(version != null)
{
mJmbeVersionLabel.setText(version.toString());
}
else
{
mJmbeVersionLabel.setText(LIBRARY_NOT_SETUP);
}
}
return mJmbeVersionLabel;
}
private Button getSelectButton()
{
if(mSelectButton == null)
{
mSelectButton = new Button("Select...");
mSelectButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select JMBE Audio Library Location");
Stage stage = (Stage)getPathToJmbeLibraryButton().getScene().getWindow();
fileChooser.setInitialDirectory(mUserPreferences.getDirectoryPreference().getDefaultJmbeDirectory().toFile());
Stage stage = (Stage)getSelectButton().getScene().getWindow();
File selected = fileChooser.showOpenDialog(stage);
if(selected != null)
{
mJmbeLibraryPreference.setPathJmbeLibrary(selected.toPath());
mUserPreferences.getJmbeLibraryPreference().setPathJmbeLibrary(selected.toPath());
}
}
});
}
return mPathToJmbeLibraryButton;
return mSelectButton;
}
private Button getPathToJmbeLibraryResetButton()
private Button getResetButton()
{
if(mPathToJmbeLibraryResetButton == null)
if(mResetButton == null)
{
mPathToJmbeLibraryResetButton = new Button("Reset");
mPathToJmbeLibraryResetButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
mJmbeLibraryPreference.resetPathJmbeLibrary();
}
});
mResetButton = new Button("Reset");
mResetButton.setOnAction(event -> mUserPreferences.getJmbeLibraryPreference().resetPathJmbeLibrary());
}
return mPathToJmbeLibraryResetButton;
return mResetButton;
}
private Label getPathToJmbeLibraryLabel()
{
if(mPathToJmbeLibraryLabel == null)
{
Path path = mJmbeLibraryPreference.getPathJmbeLibrary();
Path path = mUserPreferences.getJmbeLibraryPreference().getPathJmbeLibrary();
mPathToJmbeLibraryLabel = new Label(path != null ? path.toString() : PATH_NOT_SET);
}
@@ -163,8 +332,14 @@ public class JmbeLibraryPreferenceEditor extends HBox
{
if(preferenceType != null && preferenceType == PreferenceType.JMBE_LIBRARY)
{
Path path = mJmbeLibraryPreference.getPathJmbeLibrary();
Path path = mUserPreferences.getJmbeLibraryPreference().getPathJmbeLibrary();
getPathToJmbeLibraryLabel().setText(path != null ? path.toString() : PATH_NOT_SET);
Version version = mUserPreferences.getJmbeLibraryPreference().getCurrentVersion();
getJmbeVersionLabel().setText(version != null ? version.toString() : LIBRARY_NOT_SETUP);
getCreateButton().setText(mUserPreferences.getJmbeLibraryPreference()
.getPathJmbeLibrary() != null ? CHECK_FOR_UPDATE : CREATE_LIBRARY);
getAlertUserWhenMissingCheckBox().setSelected(mUserPreferences.getJmbeLibraryPreference()
.getAlertIfMissingLibraryRequired());
}
}
}

View File

@@ -68,6 +68,11 @@ public class DirectoryPreferenceEditor extends HBox
private Button mResetEventLogsButton;
private Label mEventLogsPathLabel;
private Label mJmbeLabel;
private Button mChangeJmbeButton;
private Button mResetJmbeButton;
private Label mJmbePathLabel;
private Label mPlaylistLabel;
private Button mChangePlaylistButton;
private Button mResetPlaylistButton;
@@ -157,6 +162,19 @@ public class DirectoryPreferenceEditor extends HBox
mEditorPane.add(getResetEventLogsButton(), 3, row++);
GridPane.setMargin(getJmbeLabel(), new Insets(0, 10, 0, 0));
mEditorPane.add(getJmbeLabel(), 0, row);
GridPane.setMargin(getJmbePathLabel(), new Insets(0, 10, 0, 0));
mEditorPane.add(getJmbePathLabel(), 1, row);
GridPane.setMargin(getChangeJmbeButton(), new Insets(2, 10, 2, 0));
mEditorPane.add(getChangeJmbeButton(), 2, row);
GridPane.setMargin(getResetJmbeButton(), new Insets(2, 0, 2, 0));
mEditorPane.add(getResetJmbeButton(), 3, row++);
GridPane.setMargin(getPlaylistLabel(), new Insets(0, 10, 0, 0));
mEditorPane.add(getPlaylistLabel(), 0, row);
@@ -407,6 +425,71 @@ public class DirectoryPreferenceEditor extends HBox
return mEventLogsPathLabel;
}
private Label getJmbeLabel()
{
if(mJmbeLabel == null)
{
mJmbeLabel = new Label("JMBE Libraries");
}
return mJmbeLabel;
}
private Button getChangeJmbeButton()
{
if(mChangeJmbeButton == null)
{
mChangeJmbeButton = new Button("Change...");
mChangeJmbeButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select JMBE Folder");
directoryChooser.setInitialDirectory(mDirectoryPreference.getDirectoryJmbe().toFile());
Stage stage = (Stage)getChangeJmbeButton().getScene().getWindow();
File selected = directoryChooser.showDialog(stage);
if(selected != null)
{
mDirectoryPreference.setDirectoryJmbe(selected.toPath());
}
}
});
}
return mChangeJmbeButton;
}
private Button getResetJmbeButton()
{
if(mResetJmbeButton == null)
{
mResetJmbeButton = new Button("Reset");
mResetJmbeButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
mDirectoryPreference.resetDirectoryJmbe();
}
});
}
return mResetJmbeButton;
}
private Label getJmbePathLabel()
{
if(mJmbePathLabel == null)
{
mJmbePathLabel = new Label(mDirectoryPreference.getDirectoryJmbe().toString());
}
return mJmbePathLabel;
}
private Label getPlaylistLabel()
{
if(mPlaylistLabel == null)