// File: CdView.jaa // Classes: CdView // Authors: Fred DiPrizito // Date 3 March 1997 // // Modified by: Kevin Carlson, David Boatwright package uci.graphedit; import gjt.DialogClient; import java.awt.*; import java.util.Vector; import java.util.Enumeration; import java.util.Hashtable; import demeter.Ident; import uml2text.*; /* View the current cd */ public class CdView extends Frame{ // Components Button dismiss, refresh; TextArea cd_text; Panel button_panel, text_panel; BorderLayout borderlayout = new BorderLayout(); GridLayout grid = new GridLayout( 1, 2 ); Document document; // Constructor CdView( Document doc ){ // Name this window and set it up super("Cd-File: " + doc.getDocName() ); setLayout( borderlayout ); resize( 400, 600); //store the current document in the curr obj document = doc; // Create the Buttons dismiss = new Button( "Dismiss" ); refresh = new Button( "Refresh" ); // Create the text area cd_text = new TextArea(24, 80); cd_text.setEditable(false); // Currently the following does not work so I commented it out. // When the UML2Text project's UGraph structure is added then // this should work with minor modifications // try{ // UGraph test = UGraph.parse( this.get_graph(document) ); // cd_text.setText( test.PrintVertices() ); // } // catch( Exception e ){ // } cd_text.setText("Not yet implemented. See CdView.java source for details"); // create a button panel button_panel = new Panel(); button_panel.setLayout( grid ); button_panel.add( dismiss ); button_panel.add( refresh ); // add the text area and the buttons to the window add( "Center", cd_text ); add( "South", button_panel ); show(); } public boolean action( Event event, Object arg ){ if ( event.target == dismiss ){ this.hide(); this.dispose(); return( true ); } if ( event.target == refresh ){ cd_text.setText( this.get_graph( document) ); return( true ); } else{ return( false ); } } // function to convert the documents graph information to gcd format private String get_graph( Document document ){ if ( document == null ){ return( "# -- NO DATA --"); } UGraph graph = new UGraph(); Vector nodes = document.net().nodes(); Enumeration elm = nodes.elements(); Hashtable hTable = new Hashtable(); while (elm.hasMoreElements()) { NetNode n=(NetNode)elm.nextElement(); Point p=n.get_Perspective().position(); Coordinates c=new Coordinates(new X(new Integer(p.x)),new Y(new Integer(p.y))); String name=n.get_Perspective().get_first().get_label(); UID uid=new UID(new Integer(n.getId())); UVertex u; if (n.get_Perspective().get_first() instanceof FigAltVert) u=new UAltVertex(); else if (n.outSize()==0) u=new UTerm(); else u=new UConstVertex(); u.set_id(uid); u.set_vertexname(new UVertexName(new Ident(name))); u.set_position(c); Vector in=n.inList(); Enumeration inEdges = in.elements(); while(inEdges.hasMoreElements()) { UID id=new UID(new Integer(((NetArc)inEdges.nextElement()).getId())); u.add_incoming(id); } Vector out=n.outList(); Enumeration outEdges = out.elements(); while(outEdges.hasMoreElements()) { UID id=new UID(new Integer(((NetArc)outEdges.nextElement()).getId())); u.add_outgoing(id); } hTable.put(name,u); graph.add_uvertex(u); } Enumeration elm1 = nodes.elements(); while (elm1.hasMoreElements()) { NetNode n=(NetNode)elm1.nextElement(); String source=n.get_Perspective().get_first().get_label(); Vector out=n.outList(); Enumeration outEdges = out.elements(); while(outEdges.hasMoreElements()) { NetArc na=(NetArc)(outEdges.nextElement()); ArcPerspective ap=na.get_perspective(); Fig f=ap.get_figure(); String dest=na.destNode().get_Perspective().get_first().get_label(); UID id=new UID(new Integer(na.getId())); UEdge u; if (f instanceof FigConstEdge) { u=new UConstEdge(); ((UConstEdge)u).set_edgename(new UEdgeName(new Ident(f.get_label()))); Cardinality c; String card=((FigConstEdge)f).get_cardinality(); if (card.equals("1")) c=new Cardinality(new Lower(new Integer(1)),null); else if (card.equals("0..1")) c=new Cardinality(new Lower(new Integer(0)), new Upper(new String("1"))); else if (card.equals("0..*")) c=new Cardinality(new Lower(new Integer(0)), new Upper(new String("*"))); else c=new Cardinality(new Lower(new Integer(1)), new Upper(new String("*"))); ((UConstEdge)u).set_card(c); } else u=new UAltEdge(); u.set_id(id); if(hTable.get(source)==null) {System.out.println("problem source");return( "-- Error -- " );} if(hTable.get(dest)==null) {System.out.println("problem");return( "-- Error -- " );} u.set_fromVertex((UVertex)hTable.get(source)); u.set_toVertex((UVertex)hTable.get(dest)); graph.add_uedge(u); } } if(graph!=null) { return ( graph.GetGraphString() ); } else { return( "--- No Data ---"); } } }