/* * Mind.java * * @author asko.soukka@iki.fi * @version 0.1 * * Copyright (c) 2002 Asko Soukka * GZigZag is written by Tuomas Lukka * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * See the LICENSE.lgpl for the specific terms of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. */ /* * Written by Asko Soukka and Tuukka Hastrup */ package org.gzigzag.module; import org.gzigzag.*; import java.util.*; import java.io.*; import java.awt.*; /** Mindmap tools from Asko Soukka for mainly hierarcical structures */ public class Mind { public static final String rcsid = "$Id: Mind.java,v 1.1.2.2 2002/02/16 15:46:58 tuukkah Exp $"; public static boolean dbg = false; static final void p(String s) { if(dbg) ZZLogger.log(s); } static final void pa(String s) { ZZLogger.log(s); } static public ZZModule module = new ZZModule() { public ZOb newZOb(String id) { if(id.equals("Sundew")) return new MindSundew(); else if(id.equals("Sun")) return new MindSun(); return null; } public void action(String id, ZZCell code, ZZCell target, ZZView v, ZZView cv, String key, Point pt, ZZScene xi) { try { ZZCell viewCell = v.getViewcell(); ZZCell viewCursor = ZZCursorReal.get(viewCell); if(id.equals("TextOut")) { FileWriter fileout = new FileWriter(target.getText() + ".txt"); BufferedWriter writer = new BufferedWriter(fileout); writer.write(target.getText()+"\n"); if (target.s("d.1", 1) != null) { writer.write("\n"); printTextTree("d.2", "d.1", target.s("d.1", 1), writer, 1, 10); writer.write("\n"); } writer.close(); } else if(id.equals("HtmlOut")) { FileWriter fileout = new FileWriter(target.getText()+".html"); BufferedWriter writer = new BufferedWriter(fileout); writer.write("\n"); writer.write("\n"); writer.write(target.getText()+"\n"); writer.write("\n"); writer.write("\n"); writer.write("

" + target.getText() + "

\n"); if (target.s("d.1", 1) != null) { writer.write("\n"); printHtmlTree("d.2", "d.1", "d.clone", target.s("d.1", 1), writer, 1, 10, 2); writer.write("\n"); } writer.write("\n"); writer.write("\n"); writer.close(); } else { pa("UNKNOWN Mind COMMAND "+id); } } catch(Exception e) { e.printStackTrace(); throw new ZZError(""+e); } } }; private static void printTextTree(String dim, String dimTop, ZZCell accursed, BufferedWriter writer, int start, int end) { Vector cells = getAllCells(dim, accursed); int i = 0; try { while (i < cells.size()) { if (!((ZZCell)cells.elementAt(i)).getText().equals("")) { writer.write(/*"
  • "+*/((ZZCell)cells.elementAt(i)).getText()+"\n"); } if (((ZZCell)cells.elementAt(i)).s(dimTop, 1) != null) { for (int j=0; j topics) writer.write("\n"); } catch (IOException iOE) {} } private static Vector getAllCells(String dim, ZZCell accursed) { int LIMIT = 1000; Vector cells = new Vector(); ZZCell next = null; cells.addElement(accursed); int i = 1; while (cells.size() < LIMIT ) { next = accursed.s(dim, i++); if(next != null && !cells.contains(next)) cells.addElement(next); else break; } return cells; } }