Code cleanup.

This commit is contained in:
Dennis Sheirer
2021-11-14 07:57:14 -05:00
parent 87e9bf8749
commit 560cbad5d7
2 changed files with 141 additions and 123 deletions

View File

@@ -1,6 +1,6 @@
/* /*
* ***************************************************************************** * *****************************************************************************
* Copyright (C) 2014-2020 Dennis Sheirer * Copyright (C) 2014-2021 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
@@ -71,6 +71,7 @@ public class AliasBulkEditor extends Editor<List<Alias>>
/** /**
* Constructs an instance * Constructs an instance
*
* @param playlistManager for accessing icon manager * @param playlistManager for accessing icon manager
*/ */
public AliasBulkEditor(PlaylistManager playlistManager) public AliasBulkEditor(PlaylistManager playlistManager)
@@ -174,12 +175,15 @@ public class AliasBulkEditor extends Editor<List<Alias>>
/** /**
* Property indicating whether a bulk change is in progress. Bulk changes may cause drastic * Property indicating whether a bulk change is in progress. Bulk changes may cause drastic
* slow downs in some UI components. * slow downs in some UI components.
*
* @return changeInProgressProperty * @return changeInProgressProperty
*/ */
public ReadOnlyBooleanProperty changeInProgressProperty() public ReadOnlyBooleanProperty changeInProgressProperty()
{ {
if(mChangeInProgressROProperty == null) if(mChangeInProgressROProperty == null)
{
mChangeInProgressROProperty = BooleanProperty.readOnlyBooleanProperty(mChangeInProgressProperty); mChangeInProgressROProperty = BooleanProperty.readOnlyBooleanProperty(mChangeInProgressProperty);
}
return mChangeInProgressROProperty; return mChangeInProgressROProperty;
} }
@@ -221,7 +225,8 @@ public class AliasBulkEditor extends Editor<List<Alias>>
if(mApplyColorButton == null) if(mApplyColorButton == null)
{ {
mApplyColorButton = new Button("Apply"); mApplyColorButton = new Button("Apply");
mApplyColorButton.setOnAction(event -> { mApplyColorButton.setOnAction(event ->
{
startChange(); startChange();
int colorValue = ColorUtil.toInteger(getColorPicker().getValue()); int colorValue = ColorUtil.toInteger(getColorPicker().getValue());
@@ -243,7 +248,8 @@ public class AliasBulkEditor extends Editor<List<Alias>>
if(mResetColorButton == null) if(mResetColorButton == null)
{ {
mResetColorButton = new Button("Reset Color"); mResetColorButton = new Button("Reset Color");
mResetColorButton.setOnAction(event -> { mResetColorButton.setOnAction(event ->
{
startChange(); startChange();
for(Alias alias : getItem()) for(Alias alias : getItem())
@@ -341,6 +347,7 @@ public class AliasBulkEditor extends Editor<List<Alias>>
} }
private static int setCount = 0; private static int setCount = 0;
private Button getApplyMonitorButton() private Button getApplyMonitorButton()
{ {
if(mApplyMonitorButton == null) if(mApplyMonitorButton == null)

View File

@@ -1,23 +1,20 @@
/* /*
* *****************************************************************************
* Copyright (C) 2014-2021 Dennis Sheirer
* *
* * ****************************************************************************** * This program is free software: you can redistribute it and/or modify
* * Copyright (C) 2014-2020 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.gui.playlist.alias; package io.github.dsheirer.gui.playlist.alias;
@@ -125,8 +122,9 @@ public class AliasConfigurationEditor extends SplitPane
/** /**
* Request to show the specified alias in the editor. * Request to show the specified alias in the editor.
* * <p>
* Note: this must be called on the FX platform thread * Note: this must be called on the FX platform thread
*
* @param alias to show * @param alias to show
*/ */
public void show(Alias alias) public void show(Alias alias)
@@ -175,7 +173,8 @@ public class AliasConfigurationEditor extends SplitPane
//Workaround for JavaFX KDE on Linux bug in FX 10/11: https://bugs.openjdk.java.net/browse/JDK-8179073 //Workaround for JavaFX KDE on Linux bug in FX 10/11: https://bugs.openjdk.java.net/browse/JDK-8179073
alert.setResizable(true); alert.setResizable(true);
alert.onShownProperty().addListener(e -> { alert.onShownProperty().addListener(e ->
{
Platform.runLater(() -> alert.setResizable(false)); Platform.runLater(() -> alert.setResizable(false));
}); });
@@ -293,7 +292,8 @@ public class AliasConfigurationEditor extends SplitPane
{ {
mAliasListNameComboBox = new ComboBox<>(mPlaylistManager.getAliasModel().aliasListNames()); mAliasListNameComboBox = new ComboBox<>(mPlaylistManager.getAliasModel().aliasListNames());
mAliasListNameComboBox.getSelectionModel().selectedItemProperty() mAliasListNameComboBox.getSelectionModel().selectedItemProperty()
.addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) ->
{
getNewAliasButton().setDisable(newValue == null || newValue.contentEquals(AliasModel.NO_ALIAS_LIST)); getNewAliasButton().setDisable(newValue == null || newValue.contentEquals(AliasModel.NO_ALIAS_LIST));
update(); update();
}); });
@@ -323,7 +323,8 @@ public class AliasConfigurationEditor extends SplitPane
if(mNewAliasListButton == null) if(mNewAliasListButton == null)
{ {
mNewAliasListButton = new Button("New Alias List"); mNewAliasListButton = new Button("New Alias List");
mNewAliasListButton.setOnAction(event -> { mNewAliasListButton.setOnAction(event ->
{
TextInputDialog dialog = new TextInputDialog(); TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Create New Alias List"); dialog.setTitle("Create New Alias List");
dialog.setHeaderText("Please enter an alias list name (max 25 chars)."); dialog.setHeaderText("Please enter an alias list name (max 25 chars).");
@@ -331,7 +332,8 @@ public class AliasConfigurationEditor extends SplitPane
dialog.getEditor().setTextFormatter(new TextFormatter<String>(new MaxLengthUnaryOperator(25))); dialog.getEditor().setTextFormatter(new TextFormatter<String>(new MaxLengthUnaryOperator(25)));
Optional<String> result = dialog.showAndWait(); Optional<String> result = dialog.showAndWait();
result.ifPresent(s -> { result.ifPresent(s ->
{
String name = result.get(); String name = result.get();
if(name != null && !name.isEmpty()) if(name != null && !name.isEmpty())
@@ -389,7 +391,8 @@ public class AliasConfigurationEditor extends SplitPane
TableColumn<Alias, Boolean> errorsColumn = new TableColumn<>("Error"); TableColumn<Alias, Boolean> errorsColumn = new TableColumn<>("Error");
errorsColumn.setPrefWidth(80); errorsColumn.setPrefWidth(80);
errorsColumn.setCellValueFactory(new PropertyValueFactory<>("overlap")); errorsColumn.setCellValueFactory(new PropertyValueFactory<>("overlap"));
errorsColumn.setCellFactory(param -> { errorsColumn.setCellFactory(param ->
{
TableCell<Alias, Boolean> tableCell = new TableCell<>() TableCell<Alias, Boolean> tableCell = new TableCell<>()
{ {
@Override @Override
@@ -422,7 +425,8 @@ public class AliasConfigurationEditor extends SplitPane
mAliasTableView.setPlaceholder(getPlaceholderLabel()); mAliasTableView.setPlaceholder(getPlaceholderLabel());
mAliasTableView.setItems(getAliasSortedList()); mAliasTableView.setItems(getAliasSortedList());
mAliasTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); mAliasTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
mAliasTableView.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Alias>)c -> { mAliasTableView.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Alias>) c ->
{
Platform.runLater(() -> setAliases(mAliasTableView.getSelectionModel().getSelectedItems())); Platform.runLater(() -> setAliases(mAliasTableView.getSelectionModel().getSelectedItems()));
}); });
} }
@@ -448,7 +452,8 @@ public class AliasConfigurationEditor extends SplitPane
mAliasSortedList.comparatorProperty().bind(getAliasTableView().comparatorProperty()); mAliasSortedList.comparatorProperty().bind(getAliasTableView().comparatorProperty());
//Don't re-sort while the bulk editor is still applying changes to aliases //Don't re-sort while the bulk editor is still applying changes to aliases
getAliasBulkEditor().changeInProgressProperty().addListener((observable, oldValue, newValue) -> { getAliasBulkEditor().changeInProgressProperty().addListener((observable, oldValue, newValue) ->
{
if(newValue) if(newValue)
{ {
mAliasSortedList.comparatorProperty().unbind(); mAliasSortedList.comparatorProperty().unbind();
@@ -499,13 +504,15 @@ public class AliasConfigurationEditor extends SplitPane
mNewAliasButton.setDisable(true); mNewAliasButton.setDisable(true);
mNewAliasButton.setAlignment(Pos.CENTER); mNewAliasButton.setAlignment(Pos.CENTER);
mNewAliasButton.setMaxWidth(Double.MAX_VALUE); mNewAliasButton.setMaxWidth(Double.MAX_VALUE);
mNewAliasButton.setOnAction(event -> { mNewAliasButton.setOnAction(event ->
{
Alias alias = new Alias("New Alias"); Alias alias = new Alias("New Alias");
alias.setAliasListName(getAliasListNameComboBox().getSelectionModel().getSelectedItem()); alias.setAliasListName(getAliasListNameComboBox().getSelectionModel().getSelectedItem());
mPlaylistManager.getAliasModel().addAlias(alias); mPlaylistManager.getAliasModel().addAlias(alias);
//Queue a select alias action to allow table to update filter predicate and display the alias //Queue a select alias action to allow table to update filter predicate and display the alias
Platform.runLater(() -> { Platform.runLater(() ->
{
getAliasTableView().getSelectionModel().clearSelection(); getAliasTableView().getSelectionModel().clearSelection();
getAliasTableView().getSelectionModel().select(alias); getAliasTableView().getSelectionModel().select(alias);
getAliasTableView().scrollTo(alias); getAliasTableView().scrollTo(alias);
@@ -523,7 +530,8 @@ public class AliasConfigurationEditor extends SplitPane
mDeleteAliasButton = new Button("Delete"); mDeleteAliasButton = new Button("Delete");
mDeleteAliasButton.setDisable(true); mDeleteAliasButton.setDisable(true);
mDeleteAliasButton.setMaxWidth(Double.MAX_VALUE); mDeleteAliasButton.setMaxWidth(Double.MAX_VALUE);
mDeleteAliasButton.setOnAction(event -> { mDeleteAliasButton.setOnAction(event ->
{
boolean multiple = getAliasTableView().getSelectionModel().getSelectedItems().size() > 1; boolean multiple = getAliasTableView().getSelectionModel().getSelectedItems().size() > 1;
@@ -558,7 +566,8 @@ public class AliasConfigurationEditor extends SplitPane
mCloneAliasButton = new Button("Clone"); mCloneAliasButton = new Button("Clone");
mCloneAliasButton.setDisable(true); mCloneAliasButton.setDisable(true);
mCloneAliasButton.setMaxWidth(Double.MAX_VALUE); mCloneAliasButton.setMaxWidth(Double.MAX_VALUE);
mCloneAliasButton.setOnAction(event -> { mCloneAliasButton.setOnAction(event ->
{
Alias original = getAliasTableView().getSelectionModel().getSelectedItem(); Alias original = getAliasTableView().getSelectionModel().getSelectedItem();
Alias copy = AliasFactory.shallowCopyOf(original); Alias copy = AliasFactory.shallowCopyOf(original);
mPlaylistManager.getAliasModel().addAlias(copy); mPlaylistManager.getAliasModel().addAlias(copy);
@@ -577,7 +586,8 @@ public class AliasConfigurationEditor extends SplitPane
{ {
mMoveToAliasButton = new MenuButton("Move To"); mMoveToAliasButton = new MenuButton("Move To");
mMoveToAliasButton.setDisable(true); mMoveToAliasButton.setDisable(true);
mMoveToAliasButton.setOnShowing(event -> { mMoveToAliasButton.setOnShowing(event ->
{
mMoveToAliasButton.getItems().clear(); mMoveToAliasButton.getItems().clear();
MenuItem emptyItem = new MenuItem("Alias Lists"); MenuItem emptyItem = new MenuItem("Alias Lists");
@@ -606,7 +616,8 @@ public class AliasConfigurationEditor extends SplitPane
{ {
super(aliasList); super(aliasList);
setOnAction(event -> { setOnAction(event ->
{
List<Alias> selectedAliases = new ArrayList<>(getAliasTableView().getSelectionModel().getSelectedItems()); List<Alias> selectedAliases = new ArrayList<>(getAliasTableView().getSelectionModel().getSelectedItems());
for(Alias selected : selectedAliases) for(Alias selected : selectedAliases)
{ {