1 /*
2 * File: IntervalRelation.java
3 * Copyright (c) 2004-2008 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 de.jaret.util.misc.PropertyObservableBase;
23
24 /**
25 * Implementation of the IIntervalRelation. Handles the references itself, i.e. setting ine end to <code>null</code>
26 * will remove the relation from the interval.
27 *
28 * @author kliem
29 * @version $Id: IntervalRelation.java 800 2008-12-27 22:27:33Z kliem $
30 */
31 public class IntervalRelation extends PropertyObservableBase implements IIntervalRelation {
32 /** the direction of the relation. */
33 protected Direction _direction = Direction.FORWARD;
34 /** start interval. */
35 protected IRelationalInterval _startInterval;
36 /** end interval. */
37 protected IRelationalInterval _endInterval;
38
39 /** type of the relation. */
40 protected Type _type = Type.END_BEGIN;
41
42 /**
43 * Construct a releation between two intervals (forward, end-begin).
44 *
45 * @param startInterval first interval
46 * @param endInterval second interval
47 */
48 public IntervalRelation(IRelationalInterval startInterval, IRelationalInterval endInterval) {
49 setStartInterval(startInterval);
50 setEndInterval(endInterval);
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 public Direction getDirection() {
57 return _direction;
58 }
59
60 /**
61 * {@inheritDoc}
62 */
63 public void setDirection(Direction direction) {
64 if (direction == null) {
65 throw new IllegalArgumentException("direction might not be null");
66 }
67 if (!direction.equals(_direction)) {
68 Direction oldValue = _direction;
69 _direction = direction;
70 firePropertyChange(DIRECTION, oldValue, direction);
71 }
72 }
73
74 /**
75 * {@inheritDoc}
76 */
77 public IRelationalInterval getEndInterval() {
78 return _endInterval;
79 }
80
81 /**
82 * {@inheritDoc}
83 */
84 public void setEndInterval(IRelationalInterval interval) {
85 if (isRealModification(_endInterval, interval)) {
86 IRelationalInterval oldVal = _endInterval;
87 // remove from old interval
88 if (oldVal != null) {
89 oldVal.removeRelation(this);
90 }
91 _endInterval = interval;
92 // add to new interval
93 if (_endInterval != null) {
94 _endInterval.addRelation(this);
95 }
96 firePropertyChange(ENDINTERVAL, oldVal, interval);
97 }
98 }
99
100 /**
101 * {@inheritDoc}
102 */
103 public IRelationalInterval getStartInterval() {
104 return _startInterval;
105 }
106
107 /**
108 * {@inheritDoc}
109 */
110 public void setStartInterval(IRelationalInterval interval) {
111 if (isRealModification(_startInterval, interval)) {
112 IRelationalInterval oldVal = _startInterval;
113 // remove from old interval
114 if (oldVal != null) {
115 oldVal.removeRelation(this);
116 }
117 _startInterval = interval;
118 // add to new interval
119 if (_startInterval != null) {
120 _startInterval.addRelation(this);
121 }
122 firePropertyChange(STARTINTERVAL, oldVal, interval);
123 }
124 }
125
126 /**
127 * {@inheritDoc}
128 */
129 public Type getType() {
130 return _type;
131 }
132
133 /**
134 * {@inheritDoc}
135 */
136 public void setType(Type type) {
137 if (type == null) {
138 throw new IllegalArgumentException("type might not be null");
139 }
140 if (!type.equals(_type)) {
141 Type oldValue = _type;
142 _type = type;
143 firePropertyChange(TYPE, oldValue, type);
144 }
145 }
146
147 }