Commits

Anonymous committed f7cf22f

added new items to system.properties, XML factory supports locating code fragments but LIME does not

  • Participants
  • Parent commits 9aca2fa

Comments (0)

Files changed (3)

File src/nl/tudelft/lime/constants/SystemSettings.java

   public static String CODE_FRAGMENT_DEFAULT_CONTEXT;
   public static String ARC_DEFAULT_TYPE;
   public static String PORT_DEFAULT_SIZE;
+  public static String GXF_TAG;
   //Normal Icons Path
   public static String Component_Normal_Icon_Path;
   public static String Input_Port_Normal_Icon_Path;

File src/nl/tudelft/lime/xml/XMLFactory.java

     @SuppressWarnings("unchecked")
     private static void createDefaultFromXML(LimeSubpart subpart,
         Element element) {
-        subpart.setName(element.element("id").getText());
+        subpart.setName(element.element(SystemSettings.ID_TAG).getText());
 
         List<Element> metaElements = element.elements(SystemSettings.META_TAG);
 
 	                else
 	                	codeFragment.setContext((String) codeElement.elementText(SystemSettings.CONTEXT_TAG));
 	                ((LimeComponent) subpart).addChild(codeFragment);
+	                //if it has size and location read it
+	                Element contextSizeAndLocation = codeElement.element(SystemSettings.META_TAG);
+					if (contextSizeAndLocation != null && 
+	                		contextSizeAndLocation.attribute(SystemSettings.ID_ATTRIBUTE) != null &&
+	                		contextSizeAndLocation.attributeValue(SystemSettings.ID_ATTRIBUTE).equals(SystemSettings.META_TAG_VISUAL_ID)){
+		            	codeFragment.setSizeByMap(getDimensionsListMap(contextSizeAndLocation.element(
+		            			SystemSettings.SIZE_TAG)));
+		                codeFragment.setLocationByMap(getDimensionsListMap(
+		                        contextSizeAndLocation.element(SystemSettings.LOCATION_TAG)));
+					}
+	                //in both cases read location and size
+	                
                 }
             }
             //if it is an unknown tag
     @SuppressWarnings("unchecked")
     private static String createPortFromXML(Port port, Element element) {
         for (Element subElement : (List<Element>) element.elements()) {
-            if (subElement.getName().equals("type")) {
+            if (subElement.getName().equals(SystemSettings.TYPE_TAG)) {
                 //two cases happen here based on the definition of LIME
                 //1. if the element is like this <type id="something"><id>something_else<id></type>
                 //2. there is only a text value for type <type>text</type> like
 
                 // in the first case add type to embedded XMLs
-                if (subElement.attribute("id") != null) {
+                if (subElement.attribute(SystemSettings.ID_ATTRIBUTE) != null) {
                     port.getPreservedXMLElements().add(subElement.createCopy());
                 }
                 //otherwise keep it as a property of the port and show it in the visual editor in the 'properties' view
                 port.setPortStatic(Port.TRUE);
             }
             //if size is not defined it is set as default
-            else if (subElement.getName().equals("size")) {
+            else if (subElement.getName().equals(SystemSettings.SIZE_TAG)) {
                 String elementSize = subElement.getText();
 
                 if (elementSize.startsWith("(") && elementSize.endsWith(")")) {
         }
 
         //previously portId could be obtained from id attribute 
-        String portId = element.attribute("id").getValue();
+        String portId = element.attribute(SystemSettings.ID_ATTRIBUTE).getValue();
 
         //TODO:but now it is should be created from the hierarchy of the port
         //???
         } else if (part instanceof Port) {
             return SystemSettings.PORT_TAG;
         } else if (part instanceof LimeDiagram) {
-            return "gxf";
+            return SystemSettings.GXF_TAG;
         }
 
         return "";
 	
 	            codeFragmentElement.add(new DefaultCDATA(codeFragment.getLabelContents()));
 	            codeFragmentElement.add(new DefaultAttribute(SystemSettings.CONTEXT_TAG, codeFragment.getContext()));
+	            
+	            //add location and size
+//	            DefaultElement metaVisual = new DefaultElement(SystemSettings.META_TAG);
+//	            metaVisual.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, SystemSettings.META_TAG_VISUAL_ID));
+//	            metaVisual.add(createDimensionList(SystemSettings.SIZE_TAG, codeFragment.getSizeMap()));
+//	            metaVisual.add(createDimensionList(SystemSettings.LOCATION_TAG,
+//	                    codeFragment.getLocationMap()));
+//
+//	            codeFragmentElement.add(metaVisual);
+
 	            root.add(metaCode);
         	}
         }
      */
     private static void addDefaultAttributes(Element root,
         LimeSubpart limeSubpart) {
-        DefaultElement metaVisual = new DefaultElement("meta");
-        metaVisual.add(new DefaultAttribute("id", SystemSettings.META_TAG_VISUAL_ID));
+        DefaultElement metaVisual = new DefaultElement(SystemSettings.META_TAG);
+        metaVisual.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, SystemSettings.META_TAG_VISUAL_ID));
         metaVisual.add(createDimensionList(SystemSettings.SIZE_TAG, limeSubpart.getSizeMap()));
         metaVisual.add(createDimensionList(SystemSettings.LOCATION_TAG,
                 limeSubpart.getLocationMap()));
 
         root.add(metaVisual);
 
-        DefaultElement partIDElement = new DefaultElement("id");
+        DefaultElement partIDElement = new DefaultElement(SystemSettings.ID_TAG);
         partIDElement.setText(limeSubpart.getRevisedName());
         root.add(partIDElement);
 
-        DefaultElement partType = new DefaultElement("type");
+        DefaultElement partType = new DefaultElement(SystemSettings.TYPE_TAG);
         partType.setText(limeSubpart.getType());
         root.add(partType);
 
-        root.add(new DefaultAttribute("id", getParentChildPath(limeSubpart)));
+        root.add(new DefaultAttribute(SystemSettings.ID_ATTRIBUTE, getParentChildPath(limeSubpart)));
 
         root.add(new DefaultAttribute(SystemSettings.XLINK_TYPE_ATTRIBUTE, "resource"));
 
 
         for (String item : dimensions.keySet()) {
             Element dimensionElement = new DefaultElement(SystemSettings.DIMENSION_TAG);
-            dimensionElement.addAttribute("id", item);
-            dimensionElement.addAttribute("value",
+            dimensionElement.addAttribute(SystemSettings.ID_ATTRIBUTE, item);
+            dimensionElement.addAttribute(SystemSettings.VALUE_ATTRIBUTE,
                 String.valueOf(dimensions.get(item)));
             element.add(dimensionElement);
         }

File src/system.properties

 SIZE_TAG=size
 LOCATION_TAG=location
 DIMENSION_TAG=dimension
+GXF_TAG=gxf 
 ID_ATTRIBUTE=id
 VALUE_ATTRIBUTE=value
 #Normal Icons Path