1 26 package org.nightlabs.editor2d.viewer.descriptor; 27 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.LinkedList ; 31 import java.util.List ; 32 import java.util.Map ; 33 34 import org.nightlabs.editor2d.DrawComponent; 35 import org.nightlabs.editor2d.viewer.ViewerPlugin; 36 37 42 public class DrawComponentDescriptor 43 implements IDrawComponentDescriptor 44 { 45 public DrawComponentDescriptor(DrawComponent dc) 46 { 47 super(); 48 setDrawComponent(dc); 49 } 50 51 protected DrawComponent dc = null; 52 53 56 public DrawComponent getDrawComponent() { 57 return dc; 58 } 59 60 64 public void setDrawComponent(DrawComponent dc) 65 { 66 this.dc = dc; 67 if (dc != null) { 68 addEntry(ViewerPlugin.getResourceString("descriptor.id.name"), ""+getDrawComponent().getId()); 69 addEntry(ViewerPlugin.getResourceString("descriptor.name.name"), getDrawComponent().getName()); 70 addEntry(ViewerPlugin.getResourceString("descriptor.x.name"), ""+getDrawComponent().getX()); 71 addEntry(ViewerPlugin.getResourceString("descriptor.y.name"), ""+getDrawComponent().getY()); 72 addEntry(ViewerPlugin.getResourceString("descriptor.width.name"), ""+getDrawComponent().getWidth()); 73 addEntry(ViewerPlugin.getResourceString("descriptor.height.name"), ""+getDrawComponent().getHeight()); 74 addEntry(ViewerPlugin.getResourceString("descriptor.rotation.name"), ""+(int)getDrawComponent().getRotation()); 75 } 76 } 77 78 protected List <String > names = new LinkedList <String >(); 79 public List <String > getNames() { 80 return names; 81 } 82 83 protected Map <String , String > properties = new HashMap <String , String >(); 84 85 88 public Map <String , String > getProperties() { 89 return properties; 90 } 91 92 95 public void addEntry(String name, String value) 96 { 97 if (!names.contains(name)) 98 names.add(name); 99 properties.put(name, value); 100 } 101 102 protected StringBuffer sb = new StringBuffer (); 103 104 136 139 public String getEntriesAsString(boolean lineWrap) 140 { 141 sb = new StringBuffer (); 142 if (!lineWrap) 143 { 144 int lastIndex = names.size()-1; 145 for (int i=0; i<lastIndex; i++) 146 { 147 String name = names.get(i); 148 String value = properties.get(name); 149 sb.append(name); 150 sb.append(" = "); 151 sb.append(value); 152 if (i != lastIndex) 153 sb.append(", "); 154 } 155 } 156 else { 157 for (Iterator <String > it = names.iterator(); it.hasNext(); ) 158 { 159 String name = it.next(); 160 String value = properties.get(name); 161 sb.append(name); 162 sb.append(" = "); 163 sb.append(value); 164 sb.append("\n"); 165 } 166 } 167 return sb.toString(); 168 } 169 170 } 171 | Popular Tags |