/* Loom.java * * Copyright (c) 2003 by Benja Fallenstein * * This file is part of Fenfire. * * Fenfire 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. * * Fenfire 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 Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * */ /* * Written by Benja Fallenstein */ package org.fenfire.loom; import org.nongnu.libvob.*; import org.nongnu.libvob.impl.DefaultVobMatcher; import org.nongnu.libvob.vobs.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.util.List; import com.hp.hpl.mesa.rdf.jena.model.*; import com.hp.hpl.mesa.rdf.jena.mem.*; /** The key and mouse bindings for Loom. * Not tested at this time. */ public class LoomBindings implements Binder { protected Screen screen; protected Loom loom; public LoomBindings(Loom loom) { this.loom = loom; } public void keystroke(String s) { System.out.println("Keystroke: "+s); if(s.equals("Ctrl-Q")) System.exit(0); if(loom.model == null) return; if(loom.view.isWheelView()) { if(s.equals("i") || s.equals("Up") || s.equals(",") || s.equals("Down")) return; if(s.equals("m") || s.equals("n") || s.equals("o")) s = "Up"; else if(s.equals("u") || s.equals(".")) s = "Down"; } else if(loom.view.isSimpleView()) { if(s.equals("u") || s.equals("o")) s = "Up"; else if(s.equals("m") || s.equals("n") || s.equals(".")) s = "Down"; } if(s.equals("Ctrl-G")) loom.showGoToDialog(); else if(s.equals("i") || s.equals("Up")) loom.cursor.rotate(-1); else if(s.equals(",") || s.equals("Down")) loom.cursor.rotate(1); else if(s.equals("j") || s.equals("Left")) { RDFNode node = loom.cursor.getRotationNode(-1); if(node == null || !(node instanceof Resource)) return; loom.lastFocus = new NodeView.Nodespec(loom.cursor.focus); List l = new ArrayList(loom.cursor.getConnections(-1)); Statement stmt = (Statement)l.get(loom.cursor.getRotationIndex(-1)); loom.lastRotation = new NodeView.Nodespec(stmt.getSubject(), stmt.getPredicate(), -1); loom.cursor.move(-1); } else if(s.equals("l") || s.equals("Right")) { RDFNode node = loom.cursor.getRotationNode(1); if(node == null || !(node instanceof Resource)) return; loom.lastFocus = new NodeView.Nodespec(loom.cursor.focus); List l = new ArrayList(loom.cursor.getConnections(1)); Statement stmt = (Statement)l.get(loom.cursor.getRotationIndex(1)); loom.lastRotation = new NodeView.Nodespec(stmt.getObject(), stmt.getPredicate(), 1); loom.cursor.move(1); } else if(s.equals("PgUp")) // previous view wanted loom.view.changeView(-1); else if(s.equals("PgDown")) // next view wanted loom.view.changeView(1); AbstractUpdateManager.chg(); } public void mouse(MouseEvent m) { if(m.getID() != m.MOUSE_CLICKED) return; VobScene vs = screen.getVobSceneForEvents(); int cs = vs.coords.getCSAt(0, m.getX(), m.getY(), null); if(cs < 0) return; Object key = vs.matcher.getKey(cs); NodeView.Nodespec spec = (NodeView.Nodespec)key; if((m.getModifiers() & m.BUTTON3_MASK) > 0 || spec.node instanceof Literal) { loom.cursor.set(loom.cursor.focus, spec.dir, spec.node); AbstractUpdateManager.chg(); } else { loom.lastFocus = new NodeView.Nodespec(loom.cursor.focus); loom.lastRotation = spec; loom.cursor.set((Resource)spec.node, -spec.dir, loom.cursor.focus); AbstractUpdateManager.chg(); } } public void setScreen(Screen s) { this.screen = s; } public void timeout(Object id) {} public void windowClosed() { System.exit(0); } }