2015-01-15 23:22:22 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
2020-05-28 13:28:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2015-01-15 23:22:22 +01:00
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* 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, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.sheepit.client.standalone;
|
|
|
|
|
|
2015-08-05 19:35:13 +01:00
|
|
|
import java.awt.AWTException;
|
2015-07-29 16:51:34 -06:00
|
|
|
import java.awt.GridBagLayout;
|
2015-08-05 19:35:13 +01:00
|
|
|
import java.awt.Image;
|
|
|
|
|
import java.awt.MenuItem;
|
|
|
|
|
import java.awt.PopupMenu;
|
|
|
|
|
import java.awt.SystemTray;
|
|
|
|
|
import java.awt.TrayIcon;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
2015-10-27 20:41:20 +00:00
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
|
import java.awt.event.WindowStateListener;
|
2020-03-19 23:48:06 +01:00
|
|
|
import java.awt.image.BufferedImage;
|
2015-01-15 23:22:22 +01:00
|
|
|
import java.net.URL;
|
2016-10-12 00:34:51 +02:00
|
|
|
import java.util.Timer;
|
|
|
|
|
import java.util.TimerTask;
|
2015-01-15 23:22:22 +01:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
import javax.swing.UIManager;
|
|
|
|
|
import javax.swing.UnsupportedLookAndFeelException;
|
|
|
|
|
import javax.swing.border.EmptyBorder;
|
2020-03-19 23:48:06 +01:00
|
|
|
import javax.imageio.ImageIO;
|
2015-01-15 23:22:22 +01:00
|
|
|
|
|
|
|
|
import com.sheepit.client.Client;
|
|
|
|
|
import com.sheepit.client.Configuration;
|
|
|
|
|
import com.sheepit.client.Gui;
|
2019-08-22 21:35:26 +02:00
|
|
|
import com.sheepit.client.SettingsLoader;
|
2016-10-12 00:34:51 +02:00
|
|
|
import com.sheepit.client.Stats;
|
2020-09-12 10:00:24 +10:00
|
|
|
import com.sheepit.client.TransferStats;
|
2015-01-15 23:22:22 +01:00
|
|
|
import com.sheepit.client.standalone.swing.activity.Settings;
|
|
|
|
|
import com.sheepit.client.standalone.swing.activity.Working;
|
2019-09-15 21:34:16 +02:00
|
|
|
import lombok.Getter;
|
2019-08-22 21:35:26 +02:00
|
|
|
import lombok.Setter;
|
2015-01-15 23:22:22 +01:00
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
import com.formdev.flatlaf.FlatLightLaf; // Required for dark & light mode
|
2020-04-14 23:24:28 +10:00
|
|
|
import com.formdev.flatlaf.FlatDarkLaf;
|
|
|
|
|
import com.formdev.flatlaf.FlatLaf;
|
|
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
public class GuiSwing extends JFrame implements Gui {
|
2015-04-08 20:32:24 +01:00
|
|
|
public static final String type = "swing";
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
public enum ActivityType {
|
|
|
|
|
WORKING, SETTINGS
|
2015-01-25 18:26:21 +00:00
|
|
|
}
|
2015-01-15 23:22:22 +01:00
|
|
|
|
2015-09-07 20:10:06 +01:00
|
|
|
private SystemTray sysTray;
|
2015-01-15 23:22:22 +01:00
|
|
|
private JPanel panel;
|
|
|
|
|
private Working activityWorking;
|
|
|
|
|
private Settings activitySettings;
|
2015-08-05 19:35:13 +01:00
|
|
|
private TrayIcon trayIcon;
|
2016-04-28 19:37:05 +02:00
|
|
|
private boolean useSysTray;
|
2018-06-14 23:07:06 +02:00
|
|
|
private String title;
|
2015-01-15 23:22:22 +01:00
|
|
|
|
|
|
|
|
private int framesRendered;
|
|
|
|
|
|
|
|
|
|
private boolean waitingForAuthentication;
|
|
|
|
|
private Client client;
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
private BufferedImage iconSprites;
|
|
|
|
|
private BufferedImage[] trayIconSprites;
|
2020-05-28 13:28:42 +02:00
|
|
|
|
|
|
|
|
@Getter @Setter private SettingsLoader settingsLoader;
|
2015-01-15 23:22:22 +01:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
private ThreadClient threadClient;
|
|
|
|
|
|
2018-06-14 23:07:06 +02:00
|
|
|
public GuiSwing(boolean useSysTray_, String title_) {
|
2015-01-15 23:22:22 +01:00
|
|
|
framesRendered = 0;
|
2016-04-28 19:37:05 +02:00
|
|
|
useSysTray = useSysTray_;
|
2018-06-14 23:07:06 +02:00
|
|
|
title = title_;
|
2015-01-15 23:22:22 +01:00
|
|
|
waitingForAuthentication = true;
|
2016-10-12 00:34:51 +02:00
|
|
|
|
|
|
|
|
new Timer().scheduleAtFixedRate(new TimerTask() {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void run() {
|
2016-10-12 00:34:51 +02:00
|
|
|
if (activityWorking != null) {
|
|
|
|
|
activityWorking.updateTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, 2 * 1000, 2 * 1000);
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void start() {
|
2016-04-28 19:37:05 +02:00
|
|
|
if (useSysTray) {
|
|
|
|
|
try {
|
|
|
|
|
sysTray = SystemTray.getSystemTray();
|
|
|
|
|
if (SystemTray.isSupported()) {
|
|
|
|
|
addWindowStateListener(new WindowStateListener() {
|
|
|
|
|
public void windowStateChanged(WindowEvent e) {
|
|
|
|
|
if (e.getNewState() == ICONIFIED) {
|
|
|
|
|
hideToTray();
|
|
|
|
|
}
|
2015-10-27 20:41:20 +00:00
|
|
|
}
|
2016-04-28 19:37:05 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (UnsupportedOperationException e) {
|
|
|
|
|
sysTray = null;
|
2015-10-27 20:41:20 +00:00
|
|
|
}
|
2015-09-07 20:10:06 +01:00
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
// load the images sprite and split into individual images
|
|
|
|
|
URL spriteSequenceUrl = getClass().getResource("/icon-sprites.png");
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
if (spriteSequenceUrl != null) {
|
|
|
|
|
try {
|
|
|
|
|
iconSprites = ImageIO.read(spriteSequenceUrl);
|
2020-05-28 13:28:42 +02:00
|
|
|
trayIconSprites = new BufferedImage[101 * 1]; // sprite sheet has 101 images in 1 column
|
|
|
|
|
|
|
|
|
|
setIconImage(extractImageFromSprite(-1)); // sprite 0 is standard Sheep It! icon
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e) {
|
2020-03-19 23:48:06 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2018-06-14 23:07:06 +02:00
|
|
|
setTitle(title);
|
2019-02-10 13:17:39 +01:00
|
|
|
setSize(520, 760);
|
2015-01-15 23:22:22 +01:00
|
|
|
|
|
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
|
|
panel = new JPanel();
|
2015-07-29 16:51:34 -06:00
|
|
|
panel.setLayout(new GridBagLayout());
|
2018-06-17 12:23:47 +02:00
|
|
|
setContentPane(this.panel);
|
2016-10-12 00:34:51 +02:00
|
|
|
panel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
2015-01-15 23:22:22 +01:00
|
|
|
|
|
|
|
|
activityWorking = new Working(this);
|
|
|
|
|
activitySettings = new Settings(this);
|
|
|
|
|
|
|
|
|
|
this.showActivity(ActivityType.SETTINGS);
|
|
|
|
|
|
2020-04-14 23:24:28 +10:00
|
|
|
try {
|
|
|
|
|
if (client.getConfiguration().getTheme().equals("light")) {
|
|
|
|
|
UIManager.setLookAndFeel(new FlatLightLaf());
|
2020-05-28 13:28:42 +02:00
|
|
|
}
|
|
|
|
|
else if (client.getConfiguration().getTheme().equals("dark")) {
|
2020-04-14 23:24:28 +10:00
|
|
|
UIManager.setLookAndFeel(new FlatDarkLaf());
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-04-14 23:24:28 +10:00
|
|
|
// Apply the selected theme to swing components
|
|
|
|
|
FlatLaf.updateUI();
|
|
|
|
|
}
|
|
|
|
|
catch (UnsupportedLookAndFeelException e1) {
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
while (waitingForAuthentication) {
|
|
|
|
|
try {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
wait();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void stop() {
|
2015-08-05 19:58:11 +01:00
|
|
|
System.exit(0);
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void status(String msg_) {
|
2020-04-26 23:35:05 +10:00
|
|
|
status(msg_, false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void status(String msg_, boolean overwriteSuspendedMsg) {
|
2015-01-15 23:22:22 +01:00
|
|
|
if (activityWorking != null) {
|
2020-04-26 23:35:05 +10:00
|
|
|
this.activityWorking.setStatus(msg_, overwriteSuspendedMsg);
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-06-17 18:24:59 +10:00
|
|
|
@Override public void status(String msg, int progress) {
|
2020-06-14 20:01:32 +10:00
|
|
|
if (activityWorking != null) {
|
|
|
|
|
this.activityWorking.setStatus(String.format("%s %d%%", msg, progress));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 18:24:59 +10:00
|
|
|
@Override public void status(String msg, int progress, long size) {
|
|
|
|
|
this.status(msg, progress);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setRenderingProjectName(String name_) {
|
2016-10-12 00:34:51 +02:00
|
|
|
if (activityWorking != null) {
|
|
|
|
|
this.activityWorking.setRenderingProjectName(name_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void error(String msg_) {
|
2020-05-11 21:51:36 +10:00
|
|
|
status(msg_, true);
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setRemainingTime(String time_) {
|
2016-10-12 00:34:51 +02:00
|
|
|
if (activityWorking != null) {
|
|
|
|
|
this.activityWorking.setRemainingTime(time_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setRenderingTime(String time_) {
|
2016-10-12 00:34:51 +02:00
|
|
|
if (activityWorking != null) {
|
|
|
|
|
this.activityWorking.setRenderingTime(time_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:00:24 +10:00
|
|
|
@Override public synchronized void displayTransferStats(TransferStats downloads, TransferStats uploads) {
|
|
|
|
|
this.activityWorking.displayTransferStats(downloads, uploads);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void AddFrameRendered() {
|
2015-01-15 23:22:22 +01:00
|
|
|
framesRendered++;
|
|
|
|
|
|
|
|
|
|
if (activityWorking != null) {
|
|
|
|
|
this.activityWorking.setRenderedFrame(framesRendered);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-05-26 20:14:18 +01:00
|
|
|
System.out.println("GuiSwing::AddFrameRendered() error: no working activity");
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void displayStats(Stats stats) {
|
2015-01-15 23:22:22 +01:00
|
|
|
if (activityWorking != null) {
|
2016-10-12 00:34:51 +02:00
|
|
|
this.activityWorking.displayStats(stats);
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void displayUploadQueueStats(int queueSize, long queueVolume) {
|
2020-04-20 01:01:43 +10:00
|
|
|
if (activityWorking != null) {
|
|
|
|
|
this.activityWorking.displayUploadQueueStats(queueSize, queueVolume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public Client getClient() {
|
2015-01-15 23:22:22 +01:00
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setClient(Client cli) {
|
2015-01-15 23:22:22 +01:00
|
|
|
client = cli;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setComputeMethod(String computeMethod) {
|
2017-05-07 21:00:20 +02:00
|
|
|
this.activityWorking.setComputeMethod(computeMethod);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
public Configuration getConfiguration() {
|
|
|
|
|
return client.getConfiguration();
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
|
|
|
|
@Override public void successfulAuthenticationEvent(String publickey) {
|
2019-08-22 21:35:26 +02:00
|
|
|
if (settingsLoader != null) {
|
|
|
|
|
if (publickey != null) {
|
|
|
|
|
settingsLoader.setPassword(publickey);
|
|
|
|
|
}
|
|
|
|
|
settingsLoader.saveFile();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-15 23:22:22 +01:00
|
|
|
|
|
|
|
|
public void setCredentials(String contentLogin, String contentPassword) {
|
|
|
|
|
client.getConfiguration().setLogin(contentLogin);
|
|
|
|
|
client.getConfiguration().setPassword(contentPassword);
|
|
|
|
|
|
|
|
|
|
waitingForAuthentication = false;
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
notifyAll();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-06 00:44:30 +01:00
|
|
|
if (threadClient == null || threadClient.isAlive() == false) {
|
2015-01-27 21:44:32 +00:00
|
|
|
threadClient = new ThreadClient();
|
|
|
|
|
threadClient.start();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
showActivity(ActivityType.WORKING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void showActivity(ActivityType type) {
|
|
|
|
|
panel.removeAll();
|
|
|
|
|
panel.doLayout();
|
|
|
|
|
|
|
|
|
|
if (type == ActivityType.WORKING) {
|
|
|
|
|
activityWorking.show();
|
|
|
|
|
}
|
|
|
|
|
else if (type == ActivityType.SETTINGS) {
|
|
|
|
|
activitySettings.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setVisible(true);
|
|
|
|
|
panel.repaint();
|
|
|
|
|
}
|
2015-01-27 21:44:32 +00:00
|
|
|
|
2015-08-05 19:35:13 +01:00
|
|
|
public void hideToTray() {
|
2015-09-07 20:10:06 +01:00
|
|
|
if (sysTray == null || SystemTray.isSupported() == false) {
|
2015-08-05 19:35:13 +01:00
|
|
|
System.out.println("GuiSwing::hideToTray SystemTray not supported!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
trayIcon = getTrayIcon();
|
2015-09-07 20:10:06 +01:00
|
|
|
sysTray.add(trayIcon);
|
2015-08-05 19:35:13 +01:00
|
|
|
}
|
|
|
|
|
catch (AWTException e) {
|
|
|
|
|
System.out.println("GuiSwing::hideToTray an error occured while trying to add system tray icon (exception: " + e + ")");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setVisible(false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void restoreFromTray() {
|
2015-09-07 20:10:06 +01:00
|
|
|
if (sysTray != null && SystemTray.isSupported()) {
|
|
|
|
|
sysTray.remove(trayIcon);
|
|
|
|
|
setVisible(true);
|
2015-10-27 20:41:20 +00:00
|
|
|
setExtendedState(getExtendedState() & ~JFrame.ICONIFIED & JFrame.NORMAL); // for toFront and requestFocus to actually work
|
|
|
|
|
toFront();
|
|
|
|
|
requestFocus();
|
2015-09-07 20:10:06 +01:00
|
|
|
}
|
2015-08-05 19:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TrayIcon getTrayIcon() {
|
|
|
|
|
final PopupMenu trayMenu = new PopupMenu();
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
// on start, show the base icon
|
|
|
|
|
Image img = extractImageFromSprite(-1);
|
2015-08-05 19:35:13 +01:00
|
|
|
final TrayIcon icon = new TrayIcon(img);
|
|
|
|
|
|
|
|
|
|
MenuItem exit = new MenuItem("Exit");
|
|
|
|
|
exit.addActionListener(new ActionListener() {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void actionPerformed(ActionEvent e) {
|
2015-08-05 19:35:13 +01:00
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
trayMenu.add(exit);
|
|
|
|
|
|
|
|
|
|
MenuItem open = new MenuItem("Open...");
|
|
|
|
|
open.addActionListener(new ActionListener() {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void actionPerformed(ActionEvent e) {
|
2015-08-05 19:35:13 +01:00
|
|
|
restoreFromTray();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
trayMenu.add(open);
|
|
|
|
|
|
|
|
|
|
MenuItem settings = new MenuItem("Settings...");
|
|
|
|
|
settings.addActionListener(new ActionListener() {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void actionPerformed(ActionEvent e) {
|
2015-08-05 19:35:13 +01:00
|
|
|
restoreFromTray();
|
|
|
|
|
showActivity(ActivityType.SETTINGS);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
trayMenu.add(settings);
|
|
|
|
|
|
|
|
|
|
icon.setPopupMenu(trayMenu);
|
|
|
|
|
icon.setImageAutoSize(true);
|
|
|
|
|
icon.setToolTip("SheepIt! Client");
|
|
|
|
|
|
|
|
|
|
icon.addActionListener(new ActionListener() {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void actionPerformed(ActionEvent e) {
|
2015-08-05 19:35:13 +01:00
|
|
|
restoreFromTray();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
|
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
private Image extractImageFromSprite(int spriteNumber) {
|
|
|
|
|
// Sprite structure
|
|
|
|
|
// Image 0: base sprite
|
|
|
|
|
// Images 1-101: progress bar percentage from 0 to 100
|
|
|
|
|
//
|
|
|
|
|
// Always add +1 to the icon requested.
|
|
|
|
|
// -1 turns into 0 (base sprite with no progress bar)
|
|
|
|
|
// 0 to 101 turns into 1 to 101 (progress sequence starts in sprite 1 and ends on sprite 101)
|
|
|
|
|
ImageIcon img = new ImageIcon(iconSprites.getSubimage(0, (spriteNumber + 1) * 114, 114, 114));
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
return img.getImage();
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
|
|
|
|
@Override public void updateTrayIcon(Integer percentage) {
|
2020-03-19 23:48:06 +01:00
|
|
|
// update the app icon on the app bar
|
|
|
|
|
Image img = extractImageFromSprite(percentage);
|
|
|
|
|
setIconImage(img);
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2020-03-19 23:48:06 +01:00
|
|
|
// if the app supports the system tray, update as well
|
|
|
|
|
if (sysTray != null && SystemTray.isSupported()) {
|
|
|
|
|
if (trayIcon != null) {
|
|
|
|
|
trayIcon.setImage(img);
|
2020-05-28 13:28:42 +02:00
|
|
|
trayIcon.setImageAutoSize(true); // use this method to ensure that icon is refreshed when on
|
|
|
|
|
// the tray
|
2020-03-19 23:48:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
public class ThreadClient extends Thread {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void run() {
|
2015-01-27 21:44:32 +00:00
|
|
|
if (GuiSwing.this.client != null) {
|
2015-01-28 19:52:40 +00:00
|
|
|
GuiSwing.this.client.run();
|
2015-01-27 21:44:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:22:22 +01:00
|
|
|
}
|