2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
|
|
|
|
* 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 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-01-15 23:20:17 +01:00
|
|
|
import com.sheepit.client.Client;
|
2014-11-20 13:21:19 +00:00
|
|
|
import com.sheepit.client.Gui;
|
2017-02-19 14:19:48 +01:00
|
|
|
import com.sheepit.client.Job;
|
2014-11-20 13:21:19 +00:00
|
|
|
import com.sheepit.client.Log;
|
2016-10-12 00:34:51 +02:00
|
|
|
import com.sheepit.client.Stats;
|
2017-02-19 14:19:48 +01:00
|
|
|
import com.sheepit.client.standalone.text.CLIInputActionHandler;
|
|
|
|
|
import com.sheepit.client.standalone.text.CLIInputObserver;
|
2016-10-12 00:34:51 +02:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
import sun.misc.Signal;
|
|
|
|
|
import sun.misc.SignalHandler;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
public class GuiText implements Gui {
|
2015-04-08 20:32:24 +01:00
|
|
|
public static final String type = "text";
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
private int framesRendered;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
private int sigIntCount = 0;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
private Log log;
|
|
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
private Client client;
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
public GuiText() {
|
|
|
|
|
this.framesRendered = 0;
|
|
|
|
|
this.log = Log.getInstance(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void start() {
|
2015-01-27 21:44:32 +00:00
|
|
|
if (client != null) {
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2017-02-19 14:19:48 +01:00
|
|
|
CLIInputObserver cli_input_observer = new CLIInputObserver(client);
|
|
|
|
|
cli_input_observer.addListener(new CLIInputActionHandler());
|
|
|
|
|
Thread cli_input_observer_thread = new Thread(cli_input_observer);
|
|
|
|
|
cli_input_observer_thread.start();
|
|
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
Signal.handle(new Signal("INT"), new SignalHandler() {
|
|
|
|
|
@Override
|
|
|
|
|
public void handle(Signal signal) {
|
|
|
|
|
sigIntCount++;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
if (sigIntCount == 4) {
|
|
|
|
|
// This is only for ugly issues that might occur
|
|
|
|
|
System.out.println("WARNING: Hitting Ctrl-C again will force close the application.");
|
|
|
|
|
}
|
|
|
|
|
else if (sigIntCount == 5) {
|
|
|
|
|
Signal.raise(new Signal("INT"));
|
|
|
|
|
Runtime.getRuntime().halt(0);
|
|
|
|
|
}
|
|
|
|
|
else if (client.isRunning() && client.isSuspended() == false) {
|
|
|
|
|
client.askForStop();
|
|
|
|
|
System.out.println("Will exit after current frame... Press Ctrl+C again to exit now.");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
client.stop();
|
2016-02-16 23:51:16 +01:00
|
|
|
GuiText.this.stop();
|
2016-01-27 13:41:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
client.run();
|
|
|
|
|
client.stop();
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void stop() {
|
2016-01-27 13:41:11 +01:00
|
|
|
Runtime.getRuntime().halt(0);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2020-03-19 23:48:06 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateTrayIcon(Integer percentage) {
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
@Override
|
|
|
|
|
public void status(String msg_) {
|
|
|
|
|
System.out.println(msg_);
|
|
|
|
|
log.debug("GUI " + msg_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void error(String err_) {
|
|
|
|
|
System.out.println("Error " + err_);
|
|
|
|
|
log.error("Error " + err_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void AddFrameRendered() {
|
|
|
|
|
this.framesRendered += 1;
|
2016-01-27 13:44:20 +01:00
|
|
|
System.out.println("Frames rendered: " + this.framesRendered);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-10-12 00:34:51 +02:00
|
|
|
public void displayStats(Stats stats) {
|
|
|
|
|
System.out.println("Frames remaining: " + stats.getRemainingFrame());
|
|
|
|
|
System.out.println("Credits earned: " + stats.getCreditsEarnedDuringSession());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRenderingProjectName(String name_) {
|
|
|
|
|
if (name_ != null && name_.isEmpty() == false) {
|
|
|
|
|
System.out.println("Rendering project \"" + name_ + "\"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRemainingTime(String time_) {
|
2016-12-06 06:33:31 +01:00
|
|
|
System.out.println("Rendering (remaining " + time_ + ")");
|
2016-10-12 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRenderingTime(String time_) {
|
2016-12-06 06:33:31 +01:00
|
|
|
System.out.println("Rendering " + time_);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:20:17 +01:00
|
|
|
@Override
|
|
|
|
|
public void setClient(Client cli) {
|
2015-01-27 21:44:32 +00:00
|
|
|
client = cli;
|
2015-01-15 23:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-07 21:00:20 +02:00
|
|
|
@Override
|
|
|
|
|
public void setComputeMethod(String computeMethod) {
|
|
|
|
|
System.out.println("Compute method: " + computeMethod);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-15 23:20:17 +01:00
|
|
|
@Override
|
|
|
|
|
public Client getClient() {
|
2015-01-27 21:44:32 +00:00
|
|
|
return client;
|
2015-01-15 23:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 21:35:26 +02:00
|
|
|
@Override
|
|
|
|
|
public void successfulAuthenticationEvent(String publickey) {
|
|
|
|
|
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|