39 |
import com.hp.hpl.mesa.rdf.jena.model.*; |
import com.hp.hpl.mesa.rdf.jena.model.*; |
40 |
import com.hp.hpl.mesa.rdf.jena.mem.*; |
import com.hp.hpl.mesa.rdf.jena.mem.*; |
41 |
|
|
42 |
/** A sample app loading an RDF file and showing part of it. |
/** The main Fenfire Loom application. |
|
* Currently used to verify visually that the tests really work. |
|
|
* May evolve into the main Loom app in the future :-) |
|
43 |
*/ |
*/ |
44 |
public class Loom { |
public class Loom { |
45 |
|
|
46 |
protected View[] views; |
protected ViewSettings view; |
|
int viewcur = 0; |
|
47 |
|
|
48 |
protected ColorScheme colors; |
protected ColorScheme colors; |
49 |
|
|
50 |
protected Model model; |
protected Model model; |
51 |
|
protected Cursor cursor; |
52 |
protected RDFVocab rdf; |
protected RDFVocab rdf; |
|
protected NamespaceMap names; |
|
53 |
|
|
54 |
protected Cursor cursor; |
protected PropertiesBox propertiesBox = new PropertiesBox(); |
55 |
|
|
56 |
protected boolean isNumberProp(Property p) { |
public void load(File file) throws RDFException, IOException, |
|
return p.toString().startsWith( |
|
|
"http://www.w3.org/1999/02/22-rdf-syntax-ns#_"); |
|
|
} |
|
|
|
|
|
public void load(File file) throws RDFException, |
|
|
IOException, |
|
57 |
org.xml.sax.SAXException { |
org.xml.sax.SAXException { |
58 |
model = new ModelMem(); |
model = new ModelMem(); |
59 |
rdf = new RDFVocab(model); |
rdf = new RDFVocab(model); |
60 |
|
|
61 |
model.read(new java.io.FileReader(file), ""); |
model.read(new java.io.FileReader(file), ""); |
62 |
|
|
63 |
names = new NamespaceMap(); |
NamespaceMap names = new NamespaceMap(); |
64 |
names.loadMappings(new java.io.FileReader(file)); |
names.loadMappings(new java.io.FileReader(file)); |
65 |
|
|
66 |
Comparator compareByAbbrev = names.getComparator(); |
initialize(names); |
67 |
|
} |
68 |
|
|
69 |
Collection classes = new TreeSet(compareByAbbrev); |
/** Initialize the cursor and PUI after a model has been loaded. |
70 |
|
*/ |
71 |
|
protected void initialize(NamespaceMap names) throws RDFException, IOException, |
72 |
|
org.xml.sax.SAXException { |
73 |
|
Collection classes = new TreeSet(names.getComparator()); |
74 |
classes.addAll(ModelUtil.getClasses(model)); |
classes.addAll(ModelUtil.getClasses(model)); |
75 |
classes = new ArrayList(classes); |
classes = new ArrayList(classes); |
|
|
|
|
properties = new ArrayList(ModelUtil.getProperties(model)); |
|
|
Collections.sort(properties, compareByAbbrev); |
|
|
|
|
|
numericPropertiesAccepted = true; |
|
|
acceptedProperties = new HashSet(properties); |
|
|
|
|
|
propList.setMultipleMode(true); |
|
|
propList.removeAll(); |
|
|
propList.add("rdf:_n properties"); |
|
|
propList.select(0); |
|
|
int i=1; |
|
|
for(Iterator iter=properties.iterator(); iter.hasNext();) { |
|
|
Property p = (Property)iter.next(); |
|
|
propList.add(names.getAbbrev(p.toString())); |
|
|
propList.select(i); |
|
|
i++; |
|
|
} |
|
76 |
|
|
77 |
|
propertiesBox.setModel(model, names); |
78 |
|
|
79 |
Statement stmt = model.listStatements().next(); |
Statement stmt = model.listStatements().next(); |
80 |
cursor = |
cursor = |
81 |
new Cursor(SimpleOrder.subjOrder, SimpleOrder.objOrder, |
new Cursor(SimpleOrder.subjOrder, SimpleOrder.objOrder, |
82 |
new StatementSelector.SimpleSelector() { |
propertiesBox.getStatementSelector(), names, |
|
protected boolean accept(Statement s) { |
|
|
Property p = s.getPredicate(); |
|
|
if(isNumberProp(p)) |
|
|
return numericPropertiesAccepted; |
|
|
return acceptedProperties.contains(p); |
|
|
} |
|
|
}, |
|
83 |
stmt.getSubject(), 1, stmt.getObject()); |
stmt.getSubject(), 1, stmt.getObject()); |
84 |
|
|
85 |
|
List properties = |
86 |
|
new ArrayList(ModelUtil.getNonNumericProperties(model)); |
87 |
|
Collections.sort(properties, names.getComparator()); |
88 |
|
|
89 |
showClassMenu.removeAll(); |
showClassMenu.removeAll(); |
90 |
showClassBy.clear(); |
showClassBy.clear(); |
91 |
classes.add(null); |
classes.add(null); |
93 |
final Resource cls = (Resource)j.next(); |
final Resource cls = (Resource)j.next(); |
94 |
Menu menu; |
Menu menu; |
95 |
if(cls != null) |
if(cls != null) |
96 |
menu = new Menu(names.getAbbrev(cls.toString())); |
menu = new Menu(cursor.names.getAbbrev(cls.toString())); |
97 |
else |
else |
98 |
menu = new Menu("All others"); |
menu = new Menu("All others"); |
99 |
showClassMenu.add(menu); |
showClassMenu.add(menu); |
108 |
MenuItem sep = new MenuItem("-"); menu.add(sep); |
MenuItem sep = new MenuItem("-"); menu.add(sep); |
109 |
for(Iterator k=properties.iterator(); k.hasNext();) { |
for(Iterator k=properties.iterator(); k.hasNext();) { |
110 |
final Property prop = (Property)k.next(); |
final Property prop = (Property)k.next(); |
111 |
MenuItem mi = new MenuItem("by "+names.getAbbrev(prop.toString())); |
MenuItem mi = new MenuItem("by "+cursor.names.getAbbrev(prop.toString())); |
112 |
menu.add(mi); |
menu.add(mi); |
113 |
mi.addActionListener(new ActionListener() { |
mi.addActionListener(new ActionListener() { |
114 |
public void actionPerformed(ActionEvent _) { |
public void actionPerformed(ActionEvent _) { |
123 |
} |
} |
124 |
} |
} |
125 |
|
|
|
protected List properties; |
|
|
protected Set acceptedProperties; |
|
|
protected boolean numericPropertiesAccepted; |
|
|
|
|
126 |
protected Frame propFrame = new Frame("Properties"); |
protected Frame propFrame = new Frame("Properties"); |
|
protected java.awt.List propList = new java.awt.List(); |
|
127 |
|
|
128 |
protected Dialog goTo; |
protected Dialog goTo; |
129 |
protected TextField goToText; |
protected TextField goToText; |
210 |
|
|
211 |
mWheel.addActionListener(new ActionListener() { |
mWheel.addActionListener(new ActionListener() { |
212 |
public void actionPerformed(ActionEvent _) { |
public void actionPerformed(ActionEvent _) { |
213 |
viewcur = 0; |
view.setWheelView(); |
214 |
AbstractUpdateManager.chg(); |
AbstractUpdateManager.chg(); |
215 |
} |
} |
216 |
}); |
}); |
217 |
|
|
218 |
mSimple.addActionListener(new ActionListener() { |
mSimple.addActionListener(new ActionListener() { |
219 |
public void actionPerformed(ActionEvent _) { |
public void actionPerformed(ActionEvent _) { |
220 |
viewcur = 1; |
view.setSimpleView(); |
221 |
AbstractUpdateManager.chg(); |
AbstractUpdateManager.chg(); |
222 |
} |
} |
223 |
}); |
}); |
224 |
|
|
225 |
propFrame.setBounds(350, 300, 350, 200); |
propFrame.setBounds(350, 300, 350, 200); |
226 |
propFrame.add(propList); |
propFrame.add(propertiesBox); |
227 |
propList.addItemListener(new ItemListener() { |
propertiesBox.addItemListener(new ItemListener() { |
228 |
public void itemStateChanged(ItemEvent e) { |
public void itemStateChanged(ItemEvent e) { |
|
numericPropertiesAccepted = false; |
|
|
acceptedProperties = new HashSet(); |
|
|
|
|
|
int[] indexes = propList.getSelectedIndexes(); |
|
|
for(int i=0; i<indexes.length; i++) { |
|
|
if(indexes[i] == 0) |
|
|
numericPropertiesAccepted = true; |
|
|
else |
|
|
acceptedProperties.add(properties.get(indexes[i]-1)); |
|
|
} |
|
|
|
|
229 |
// the rotation cannot be sanely kept |
// the rotation cannot be sanely kept |
230 |
// when properties are added or removed |
// when properties are added or removed |
231 |
cursor.rotation = 0; |
cursor.rotation = 0; |
236 |
final GraphicsAPI api = GraphicsAPI.getInstance(); |
final GraphicsAPI api = GraphicsAPI.getInstance(); |
237 |
|
|
238 |
final TextStyle style = api.getTextStyle("Serif", 0, 12); |
final TextStyle style = api.getTextStyle("Serif", 0, 12); |
239 |
final NodeView nodeView = new NodeView() { |
view = new ViewSettings(new NodeView() { |
240 |
public void render(VobScene sc, int into, Nodespec spec) { |
public void render(VobScene sc, int into, Nodespec spec) { |
241 |
RDFNode node = spec.node; |
RDFNode node = spec.node; |
242 |
Property prop = spec.prop; |
Property prop = spec.prop; |
256 |
String s = node.toString(); |
String s = node.toString(); |
257 |
boolean isByClass = false; |
boolean isByClass = false; |
258 |
if(node instanceof Resource) { |
if(node instanceof Resource) { |
259 |
s = names.getAbbrev(s); |
s = cursor.names.getAbbrev(s); |
260 |
String t = s; |
String t = s; |
261 |
|
|
262 |
try { |
try { |
276 |
if(byStmt.getObject() instanceof Literal) |
if(byStmt.getObject() instanceof Literal) |
277 |
s = byStmt.getString(); |
s = byStmt.getString(); |
278 |
else |
else |
279 |
s = names.getAbbrev(byStmt.getObject().toString()); |
s = cursor.names.getAbbrev(byStmt.getObject().toString()); |
280 |
|
|
281 |
isByClass = true; |
isByClass = true; |
282 |
} |
} |
301 |
|
|
302 |
if(prop != null) { |
if(prop != null) { |
303 |
s = prop.toString(); |
s = prop.toString(); |
304 |
s = names.getAbbrev(s); |
s = cursor.names.getAbbrev(s); |
305 |
if(s.length() > 15) s = s.substring(s.length()-15); |
if(s.length() > 15) s = s.substring(s.length()-15); |
306 |
if(dir > 0) |
if(dir > 0) |
307 |
x = 0; |
x = 0; |
313 |
sc.map.put(new TextVob(style, s), propCs); |
sc.map.put(new TextVob(style, s), propCs); |
314 |
} |
} |
315 |
} |
} |
316 |
}; |
}); |
|
views = new View[] { new WheelView(nodeView), |
|
|
new SimpleView(nodeView) }; |
|
317 |
final Shower s = new Shower() { |
final Shower s = new Shower() { |
318 |
Screen screen; |
Screen screen; |
319 |
public void setScreen(Screen s) { |
public void setScreen(Screen s) { |
326 |
|
|
327 |
if(model == null) return sc; |
if(model == null) return sc; |
328 |
|
|
329 |
views[viewcur].render(sc, 0, cursor); |
view.getView().render(sc, 0, cursor); |
330 |
|
|
331 |
if(lastFocus != null) { |
if(lastFocus != null) { |
332 |
DefaultVobMatcher lm = (DefaultVobMatcher)old.matcher; |
DefaultVobMatcher lm = (DefaultVobMatcher)old.matcher; |
361 |
System.exit(0); |
System.exit(0); |
362 |
if(model == null) return; |
if(model == null) return; |
363 |
|
|
364 |
if(viewcur == 0) { |
if(view.isWheelView()) { |
365 |
if(s.equals("i") || s.equals("Up") || |
if(s.equals("i") || s.equals("Up") || |
366 |
s.equals(",") || s.equals("Down")) return; |
s.equals(",") || s.equals("Down")) return; |
367 |
if(s.equals("m") || s.equals("n") || s.equals("o")) |
if(s.equals("m") || s.equals("n") || s.equals("o")) |
368 |
s = "Up"; |
s = "Up"; |
369 |
else if(s.equals("u") || s.equals(".")) |
else if(s.equals("u") || s.equals(".")) |
370 |
s = "Down"; |
s = "Down"; |
371 |
} else { |
} else if(view.isSimpleView()) { |
372 |
if(s.equals("u") || s.equals("o")) |
if(s.equals("u") || s.equals("o")) |
373 |
s = "Up"; |
s = "Up"; |
374 |
else if(s.equals("m") || s.equals("n") || s.equals(".")) |
else if(s.equals("m") || s.equals("n") || s.equals(".")) |
404 |
stmt.getPredicate(), 1); |
stmt.getPredicate(), 1); |
405 |
cursor.move(1); |
cursor.move(1); |
406 |
} else if(s.equals("PgUp")) // previous view wanted |
} else if(s.equals("PgUp")) // previous view wanted |
407 |
viewcur = (viewcur-1+views.length) |
view.changeView(-1); |
|
% views.length; |
|
408 |
else if(s.equals("PgDown")) // next view wanted |
else if(s.equals("PgDown")) // next view wanted |
409 |
viewcur = (viewcur+1) % views.length; |
view.changeView(1); |
410 |
|
|
411 |
AbstractUpdateManager.chg(); |
AbstractUpdateManager.chg(); |
412 |
} |
} |