implement node addition and removal events
[jSite2.git] / src / net / pterodactylus / jsite / gui / MainWindow.java
index 3d61638..4eb7ab7 100644 (file)
@@ -24,6 +24,7 @@ import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
 
 import javax.swing.Action;
 import javax.swing.Box;
@@ -53,7 +54,7 @@ import net.pterodactylus.util.swing.SwingUtils;
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  * @version $Id$
  */
-public class MainWindow extends JFrame implements I18nable {
+public class MainWindow extends JFrame implements WindowListener, I18nable {
 
        /** The swing interface that receives all actions. */
        private final SwingInterface swingInterface;
@@ -109,7 +110,7 @@ public class MainWindow extends JFrame implements I18nable {
                pack();
                SwingUtils.center(this);
                I18n.registerI18nable(this);
-               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+               addWindowListener(this);
        }
 
        //
@@ -169,10 +170,20 @@ public class MainWindow extends JFrame implements I18nable {
                for (Action nodeConnectAction: swingInterface.getNodeConnectActions()) {
                        connectMenu.add(nodeConnectAction);
                }
+               if (connectMenu.getMenuComponentCount() == 0) {
+                       JMenuItem noNodeAvailableItem = new JMenuItem(I18n.get("mainWindow.menu.connectNoNodeAvailable.name"));
+                       noNodeAvailableItem.setEnabled(false);
+                       connectMenu.add(noNodeAvailableItem);
+               }
                disconnectMenu.removeAll();
                for (Action nodeDisconnectAction: swingInterface.getNodeDisconnectActions()) {
                        disconnectMenu.add(nodeDisconnectAction);
                }
+               if (disconnectMenu.getMenuComponentCount() == 0) {
+                       JMenuItem noNodeAvailableItem = new JMenuItem(I18n.get("mainWindow.menu.disconnectNoNodeAvailable.name"));
+                       noNodeAvailableItem.setEnabled(false);
+                       disconnectMenu.add(noNodeAvailableItem);
+               }
        }
 
        //
@@ -206,6 +217,7 @@ public class MainWindow extends JFrame implements I18nable {
                nodeMenu.add(connectMenu);
                nodeMenu.add(disconnectMenuItem = new FixedJMenuItem(swingInterface.getNodeDisconnectAction()));
                nodeMenu.add(disconnectMenu);
+               refreshNodeMenuItems();
 
                languageMenu = new I18nMenu("mainWindow.menu.language");
                menuBar.add(languageMenu);
@@ -314,7 +326,61 @@ public class MainWindow extends JFrame implements I18nable {
                for (int componentIndex = 0; componentIndex < projectPane.getTabCount(); componentIndex++) {
                        projectPane.setTitleAt(componentIndex, projectPane.getComponentAt(componentIndex).getName());
                }
+               refreshNodeMenuItems();
                SwingUtils.repackCentered(this);
        }
 
+       //
+       // INTERFACE WindowListener
+       //
+       
+       /**
+        * {@inheritDoc}
+        */
+       public void windowActivated(WindowEvent e) {
+               /* do nothing. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void windowClosed(WindowEvent e) {
+               /* do nothing. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void windowClosing(WindowEvent e) {
+               swingInterface.getQuitAction().actionPerformed(null);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void windowDeactivated(WindowEvent e) {
+               /* do nothing. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void windowDeiconified(WindowEvent e) {
+               /* do nothing. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void windowIconified(WindowEvent e) {
+               /* do nothing. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void windowOpened(WindowEvent e) {
+               /* do nothing. */
+       }
+
 }