Author: jflesch
Date: 2007-07-09 14:24:22 +0000 (Mon, 09 Jul 2007)
New Revision: 14002

Modified:
   trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
   trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
Log:
#1504 : Make the peerMonitor panel escamotable

Modified: trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java   2007-07-09 10:42:30 UTC 
(rev 14001)
+++ trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java   2007-07-09 14:24:22 UTC 
(rev 14002)
@@ -6,15 +6,20 @@
 import java.util.HashMap;

 import java.awt.BorderLayout;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;

+import javax.swing.JButton;
+
 import thaw.core.I18n;
 import thaw.core.Core;
+import thaw.core.Logger;

 import thaw.plugins.peerMonitor.*;
 import thaw.fcp.*;


-public class PeerMonitor implements thaw.core.Plugin, Observer
+public class PeerMonitor implements thaw.core.Plugin, Observer, ActionListener
 {
        public final static int DEFAULT_REFRESH_RATE = 10; /* in sec */

@@ -27,6 +32,8 @@

        private boolean advancedMode;

+       private JButton unfoldButton;
+       private boolean folded = false;

        public PeerMonitor() {

@@ -102,12 +109,14 @@

                advancedMode = 
Boolean.valueOf(core.getConfig().getValue("advancedMode")).booleanValue();

+               unfoldButton = new JButton("<");
+               unfoldButton.addActionListener(this);

                peerPanel = new PeerMonitorPanel(this, core.getQueueManager(), 
core.getConfig(), core.getMainWindow());

                peerPanel.addObserver(this);
+               peerPanel.getFoldButton().addActionListener(this);

-
                core.getMainWindow().addComponent(peerPanel.getPeerListPanel(),
                                                  BorderLayout.EAST);

@@ -116,13 +125,24 @@
                Thread th = new Thread(new DisplayRefresher());
                th.start();

+               if (core.getConfig().getValue("peerMonitorFolded") != null) {
+                       boolean f = (new 
Boolean(core.getConfig().getValue("peerMonitorFolded"))).booleanValue();
+                       if (f) foldPanel();
+               }
+
                return true;
        }


        public boolean stop() {
                hideTab();
-               
core.getMainWindow().removeComponent(peerPanel.getPeerListPanel());
+               if (!folded)
+                       
core.getMainWindow().removeComponent(peerPanel.getPeerListPanel());
+               else
+                       core.getMainWindow().removeComponent(unfoldButton);
+
+               core.getConfig().setValue("peerMonitorFolded", 
Boolean.toString(folded));
+
                running = false;
                return false;
        }
@@ -160,4 +180,32 @@
                        tabVisible = false;
                }
        }
+
+
+       public void foldPanel() {
+               Logger.info(this, "Folding peer monitor panel");
+               
core.getMainWindow().removeComponent(peerPanel.getPeerListPanel());
+               core.getMainWindow().getMainFrame().validate();
+               core.getMainWindow().addComponent(unfoldButton,
+                                                 BorderLayout.EAST);
+               core.getMainWindow().getMainFrame().validate();
+               folded = true;
+       }
+
+       public void unfoldPanel() {
+               Logger.info(this, "Unfolding peer monitor panel");
+               core.getMainWindow().removeComponent(unfoldButton);
+               core.getMainWindow().getMainFrame().validate();
+               core.getMainWindow().addComponent(peerPanel.getPeerListPanel(),
+                                                 BorderLayout.EAST);
+               core.getMainWindow().getMainFrame().validate();
+               folded = false;
+       }
+
+       public void actionPerformed(ActionEvent e) {
+               if (e.getSource() == peerPanel.getFoldButton())
+                       foldPanel();
+               else if (e.getSource() == unfoldButton)
+                       unfoldPanel();
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java  
2007-07-09 10:42:30 UTC (rev 14001)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java  
2007-07-09 14:24:22 UTC (rev 14002)
@@ -112,6 +112,9 @@

        private ToolbarModifier toolbarModifier;

+       private JButton foldButton;
+
+
        public PeerMonitorPanel(PeerMonitor peerMonitor,
                                FCPQueueManager queueManager,
                                Config config,
@@ -143,7 +146,11 @@
                JLabel peerListLabel = new 
JLabel(I18n.getMessage("thaw.plugin.peerMonitor.peerList"));
                peerListLabel.setIcon(IconBox.peers);

+               /* We are not the listener */
+               /* te listener will be thaw.plugins.PeerMonitor */
+               foldButton = new JButton(">");

+
                nodeMemBar = new JProgressBar(0, 100);
                thawMemBar = new JProgressBar(0, 100);
                nodeMemBar.setStringPainted(true);
@@ -179,8 +186,11 @@
                southSouth.add(littleButtonPanel, BorderLayout.WEST);


+               JPanel titlePanel = new JPanel(new BorderLayout(5, 5));
+               titlePanel.add(peerListLabel, BorderLayout.CENTER);
+               titlePanel.add(foldButton, BorderLayout.EAST);

-               peerPanel.add(peerListLabel, BorderLayout.NORTH);
+               peerPanel.add(titlePanel, BorderLayout.NORTH);
                peerPanel.add(new JScrollPane(peerList), BorderLayout.CENTER);

                JPanel memPanel = new JPanel(new GridLayout(3, 1));
@@ -273,6 +283,11 @@
        }


+       public JButton getFoldButton() {
+               return foldButton;
+       }
+
+
        public void setMemBar(long used, long max) {
                int pourcent;



Reply via email to