// File: SGraphNode.java // Classes: SGraphNode // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.util.Enumeration; import javax.swing.tree.DefaultMutableTreeNode; /* Purpose : Responsible for presenting the strategy graph information */ public class SGraphNode implements Behdata { private String _name; private EditorMenus _menu; private int _count; public SGraphNode(String name,EditorMenus menu) { _name =name; _menu= menu; _count =0; } public String toString(){return _name;} public void setName(String name){_name = name;} public void setMenu(){_menu.setMenuforSGraph();} public String getDescription(){return "graph details not available";} public String nextEdgeName(){return "SEdge_"+ ++_count;} public String getString(DefaultMutableTreeNode node) { // If the graph is empty return null as it is not savable if(node.getChildCount()<1) return null; if( ! (node.getUserObject() instanceof SGraphNode) ) // should never happen return null; // If one of the strategy edges is not valid return null Enumeration enum = node.children(); String stratGraphString=new String(); while(enum.hasMoreElements()) { DefaultMutableTreeNode edgeNode = (DefaultMutableTreeNode)enum.nextElement(); SEdgeNode edge = (SEdgeNode)edgeNode.getUserObject(); int status = edge.get_status(); if(status!=SEdgeNode.VALID) return null; String stratDefinition = edge.getDescription(); stratGraphString +=stratDefinition; stratGraphString +="\n"; } return "{\n"+stratGraphString+"}\n"; } }