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    
005    package graphlab.graph.atributeset;
006    
007    import graphlab.graph.graph.EdgeModel;
008    import graphlab.graph.graph.GraphPoint;
009    import graphlab.graph.old.Arrow;
010    import graphlab.graph.old.GStroke;
011    import graphlab.platform.attribute.AttributeSet;
012    import graphlab.platform.attribute.NotifiableAttributeSetImpl;
013    
014    import java.util.HashMap;
015    import java.util.Map;
016    
017    /**
018     * @author Azin Azadi
019     * @see GraphAttrSet
020     */
021    public class EdgeAttrSet implements AttributeSet {
022    
023        EdgeModel e;
024        NotifiableAttributeSetImpl atrs = new NotifiableAttributeSetImpl();
025    
026        public EdgeAttrSet(EdgeModel e) {
027            this.e = e;
028        }
029    
030        public static final String SOURCE = "source";
031        public static final String TARGET = "target";
032        //public static final String DIRECTED = "directed";
033        //public static final String ID = "id";
034        public static final String WEIGHT = "Weight";
035        public static final String LABEL = "Label";
036        public static final String SHOW_WEIGHT = "Show Weight";
037        public static final String COLOR = "Color";
038        public static final String MARK = "Mark";
039        public static final String STROKE = "Stroke";
040        public static final String LABEL_LOCATION = "Label Location";
041        public static final String ARROW = "Arrow";
042        public static final String CURVE_CONTROL_POINT = "Curve Control Point";
043    
044        public void put(String atrName, Object val) {
045            if (atrName.equals(LABEL)) {
046                e.setLabel((String) val);
047            } else if (atrName.equals(WEIGHT)) {
048                e.setWeight((Integer) val);
049            } else if (atrName.equals(SHOW_WEIGHT)) {
050                e.setShowWeight((Boolean) val);
051            } else if (atrName.equals(COLOR)) {
052                e.setColor((Integer) val);
053            } else if (atrName.equals(MARK)) {
054                e.setMark((Boolean) val);
055            } else if (atrName.equals(COLOR)) {
056                e.setColor((Integer) val);
057            } else if (atrName.equals(STROKE)) {
058                e.setStroke((GStroke) val);
059            } else if (atrName.equals(LABEL_LOCATION)) {
060                e.setLabelLocation((GraphPoint) val);
061            } else if (atrName.equals(ARROW)) {
062                e.setArrow((Arrow) val);
063            } else if (atrName.equals(CURVE_CONTROL_POINT)) {
064                e.setCurveControlPoint((GraphPoint) val);
065            } else {
066                e.setUserDefinedAttribute(atrName, val);
067            }
068        }
069    
070    
071        public Object get(String atrName) {
072            Object ret = null;
073            if (atrName.equals(LABEL)) {
074                ret = e.getLabel();
075            } else if (atrName.equals(STROKE)) {
076                ret = e.getStroke();
077            } else if (atrName.equals(COLOR)) {
078                ret = e.getColor();
079            } else if (atrName.equals(MARK)) {
080                ret = e.getMark();
081            } else if (atrName.equals(WEIGHT)) {
082                ret = e.getWeight();
083            } else if (atrName.equals(SHOW_WEIGHT)) {
084                ret = e.isShowWeight();
085            } else if (atrName.equals(LABEL_LOCATION)) {
086                ret = e.getLabelLocation();
087            } else if (atrName.equals(ARROW)) {
088                ret = e.getArrow();
089    //        } else if (atrName.equals(HEAD)) {
090    //            ret = e.source;
091    //        } else if (atrName.equals(TAIL)) {
092    //            ret = e.target;
093            } else if (atrName.equals(CURVE_CONTROL_POINT)) {
094                ret = e.getCurveControlPoint();
095            } else {
096                ret = e.getUserDefinedAttribute(atrName);
097            }
098            return ret;
099        }
100    
101        public Map<String, Object> getAttrs() {
102            Map<String, Object> ret = new HashMap<String, Object>();
103            ret.put(WEIGHT, e.getWeight());
104            ret.put(LABEL, e.getLabel());
105            ret.put(SHOW_WEIGHT, e.isShowWeight());
106            ret.put(COLOR, e.getColor());
107            ret.put(MARK, e.getMark());
108            ret.put(STROKE, e.getStroke());
109            ret.put(LABEL_LOCATION, e.getLabelLocation());
110            ret.put(ARROW, e.getArrow());
111            ret.put(CURVE_CONTROL_POINT, e.getCurveControlPoint());
112            if (e.getUserDefinedAttributes() != null)
113                ret.putAll(e.getUserDefinedAttributes());
114            return ret;
115        }
116    
117    }