From 7bcd3e2b18a02450b1bd016ef554b966af62f59a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 16 May 2008 16:15:46 +0000 Subject: [PATCH] add main window as property change listener to project 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 | 40 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 6708f5e..843fd1f 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -20,11 +20,14 @@ 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 <bombe@freenetproject.org> * @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(); + } + } + } + } + } + } + } -- 2.7.4