1 /*
2 * File: AbstractTimeBarMarker.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;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import de.jaret.util.date.JaretDate;
26
27 /**
28 * Abstract base implementation of a TimeBarMarker.
29 *
30 * @author Peter Kliem
31 * @version $Id: AbstractTimeBarMarker.java 251 2007-02-12 21:09:03Z olk $
32 */
33 public abstract class AbstractTimeBarMarker implements TimeBarMarker {
34 /** attribute storing the draggable state. */
35 protected boolean _draggable = true;
36
37 /** listener list. */
38 protected List<TimeBarMarkerListener> _listenerList;
39
40 /**
41 * @param draggable true if the marker should be draggable
42 */
43 public AbstractTimeBarMarker(boolean draggable) {
44 _draggable = draggable;
45 }
46
47 /**
48 * {@inheritDoc}
49 */
50 public boolean isDraggable() {
51 return _draggable;
52 }
53
54 /**
55 * @param draggable The draggable to set.
56 */
57 public void setDraggable(boolean draggable) {
58 _draggable = draggable;
59 // fire a description change to trigger redraw
60 fireMarkerDescriptionChanged(getDescription(), getDescription());
61 }
62
63 /**
64 * {@inheritDoc}
65 */
66 public void addTimeBarMarkerListener(TimeBarMarkerListener tbml) {
67 if (_listenerList == null) {
68 _listenerList = new ArrayList<TimeBarMarkerListener>();
69 }
70 _listenerList.add(tbml);
71 }
72
73 /**
74 * {@inheritDoc}
75 */
76 public void remTimeBarMarkerListener(TimeBarMarkerListener tbml) {
77 if (_listenerList != null) {
78 _listenerList.remove(tbml);
79 }
80 }
81
82 /**
83 * Inform registered listeners of a date change.
84 *
85 * @param oldDate the last date the amrker was set to
86 * @param newDate the new date
87 */
88 protected void fireMarkerChanged(JaretDate oldDate, JaretDate newDate) {
89 if (_listenerList != null) {
90 for (TimeBarMarkerListener listener : _listenerList) {
91 listener.markerMoved(this, oldDate, newDate);
92 }
93 }
94 }
95
96 /**
97 * Inform registered listeners of a description change.
98 *
99 * @param oldValue the prevoiuos description
100 * @param newValue the new value
101 */
102 protected void fireMarkerDescriptionChanged(String oldValue, String newValue) {
103 if (_listenerList != null) {
104 for (TimeBarMarkerListener listener : _listenerList) {
105 listener.markerDescriptionChanged(this, oldValue, newValue);
106 }
107 }
108 }
109 }