Skip to content

Commit

Permalink
Merge pull request #1732 from DSheirer/1731-application-status-bar
Browse files Browse the repository at this point in the history
#1731 Application Status Bar (cpu/memory/disk space).
  • Loading branch information
DSheirer authored Nov 12, 2023
2 parents e79f2af + dba5074 commit 2b9e753
Show file tree
Hide file tree
Showing 7 changed files with 561 additions and 25 deletions.
24 changes: 24 additions & 0 deletions src/main/java/io/github/dsheirer/gui/JavaFxWindowManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import io.github.dsheirer.jmbe.JmbeEditor;
import io.github.dsheirer.jmbe.JmbeEditorRequest;
import io.github.dsheirer.module.log.EventLogManager;
import io.github.dsheirer.monitor.ResourceMonitor;
import io.github.dsheirer.monitor.StatusBox;
import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.source.tuner.manager.TunerManager;
Expand Down Expand Up @@ -90,6 +92,7 @@ public class JavaFxWindowManager extends Application
private Stage mPlaylistStage;
private Stage mUserPreferencesStage;
private Stage mRecordingViewerStage;
private JFXPanel mStatusPanel;

/**
* Constructs an instance. Note: this constructor is used for Swing applications.
Expand Down Expand Up @@ -118,6 +121,27 @@ public JavaFxWindowManager()
setup();
}

/**
* Creates or accesses the JavaFX status panel, used by the main application GUI.
* @param resourceMonitor for statistics
* @return JFXPanel accessible on Swing thread that delegates JavaFX scene creation to the FX event thread.
*/
public JFXPanel getStatusPanel(ResourceMonitor resourceMonitor)
{
if(mStatusPanel == null)
{
mStatusPanel = new JFXPanel();

//JFXPanel has to be populated on the FX event thread
Platform.runLater(() -> {
Scene scene = new Scene(new StatusBox(resourceMonitor));
mStatusPanel.setScene(scene);
});
}

return mStatusPanel;
}

private void setup()
{
//Register this class to receive events via each method annotated with @Subscribe
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/io/github/dsheirer/gui/SDRTrunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.github.dsheirer.log.ApplicationLog;
import io.github.dsheirer.map.MapService;
import io.github.dsheirer.module.log.EventLogManager;
import io.github.dsheirer.monitor.ResourceMonitor;
import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.properties.SystemProperties;
Expand All @@ -68,7 +69,6 @@
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand All @@ -82,6 +82,7 @@
import java.util.Locale;
import java.util.Optional;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.control.ButtonType;
import jiconfont.icons.font_awesome.FontAwesome;
import jiconfont.swing.IconFontSwing;
Expand Down Expand Up @@ -128,6 +129,8 @@ public class SDRTrunk implements Listener<TunerEvent>
private UserPreferences mUserPreferences = new UserPreferences();
private TunerManager mTunerManager;
private ApplicationLog mApplicationLog;
private ResourceMonitor mResourceMonitor;
private JFXPanel mStatusPanel;

private String mTitle;

Expand All @@ -141,6 +144,8 @@ public SDRTrunk()
mApplicationLog = new ApplicationLog(mUserPreferences);
mApplicationLog.start();

mResourceMonitor = new ResourceMonitor(mUserPreferences);

String operatingSystem = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);

if(operatingSystem.contains("mac") || operatingSystem.contains("nux"))
Expand Down Expand Up @@ -316,7 +321,7 @@ private void autoStartChannels()
*/
private void initGUI()
{
mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]"));
mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill][]"));

/**
* Setup main JFrame window
Expand Down Expand Up @@ -382,6 +387,10 @@ private void initGUI()

mMainGui.add(mSplitPane, "cell 0 0,span,grow");

mResourceMonitor.start();
mStatusPanel = mJavaFxWindowManager.getStatusPanel(mResourceMonitor);
mMainGui.add(mStatusPanel, "span,growx");

/**
* Menu items
*/
Expand All @@ -392,14 +401,9 @@ private void initGUI()
menuBar.add(fileMenu);

JMenuItem exitMenu = new JMenuItem("Exit");
exitMenu.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
processShutdown();
System.exit(0);
}
exitMenu.addActionListener(event -> {
processShutdown();
System.exit(0);
}
);

Expand Down Expand Up @@ -571,6 +575,7 @@ private void processShutdown()
mLog.info("Stopping channels ...");
mPlaylistManager.getChannelProcessingManager().shutdown();
mAudioRecordingManager.stop();
mResourceMonitor.stop();

mLog.info("Stopping spectral display ...");
mSpectralPanel.clearTuner();
Expand Down Expand Up @@ -742,14 +747,9 @@ public BroadcastStatusVisibleMenuItem(ControllerPanel controllerPanel)

setSelected(mBroadcastStatusPanel != null);

addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
toggleBroadcastStatusPanelVisibility();
setSelected(mBroadcastStatusVisible);
}
addActionListener(e -> {
toggleBroadcastStatusPanelVisibility();
setSelected(mBroadcastStatusVisible);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -24,13 +24,15 @@
import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.directory.DirectoryPreference;
import java.io.File;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.Spinner;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
Expand All @@ -39,8 +41,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;


/**
* Preference settings for channel event view
Expand Down Expand Up @@ -97,6 +97,9 @@ public class DirectoryPreferenceEditor extends HBox
private Button mResetStreamingButton;
private Label mStreamingPathLabel;

private Spinner<Integer> mRecordingSpinner;
private Spinner<Integer> mEventLogSpinner;

public DirectoryPreferenceEditor(UserPreferences userPreferences)
{
mDirectoryPreference = userPreferences.getDirectoryPreference();
Expand Down Expand Up @@ -247,11 +250,57 @@ private GridPane getEditorPane()

GridPane.setMargin(getResetStreamingButton(), new Insets(2, 0, 2, 0));
mEditorPane.add(getResetStreamingButton(), 3, row++);

Label monitorLabel = new Label("File storage usage monitoring - maximum size thresholds (MB)");
GridPane.setMargin(monitorLabel, new Insets(15, 0, 2, 0));
mEditorPane.add(monitorLabel, 0, row++, 4, 1);
mEditorPane.add(new Separator(Orientation.HORIZONTAL), 0, row++, 4, 1);

mEditorPane.add(new Label("Event Logs"), 0, row);
GridPane.setMargin(getEventLogSpinner(), new Insets(2, 2, 2, 0));
mEditorPane.add(getEventLogSpinner(), 1, row++);

mEditorPane.add(new Label("Recordings"), 0, row);
GridPane.setMargin(getRecordingSpinner(), new Insets(2, 2, 2, 0));
mEditorPane.add(getRecordingSpinner(), 1, row);
}

return mEditorPane;
}

/**
* Recording directory maximum size threshold spinner
* @return spinner
*/
private Spinner<Integer> getRecordingSpinner()
{
if(mRecordingSpinner == null)
{
mRecordingSpinner = new Spinner<>(100, Integer.MAX_VALUE, mDirectoryPreference.getDirectoryMaxUsageRecordings(), 100);
mRecordingSpinner.valueProperty().addListener((observable, oldValue, newValue) -> mDirectoryPreference
.setDirectoryMaxUsageRecordings(newValue));
}

return mRecordingSpinner;
}

/**
* Event log directory maximum size threshold spinner
* @return spinner
*/
private Spinner<Integer> getEventLogSpinner()
{
if(mEventLogSpinner == null)
{
mEventLogSpinner = new Spinner<>(100, Integer.MAX_VALUE, mDirectoryPreference.getDirectoryMaxUsageEventLogs(), 100);
mEventLogSpinner.setEditable(true);
mEventLogSpinner.valueProperty().addListener((observable, oldValue, newValue) -> mDirectoryPreference
.setDirectoryMaxUsageEventLogs(newValue));
}

return mEventLogSpinner;
}

private Label getApplicationRootLabel()
{
if(mApplicationRootLabel == null)
Expand Down
Loading

0 comments on commit 2b9e753

Please sign in to comment.