001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    package graphlab.ui;
005    
006    import graphlab.platform.attribute.AttributeListener;
007    import graphlab.platform.attribute.AttributeSet;
008    import graphlab.platform.attribute.NotifiableAttributeSet;
009    import graphlab.platform.attribute.NotifiableAttributeSetImpl;
010    
011    import java.util.Collection;
012    import java.util.Map;
013    
014    /**
015     * this is a portable NotifiableAttributeSetImpl + View
016     * this means that the model of view can be changed
017     *
018     * @author azin azadi
019     */
020    public class PortableNotifiableAttributeSetImpl implements NotifiableAttributeSet, NotifiableAttributeSetView {
021        private AttributeSetView view;
022        private NotifiableAttributeSet model;
023    
024        public PortableNotifiableAttributeSetImpl() {
025            view = new AttributeSetView();
026            model = new NotifiableAttributeSetImpl();
027            view.setAttribute(this.getAttributes());
028        }
029    
030        public void setView(AttributeSetView view) {
031            this.view = view;
032            view.setAttribute(model);
033        }
034    
035        public AttributeSetView getView() {
036            return view;
037        }
038    
039        public void setModel(NotifiableAttributeSet aModel) {
040            model = aModel;
041            view.setAttribute(model);
042        }
043    
044        public AttributeSet getAttributes() {
045            return model;
046        }
047    
048        public void addAttributeListener(AttributeListener attributeListener) {
049            model.addAttributeListener(attributeListener);
050        }
051    
052        public Collection<AttributeListener> getAttributeListeners() {
053            return model.getAttributeListeners();
054        }
055    
056        public void removeAttributeListener(AttributeListener attributeListener) {
057            model.removeAttributeListener(attributeListener);
058        }
059    
060        public NotifiableAttributeSet getModel() {
061            return model;
062        }
063    
064        public Map<String, Object> getAttrs() {
065            return model.getAttrs();
066        }
067    
068        public void put(String name, Object value) {
069            model.put(name, value);
070        }
071    
072    //    /**
073    //     * puts an attribute in the model
074    //     *
075    //     * @param name
076    //     * @param atr
077    //     */
078    //    public void put(String name, Object atr) {
079    //        model.getAttributes().put(name, atr);
080    //    }
081    
082        public Object get(String name) {
083            return model.get(name);
084        }
085    
086    //    public boolean contains(String name) {
087    //        return model.contains(name);
088    //    }
089    
090    //    /**
091    //     * gets an attribute from model
092    //     *
093    //     * @param name
094    //     */
095    //    public <t>t get(String name) {
096    //        return (t) model.getAttributes().get(name);
097    //    }
098    }