add main window as property change listener to project
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 16 May 2008 16:15:46 +0000 (16:15 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 16 May 2008 16:15:46 +0000 (16:15 +0000)
react on project property changes

git-svn-id: http://trooper/svn/projects/jSite/trunk@904 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/gui/MainWindow.java

index 6708f5e..843fd1f 100644 (file)
 package net.pterodactylus.jsite.gui;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -58,7 +61,7 @@ import net.pterodactylus.util.swing.SwingUtils;
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  * @version $Id$
  */
-public class MainWindow extends JFrame implements WindowListener, I18nable {
+public class MainWindow extends JFrame implements WindowListener, I18nable, PropertyChangeListener {
 
        /** The swing interface that receives all actions. */
        private final SwingInterface swingInterface;
@@ -245,6 +248,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable {
        void addProject(Project project) {
                ProjectPanel projectPanel = new ProjectPanel(swingInterface, project);
                projectPane.add(project.getName(), projectPanel);
+               project.addPropertyChangeListener(this);
        }
 
        //
@@ -354,8 +358,8 @@ public class MainWindow extends JFrame implements WindowListener, I18nable {
                requestTable = new JTable(swingInterface.getRequestTableModel());
                getContentPane().add(new JScrollPane(requestTable), BorderLayout.CENTER);
 
-// JPanel lowerPanel = new JPanel(new BorderLayout(12, 12));
-// getContentPane().add(lowerPanel, BorderLayout.CENTER);
+               // JPanel lowerPanel = new JPanel(new BorderLayout(12, 12));
+               // getContentPane().add(lowerPanel, BorderLayout.CENTER);
        }
 
        //
@@ -447,4 +451,34 @@ public class MainWindow extends JFrame implements WindowListener, I18nable {
                /* do nothing. */
        }
 
+       //
+       // INTERFACE PropertyChangeListener
+       //
+
+       /**
+        * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+        */
+       public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
+               Object eventSource = propertyChangeEvent.getSource();
+               String propertyName = propertyChangeEvent.getPropertyName();
+               if (eventSource instanceof Project) {
+                       /* if a project was changed, update the tab title and tooltip. */
+                       if (Project.PROPERTY_NAME.equals(propertyName) || Project.PROPERTY_DESCRIPTION.equals(propertyName)) {
+                               Project project = (Project) eventSource;
+                               int tabCount = projectPane.getTabCount();
+                               for (int tabIndex = 0; tabIndex < tabCount; tabIndex++) {
+                                       Component tabComponent = projectPane.getComponentAt(tabIndex);
+                                       if (tabComponent instanceof ProjectPanel) {
+                                               Project tabProject = ((ProjectPanel) tabComponent).getProject();
+                                               if (tabProject.equals(project)) {
+                                                       projectPane.setTitleAt(tabIndex, project.getName());
+                                                       projectPane.setToolTipTextAt(tabIndex, project.getDescription());
+                                                       projectPane.repaint();
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
 }