mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-17 11:07:35 -05:00
#1500 Makes Channel Auto-Start timeout a user-preference item to select in range 0-30 seconds. (#1501)
Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* ******************************************************************************
|
* *****************************************************************************
|
||||||
* sdrtrunk
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -15,22 +14,13 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
* *****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
package io.github.dsheirer.controller.channel;
|
package io.github.dsheirer.controller.channel;
|
||||||
|
|
||||||
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
import io.github.dsheirer.sample.Listener;
|
import io.github.dsheirer.sample.Listener;
|
||||||
import io.github.dsheirer.util.ThreadPool;
|
import io.github.dsheirer.util.ThreadPool;
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@@ -41,12 +31,21 @@ import java.util.List;
|
|||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
|
||||||
public class ChannelAutoStartFrame extends JFrame
|
public class ChannelAutoStartFrame extends JFrame
|
||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger(ChannelAutoStartFrame.class);
|
private final static Logger mLog = LoggerFactory.getLogger(ChannelAutoStartFrame.class);
|
||||||
|
|
||||||
private static final int COUNTDOWN_SECONDS = 10;
|
|
||||||
private Listener<ChannelEvent> mChannelEventListener;
|
private Listener<ChannelEvent> mChannelEventListener;
|
||||||
private List<Channel> mChannels;
|
private List<Channel> mChannels;
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ public class ChannelAutoStartFrame extends JFrame
|
|||||||
private JButton mCancelButton;
|
private JButton mCancelButton;
|
||||||
private JTable mChannelTable;
|
private JTable mChannelTable;
|
||||||
private AtomicBoolean mChannelsStarted = new AtomicBoolean();
|
private AtomicBoolean mChannelsStarted = new AtomicBoolean();
|
||||||
|
private int mAutoStartTimeoutSeconds;
|
||||||
private ScheduledFuture<?> mTimerFuture;
|
private ScheduledFuture<?> mTimerFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,10 +65,12 @@ public class ChannelAutoStartFrame extends JFrame
|
|||||||
* @param listener to receive channel start/enable request(s)
|
* @param listener to receive channel start/enable request(s)
|
||||||
* @param channels to auto-start
|
* @param channels to auto-start
|
||||||
*/
|
*/
|
||||||
public ChannelAutoStartFrame(Listener<ChannelEvent> listener, List<Channel> channels)
|
public ChannelAutoStartFrame(Listener<ChannelEvent> listener, List<Channel> channels, UserPreferences userPreferences)
|
||||||
{
|
{
|
||||||
mChannelEventListener = listener;
|
mChannelEventListener = listener;
|
||||||
mChannels = channels;
|
mChannels = channels;
|
||||||
|
mAutoStartTimeoutSeconds = userPreferences.getApplicationPreference().getChannelAutoStartTimeout();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
EventQueue.invokeLater(() -> {
|
EventQueue.invokeLater(() -> {
|
||||||
@@ -100,7 +101,7 @@ public class ChannelAutoStartFrame extends JFrame
|
|||||||
"[][][grow,fill][]"));
|
"[][][grow,fill][]"));
|
||||||
panel.add(new JLabel("The following channels will be automatically"), "span");
|
panel.add(new JLabel("The following channels will be automatically"), "span");
|
||||||
|
|
||||||
mCountdownLabel = new JLabel(getCountdownText(COUNTDOWN_SECONDS));
|
mCountdownLabel = new JLabel(getCountdownText(mAutoStartTimeoutSeconds));
|
||||||
panel.add(mCountdownLabel, "span");
|
panel.add(mCountdownLabel, "span");
|
||||||
|
|
||||||
panel.add(new JScrollPane(getChannelTable()), "span");
|
panel.add(new JScrollPane(getChannelTable()), "span");
|
||||||
@@ -220,7 +221,7 @@ public class ChannelAutoStartFrame extends JFrame
|
|||||||
*/
|
*/
|
||||||
public class CountdownTimer implements Runnable
|
public class CountdownTimer implements Runnable
|
||||||
{
|
{
|
||||||
private int mCount = COUNTDOWN_SECONDS;
|
private int mCount = mAutoStartTimeoutSeconds;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new ChannelAutoStartFrame(mPlaylistManager.getChannelProcessingManager(), channels);
|
new ChannelAutoStartFrame(mPlaylistManager.getChannelProcessingManager(), channels, mUserPreferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package io.github.dsheirer.gui.preference;
|
package io.github.dsheirer.gui.preference;
|
||||||
|
|
||||||
|
import io.github.dsheirer.gui.preference.application.ApplicationPreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.calibration.VectorCalibrationPreferenceEditor;
|
import io.github.dsheirer.gui.preference.calibration.VectorCalibrationPreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.decoder.JmbeLibraryPreferenceEditor;
|
import io.github.dsheirer.gui.preference.decoder.JmbeLibraryPreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.directory.DirectoryPreferenceEditor;
|
import io.github.dsheirer.gui.preference.directory.DirectoryPreferenceEditor;
|
||||||
@@ -39,6 +40,8 @@ public class PreferenceEditorFactory
|
|||||||
{
|
{
|
||||||
switch(preferenceEditorType)
|
switch(preferenceEditorType)
|
||||||
{
|
{
|
||||||
|
case APPLICATION:
|
||||||
|
return new ApplicationPreferenceEditor(userPreferences);
|
||||||
case AUDIO_DUPLICATE_CALL_DETECTION:
|
case AUDIO_DUPLICATE_CALL_DETECTION:
|
||||||
return new DuplicateCallPreferenceEditor(userPreferences);
|
return new DuplicateCallPreferenceEditor(userPreferences);
|
||||||
case AUDIO_MP3:
|
case AUDIO_MP3:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -24,6 +24,7 @@ package io.github.dsheirer.gui.preference;
|
|||||||
*/
|
*/
|
||||||
public enum PreferenceEditorType
|
public enum PreferenceEditorType
|
||||||
{
|
{
|
||||||
|
APPLICATION("Application"),
|
||||||
CHANNEL_EVENT("Channel Events"),
|
CHANNEL_EVENT("Channel Events"),
|
||||||
DIRECTORY("Directories"),
|
DIRECTORY("Directories"),
|
||||||
JMBE_LIBRARY("JMBE Audio Library"),
|
JMBE_LIBRARY("JMBE Audio Library"),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -165,6 +165,11 @@ public class UserPreferencesEditor extends BorderPane
|
|||||||
{
|
{
|
||||||
TreeItem<String> treeRoot = new TreeItem<>("Root node");
|
TreeItem<String> treeRoot = new TreeItem<>("Root node");
|
||||||
|
|
||||||
|
TreeItem<String> applicationItem = new TreeItem<>("Application");
|
||||||
|
applicationItem.getChildren().add(new TreeItem(PreferenceEditorType.APPLICATION));
|
||||||
|
treeRoot.getChildren().add(applicationItem);
|
||||||
|
applicationItem.setExpanded(true);
|
||||||
|
|
||||||
TreeItem<String> audioItem = new TreeItem<>("Audio");
|
TreeItem<String> audioItem = new TreeItem<>("Audio");
|
||||||
audioItem.getChildren().add(new TreeItem(PreferenceEditorType.AUDIO_DUPLICATE_CALL_DETECTION));
|
audioItem.getChildren().add(new TreeItem(PreferenceEditorType.AUDIO_DUPLICATE_CALL_DETECTION));
|
||||||
audioItem.getChildren().add(new TreeItem(PreferenceEditorType.AUDIO_MP3));
|
audioItem.getChildren().add(new TreeItem(PreferenceEditorType.AUDIO_MP3));
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* 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.preference.application;
|
||||||
|
|
||||||
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
|
import io.github.dsheirer.preference.application.ApplicationPreference;
|
||||||
|
import javafx.geometry.HPos;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.Spinner;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference settings for application
|
||||||
|
*/
|
||||||
|
public class ApplicationPreferenceEditor extends HBox
|
||||||
|
{
|
||||||
|
private ApplicationPreference mApplicationPreference;
|
||||||
|
private GridPane mEditorPane;
|
||||||
|
private Label mAutoStartTimeoutLabel;
|
||||||
|
private Spinner<Integer> mTimeoutSpinner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance
|
||||||
|
* @param userPreferences for obtaining reference to preference.
|
||||||
|
*/
|
||||||
|
public ApplicationPreferenceEditor(UserPreferences userPreferences)
|
||||||
|
{
|
||||||
|
mApplicationPreference = userPreferences.getApplicationPreference();
|
||||||
|
getChildren().add(getEditorPane());
|
||||||
|
}
|
||||||
|
|
||||||
|
private GridPane getEditorPane()
|
||||||
|
{
|
||||||
|
if(mEditorPane == null)
|
||||||
|
{
|
||||||
|
int row = 0;
|
||||||
|
mEditorPane = new GridPane();
|
||||||
|
mEditorPane.setVgap(10);
|
||||||
|
mEditorPane.setHgap(10);
|
||||||
|
mEditorPane.setPadding(new Insets(10, 10, 10, 10));
|
||||||
|
GridPane.setHalignment(getAutoStartTimeoutLabel(), HPos.RIGHT);
|
||||||
|
mEditorPane.add(getAutoStartTimeoutLabel(), 0, row);
|
||||||
|
mEditorPane.add(getTimeoutSpinner(), 1, row);
|
||||||
|
mEditorPane.add(new Label("seconds"), 2, row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mEditorPane;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Label getAutoStartTimeoutLabel()
|
||||||
|
{
|
||||||
|
if(mAutoStartTimeoutLabel == null)
|
||||||
|
{
|
||||||
|
mAutoStartTimeoutLabel = new Label("Channel Auto-Start Timeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mAutoStartTimeoutLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spinner to select channel auto-start timeout value in range 0-30 seconds.
|
||||||
|
* @return spinner
|
||||||
|
*/
|
||||||
|
private Spinner<Integer> getTimeoutSpinner()
|
||||||
|
{
|
||||||
|
if(mTimeoutSpinner == null)
|
||||||
|
{
|
||||||
|
mTimeoutSpinner = new Spinner<>(0, 30, mApplicationPreference.getChannelAutoStartTimeout(), 1);
|
||||||
|
mTimeoutSpinner.valueProperty().addListener((observable, oldValue, newValue) -> mApplicationPreference.setChannelAutoStartTimeout(newValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mTimeoutSpinner;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -24,6 +24,7 @@ package io.github.dsheirer.preference;
|
|||||||
*/
|
*/
|
||||||
public enum PreferenceType
|
public enum PreferenceType
|
||||||
{
|
{
|
||||||
|
APPLICATION,
|
||||||
CALIBRATION,
|
CALIBRATION,
|
||||||
DECODE_EVENT,
|
DECODE_EVENT,
|
||||||
DIRECTORY,
|
DIRECTORY,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
package io.github.dsheirer.preference;
|
package io.github.dsheirer.preference;
|
||||||
|
|
||||||
import io.github.dsheirer.eventbus.MyEventBus;
|
import io.github.dsheirer.eventbus.MyEventBus;
|
||||||
|
import io.github.dsheirer.preference.application.ApplicationPreference;
|
||||||
import io.github.dsheirer.preference.calibration.VectorCalibrationPreference;
|
import io.github.dsheirer.preference.calibration.VectorCalibrationPreference;
|
||||||
import io.github.dsheirer.preference.decoder.JmbeLibraryPreference;
|
import io.github.dsheirer.preference.decoder.JmbeLibraryPreference;
|
||||||
import io.github.dsheirer.preference.directory.DirectoryPreference;
|
import io.github.dsheirer.preference.directory.DirectoryPreference;
|
||||||
@@ -55,7 +56,7 @@ import io.github.dsheirer.sample.Listener;
|
|||||||
*/
|
*/
|
||||||
public class UserPreferences implements Listener<PreferenceType>
|
public class UserPreferences implements Listener<PreferenceType>
|
||||||
{
|
{
|
||||||
private VectorCalibrationPreference mVectorCalibrationPreference;
|
private ApplicationPreference mApplicationPreference;
|
||||||
private ChannelMultiFrequencyPreference mChannelMultiFrequencyPreference;
|
private ChannelMultiFrequencyPreference mChannelMultiFrequencyPreference;
|
||||||
private DecodeEventPreference mDecodeEventPreference;
|
private DecodeEventPreference mDecodeEventPreference;
|
||||||
private DirectoryPreference mDirectoryPreference;
|
private DirectoryPreference mDirectoryPreference;
|
||||||
@@ -68,6 +69,7 @@ public class UserPreferences implements Listener<PreferenceType>
|
|||||||
private RecordPreference mRecordPreference;
|
private RecordPreference mRecordPreference;
|
||||||
private TalkgroupFormatPreference mTalkgroupFormatPreference;
|
private TalkgroupFormatPreference mTalkgroupFormatPreference;
|
||||||
private TunerPreference mTunerPreference;
|
private TunerPreference mTunerPreference;
|
||||||
|
private VectorCalibrationPreference mVectorCalibrationPreference;
|
||||||
|
|
||||||
private SwingPreference mSwingPreference = new SwingPreference();
|
private SwingPreference mSwingPreference = new SwingPreference();
|
||||||
private JavaFxPreferences mJavaFxPreferences = new JavaFxPreferences();
|
private JavaFxPreferences mJavaFxPreferences = new JavaFxPreferences();
|
||||||
@@ -80,6 +82,19 @@ public class UserPreferences implements Listener<PreferenceType>
|
|||||||
loadPreferenceTypes();
|
loadPreferenceTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application general/miscellaneous preferences.
|
||||||
|
* @return application preferences.
|
||||||
|
*/
|
||||||
|
public ApplicationPreference getApplicationPreference()
|
||||||
|
{
|
||||||
|
return mApplicationPreference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vector/SIMD calibration preferences.
|
||||||
|
* @return vector calibration preferences.
|
||||||
|
*/
|
||||||
public VectorCalibrationPreference getVectorCalibrationPreference()
|
public VectorCalibrationPreference getVectorCalibrationPreference()
|
||||||
{
|
{
|
||||||
return mVectorCalibrationPreference;
|
return mVectorCalibrationPreference;
|
||||||
@@ -203,7 +218,7 @@ public class UserPreferences implements Listener<PreferenceType>
|
|||||||
*/
|
*/
|
||||||
private void loadPreferenceTypes()
|
private void loadPreferenceTypes()
|
||||||
{
|
{
|
||||||
mVectorCalibrationPreference = new VectorCalibrationPreference(this::receive);
|
mApplicationPreference = new ApplicationPreference(this::receive);
|
||||||
mChannelMultiFrequencyPreference = new ChannelMultiFrequencyPreference(this::receive);
|
mChannelMultiFrequencyPreference = new ChannelMultiFrequencyPreference(this::receive);
|
||||||
mDecodeEventPreference = new DecodeEventPreference(this::receive);
|
mDecodeEventPreference = new DecodeEventPreference(this::receive);
|
||||||
mDirectoryPreference = new DirectoryPreference(this::receive);
|
mDirectoryPreference = new DirectoryPreference(this::receive);
|
||||||
@@ -216,6 +231,7 @@ public class UserPreferences implements Listener<PreferenceType>
|
|||||||
mRecordPreference = new RecordPreference(this::receive);
|
mRecordPreference = new RecordPreference(this::receive);
|
||||||
mTalkgroupFormatPreference = new TalkgroupFormatPreference(this::receive);
|
mTalkgroupFormatPreference = new TalkgroupFormatPreference(this::receive);
|
||||||
mTunerPreference = new TunerPreference(this::receive);
|
mTunerPreference = new TunerPreference(this::receive);
|
||||||
|
mVectorCalibrationPreference = new VectorCalibrationPreference(this::receive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* 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.preference.application;
|
||||||
|
|
||||||
|
import io.github.dsheirer.preference.Preference;
|
||||||
|
import io.github.dsheirer.preference.PreferenceType;
|
||||||
|
import io.github.dsheirer.sample.Listener;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General/Miscellaneous preferences
|
||||||
|
*/
|
||||||
|
public class ApplicationPreference extends Preference
|
||||||
|
{
|
||||||
|
private static final String PREFERENCE_KEY_CHANNEL_AUTO_START_TIMEOUT = "channel.auto.start.timeout";
|
||||||
|
|
||||||
|
private final static Logger mLog = LoggerFactory.getLogger(ApplicationPreference.class);
|
||||||
|
private Preferences mPreferences = Preferences.userNodeForPackage(ApplicationPreference.class);
|
||||||
|
private Integer mChannelAutoStartTimeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance
|
||||||
|
* @param updateListener to receive notifications that a preference has been updated
|
||||||
|
*/
|
||||||
|
public ApplicationPreference(Listener<PreferenceType> updateListener)
|
||||||
|
{
|
||||||
|
super(updateListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferenceType getPreferenceType()
|
||||||
|
{
|
||||||
|
return PreferenceType.APPLICATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channel auto-start timeout. This is the countdown in seconds to allow the user to cancel the channel auto-start.
|
||||||
|
* @return timeout in seconds.
|
||||||
|
*/
|
||||||
|
public int getChannelAutoStartTimeout()
|
||||||
|
{
|
||||||
|
if(mChannelAutoStartTimeout == null)
|
||||||
|
{
|
||||||
|
mChannelAutoStartTimeout = mPreferences.getInt(PREFERENCE_KEY_CHANNEL_AUTO_START_TIMEOUT, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mChannelAutoStartTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the channel auto-start timeout seconds value.
|
||||||
|
* @param timeout in seconds.
|
||||||
|
*/
|
||||||
|
public void setChannelAutoStartTimeout(int timeout)
|
||||||
|
{
|
||||||
|
mChannelAutoStartTimeout = timeout;
|
||||||
|
mPreferences.putInt(PREFERENCE_KEY_CHANNEL_AUTO_START_TIMEOUT, timeout);
|
||||||
|
notifyPreferenceUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user