1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package de.jaret.util.ui.timebars.model;
21
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Vector;
26
27 import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
28
29
30
31
32
33
34
35 public class DefaultTimeBarViewState implements ITimeBarViewState {
36
37 protected List<ITimeBarViewStateListener> _tbvsListeners = new Vector<ITimeBarViewStateListener>();
38
39
40 protected Map<TimeBarRow, Integer> _heights = new HashMap<TimeBarRow, Integer>();
41
42
43 protected Map<TimeBarRow, Boolean> _drawOverlapping = new HashMap<TimeBarRow, Boolean>();
44
45
46 protected boolean _useVariableRowHeights = false;
47
48
49 protected int _defaultHeight;
50
51
52 protected IRowHeightStrategy _rowHeightStrategy;
53
54
55 protected TimeBarViewerDelegate _delegate;
56
57
58
59
60
61
62 public DefaultTimeBarViewState(TimeBarViewerDelegate delegate) {
63 _delegate = delegate;
64 }
65
66
67
68
69 public int getRowHeight(TimeBarRow row) {
70 if (!_useVariableRowHeights) {
71 return _defaultHeight;
72 }
73 Integer h = _heights.get(row);
74 if (h == null || (_rowHeightStrategy != null) && _rowHeightStrategy.overrideDefault()) {
75 if (_rowHeightStrategy == null) {
76
77 return _defaultHeight;
78 } else {
79 return _rowHeightStrategy.calculateRowHeight(_delegate, this, row);
80 }
81 }
82 return h;
83 }
84
85
86
87
88 public void setRowHeight(TimeBarRow row, int height) {
89 int curHeight = getRowHeight(row);
90 if (curHeight != height) {
91 _heights.put(row, height);
92 fireRowHeightChanged(row, height);
93 }
94 }
95
96
97
98
99 public void setRowHeightStrategy(IRowHeightStrategy rowHeightStrategy) {
100 _rowHeightStrategy = rowHeightStrategy;
101 fireViewStateChanged();
102 }
103
104
105
106
107 public IRowHeightStrategy getRowHeightStrategy() {
108 return _rowHeightStrategy;
109 }
110
111
112
113
114
115
116
117 public void fireRowHeightChanged(TimeBarRow row, int height) {
118 for (ITimeBarViewStateListener listener : _tbvsListeners) {
119 listener.rowHeightChanged(row, height);
120 }
121 }
122
123
124
125
126 public void fireViewStateChanged() {
127 for (ITimeBarViewStateListener listener : _tbvsListeners) {
128 listener.viewStateChanged();
129 }
130 }
131
132
133
134
135 public void removeTimeBarViewStateListener(ITimeBarViewStateListener listener) {
136 _tbvsListeners.remove(listener);
137 }
138
139
140
141
142 public void addTimeBarViewStateListener(ITimeBarViewStateListener listener) {
143 _tbvsListeners.add(listener);
144 }
145
146
147
148
149 public void setDefaultRowHeight(int height) {
150 _defaultHeight = height;
151 }
152
153
154
155
156 public int getDefaultRowHeight() {
157 return _defaultHeight;
158 }
159
160
161
162
163 public boolean getUseVariableRowHeights() {
164 return _useVariableRowHeights;
165 }
166
167
168
169
170 public void setUseVariableRowHeights(boolean useVariableRowHeights) {
171 if (useVariableRowHeights != _useVariableRowHeights) {
172 _useVariableRowHeights = useVariableRowHeights;
173 fireViewStateChanged();
174 }
175 }
176
177
178
179
180 public boolean getDrawOverlapping(TimeBarRow row) {
181 Boolean result = _drawOverlapping.get(row);
182 if (result == null) {
183 return _delegate.isDrawOverlapping();
184 }
185 return result.booleanValue();
186 }
187
188
189
190
191 public void setDrawOverlapping(TimeBarRow row, boolean drawOverlapping) {
192 _drawOverlapping.put(row, drawOverlapping);
193 }
194
195 }