31 |
import gzz.vob.vobs.*; |
import gzz.vob.vobs.*; |
32 |
|
|
33 |
import java.awt.*; |
import java.awt.*; |
34 |
import java.awt.event.ActionEvent; |
import java.awt.event.*; |
|
import java.awt.event.ActionListener; |
|
|
import java.awt.event.MouseEvent; |
|
35 |
import java.io.*; |
import java.io.*; |
36 |
import java.util.*; |
import java.util.*; |
37 |
import java.util.List; |
import java.util.List; |
51 |
protected ColorScheme colors; |
protected ColorScheme colors; |
52 |
|
|
53 |
protected Model model; |
protected Model model; |
54 |
|
protected Property typeProp; |
55 |
protected NamespaceMap names; |
protected NamespaceMap names; |
56 |
|
|
57 |
protected Cursor cursor; |
protected Cursor cursor; |
58 |
|
|
59 |
|
protected boolean isNumberProp(Property p) { |
60 |
|
return p.toString().startsWith( |
61 |
|
"http://www.w3.org/1999/02/22-rdf-syntax-ns#_"); |
62 |
|
} |
63 |
|
|
64 |
public void load(File file) throws RDFException, |
public void load(File file) throws RDFException, |
65 |
IOException, |
IOException, |
66 |
org.xml.sax.SAXException { |
org.xml.sax.SAXException { |
67 |
model = new ModelMem(); |
model = new ModelMem(); |
68 |
|
typeProp = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#", |
69 |
|
"type"); |
70 |
model.read(new java.io.FileReader(file), ""); |
model.read(new java.io.FileReader(file), ""); |
71 |
|
|
72 |
names = new NamespaceMap(); |
names = new NamespaceMap(); |
73 |
names.loadMappings(new java.io.FileReader(file)); |
names.loadMappings(new java.io.FileReader(file)); |
74 |
|
|
75 |
|
|
76 |
|
Comparator compareByAbbrev = |
77 |
|
new Comparator() { |
78 |
|
public int compare(Object o1, Object o2) { |
79 |
|
String s1 = names.getAbbrev(o1.toString()); |
80 |
|
String s2 = names.getAbbrev(o2.toString()); |
81 |
|
return s1.compareTo(s2); |
82 |
|
} |
83 |
|
}; |
84 |
|
|
85 |
|
Set props = new TreeSet(compareByAbbrev); |
86 |
|
Set classes = new TreeSet(compareByAbbrev); |
87 |
|
|
88 |
|
for(StmtIterator iter = model.listStatements(); iter.hasNext();) { |
89 |
|
Statement stmt = iter.next(); |
90 |
|
Property p = stmt.getPredicate(); |
91 |
|
if(!isNumberProp(p)) props.add(p); |
92 |
|
if(p.toString().equals( |
93 |
|
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && |
94 |
|
stmt.getObject() instanceof Resource) |
95 |
|
classes.add(stmt.getObject()); |
96 |
|
} |
97 |
|
properties = new ArrayList(props); |
98 |
|
|
99 |
|
propList.setMultipleMode(true); |
100 |
|
propList.removeAll(); |
101 |
|
propList.add("rdf:_n properties"); |
102 |
|
propList.select(0); |
103 |
|
int i=1; |
104 |
|
for(Iterator iter=properties.iterator(); iter.hasNext();) { |
105 |
|
Property p = (Property)iter.next(); |
106 |
|
propList.add(names.getAbbrev(p.toString())); |
107 |
|
propList.select(i); |
108 |
|
i++; |
109 |
|
} |
110 |
|
|
111 |
Statement stmt = model.listStatements().next(); |
Statement stmt = model.listStatements().next(); |
112 |
cursor = |
cursor = |
113 |
new Cursor(SimpleOrder.subjOrder, SimpleOrder.objOrder, |
new Cursor(SimpleOrder.subjOrder, SimpleOrder.objOrder, |
114 |
StatementSelector.simpleSelector, |
new StatementSelector.SimpleSelector() { |
115 |
|
protected boolean accept(Statement s) { |
116 |
|
Property p = s.getPredicate(); |
117 |
|
if(isNumberProp(p)) |
118 |
|
return propList.isIndexSelected(0); |
119 |
|
int i = properties.indexOf(p); |
120 |
|
return propList.isIndexSelected(i+1); |
121 |
|
} |
122 |
|
}, |
123 |
stmt.getSubject(), 1, stmt.getObject()); |
stmt.getSubject(), 1, stmt.getObject()); |
124 |
|
|
125 |
|
showClassMenu.removeAll(); |
126 |
|
showClassBy.clear(); |
127 |
|
for(Iterator j=classes.iterator(); j.hasNext();) { |
128 |
|
final Resource cls = (Resource)j.next(); |
129 |
|
Menu menu = |
130 |
|
new Menu(names.getAbbrev(cls.toString())); |
131 |
|
showClassMenu.add(menu); |
132 |
|
|
133 |
|
MenuItem byURI = new MenuItem("by URI"); menu.add(byURI); |
134 |
|
byURI.addActionListener(new ActionListener() { |
135 |
|
public void actionPerformed(ActionEvent _) { |
136 |
|
showClassBy.remove(cls); |
137 |
|
} |
138 |
|
}); |
139 |
|
MenuItem sep = new MenuItem("-"); menu.add(sep); |
140 |
|
for(Iterator k=properties.iterator(); k.hasNext();) { |
141 |
|
final Property prop = (Property)k.next(); |
142 |
|
MenuItem mi = new MenuItem("by "+names.getAbbrev(prop.toString())); |
143 |
|
menu.add(mi); |
144 |
|
mi.addActionListener(new ActionListener() { |
145 |
|
public void actionPerformed(ActionEvent _) { |
146 |
|
showClassBy.put(cls, prop); |
147 |
|
AbstractUpdateManager.chg(); |
148 |
|
} |
149 |
|
}); |
150 |
|
} |
151 |
|
} |
152 |
} |
} |
153 |
|
|
154 |
|
protected List properties; |
155 |
|
protected Frame propFrame = new Frame("Properties"); |
156 |
|
protected java.awt.List propList = new java.awt.List(); |
157 |
|
|
158 |
public static void main(String[] args) throws RDFException, IOException, |
public static void main(String[] args) throws RDFException, IOException, |
159 |
org.xml.sax.SAXException { |
org.xml.sax.SAXException { |
160 |
String file = null; |
String file = null; |
161 |
|
|
162 |
System.err.println("Fenfire Loom starting..."); |
System.err.println("Fenfire Loom starting..."); |
163 |
|
|
164 |
if(args.length == 1) { |
if(args.length == 1 && !args[0].trim().equals("")) { |
165 |
file = args[0]; |
file = args[0]; |
166 |
} else if(args.length > 1) { |
} else if(args.length > 1) { |
167 |
System.err.println("You gave "+args.length+" arguments."); |
System.err.println("You gave "+args.length+" arguments."); |
178 |
protected Frame frame; |
protected Frame frame; |
179 |
protected FileDialog fileDialog; |
protected FileDialog fileDialog; |
180 |
|
|
181 |
|
protected Map showClassBy = new HashMap(); |
182 |
|
protected Menu showClassMenu = new Menu("Show class"); |
183 |
|
|
184 |
public Loom(String file, ColorScheme colors0) |
public Loom(String file, ColorScheme colors0) |
185 |
throws RDFException, IOException, org.xml.sax.SAXException { |
throws RDFException, IOException, org.xml.sax.SAXException { |
186 |
|
|
192 |
Menu mFile = new Menu("File"); mBar.add(mFile); |
Menu mFile = new Menu("File"); mBar.add(mFile); |
193 |
MenuItem mOpen = new MenuItem("Open..."); mFile.add(mOpen); |
MenuItem mOpen = new MenuItem("Open..."); mFile.add(mOpen); |
194 |
MenuItem mQuit = new MenuItem("Quit"); mFile.add(mQuit); |
MenuItem mQuit = new MenuItem("Quit"); mFile.add(mQuit); |
195 |
/*Menu mView = new Menu("View"); mBar.add(mView); |
Menu mView = new Menu("View"); mBar.add(mView); |
196 |
MenuItem mSimple = new CheckboxMenuItem("Simple View"); |
MenuItem mSimple = new /*Checkbox*/MenuItem("Simple View"); |
197 |
MenuItem mWheel = new CheckboxMenuItem("Wheel View"); |
MenuItem mWheel = new /*Checkbox*/MenuItem("Wheel View"); |
198 |
mView.add(mSimple); mView.add(mWheel);*/ |
mView.add(mSimple); mView.add(mWheel); |
199 |
|
mView.add(new MenuItem("-")); |
200 |
|
mView.add(showClassMenu); |
201 |
|
|
202 |
mOpen.addActionListener(new ActionListener() { |
mOpen.addActionListener(new ActionListener() { |
203 |
public void actionPerformed(ActionEvent _) { |
public void actionPerformed(ActionEvent _) { |
219 |
} |
} |
220 |
}); |
}); |
221 |
|
|
222 |
|
mSimple.addActionListener(new ActionListener() { |
223 |
|
public void actionPerformed(ActionEvent _) { |
224 |
|
viewcur = 0; |
225 |
|
AbstractUpdateManager.chg(); |
226 |
|
} |
227 |
|
}); |
228 |
|
|
229 |
|
mWheel.addActionListener(new ActionListener() { |
230 |
|
public void actionPerformed(ActionEvent _) { |
231 |
|
viewcur = 1; |
232 |
|
AbstractUpdateManager.chg(); |
233 |
|
} |
234 |
|
}); |
235 |
|
|
236 |
|
propFrame.add(propList); |
237 |
|
propList.addItemListener(new ItemListener() { |
238 |
|
public void itemStateChanged(ItemEvent e) { |
239 |
|
// the rotation cannot be sanely kept |
240 |
|
// when properties are added or removed |
241 |
|
cursor.rotation = 0; |
242 |
|
AbstractUpdateManager.chg(); |
243 |
|
} |
244 |
|
}); |
245 |
|
propFrame.setVisible(true); |
246 |
|
|
247 |
final GraphicsAPI api = GraphicsAPI.getInstance(); |
final GraphicsAPI api = GraphicsAPI.getInstance(); |
248 |
|
|
249 |
final TextStyle style = api.getTextStyle("Serif", 0, 12); |
final TextStyle style = api.getTextStyle("Serif", 0, 12); |
266 |
} |
} |
267 |
|
|
268 |
String s = node.toString(); |
String s = node.toString(); |
269 |
if(node instanceof Resource) s = names.getAbbrev(s); |
if(node instanceof Resource) { |
270 |
|
s = names.getAbbrev(s); |
271 |
|
String t = s; |
272 |
|
|
273 |
|
try { |
274 |
|
Statement typeStmt = |
275 |
|
((Resource)node).getProperty(typeProp); |
276 |
|
|
277 |
|
RDFNode type = typeStmt.getObject(); |
278 |
|
Property by = (Property)showClassBy.get(type); |
279 |
|
if(by != null) { |
280 |
|
Statement byStmt = ((Resource)node).getProperty(by); |
281 |
|
if(byStmt.getObject() instanceof Literal) |
282 |
|
s = byStmt.getString(); |
283 |
|
else |
284 |
|
s = names.getAbbrev(byStmt.getObject().toString()); |
285 |
|
} |
286 |
|
} catch(RDFException e) { |
287 |
|
s = t; |
288 |
|
} |
289 |
|
} |
290 |
if(s.length() > 27) { |
if(s.length() > 27) { |
291 |
if(node instanceof Literal) |
if(node instanceof Literal) |
292 |
s = s.substring(0, 24) + "..."; |
s = s.substring(0, 24) + "..."; |