Skip to content

Commit

Permalink
Merge pull request #1698 from DSheirer/1654-playlist-editor-channel-f…
Browse files Browse the repository at this point in the history
…requency-sort

#1654 Playlist Channel Editor Frequency Column Sort
  • Loading branch information
DSheirer authored Nov 5, 2023
2 parents 66f0731 + a62f81f commit 99eda40
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
* Copyright (C) 2014-2023 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
Expand All @@ -26,6 +26,12 @@
import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.source.tuner.manager.TunerManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -63,13 +69,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;

/**
* JavaFX editor for managing channel configurations.
*/
Expand Down Expand Up @@ -449,6 +448,25 @@ protected void updateItem(Boolean item, boolean empty)
nameColumn.setPrefWidth(200);

TableColumn frequencyColumn = new TableColumn("Frequency");
frequencyColumn.setComparator((o1, o2) -> {
if(o1 instanceof Channel c1 && o2 instanceof Channel c2)
{
if(!c1.getFrequencyList().isEmpty() && !c2.getFrequencyList().isEmpty())
{
return Long.compare(c1.getFrequencyList().get(0), c2.getFrequencyList().get(0));
}
else if(!c1.getFrequencyList().isEmpty())
{
return Long.compare(c1.getFrequencyList().get(0), 0l);
}
else if(!c2.getFrequencyList().isEmpty())
{
return Long.compare(0l, c2.getFrequencyList().get(0));
}
}

return Integer.compare(o1.hashCode(), o2.hashCode());
});
frequencyColumn.setCellValueFactory(new FrequencyCellValueFactory());
frequencyColumn.setPrefWidth(100);

Expand Down

0 comments on commit 99eda40

Please sign in to comment.