Skip to content

Commit 2782953

Browse files
DSheirerDennis Sheirer
andauthored
#1500 Makes Channel Auto-Start timeout a user-preference item to select in range 0-30 seconds. (#1501)
Co-authored-by: Dennis Sheirer <[email protected]>
1 parent 3660551 commit 2782953

File tree

9 files changed

+228
-27
lines changed

9 files changed

+228
-27
lines changed

src/main/java/io/github/dsheirer/controller/channel/ChannelAutoStartFrame.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* ******************************************************************************
3-
* sdrtrunk
4-
* Copyright (C) 2014-2018 Dennis Sheirer
2+
* *****************************************************************************
3+
* Copyright (C) 2014-2023 Dennis Sheirer
54
*
65
* This program is free software: you can redistribute it and/or modify
76
* it under the terms of the GNU General Public License as published by
@@ -15,22 +14,13 @@
1514
*
1615
* You should have received a copy of the GNU General Public License
1716
* along with this program. If not, see <http://www.gnu.org/licenses/>
18-
* *****************************************************************************
17+
* ****************************************************************************
1918
*/
2019
package io.github.dsheirer.controller.channel;
2120

21+
import io.github.dsheirer.preference.UserPreferences;
2222
import io.github.dsheirer.sample.Listener;
2323
import io.github.dsheirer.util.ThreadPool;
24-
import net.miginfocom.swing.MigLayout;
25-
import org.slf4j.Logger;
26-
import org.slf4j.LoggerFactory;
27-
28-
import javax.swing.JButton;
29-
import javax.swing.JFrame;
30-
import javax.swing.JLabel;
31-
import javax.swing.JPanel;
32-
import javax.swing.JScrollPane;
33-
import javax.swing.JTable;
3424
import java.awt.Dimension;
3525
import java.awt.EventQueue;
3626
import java.awt.event.ActionEvent;
@@ -41,12 +31,21 @@
4131
import java.util.concurrent.ScheduledFuture;
4232
import java.util.concurrent.TimeUnit;
4333
import java.util.concurrent.atomic.AtomicBoolean;
34+
import net.miginfocom.swing.MigLayout;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
37+
38+
import javax.swing.JButton;
39+
import javax.swing.JFrame;
40+
import javax.swing.JLabel;
41+
import javax.swing.JPanel;
42+
import javax.swing.JScrollPane;
43+
import javax.swing.JTable;
4444

4545
public class ChannelAutoStartFrame extends JFrame
4646
{
4747
private final static Logger mLog = LoggerFactory.getLogger(ChannelAutoStartFrame.class);
4848

49-
private static final int COUNTDOWN_SECONDS = 10;
5049
private Listener<ChannelEvent> mChannelEventListener;
5150
private List<Channel> mChannels;
5251

@@ -55,7 +54,7 @@ public class ChannelAutoStartFrame extends JFrame
5554
private JButton mCancelButton;
5655
private JTable mChannelTable;
5756
private AtomicBoolean mChannelsStarted = new AtomicBoolean();
58-
57+
private int mAutoStartTimeoutSeconds;
5958
private ScheduledFuture<?> mTimerFuture;
6059

6160
/**
@@ -66,10 +65,12 @@ public class ChannelAutoStartFrame extends JFrame
6665
* @param listener to receive channel start/enable request(s)
6766
* @param channels to auto-start
6867
*/
69-
public ChannelAutoStartFrame(Listener<ChannelEvent> listener, List<Channel> channels)
68+
public ChannelAutoStartFrame(Listener<ChannelEvent> listener, List<Channel> channels, UserPreferences userPreferences)
7069
{
7170
mChannelEventListener = listener;
7271
mChannels = channels;
72+
mAutoStartTimeoutSeconds = userPreferences.getApplicationPreference().getChannelAutoStartTimeout();
73+
7374
init();
7475

7576
EventQueue.invokeLater(() -> {
@@ -100,7 +101,7 @@ public void windowClosing(WindowEvent event)
100101
"[][][grow,fill][]"));
101102
panel.add(new JLabel("The following channels will be automatically"), "span");
102103

103-
mCountdownLabel = new JLabel(getCountdownText(COUNTDOWN_SECONDS));
104+
mCountdownLabel = new JLabel(getCountdownText(mAutoStartTimeoutSeconds));
104105
panel.add(mCountdownLabel, "span");
105106

106107
panel.add(new JScrollPane(getChannelTable()), "span");
@@ -220,7 +221,7 @@ private void stopTimer()
220221
*/
221222
public class CountdownTimer implements Runnable
222223
{
223-
private int mCount = COUNTDOWN_SECONDS;
224+
private int mCount = mAutoStartTimeoutSeconds;
224225

225226
@Override
226227
public void run()

src/main/java/io/github/dsheirer/gui/SDRTrunk.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private void autoStartChannels()
313313
}
314314
else
315315
{
316-
new ChannelAutoStartFrame(mPlaylistManager.getChannelProcessingManager(), channels);
316+
new ChannelAutoStartFrame(mPlaylistManager.getChannelProcessingManager(), channels, mUserPreferences);
317317
}
318318
}
319319
}

src/main/java/io/github/dsheirer/gui/preference/PreferenceEditorFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2022 Dennis Sheirer
3+
* Copyright (C) 2014-2023 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
1919

2020
package io.github.dsheirer.gui.preference;
2121

22+
import io.github.dsheirer.gui.preference.application.ApplicationPreferenceEditor;
2223
import io.github.dsheirer.gui.preference.calibration.VectorCalibrationPreferenceEditor;
2324
import io.github.dsheirer.gui.preference.decoder.JmbeLibraryPreferenceEditor;
2425
import io.github.dsheirer.gui.preference.directory.DirectoryPreferenceEditor;
@@ -39,6 +40,8 @@ public static Node getEditor(PreferenceEditorType preferenceEditorType, UserPref
3940
{
4041
switch(preferenceEditorType)
4142
{
43+
case APPLICATION:
44+
return new ApplicationPreferenceEditor(userPreferences);
4245
case AUDIO_DUPLICATE_CALL_DETECTION:
4346
return new DuplicateCallPreferenceEditor(userPreferences);
4447
case AUDIO_MP3:

src/main/java/io/github/dsheirer/gui/preference/PreferenceEditorType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2022 Dennis Sheirer
3+
* Copyright (C) 2014-2023 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
2424
*/
2525
public enum PreferenceEditorType
2626
{
27+
APPLICATION("Application"),
2728
CHANNEL_EVENT("Channel Events"),
2829
DIRECTORY("Directories"),
2930
JMBE_LIBRARY("JMBE Audio Library"),

src/main/java/io/github/dsheirer/gui/preference/UserPreferencesEditor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2022 Dennis Sheirer
3+
* Copyright (C) 2014-2023 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -165,6 +165,11 @@ private TreeView getEditorSelectionTreeView()
165165
{
166166
TreeItem<String> treeRoot = new TreeItem<>("Root node");
167167

168+
TreeItem<String> applicationItem = new TreeItem<>("Application");
169+
applicationItem.getChildren().add(new TreeItem(PreferenceEditorType.APPLICATION));
170+
treeRoot.getChildren().add(applicationItem);
171+
applicationItem.setExpanded(true);
172+
168173
TreeItem<String> audioItem = new TreeItem<>("Audio");
169174
audioItem.getChildren().add(new TreeItem(PreferenceEditorType.AUDIO_DUPLICATE_CALL_DETECTION));
170175
audioItem.getChildren().add(new TreeItem(PreferenceEditorType.AUDIO_MP3));
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* *****************************************************************************
3+
* Copyright (C) 2014-2023 Dennis Sheirer
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
* ****************************************************************************
18+
*/
19+
20+
package io.github.dsheirer.gui.preference.application;
21+
22+
import io.github.dsheirer.preference.UserPreferences;
23+
import io.github.dsheirer.preference.application.ApplicationPreference;
24+
import javafx.geometry.HPos;
25+
import javafx.geometry.Insets;
26+
import javafx.scene.control.Label;
27+
import javafx.scene.control.Spinner;
28+
import javafx.scene.layout.GridPane;
29+
import javafx.scene.layout.HBox;
30+
31+
32+
/**
33+
* Preference settings for application
34+
*/
35+
public class ApplicationPreferenceEditor extends HBox
36+
{
37+
private ApplicationPreference mApplicationPreference;
38+
private GridPane mEditorPane;
39+
private Label mAutoStartTimeoutLabel;
40+
private Spinner<Integer> mTimeoutSpinner;
41+
42+
/**
43+
* Constructs an instance
44+
* @param userPreferences for obtaining reference to preference.
45+
*/
46+
public ApplicationPreferenceEditor(UserPreferences userPreferences)
47+
{
48+
mApplicationPreference = userPreferences.getApplicationPreference();
49+
getChildren().add(getEditorPane());
50+
}
51+
52+
private GridPane getEditorPane()
53+
{
54+
if(mEditorPane == null)
55+
{
56+
int row = 0;
57+
mEditorPane = new GridPane();
58+
mEditorPane.setVgap(10);
59+
mEditorPane.setHgap(10);
60+
mEditorPane.setPadding(new Insets(10, 10, 10, 10));
61+
GridPane.setHalignment(getAutoStartTimeoutLabel(), HPos.RIGHT);
62+
mEditorPane.add(getAutoStartTimeoutLabel(), 0, row);
63+
mEditorPane.add(getTimeoutSpinner(), 1, row);
64+
mEditorPane.add(new Label("seconds"), 2, row);
65+
}
66+
67+
return mEditorPane;
68+
}
69+
70+
private Label getAutoStartTimeoutLabel()
71+
{
72+
if(mAutoStartTimeoutLabel == null)
73+
{
74+
mAutoStartTimeoutLabel = new Label("Channel Auto-Start Timeout");
75+
}
76+
77+
return mAutoStartTimeoutLabel;
78+
}
79+
80+
/**
81+
* Spinner to select channel auto-start timeout value in range 0-30 seconds.
82+
* @return spinner
83+
*/
84+
private Spinner<Integer> getTimeoutSpinner()
85+
{
86+
if(mTimeoutSpinner == null)
87+
{
88+
mTimeoutSpinner = new Spinner<>(0, 30, mApplicationPreference.getChannelAutoStartTimeout(), 1);
89+
mTimeoutSpinner.valueProperty().addListener((observable, oldValue, newValue) -> mApplicationPreference.setChannelAutoStartTimeout(newValue));
90+
}
91+
92+
return mTimeoutSpinner;
93+
}
94+
}

src/main/java/io/github/dsheirer/preference/PreferenceType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2022 Dennis Sheirer
3+
* Copyright (C) 2014-2023 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
2424
*/
2525
public enum PreferenceType
2626
{
27+
APPLICATION,
2728
CALIBRATION,
2829
DECODE_EVENT,
2930
DIRECTORY,

src/main/java/io/github/dsheirer/preference/UserPreferences.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2022 Dennis Sheirer
3+
* Copyright (C) 2014-2023 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
2020
package io.github.dsheirer.preference;
2121

2222
import io.github.dsheirer.eventbus.MyEventBus;
23+
import io.github.dsheirer.preference.application.ApplicationPreference;
2324
import io.github.dsheirer.preference.calibration.VectorCalibrationPreference;
2425
import io.github.dsheirer.preference.decoder.JmbeLibraryPreference;
2526
import io.github.dsheirer.preference.directory.DirectoryPreference;
@@ -55,7 +56,7 @@
5556
*/
5657
public class UserPreferences implements Listener<PreferenceType>
5758
{
58-
private VectorCalibrationPreference mVectorCalibrationPreference;
59+
private ApplicationPreference mApplicationPreference;
5960
private ChannelMultiFrequencyPreference mChannelMultiFrequencyPreference;
6061
private DecodeEventPreference mDecodeEventPreference;
6162
private DirectoryPreference mDirectoryPreference;
@@ -68,6 +69,7 @@ public class UserPreferences implements Listener<PreferenceType>
6869
private RecordPreference mRecordPreference;
6970
private TalkgroupFormatPreference mTalkgroupFormatPreference;
7071
private TunerPreference mTunerPreference;
72+
private VectorCalibrationPreference mVectorCalibrationPreference;
7173

7274
private SwingPreference mSwingPreference = new SwingPreference();
7375
private JavaFxPreferences mJavaFxPreferences = new JavaFxPreferences();
@@ -80,6 +82,19 @@ public UserPreferences()
8082
loadPreferenceTypes();
8183
}
8284

85+
/**
86+
* Application general/miscellaneous preferences.
87+
* @return application preferences.
88+
*/
89+
public ApplicationPreference getApplicationPreference()
90+
{
91+
return mApplicationPreference;
92+
}
93+
94+
/**
95+
* Vector/SIMD calibration preferences.
96+
* @return vector calibration preferences.
97+
*/
8398
public VectorCalibrationPreference getVectorCalibrationPreference()
8499
{
85100
return mVectorCalibrationPreference;
@@ -203,7 +218,7 @@ public DuplicateCallDetectionPreference getDuplicateCallDetectionPreference()
203218
*/
204219
private void loadPreferenceTypes()
205220
{
206-
mVectorCalibrationPreference = new VectorCalibrationPreference(this::receive);
221+
mApplicationPreference = new ApplicationPreference(this::receive);
207222
mChannelMultiFrequencyPreference = new ChannelMultiFrequencyPreference(this::receive);
208223
mDecodeEventPreference = new DecodeEventPreference(this::receive);
209224
mDirectoryPreference = new DirectoryPreference(this::receive);
@@ -216,6 +231,7 @@ private void loadPreferenceTypes()
216231
mRecordPreference = new RecordPreference(this::receive);
217232
mTalkgroupFormatPreference = new TalkgroupFormatPreference(this::receive);
218233
mTunerPreference = new TunerPreference(this::receive);
234+
mVectorCalibrationPreference = new VectorCalibrationPreference(this::receive);
219235
}
220236

221237
/**

0 commit comments

Comments
 (0)