/* 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 gzz.client.*; 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.*; /** The menu bar code for Loom. * The code in this class is currently not tested. */ public class LoomMenuBar extends MenuBar { protected Loom loom; protected Menu showClassMenu = new Menu("Show class"); public LoomMenuBar(final Loom loom) { this.loom = loom; Menu mFile = new Menu("File"); add(mFile); MenuItem mOpen = new MenuItem("Open..."); mFile.add(mOpen); MenuItem mQuit = new MenuItem("Quit (Ctrl-Q)"); mFile.add(mQuit); Menu mView = new Menu("View"); add(mView); MenuItem mGoTo = new MenuItem("Go to URI... (Ctrl-G)"); mView.add(mGoTo); mView.add(new MenuItem("-")); MenuItem mWheel = new /*Checkbox*/MenuItem("Wheel View"); MenuItem mSimple = new /*Checkbox*/MenuItem("Simple View"); mView.add(mWheel); mView.add(mSimple); mView.add(new MenuItem("-")); mView.add(showClassMenu); mOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { loom.fileDialog.show(); if(loom.fileDialog.getFile() != null) { try { loom.load(new File(loom.fileDialog.getDirectory(), loom.fileDialog.getFile())); } catch(Exception e) { e.printStackTrace(); } } AbstractUpdateManager.chg(); } }); mQuit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { System.exit(0); } }); mGoTo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { loom.showGoToDialog(); } }); mWheel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { loom.view.setWheelView(); AbstractUpdateManager.chg(); } }); mSimple.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { loom.view.setSimpleView(); AbstractUpdateManager.chg(); } }); } public void setModel(Model model, NamespaceMap names) throws RDFException { List properties = new ArrayList(ModelUtil.getNonNumericProperties(model)); Collections.sort(properties, names.getComparator()); Collection classes = new TreeSet(names.getComparator()); classes.addAll(ModelUtil.getClasses(model)); classes = new ArrayList(classes); classes.add(null); showClassMenu.removeAll(); loom.showClassBy.clear(); loom.showNoClassBy = null; for(Iterator j=classes.iterator(); j.hasNext();) { final Resource cls = (Resource)j.next(); Menu menu; if(cls != null) menu = new Menu(loom.cursor.names.getAbbrev(cls.toString())); else menu = new Menu("All others"); showClassMenu.add(menu); MenuItem byURI = new MenuItem("by URI"); menu.add(byURI); byURI.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { if(cls != null) loom.showClassBy.remove(cls); else loom.showNoClassBy = null; AbstractUpdateManager.chg(); } }); MenuItem sep = new MenuItem("-"); menu.add(sep); for(Iterator k=properties.iterator(); k.hasNext();) { final Property prop = (Property)k.next(); MenuItem mi = new MenuItem("by "+loom.cursor.names.getAbbrev(prop.toString())); menu.add(mi); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent _) { if(cls != null) loom.showClassBy.put(cls, prop); else loom.showNoClassBy = prop; AbstractUpdateManager.chg(); } }); } } } }