Skip to content

Commit

Permalink
Add running indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Apr 26, 2023
1 parent 5b1f43b commit 47f026b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/qz/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public class Constants {
public static final Color TRUSTED_COLOR_LITE = Color.BLUE;
public static final Color WARNING_COLOR_DARK = Color.decode("#EB6261");
public static final Color TRUSTED_COLOR_DARK = Color.decode("#589DF6");
public static final Color RUNNING_COLOR = Color.decode("#00AD47");
public static final Color PENDING_COLOR = Color.decode("#B2B247");
public static final Color STOPPED_COLOR = Color.decode("#AE4745");

public static Color WARNING_COLOR = WARNING_COLOR_LITE;
public static Color TRUSTED_COLOR = TRUSTED_COLOR_LITE;

Expand Down
1 change: 1 addition & 0 deletions src/qz/common/TrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ private void setIcon(final IconCache.Icon i) {
public void refreshIcon(final Runnable whenDone) {
SwingUtilities.invokeLater(() -> {
tray.setIcon(shownIcon);
controlDialog.setRunningIndicator(shownIcon);
if(whenDone != null) {
whenDone.run();
}
Expand Down
60 changes: 56 additions & 4 deletions src/qz/ui/ControlDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package qz.ui;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import qz.common.Constants;
import qz.ui.component.IconCache;

Expand All @@ -14,6 +16,8 @@
* A container for all the System Tray menu items
*/
public class ControlDialog extends BasicDialog implements Themeable {
private static final Logger log = LogManager.getLogger(ControlDialog.class);

public enum Category {
STATUS,
GENERAL,
Expand All @@ -24,10 +28,15 @@ public enum Category {
private boolean persistent = false;

private JPanel statusPanel;
private JPanel statusLeftPanel;
private JPanel statusRightPanel;
private JPanel generalPanel;
private JPanel advancedPanel;
private JPanel diagnosticPanel;

private JLabel runningIndicator;
private JLabel runningLabel;

public ControlDialog(IconCache iconCache) {
super(Constants.ABOUT_TITLE, iconCache);
initComponents();
Expand Down Expand Up @@ -60,18 +69,22 @@ public void add(Component component, String text, Category category) {
toAdd = button;
} else if(component instanceof JSeparator){
toAdd = (JSeparator)component;
} else if (component instanceof JComponent){
toAdd = (JComponent)component;
} else {
log.warn("Cannot add {}, not yet supported.", component.getClass().getSimpleName());
}
if(toAdd != null) {
switch(category) {
case STATUS:
statusRightPanel.add(toAdd);
break;
case ADVANCED:
advancedPanel.add(toAdd);
break;
case DIAGNOSTIC:
diagnosticPanel.add(toAdd);
break;
case STATUS:
statusPanel.add(toAdd);
break;
case GENERAL:
default:
generalPanel.add(toAdd);
Expand All @@ -86,7 +99,29 @@ private void initComponents() {
mainPanel.setLayout(new BorderLayout());
mainPanel.setBorder(createPaddedLineBorder(5, SwingConstants.SOUTH));

statusPanel = new JPanel(new FlowLayout());
statusLeftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
statusRightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

statusPanel = new JPanel(new GridLayout(1, 3));

// Running indicator
runningIndicator = new JLabel("•");
runningIndicator.setFont(new Font("", Font.BOLD, 24));
runningIndicator.setForeground(Constants.STOPPED_COLOR);
runningIndicator.setBorder(new EmptyBorder(0, 2, 2, 2));
runningLabel = new JLabel("Stopped");
runningLabel.setBorder(new EmptyBorder(0, 0, 0, 4));
statusLeftPanel.add(runningIndicator);
statusLeftPanel.add(runningLabel);
statusPanel.add(statusLeftPanel);

// Version label
JLabel versionLabel = new JLabel(Constants.ABOUT_TITLE + " " + Constants.VERSION);
versionLabel.setFont(runningLabel.getFont());
statusPanel.add(versionLabel);

// Additional controls added with .add()
statusPanel.add(statusRightPanel);

Font headingFont = new JLabel().getFont().deriveFont(16f).deriveFont(Font.BOLD);

Expand Down Expand Up @@ -170,6 +205,23 @@ public void refresh() {
ThemeUtilities.refreshAll(this);
}

public void setRunningIndicator(IconCache.Icon icon) {
switch(icon) {
case WARNING_ICON:
runningIndicator.setForeground(Constants.PENDING_COLOR);
runningLabel.setText("Pending");
break;
case DANGER_ICON:
runningIndicator.setForeground(Constants.STOPPED_COLOR);
runningLabel.setText("Stopped");
break;
case DEFAULT_ICON:
default:
runningIndicator.setForeground(Constants.RUNNING_COLOR);
runningLabel.setText("Running");
}
}

/**
* Sets persistent mode, window can't be closed unless shutdown
*/
Expand Down

0 comments on commit 47f026b

Please sign in to comment.