Skip to content

Commit

Permalink
added minimize to tray option
Browse files Browse the repository at this point in the history
  • Loading branch information
s1mpl3x committed Sep 13, 2014
1 parent ece5ba0 commit 3e82982
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/eu/over9000/skadi/SkadiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class SkadiMain {

public boolean use_livestreamer = true;
public boolean display_notifications = true;
public boolean minimize_to_tray = false;

public static SkadiMain getInstance() {
if (SkadiMain.instance == null) {
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/eu/over9000/skadi/gui/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class SettingsDialog extends JDialog {
private JLabel lbChatLogValue;
private JButton btnOpenSkadiDir;
private JCheckBox chckbxDisplayNotifications;
private JCheckBox chckbxMinimizeToTray;

public SettingsDialog(final SkadiGUI gui) {
this.gui = gui;
Expand Down Expand Up @@ -137,6 +138,8 @@ public void actionPerformed(final ActionEvent e) {
.isSelected();
SkadiMain.getInstance().display_notifications = SettingsDialog.this.getChckbxDisplayNotifications()
.isSelected();
SkadiMain.getInstance().minimize_to_tray = SettingsDialog.this.getChckbxMinimizeToTray()
.isSelected();

SkadiLogging.log("settings updated");
SettingsDialog.this.setVisible(false);
Expand Down Expand Up @@ -218,9 +221,9 @@ private JPanel getPnOtherSettings() {
null)));
final GridBagLayout gbl_pnOtherSettings = new GridBagLayout();
gbl_pnOtherSettings.columnWidths = new int[] { 0, 0 };
gbl_pnOtherSettings.rowHeights = new int[] { 0, 0, 0 };
gbl_pnOtherSettings.rowHeights = new int[] { 0, 0, 0, 0 };
gbl_pnOtherSettings.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
gbl_pnOtherSettings.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
gbl_pnOtherSettings.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
this.pnOtherSettings.setLayout(gbl_pnOtherSettings);
final GridBagConstraints gbc_chckbxUseLivestreamerFor = new GridBagConstraints();
gbc_chckbxUseLivestreamerFor.anchor = GridBagConstraints.WEST;
Expand All @@ -229,10 +232,16 @@ private JPanel getPnOtherSettings() {
gbc_chckbxUseLivestreamerFor.gridy = 0;
this.pnOtherSettings.add(this.getChckbxUseLivestreamerFor(), gbc_chckbxUseLivestreamerFor);
final GridBagConstraints gbc_chckbxDisplayNotifications = new GridBagConstraints();
gbc_chckbxDisplayNotifications.insets = new Insets(0, 0, 5, 0);
gbc_chckbxDisplayNotifications.anchor = GridBagConstraints.WEST;
gbc_chckbxDisplayNotifications.gridx = 0;
gbc_chckbxDisplayNotifications.gridy = 1;
this.pnOtherSettings.add(this.getChckbxDisplayNotifications(), gbc_chckbxDisplayNotifications);
final GridBagConstraints gbc_chckbxMinimizeToTray = new GridBagConstraints();
gbc_chckbxMinimizeToTray.anchor = GridBagConstraints.WEST;
gbc_chckbxMinimizeToTray.gridx = 0;
gbc_chckbxMinimizeToTray.gridy = 2;
this.pnOtherSettings.add(this.getChckbxMinimizeToTray(), gbc_chckbxMinimizeToTray);
}
return this.pnOtherSettings;
}
Expand Down Expand Up @@ -297,6 +306,13 @@ private JCheckBox getChckbxDisplayNotifications() {
return this.chckbxDisplayNotifications;
}

private JCheckBox getChckbxMinimizeToTray() {
if (this.chckbxMinimizeToTray == null) {
this.chckbxMinimizeToTray = new JCheckBox("Minimize to tray", SkadiMain.getInstance().minimize_to_tray);
}
return this.chckbxMinimizeToTray;
}

private JPanel getPnLogs() {
if (this.pnLogs == null) {
this.pnLogs = new JPanel();
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/eu/over9000/skadi/gui/SkadiGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
Expand All @@ -49,6 +52,7 @@
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

import eu.over9000.skadi.SkadiMain;
import eu.over9000.skadi.channel.Channel;
import eu.over9000.skadi.channel.ChannelEventListener;
import eu.over9000.skadi.channel.ChannelManager;
Expand Down Expand Up @@ -102,6 +106,21 @@ private SkadiGUI() {

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.addWindowStateListener(new WindowStateListener() {

@Override
public void windowStateChanged(final WindowEvent e) {
if (!SkadiMain.getInstance().minimize_to_tray) {
return;
}

if (e.getNewState() == Frame.ICONIFIED) {

SkadiGUI.this.setVisible(false);
}
}
});

this.tableModel = new ChannelDataTableModel();
this.setMinimumSize(new Dimension(700, 480));
this.initialize();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/eu/over9000/skadi/io/PersistenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public void saveData() {
display_notifications.setTextContent(Boolean.toString(SkadiMain.getInstance().display_notifications));
dataRoot.appendChild(display_notifications);

final Element minimize_to_tray = document.createElement(XMLTags.MINIMIZE_TO_TRAY);
minimize_to_tray.setTextContent(Boolean.toString(SkadiMain.getInstance().minimize_to_tray));
dataRoot.appendChild(minimize_to_tray);

dataRoot.appendChild(channelsRoot);
for (final Channel channel : ChannelManager.getInstance().getChannels()) {
final Element channelRoot = document.createElement(XMLTags.CHANNEL);
Expand Down Expand Up @@ -198,6 +202,7 @@ public void loadData() {
SkadiMain.getInstance().use_livestreamer = this.loadUseLivestreamer(document.getDocumentElement());
SkadiMain.getInstance().display_notifications = this
.loadDisplayNotifications(document.getDocumentElement());
SkadiMain.getInstance().minimize_to_tray = this.loadMinimizeToTray(document.getDocumentElement());

final Element channels = (Element) document.getDocumentElement().getElementsByTagName(XMLTags.CHANNELS)
.item(0);
Expand Down Expand Up @@ -256,6 +261,15 @@ private boolean loadDisplayNotifications(final Element doc) {
}
}

private boolean loadMinimizeToTray(final Element doc) {
try {
return Boolean.valueOf(doc.getElementsByTagName(XMLTags.MINIMIZE_TO_TRAY).item(0).getTextContent());
} catch (final Exception e) {
SkadiLogging.log("could not find minimize_to_tray var in data file, will use default value");
return SkadiMain.getInstance().use_livestreamer;
}
}

public static void checkAndCreateDir() {
final File dir = new File(PersistenceManager.PERSISTENCE_DIRECTORY);
dir.mkdirs();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/eu/over9000/skadi/io/XMLTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class XMLTags {

public static final String USE_LIVESTREAMER = "USE_LIVESTREAMER";
public static final String DISPLAY_NOTIFICATIONS = "DISPLAY_NOTIFICATIONS";
public static final String MINIMIZE_TO_TRAY = "MINIMIZE_TO_TRAY";

public static final String CHROME_EXECUTABLE = "CHROME";
public static final String LIVESTREAMER_EXECUTABLE = "LIVESTREAMER";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.over9000.skadi.notification;

import java.awt.AWTException;
import java.awt.Frame;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
Expand All @@ -15,6 +16,7 @@
import eu.over9000.skadi.channel.Channel;
import eu.over9000.skadi.channel.ChannelEventListener;
import eu.over9000.skadi.channel.ChannelManager;
import eu.over9000.skadi.gui.SkadiGUI;
import eu.over9000.skadi.util.StringUtil;

public class NotificationManager implements ChannelEventListener {
Expand All @@ -39,7 +41,9 @@ public NotificationManager() {
@Override
public void mouseClicked(final MouseEvent e) {
if ((e.getClickCount() == 1) || (e.getClickCount() == 2)) {
System.out.println("clicked on icon");
SkadiGUI.getInstance().setVisible(true);
SkadiGUI.getInstance().setState(Frame.NORMAL);
SkadiGUI.getInstance().toFront();
}
}
});
Expand Down

0 comments on commit 3e82982

Please sign in to comment.