View Javadoc

1   /*
2    *  File: AbstractTimeBarNode.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.util.ui.timebars.model;
21  
22  import java.util.List;
23  import java.util.Vector;
24  
25  /**
26   * Abstract base implementation for a timebar node.
27   * 
28   * @author Peter Kliem
29   * @version $Id: AbstractTimeBarNode.java 802 2008-12-28 12:30:41Z kliem $
30   */
31  public abstract class AbstractTimeBarNode extends AbstractTimeBarRowModel implements TimeBarNode {
32      /** list of registered listeners. */
33      protected List<TimeBarNodeListener> _nodeListeners;
34  
35      /**
36       * Default constructor. Do not forget to set a headre when using this constructor.
37       */
38      public AbstractTimeBarNode() {
39  
40      }
41  
42      /**
43       * Constructor supplying a header.
44       * 
45       * @param header the header for teh node
46       */
47      public AbstractTimeBarNode(TimeBarRowHeader header) {
48          super(header);
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      public synchronized void addTimeBarNodeListener(TimeBarNodeListener tbnl) {
55          if (_nodeListeners == null) {
56              _nodeListeners = new Vector<TimeBarNodeListener>();
57          }
58          _nodeListeners.add(tbnl);
59          super.addTimeBarRowListener(tbnl);
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      public synchronized void removeTimeBarNodeListener(TimeBarNodeListener tbnl) {
66          if (_nodeListeners == null) {
67              return;
68          }
69          _nodeListeners.remove(tbnl);
70          super.remTimeBarRowListener(tbnl);
71      }
72  
73      /**
74       * Inform listeners about a new node.
75       * 
76       * @param newNode the added node
77       */
78      protected void fireNodeAdded(TimeBarNode newNode) {
79          if (_nodeListeners != null) {
80              for (TimeBarNodeListener listener : _nodeListeners) {
81                  listener.nodeAdded(this, newNode);
82              }
83          }
84      }
85  
86      /**
87       * Inform listeners about a removed node.
88       * 
89       * @param removedNode the node that has been removed
90       */
91      protected void fireNodeRemoved(TimeBarNode removedNode) {
92          if (_nodeListeners != null) {
93              for (TimeBarNodeListener listener : _nodeListeners) {
94                  listener.nodeRemoved(this, removedNode);
95              }
96          }
97      }
98  
99  }