40 |
import com.hp.hpl.mesa.rdf.jena.mem.*; |
import com.hp.hpl.mesa.rdf.jena.mem.*; |
41 |
|
|
42 |
/** The main Fenfire Loom application. |
/** The main Fenfire Loom application. |
43 |
|
* The code in this class is currently not tested. |
44 |
*/ |
*/ |
45 |
public class Loom { |
public class Loom { |
46 |
|
|
64 |
NamespaceMap names = new NamespaceMap(); |
NamespaceMap names = new NamespaceMap(); |
65 |
names.loadMappings(new java.io.FileReader(file)); |
names.loadMappings(new java.io.FileReader(file)); |
66 |
|
|
|
initialize(names); |
|
|
} |
|
|
|
|
|
/** Initialize the cursor and PUI after a model has been loaded. |
|
|
*/ |
|
|
protected void initialize(NamespaceMap names) throws RDFException, IOException, |
|
|
org.xml.sax.SAXException { |
|
|
Collection classes = new TreeSet(names.getComparator()); |
|
|
classes.addAll(ModelUtil.getClasses(model)); |
|
|
classes = new ArrayList(classes); |
|
|
|
|
67 |
propertiesBox.setModel(model, names); |
propertiesBox.setModel(model, names); |
68 |
|
|
69 |
Statement stmt = model.listStatements().next(); |
Statement stmt = model.listStatements().next(); |
72 |
propertiesBox.getStatementSelector(), names, |
propertiesBox.getStatementSelector(), names, |
73 |
stmt.getSubject(), 1, stmt.getObject()); |
stmt.getSubject(), 1, stmt.getObject()); |
74 |
|
|
75 |
List properties = |
menuBar.setModel(model, names); |
|
new ArrayList(ModelUtil.getNonNumericProperties(model)); |
|
|
Collections.sort(properties, names.getComparator()); |
|
|
|
|
|
showClassMenu.removeAll(); |
|
|
showClassBy.clear(); |
|
|
classes.add(null); |
|
|
for(Iterator j=classes.iterator(); j.hasNext();) { |
|
|
final Resource cls = (Resource)j.next(); |
|
|
Menu menu; |
|
|
if(cls != null) |
|
|
menu = new Menu(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 _) { |
|
|
showClassBy.remove(cls); |
|
|
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 "+cursor.names.getAbbrev(prop.toString())); |
|
|
menu.add(mi); |
|
|
mi.addActionListener(new ActionListener() { |
|
|
public void actionPerformed(ActionEvent _) { |
|
|
if(cls != null) |
|
|
showClassBy.put(cls, prop); |
|
|
else |
|
|
showNoClassBy = prop; |
|
|
AbstractUpdateManager.chg(); |
|
|
} |
|
|
}); |
|
|
} |
|
|
} |
|
76 |
} |
} |
77 |
|
|
78 |
protected Frame propFrame = new Frame("Properties"); |
protected Frame propFrame = new Frame("Properties"); |
79 |
|
|
80 |
protected Dialog goTo; |
protected Dialog goTo; |
81 |
protected TextField goToText; |
protected TextField goToText; |
82 |
|
|
83 |
|
protected LoomMenuBar menuBar = new LoomMenuBar(this); |
84 |
|
|
85 |
protected void showGoToDialog() { |
protected void showGoToDialog() { |
86 |
String uri = cursor.focus.getURI(); |
String uri = cursor.focus.getURI(); |
87 |
|
if(uri == null) uri = ""; |
88 |
goToText.setText(uri); |
goToText.setText(uri); |
89 |
goToText.setCaretPosition(uri.length()); |
goToText.setCaretPosition(uri.length()); |
90 |
goTo.setVisible(true); |
goTo.setVisible(true); |
115 |
|
|
116 |
protected Map showClassBy = new HashMap(); |
protected Map showClassBy = new HashMap(); |
117 |
protected Property showNoClassBy = null; |
protected Property showNoClassBy = null; |
|
protected Menu showClassMenu = new Menu("Show class"); |
|
118 |
|
|
119 |
public Loom(String file, ColorScheme colors0) |
public Loom(String file, ColorScheme colors0) |
120 |
throws RDFException, IOException, org.xml.sax.SAXException { |
throws RDFException, IOException, org.xml.sax.SAXException { |
123 |
load(new File(file)); |
load(new File(file)); |
124 |
this.colors = colors0; |
this.colors = colors0; |
125 |
|
|
|
final MenuBar mBar = new MenuBar(); |
|
|
Menu mFile = new Menu("File"); mBar.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"); mBar.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 _) { |
|
|
fileDialog.show(); |
|
|
if(fileDialog.getFile() != null) { |
|
|
try { |
|
|
load(new File(fileDialog.getDirectory(), 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 _) { |
|
|
showGoToDialog(); |
|
|
} |
|
|
}); |
|
|
|
|
|
mWheel.addActionListener(new ActionListener() { |
|
|
public void actionPerformed(ActionEvent _) { |
|
|
view.setWheelView(); |
|
|
AbstractUpdateManager.chg(); |
|
|
} |
|
|
}); |
|
|
|
|
|
mSimple.addActionListener(new ActionListener() { |
|
|
public void actionPerformed(ActionEvent _) { |
|
|
view.setSimpleView(); |
|
|
AbstractUpdateManager.chg(); |
|
|
} |
|
|
}); |
|
|
|
|
126 |
propFrame.setBounds(350, 300, 350, 200); |
propFrame.setBounds(350, 300, 350, 200); |
127 |
propFrame.add(propertiesBox); |
propFrame.add(propertiesBox); |
128 |
propertiesBox.addItemListener(new ItemListener() { |
propertiesBox.addItemListener(new ItemListener() { |
375 |
|
|
376 |
fileDialog = new FileDialog(frame, "Open", |
fileDialog = new FileDialog(frame, "Open", |
377 |
FileDialog.LOAD); |
FileDialog.LOAD); |
378 |
frame.setMenuBar(mBar); |
frame.setMenuBar(menuBar); |
379 |
AbstractUpdateManager.addWindow(scr); |
AbstractUpdateManager.addWindow(scr); |
380 |
scr.window.setLocation(0, 0, 640, 400); |
scr.window.setLocation(0, 0, 640, 400); |
381 |
propFrame.setVisible(true); |
propFrame.setVisible(true); |