Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Feature: make stats and last rendered frame panels collapsible
Browse files Browse the repository at this point in the history
  • Loading branch information
luguina committed Sep 12, 2020
1 parent 17d45f6 commit edae180
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface Activity {

public void show();

public void resizeWindow();

}
12 changes: 7 additions & 5 deletions src/com/sheepit/client/standalone/swing/activity/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Settings(GuiSwing parent_) {
currentRow++;

// authentication
CollapsibleJPanel authentication_panel = new CollapsibleJPanel(new GridLayout(2, 2));
CollapsibleJPanel authentication_panel = new CollapsibleJPanel(new GridLayout(2, 2), this);
authentication_panel.setBorder(BorderFactory.createTitledBorder("Authentication"));

JLabel loginLabel = new JLabel("Username:");
Expand All @@ -185,7 +185,7 @@ public Settings(GuiSwing parent_) {
parent.getContentPane().add(authentication_panel, constraints);

// Theme selection panel
CollapsibleJPanel themePanel = new CollapsibleJPanel(new GridLayout(1, 3));
CollapsibleJPanel themePanel = new CollapsibleJPanel(new GridLayout(1, 3), this);
themePanel.setBorder(BorderFactory.createTitledBorder("Theme"));

themeOptionsGroup = new ButtonGroup();
Expand Down Expand Up @@ -215,7 +215,7 @@ public Settings(GuiSwing parent_) {
parent.getContentPane().add(themePanel, constraints);

// directory
CollapsibleJPanel directory_panel = new CollapsibleJPanel(new GridLayout(1, 3));
CollapsibleJPanel directory_panel = new CollapsibleJPanel(new GridLayout(1, 3), this);
directory_panel.setBorder(BorderFactory.createTitledBorder("Cache"));
JLabel cacheLabel = new JLabel("Working directory:");
directory_panel.add(cacheLabel);
Expand Down Expand Up @@ -249,7 +249,7 @@ public Settings(GuiSwing parent_) {
// compute devices
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints compute_devices_constraints = new GridBagConstraints();
CollapsibleJPanel compute_devices_panel = new CollapsibleJPanel(gridbag);
CollapsibleJPanel compute_devices_panel = new CollapsibleJPanel(gridbag, this);

compute_devices_panel.setBorder(BorderFactory.createTitledBorder("Compute devices"));

Expand Down Expand Up @@ -453,7 +453,7 @@ else if (config.getGPUDevice().getType().equals("OPENCL")) {
parent.getContentPane().add(compute_devices_panel, constraints);

// other
CollapsibleJPanel advanced_panel = new CollapsibleJPanel(new GridLayout(4, 2));
CollapsibleJPanel advanced_panel = new CollapsibleJPanel(new GridLayout(4, 2), this);
advanced_panel.setBorder(BorderFactory.createTitledBorder("Advanced options"));

JLabel useSysTrayLabel = new JLabel("Minimize to SysTray");
Expand Down Expand Up @@ -542,6 +542,8 @@ else if (config.getGPUDevice().getType().equals("OPENCL")) {
}
}

public void resizeWindow() { }

private void buildRenderBucketSizeSlider(int maxRenderbucketSize, int selectedBucketSize) {
Hashtable<Integer, JLabel> renderbucketSizeTable = new Hashtable<Integer, JLabel>();

Expand Down
32 changes: 19 additions & 13 deletions src/com/sheepit/client/standalone/swing/activity/Working.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@
import com.sheepit.client.Utils;
import com.sheepit.client.standalone.GuiSwing;
import com.sheepit.client.standalone.GuiSwing.ActivityType;
import com.sheepit.client.standalone.swing.components.CollapsibleJPanel;

public class Working implements Activity {
private GuiSwing parent;

private CollapsibleJPanel session_info_panel;
private CollapsibleJPanel global_stats_panel;
private CollapsibleJPanel last_frame_panel;
private JLabel statusContent;
private String previousStatus;
private JLabel renderedFrameContent;
Expand Down Expand Up @@ -97,7 +101,7 @@ public Working(GuiSwing parent_) {
waiting_projects_value = new JLabel("");
connected_machines_value = new JLabel("");
user_info_total_rendertime_this_session_value = new JLabel("");
lastRenderTime = new JLabel("");
lastRenderTime = new JLabel(" "); // Insert a space to ensure the component reserves the space in the screen (for the window size calculation)
lastRender = new JLabel("");
userInfoQueuedUploadsAndSizeValue = new JLabel("0");
sessionDownloadsStatsValue = new JLabel("0KB");
Expand Down Expand Up @@ -139,7 +143,7 @@ public Working(GuiSwing parent_) {
}

// current project
JPanel current_project_panel = new JPanel(new SpringLayout());
JPanel current_project_panel = new JPanel(new GridLayout(5, 2));
current_project_panel.setBorder(BorderFactory.createTitledBorder("Project"));

JLabel current_project_status = new JLabel("Status: ", JLabel.TRAILING);
Expand All @@ -164,7 +168,7 @@ public Working(GuiSwing parent_) {
current_project_panel.add(current_project_compute_method_value);

// user info
JPanel session_info_panel = new JPanel(new SpringLayout());
session_info_panel = new CollapsibleJPanel(new GridLayout(7, 2), this);
session_info_panel.setBorder(BorderFactory.createTitledBorder("Session infos"));

JLabel user_info_credits_this_session = new JLabel("Points earned: ", JLabel.TRAILING);
Expand Down Expand Up @@ -197,7 +201,7 @@ public Working(GuiSwing parent_) {
session_info_panel.add(user_info_total_rendertime_this_session_value);

// global stats
JPanel global_stats_panel = new JPanel(new SpringLayout());
global_stats_panel = new CollapsibleJPanel(new GridLayout(4, 2), this);
global_stats_panel.setBorder(BorderFactory.createTitledBorder("Global stats"));

JLabel global_stats_machine_connected = new JLabel("Machines connected: ", JLabel.TRAILING);
Expand All @@ -218,9 +222,10 @@ public Working(GuiSwing parent_) {
global_stats_panel.add(user_info_points_total_value);

// last frame
JPanel last_frame_panel = new JPanel();
last_frame_panel = new CollapsibleJPanel(new GridLayout(2, 2), this);
last_frame_panel.setLayout(new BoxLayout(last_frame_panel, BoxLayout.Y_AXIS));
last_frame_panel.setBorder(BorderFactory.createTitledBorder("Last uploaded frame"));

lastRender.setIcon(new ImageIcon(new BufferedImage(200, 120, BufferedImage.TYPE_INT_ARGB)));
lastRender.setAlignmentX(Component.CENTER_ALIGNMENT);
lastRenderTime.setAlignmentX(Component.CENTER_ALIGNMENT);
Expand Down Expand Up @@ -270,15 +275,16 @@ public Working(GuiSwing parent_) {
parent.getContentPane().add(new JLabel(" "), global_constraints); // Add a separator between last panel and buttons
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, 4, 2));
alignPanel(current_project_panel, 5, 2, widthLeftColumn);
alignPanel(global_stats_panel, 4, 2, widthLeftColumn);
alignPanel(session_info_panel, 7, 2, widthLeftColumn);

// Set the proper size for the Working (if coming from Settings screen, the window size will be too big for the content!)
parent.setSize(520, 820);
resizeWindow();
}

public void resizeWindow() {
parent.revalidate();
parent.repaint();

// Calculate the proper size based on the status of the panels (opened/collapsed)
parent.setSize(520, (int) (session_info_panel.getHeight() + global_stats_panel.getHeight() + last_frame_panel.getHeight()) + 400);
}

public void setStatus(String msg_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.sheepit.client.standalone.swing.components;

import com.sheepit.client.standalone.swing.activity.Activity;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.LayoutManager;
Expand All @@ -35,10 +37,12 @@ public class CollapsibleJPanel extends JPanel {
private String borderTitle = "";
private int COLLAPSED_HEIGHT = 22;
private boolean[] originalVisibilty;
private Activity parent;

public CollapsibleJPanel(LayoutManager layoutManager) {
public CollapsibleJPanel(LayoutManager layoutManager, Activity parent) {
setLayout(layoutManager);
addMouseListener(new onClickHandler());
this.parent = parent;
}

public void setCollapsed(boolean aFlag) {
Expand Down Expand Up @@ -134,6 +138,9 @@ public class onClickHandler implements MouseListener {
if (e.getPoint().y < COLLAPSED_HEIGHT) { // Only if click is on top of panel
((CollapsibleJPanel) e.getComponent()).toggleCollapsed();
}

// Recalculate the proper window size
parent.resizeWindow();
}

@Override public void mouseEntered(MouseEvent e) {
Expand Down

0 comments on commit edae180

Please sign in to comment.