mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-19 03:57:26 -05:00
#2671 Spectral display right click on signal context menu radio reference options. Unifies the popout card to channels in order: 1) in playlist and enabled, in playlist, in radio reference, ordered by distance from the user's my location (#2675)
Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 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/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.spectrum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Channel shown in the display's Channels hover card
|
||||
* @param title of the channel, drawn in the color of its state
|
||||
* @param details lines
|
||||
* @param state of the channel: an enabled or disabled playlist channel, or a radio reference candidate
|
||||
* @param key identifying the channel, e.g. the playlist channel, so the card lists it once, or null
|
||||
* @param prompts true when the entry is reason to show the card, e.g. the channel's labels don't fit in its box, or
|
||||
* false when it's only listed while the card is shown for other entries
|
||||
*/
|
||||
public record ChannelCardEntry(String title, List<String> details, ChannelMenus.State state, Object key,
|
||||
boolean prompts)
|
||||
{
|
||||
}
|
||||
399
src/main/java/io/github/dsheirer/gui/spectrum/ChannelMenus.java
Normal file
399
src/main/java/io/github/dsheirer/gui/spectrum/ChannelMenus.java
Normal file
@@ -0,0 +1,399 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 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/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.spectrum;
|
||||
|
||||
import io.github.dsheirer.controller.channel.Channel;
|
||||
import io.github.dsheirer.eventbus.MyEventBus;
|
||||
import io.github.dsheirer.gui.playlist.channel.ViewChannelRequest;
|
||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javafx.event.Event;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.SeparatorMenuItem;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
/**
|
||||
* Context menu entries of the Channels section, shared by the playlist channel and radio reference layers. Each
|
||||
* channel is a submenu showing its title and details, like the display's hover cards, with the actions for its state.
|
||||
* The entries have the display theme's colors: the card background, with the title colored by state - the theme's
|
||||
* active color (a green) for an enabled playlist channel, its inactive color (a blue) for a disabled one, and its
|
||||
* plain text color for a radio reference candidate that isn't in the playlist.
|
||||
*/
|
||||
public final class ChannelMenus
|
||||
{
|
||||
/**
|
||||
* Context menu section of the channel entries
|
||||
*/
|
||||
public static final String SECTION = "Channels";
|
||||
|
||||
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
||||
private static final String STYLE_ITEM = "channel-menu-item";
|
||||
private static final String STYLE_TITLE = "channel-menu-title";
|
||||
private static final String STYLE_DETAIL = "channel-menu-detail";
|
||||
private static final String STYLE_NOTE = "channel-menu-note";
|
||||
//Minimum contrast ratio of the colored text against the menu background
|
||||
private static final double MIN_CONTRAST = 3.0;
|
||||
|
||||
/**
|
||||
* State of a channel entry, which sets its color
|
||||
*/
|
||||
public enum State
|
||||
{
|
||||
ENABLED("channel-menu-enabled"),
|
||||
DISABLED("channel-menu-disabled"),
|
||||
CANDIDATE("channel-menu-candidate");
|
||||
|
||||
private final String mStyleClass;
|
||||
|
||||
State(String styleClass)
|
||||
{
|
||||
mStyleClass = styleClass;
|
||||
}
|
||||
|
||||
public String getStyleClass()
|
||||
{
|
||||
return mStyleClass;
|
||||
}
|
||||
}
|
||||
|
||||
private ChannelMenus()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel entry submenu showing the title and details
|
||||
* @param title of the channel
|
||||
* @param details line, or null
|
||||
* @param state of the channel
|
||||
* @param key identifying the channel, e.g. the playlist channel, so the display lists it once, or null
|
||||
*/
|
||||
public static Menu createEntry(String title, String details, State state, Object key)
|
||||
{
|
||||
Label titleLabel = new Label(title);
|
||||
titleLabel.getStyleClass().add(STYLE_TITLE);
|
||||
VBox box = new VBox(titleLabel);
|
||||
|
||||
if(details != null)
|
||||
{
|
||||
Label detailLabel = new Label(details);
|
||||
detailLabel.getStyleClass().add(STYLE_DETAIL);
|
||||
box.getChildren().add(detailLabel);
|
||||
}
|
||||
|
||||
Menu menu = new Menu(null, box);
|
||||
menu.getStyleClass().addAll(STYLE_ITEM, state.getStyleClass());
|
||||
menu.setUserData(key);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry for a playlist channel: enable or disable it, and view or edit it in the playlist editor
|
||||
* @param channel in the playlist
|
||||
* @param tunerChannel of the channel to describe, or null for the channel's first
|
||||
* @param toggle that enables the channel when it's disabled or disables it when it's enabled, or null when the
|
||||
* channel can't be started or stopped from the menu, e.g. a traffic channel
|
||||
*/
|
||||
public static Menu createChannelEntry(Channel channel, TunerChannel tunerChannel, Runnable toggle)
|
||||
{
|
||||
boolean processing = channel.isProcessing();
|
||||
State state = getState(channel);
|
||||
Menu menu = createEntry(getTitle(channel), String.join(" \u00B7 ", getDetails(channel, tunerChannel)), state,
|
||||
channel);
|
||||
|
||||
if(toggle != null)
|
||||
{
|
||||
menu.getItems().add(createItem(processing ? "Disable" : "Enable", state, toggle));
|
||||
}
|
||||
|
||||
menu.getItems().add(createItem("View/Edit in Playlist", state,
|
||||
() -> MyEventBus.getGlobalEventBus().post(new ViewChannelRequest(channel))));
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hover card entry for a playlist channel
|
||||
* @param channel in the playlist
|
||||
* @param tunerChannel of the channel to describe, or null for the channel's first
|
||||
* @param prompts true when the entry is reason to show the card
|
||||
*/
|
||||
public static ChannelCardEntry createCardEntry(Channel channel, TunerChannel tunerChannel, boolean prompts)
|
||||
{
|
||||
//One details line, as in the menu entry, so the card has room for more channels
|
||||
return new ChannelCardEntry(getTitle(channel), List.of(String.join(" \u00B7 ", getDetails(channel,
|
||||
tunerChannel))), getState(channel), channel, prompts);
|
||||
}
|
||||
|
||||
/**
|
||||
* State of a playlist channel
|
||||
*/
|
||||
public static State getState(Channel channel)
|
||||
{
|
||||
return channel.isProcessing() ? State.ENABLED : State.DISABLED;
|
||||
}
|
||||
|
||||
private static String getTitle(Channel channel)
|
||||
{
|
||||
return channel.getName() != null && !channel.getName().isEmpty() ? channel.getName() : "(unnamed)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail lines of a playlist channel: the system and site, then the decoder, frequency and state
|
||||
* @param tunerChannel of the channel to describe, or null for the channel's first
|
||||
*/
|
||||
public static List<String> getDetails(Channel channel, TunerChannel tunerChannel)
|
||||
{
|
||||
if(tunerChannel == null)
|
||||
{
|
||||
List<TunerChannel> tunerChannels = channel.getTunerChannels();
|
||||
tunerChannel = tunerChannels.isEmpty() ? null : tunerChannels.get(0);
|
||||
}
|
||||
|
||||
List<String> details = new ArrayList<>();
|
||||
String systemSite = join(channel.hasSystem() ? channel.getSystem() : null,
|
||||
channel.hasSite() ? channel.getSite() : null);
|
||||
|
||||
if(systemSite != null)
|
||||
{
|
||||
details.add(systemSite);
|
||||
}
|
||||
|
||||
details.add(join(channel.getDecodeConfiguration().getDecoderType().getShortDisplayString(),
|
||||
tunerChannel != null ? FREQUENCY_FORMAT.format(tunerChannel.getFrequency() / 1E6) + " MHz" : null,
|
||||
channel.isProcessing() ? "Enabled" : "Disabled"));
|
||||
return details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action item of an entry's submenu
|
||||
*/
|
||||
public static MenuItem createItem(String text, State state, Runnable action)
|
||||
{
|
||||
MenuItem item = new MenuItem(text);
|
||||
item.getStyleClass().addAll(STYLE_ITEM, state.getStyleClass());
|
||||
item.setOnAction(event -> action.run());
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inactive item of an entry's submenu that explains something, e.g. why a candidate can't be added
|
||||
*/
|
||||
public static MenuItem createNote(String text)
|
||||
{
|
||||
MenuItem item = new MenuItem(text);
|
||||
item.getStyleClass().addAll(STYLE_ITEM, STYLE_NOTE);
|
||||
item.setDisable(true);
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separator of an entry's submenu
|
||||
*/
|
||||
public static SeparatorMenuItem createSeparator()
|
||||
{
|
||||
SeparatorMenuItem separator = new SeparatorMenuItem();
|
||||
separator.getStyleClass().add(STYLE_ITEM);
|
||||
return separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the context menu's channel entries the theme's colors. The stylesheet goes into the scenes of the menu
|
||||
* and the entry submenus, since a popup takes its owner's stylesheets when it's shown and the application theme's
|
||||
* stylesheets are added to each popup's scene: the more specific rules win in the same scene.
|
||||
*/
|
||||
public static void style(ContextMenu menu, SpectralDisplayTheme theme)
|
||||
{
|
||||
String stylesheet = createStylesheet(theme);
|
||||
menu.addEventHandler(WindowEvent.WINDOW_SHOWN, event -> addStylesheet(menu.getScene(), stylesheet));
|
||||
|
||||
for(MenuItem item: menu.getItems())
|
||||
{
|
||||
if(item instanceof Menu entry && entry.getStyleClass().contains(STYLE_ITEM))
|
||||
{
|
||||
//The submenu's popup isn't exposed, but its items' nodes are in its scene once it's showing
|
||||
EventHandler<Event> handler = event -> {
|
||||
for(MenuItem child: entry.getItems())
|
||||
{
|
||||
Node node = child.getStyleableNode();
|
||||
|
||||
if(node != null && node.getScene() != null)
|
||||
{
|
||||
addStylesheet(node.getScene(), stylesheet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
entry.setOnShowing(handler);
|
||||
entry.setOnShown(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addStylesheet(Scene scene, String stylesheet)
|
||||
{
|
||||
if(scene != null && !scene.getStylesheets().contains(stylesheet))
|
||||
{
|
||||
scene.getStylesheets().add(stylesheet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stylesheet with the theme's colors
|
||||
* @return data URL of the stylesheet
|
||||
*/
|
||||
static String createStylesheet(SpectralDisplayTheme theme)
|
||||
{
|
||||
Color background = opaque(theme.getBackground());
|
||||
String detail = css(readable(opaque(theme.getLine()), background));
|
||||
String item = ".menu-item." + STYLE_ITEM;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(item).append(" { -fx-background-color: ").append(css(background)).append("; }\n");
|
||||
sb.append(item).append(":focused, ").append(item).append(":hover { -fx-background-color: ")
|
||||
.append(css(background)).append(", ").append(css(theme.getLine(0.35))).append("; }\n");
|
||||
sb.append(item).append(":disabled, ").append(item).append(":disabled .label { -fx-opacity: 1; }\n");
|
||||
|
||||
for(State state: State.values())
|
||||
{
|
||||
String color = css(readable(getColor(theme, state), background));
|
||||
String stateItem = item + "." + state.getStyleClass();
|
||||
//The item labels, and the title of an entry
|
||||
sb.append(textRules(color, stateItem + " .label", stateItem + ":focused .label",
|
||||
stateItem + ":hover .label"));
|
||||
}
|
||||
|
||||
//More specific than the state rules, so the details keep their color on hover
|
||||
sb.append(textRules(detail, item + " .label." + STYLE_DETAIL, item + ":focused .label." + STYLE_DETAIL,
|
||||
item + ":hover .label." + STYLE_DETAIL, item + "." + STYLE_NOTE + " .label"));
|
||||
sb.append(item).append(" .label.").append(STYLE_TITLE).append(" { -fx-font-weight: bold; }\n");
|
||||
sb.append(".menu.").append(STYLE_ITEM).append(" > .right-container > .arrow { -fx-background-color: ")
|
||||
.append(detail).append("; }\n");
|
||||
sb.append(".separator-menu-item.").append(STYLE_ITEM).append(" { -fx-padding: 0.25em 0; }\n");
|
||||
sb.append(".separator-menu-item.").append(STYLE_ITEM).append(" > .line { -fx-border-color: ")
|
||||
.append(css(theme.getLine(0.5)))
|
||||
.append(" transparent transparent transparent; -fx-border-insets: 0; -fx-padding: 0; }\n");
|
||||
return "data:text/css;base64," +
|
||||
Base64.getEncoder().encodeToString(sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Title color of the state: the theme's active color (a green) for an enabled playlist channel, its inactive
|
||||
* color (a blue) for a disabled one, and its plain text color for a radio reference candidate
|
||||
*/
|
||||
public static Color getColor(SpectralDisplayTheme theme, State state)
|
||||
{
|
||||
return switch(state)
|
||||
{
|
||||
case ENABLED -> theme.getChannelActive();
|
||||
case DISABLED -> theme.getChannelInactive();
|
||||
case CANDIDATE -> theme.getText();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Color moved toward white on a dark background, or black on a light one, until it's readable on the background
|
||||
*/
|
||||
public static Color readable(Color color, Color background)
|
||||
{
|
||||
Color target = luminance(background) < 0.5 ? Color.WHITE : Color.BLACK;
|
||||
Color adjusted = color;
|
||||
|
||||
for(int step = 1; step <= 10 && contrast(adjusted, background) < MIN_CONTRAST; step++)
|
||||
{
|
||||
adjusted = color.interpolate(target, step / 10.0);
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
static double contrast(Color a, Color b)
|
||||
{
|
||||
double la = luminance(a);
|
||||
double lb = luminance(b);
|
||||
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
||||
}
|
||||
|
||||
private static double luminance(Color color)
|
||||
{
|
||||
return (0.2126 * linear(color.getRed())) + (0.7152 * linear(color.getGreen())) +
|
||||
(0.0722 * linear(color.getBlue()));
|
||||
}
|
||||
|
||||
private static double linear(double channel)
|
||||
{
|
||||
return channel <= 0.03928 ? channel / 12.92 : Math.pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rules that set the text color of the labels and of their text nodes. The dark application theme fills each
|
||||
* label's text node, so both are set.
|
||||
*/
|
||||
private static String textRules(String color, String... labelSelectors)
|
||||
{
|
||||
String labels = String.join(", ", labelSelectors);
|
||||
String texts = String.join(" .text, ", labelSelectors) + " .text";
|
||||
return labels + " { -fx-text-fill: " + color + "; }\n" + texts + " { -fx-fill: " + color + "; }\n";
|
||||
}
|
||||
|
||||
private static Color opaque(Color color)
|
||||
{
|
||||
return Color.color(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
private static String css(Color color)
|
||||
{
|
||||
return String.format(Locale.ROOT, "rgba(%d,%d,%d,%.3f)", Math.round(color.getRed() * 255),
|
||||
Math.round(color.getGreen() * 255), Math.round(color.getBlue() * 255), color.getOpacity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Values joined with a middle dot, skipping null and empty values
|
||||
*/
|
||||
public static String join(String... values)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(String value: values)
|
||||
{
|
||||
if(value != null && !value.isEmpty())
|
||||
{
|
||||
if(!sb.isEmpty())
|
||||
{
|
||||
sb.append(" · ");
|
||||
}
|
||||
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.isEmpty() ? null : sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,12 @@
|
||||
package io.github.dsheirer.gui.spectrum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -1120,15 +1126,53 @@ public class SpectralDisplay extends StackPane
|
||||
double xFraction = width > 0 ? event.getX() / width : 0.5;
|
||||
ContextMenu menu = new ContextMenu();
|
||||
|
||||
//Items of the layers grouped by section, in layer order. A layer without a section is a group of its own.
|
||||
Map<Object,List<MenuItem>> groups = new LinkedHashMap<>();
|
||||
Map<Object,Map<Object,MenuItem>> listed = new HashMap<>();
|
||||
|
||||
for(SpectralDisplayLayer layer: mLayers)
|
||||
{
|
||||
List<MenuItem> items = layer.getContextMenuItems(pane.getSection(), frequency);
|
||||
|
||||
if(items != null && !items.isEmpty())
|
||||
if(items == null || items.isEmpty())
|
||||
{
|
||||
menu.getItems().addAll(items);
|
||||
menu.getItems().add(new SeparatorMenuItem());
|
||||
continue;
|
||||
}
|
||||
|
||||
Object key = layer.getContextMenuSection() != null ? layer.getContextMenuSection() : layer;
|
||||
List<MenuItem> group = groups.computeIfAbsent(key, k -> new ArrayList<>());
|
||||
Map<Object,MenuItem> keys = listed.computeIfAbsent(key, k -> new IdentityHashMap<>());
|
||||
|
||||
for(MenuItem item: items)
|
||||
{
|
||||
MenuItem earlier = item.getUserData() != null ? keys.get(item.getUserData()) : null;
|
||||
|
||||
if(earlier != null)
|
||||
{
|
||||
//The same channel from another layer is listed once, with the other layer's options added
|
||||
mergeOptions(earlier, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(item.getUserData() != null)
|
||||
{
|
||||
keys.put(item.getUserData(), item);
|
||||
}
|
||||
|
||||
group.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Map.Entry<Object,List<MenuItem>> group: groups.entrySet())
|
||||
{
|
||||
if(group.getKey() instanceof String section)
|
||||
{
|
||||
menu.getItems().add(SpectralDisplayLayer.createSectionHeader(section));
|
||||
}
|
||||
|
||||
menu.getItems().addAll(group.getValue());
|
||||
menu.getItems().add(new SeparatorMenuItem());
|
||||
}
|
||||
|
||||
Menu zoomMenu = new Menu("Zoom");
|
||||
@@ -1154,11 +1198,97 @@ public class SpectralDisplay extends StackPane
|
||||
menu.getItems().add(pause);
|
||||
}
|
||||
|
||||
alignLabels(menu.getItems());
|
||||
ChannelMenus.style(menu, getTheme());
|
||||
mContextMenu = menu;
|
||||
menu.show(pane, event.getScreenX(), event.getScreenY());
|
||||
event.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the submenu options of a later entry for the same channel that the earlier entry doesn't have, e.g. the
|
||||
* radio reference layer's option to view a playlist channel's listing. When the later entry has all of the
|
||||
* earlier entry's options, the earlier entry takes the later entry's options in their order, otherwise the
|
||||
* missing options are added after a separator.
|
||||
*/
|
||||
private static void mergeOptions(MenuItem earlier, MenuItem later)
|
||||
{
|
||||
if(!(earlier instanceof Menu earlierMenu) || !(later instanceof Menu laterMenu))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> earlierTexts = getOptionTexts(earlierMenu);
|
||||
Set<String> laterTexts = getOptionTexts(laterMenu);
|
||||
|
||||
if(laterTexts.containsAll(earlierTexts))
|
||||
{
|
||||
if(laterTexts.size() > earlierTexts.size())
|
||||
{
|
||||
//Items belong to one menu, so they're moved
|
||||
List<MenuItem> options = new ArrayList<>(laterMenu.getItems());
|
||||
laterMenu.getItems().clear();
|
||||
earlierMenu.getItems().setAll(options);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
List<MenuItem> added = new ArrayList<>();
|
||||
|
||||
for(MenuItem option: laterMenu.getItems())
|
||||
{
|
||||
if(!(option instanceof SeparatorMenuItem) && option.getText() != null &&
|
||||
!earlierTexts.contains(option.getText()))
|
||||
{
|
||||
added.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
if(!added.isEmpty())
|
||||
{
|
||||
laterMenu.getItems().removeAll(added);
|
||||
earlierMenu.getItems().add(ChannelMenus.createSeparator());
|
||||
earlierMenu.getItems().addAll(added);
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<String> getOptionTexts(Menu menu)
|
||||
{
|
||||
Set<String> texts = new HashSet<>();
|
||||
|
||||
for(MenuItem option: menu.getItems())
|
||||
{
|
||||
if(!(option instanceof SeparatorMenuItem) && option.getText() != null)
|
||||
{
|
||||
texts.add(option.getText());
|
||||
}
|
||||
}
|
||||
|
||||
return texts;
|
||||
}
|
||||
|
||||
/**
|
||||
* A context menu places item text in a column after the widest graphic, so when a layer's items show their
|
||||
* content as a graphic, the text of the other items is moved into a graphic too, to line up on the left.
|
||||
*/
|
||||
private static void alignLabels(List<MenuItem> items)
|
||||
{
|
||||
if(items.stream().noneMatch(item -> item.getGraphic() != null && !(item instanceof SeparatorMenuItem)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(MenuItem item: items)
|
||||
{
|
||||
if(item.getGraphic() == null && item.getText() != null && !(item instanceof SeparatorMenuItem))
|
||||
{
|
||||
item.setGraphic(new Label(item.getText()));
|
||||
item.setText(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizable pane that holds a canvas for one display section.
|
||||
*/
|
||||
|
||||
@@ -147,6 +147,44 @@ public abstract class SpectralDisplayLayer
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels at the mouse position for the display's Channels hover card (see
|
||||
* {@link io.github.dsheirer.gui.spectrum.layer.ChannelCardLayer}). Called on the JavaFX application thread while
|
||||
* the mouse rests over the display, so it should be quick.
|
||||
* @param cursor mouse position
|
||||
* @param area of the section under the mouse
|
||||
* @return entries, or an empty list
|
||||
*/
|
||||
public List<ChannelCardEntry> getCardEntries(DisplayCursor cursor, RenderArea area)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Context menu section of this layer's items. The items of layers with the same section are listed together
|
||||
* under a header with the section name, each item once: an item whose user data is the same object as an earlier
|
||||
* item's in the section is left out.
|
||||
* @return section name, or null for items of their own without a header
|
||||
*/
|
||||
public String getContextMenuSection()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Section header for context menu items: an inactive item with smaller bold text in the theme's text color,
|
||||
* slightly faded. Inline styles, since the application theme's stylesheets are added to each popup's scene.
|
||||
* @param title of the section
|
||||
*/
|
||||
public static MenuItem createSectionHeader(String title)
|
||||
{
|
||||
MenuItem header = new MenuItem(title);
|
||||
header.setDisable(true);
|
||||
header.getStyleClass().add("spectral-menu-section-header");
|
||||
header.setStyle("-fx-opacity: 0.6; -fx-font-size: 0.85em; -fx-font-weight: bold;");
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Title of this layer's section in the configuration panel, or null to place the layer's rows in the panel's
|
||||
* Display section instead of a section of their own.
|
||||
|
||||
@@ -239,6 +239,74 @@ public enum SpectralDisplayTheme
|
||||
return mCorrection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text color for an active (enabled) playlist channel in the Channels menu and card: a green that reads as
|
||||
* active on the theme's background, or the theme's own highlight in the monochrome themes. Red/green color
|
||||
* blind themes use a yellowish green and blue/yellow color blind themes a green that stays distinct from
|
||||
* {@link #getChannelInactive()}.
|
||||
*/
|
||||
public Color getChannelActive()
|
||||
{
|
||||
return Color.web(switch(this)
|
||||
{
|
||||
case CLASSIC -> "#33E633";
|
||||
case DARK -> "#66BB6A";
|
||||
case MEDIUM -> "#81C784";
|
||||
case LIGHT -> "#2E7D32";
|
||||
case GREEN_PHOSPHOR -> "#66FF8C";
|
||||
case AMBER -> "#FFC233";
|
||||
case GRAYSCALE -> "#FFFFFF";
|
||||
case HIGH_CONTRAST_DARK -> "#00FF00";
|
||||
case HIGH_CONTRAST_LIGHT -> "#006400";
|
||||
case VIRIDIS -> "#6DCD59";
|
||||
case CIVIDIS -> "#B4DE2C";
|
||||
case INFERNO -> "#4CC764";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Text color for an inactive (disabled) playlist channel in the Channels menu and card: a blue that reads as
|
||||
* inactive on the theme's background, or a dimmed shade in the monochrome themes. The blue/yellow color blind
|
||||
* theme uses a pink, since blue and green look alike there.
|
||||
*/
|
||||
public Color getChannelInactive()
|
||||
{
|
||||
return Color.web(switch(this)
|
||||
{
|
||||
case CLASSIC -> "#4D9FFF";
|
||||
case DARK -> "#64B5F6";
|
||||
case MEDIUM -> "#90CAF9";
|
||||
case LIGHT -> "#1565C0";
|
||||
case GREEN_PHOSPHOR -> "#3FAF5C";
|
||||
case AMBER -> "#B07A10";
|
||||
case GRAYSCALE -> "#8C8C8C";
|
||||
case HIGH_CONTRAST_DARK -> "#00BFFF";
|
||||
case HIGH_CONTRAST_LIGHT -> "#0000C0";
|
||||
case VIRIDIS -> "#5B9BF0";
|
||||
case CIVIDIS -> "#56B4E9";
|
||||
case INFERNO -> "#E879C6";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain text color on the theme's background, e.g. for menu entries that aren't highlighted
|
||||
*/
|
||||
public Color getText()
|
||||
{
|
||||
return Color.web(switch(this)
|
||||
{
|
||||
case CLASSIC, HIGH_CONTRAST_DARK -> "#FFFFFF";
|
||||
case DARK -> "#E6E8EB";
|
||||
case MEDIUM -> "#F0F4F8";
|
||||
case LIGHT -> "#212529";
|
||||
case GREEN_PHOSPHOR -> "#CCFFCC";
|
||||
case AMBER -> "#FFF0C2";
|
||||
case GRAYSCALE -> "#D0D0D0";
|
||||
case HIGH_CONTRAST_LIGHT -> "#000000";
|
||||
case VIRIDIS, CIVIDIS, INFERNO -> "#E8E8EE";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ARGB color for the waterfall intensity index (0 - 255).
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,7 @@ package io.github.dsheirer.gui.spectrum;
|
||||
import io.github.dsheirer.controller.channel.ChannelModel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
||||
import io.github.dsheirer.gui.spectrum.layer.ChannelCardLayer;
|
||||
import io.github.dsheirer.gui.spectrum.layer.ChannelLayer;
|
||||
import io.github.dsheirer.gui.spectrum.layer.RadioReferenceLayer;
|
||||
import io.github.dsheirer.playlist.PlaylistManager;
|
||||
@@ -104,8 +105,8 @@ public class TunerSpectralDisplay extends DftSpectralDisplay implements ISourceE
|
||||
private TunerSpectralDisplay(ChannelLayer channelLayer, RadioReferenceLayer radioReferenceLayer,
|
||||
DiscoveredTunerModel discoveredTunerModel, boolean saveSettings)
|
||||
{
|
||||
//The radio reference layer draws after the channel layer, so its card is on top
|
||||
super(SETTINGS_PREFIX, saveSettings, channelLayer, radioReferenceLayer);
|
||||
//The channels card draws after the other layers, so it's on top
|
||||
super(SETTINGS_PREFIX, saveSettings, channelLayer, radioReferenceLayer, new ChannelCardLayer());
|
||||
mChannelLayer = channelLayer;
|
||||
mRadioReferenceLayer = radioReferenceLayer;
|
||||
mDiscoveredTunerModel = discoveredTunerModel;
|
||||
|
||||
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 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/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.spectrum.layer;
|
||||
|
||||
import io.github.dsheirer.gui.spectrum.ChannelCardEntry;
|
||||
import io.github.dsheirer.gui.spectrum.ChannelMenus;
|
||||
import io.github.dsheirer.gui.spectrum.CursorReadout;
|
||||
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
||||
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
||||
import io.github.dsheirer.gui.spectrum.RenderArea;
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayLayer;
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayModel;
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayTheme;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
import javafx.util.Duration;
|
||||
|
||||
/**
|
||||
* Channels hover card. When the mouse rests over the spectrum or the waterfall, shows a card next to the mouse with
|
||||
* the channels at the mouse position that the other layers provide (see
|
||||
* {@link SpectralDisplayLayer#getCardEntries}): playlist channels first, then radio reference candidates. The titles
|
||||
* have the colors of the Channels context menu entries: one for an enabled playlist channel, one for a disabled one
|
||||
* and one for a candidate. The card replaces the cursor readout and ends with the readout lines.
|
||||
*
|
||||
* The card is shown when an entry prompts it, e.g. a playlist channel whose labels don't fit in its box or a
|
||||
* candidate; the other channels at the mouse position are then listed too.
|
||||
*/
|
||||
public class ChannelCardLayer extends SpectralDisplayLayer
|
||||
{
|
||||
private static final Duration HOVER_DELAY = Duration.millis(400);
|
||||
private static final Font FONT = Font.font(11);
|
||||
private static final Font TITLE_FONT = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
||||
private static final int MAX_ENTRIES = 6;
|
||||
private static final double MAX_TEXT_WIDTH = 380;
|
||||
private static final double PADDING = 6;
|
||||
private static final double GAP = 5;
|
||||
//Space beside the text and below the readout lines, as in the cursor readout, so the readout lines stay in place
|
||||
private static final double PADDING_X = 4;
|
||||
//Space kept between the card and the edges of the section
|
||||
private static final double EDGE_MARGIN = 2;
|
||||
private static final double READOUT_PADDING = 2;
|
||||
private static final String HEADER = ChannelMenus.SECTION;
|
||||
|
||||
private final Text mMeasure = new Text();
|
||||
private final double mTextHeight;
|
||||
private PauseTransition mHoverTimer;
|
||||
private DisplaySection mHoverSection;
|
||||
private double mHoverX = Double.NaN;
|
||||
private double mHoverY = Double.NaN;
|
||||
private boolean mHoverReady;
|
||||
private List<ChannelCardEntry> mEntries = Collections.emptyList();
|
||||
private Card mCard;
|
||||
|
||||
/**
|
||||
* Card text, measured when the entries or the room change
|
||||
* @param entries lines of each shown entry: the title, then the details
|
||||
* @param states of the shown entries
|
||||
* @param more line, or null
|
||||
* @param textWidth of the widest line
|
||||
* @param lineCount of the header, entry and more lines
|
||||
* @param source entries the card was made from
|
||||
* @param maxTextWidth that the lines were shortened to
|
||||
* @param maxHeight that the card was limited to
|
||||
* @param readoutLines that the card was sized for
|
||||
*/
|
||||
private record Card(List<List<String>> entries, List<ChannelMenus.State> states, String more, double textWidth,
|
||||
int lineCount, List<ChannelCardEntry> source, double maxTextWidth, double maxHeight,
|
||||
int readoutLines)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public ChannelCardLayer()
|
||||
{
|
||||
mMeasure.setFont(FONT);
|
||||
mMeasure.setText("Ag");
|
||||
mTextHeight = Math.ceil(mMeasure.getLayoutBounds().getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
if(mHoverTimer != null)
|
||||
{
|
||||
mHoverTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSpectrumForeground(GraphicsContext gc, RenderArea area)
|
||||
{
|
||||
render(gc, area, DisplaySection.SPECTRUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWaterfall(GraphicsContext gc, RenderArea area)
|
||||
{
|
||||
render(gc, area, DisplaySection.WATERFALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the card in the section under the mouse once the mouse has rested for the hover delay
|
||||
*/
|
||||
private void render(GraphicsContext gc, RenderArea area, DisplaySection section)
|
||||
{
|
||||
DisplayCursor cursor = getSpectralDisplay() != null ? getSpectralDisplay().getDisplayCursor() : null;
|
||||
trackHover(cursor);
|
||||
|
||||
if(cursor != null && cursor.section() == section && replacesCursorReadout(cursor, area))
|
||||
{
|
||||
drawCard(gc, area, cursor, mEntries);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The card replaces the cursor readout while it's shown: it ends with the readout lines, in the readout's place.
|
||||
*/
|
||||
@Override
|
||||
public boolean replacesCursorReadout(DisplayCursor cursor, RenderArea area)
|
||||
{
|
||||
SpectralDisplayModel model = getModel();
|
||||
|
||||
//Only for the position the mouse rested at - the readout comes back as soon as the mouse moves
|
||||
if(!mHoverReady || model == null || !model.hasSource() || cursor == null || cursor.section() != mHoverSection ||
|
||||
cursor.x() != mHoverX || cursor.y() != mHoverY || area.width() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
mEntries = getEntries(cursor, area);
|
||||
return mEntries.stream().anyMatch(ChannelCardEntry::prompts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entries of the other layers, each channel once, playlist channels first
|
||||
*/
|
||||
private List<ChannelCardEntry> getEntries(DisplayCursor cursor, RenderArea area)
|
||||
{
|
||||
List<ChannelCardEntry> entries = new ArrayList<>();
|
||||
Set<Object> keys = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
|
||||
for(SpectralDisplayLayer layer: getSpectralDisplay().getLayers())
|
||||
{
|
||||
if(layer == this)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(ChannelCardEntry entry: layer.getCardEntries(cursor, area))
|
||||
{
|
||||
if(entry.key() == null || keys.add(entry.key()))
|
||||
{
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entries.sort(Comparator.comparing(entry -> entry.state() == ChannelMenus.State.CANDIDATE));
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the hover delay each time the mouse moves, and hides the card until it passes
|
||||
*/
|
||||
private void trackHover(DisplayCursor cursor)
|
||||
{
|
||||
if(cursor == null)
|
||||
{
|
||||
if(mHoverSection != null)
|
||||
{
|
||||
mHoverSection = null;
|
||||
mHoverReady = false;
|
||||
getHoverTimer().stop();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(cursor.section() != mHoverSection || cursor.x() != mHoverX || cursor.y() != mHoverY)
|
||||
{
|
||||
mHoverSection = cursor.section();
|
||||
mHoverX = cursor.x();
|
||||
mHoverY = cursor.y();
|
||||
mHoverReady = false;
|
||||
getHoverTimer().playFromStart();
|
||||
}
|
||||
}
|
||||
|
||||
private PauseTransition getHoverTimer()
|
||||
{
|
||||
if(mHoverTimer == null)
|
||||
{
|
||||
mHoverTimer = new PauseTransition(HOVER_DELAY);
|
||||
mHoverTimer.setOnFinished(event -> {
|
||||
mHoverReady = true;
|
||||
requestRender();
|
||||
});
|
||||
}
|
||||
|
||||
return mHoverTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the card in place of the cursor readout: beside the mouse and above it, placed like the readout, with the
|
||||
* channels above the readout lines so the frequency and level stay where the readout showed them. The card fits
|
||||
* the larger side of the mouse and the height of the section, showing as many channels as fit.
|
||||
*/
|
||||
private void drawCard(GraphicsContext gc, RenderArea area, DisplayCursor cursor, List<ChannelCardEntry> entries)
|
||||
{
|
||||
//The level line changes with the mouse height while the channels don't
|
||||
List<String> readout = CursorReadout.lines(cursor, area, getModel());
|
||||
double readoutWidth = 0;
|
||||
|
||||
for(String line: readout)
|
||||
{
|
||||
readoutWidth = Math.max(readoutWidth, measure(line, FONT));
|
||||
}
|
||||
|
||||
double room = Math.max(area.width() - cursor.x(), cursor.x()) - CursorReadout.GAP_X - EDGE_MARGIN;
|
||||
double maxTextWidth = Math.max(readoutWidth, Math.min(MAX_TEXT_WIDTH, room - (PADDING_X * 2)));
|
||||
//Above the mouse, so the readout lines stay where the readout showed them, when an entry fits there
|
||||
double above = cursor.y() - CursorReadout.GAP_Y;
|
||||
double maxHeight = above >= cardHeight(5, 1, true, readout.size()) ? above : area.plotHeight() - EDGE_MARGIN;
|
||||
|
||||
if(mCard == null || !mCard.source().equals(entries) || mCard.maxTextWidth() != maxTextWidth ||
|
||||
mCard.maxHeight() != maxHeight || mCard.readoutLines() != readout.size())
|
||||
{
|
||||
mCard = createCard(entries, maxTextWidth, maxHeight, readout.size());
|
||||
}
|
||||
|
||||
Card card = mCard;
|
||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
||||
Color background = opaque(theme.getBackground());
|
||||
Color detail = opaque(theme.getLine());
|
||||
double width = Math.max(card.textWidth(), readoutWidth) + (PADDING_X * 2);
|
||||
double height = cardHeight(card.lineCount(), card.entries().size(), card.more() != null, readout.size());
|
||||
double x = Math.max(0, CursorReadout.x(cursor, width, area));
|
||||
double y = CursorReadout.y(cursor, height, area);
|
||||
|
||||
gc.setFill(theme.getBackground(0.92));
|
||||
gc.fillRoundRect(x, y, width, height, 8, 8);
|
||||
gc.setStroke(detail);
|
||||
gc.setLineWidth(1.0);
|
||||
gc.strokeRoundRect(Math.floor(x) + 0.5, Math.floor(y) + 0.5, width, height, 8, 8);
|
||||
gc.setTextAlign(TextAlignment.LEFT);
|
||||
gc.setTextBaseline(VPos.TOP);
|
||||
|
||||
double textX = x + PADDING_X;
|
||||
double lineY = y + PADDING;
|
||||
gc.setFill(detail);
|
||||
gc.setFont(TITLE_FONT);
|
||||
gc.fillText(HEADER, textX, lineY);
|
||||
lineY += mTextHeight + GAP;
|
||||
|
||||
for(int index = 0; index < card.entries().size(); index++)
|
||||
{
|
||||
List<String> lines = card.entries().get(index);
|
||||
gc.setFill(ChannelMenus.readable(ChannelMenus.getColor(theme, card.states().get(index)), background));
|
||||
gc.setFont(TITLE_FONT);
|
||||
gc.fillText(lines.get(0), textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
gc.setFill(detail);
|
||||
gc.setFont(FONT);
|
||||
|
||||
for(int line = 1; line < lines.size(); line++)
|
||||
{
|
||||
gc.fillText(lines.get(line), textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
}
|
||||
|
||||
lineY += GAP;
|
||||
}
|
||||
|
||||
if(card.more() != null)
|
||||
{
|
||||
gc.setFill(detail);
|
||||
gc.setFont(FONT);
|
||||
gc.fillText(card.more(), textX, lineY);
|
||||
lineY += mTextHeight + GAP;
|
||||
}
|
||||
|
||||
//The readout lines, separated from the channels, in the readout's style
|
||||
double separator = Math.floor(lineY - (GAP / 2.0)) + 0.5;
|
||||
gc.setStroke(theme.getLine(0.5));
|
||||
gc.strokeLine(textX, separator, x + width - PADDING_X, separator);
|
||||
gc.setFill(theme.getCursor());
|
||||
gc.setFont(FONT);
|
||||
|
||||
for(String line: readout)
|
||||
{
|
||||
gc.fillText(line, textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Height of a card with the lines
|
||||
* @param lineCount of the header, entry and more lines
|
||||
* @param entries number of entries
|
||||
* @param more true when the card has a more line
|
||||
* @param readoutLines number of readout lines
|
||||
*/
|
||||
private double cardHeight(int lineCount, int entries, boolean more, int readoutLines)
|
||||
{
|
||||
int gaps = 1 + entries + (more ? 1 : 0);
|
||||
return ((lineCount + readoutLines) * mTextHeight) + (gaps * GAP) + PADDING + READOUT_PADDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Card text for as many entries as fit the height, shortened to the width
|
||||
*/
|
||||
private Card createCard(List<ChannelCardEntry> source, double maxTextWidth, double maxHeight, int readoutLines)
|
||||
{
|
||||
int limit = Math.min(source.size(), MAX_ENTRIES);
|
||||
List<List<String>> entries = new ArrayList<>();
|
||||
List<ChannelMenus.State> states = new ArrayList<>();
|
||||
double textWidth = measure(HEADER, TITLE_FONT);
|
||||
int lineCount = 1;
|
||||
|
||||
for(int index = 0; index < limit; index++)
|
||||
{
|
||||
ChannelCardEntry entry = source.get(index);
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add(fit(entry.title(), TITLE_FONT, maxTextWidth));
|
||||
|
||||
for(String detail: entry.details())
|
||||
{
|
||||
if(detail != null)
|
||||
{
|
||||
lines.add(fit(detail, FONT, maxTextWidth));
|
||||
}
|
||||
}
|
||||
|
||||
//Keep room for the more line when entries are left out
|
||||
boolean more = index + 1 < source.size();
|
||||
|
||||
if(!entries.isEmpty() && cardHeight(lineCount + lines.size() + (more ? 1 : 0), entries.size() + 1, more,
|
||||
readoutLines) > maxHeight)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
textWidth = Math.max(textWidth, measure(lines.get(0), TITLE_FONT));
|
||||
|
||||
for(int line = 1; line < lines.size(); line++)
|
||||
{
|
||||
textWidth = Math.max(textWidth, measure(lines.get(line), FONT));
|
||||
}
|
||||
|
||||
lineCount += lines.size();
|
||||
entries.add(lines);
|
||||
states.add(entry.state());
|
||||
}
|
||||
|
||||
String more = source.size() > entries.size() ? "+ " + (source.size() - entries.size()) + " more" : null;
|
||||
|
||||
if(more != null)
|
||||
{
|
||||
textWidth = Math.max(textWidth, measure(more, FONT));
|
||||
lineCount++;
|
||||
}
|
||||
|
||||
return new Card(entries, states, more, textWidth, lineCount, source, maxTextWidth, maxHeight, readoutLines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Text shortened with an ellipsis to fit the width
|
||||
*/
|
||||
private String fit(String text, Font font, double maxWidth)
|
||||
{
|
||||
if(measure(text, font) <= maxWidth)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
int length = text.length();
|
||||
|
||||
while(length > 1 && measure(text.substring(0, length) + "…", font) > maxWidth)
|
||||
{
|
||||
length--;
|
||||
}
|
||||
|
||||
return text.substring(0, length) + "…";
|
||||
}
|
||||
|
||||
private double measure(String text, Font font)
|
||||
{
|
||||
mMeasure.setFont(font);
|
||||
mMeasure.setText(text);
|
||||
double width = mMeasure.getLayoutBounds().getWidth();
|
||||
mMeasure.setFont(FONT);
|
||||
return width;
|
||||
}
|
||||
|
||||
private static Color opaque(Color color)
|
||||
{
|
||||
return Color.color(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ import io.github.dsheirer.controller.channel.ChannelEvent;
|
||||
import io.github.dsheirer.controller.channel.ChannelException;
|
||||
import io.github.dsheirer.controller.channel.ChannelModel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.eventbus.MyEventBus;
|
||||
import io.github.dsheirer.gui.playlist.channel.ViewChannelRequest;
|
||||
import io.github.dsheirer.gui.spectrum.ChannelCardEntry;
|
||||
import io.github.dsheirer.gui.spectrum.ChannelMenus;
|
||||
import io.github.dsheirer.gui.spectrum.ConfigurationRow;
|
||||
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
||||
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
||||
@@ -56,7 +56,6 @@ import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
|
||||
@@ -66,24 +65,20 @@ import javafx.scene.text.TextAlignment;
|
||||
* decoder. Processing and selected channels use their own colors. When the decoder applies a frequency correction,
|
||||
* a bracket at the bottom of the box shows the corrected channel position and the PPM error.
|
||||
*
|
||||
* When the zoom level is too low for a channel's labels to fit in its box, moving the mouse over the channel shows a
|
||||
* popout card near the bottom of the spectrum (or the waterfall) with the channel name, system, site, decoder,
|
||||
* frequency and state. The popout can be turned off with the hover details setting.
|
||||
* When the zoom level is too low for a channel's labels to fit in its box, resting the mouse over the channel lists
|
||||
* it in the Channels hover card (drawn by {@link ChannelCardLayer}) with its system, site, decoder, frequency and
|
||||
* state. This can be turned off with the hover details setting.
|
||||
*
|
||||
* Right-clicking a channel adds a menu item to view or edit the channel in the playlist editor.
|
||||
* Right-clicking a channel lists it in the Channels context menu, to enable or disable it or view or edit it in the
|
||||
* playlist editor.
|
||||
*/
|
||||
public class ChannelLayer extends SpectralDisplayLayer
|
||||
{
|
||||
private static final Font FONT = Font.font(11);
|
||||
private static final DecimalFormat PPM_FORMAT = new DecimalFormat("0.0");
|
||||
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
||||
private static final Font POPOUT_TITLE_FONT = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
||||
private static final double MIN_LABEL_BOX_WIDTH = 12;
|
||||
private static final double POPOUT_MIN_HIT_WIDTH = 10;
|
||||
private static final double POPOUT_PADDING = 6;
|
||||
private static final double POPOUT_GAP = 5;
|
||||
private static final double POPOUT_SWATCH = 8;
|
||||
private static final int POPOUT_MAX_CHANNELS = 4;
|
||||
private static final double MIN_HIT_WIDTH = 10;
|
||||
|
||||
/**
|
||||
* Which channels the layer shows.
|
||||
@@ -382,131 +377,23 @@ public class ChannelLayer extends SpectralDisplayLayer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderPopout(gc, area, DisplaySection.SPECTRUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWaterfall(GraphicsContext gc, RenderArea area)
|
||||
{
|
||||
renderPopout(gc, area, DisplaySection.WATERFALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a card near the bottom of the section under the mouse with the details of each channel under the mouse
|
||||
* whose labels don't fit in its box at the current zoom. The card moves to the top of the section when the mouse
|
||||
* is over the bottom of the section.
|
||||
* Card entries for the channels under the mouse. A channel whose labels don't fit in its box at the current
|
||||
* zoom prompts the card. The hit area of a narrow channel is widened so it can be found with the mouse.
|
||||
*/
|
||||
private void renderPopout(GraphicsContext gc, RenderArea area, DisplaySection section)
|
||||
@Override
|
||||
public List<ChannelCardEntry> getCardEntries(DisplayCursor cursor, RenderArea area)
|
||||
{
|
||||
SpectralDisplayModel model = getModel();
|
||||
DisplayCursor cursor = getSpectralDisplay().getDisplayCursor();
|
||||
List<ChannelCardEntry> entries = new ArrayList<>();
|
||||
|
||||
if(!mHoverDetails.get() || model == null || !model.hasSource() || cursor == null ||
|
||||
cursor.section() != section || mChannelDisplay.get() == ChannelDisplay.NONE)
|
||||
if(!mHoverDetails.get() || model == null || mChannelDisplay.get() == ChannelDisplay.NONE)
|
||||
{
|
||||
return;
|
||||
return entries;
|
||||
}
|
||||
|
||||
List<PopoutEntry> entries = getPopoutEntries(model, area, cursor.x());
|
||||
|
||||
if(entries.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
||||
int shown = Math.min(entries.size(), POPOUT_MAX_CHANNELS);
|
||||
String more = entries.size() > shown ? "+ " + (entries.size() - shown) + " more" : null;
|
||||
|
||||
//Measure the card
|
||||
double textWidth = 0;
|
||||
int lineCount = 0;
|
||||
|
||||
for(int x = 0; x < shown; x++)
|
||||
{
|
||||
PopoutEntry entry = entries.get(x);
|
||||
textWidth = Math.max(textWidth, measure(entry.title(), POPOUT_TITLE_FONT) + POPOUT_SWATCH + 5);
|
||||
|
||||
for(String line: entry.details())
|
||||
{
|
||||
textWidth = Math.max(textWidth, measure(line, FONT));
|
||||
}
|
||||
|
||||
lineCount += 1 + entry.details().size();
|
||||
}
|
||||
|
||||
if(more != null)
|
||||
{
|
||||
textWidth = Math.max(textWidth, measure(more, FONT));
|
||||
lineCount++;
|
||||
}
|
||||
|
||||
double width = textWidth + (POPOUT_PADDING * 2);
|
||||
double height = (lineCount * mTextHeight) + ((shown - 1) * POPOUT_GAP) + (POPOUT_PADDING * 2);
|
||||
double bottom = section == DisplaySection.SPECTRUM ? area.plotHeight() : area.height();
|
||||
double x = Math.max(4, Math.min(area.width() - width - 4, cursor.x() - (width / 2.0)));
|
||||
double y = bottom - height - 6;
|
||||
|
||||
//Keep the card out from under the mouse
|
||||
if(cursor.y() >= y - 4)
|
||||
{
|
||||
y = 6;
|
||||
}
|
||||
|
||||
if(y < 0 || width > area.width())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
gc.setFill(theme.getBackground(0.88));
|
||||
gc.fillRoundRect(x, y, width, height, 8, 8);
|
||||
gc.setStroke(opaque(theme.getLine()));
|
||||
gc.setLineWidth(1.0);
|
||||
gc.strokeRoundRect(Math.floor(x) + 0.5, Math.floor(y) + 0.5, width, height, 8, 8);
|
||||
gc.setTextAlign(TextAlignment.LEFT);
|
||||
gc.setTextBaseline(VPos.TOP);
|
||||
|
||||
double lineY = y + POPOUT_PADDING;
|
||||
double textX = x + POPOUT_PADDING;
|
||||
|
||||
for(int index = 0; index < shown; index++)
|
||||
{
|
||||
PopoutEntry entry = entries.get(index);
|
||||
double swatchY = lineY + ((mTextHeight - POPOUT_SWATCH) / 2.0);
|
||||
gc.setFill(opaque(entry.color()));
|
||||
gc.fillRect(textX, swatchY, POPOUT_SWATCH, POPOUT_SWATCH);
|
||||
gc.setFill(theme.getCursor());
|
||||
gc.setFont(POPOUT_TITLE_FONT);
|
||||
gc.fillText(entry.title(), textX + POPOUT_SWATCH + 5, lineY);
|
||||
lineY += mTextHeight;
|
||||
gc.setFill(opaque(theme.getLine()));
|
||||
gc.setFont(FONT);
|
||||
|
||||
for(String line: entry.details())
|
||||
{
|
||||
gc.fillText(line, textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
}
|
||||
|
||||
lineY += POPOUT_GAP;
|
||||
}
|
||||
|
||||
if(more != null)
|
||||
{
|
||||
gc.fillText(more, textX, lineY - POPOUT_GAP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels under the screen x position whose labels don't fit in the channel box. The hit area of a narrow
|
||||
* channel is widened so it can be found with the mouse.
|
||||
*/
|
||||
private List<PopoutEntry> getPopoutEntries(SpectralDisplayModel model, RenderArea area, double cursorX)
|
||||
{
|
||||
List<PopoutEntry> entries = new ArrayList<>();
|
||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
||||
|
||||
for(Channel channel: getChannels(model))
|
||||
{
|
||||
if(!isShown(channel))
|
||||
@@ -523,38 +410,14 @@ public class ChannelLayer extends SpectralDisplayLayer
|
||||
continue;
|
||||
}
|
||||
|
||||
double hitWidth = Math.max(POPOUT_MIN_HIT_WIDTH, box.width());
|
||||
double hitWidth = Math.max(MIN_HIT_WIDTH, box.width());
|
||||
double hitStart = box.center() - (hitWidth / 2.0);
|
||||
|
||||
if(cursorX < hitStart || cursorX > hitStart + hitWidth || labelsFit(channel, box))
|
||||
if(cursor.x() >= hitStart && cursor.x() <= hitStart + hitWidth)
|
||||
{
|
||||
continue;
|
||||
entries.add(ChannelMenus.createCardEntry(channel, tunerChannel, !labelsFit(channel, box)));
|
||||
break;
|
||||
}
|
||||
|
||||
List<String> details = new ArrayList<>();
|
||||
String systemSite = join(channel.hasSystem() ? channel.getSystem() : null,
|
||||
channel.hasSite() ? channel.getSite() : null);
|
||||
|
||||
if(systemSite != null)
|
||||
{
|
||||
details.add(systemSite);
|
||||
}
|
||||
|
||||
String state = channel.isProcessing() ? "Enabled" : "Disabled";
|
||||
|
||||
if(channel.isSelected())
|
||||
{
|
||||
state += ", Selected";
|
||||
}
|
||||
|
||||
details.add(join(channel.getDecodeConfiguration().getDecoderType().getShortDisplayString(),
|
||||
FREQUENCY_FORMAT.format(tunerChannel.getFrequency() / 1E6) + " MHz", state));
|
||||
|
||||
Color color = channel.isSelected() ? theme.getChannelSelected() :
|
||||
channel.isProcessing() ? theme.getChannelProcessing() : theme.getChannel();
|
||||
entries.add(new PopoutEntry(channel.getName() != null ? channel.getName() : "(unnamed)", details,
|
||||
color));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,14 +586,9 @@ public class ChannelLayer extends SpectralDisplayLayer
|
||||
frequency <= tunerChannel.getMaxFrequency())
|
||||
{
|
||||
//Traffic channels are started and stopped by their decoder, not from the playlist
|
||||
if(!channel.isTrafficChannel() && mChannelProcessingManager != null)
|
||||
{
|
||||
items.add(createEnableItem(channel));
|
||||
}
|
||||
|
||||
MenuItem item = new MenuItem("View/Edit: " + channel.getShortTitle());
|
||||
item.setOnAction(e -> MyEventBus.getGlobalEventBus().post(new ViewChannelRequest(channel)));
|
||||
items.add(item);
|
||||
Runnable toggle = !channel.isTrafficChannel() && mChannelProcessingManager != null ?
|
||||
() -> toggle(channel) : null;
|
||||
items.add(ChannelMenus.createChannelEntry(channel, tunerChannel, toggle));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -739,14 +597,20 @@ public class ChannelLayer extends SpectralDisplayLayer
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContextMenuSection()
|
||||
{
|
||||
return ChannelMenus.SECTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu item that starts the channel when it's disabled, or stops it when it's enabled, in the background
|
||||
* Stops the channel when it's processing, otherwise starts it
|
||||
*/
|
||||
private MenuItem createEnableItem(Channel channel)
|
||||
private void toggle(Channel channel)
|
||||
{
|
||||
boolean processing = channel.isProcessing();
|
||||
MenuItem item = new MenuItem((processing ? "Disable: " : "Enable: ") + channel.getShortTitle());
|
||||
item.setOnAction(e -> ThreadPool.CACHED.execute(() -> {
|
||||
|
||||
ThreadPool.CACHED.execute(() -> {
|
||||
try
|
||||
{
|
||||
if(processing)
|
||||
@@ -762,8 +626,7 @@ public class ChannelLayer extends SpectralDisplayLayer
|
||||
{
|
||||
showError((processing ? "Can't stop " : "Can't start ") + channel.getShortTitle(), ce.getMessage());
|
||||
}
|
||||
}));
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -792,10 +655,4 @@ public class ChannelLayer extends SpectralDisplayLayer
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel details for the popout card.
|
||||
*/
|
||||
private record PopoutEntry(String title, List<String> details, Color color)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,24 +20,27 @@
|
||||
package io.github.dsheirer.gui.spectrum.layer;
|
||||
|
||||
import io.github.dsheirer.controller.channel.Channel;
|
||||
import io.github.dsheirer.eventbus.MyEventBus;
|
||||
import io.github.dsheirer.gui.playlist.radioreference.ViewRadioReferenceRequest;
|
||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
||||
import io.github.dsheirer.module.decode.DecoderType;
|
||||
import io.github.dsheirer.service.radioreference.SiteRecord;
|
||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import io.github.dsheirer.gui.spectrum.ChannelCardEntry;
|
||||
import io.github.dsheirer.gui.spectrum.ChannelMenus;
|
||||
import io.github.dsheirer.gui.spectrum.ChannelMenus.State;
|
||||
import io.github.dsheirer.gui.spectrum.ConfigurationRow;
|
||||
import io.github.dsheirer.gui.spectrum.CursorReadout;
|
||||
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
||||
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
||||
import io.github.dsheirer.gui.spectrum.RenderArea;
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayLayer;
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayModel;
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayTheme;
|
||||
import io.github.dsheirer.service.radioreference.DistanceFormat;
|
||||
import io.github.dsheirer.service.radioreference.FrequencyCandidate;
|
||||
import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex;
|
||||
@@ -45,76 +48,37 @@ import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex.Ra
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
import javafx.util.Duration;
|
||||
|
||||
/**
|
||||
* Radio reference candidates layer. When the mouse rests over the spectrum or the waterfall, shows a card next to the
|
||||
* mouse with the radio reference frequencies near the frequency under the mouse, nearest to the user's location first.
|
||||
* Radio reference candidates layer. Lists the radio reference frequencies near the frequency under the mouse,
|
||||
* nearest to the user's location first, in the Channels hover card (drawn by {@link ChannelCardLayer}) and the
|
||||
* Channels context menu. A candidate that a playlist channel already decodes is listed as that channel.
|
||||
*
|
||||
* The candidates come from the radio reference frequency index, which needs a premium account and the user's location.
|
||||
* Looking up a frequency doesn't call the web service.
|
||||
*/
|
||||
public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
{
|
||||
private static final Duration HOVER_DELAY = Duration.millis(400);
|
||||
private static final Font FONT = Font.font(11);
|
||||
private static final Font TITLE_FONT = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
||||
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
||||
private static final long MIN_TOLERANCE_HZ = 3_000;
|
||||
private static final double TOLERANCE_PIXELS = 3.0;
|
||||
private static final int MAX_CANDIDATES = 6;
|
||||
private static final double MAX_TEXT_WIDTH = 380;
|
||||
private static final double PADDING = 6;
|
||||
private static final double GAP = 5;
|
||||
//Space beside the text and below the readout lines, as in the cursor readout, so the readout lines stay in place
|
||||
private static final double PADDING_X = 4;
|
||||
//Space kept between the card and the edges of the section
|
||||
private static final double EDGE_MARGIN = 2;
|
||||
private static final double READOUT_PADDING = 2;
|
||||
private static final String HEADER = "Radio Reference";
|
||||
|
||||
private final RadioReferenceFrequencyIndex mIndex;
|
||||
private final RadioReferencePlaylistActions mActions;
|
||||
private final BooleanProperty mHoverCandidates = new SimpleBooleanProperty(true);
|
||||
private final Text mMeasure = new Text();
|
||||
private final double mTextHeight;
|
||||
private PauseTransition mHoverTimer;
|
||||
private DisplaySection mHoverSection;
|
||||
private double mHoverX = Double.NaN;
|
||||
private double mHoverY = Double.NaN;
|
||||
private boolean mHoverReady;
|
||||
private long mResultsFrequency = Long.MIN_VALUE;
|
||||
private long mResultsTolerance;
|
||||
private List<RankedCandidate> mResults = Collections.emptyList();
|
||||
private Card mCard;
|
||||
|
||||
/**
|
||||
* Candidate text of the card, measured once per lookup
|
||||
* @param entries lines of each candidate: the title, then the details
|
||||
* @param more line, or null
|
||||
* @param textWidth of the widest line
|
||||
* @param lineCount of the header, candidate and more lines
|
||||
* @param maxTextWidth that the lines were shortened to
|
||||
* @param maxHeight that the card was limited to
|
||||
* @param readoutLines that the card was sized for
|
||||
*/
|
||||
private record Card(List<List<String>> entries, String more, double textWidth, int lineCount,
|
||||
double maxTextWidth, double maxHeight, int readoutLines)
|
||||
{
|
||||
}
|
||||
private List<RankedCandidate> mCardCandidates;
|
||||
private List<ChannelCardEntry> mCardEntries = Collections.emptyList();
|
||||
private long mCardEntriesTime;
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
@@ -125,9 +89,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
{
|
||||
mIndex = index;
|
||||
mActions = actions;
|
||||
mMeasure.setFont(FONT);
|
||||
mMeasure.setText("Ag");
|
||||
mTextHeight = Math.ceil(mMeasure.getLayoutBounds().getHeight());
|
||||
mHoverCandidates.addListener((ob, ov, nv) -> requestRender());
|
||||
}
|
||||
|
||||
@@ -148,15 +109,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
if(mHoverTimer != null)
|
||||
{
|
||||
mHoverTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigurationTitle()
|
||||
{
|
||||
@@ -181,10 +133,17 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
return List.of(hover, new ConfigurationRow("Nearby", status));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContextMenuSection()
|
||||
{
|
||||
return ChannelMenus.SECTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context menu items for the candidates at the frequency, in the card's order: add a candidate to the playlist and
|
||||
* start it, or enable or disable the playlist channel that already decodes it. One item per site, and per
|
||||
* frequency and protocol, so an item never adds a duplicate channel.
|
||||
* Channel entries for the candidates at the frequency, in the card's order. A candidate that a playlist channel
|
||||
* already decodes is listed as that playlist channel, otherwise as a candidate to add to the playlist (and
|
||||
* start). Both can be viewed in the playlist editor's Radio Reference tab (View in Radio Reference). One entry per site, since the site's
|
||||
* frequencies share its channel. Adding never duplicates a playlist channel.
|
||||
*/
|
||||
@Override
|
||||
public List<MenuItem> getContextMenuItems(DisplaySection section, long frequency)
|
||||
@@ -219,139 +178,121 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
|
||||
if(site != null && offered.add(key))
|
||||
{
|
||||
addSiteItem(items, site, candidate, frequency);
|
||||
items.add(createSiteEntry(site, ranked));
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(offered.add("frequency:" + candidate.frequencyHz() + ":" + candidate.title() + ":" +
|
||||
candidate.source()))
|
||||
{
|
||||
DecoderType decoderType = RadioReferencePlaylistActions.getDecoderType(candidate);
|
||||
Set<DecoderType> family = RadioReferencePlaylistActions.getProtocolFamily(decoderType);
|
||||
String protocol = family.isEmpty() ? String.valueOf(candidate.mode()) : family.iterator().next().name();
|
||||
|
||||
if(offered.add("frequency:" + candidate.frequencyHz() + ":" + protocol))
|
||||
{
|
||||
addConventionalItem(items, candidate, decoderType, frequency);
|
||||
}
|
||||
items.add(createConventionalEntry(ranked, RadioReferencePlaylistActions.getDecoderType(candidate)));
|
||||
}
|
||||
}
|
||||
|
||||
if(!items.isEmpty())
|
||||
{
|
||||
MenuItem header = new MenuItem("Radio Reference");
|
||||
header.setDisable(true);
|
||||
items.add(0, header);
|
||||
}
|
||||
|
||||
//Playlist channels first, then the candidates, each in the card's order
|
||||
items.sort(Comparator.comparing(item -> item.getUserData() == null));
|
||||
return items;
|
||||
}
|
||||
|
||||
private void addSiteItem(List<MenuItem> items, SiteRecord site, FrequencyCandidate candidate, long frequency)
|
||||
/**
|
||||
* Entry for a trunked system site, or for the candidate's repeater of a repeater site (LTR)
|
||||
*/
|
||||
private Menu createSiteEntry(SiteRecord site, RankedCandidate ranked)
|
||||
{
|
||||
String label = site.systemName() + " \u00B7 Site " + site.siteNumber() +
|
||||
(site.description() != null ? " " + site.description() : "");
|
||||
FrequencyCandidate candidate = ranked.candidate();
|
||||
boolean repeater = RadioReferencePlaylistActions.isRepeaterSite(site);
|
||||
ViewRadioReferenceRequest view = ViewRadioReferenceRequest.site(site.systemId(), site.siteId());
|
||||
String unsupported = RadioReferencePlaylistActions.getUnsupportedReason(site);
|
||||
Channel existing = unsupported != null ? null : repeater ? mActions.findChannel(List.of(candidate.frequencyHz()),
|
||||
RadioReferencePlaylistActions.getSiteDecoderTypes(site)) : mActions.findSiteChannel(site);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
return createPlaylistEntry(existing, view);
|
||||
}
|
||||
|
||||
String title = site.systemName() + " \u00B7 Site " + site.siteNumber() +
|
||||
(site.description() != null ? " " + site.description() : "");
|
||||
|
||||
if(repeater)
|
||||
{
|
||||
title += site.channels().stream().filter(channel -> channel.frequencyHz() == candidate.frequencyHz() &&
|
||||
channel.logicalChannelNumber() > 0).map(channel -> " LCN " + channel.logicalChannelNumber())
|
||||
.findFirst().orElse("");
|
||||
}
|
||||
|
||||
Menu menu = ChannelMenus.createEntry(title, describe(ranked), State.CANDIDATE, null);
|
||||
|
||||
if(unsupported != null)
|
||||
{
|
||||
MenuItem item = new MenuItem(label + " \u2013 " + unsupported);
|
||||
item.setDisable(true);
|
||||
items.add(item);
|
||||
return;
|
||||
menu.getItems().add(ChannelMenus.createNote(unsupported));
|
||||
}
|
||||
|
||||
if(RadioReferencePlaylistActions.isRepeaterSite(site))
|
||||
else if(repeater)
|
||||
{
|
||||
addRepeaterItem(items, site, candidate.frequencyHz(), label, frequency);
|
||||
return;
|
||||
}
|
||||
|
||||
Channel existing = mActions.findSiteChannel(site);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
//The channel layer offers the channels at the clicked frequency
|
||||
if(!covers(existing, frequency))
|
||||
{
|
||||
items.add(createEnableItem(existing));
|
||||
}
|
||||
menu.getItems().addAll(
|
||||
ChannelMenus.createItem("Add to Playlist and Start", State.CANDIDATE,
|
||||
() -> mActions.addRepeater(site, candidate.frequencyHz(), true, this::showError)),
|
||||
ChannelMenus.createItem("Add to Playlist", State.CANDIDATE,
|
||||
() -> mActions.addRepeater(site, candidate.frequencyHz(), false, this::showError)));
|
||||
}
|
||||
else
|
||||
{
|
||||
MenuItem item = new MenuItem("Add and Start: " + label);
|
||||
//Start on the right-clicked frequency when it's a control or alternate control channel
|
||||
item.setOnAction(event -> mActions.addSite(site, candidate.frequencyHz(), this::showError));
|
||||
items.add(item);
|
||||
//Start on the candidate frequency when it's a control or alternate control channel
|
||||
menu.getItems().addAll(
|
||||
ChannelMenus.createItem("Add to Playlist and Start", State.CANDIDATE,
|
||||
() -> mActions.addSite(site, candidate.frequencyHz(), true, this::showError)),
|
||||
ChannelMenus.createItem("Add to Playlist", State.CANDIDATE,
|
||||
() -> mActions.addSite(site, candidate.frequencyHz(), false, this::showError)));
|
||||
}
|
||||
|
||||
addViewItem(menu, State.CANDIDATE, view);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu item for one repeater of a repeater site (LTR): add and start it, or enable or disable its channel
|
||||
* Entry for a conventional frequency
|
||||
*/
|
||||
private void addRepeaterItem(List<MenuItem> items, SiteRecord site, long repeaterFrequency, String label,
|
||||
long frequency)
|
||||
private Menu createConventionalEntry(RankedCandidate ranked, DecoderType decoderType)
|
||||
{
|
||||
Channel existing = mActions.findChannel(List.of(repeaterFrequency),
|
||||
RadioReferencePlaylistActions.getSiteDecoderTypes(site));
|
||||
FrequencyCandidate candidate = ranked.candidate();
|
||||
String sourceKey = mIndex.getSourceKey(candidate);
|
||||
ViewRadioReferenceRequest view = sourceKey != null ?
|
||||
ViewRadioReferenceRequest.frequency(sourceKey, candidate) : null;
|
||||
Channel existing = decoderType != null ? mActions.findConventionalChannel(candidate) : null;
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
if(!covers(existing, frequency))
|
||||
{
|
||||
items.add(createEnableItem(existing));
|
||||
}
|
||||
|
||||
return;
|
||||
return createPlaylistEntry(existing, view);
|
||||
}
|
||||
|
||||
String lcn = site.channels().stream().filter(channel -> channel.frequencyHz() == repeaterFrequency &&
|
||||
channel.logicalChannelNumber() > 0).map(channel -> " LCN " + channel.logicalChannelNumber())
|
||||
.findFirst().orElse("");
|
||||
MenuItem item = new MenuItem("Add and Start: " + label + lcn + " (" +
|
||||
FREQUENCY_FORMAT.format(repeaterFrequency / 1E6) + " MHz)");
|
||||
item.setOnAction(event -> mActions.addRepeater(site, repeaterFrequency, this::showError));
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
private void addConventionalItem(List<MenuItem> items, FrequencyCandidate candidate, DecoderType decoderType,
|
||||
long frequency)
|
||||
{
|
||||
String label = candidate.title() + " (" + FREQUENCY_FORMAT.format(candidate.frequencyHz() / 1E6) + " MHz" +
|
||||
(candidate.mode() != null ? " " + candidate.mode() : "") + ")";
|
||||
Menu menu = ChannelMenus.createEntry(candidate.title() != null ? candidate.title() : "(untitled)",
|
||||
describe(ranked), State.CANDIDATE, null);
|
||||
|
||||
if(decoderType == null)
|
||||
{
|
||||
MenuItem item = new MenuItem(label + " \u2013 mode isn't supported");
|
||||
item.setDisable(true);
|
||||
items.add(item);
|
||||
return;
|
||||
}
|
||||
|
||||
Channel existing = mActions.findConventionalChannel(candidate);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
if(!covers(existing, frequency))
|
||||
{
|
||||
items.add(createEnableItem(existing));
|
||||
}
|
||||
menu.getItems().add(ChannelMenus.createNote("Mode isn't supported"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MenuItem item = new MenuItem("Add and Start: " + label);
|
||||
item.setOnAction(event -> mActions.addConventional(candidate, this::showError));
|
||||
items.add(item);
|
||||
menu.getItems().addAll(
|
||||
ChannelMenus.createItem("Add to Playlist and Start", State.CANDIDATE,
|
||||
() -> mActions.addConventional(candidate, true, this::showError)),
|
||||
ChannelMenus.createItem("Add to Playlist", State.CANDIDATE,
|
||||
() -> mActions.addConventional(candidate, false, this::showError)));
|
||||
}
|
||||
|
||||
addViewItem(menu, State.CANDIDATE, view);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu item that enables the playlist channel when it's disabled, or disables it when it's enabled
|
||||
* Entry for the playlist channel that decodes a candidate: enable or disable it, view or edit it, and view the
|
||||
* candidate in the Radio Reference tab
|
||||
* @param view request for the candidate, or null when its listing isn't known
|
||||
*/
|
||||
private MenuItem createEnableItem(Channel channel)
|
||||
private Menu createPlaylistEntry(Channel channel, ViewRadioReferenceRequest view)
|
||||
{
|
||||
boolean processing = channel.isProcessing();
|
||||
MenuItem item = new MenuItem((processing ? "Disable: " : "Enable: ") + channel.getShortTitle());
|
||||
item.setOnAction(event -> {
|
||||
if(processing)
|
||||
Runnable toggle = channel.isTrafficChannel() ? null : () -> {
|
||||
if(channel.isProcessing())
|
||||
{
|
||||
mActions.disable(channel, this::showError);
|
||||
}
|
||||
@@ -359,25 +300,22 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
{
|
||||
mActions.enable(channel, this::showError);
|
||||
}
|
||||
});
|
||||
return item;
|
||||
};
|
||||
Menu menu = ChannelMenus.createChannelEntry(channel, null, toggle);
|
||||
addViewItem(menu, channel.isProcessing() ? State.ENABLED : State.DISABLED, view);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if one of the channel's tuner channels includes the frequency
|
||||
* Adds the item that shows the candidate in the playlist editor's Radio Reference tab
|
||||
* @param request to show the candidate, or null when the candidate's listing isn't known
|
||||
*/
|
||||
private static boolean covers(Channel channel, long frequency)
|
||||
private static void addViewItem(Menu menu, State state, ViewRadioReferenceRequest request)
|
||||
{
|
||||
for(TunerChannel tunerChannel: channel.getTunerChannels())
|
||||
{
|
||||
if(tunerChannel != null && tunerChannel.getMinFrequency() <= frequency &&
|
||||
frequency <= tunerChannel.getMaxFrequency())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
MenuItem view = ChannelMenus.createItem("View in Radio Reference", state,
|
||||
() -> MyEventBus.getGlobalEventBus().post(request));
|
||||
view.setDisable(request == null);
|
||||
menu.getItems().addAll(ChannelMenus.createSeparator(), view);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,49 +337,88 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSpectrumForeground(GraphicsContext gc, RenderArea area)
|
||||
{
|
||||
render(gc, area, DisplaySection.SPECTRUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWaterfall(GraphicsContext gc, RenderArea area)
|
||||
{
|
||||
render(gc, area, DisplaySection.WATERFALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the card in the section under the mouse once the mouse has rested for the hover delay
|
||||
*/
|
||||
private void render(GraphicsContext gc, RenderArea area, DisplaySection section)
|
||||
{
|
||||
DisplayCursor cursor = getSpectralDisplay() != null ? getSpectralDisplay().getDisplayCursor() : null;
|
||||
trackHover(cursor);
|
||||
|
||||
if(cursor != null && cursor.section() == section && replacesCursorReadout(cursor, area))
|
||||
{
|
||||
drawCard(gc, area, cursor, getCandidates(cursor.frequency(), getTolerance(getModel(), area)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The card replaces the cursor readout while it's shown: it ends with the readout lines, in the readout's place.
|
||||
* Card entries for the candidates at the mouse position, in the card's order. A candidate that a playlist
|
||||
* channel already decodes is listed as that playlist channel.
|
||||
*/
|
||||
@Override
|
||||
public boolean replacesCursorReadout(DisplayCursor cursor, RenderArea area)
|
||||
public List<ChannelCardEntry> getCardEntries(DisplayCursor cursor, RenderArea area)
|
||||
{
|
||||
SpectralDisplayModel model = getModel();
|
||||
|
||||
//Only for the position the mouse rested at - the readout comes back as soon as the mouse moves
|
||||
if(mIndex == null || !mHoverCandidates.get() || !mHoverReady || model == null || !model.hasSource() ||
|
||||
cursor == null || cursor.section() != mHoverSection || cursor.x() != mHoverX || cursor.y() != mHoverY ||
|
||||
area.width() <= 0)
|
||||
if(mIndex == null || !mHoverCandidates.get() || model == null || area.width() <= 0)
|
||||
{
|
||||
return false;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return !getCandidates(cursor.frequency(), getTolerance(model, area)).isEmpty();
|
||||
List<RankedCandidate> candidates = getCandidates(cursor.frequency(), getTolerance(model, area));
|
||||
|
||||
//The playlist channels of the candidates, looked up once per lookup or second, since that copies the playlist
|
||||
if(candidates != mCardCandidates || System.currentTimeMillis() - mCardEntriesTime > 1000)
|
||||
{
|
||||
mCardCandidates = candidates;
|
||||
mCardEntriesTime = System.currentTimeMillis();
|
||||
mCardEntries = createCardEntries(candidates);
|
||||
}
|
||||
|
||||
return mCardEntries;
|
||||
}
|
||||
|
||||
private List<ChannelCardEntry> createCardEntries(List<RankedCandidate> candidates)
|
||||
{
|
||||
List<ChannelCardEntry> entries = new ArrayList<>();
|
||||
Set<String> listed = new HashSet<>();
|
||||
|
||||
for(RankedCandidate ranked: candidates)
|
||||
{
|
||||
FrequencyCandidate candidate = ranked.candidate();
|
||||
Channel existing = mActions != null ? findChannel(candidate) : null;
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
entries.add(ChannelMenus.createCardEntry(existing, null, true));
|
||||
}
|
||||
//The same listing in several places (e.g. a county and its agency) is shown once
|
||||
else if(listed.add(candidate.frequencyHz() + "|" + candidate.title() + "|" + candidate.source()))
|
||||
{
|
||||
List<String> details = new ArrayList<>();
|
||||
details.add(describe(ranked));
|
||||
String source = source(candidate);
|
||||
|
||||
if(source != null)
|
||||
{
|
||||
details.add(source);
|
||||
}
|
||||
|
||||
String title = candidate.title() != null ? candidate.title() : "(untitled)";
|
||||
entries.add(new ChannelCardEntry(title, details, State.CANDIDATE, null, true));
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Playlist channel that decodes the candidate, or null
|
||||
*/
|
||||
private Channel findChannel(FrequencyCandidate candidate)
|
||||
{
|
||||
if(candidate.isSiteFrequency())
|
||||
{
|
||||
SiteRecord site = mIndex.getSite(candidate.systemId(), candidate.siteId());
|
||||
|
||||
if(site == null || RadioReferencePlaylistActions.getUnsupportedReason(site) != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return RadioReferencePlaylistActions.isRepeaterSite(site) ?
|
||||
mActions.findChannel(List.of(candidate.frequencyHz()),
|
||||
RadioReferencePlaylistActions.getSiteDecoderTypes(site)) : mActions.findSiteChannel(site);
|
||||
}
|
||||
|
||||
return RadioReferencePlaylistActions.getDecoderType(candidate) != null ?
|
||||
mActions.findConventionalChannel(candidate) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,47 +430,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
return Math.max(MIN_TOLERANCE_HZ, Math.round(Math.max(TOLERANCE_PIXELS * hertzPerPixel, model.getBinWidth())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the hover delay each time the mouse moves, and hides the card until it passes
|
||||
*/
|
||||
private void trackHover(DisplayCursor cursor)
|
||||
{
|
||||
if(cursor == null)
|
||||
{
|
||||
if(mHoverSection != null)
|
||||
{
|
||||
mHoverSection = null;
|
||||
mHoverReady = false;
|
||||
getHoverTimer().stop();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(cursor.section() != mHoverSection || cursor.x() != mHoverX || cursor.y() != mHoverY)
|
||||
{
|
||||
mHoverSection = cursor.section();
|
||||
mHoverX = cursor.x();
|
||||
mHoverY = cursor.y();
|
||||
mHoverReady = false;
|
||||
getHoverTimer().playFromStart();
|
||||
}
|
||||
}
|
||||
|
||||
private PauseTransition getHoverTimer()
|
||||
{
|
||||
if(mHoverTimer == null)
|
||||
{
|
||||
mHoverTimer = new PauseTransition(HOVER_DELAY);
|
||||
mHoverTimer.setOnFinished(event -> {
|
||||
mHoverReady = true;
|
||||
requestRender();
|
||||
});
|
||||
}
|
||||
|
||||
return mHoverTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Candidates for the frequency, looked up again only when the frequency or the tolerance changes
|
||||
*/
|
||||
@@ -504,172 +440,11 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
mResults = mIndex.lookup(frequency, tolerance);
|
||||
mResultsFrequency = frequency;
|
||||
mResultsTolerance = tolerance;
|
||||
mCard = null;
|
||||
}
|
||||
|
||||
return mResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the card in place of the cursor readout: beside the mouse and above it, placed like the readout, with the
|
||||
* candidates above the readout lines so the frequency and level stay where the readout showed them. The card
|
||||
* fits the larger side of the mouse and the height of the section, showing as many candidates as fit.
|
||||
*/
|
||||
private void drawCard(GraphicsContext gc, RenderArea area, DisplayCursor cursor, List<RankedCandidate> candidates)
|
||||
{
|
||||
//The level line changes with the mouse height while the candidates don't
|
||||
List<String> readout = CursorReadout.lines(cursor, area, getModel());
|
||||
double readoutWidth = 0;
|
||||
|
||||
for(String line: readout)
|
||||
{
|
||||
readoutWidth = Math.max(readoutWidth, measure(line, FONT));
|
||||
}
|
||||
|
||||
double room = Math.max(area.width() - cursor.x(), cursor.x()) - CursorReadout.GAP_X - EDGE_MARGIN;
|
||||
double maxTextWidth = Math.max(readoutWidth, Math.min(MAX_TEXT_WIDTH, room - (PADDING_X * 2)));
|
||||
//Above the mouse, so the readout lines stay where the readout showed them, when a candidate fits there
|
||||
double above = cursor.y() - CursorReadout.GAP_Y;
|
||||
double maxHeight = above >= cardHeight(5, 1, true, readout.size()) ? above : area.plotHeight() - EDGE_MARGIN;
|
||||
|
||||
if(mCard == null || mCard.maxTextWidth() != maxTextWidth || mCard.maxHeight() != maxHeight ||
|
||||
mCard.readoutLines() != readout.size())
|
||||
{
|
||||
mCard = createCard(candidates, maxTextWidth, maxHeight, readout.size());
|
||||
}
|
||||
|
||||
Card card = mCard;
|
||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
||||
double width = Math.max(card.textWidth(), readoutWidth) + (PADDING_X * 2);
|
||||
double height = cardHeight(card.lineCount(), card.entries().size(), card.more() != null, readout.size());
|
||||
double x = Math.max(0, CursorReadout.x(cursor, width, area));
|
||||
double y = CursorReadout.y(cursor, height, area);
|
||||
|
||||
gc.setFill(theme.getBackground(0.92));
|
||||
gc.fillRoundRect(x, y, width, height, 8, 8);
|
||||
gc.setStroke(opaque(theme.getLine()));
|
||||
gc.setLineWidth(1.0);
|
||||
gc.strokeRoundRect(Math.floor(x) + 0.5, Math.floor(y) + 0.5, width, height, 8, 8);
|
||||
gc.setTextAlign(TextAlignment.LEFT);
|
||||
gc.setTextBaseline(VPos.TOP);
|
||||
|
||||
double textX = x + PADDING_X;
|
||||
double lineY = y + PADDING;
|
||||
gc.setFill(theme.getCursor());
|
||||
gc.setFont(TITLE_FONT);
|
||||
gc.fillText(HEADER, textX, lineY);
|
||||
lineY += mTextHeight + GAP;
|
||||
|
||||
for(List<String> lines: card.entries())
|
||||
{
|
||||
gc.setFill(theme.getCursor());
|
||||
gc.setFont(TITLE_FONT);
|
||||
gc.fillText(lines.get(0), textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
gc.setFill(opaque(theme.getLine()));
|
||||
gc.setFont(FONT);
|
||||
|
||||
for(int line = 1; line < lines.size(); line++)
|
||||
{
|
||||
gc.fillText(lines.get(line), textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
}
|
||||
|
||||
lineY += GAP;
|
||||
}
|
||||
|
||||
if(card.more() != null)
|
||||
{
|
||||
gc.setFill(opaque(theme.getLine()));
|
||||
gc.setFont(FONT);
|
||||
gc.fillText(card.more(), textX, lineY);
|
||||
lineY += mTextHeight + GAP;
|
||||
}
|
||||
|
||||
//The readout lines, separated from the candidates, in the readout's style
|
||||
double separator = Math.floor(lineY - (GAP / 2.0)) + 0.5;
|
||||
gc.setStroke(theme.getLine(0.5));
|
||||
gc.strokeLine(textX, separator, x + width - PADDING_X, separator);
|
||||
gc.setFill(theme.getCursor());
|
||||
gc.setFont(FONT);
|
||||
|
||||
for(String line: readout)
|
||||
{
|
||||
gc.fillText(line, textX, lineY);
|
||||
lineY += mTextHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Height of a card with the lines
|
||||
* @param lineCount of the header, candidate and more lines
|
||||
* @param entries number of candidates
|
||||
* @param more true when the card has a more line
|
||||
* @param readoutLines number of readout lines
|
||||
*/
|
||||
private double cardHeight(int lineCount, int entries, boolean more, int readoutLines)
|
||||
{
|
||||
int gaps = 1 + entries + (more ? 1 : 0);
|
||||
return ((lineCount + readoutLines) * mTextHeight) + (gaps * GAP) + PADDING + READOUT_PADDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Card text for as many candidates as fit the height: each candidate's title, details and source, shortened to
|
||||
* the width
|
||||
*/
|
||||
private Card createCard(List<RankedCandidate> candidates, double maxTextWidth, double maxHeight,
|
||||
int readoutLines)
|
||||
{
|
||||
int limit = Math.min(candidates.size(), MAX_CANDIDATES);
|
||||
List<List<String>> entries = new ArrayList<>();
|
||||
double textWidth = measure(HEADER, TITLE_FONT);
|
||||
int lineCount = 1;
|
||||
|
||||
for(int index = 0; index < limit; index++)
|
||||
{
|
||||
RankedCandidate candidate = candidates.get(index);
|
||||
List<String> lines = new ArrayList<>();
|
||||
String title = candidate.candidate().title() != null ? candidate.candidate().title() : "(untitled)";
|
||||
lines.add(fit(title, TITLE_FONT, maxTextWidth));
|
||||
lines.add(fit(describe(candidate), FONT, maxTextWidth));
|
||||
String source = source(candidate.candidate());
|
||||
|
||||
if(source != null)
|
||||
{
|
||||
lines.add(fit(source, FONT, maxTextWidth));
|
||||
}
|
||||
|
||||
//Keep room for the more line when candidates are left out
|
||||
boolean more = index + 1 < candidates.size();
|
||||
|
||||
if(!entries.isEmpty() && cardHeight(lineCount + lines.size() + (more ? 1 : 0), entries.size() + 1, more,
|
||||
readoutLines) > maxHeight)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
textWidth = Math.max(textWidth, measure(lines.get(0), TITLE_FONT));
|
||||
|
||||
for(int line = 1; line < lines.size(); line++)
|
||||
{
|
||||
textWidth = Math.max(textWidth, measure(lines.get(line), FONT));
|
||||
}
|
||||
|
||||
lineCount += lines.size();
|
||||
entries.add(lines);
|
||||
}
|
||||
|
||||
String more = candidates.size() > entries.size() ? "+ " + (candidates.size() - entries.size()) + " more" : null;
|
||||
|
||||
if(more != null)
|
||||
{
|
||||
textWidth = Math.max(textWidth, measure(more, FONT));
|
||||
lineCount++;
|
||||
}
|
||||
|
||||
return new Card(entries, more, textWidth, lineCount, maxTextWidth, maxHeight, readoutLines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frequency, mode or use, tone, encryption and distance of the candidate
|
||||
*/
|
||||
@@ -691,35 +466,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
return join(alphaTag, candidate.source());
|
||||
}
|
||||
|
||||
/**
|
||||
* Text shortened with an ellipsis to fit the width
|
||||
*/
|
||||
private String fit(String text, Font font, double maxWidth)
|
||||
{
|
||||
if(measure(text, font) <= maxWidth)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
int length = text.length();
|
||||
|
||||
while(length > 1 && measure(text.substring(0, length) + "…", font) > maxWidth)
|
||||
{
|
||||
length--;
|
||||
}
|
||||
|
||||
return text.substring(0, length) + "…";
|
||||
}
|
||||
|
||||
private double measure(String text, Font font)
|
||||
{
|
||||
mMeasure.setFont(font);
|
||||
mMeasure.setText(text);
|
||||
double width = mMeasure.getLayoutBounds().getWidth();
|
||||
mMeasure.setFont(FONT);
|
||||
return width;
|
||||
}
|
||||
|
||||
private static String join(String... values)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -739,9 +485,4 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||
|
||||
return sb.isEmpty() ? null : sb.toString();
|
||||
}
|
||||
|
||||
private static Color opaque(Color color)
|
||||
{
|
||||
return Color.color(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user