View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // GenomeBrowser Project
18  //
19  // TrackPropertyChangeImpl.java
20  // Since: Jun 25, 2007
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.impl;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  import org.utgenome.gwt.utgb.client.track.TrackGroupProperty;
31  import org.utgenome.gwt.utgb.client.track.TrackGroupPropertyChange;
32  import org.utgenome.gwt.utgb.client.track.TrackWindow;
33  import org.utgenome.gwt.utgb.client.util.xml.XMLWriter;
34  
35  /**
36   * An implementation of the {@link TrackGroupPropertyChange}
37   * 
38   * @author leo
39   * 
40   */
41  class TrackPropertyChangeImpl implements TrackGroupPropertyChange {
42  	private HashSet<String> _keySetOfChangedProperties = new HashSet<String>();
43  
44  	private TrackGroupProperty _reader;
45  
46  	public TrackPropertyChangeImpl(TrackGroupProperty reader, String keyOfChangedProperty) {
47  		this._reader = reader;
48  		addChangedProperty(keyOfChangedProperty);
49  	}
50  
51  	public TrackPropertyChangeImpl(TrackGroupProperty reader, Set<String> keySet) {
52  		this._reader = reader;
53  		addChangedProperty(keySet);
54  	}
55  
56  	public void addChangedProperty(String key) {
57  		_keySetOfChangedProperties.add(key);
58  	}
59  
60  	public void addChangedProperty(Set<String> keySet) {
61  		for (String key : keySet)
62  			addChangedProperty(key);
63  	}
64  
65  	public boolean contains(String key) {
66  		return _keySetOfChangedProperties.contains(key);
67  	}
68  
69  	public boolean containsOneOf(String[] keySet) {
70  		for (int i = 0; i < keySet.length; i++) {
71  			if (_keySetOfChangedProperties.contains(keySet[i]))
72  				return true;
73  		}
74  		return false;
75  	}
76  
77  	public boolean containsOneOf(Iterable<String> keyList) {
78  		for (String key : keyList) {
79  			if (_keySetOfChangedProperties.contains(key))
80  				return true;
81  		}
82  		return false;
83  	}
84  
85  	public String getProperty(String key) {
86  		return _reader.getProperty(key);
87  	}
88  
89  	public String getProperty(String key, String defaultValue) {
90  		return _reader.getProperty(key, defaultValue);
91  	}
92  
93  	public TrackWindow getTrackWindow() {
94  		return _reader.getTrackWindow();
95  	}
96  
97  	public Set<String> keySet() {
98  		return _reader.keySet();
99  	}
100 
101 	public Set<String> changedKeySet() {
102 		return _keySetOfChangedProperties;
103 	}
104 
105 	public void toXML(XMLWriter xmlWriter) {
106 		_reader.toXML(xmlWriter);
107 	}
108 
109 }