* Better ui with more infos

* Remove revision from protocol since it's not use anymore
This commit is contained in:
Laurent Clouet
2016-10-12 00:34:51 +02:00
parent 09eb650da2
commit 07f9662c00
12 changed files with 543 additions and 356 deletions

View File

@@ -5,7 +5,7 @@
<property name="compile.deprecation" value="true"/> <property name="compile.deprecation" value="true"/>
<property name="compile.optimize" value="true"/> <property name="compile.optimize" value="true"/>
<property name="compile.version" value="1.7"/> <property name="compile.version" value="1.7"/>
<property name="compile.release" value="3.3.2"/> <property name="compile.release" value="5.0.0"/>
<target name="precompile"> <target name="precompile">
<antcall target="clean" /> <antcall target="clean" />

View File

@@ -66,7 +66,6 @@ Url: use the request type "download-archive" from the configuration answer.
Parameter as GET or POST: Parameter as GET or POST:
* type: "job" * type: "job"
* job: Id of the job * job: Id of the job
* revision: Revision of the job
Answer: Answer:
No error: the file No error: the file
@@ -100,7 +99,7 @@ Answer with no error:
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<jobrequest status="0"> <jobrequest status="0">
<frames remaining="1187" /> <frames remaining="1187" />
<job id="1" use_gpu="1" archive_md5="11d046f9912267a29f99a731c7e4e3b0" revision="0" path="compute_method.blend" frame="0340" synchronous_upload="1" name="human name" password="some_passowrd"> <job id="1" use_gpu="1" archive_md5="11d046f9912267a29f99a731c7e4e3b0" path="compute_method.blend" frame="0340" synchronous_upload="1" name="human name" password="some_passowrd">
<renderer md5="ceda00890578762c6fac96f1a13f671a" commandline=".e --factory-startup --disable-autoexec -b .c -o .o -f .f -x 1" update_method="remainingtime"/> <renderer md5="ceda00890578762c6fac96f1a13f671a" commandline=".e --factory-startup --disable-autoexec -b .c -o .o -f .f -x 1" update_method="remainingtime"/>
<script>import bpy <script>import bpy
# disable the GPU for Cycles # disable the GPU for Cycles
@@ -126,7 +125,6 @@ Parameter as GET or POST:
* job: Job's id * job: Job's id
* frame: Job's frame number * frame: Job's frame number
* rendertime: Job's render time * rendertime: Job's render time
* revision: Job's revision
* extras: Job's extra data * extras: Job's extra data
* file: Frame to validate as form-data post * file: Frame to validate as form-data post
* memoryused (optional): Max memory used for the render * memoryused (optional): Max memory used for the render

View File

@@ -51,6 +51,7 @@ public class Client {
private Job renderingJob; private Job renderingJob;
private BlockingQueue<Job> jobsToValidate; private BlockingQueue<Job> jobsToValidate;
private boolean isValidatingJob; private boolean isValidatingJob;
private long start_time;
private boolean disableErrorSending; private boolean disableErrorSending;
private boolean running; private boolean running;
@@ -96,6 +97,10 @@ public class Client {
return this.log; return this.log;
} }
public long getStartTime() {
return this.start_time;
}
public int run() { public int run() {
if (this.config.checkOSisSupported() == false) { if (this.config.checkOSisSupported() == false) {
this.gui.error(Error.humanString(Error.Type.OS_NOT_SUPPORTED)); this.gui.error(Error.humanString(Error.Type.OS_NOT_SUPPORTED));
@@ -127,6 +132,7 @@ public class Client {
return -1; return -1;
} }
this.start_time = new Date().getTime();
this.server.start(); // for staying alive this.server.start(); // for staying alive
// create a thread which will send the frame // create a thread which will send the frame
@@ -182,12 +188,12 @@ public class Client {
} }
catch (FermeExceptionNoSession e) { catch (FermeExceptionNoSession e) {
// User has no session need to re-authenticate // User has no session need to re-authenticate
ret = this.server.getConfiguration(); ret = this.server.getConfiguration();
if (ret != Error.Type.OK) { if (ret != Error.Type.OK) {
this.renderingJob = null; this.renderingJob = null;
} }
else { else {
this.start_time = new Date().getTime(); // reset start session time because the server did it
try { try {
Calendar next_request = this.nextJobRequest(); Calendar next_request = this.nextJobRequest();
if (next_request != null) { if (next_request != null) {
@@ -274,7 +280,7 @@ public class Client {
int time_sleep = 1000 * 60 * 15; int time_sleep = 1000 * 60 * 15;
Date wakeup_time = new Date(new Date().getTime() + time_sleep); Date wakeup_time = new Date(new Date().getTime() + time_sleep);
this.gui.status(String.format("No job available. Sleeping for 15 minutes (will wake up at %tR)", wakeup_time)); this.gui.status(String.format("No job available. Sleeping for 15 minutes (will wake up at %tR)", wakeup_time));
this.gui.framesRemaining(0); this.gui.displayStats(new Stats());
this.suspended = true; this.suspended = true;
int time_slept = 0; int time_slept = 0;
while (time_slept < time_sleep && this.running == true) { while (time_slept < time_sleep && this.running == true) {
@@ -545,26 +551,32 @@ public class Client {
public Error.Type work(Job ajob) { public Error.Type work(Job ajob) {
int ret; int ret;
gui.setRenderingProjectName(ajob.getName());
try { try {
ret = this.downloadExecutable(ajob); ret = this.downloadExecutable(ajob);
if (ret != 0) { if (ret != 0) {
gui.setRenderingProjectName("");
this.log.error("Client::work problem with downloadExecutable (ret " + ret + ")"); this.log.error("Client::work problem with downloadExecutable (ret " + ret + ")");
return Error.Type.DOWNLOAD_FILE; return Error.Type.DOWNLOAD_FILE;
} }
ret = this.downloadSceneFile(ajob); ret = this.downloadSceneFile(ajob);
if (ret != 0) { if (ret != 0) {
gui.setRenderingProjectName("");
this.log.error("Client::work problem with downloadSceneFile (ret " + ret + ")"); this.log.error("Client::work problem with downloadSceneFile (ret " + ret + ")");
return Error.Type.DOWNLOAD_FILE; return Error.Type.DOWNLOAD_FILE;
} }
ret = this.prepareWorkingDirectory(ajob); // decompress renderer and scene archives ret = this.prepareWorkingDirectory(ajob); // decompress renderer and scene archives
if (ret != 0) { if (ret != 0) {
gui.setRenderingProjectName("");
this.log.error("Client::work problem with this.prepareWorkingDirectory (ret " + ret + ")"); this.log.error("Client::work problem with this.prepareWorkingDirectory (ret " + ret + ")");
return Error.Type.CAN_NOT_CREATE_DIRECTORY; return Error.Type.CAN_NOT_CREATE_DIRECTORY;
} }
} }
catch (FermeExceptionNoSpaceLeftOnDevice e) { catch (FermeExceptionNoSpaceLeftOnDevice e) {
gui.setRenderingProjectName("");
return Error.Type.NO_SPACE_LEFT_ON_DEVICE; return Error.Type.NO_SPACE_LEFT_ON_DEVICE;
} }
@@ -572,16 +584,21 @@ public class Client {
File renderer_file = new File(ajob.getRendererPath()); File renderer_file = new File(ajob.getRendererPath());
if (scene_file.exists() == false) { if (scene_file.exists() == false) {
gui.setRenderingProjectName("");
this.log.error("Client::work job preparation failed (scene file '" + scene_file.getAbsolutePath() + "' does not exist)"); this.log.error("Client::work job preparation failed (scene file '" + scene_file.getAbsolutePath() + "' does not exist)");
return Error.Type.MISSING_SCENE; return Error.Type.MISSING_SCENE;
} }
if (renderer_file.exists() == false) { if (renderer_file.exists() == false) {
gui.setRenderingProjectName("");
this.log.error("Client::work job preparation failed (renderer file '" + renderer_file.getAbsolutePath() + "' does not exist)"); this.log.error("Client::work job preparation failed (renderer file '" + renderer_file.getAbsolutePath() + "' does not exist)");
return Error.Type.MISSING_RENDER; return Error.Type.MISSING_RENDER;
} }
Error.Type err = ajob.render(); Error.Type err = ajob.render();
gui.setRenderingProjectName("");
gui.setRemainingTime("");
gui.setRenderingTime("");
if (err != Error.Type.OK) { if (err != Error.Type.OK) {
this.log.error("Client::work problem with runRenderer (ret " + err + ")"); this.log.error("Client::work problem with runRenderer (ret " + err + ")");
return err; return err;
@@ -591,7 +608,7 @@ public class Client {
} }
protected int downloadSceneFile(Job ajob_) throws FermeExceptionNoSpaceLeftOnDevice { protected int downloadSceneFile(Job ajob_) throws FermeExceptionNoSpaceLeftOnDevice {
return this.downloadFile(ajob_, ajob_.getSceneArchivePath(), ajob_.getSceneMD5(), String.format("%s?type=job&job=%s&revision=%s", this.server.getPage("download-archive"), ajob_.getId(), ajob_.getRevision()), "project"); return this.downloadFile(ajob_, ajob_.getSceneArchivePath(), ajob_.getSceneMD5(), String.format("%s?type=job&job=%s", this.server.getPage("download-archive"), ajob_.getId()), "project");
} }
protected int downloadExecutable(Job ajob) throws FermeExceptionNoSpaceLeftOnDevice { protected int downloadExecutable(Job ajob) throws FermeExceptionNoSpaceLeftOnDevice {
@@ -718,7 +735,7 @@ public class Client {
extras_config = "&cores=" + process.getCoresUsed(); extras_config = "&cores=" + process.getCoresUsed();
} }
String url_real = String.format("%s?job=%s&frame=%s&rendertime=%d&revision=%s&memoryused=%s&extras=%s%s", this.server.getPage("validate-job"), ajob.getId(), ajob.getFrameNumber(), ajob.getProcessRender().getDuration(), ajob.getRevision(), ajob.getProcessRender().getMemoryUsed(), ajob.getExtras(), extras_config); String url_real = String.format("%s?job=%s&frame=%s&rendertime=%d&memoryused=%s&extras=%s%s", this.server.getPage("validate-job"), ajob.getId(), ajob.getFrameNumber(), ajob.getProcessRender().getDuration(), ajob.getProcessRender().getMemoryUsed(), ajob.getExtras(), extras_config);
this.isValidatingJob = true; this.isValidatingJob = true;
int nb_try = 1; int nb_try = 1;

View File

@@ -20,18 +20,24 @@
package com.sheepit.client; package com.sheepit.client;
public interface Gui { public interface Gui {
public abstract void start(); public void start();
public abstract void stop(); public void stop();
public abstract void status(String msg_); public void status(String msg_);
public void setRenderingProjectName(String name_);
public void setRemainingTime(String time_);
public void setRenderingTime(String time_);
public void displayStats(Stats stats);
public void error(String err_); public void error(String err_);
public void AddFrameRendered(); public void AddFrameRendered();
public void framesRemaining(int nb_);
public void setClient(Client cli); public void setClient(Client cli);
public Client getClient(); public Client getClient();

View File

@@ -50,7 +50,6 @@ public class Job {
private String sceneMD5; private String sceneMD5;
private String rendererMD5; private String rendererMD5;
private String id; private String id;
private String revision;
private String pictureFilename; private String pictureFilename;
private String path; // path inside of the archive private String path; // path inside of the archive
private String rendererCommand; private String rendererCommand;
@@ -68,11 +67,10 @@ public class Job {
private Configuration config; private Configuration config;
private Log log; private Log log;
public Job(Configuration config_, Gui gui_, Log log_, String id_, String frame_, String revision_, String path_, boolean use_gpu, String command_, String script_, String sceneMd5_, String rendererMd5_, String name_, String password_, String extras_, boolean synchronous_upload_, String update_method_) { public Job(Configuration config_, Gui gui_, Log log_, String id_, String frame_, String path_, boolean use_gpu, String command_, String script_, String sceneMd5_, String rendererMd5_, String name_, String password_, String extras_, boolean synchronous_upload_, String update_method_) {
config = config_; config = config_;
id = id_; id = id_;
numFrame = frame_; numFrame = frame_;
revision = revision_;
path = path_; path = path_;
useGPU = use_gpu; useGPU = use_gpu;
rendererCommand = command_; rendererCommand = command_;
@@ -97,7 +95,7 @@ public class Job {
} }
public String toString() { public String toString() {
return String.format("Job (numFrame '%s' sceneMD5 '%s' rendererMD5 '%s' ID '%s' revision '%s' pictureFilename '%s' jobPath '%s' gpu %s name '%s' extras '%s' updateRenderingStatusMethod '%s' render %s)", numFrame, sceneMD5, rendererMD5, id, revision, pictureFilename, path, useGPU, name, extras, updateRenderingStatusMethod, render); return String.format("Job (numFrame '%s' sceneMD5 '%s' rendererMD5 '%s' ID '%s' pictureFilename '%s' jobPath '%s' gpu %s name '%s' extras '%s' updateRenderingStatusMethod '%s' render %s)", numFrame, sceneMD5, rendererMD5, id, pictureFilename, path, useGPU, name, extras, updateRenderingStatusMethod, render);
} }
public String getId() { public String getId() {
@@ -156,8 +154,8 @@ public class Job {
return useGPU; return useGPU;
} }
public String getRevision() { public String getName() {
return revision; return name;
} }
public void setOutputImagePath(String path) { public void setOutputImagePath(String path) {
@@ -205,7 +203,7 @@ public class Job {
} }
public Error.Type render() { public Error.Type render() {
gui.status("Rendering project \"" + this.name + "\""); gui.status("Rendering");
RenderProcess process = getProcessRender(); RenderProcess process = getProcessRender();
String core_script = "import bpy\n" + "bpy.context.user_preferences.system.compute_device_type = \"%s\"\n" + "bpy.context.scene.cycles.device = \"%s\"\n" + "bpy.context.user_preferences.system.compute_device = \"%s\"\n"; String core_script = "import bpy\n" + "bpy.context.user_preferences.system.compute_device_type = \"%s\"\n" + "bpy.context.scene.cycles.device = \"%s\"\n" + "bpy.context.user_preferences.system.compute_device = \"%s\"\n";
if (getUseGPU() && config.getGPUDevice() != null && config.getComputeMethod() != ComputeType.CPU) { if (getUseGPU() && config.getGPUDevice() != null && config.getComputeMethod() != ComputeType.CPU) {
@@ -406,7 +404,9 @@ public class Job {
int current = Integer.parseInt(parts[0]); int current = Integer.parseInt(parts[0]);
int total = Integer.parseInt(parts[1]); int total = Integer.parseInt(parts[1]);
if (total != 0) { if (total != 0) {
gui.status(String.format("Rendering %s %%", (int) (100.0 * current / total))); long end_render = (new Date().getTime() - this.render.getStartTime()) * total / current;
Date date = new Date(end_render);
gui.setRemainingTime(String.format("%s %% (%s)", (int) (100.0 - 100.0 * current / total), Utils.humanDuration(date)));
return; return;
} }
} }
@@ -440,7 +440,7 @@ public class Job {
} }
date_parse.setTimeZone(TimeZone.getTimeZone("GMT")); date_parse.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = date_parse.parse(remaining_time); Date date = date_parse.parse(remaining_time);
gui.status(String.format("Rendering (remaining %s)", Utils.humanDuration(date))); gui.setRemainingTime(Utils.humanDuration(date));
getProcessRender().setRemainingDuration((int) (date.getTime() / 1000)); getProcessRender().setRemainingDuration((int) (date.getTime() / 1000));
} }
catch (ParseException err) { catch (ParseException err) {

View File

@@ -352,15 +352,23 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
Element a_node = null; Element a_node = null;
NodeList ns = null; NodeList ns = null;
ns = document.getElementsByTagName("frames"); ns = document.getElementsByTagName("stats");
if (ns.getLength() == 0) { if (ns.getLength() == 0) {
throw new FermeException("error requestJob: parseXML failed, no 'frame' node"); throw new FermeException("error requestJob: parseXML failed, no 'frame' node");
} }
a_node = (Element) ns.item(0); a_node = (Element) ns.item(0);
int remaining_frames = -1; int remaining_frames = 0;
if (a_node.hasAttribute("remaining")) { int credits_earned = 0;
remaining_frames = Integer.parseInt(a_node.getAttribute("remaining")); int credits_earned_session = 0;
int waiting_project = 0;
int connected_machine = 0;
if (a_node.hasAttribute("frame_remaining") && a_node.hasAttribute("credits_total") && a_node.hasAttribute("credits_session") && a_node.hasAttribute("waiting_project") && a_node.hasAttribute("connected_machine")) {
remaining_frames = Integer.parseInt(a_node.getAttribute("frame_remaining"));
credits_earned = Integer.parseInt(a_node.getAttribute("credits_total"));
credits_earned_session = Integer.parseInt(a_node.getAttribute("credits_session"));
waiting_project = Integer.parseInt(a_node.getAttribute("waiting_project"));
connected_machine = Integer.parseInt(a_node.getAttribute("connected_machine"));
} }
ns = document.getElementsByTagName("job"); ns = document.getElementsByTagName("job");
@@ -387,7 +395,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
e.printStackTrace(); e.printStackTrace();
} }
String[] job_node_require_attribute = { "id", "archive_md5", "path", "revision", "use_gpu", "frame", "name", "extras", "password" }; String[] job_node_require_attribute = { "id", "archive_md5", "path", "use_gpu", "frame", "name", "extras", "password" };
String[] renderer_node_require_attribute = { "md5", "commandline" }; String[] renderer_node_require_attribute = { "md5", "commandline" };
for (String e : job_node_require_attribute) { for (String e : job_node_require_attribute) {
@@ -424,7 +432,6 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
this.client.getLog(), this.client.getLog(),
job_node.getAttribute("id"), job_node.getAttribute("id"),
job_node.getAttribute("frame"), job_node.getAttribute("frame"),
job_node.getAttribute("revision"),
job_node.getAttribute("path").replace("/", File.separator), job_node.getAttribute("path").replace("/", File.separator),
use_gpu, use_gpu,
renderer_node.getAttribute("commandline"), renderer_node.getAttribute("commandline"),
@@ -438,7 +445,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
update_method update_method
); );
this.client.getGui().framesRemaining(remaining_frames); this.client.getGui().displayStats(new Stats(remaining_frames, credits_earned, credits_earned_session, waiting_project, connected_machine));
return a_job; return a_job;
} }
@@ -795,39 +802,6 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
return null; return null;
} }
public String getCreditEarnedOnCurrentSession() {
try {
HttpURLConnection httpCon = this.HTTPRequest(this.getPage("credits-earned"));
InputStream inStrm = httpCon.getInputStream();
if (httpCon.getResponseCode() != HttpURLConnection.HTTP_OK) {
this.log.debug("Server::getCreditEarnedOnCurrentSession code not ok " + httpCon.getResponseCode());
return null;
}
int size = httpCon.getContentLength();
if (size == 0) {
this.log.debug("Server::getLastRender size is 0");
return null;
}
byte[] ret = new byte[size];
byte[] ch = new byte[1024];
int n = 0;
int i = 0;
while ((n = inStrm.read(ch)) != -1) {
System.arraycopy(ch, 0, ret, i, n);
i += n;
}
inStrm.close();
return new String(ret);
}
catch (Exception e) {
this.log.error("Server::getCreditEarnedOnCurrentSession exception " + e);
}
return null;
}
private String generateXMLForMD5cache() { private String generateXMLForMD5cache() {
String xml_str = null; String xml_str = null;
try { try {

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2016 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;
public class Stats {
private int remainingFrame;
private int creditsEarned;
private int creditsEarnedSession;
private int waitingProject;
private int connectedMachine;
public Stats(int frame, int credits, int creditsSession, int waitings, int machines) {
remainingFrame = frame;
creditsEarned = credits;
creditsEarnedSession = creditsSession;
waitingProject = waitings;
connectedMachine = machines;
}
public Stats() {
remainingFrame = 0;
creditsEarned = 0;
creditsEarnedSession = 0;
waitingProject = 0;
connectedMachine = 0;
}
public int getRemainingFrame() {
return remainingFrame;
}
public int getCreditsEarnedDuringSession() {
return creditsEarnedSession;
}
public int getCreditsEarned() {
return creditsEarned;
}
public int getWaitingProject() {
return waitingProject;
}
public int getConnectedMachine() {
return connectedMachine;
}
@Override
public String toString() {
return "Stats [remainingFrame=" + remainingFrame + ", creditsEarned=" + creditsEarned + ", creditsEarnedSession=" + creditsEarnedSession + ", waitingProject=" + waitingProject + ", connectedMachine=" + connectedMachine + "]";
}
}

View File

@@ -20,7 +20,6 @@
package com.sheepit.client.standalone; package com.sheepit.client.standalone;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Image; import java.awt.Image;
import java.awt.MenuItem; import java.awt.MenuItem;
@@ -33,10 +32,11 @@ import java.awt.event.ActionListener;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener; import java.awt.event.WindowStateListener;
import java.net.URL; import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UnsupportedLookAndFeelException;
@@ -45,11 +45,13 @@ import javax.swing.border.EmptyBorder;
import com.sheepit.client.Client; import com.sheepit.client.Client;
import com.sheepit.client.Configuration; import com.sheepit.client.Configuration;
import com.sheepit.client.Gui; import com.sheepit.client.Gui;
import com.sheepit.client.Stats;
import com.sheepit.client.standalone.swing.activity.Settings; import com.sheepit.client.standalone.swing.activity.Settings;
import com.sheepit.client.standalone.swing.activity.Working; import com.sheepit.client.standalone.swing.activity.Working;
public class GuiSwing extends JFrame implements Gui { public class GuiSwing extends JFrame implements Gui {
public static final String type = "swing"; public static final String type = "swing";
public enum ActivityType { public enum ActivityType {
WORKING, SETTINGS WORKING, SETTINGS
} }
@@ -72,6 +74,15 @@ public class GuiSwing extends JFrame implements Gui {
framesRendered = 0; framesRendered = 0;
useSysTray = useSysTray_; useSysTray = useSysTray_;
waitingForAuthentication = true; waitingForAuthentication = true;
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (activityWorking != null) {
activityWorking.updateTime();
}
}
}, 2 * 1000, 2 * 1000);
} }
@Override @Override
@@ -101,7 +112,6 @@ public class GuiSwing extends JFrame implements Gui {
} }
} }
URL iconUrl = getClass().getResource("/icon.png"); URL iconUrl = getClass().getResource("/icon.png");
if (iconUrl != null) { if (iconUrl != null) {
ImageIcon img = new ImageIcon(iconUrl); ImageIcon img = new ImageIcon(iconUrl);
@@ -109,14 +119,14 @@ public class GuiSwing extends JFrame implements Gui {
} }
setTitle("SheepIt Render Farm"); setTitle("SheepIt Render Farm");
setSize(600, 600); setSize(520, 640);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel(); panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
setContentPane(this.panel); setContentPane(this.panel);
panel.setBorder(new EmptyBorder(5, 5, 5, 5)); panel.setBorder(new EmptyBorder(20, 20, 20, 20));
activityWorking = new Working(this); activityWorking = new Working(this);
activitySettings = new Settings(this); activitySettings = new Settings(this);
@@ -147,11 +157,32 @@ public class GuiSwing extends JFrame implements Gui {
} }
} }
@Override
public void setRenderingProjectName(String name_) {
if (activityWorking != null) {
this.activityWorking.setRenderingProjectName(name_);
}
}
@Override @Override
public void error(String msg_) { public void error(String msg_) {
status(msg_); status(msg_);
} }
@Override
public void setRemainingTime(String time_) {
if (activityWorking != null) {
this.activityWorking.setRemainingTime(time_);
}
}
@Override
public void setRenderingTime(String time_) {
if (activityWorking != null) {
this.activityWorking.setRenderingTime(time_);
}
}
@Override @Override
public void AddFrameRendered() { public void AddFrameRendered() {
framesRendered++; framesRendered++;
@@ -165,12 +196,9 @@ public class GuiSwing extends JFrame implements Gui {
} }
@Override @Override
public void framesRemaining(int n) { public void displayStats(Stats stats) {
if (activityWorking != null) { if (activityWorking != null) {
this.activityWorking.setRemainingFrame(n); this.activityWorking.displayStats(stats);
}
else {
System.out.println("GuiSwing::framesRemaining(" + n + ") error: no working activity");
} }
} }
@@ -184,37 +212,6 @@ public class GuiSwing extends JFrame implements Gui {
client = cli; client = cli;
} }
public JLabel addPaddingReturn(int x, int y, int width, int height) {
GridBagConstraints constraints = new GridBagConstraints();
JLabel label = new JLabel("");
return label;
}
public GridBagConstraints addPaddingConstraints(int x, int y, int width, int height) {
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.gridwidth = width;
constraints.gridheight = height;
constraints.gridx = x;
constraints.gridy = y;
return constraints;
}
public void addPadding(int x, int y, int width, int height) {
GridBagConstraints constraints = new GridBagConstraints();
JLabel label = new JLabel("");
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.gridwidth = width;
constraints.gridheight = height;
constraints.gridx = x;
constraints.gridy = y;
getContentPane().add(label, constraints);
}
public Configuration getConfiguration() { public Configuration getConfiguration() {
return client.getConfiguration(); return client.getConfiguration();
} }

View File

@@ -22,6 +22,8 @@ package com.sheepit.client.standalone;
import com.sheepit.client.Client; import com.sheepit.client.Client;
import com.sheepit.client.Gui; import com.sheepit.client.Gui;
import com.sheepit.client.Log; import com.sheepit.client.Log;
import com.sheepit.client.Stats;
import sun.misc.Signal; import sun.misc.Signal;
import sun.misc.SignalHandler; import sun.misc.SignalHandler;
@@ -95,13 +97,29 @@ public class GuiText implements Gui {
public void AddFrameRendered() { public void AddFrameRendered() {
this.framesRendered += 1; this.framesRendered += 1;
System.out.println("Frames rendered: " + this.framesRendered); System.out.println("Frames rendered: " + this.framesRendered);
String creditsEarned = this.client.getServer().getCreditEarnedOnCurrentSession();
System.out.println("Credits earned: " + (creditsEarned != null ? creditsEarned : "unknown"));
} }
@Override @Override
public void framesRemaining(int n_) { public void displayStats(Stats stats) {
System.out.println("Frames remaining: " + n_); 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_) {
System.out.println("Rendering " + time_);
}
@Override
public void setRenderingTime(String time_) {
System.out.println("Rendering (remaining " + time_ + ")");
} }
@Override @Override

View File

@@ -21,12 +21,15 @@ package com.sheepit.client.standalone;
import com.sheepit.client.Client; import com.sheepit.client.Client;
import com.sheepit.client.Gui; import com.sheepit.client.Gui;
import com.sheepit.client.Stats;
import sun.misc.Signal; import sun.misc.Signal;
import sun.misc.SignalHandler; import sun.misc.SignalHandler;
public class GuiTextOneLine implements Gui { public class GuiTextOneLine implements Gui {
public static final String type = "oneLine"; public static final String type = "oneLine";
private String project;
private int rendered; private int rendered;
private int remaining; private int remaining;
private String creditsEarned; private String creditsEarned;
@@ -40,6 +43,7 @@ public class GuiTextOneLine implements Gui {
private Client client; private Client client;
public GuiTextOneLine() { public GuiTextOneLine() {
project = "";
rendered = 0; rendered = 0;
remaining = 0; remaining = 0;
creditsEarned = null; creditsEarned = null;
@@ -87,6 +91,17 @@ public class GuiTextOneLine implements Gui {
updateLine(); updateLine();
} }
@Override
public void setRenderingProjectName(String name_) {
if (name_ == null || name_.isEmpty()) {
project = "";
}
else {
project = "Project \"" + name_ + "\" |";
}
updateLine();
}
@Override @Override
public void error(String msg_) { public void error(String msg_) {
status = "Error " + msg_; status = "Error " + msg_;
@@ -96,13 +111,25 @@ public class GuiTextOneLine implements Gui {
@Override @Override
public void AddFrameRendered() { public void AddFrameRendered() {
rendered += 1; rendered += 1;
creditsEarned = client.getServer().getCreditEarnedOnCurrentSession();
updateLine(); updateLine();
} }
@Override @Override
public void framesRemaining(int n_) { public void displayStats(Stats stats) {
remaining = n_; remaining = stats.getRemainingFrame();
creditsEarned = String.valueOf(stats.getCreditsEarnedDuringSession());
updateLine();
}
@Override
public void setRemainingTime(String time_) {
status = "Rendering " + time_;
updateLine();
}
@Override
public void setRenderingTime(String time_) {
status = "Rendering (remaining " + time_ + ")";
updateLine(); updateLine();
} }
@@ -120,7 +147,7 @@ public class GuiTextOneLine implements Gui {
int charToRemove = line.length(); int charToRemove = line.length();
System.out.print("\r"); System.out.print("\r");
line = String.format("Frames rendered: %d remaining: %d Credits earned: %s | %s", rendered, remaining, creditsEarned != null ? creditsEarned : "unknown", status + (exiting ? " (Exiting after this frame)" : "")); line = String.format("Frames rendered: %d remaining: %d Credits earned: %s | %s %s", rendered, remaining, creditsEarned != null ? creditsEarned : "unknown", project, status + (exiting ? " (Exiting after this frame)" : ""));
System.out.print(line); System.out.print(line);
for (int i = line.length(); i <= charToRemove; i++) { for (int i = line.length(); i <= charToRemove; i++) {
System.out.print(" "); System.out.print(" ");

View File

@@ -19,11 +19,9 @@
package com.sheepit.client.standalone.swing.activity; package com.sheepit.client.standalone.swing.activity;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.Insets; import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@@ -76,7 +74,6 @@ public class Settings implements Activity {
private boolean haveAutoStarted; private boolean haveAutoStarted;
private JLabel tileSizePadding;
private JTextField tileSizeValue; private JTextField tileSizeValue;
private JLabel tileSizeLabel; private JLabel tileSizeLabel;
private JCheckBox customTileSize; private JCheckBox customTileSize;
@@ -96,85 +93,49 @@ public class Settings implements Activity {
List<GPUDevice> gpus = GPU.listDevices(); List<GPUDevice> gpus = GPU.listDevices();
GridBagConstraints constraints = new GridBagConstraints(); GridBagConstraints constraints = new GridBagConstraints();
int columns = 4 + (gpus != null ? gpus.size() : 0);
int currentRow = 0; int currentRow = 0;
parent.addPadding(1, ++currentRow, columns - 2, 1);
++currentRow;
ImageIcon image = new ImageIcon(getClass().getResource("/title.png")); ImageIcon image = new ImageIcon(getClass().getResource("/title.png"));
constraints.fill = GridBagConstraints.CENTER;
JLabel labelImage = new JLabel(image); JLabel labelImage = new JLabel(image);
constraints.fill = GridBagConstraints.BOTH; constraints.gridwidth = 2;
constraints.weightx = 1.0; constraints.gridx = 0;
constraints.weighty = 3.0;
constraints.gridwidth = columns - 2;
constraints.gridx = 1;
constraints.gridy = currentRow; constraints.gridy = currentRow;
parent.getContentPane().add(labelImage, constraints); parent.getContentPane().add(labelImage, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1);
++currentRow; ++currentRow;
JLabel loginLabel = new JLabel("Login:"); // authentication
constraints.fill = GridBagConstraints.HORIZONTAL; JPanel authentification_panel = new JPanel(new GridLayout(2, 2));
constraints.weighty = 0.0; authentification_panel.setBorder(BorderFactory.createTitledBorder("Authentification"));
constraints.gridwidth = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(loginLabel, constraints);
JLabel loginLabel = new JLabel("Login :");
login = new JTextField(); login = new JTextField();
login.setText(parent.getConfiguration().login()); login.setText(parent.getConfiguration().login());
login.setColumns(20); login.setColumns(20);
login.addKeyListener(new CheckCanStart()); login.addKeyListener(new CheckCanStart());
constraints.gridwidth = columns - 3; JLabel passwordLabel = new JLabel("Password :");
constraints.gridx = 2;
parent.getContentPane().add(login, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1);
++currentRow;
JLabel passwordLabel = new JLabel("Password:");
constraints.weighty = 0.0;
constraints.gridwidth = 1;
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(passwordLabel, constraints);
password = new JPasswordField(); password = new JPasswordField();
password.setText(parent.getConfiguration().password()); password.setText(parent.getConfiguration().password());
password.setColumns(10); password.setColumns(10);
password.addKeyListener(new CheckCanStart()); password.addKeyListener(new CheckCanStart());
constraints.gridwidth = columns - 3;
constraints.gridx = 2;
parent.getContentPane().add(password, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1); authentification_panel.add(loginLabel);
++currentRow; authentification_panel.add(login);
JLabel proxyLabel = new JLabel("Proxy:"); authentification_panel.add(passwordLabel);
proxyLabel.setToolTipText("http://login:password@host:port"); authentification_panel.add(password);
constraints.gridwidth = 1;
constraints.gridx = 1; constraints.gridx = 0;
constraints.gridy = currentRow; constraints.gridy = currentRow;
parent.getContentPane().add(proxyLabel, constraints); constraints.fill = GridBagConstraints.HORIZONTAL;
parent.getContentPane().add(authentification_panel, constraints);
proxy = new JTextField();
proxy.setToolTipText("http://login:password@host:port");
proxy.setText(parent.getConfiguration().getProxy());
proxy.addKeyListener(new CheckCanStart());
constraints.gridwidth = columns - 3;
constraints.gridx = 2;
parent.getContentPane().add(proxy, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1);
++currentRow;
JLabel cacheLabel = new JLabel("Working directory:");
constraints.gridwidth = 1;
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(cacheLabel, constraints);
// directory
JPanel directory_panel = new JPanel(new GridLayout(1, 3));
directory_panel.setBorder(BorderFactory.createTitledBorder("Cache"));
JLabel cacheLabel = new JLabel("Working directory :");
directory_panel.add(cacheLabel);
String destination = DUMMY_CACHE_DIR; String destination = DUMMY_CACHE_DIR;
if (config.getUserSpecifiedACacheDir()) { if (config.getUserSpecifiedACacheDir()) {
destination = config.getStorageDir().getName(); destination = config.getStorageDir().getName();
@@ -193,17 +154,21 @@ public class Settings implements Activity {
openButton.addActionListener(new ChooseFileAction()); openButton.addActionListener(new ChooseFileAction());
cacheDirWrapper.add(openButton); cacheDirWrapper.add(openButton);
constraints.gridwidth = columns - 3; directory_panel.add(cacheDirWrapper);
constraints.gridx = 2;
parent.getContentPane().add(cacheDirWrapper, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1); currentRow++;
++currentRow; constraints.gridx = 0;
JLabel computeMethodLabel = new JLabel("Use:");
constraints.gridx = 1;
constraints.gridy = currentRow; constraints.gridy = currentRow;
parent.getContentPane().add(computeMethodLabel, constraints); constraints.gridwidth = 2;
parent.getContentPane().add(directory_panel, constraints);
// compute devices
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints compute_devices_constraints = new GridBagConstraints();
JPanel compute_devices_panel = new JPanel(gridbag);
compute_devices_panel.setBorder(BorderFactory.createTitledBorder("Compute devices"));
ComputeType method = config.getComputeMethod(); ComputeType method = config.getComputeMethod();
useCPU = new JCheckBox("CPU"); useCPU = new JCheckBox("CPU");
@@ -221,16 +186,18 @@ public class Settings implements Activity {
useCPU.setSelected(false); useCPU.setSelected(false);
gpuChecked = true; gpuChecked = true;
} }
useCPU.addActionListener(new CpuChangeAction()); useCPU.addActionListener(new CpuChangeAction());
constraints.gridwidth = Math.max(1, columns - (gpus != null ? gpus.size() : 0) - 3);
constraints.gridx = 2;
parent.getContentPane().add(useCPU, constraints);
constraints.gridwidth = 1; compute_devices_constraints.gridx = 1;
if (gpus != null) { compute_devices_constraints.gridy = 0;
for (int i=0; i < gpus.size(); i++) { compute_devices_constraints.fill = GridBagConstraints.BOTH;
GPUDevice gpu = gpus.get(i); compute_devices_constraints.weightx = 1.0;
compute_devices_constraints.weighty = 1.0;
gridbag.setConstraints(useCPU, compute_devices_constraints);
compute_devices_panel.add(useCPU);
for (GPUDevice gpu : gpus) {
JCheckBoxGPU gpuCheckBox = new JCheckBoxGPU(gpu); JCheckBoxGPU gpuCheckBox = new JCheckBoxGPU(gpu);
gpuCheckBox.setToolTipText(gpu.getCudaName()); gpuCheckBox.setToolTipText(gpu.getCudaName());
if (gpuChecked) { if (gpuChecked) {
@@ -240,14 +207,12 @@ public class Settings implements Activity {
} }
} }
gpuCheckBox.addActionListener(new GpuChangeAction()); gpuCheckBox.addActionListener(new GpuChangeAction());
constraints.gridx = i + 3;
parent.getContentPane().add(gpuCheckBox, constraints); compute_devices_constraints.gridy++;
gridbag.setConstraints(gpuCheckBox, compute_devices_constraints);
compute_devices_panel.add(gpuCheckBox);
useGPUs.add(gpuCheckBox); useGPUs.add(gpuCheckBox);
} }
}
parent.addPadding(1, ++currentRow, columns - 2, 1);
++currentRow;
CPU cpu = new CPU(); CPU cpu = new CPU();
if (cpu.cores() > 1) { // if only one core is available, no need to show the choice if (cpu.cores() > 1) { // if only one core is available, no need to show the choice
@@ -258,32 +223,48 @@ public class Settings implements Activity {
cpuCores.setPaintLabels(true); cpuCores.setPaintLabels(true);
cpuCores.setValue(config.getNbCores() != -1 ? config.getNbCores() : cpuCores.getMaximum()); cpuCores.setValue(config.getNbCores() != -1 ? config.getNbCores() : cpuCores.getMaximum());
JLabel coreLabel = new JLabel("CPU cores:"); JLabel coreLabel = new JLabel("CPU cores:");
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(coreLabel, constraints);
constraints.gridwidth = columns - 3;
constraints.gridx = 2;
parent.getContentPane().add(cpuCores, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1); compute_devices_constraints.weightx = 1.0 / gpus.size();
++currentRow; compute_devices_constraints.gridx = 0;
compute_devices_constraints.gridy++;
gridbag.setConstraints(coreLabel, compute_devices_constraints);
compute_devices_panel.add(coreLabel);
compute_devices_constraints.gridx = 1;
compute_devices_constraints.weightx = 1.0;
gridbag.setConstraints(cpuCores, compute_devices_constraints);
compute_devices_panel.add(cpuCores);
} }
customTileSize = new JCheckBox("Custom render tile size", config.getTileSize() != -1); currentRow++;
constraints.gridx = 2; constraints.gridx = 0;
constraints.gridy = currentRow; constraints.gridy = currentRow;
parent.getContentPane().add(customTileSize, constraints); constraints.gridwidth = 2;
parent.getContentPane().add(compute_devices_panel, constraints);
// other
JPanel advanced_panel = new JPanel(new GridLayout(3, 2));
advanced_panel.setBorder(BorderFactory.createTitledBorder("Advanced options"));
JLabel proxyLabel = new JLabel("Proxy :");
proxyLabel.setToolTipText("http://login:password@host:port");
proxy = new JTextField();
proxy.setToolTipText("http://login:password@host:port");
proxy.setText(parent.getConfiguration().getProxy());
proxy.addKeyListener(new CheckCanStart());
advanced_panel.add(proxyLabel);
advanced_panel.add(proxy);
JLabel customTileSizeLabel = new JLabel("Custom render tile size");
customTileSize = new JCheckBox("", config.getTileSize() != -1);
advanced_panel.add(customTileSizeLabel);
advanced_panel.add(customTileSize);
customTileSize.addActionListener(new TileSizeChange()); customTileSize.addActionListener(new TileSizeChange());
tileSizePadding = parent.addPaddingReturn(1, ++currentRow, columns - 2, 1);
parent.getContentPane().add(tileSizePadding, parent.addPaddingConstraints(1, ++currentRow, columns - 2, 1));
++currentRow;
tileSizeLabel = new JLabel("Tile Size:"); tileSizeLabel = new JLabel("Tile Size:");
constraints.gridwidth = columns - 3;
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(tileSizeLabel, constraints);
tileSizeValue = new JTextField(); tileSizeValue = new JTextField();
int fromConfig = parent.getConfiguration().getTileSize(); int fromConfig = parent.getConfiguration().getTileSize();
@@ -296,31 +277,32 @@ public class Settings implements Activity {
} }
} }
tileSizeValue.setText(Integer.toString(fromConfig)); tileSizeValue.setText(Integer.toString(fromConfig));
constraints.gridx = 2;
constraints.gridy = currentRow;
parent.getContentPane().add(tileSizeValue, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1);
++currentRow;
hideCustomTileSize(config.getTileSize() != -1, false); hideCustomTileSize(config.getTileSize() != -1, false);
saveFile = new JCheckBox("Save settings", true); advanced_panel.add(tileSizeLabel);
constraints.gridwidth = columns - 3; advanced_panel.add(tileSizeValue);
constraints.gridx = 2;
constraints.gridy = currentRow;
parent.getContentPane().add(saveFile, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1); currentRow++;
++currentRow; constraints.gridx = 0;
constraints.gridy = currentRow;
constraints.gridwidth = 2;
parent.getContentPane().add(advanced_panel, constraints);
// general settings
JPanel general_panel = new JPanel(new GridLayout(1, 2));
saveFile = new JCheckBox("Save settings", true);
general_panel.add(saveFile);
autoSignIn = new JCheckBox("Auto sign in", config.getAutoSignIn()); autoSignIn = new JCheckBox("Auto sign in", config.getAutoSignIn());
autoSignIn.addActionListener(new AutoSignInChangeAction()); autoSignIn.addActionListener(new AutoSignInChangeAction());
constraints.gridy = currentRow; general_panel.add(autoSignIn);
parent.getContentPane().add(autoSignIn, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1); currentRow++;
++currentRow; constraints.gridx = 0;
constraints.gridy = currentRow;
constraints.gridwidth = 2;
parent.getContentPane().add(general_panel, constraints);
String buttonText = "Start"; String buttonText = "Start";
if (parent.getClient() != null) { if (parent.getClient() != null) {
@@ -328,19 +310,15 @@ public class Settings implements Activity {
buttonText = "Save"; buttonText = "Save";
} }
} }
saveButton = new JButton(buttonText); saveButton = new JButton(buttonText);
checkDisplaySaveButton(); checkDisplaySaveButton();
saveButton.addActionListener(new SaveAction()); saveButton.addActionListener(new SaveAction());
constraints.gridwidth = columns - 2; currentRow++;
constraints.gridx = 1; constraints.gridwidth = 2;
constraints.gridx = 0;
constraints.gridy = currentRow; constraints.gridy = currentRow;
parent.getContentPane().add(saveButton, constraints); parent.getContentPane().add(saveButton, constraints);
parent.addPadding(1, ++currentRow, columns - 2, 1);
parent.addPadding(0, 0, 1, currentRow + 1);
parent.addPadding(columns - 1, 0, 1, currentRow + 1);
if (haveAutoStarted == false && config.getAutoSignIn() && checkDisplaySaveButton()) { if (haveAutoStarted == false && config.getAutoSignIn() && checkDisplaySaveButton()) {
// auto start // auto start
haveAutoStarted = true; haveAutoStarted = true;
@@ -349,7 +327,6 @@ public class Settings implements Activity {
} }
public void hideCustomTileSize(boolean hidden, boolean displayWarning) { public void hideCustomTileSize(boolean hidden, boolean displayWarning) {
tileSizePadding.setVisible(hidden);
tileSizeValue.setVisible(hidden); tileSizeValue.setVisible(hidden);
tileSizeLabel.setVisible(hidden); tileSizeLabel.setVisible(hidden);
if (customTileSize.isSelected() == true && displayWarning) { if (customTileSize.isSelected() == true && displayWarning) {

View File

@@ -16,24 +16,38 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
package com.sheepit.client.standalone.swing.activity; package com.sheepit.client.standalone.swing.activity;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.Date;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import com.sheepit.client.Client; import com.sheepit.client.Client;
import com.sheepit.client.Job; import com.sheepit.client.Job;
import com.sheepit.client.RenderProcess; import com.sheepit.client.RenderProcess;
import com.sheepit.client.Server; import com.sheepit.client.Server;
import com.sheepit.client.Stats;
import com.sheepit.client.Utils;
import com.sheepit.client.os.OS; import com.sheepit.client.os.OS;
import com.sheepit.client.standalone.GuiSwing; import com.sheepit.client.standalone.GuiSwing;
import com.sheepit.client.standalone.GuiSwing.ActivityType; import com.sheepit.client.standalone.GuiSwing.ActivityType;
@@ -48,139 +62,184 @@ public class Working implements Activity {
JLabel creditEarned; JLabel creditEarned;
JButton pauseButton; JButton pauseButton;
JButton exitAfterFrame; JButton exitAfterFrame;
JLabel current_project_name_value;
JLabel current_project_duration_value;
JLabel currrent_project_progression_value;
JLabel user_info_points_total_value;
JLabel waiting_projects_value;
JLabel connected_machines_value;
JLabel user_info_total_rendertime_this_session_value;
public Working(GuiSwing parent_) { public Working(GuiSwing parent_) {
parent = parent_; parent = parent_;
statusContent = new JLabel("Init"); statusContent = new JLabel("Init");
renderedFrameContent = new JLabel("0"); renderedFrameContent = new JLabel("");
remainingFrameContent = new JLabel("0"); remainingFrameContent = new JLabel("");
creditEarned = new JLabel(""); creditEarned = new JLabel("");
current_project_name_value = new JLabel("");
lastRender = new JLabel(); current_project_duration_value = new JLabel("");
currrent_project_progression_value = new JLabel("");
user_info_points_total_value = new JLabel("");
waiting_projects_value = new JLabel("");
connected_machines_value = new JLabel("");
user_info_total_rendertime_this_session_value = new JLabel("");
lastRender = new JLabel("");
} }
@Override @Override
public void show() { public void show() {
GridBagConstraints constraints = new GridBagConstraints(); // current project
int currentRow = 0; JPanel current_project_panel = new JPanel(new SpringLayout());
current_project_panel.setBorder(BorderFactory.createTitledBorder("Project"));
parent.addPadding(1, ++currentRow, 2, 1); JLabel current_project_status = new JLabel("Status : ", JLabel.TRAILING);
++currentRow; JLabel current_project_name = new JLabel("Name : ", JLabel.TRAILING);
JLabel current_project_duration = new JLabel("Rendering for : ", JLabel.TRAILING);
JLabel current_project_progression = new JLabel("Remaining : ", JLabel.TRAILING);
current_project_panel.add(current_project_status);
current_project_panel.add(statusContent);
current_project_panel.add(current_project_name);
current_project_panel.add(current_project_name_value);
current_project_panel.add(current_project_duration);
current_project_panel.add(current_project_duration_value);
current_project_panel.add(current_project_progression);
current_project_panel.add(currrent_project_progression_value);
// user info
JPanel session_info_panel = new JPanel(new SpringLayout());
session_info_panel.setBorder(BorderFactory.createTitledBorder("Session infos"));
JLabel user_info_credits_this_session = new JLabel("Points earned : ", JLabel.TRAILING);
JLabel user_info_total_rendertime_this_session = new JLabel("Duration : ", JLabel.TRAILING);
JLabel user_info_rendered_frame_this_session = new JLabel("Rendered frames : ", JLabel.TRAILING);
session_info_panel.add(user_info_credits_this_session);
session_info_panel.add(creditEarned);
session_info_panel.add(user_info_rendered_frame_this_session);
session_info_panel.add(renderedFrameContent);
session_info_panel.add(user_info_total_rendertime_this_session);
session_info_panel.add(user_info_total_rendertime_this_session_value);
// global stats
JPanel global_stats_panel = new JPanel(new SpringLayout());
global_stats_panel.setBorder(BorderFactory.createTitledBorder("Global stats"));
JLabel global_stats_machine_connected = new JLabel("Machine connected : ", JLabel.TRAILING);
JLabel global_stats_remaining_frame = new JLabel("Remaining frames : ", JLabel.TRAILING);
JLabel global_stats_waiting_project = new JLabel("Waiting project : ", JLabel.TRAILING);
JLabel global_stats_user_points = new JLabel("User points : ", JLabel.TRAILING);
global_stats_panel.add(global_stats_waiting_project);
global_stats_panel.add(waiting_projects_value);
global_stats_panel.add(global_stats_machine_connected);
global_stats_panel.add(connected_machines_value);
global_stats_panel.add(global_stats_remaining_frame);
global_stats_panel.add(remainingFrameContent);
global_stats_panel.add(global_stats_user_points);
global_stats_panel.add(user_info_points_total_value);
// last frame
JPanel last_frame_panel = new JPanel();
last_frame_panel.setBorder(BorderFactory.createTitledBorder("Last rendered frame"));
lastRender.setIcon(new ImageIcon(new BufferedImage(200, 120, BufferedImage.TYPE_INT_ARGB)));
last_frame_panel.add(lastRender);
ImageIcon image = new ImageIcon(getClass().getResource("/title.png")); ImageIcon image = new ImageIcon(getClass().getResource("/title.png"));
JLabel labelImage = new JLabel(image); JLabel labelImage = new JLabel(image);
constraints.fill = GridBagConstraints.BOTH; labelImage.setAlignmentX(Component.CENTER_ALIGNMENT);
constraints.weightx = 1.0; parent.getContentPane().add(labelImage);
constraints.weighty = 3.0;
constraints.gridwidth = 2;
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(labelImage, constraints);
parent.addPadding(1, ++currentRow, 2, 1); JPanel buttonsPanel = new JPanel(new GridLayout(2, 2));
++currentRow;
JLabel statusLabel = new JLabel("Status:");
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weighty = 0.0;
constraints.gridwidth = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(statusLabel, constraints);
statusContent.setVerticalAlignment(JLabel.TOP);
statusContent.setVerticalTextPosition(JLabel.TOP);
constraints.gridx = 2;
parent.getContentPane().add(statusContent, constraints);
parent.addPadding(1, ++currentRow, 2, 1);
++currentRow;
JLabel creditsEarnedLabel = new JLabel("Credits earned:");
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(creditsEarnedLabel, constraints);
constraints.gridx = 2;
parent.getContentPane().add(creditEarned, constraints);
parent.addPadding(1, ++currentRow, 2, 1);
++currentRow;
JLabel renderedFrameLabel = new JLabel("Rendered frames:");
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(renderedFrameLabel, constraints);
constraints.gridx = 2;
parent.getContentPane().add(renderedFrameContent, constraints);
parent.addPadding(1, ++currentRow, 2, 1);
++currentRow;
JLabel remainingFrameLabel = new JLabel("Remaining frames:");
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(remainingFrameLabel, constraints);
constraints.gridx = 2;
parent.getContentPane().add(remainingFrameContent, constraints);
parent.addPadding(1, ++currentRow, 2, 1);
++currentRow;
JLabel lastRenderedFrameLabel = new JLabel("Last rendered frame:");
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(lastRenderedFrameLabel, constraints);
constraints.gridx = 2;
parent.getContentPane().add(lastRender, constraints);
parent.addPadding(1, ++currentRow, 2, 1);
++currentRow;
JButton settingsButton = new JButton("Settings"); JButton settingsButton = new JButton("Settings");
settingsButton.addActionListener(new SettingsAction()); settingsButton.addActionListener(new SettingsAction());
constraints.gridx = 1;
constraints.gridy = currentRow;
parent.getContentPane().add(settingsButton, constraints);
pauseButton = new JButton("Pause"); pauseButton = new JButton("Pause");
pauseButton.addActionListener(new PauseAction()); pauseButton.addActionListener(new PauseAction());
constraints.gridx = 2;
constraints.gridy = currentRow;
parent.getContentPane().add(pauseButton, constraints);
++currentRow;
JButton blockJob = new JButton("Block this project"); JButton blockJob = new JButton("Block this project");
constraints.gridx = 1;
constraints.gridy = currentRow;
blockJob.addActionListener(new blockJobAction()); blockJob.addActionListener(new blockJobAction());
parent.getContentPane().add(blockJob, constraints);
exitAfterFrame = new JButton("Exit after this frame"); exitAfterFrame = new JButton("Exit after this frame");
constraints.gridx = 2;
constraints.gridy = currentRow;
exitAfterFrame.addActionListener(new ExitAfterAction()); exitAfterFrame.addActionListener(new ExitAfterAction());
parent.getContentPane().add(exitAfterFrame, constraints);
parent.addPadding(1, ++currentRow, 2, 1); buttonsPanel.add(settingsButton);
parent.addPadding(0, 0, 1, currentRow + 1); buttonsPanel.add(pauseButton);
parent.addPadding(3, 0, 1, currentRow + 1); buttonsPanel.add(blockJob);
buttonsPanel.add(exitAfterFrame);
parent.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints global_constraints = new GridBagConstraints();
global_constraints.fill = GridBagConstraints.HORIZONTAL;
global_constraints.weightx = 1;
global_constraints.gridx = 0;
parent.getContentPane().add(current_project_panel, global_constraints);
parent.getContentPane().add(global_stats_panel, global_constraints);
parent.getContentPane().add(session_info_panel, global_constraints);
parent.getContentPane().add(last_frame_panel, global_constraints);
parent.getContentPane().add(buttonsPanel, global_constraints);
Spring widthLeftColumn = getBestWidth(current_project_panel, 4, 2);
widthLeftColumn = Spring.max(widthLeftColumn, getBestWidth(global_stats_panel, 4, 2));
widthLeftColumn = Spring.max(widthLeftColumn, getBestWidth(session_info_panel, 3, 2));
alignPanel(current_project_panel, 4, 2, widthLeftColumn);
alignPanel(global_stats_panel, 4, 2, widthLeftColumn);
alignPanel(session_info_panel, 3, 2, widthLeftColumn);
} }
public void setStatus(String msg_) { public void setStatus(String msg_) {
statusContent.setText("<html>" + msg_ + "</html>"); // html for the text wrapping statusContent.setText("<html>" + msg_ + "</html>");
} }
public void setRemainingFrame(int n) { public void setRenderingProjectName(String msg_) {
remainingFrameContent.setText(String.valueOf(n)); current_project_name_value.setText("<html>" + (msg_.length() > 26 ? msg_.substring(0, 26) : msg_) + "</html>");
}
public void setRemainingTime(String time_) {
currrent_project_progression_value.setText("<html>" + time_ + "</html>");
}
public void setRenderingTime(String time_) {
current_project_duration_value.setText("<html>" + time_ + "</html>");
}
public void displayStats(Stats stats) {
DecimalFormat df = new DecimalFormat("##,##,##,##,##,##,##0");
remainingFrameContent.setText(df.format(stats.getRemainingFrame()));
creditEarned.setText(df.format(stats.getCreditsEarnedDuringSession()));
user_info_points_total_value.setText(df.format(stats.getCreditsEarned()));
waiting_projects_value.setText(df.format(stats.getWaitingProject()));
connected_machines_value.setText(df.format(stats.getConnectedMachine()));
updateTime();
}
public void updateTime() {
if (this.parent.getClient().getStartTime() != 0) {
user_info_total_rendertime_this_session_value.setText(Utils.humanDuration(new Date((new Date().getTime() - this.parent.getClient().getStartTime()))));
}
Job job = this.parent.getClient().getRenderingJob();
if (job != null && job.getProcessRender() != null && job.getProcessRender().getStartTime() > 0) {
current_project_duration_value.setText("<html>" + Utils.humanDuration(new Date((new Date().getTime() - job.getProcessRender().getStartTime()))) + "</html>");
}
else {
current_project_duration_value.setText("");
}
} }
public void setRenderedFrame(int n) { public void setRenderedFrame(int n) {
renderedFrameContent.setText(String.valueOf(n)); renderedFrameContent.setText(String.valueOf(n));
showCreditEarned();
showLastRender(); showLastRender();
} }
@@ -208,17 +267,62 @@ public class Working implements Activity {
} }
public void showCreditEarned() { private void alignPanel(Container parent, int rows, int cols, Spring width) {
Client client = parent.getClient(); SpringLayout layout;
if (client != null) { try {
Server server = client.getServer(); layout = (SpringLayout) parent.getLayout();
if (server != null) { }
String data = server.getCreditEarnedOnCurrentSession(); catch (ClassCastException exc) {
if (data != null) { System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
creditEarned.setText(data); return;
}
Spring x = Spring.constant(0);
for (int c = 0; c < cols; c++) {
for (int r = 0; r < rows; r++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, width);
}
Spring y = Spring.constant(0);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
}
for (int c = 0; c < cols; c++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, height);
}
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
private Spring getBestWidth(Container parent, int rows, int cols) {
Spring x = Spring.constant(0);
Spring width = Spring.constant(0);
for (int c = 0; c < cols; c++) {
for (int r = 0; r < rows; r++) {
width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
} }
} }
return width;
} }
private SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
} }
class PauseAction implements ActionListener { class PauseAction implements ActionListener {