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.GraphPoint; 008 import graphlab.graph.graph.VertexModel; 009 import graphlab.graph.old.GShape; 010 import graphlab.graph.old.GStroke; 011 import graphlab.platform.attribute.AttributeSet; 012 013 import java.util.HashMap; 014 import java.util.Map; 015 016 /** 017 * @author Azin Azadi 018 * @see graphlab.graph.atributeset.GraphAttrSet 019 */ 020 public class VertexAttrSet implements AttributeSet { 021 private VertexModel v; 022 public static final String LABEL = "Label"; 023 public static final String COLOR = "Color"; 024 public static final String SHAPE = "Shape"; 025 public static final String BORDER = "Border"; 026 public static final String LOCATION = "Location"; 027 public static final String SIZE = "Size"; 028 public static final String MARK = "Mark"; 029 public static final String SELECTED = "Selected"; 030 public static final String LABEL_LOCATION = "Label Location"; 031 032 public VertexAttrSet(VertexModel v) { 033 this.v = v; 034 } 035 036 public Map<String, Object> getAttrs() { 037 Map<String, Object> ret = new HashMap<String, Object>(15); 038 ret.put(LABEL, v.getLabel()); 039 ret.put(COLOR, v.getColor()); 040 ret.put(SHAPE, v.getShape()); 041 ret.put(BORDER, v.getShapeStroke()); 042 ret.put(LOCATION, v.getLocation()); 043 ret.put(SIZE, v.getSize()); 044 ret.put(MARK, v.getMark()); 045 ret.put(SELECTED, v.isSelected()); 046 ret.put(LABEL_LOCATION, v.getLabelLocation()); 047 if (v.getUserDefinedAttributes() != null) 048 ret.putAll(v.getUserDefinedAttributes()); 049 return ret; 050 } 051 052 public void put(String atrName, Object val) { 053 if (atrName.equals(LABEL)) { 054 v.setLabel((String) val); 055 } else if (atrName.equals(SHAPE)) { 056 v.setShape((GShape) val); 057 } else if (atrName.equals(BORDER)) { 058 v.setShapeStroke((GStroke) val); 059 } else if (atrName.equals(LOCATION)) { 060 v.setLocation((GraphPoint) val); 061 } else if (atrName.equals(SIZE)) { 062 v.setSize((GraphPoint) val); 063 } else if (atrName.equals(MARK)) { 064 v.setMark((Boolean) val); 065 } else if (atrName.equals(SELECTED)) { 066 v.setSelected((Boolean) val); 067 } else if (atrName.equals(COLOR)) { 068 v.setColor((Integer) val); 069 } else if (atrName.equals(LABEL_LOCATION)) { 070 v.setLabelLocation((GraphPoint) val); 071 } else { 072 v.setUserDefinedAttribute(atrName, val); 073 } 074 } 075 076 public Object get(String atrName) { 077 Object ret = null; 078 if (atrName.equals(LABEL)) { 079 ret = v.getLabel(); 080 } else if (atrName.equals(SHAPE)) { 081 ret = v.getShape(); 082 } else if (atrName.equals(BORDER)) { 083 ret = v.getShapeStroke(); 084 } else if (atrName.equals(LOCATION)) { 085 ret = v.getLocation(); 086 } else if (atrName.equals(SIZE)) { 087 ret = v.getSize(); 088 } else if (atrName.equals(MARK)) { 089 ret = v.getMark(); 090 } else if (atrName.equals(SELECTED)) { 091 ret = v.isSelected; 092 } else if (atrName.equals(COLOR)) { 093 ret = v.getColor(); 094 } else if (atrName.equals(LABEL_LOCATION)) { 095 ret = v.getLabelLocation(); 096 } else { 097 ret = v.getUserDefinedAttribute(atrName); 098 } 099 return ret; 100 } 101 102 }