Author: jflesch
Date: 2006-11-01 17:51:20 +0000 (Wed, 01 Nov 2006)
New Revision: 10777

Added:
   trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java
Modified:
   trunk/apps/Thaw/src/thaw/core/MainWindow.java
   trunk/apps/Thaw/src/thaw/core/PluginManager.java
   trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java
   trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java
   trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java
   trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
Log:
Remove 2 tabs and add 2 buttons in the Toolbar

Modified: trunk/apps/Thaw/src/thaw/core/MainWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/MainWindow.java       2006-11-01 17:13:09 UTC 
(rev 10776)
+++ trunk/apps/Thaw/src/thaw/core/MainWindow.java       2006-11-01 17:51:20 UTC 
(rev 10777)
@@ -17,7 +17,10 @@
 import javax.swing.Icon;
 import java.awt.Font;

+import java.util.Vector;
+import java.util.Iterator;

+
 /**
  * MainWindow. This class create the main window.
  *
@@ -69,6 +72,7 @@

        private Core core = null; /* core is called back when exit() */

+       private Object lastToolBarModifier = null;

        /**
         * Creates a new <code>MainWindow</code> instance, and so a new Swing 
window.
@@ -122,8 +126,6 @@
                this.menuBar.add(this.helpMenu);

                // TOOLBAR
-               this.toolBar = new 
JToolBar(I18n.getMessage("thaw.toolbar.title"));
-
                this.connectButton = new JButton(IconBox.connectAction);
                
this.connectButton.setToolTipText(I18n.getMessage("thaw.toolbar.button.connect"));
                this.disconnectButton = new JButton(IconBox.disconnectAction);
@@ -135,21 +137,12 @@
                this.quitButton = new JButton(IconBox.quitAction);
                
this.quitButton.setToolTipText(I18n.getMessage("thaw.toolbar.button.quit"));

-
                this.connectButton.addActionListener(this);
                this.disconnectButton.addActionListener(this);
                this.settingsButton.addActionListener(this);
                this.quitButton.addActionListener(this);

-               this.toolBar.add(this.connectButton);
-               this.toolBar.add(this.disconnectButton);
-               this.toolBar.addSeparator();
-               this.toolBar.add(this.settingsButton);
-               this.toolBar.addSeparator();
-               this.toolBar.add(this.quitButton);

-               this.updateToolBar();
-
                // TABBED PANE

                this.tabbedPane = new JTabbedPane();
@@ -164,7 +157,8 @@
                this.mainWindow.getContentPane().setLayout(new BorderLayout());

                this.mainWindow.setJMenuBar(this.menuBar);
-               this.mainWindow.getContentPane().add(this.toolBar, 
BorderLayout.NORTH);
+
+               /* Toolbar adding: */ changeButtonsInTheToolbar(this, null);
                this.mainWindow.getContentPane().add(this.tabbedPane, 
BorderLayout.CENTER);
                this.mainWindow.getContentPane().add(this.statusBar, 
BorderLayout.SOUTH);

@@ -199,6 +193,54 @@
        }

        /**
+        * @param modifier Correspond to the caller object: it's a security to 
avoid that a modifier wipe out the buttons from another one
+        */
+       public void changeButtonsInTheToolbar(Object modifier, Vector 
newButtons) {
+               JToolBar newToolBar;
+
+               Logger.debug(this, "Called by "+modifier.getClass().getName());
+
+               if (lastToolBarModifier == null || newButtons != null || 
lastToolBarModifier == modifier) {
+                       lastToolBarModifier = modifier;
+               } else {
+                       /* Only the modifer who added the buttons can remove 
them */
+                       return;
+               }
+
+               newToolBar = new 
JToolBar(I18n.getMessage("thaw.toolbar.title"));
+
+               newToolBar.add(this.connectButton);
+               newToolBar.add(this.disconnectButton);
+               newToolBar.addSeparator();
+               newToolBar.add(this.settingsButton);
+               newToolBar.addSeparator();
+
+               if (newButtons != null) {
+                       newToolBar.addSeparator();
+                       for (Iterator it = newButtons.iterator();
+                            it.hasNext();) {
+                               JButton button = (JButton)it.next();
+                               if (button != null)
+                                       newToolBar.add(button);
+                               else
+                                       newToolBar.addSeparator();
+                       }
+                       newToolBar.addSeparator();
+                       newToolBar.addSeparator();
+               }
+
+               newToolBar.add(this.quitButton);
+               newToolBar.setFloatable(false);
+
+               if (this.toolBar != null)
+                       this.mainWindow.getContentPane().remove(this.toolBar);
+               this.toolBar = newToolBar;
+               this.mainWindow.getContentPane().add(this.toolBar, 
BorderLayout.NORTH);
+               this.updateToolBar();
+       }
+
+
+       /**
         * Used to add a tab in the main window.
         * In the future, even if the interface, this function should remain 
available.
         */

Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/PluginManager.java    2006-11-01 17:13:09 UTC 
(rev 10776)
+++ trunk/apps/Thaw/src/thaw/core/PluginManager.java    2006-11-01 17:51:20 UTC 
(rev 10777)
@@ -9,8 +9,8 @@
  */
 public class PluginManager {
        private final static String[] defaultPlugins = 
{"thaw.plugins.QueueWatcher",
+                                                       
"thaw.plugins.FetchPlugin",
                                                        
"thaw.plugins.InsertPlugin",
-                                                       
"thaw.plugins.FetchPlugin",
                                                        
"thaw.plugins.StatusBar",
                                                        
"thaw.plugins.IndexBrowser",
                                                        
"thaw.plugins.IndexEditor"};

Modified: trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java   2006-11-01 17:13:09 UTC 
(rev 10776)
+++ trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java   2006-11-01 17:51:20 UTC 
(rev 10777)
@@ -1,16 +1,27 @@
 package thaw.plugins;

+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import javax.swing.JFrame;
+import javax.swing.JButton;
+import javax.swing.WindowConstants;
+
 import thaw.core.*;
 import thaw.plugins.fetchPlugin.*;

 import thaw.fcp.*;

-public class FetchPlugin implements thaw.core.Plugin {
+public class FetchPlugin implements thaw.core.Plugin, ActionListener {
        private Core core;

        private FetchPanel fetchPanel = null;
-       

+       private JFrame fetchFrame = null;
+       private JButton buttonInToolBar = null;
+
+       private QueueWatcher queueWatcher;
+
        public FetchPlugin() {

        }
@@ -18,15 +29,44 @@

        public boolean run(Core core) {
                this.core = core;
-               
+
                Logger.info(this, "Starting plugin \"FetchPlugin\" ...");

                this.fetchPanel = new FetchPanel(core, this);

-               
core.getMainWindow().addTab(I18n.getMessage("thaw.common.download"), 
-                                           IconBox.minDownloads,
-                                           this.fetchPanel.getPanel());
+               
//core.getMainWindow().addTab(I18n.getMessage("thaw.common.download"),
+               //                          IconBox.minDownloads,
+               //                          this.fetchPanel.getPanel());

+
+               // Prepare the frame
+
+               fetchFrame = new 
JFrame(I18n.getMessage("thaw.common.download"));
+               fetchFrame.setVisible(false);
+               
fetchFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
+               fetchFrame.setContentPane(fetchPanel.getPanel());
+               fetchFrame.setSize(650, 500);
+
+               // Add the button to the toolbar when the QueueWatch tab is 
selected
+               buttonInToolBar = new JButton(IconBox.downloads);
+               
buttonInToolBar.setToolTipText(I18n.getMessage("thaw.common.download"));
+               buttonInToolBar.addActionListener(this);
+
+
+               
if(core.getPluginManager().getPlugin("thaw.plugins.QueueWatcher") == null) {
+                       Logger.info(this, "Loading QueueWatcher plugin");
+
+                       
if(!core.getPluginManager().loadPlugin("thaw.plugins.QueueWatcher")
+                          || 
!core.getPluginManager().runPlugin("thaw.plugins.QueueWatcher")) {
+                               Logger.error(this, "Unable to load 
thaw.plugins.QueueWatcher !");
+                               return false;
+                       }
+               }
+
+               queueWatcher = 
(QueueWatcher)core.getPluginManager().getPlugin("thaw.plugins.QueueWatcher");
+
+               queueWatcher.addButtonToTheToolbar(buttonInToolBar);
+
                return true;
        }

@@ -34,8 +74,11 @@
        public boolean stop() {
                Logger.info(this, "Stopping plugin \"FetchPlugin\" ...");

-               this.core.getMainWindow().removeTab(this.fetchPanel.getPanel());
+               
//this.core.getMainWindow().removeTab(this.fetchPanel.getPanel());

+               if (queueWatcher != null)
+                       
queueWatcher.removeButtonFromTheToolbar(buttonInToolBar);
+
                return true;
        }

@@ -43,6 +86,10 @@
                return I18n.getMessage("thaw.common.download");
        }

+       public void actionPerformed(ActionEvent e) {
+               if (e.getSource() == buttonInToolBar)
+                       fetchFrame.setVisible(true);
+       }

        public void fetchFiles(String[] keys, int priority,
                               int persistence, boolean globalQueue,
@@ -63,6 +110,7 @@
                                                                                
          destination));
                }

+               fetchFrame.setVisible(false);
        }

 }

Modified: trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java        2006-11-01 17:13:09 UTC 
(rev 10776)
+++ trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java        2006-11-01 17:51:20 UTC 
(rev 10777)
@@ -35,7 +35,7 @@
        }


-       public void lockWriting() {
+       public synchronized void lockWriting() {
                while(writeLock > 0) {
                        try {
                                Thread.sleep(100);

Modified: trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java  2006-11-01 17:13:09 UTC 
(rev 10776)
+++ trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java  2006-11-01 17:51:20 UTC 
(rev 10777)
@@ -3,16 +3,29 @@
 import javax.swing.JScrollPane;
 import java.io.File;

+import javax.swing.JFrame;
+import javax.swing.JButton;
+import javax.swing.WindowConstants;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
 import thaw.core.*;
 import thaw.plugins.insertPlugin.*;
 import thaw.fcp.*;

-public class InsertPlugin implements thaw.core.Plugin {
+public class InsertPlugin implements thaw.core.Plugin, ActionListener {
        private Core core;

        private InsertPanel insertPanel;
        private JScrollPane scrollPane;

+       private JFrame insertionFrame;
+       private JButton buttonInToolBar;
+
+       private QueueWatcher queueWatcher;
+
+
        public InsertPlugin() {

        }
@@ -28,10 +41,40 @@

                this.scrollPane = new JScrollPane(this.insertPanel.getPanel());

-               
core.getMainWindow().addTab(I18n.getMessage("thaw.common.insertion"),
-                                           IconBox.minInsertions,
-                                           this.scrollPane);
+               
//core.getMainWindow().addTab(I18n.getMessage("thaw.common.insertion"),
+               //                          IconBox.minInsertions,
+               //                          this.scrollPane);

+               insertionFrame = new 
JFrame(I18n.getMessage("thaw.common.insertion"));
+               insertionFrame.setVisible(false);
+               
insertionFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
+               insertionFrame.setContentPane(scrollPane);
+
+               if (core.getConfig().getValue("advancedMode") == null
+                   || 
Boolean.valueOf(core.getConfig().getValue("advancedMode")).booleanValue()) {
+                       insertionFrame.setSize(750, 450);
+               } else {
+                       insertionFrame.setSize(350, 200);
+               }
+
+               buttonInToolBar = new JButton(IconBox.insertions);
+               
buttonInToolBar.setToolTipText(I18n.getMessage("thaw.common.insertion"));
+               buttonInToolBar.addActionListener(this);
+
+               
if(core.getPluginManager().getPlugin("thaw.plugins.QueueWatcher") == null) {
+                       Logger.info(this, "Loading QueueWatcher plugin");
+
+                       
if(!core.getPluginManager().loadPlugin("thaw.plugins.QueueWatcher")
+                          || 
!core.getPluginManager().runPlugin("thaw.plugins.QueueWatcher")) {
+                               Logger.error(this, "Unable to load 
thaw.plugins.QueueWatcher !");
+                               return false;
+                       }
+               }
+
+               queueWatcher = 
(QueueWatcher)core.getPluginManager().getPlugin("thaw.plugins.QueueWatcher");
+
+               queueWatcher.addButtonToTheToolbar(buttonInToolBar);
+
                return true;
        }

@@ -39,8 +82,11 @@
        public boolean stop() {
                Logger.info(this, "Stopping plugin \"InsertPlugin\" ...");

-               this.core.getMainWindow().removeTab(this.scrollPane);
+               //this.core.getMainWindow().removeTab(this.scrollPane);

+               if (queueWatcher != null)
+                       
queueWatcher.removeButtonFromTheToolbar(buttonInToolBar);
+
                return true;
        }

@@ -50,6 +96,12 @@
        }


+       public void actionPerformed(ActionEvent e) {
+               if (e.getSource() == buttonInToolBar)
+                       insertionFrame.setVisible(true);
+       }
+
+
        /**
         * Note: public key is found from private one.
         * @param fileList File list, separated by ';'
@@ -98,6 +150,8 @@

                }

+               insertionFrame.setVisible(false);
+
                return true;
        }


Modified: trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java  2006-11-01 17:13:09 UTC 
(rev 10776)
+++ trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java  2006-11-01 17:51:20 UTC 
(rev 10777)
@@ -7,13 +7,16 @@
 import java.util.Iterator;
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ChangeEvent;

+
 import thaw.core.*;
 import thaw.plugins.queueWatcher.*;

 import thaw.fcp.*;

-public class QueueWatcher implements thaw.core.Plugin, PropertyChangeListener {
+public class QueueWatcher extends ToolbarModifier implements thaw.core.Plugin, 
PropertyChangeListener, ChangeListener {
        private Core core;

        //private JPanel mainPanel;
@@ -83,23 +86,17 @@
                        this.panelAdded = this.panel;
                }

+               setMainWindow(core.getMainWindow());
+
                
core.getMainWindow().addTab(I18n.getMessage("thaw.common.status"),
                                            IconBox.minQueue,
                                            this.panelAdded);
+               core.getMainWindow().getTabbedPane().addChangeListener(this);

-               //if(core.getConnectionManager() != null && 
core.getConnectionManager().isConnected()) {
-               //      core.getConnectionManager().addObserver(this);
-               //}
+               this.dnd = new DragAndDropManager(core, this.queuePanels);

-               //if(core.getQueueManager() != null)
-               //    core.getQueueManager().addObserver(this);
-               //else {
-               //    Logger.warning(this, "Unable to connect to QueueManager. 
Is the connection established ?");
-               //    return false;
-               //}
+               stateChanged(null);

-               this.dnd = new DragAndDropManager(core, this.queuePanels);
-
                return true;
        }

@@ -137,6 +134,9 @@

        }

+       /**
+        * Called when the split bar position changes.
+        */
        public void propertyChange(PropertyChangeEvent evt) {

                if("dividerLocation".equals( evt.getPropertyName() )) {
@@ -162,4 +162,24 @@

        }

+       /**
+        * Called when the JTabbedPane changed (ie change in the selected tab, 
etc)
+        * @param e can be null.
+        */
+       public void stateChanged(ChangeEvent e) {
+               int tabId;
+
+               tabId = 
core.getMainWindow().getTabbedPane().indexOfTab(I18n.getMessage("thaw.common.status"));
+
+               if (tabId < 0) {
+                       Logger.warning(this, "Unable to find back the tab !");
+                       return;
+               }
+
+               if (core.getMainWindow().getTabbedPane().getSelectedIndex() == 
tabId) {
+                       displayButtonsInTheToolbar();
+               } else {
+                       hideButtonsInTheToolbar();
+               }
+       }
 }

Added: trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java       2006-11-01 
17:13:09 UTC (rev 10776)
+++ trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java       2006-11-01 
17:51:20 UTC (rev 10777)
@@ -0,0 +1,63 @@
+package thaw.plugins;
+
+import java.util.Vector;
+import javax.swing.JButton;
+
+import thaw.core.Logger;
+import thaw.core.MainWindow;
+
+/**
+ * Not a plugin ! Just an helper for the plugins !
+ */
+public class ToolbarModifier {
+       private MainWindow mainWindow = null;
+
+       private Vector buttons; /* JButtons */
+
+       private boolean areDisplayed = false;
+
+       public ToolbarModifier() {
+               buttons = new Vector();
+               areDisplayed = false;
+       }
+
+       public ToolbarModifier(MainWindow toolbarTarget) {
+               this();
+               setMainWindow(toolbarTarget);
+       }
+
+
+       public void setMainWindow(MainWindow target) {
+               this.mainWindow = target;
+       }
+
+       public void addButtonToTheToolbar(JButton button) {
+               buttons.add(button);
+
+               if (areDisplayed)
+                       displayButtonsInTheToolbar();
+       }
+
+       public void removeButtonFromTheToolbar(JButton button) {
+               buttons.remove(button);
+
+               if (areDisplayed)
+                       displayButtonsInTheToolbar();
+       }
+
+       public void displayButtonsInTheToolbar() {
+               if (mainWindow != null) {
+                       mainWindow.changeButtonsInTheToolbar(this, buttons);
+                       areDisplayed = true;
+               } else
+                       Logger.error(this, "MainWindow not SET !");
+       }
+
+       public void hideButtonsInTheToolbar() {
+               if (mainWindow != null) {
+                       mainWindow.changeButtonsInTheToolbar(this, null);
+                       areDisplayed = false;
+               } else
+                       Logger.error(this, "MainWindow not SET !");
+       }
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-11-01 17:13:09 UTC (rev 10776)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-11-01 17:51:20 UTC (rev 10777)
@@ -264,6 +264,10 @@
                        this.resetPriorityRadioButtons();
                } else {
                        FCPTransferQuery query = 
this.tableModel.getQuery(this.selectedRows[0]);
+
+                       if (query == null)
+                               return;
+
                        
this.priorityRadioButton[query.getFCPPriority()].setSelected(true);
                }
        }


Reply via email to