From b21e5c5a2c2e82eca82a0514141b1ab7acc9778c Mon Sep 17 00:00:00 2001 From: Luis Uguina Date: Thu, 29 Oct 2020 22:06:00 +1100 Subject: [PATCH] feat: make stats and last rendered frame panels collapsible The visual footprint of the client is quite big (520x800 px). This PR allows the use to collapse/expand any of the Global stats, Session infos and Last uploaded frame panels to reduce the vertical visual footprint. Fixed the wrong size detection at client start issue found by Clou. --- .../standalone/swing/activity/Activity.java | 2 ++ .../standalone/swing/activity/Settings.java | 12 ++++---- .../standalone/swing/activity/Working.java | 30 +++++++++++-------- .../swing/components/CollapsibleJPanel.java | 9 +++++- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/com/sheepit/client/standalone/swing/activity/Activity.java b/src/com/sheepit/client/standalone/swing/activity/Activity.java index 15a996f..02a495c 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Activity.java +++ b/src/com/sheepit/client/standalone/swing/activity/Activity.java @@ -23,4 +23,6 @@ public interface Activity { public void show(); + public void resizeWindow(); + } diff --git a/src/com/sheepit/client/standalone/swing/activity/Settings.java b/src/com/sheepit/client/standalone/swing/activity/Settings.java index 661a1db..2895e08 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/com/sheepit/client/standalone/swing/activity/Settings.java @@ -159,7 +159,7 @@ public class Settings implements Activity { 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:"); @@ -185,7 +185,7 @@ public class Settings implements Activity { 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(); @@ -215,7 +215,7 @@ public class Settings implements Activity { 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); @@ -249,7 +249,7 @@ public class Settings implements Activity { // 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")); @@ -453,7 +453,7 @@ public class Settings implements Activity { 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"); @@ -542,6 +542,8 @@ public class Settings implements Activity { } } + public void resizeWindow() {} + private void buildRenderBucketSizeSlider(int maxRenderbucketSize, int selectedBucketSize) { Hashtable renderbucketSizeTable = new Hashtable(); diff --git a/src/com/sheepit/client/standalone/swing/activity/Working.java b/src/com/sheepit/client/standalone/swing/activity/Working.java index 4d62977..8dbef68 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Working.java +++ b/src/com/sheepit/client/standalone/swing/activity/Working.java @@ -54,9 +54,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; @@ -97,7 +102,7 @@ public class Working implements Activity { 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"); @@ -139,7 +144,7 @@ public class Working implements Activity { } // 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); @@ -164,7 +169,7 @@ public class Working implements Activity { 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); @@ -197,7 +202,7 @@ public class Working implements Activity { 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); @@ -218,7 +223,7 @@ public class Working implements Activity { 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))); @@ -270,17 +275,18 @@ public class Working implements Activity { 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); } + 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_) { setStatus(msg_, false); } diff --git a/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java b/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java index facd97f..27f1b7d 100644 --- a/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java +++ b/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java @@ -28,6 +28,8 @@ import javax.swing.JPanel; import javax.swing.border.Border; import javax.swing.border.TitledBorder; +import com.sheepit.client.standalone.swing.activity.Activity; + public class CollapsibleJPanel extends JPanel { private boolean isCompnentsVisible = true; @@ -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) { @@ -134,6 +138,9 @@ public class CollapsibleJPanel extends JPanel { 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) {