public void saveGraph() { if (file != null) saveGraph(file); else saveAsGraph();
private void saveGraph(File outputFile) { if (outputFile == null) return; StringBuffer colorTable = new StringBuffer(500);  Attribute ct = getAttribute(COLOR_TABLE);   String graphUID = null; if (ct == null) { InetAddress localHost = null; try { localHost = InetAddress.getLocalHost(); } catch (Exception e) { System.out.println("CSMARTGraph: Can't get local host: " + e); } graphUID = localHost.toString() + "/" + (new UID()).toString(); } Hashtable colorsWritten = new Hashtable(); GraphEnumeration ge = elements(GrappaConstants.NODE); while (ge.hasMoreElements()) { Node node = (Node)ge.nextGraphElement();  Attribute a = node.getAttribute(COLOR_DETERMINER); if (a == null) continue; String colorName = a.getStringValue(); Color c = properties.getClusterColor(colorName);  if (graphUID != null) { colorName = graphUID + "=" + colorName; node.setAttribute(COLOR_DETERMINER, colorName); } if (colorsWritten.get(colorName) != null) continue; colorsWritten.put(colorName, c); colorTable.append(colorName); colorTable.append("+"); colorTable.append(Integer.toString(c.getRed())); colorTable.append(","); colorTable.append(Integer.toString(c.getGreen())); colorTable.append(","); colorTable.append(Integer.toString(c.getBlue())); colorTable.append(";"); }  setAttribute(COLOR_TABLE, colorTable.toString());  ge = elements(GrappaConstants.EDGE); while (ge.hasMoreElements()) { Element e = ge.nextGraphElement(); e.setAttribute(GrappaConstants.COLOR_ATTR, "black"); } String pathname = outputFile.getPath(); String extension = ""; int i = pathname.lastIndexOf('.'); if (i > 0 && i < pathname.length()-1) extension = pathname.substring(i+1).toLowerCase();  if (extension.length() == 0 || !(extension.equals("dot"))) { pathname = pathname + ".dot"; outputFile = new File(pathname); extension = "dot"; } FileOutputStream fos = null; try { fos = new FileOutputStream(outputFile); PrintWriter pw = new PrintWriter(fos); printGraph(pw); fos.flush(); fos.close(); } catch (Exception e) { System.out.println("CSMARTGraph: Could not write to file:" + e); }
  public void saveGraph() {    if (file != null)      saveGraph(file);    else       saveAsGraph();  }