Code Search for Developers
 
 
  

Loom.java from gzz at Krugle


Show Loom.java syntax highlighted

/*
Loom.java
 *
 *    Copyright (c) 2003 by Benja Fallenstein
 *
 *    This file is part of Gzz.
 *    
 *    Gzz is free software; you can redistribute it and/or modify it under
 *    the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *    
 *    Gzz 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 Lesser General
 *    Public License for more details.
 *    
 *    You should have received a copy of the GNU Lesser General
 *    Public License along with Gzz; if not, write to the Free
 *    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 */
/*
 * Written by Benja Fallenstein
 */
package gzz.loom;
import gzz.client.*;
import gzz.vob.*;
import gzz.vob.vobs.*;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.io.*;
import java.util.*;

import com.hp.hpl.mesa.rdf.jena.model.*;
import com.hp.hpl.mesa.rdf.jena.mem.*;

/** A sample app loading an RDF file and showing part of it.
 *  Currently used to verify visually that the tests really work.
 *  May evolve into the main Loom app in the future :-)
 */
public class Loom {

    protected Class[] viewclasses = {
	SimpleView.class, 
	WheelView.class
    };
    int viewcur = 0;

    public static Model load(String filename) throws RDFException, 
						     IOException {
	Model model = new ModelMem();
	model.read(new java.io.FileReader(filename), "");
        return model;
    }

    public static void main(String[] args) throws RDFException, IOException {
	String file = "";

	System.err.println("Fenfire Loom starting...");

	if(args.length < 1) {
	    System.err.println("Please give as an argument a filename of "+
			       "the RDF file to load.");
	    System.exit(1);
	} else if(args.length == 1) {
	    file = args[0];
	} else {
	    System.err.println("You gave "+args.length+" arguments.");
	    System.err.println("Please only give one filename of an RDF file");
	    System.exit(1);
	}

	new Loom(file);
    }

    public Loom(String file) throws RDFException, IOException {

	final Model model = load(file);
	final Statement stmt = model.listStatements().next();
	final GraphicsAPI api = GraphicsAPI.getInstance();

	final Comparator order = new Comparator() {
		public int compare(Object o1, Object o2) {
		    return o1.hashCode() - o2.hashCode();
		}
	    };
	final Cursor cursor = 
	    new Cursor(order, stmt.getSubject(), 1, stmt.getObject());

	final TextStyle style = api.getTextStyle("Serif", 0, 12);
	final NodeView nodeView = new NodeView() {
		public void render(VobScene sc, int into, RDFNode node, 
				   int dir) {
		    RectBgVob bg = new RectBgVob();
		    if(node.equals(cursor.getRotationNode(dir))) // if selected
			bg.addColor(Color.red);
		    if(!(node instanceof Resource)) // if literal
			bg.addColor(Color.yellow);
		    sc.map.put(bg, into);
		    String s = node.toString();
		    if(s.length() > 25) s = s.substring(s.length()-25);
		    sc.map.put(new TextVob(style, s), 
			       sc.unitSqCS(into, "text"));
		}
	    };
	final Shower s = new Shower() {
		Screen screen;
		public void setScreen(Screen s) {
		    this.screen = s;
		}
		public VobScene generate() {
		    VobScene sc = this.screen.window.createVobScene();
		    sc.map.put(new SolidBackdropVob(java.awt.Color.white), 0);
		    View view;
		    try {
			view = (View) viewclasses[viewcur]
			    .getConstructor(new Class[] {NodeView.class})
			    .newInstance(new Object[] {nodeView});
		    } catch (Exception e) {
			e.printStackTrace();
			return null;
		    }

		    view.render(sc, 0, cursor);
		    return sc;
		}
		public void chg() {}
	    };
	final Binder b = new Binder() {
		public void keystroke(String s) {
		    System.out.println("Keystroke: "+s);
		    if(s.equals("Up"))
			cursor.rotate(-1);
		    else if(s.equals("Down"))
			cursor.rotate(1);
		    else if(s.equals("Left"))
			cursor.move(-1);
		    else if(s.equals("Right"))
			cursor.move(1);
		    else if(s.equals("PgUp")) // previous view wanted
			viewcur = (viewcur-1+viewclasses.length) 
			    % viewclasses.length;
		    else if(s.equals("PgDown")) // next view wanted
			viewcur = (viewcur+1) % viewclasses.length;

		    AbstractUpdateManager.chg();
		}
		public void mouse(MouseEvent m) {}
		public void setScreen(Screen s) {}
		public void timeout(Object id) {}
		public void windowClosed() {}
	    };

	api.startUpdateManager(new Runnable() {
		public void run() {
		    Screen scr = new Screen(api.createWindow(), b, s);
		    AbstractUpdateManager.addWindow(scr);
		    scr.window.setLocation(0, 0, 300, 300);
		    AbstractUpdateManager.chg();
		}
	    });
    }
}




See more files for this project here

gzz

An implementation of Ted Nelson's ZZstructure. ZZstructure is a new type of programming platform for structured data.

Project homepage: http://savannah.nongnu.org/projects/gzz
Programming language(s): C++,Java,Python
License: lgpl21

  Cursor.java
  Loom.java
  NodeView.java
  SimpleView.java
  View.java
  WheelView.java