mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-21 13:05:43 -05:00
* Removes the FlatLaf, JIDE, MigLayout and jiconfont-swing dependencies; the runtime image no longer includes javafx.swing. * Removes the Swing channelizer developer viewers and the Swing spectrum panel; the symbol, sync and filter debug viewers are plain JavaFX windows. * ChannelMapModel is no longer a Swing list model; removes unused Swing color menu items and models. * Removes the Swing image methods from the icon classes; icons load as JavaFX images. * Themes no longer use FlatLaf: each theme stores its palette and ThemeManager styles JavaFX only. * The channel auto-start countdown, the event and message filter editor and the alias and deadlock alerts are now JavaFX. The main window only stores split pane divider positions after the user drags a divider. * Main window converted to JavaFX, with a spectrum and waterfall display that can be hidden. * A hidden spectrum and waterfall is disposed so that it uses no processing or memory. Show or hide it from the View menu, Ctrl+Shift+S, the display settings panel or the bar shown while it is hidden. * Streaming status panel converted to JavaFX with status chips, a summary, configurable columns and a shortcut to the streaming editor. * BroadcastModel is no longer a Swing table model. * Audio panel converted to JavaFX and redesigned as a prominent playback display at the top of the main window. * Mono and stereo outputs show one display per channel with the TO alias, icon and color, the FROM radio, system/site/channel, elapsed time, a level meter and per-channel mute. The master section has mute all, volume and audio device settings. * Renames JavaFxWindowManager to WindowManager and removes its standalone launcher and the remaining Swing-era comments. Co-authored-by: denny <dennis.sheirer@gmail.com>
193 lines
5.6 KiB
Java
193 lines
5.6 KiB
Java
/*
|
|
* *****************************************************************************
|
|
* Copyright (C) 2014-2022 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.alias.action;
|
|
|
|
import io.github.dsheirer.gui.FxToolkit;
|
|
import javafx.application.Platform;
|
|
import javafx.scene.control.Alert;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
|
import io.github.dsheirer.alias.Alias;
|
|
import io.github.dsheirer.message.IMessage;
|
|
import io.github.dsheirer.util.ThreadPool;
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
public abstract class RecurringAction extends AliasAction
|
|
{
|
|
@JsonIgnore
|
|
protected AtomicBoolean mRunning = new AtomicBoolean(false);
|
|
@JsonIgnore
|
|
private ScheduledFuture<?> mPerpetualAction;
|
|
|
|
protected Interval mInterval = Interval.ONCE;
|
|
protected int mPeriod = 5;
|
|
|
|
public abstract void performAction(Alias alias, IMessage message);
|
|
|
|
@Override
|
|
public void execute(Alias alias, IMessage message)
|
|
{
|
|
if(mRunning.compareAndSet(false, true))
|
|
{
|
|
switch(mInterval)
|
|
{
|
|
case ONCE:
|
|
performThreadedAction(alias, message);
|
|
/* Don't reset */
|
|
break;
|
|
case DELAYED_RESET:
|
|
performThreadedAction(alias, message);
|
|
ThreadPool.SCHEDULED.schedule(new ResetTask(), mPeriod, TimeUnit.SECONDS);
|
|
break;
|
|
case UNTIL_DISMISSED:
|
|
mPerpetualAction = ThreadPool.SCHEDULED.scheduleAtFixedRate(
|
|
new PerformActionTask(alias, message), 0, mPeriod, TimeUnit.SECONDS);
|
|
|
|
String text = "Alias [" + alias.getName() + "] is active in message [" + message + "]";
|
|
|
|
Runnable dismissed = () -> {
|
|
dismiss(false);
|
|
ThreadPool.SCHEDULED.schedule(new ResetTask(), 15, TimeUnit.SECONDS);
|
|
};
|
|
|
|
if(FxToolkit.isStarted())
|
|
{
|
|
//The action repeats until the user closes the alert
|
|
Platform.runLater(() -> {
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION, text);
|
|
alert.setTitle("Alias Alert");
|
|
alert.setHeaderText(null);
|
|
alert.setOnHidden(event -> dismissed.run());
|
|
alert.show();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
dismissed.run();
|
|
}
|
|
break;
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Spawns the performAction() event into a new thread so that it doesn't
|
|
* delay any decoder actions.
|
|
*/
|
|
private void performThreadedAction(final Alias alias, final IMessage message)
|
|
{
|
|
ThreadPool.CACHED.execute(() -> performAction(alias, message));
|
|
}
|
|
|
|
@Override
|
|
public void dismiss(boolean reset)
|
|
{
|
|
if(mPerpetualAction != null)
|
|
{
|
|
mPerpetualAction.cancel(true);
|
|
|
|
mPerpetualAction = null;
|
|
}
|
|
|
|
if(reset)
|
|
{
|
|
mRunning.set(false);
|
|
}
|
|
}
|
|
|
|
@JacksonXmlProperty(isAttribute = true, localName = "period")
|
|
public int getPeriod()
|
|
{
|
|
return mPeriod;
|
|
}
|
|
|
|
public void setPeriod(int period)
|
|
{
|
|
mPeriod = period;
|
|
updateValueProperty();
|
|
}
|
|
|
|
@JacksonXmlProperty(isAttribute = true, localName = "interval")
|
|
public Interval getInterval()
|
|
{
|
|
return mInterval;
|
|
}
|
|
|
|
public void setInterval(Interval interval)
|
|
{
|
|
mInterval = interval;
|
|
mRunning.set(false);
|
|
updateValueProperty();
|
|
}
|
|
|
|
public enum Interval
|
|
{
|
|
ONCE("Once"),
|
|
DELAYED_RESET("Once - Reset After Delay"),
|
|
UNTIL_DISMISSED("Until Dismissed");
|
|
|
|
private String mLabel;
|
|
|
|
Interval(String label)
|
|
{
|
|
mLabel = label;
|
|
}
|
|
|
|
public String toString()
|
|
{
|
|
return mLabel;
|
|
}
|
|
}
|
|
|
|
public class PerformActionTask implements Runnable
|
|
{
|
|
private Alias mAlias;
|
|
private IMessage mMessage;
|
|
|
|
public PerformActionTask(Alias alias, IMessage message)
|
|
{
|
|
mAlias = alias;
|
|
mMessage = message;
|
|
}
|
|
|
|
@Override
|
|
public void run()
|
|
{
|
|
/* Don't use the performThreadedAction() method, since this is
|
|
* already running in a separate thread */
|
|
performAction(mAlias, mMessage);
|
|
}
|
|
}
|
|
|
|
public class ResetTask implements Runnable
|
|
{
|
|
@Override
|
|
public void run()
|
|
{
|
|
mRunning.set(false);
|
|
}
|
|
}
|
|
}
|