diff --git a/src/com/sheepit/client/standalone/swing/activity/Activity.java b/src/com/sheepit/client/standalone/swing/activity/Activity.java index 15a996f2..02a495ce 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 661a1db3..59fabfd9 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 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:"); @@ -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(); @@ -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); @@ -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")); @@ -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"); @@ -542,6 +542,8 @@ else if (config.getGPUDevice().getType().equals("OPENCL")) { } } + 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 64dc3672..0e86ad92 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Working.java +++ b/src/com/sheepit/client/standalone/swing/activity/Working.java @@ -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; @@ -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"); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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_) { diff --git a/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java b/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java index facd97f5..3bbf20c9 100644 --- a/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java +++ b/src/com/sheepit/client/standalone/swing/components/CollapsibleJPanel.java @@ -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; @@ -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 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) {