Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored a bit, started looking at graph zoom, added license

  • Loading branch information...
commit c2d37302209537bbfd1356d93a06af64738e6056 1 parent b9cab3f
@danja authored
View
6 data/samples/common-prefixes.ttl
@@ -0,0 +1,6 @@
+@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix dct: <http://purl.org/dc/terms/> .
+
View
102 data/samples/redland-doap.rdf
@@ -0,0 +1,102 @@
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns="http://usefulinc.com/ns/doap#">
+
+<!--
+ Though it is recommended DOAP files start with Project as the document
+ element, they can be full fledged RDF files like this one is. Just
+ don't expect the validator to work on them. You are assumed to know
+ what you're doing if you do it like this :)
+-->
+
+<Project>
+ <name>Redland RDF Application Framework</name>
+ <homepage rdf:resource="http://www.redland.opensource.ac.uk/" />
+ <created>2000-06-21</created>
+ <shortdesc xml:lang="en">
+ A library for the Resource Description Framework (RDF) allowing
+ it parsed from XML, stored, queried and
+ manipulated.
+ </shortdesc>
+
+ <description xml:lang="en">
+ Redland is a library that provides a high-level interface for
+ the Resource Description Framework (RDF) allowing the RDF graph
+ to be parsed from XML, stored, queried and manipulated. Redland
+ implements each of the RDF concepts in its own class via an
+ object based API, reflected into the language APIs, currently
+ Java, Perl, PHP, Python, Ruby and Tcl. Several classes
+ providing functionality such as for parsers, storage are built
+ as modules that can be loaded at compile or run-time as
+ required.
+ </description>
+
+ <release>
+ <Version>
+ <name>stable</name>
+ <created>2004-02-24</created>
+ <revision>0.9.16</revision>
+ </Version>
+ </release>
+
+ <mailing-list rdf:resource="http://lists.usefulinc.com/mailman/listinfo/redland-dev" />
+ <mailing-list rdf:resource="http://lists.usefulinc.com/mailman/listinfo/redland-announce" />
+ <mailing-list rdf:resource="http://lists.usefulinc.com/mailman/listinfo/redland-commits" />
+
+ <download-page rdf:resource="http://www.redland.opensource.ac.uk/dist/" />
+ <download-mirror rdf:resource="http://sourceforge.net/projects/librdf/" />
+
+ <maintainer>
+ <foaf:Person>
+ <foaf:name>Dave Beckett</foaf:name>
+ <foaf:mbox_sha1sum>970987f991961f2553a1bf2574166fa29befbccb</foaf:mbox_sha1sum>
+ <rdfs:seeAlso rdf:resource="http://www.ilrt.bris.ac.uk/people/cmdjb/webwho.xrdf" />
+ </foaf:Person>
+ </maintainer>
+
+ <!-- Freshmeat category: Database Engines/Servers -->
+ <category rdf:resource="http://software.freshmeat.net/browse/67/" />
+ <!-- Internet :: WWW/HTTP :: Indexing/Search -->
+ <category rdf:resource="http://software.freshmeat.net/browse/93/" />
+ <!-- Software Development :: Libraries -->
+ <category rdf:resource="http://software.freshmeat.net/browse/809/" />
+ <!-- Software Development :: Libraries :: Application Frameworks -->
+ <category rdf:resource="http://software.freshmeat.net/browse/810/" />
+ <!-- Text Processing :: Markup :: XML -->
+ <category rdf:resource="http://software.freshmeat.net/browse/868/" />
+
+ <!-- Sourceforge category: -->
+ <category rdf:resource="http://sourceforge.net/softwaremap/trove_list.php?form_cat=237" />
+
+ <!-- Licensing details -->
+ <license rdf:resource="http://usefulinc.com/doap/licenses/gpl" />
+ <license rdf:resource="http://usefulinc.com/doap/licenses/lgpl" />
+ <license rdf:resource="http://usefulinc.com/doap/licenses/mpl" />
+
+ <!-- source repository -->
+ <repository>
+ <CVSRepository>
+ <anon-root>:pserver:anonymous@cvs.ilrt.org:2401/cvsroot</anon-root>
+ <module>redland</module>
+ <browse rdf:resource="http://cvs.ilrt.org/cvsweb/redland/librdf/" />
+ </CVSRepository>
+ </repository>
+
+</Project>
+
+<!--
+ optional administravia:
+ authoring tools can add more here if they'd like.
+ -->
+<rdf:Description rdf:about="">
+ <foaf:maker>
+ <foaf:Person>
+ <foaf:name>Edd Dumbill</foaf:name>
+ <foaf:mbox rdf:resource="mailto:edd@usefulinc.com" />
+ </foaf:Person>
+ </foaf:maker>
+</rdf:Description>
+
+
+</rdf:RDF>
View
208 data/samples/timbl-card.n3
@@ -0,0 +1,208 @@
+# N3
+# Personal information in machine-readable form
+#
+# This (card.n3) is Tim Berners-Lee's FOAF file. It is a data file with the
+# sort of information which would be on a home page.
+# This is RDF data.
+# This is written in Notation3 - see http://www.w3.org/DesignIssues/Notation3
+# See alternatively the RDF/XML file card.rdf generated from this.
+# Use the uri <http://www.w3.org/People/Berners-Lee/card> to refer to this
+# file independent of the format.
+# Use the uri <http://www.w3.org/People/Berners-Lee/card#i> to refer to Tim BL.
+#
+@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+@prefix doap: <http://usefulinc.com/ns/doap#>.
+@prefix : <http://www.w3.org/2000/10/swap/pim/contact#>.
+@prefix s: <http://www.w3.org/2000/01/rdf-schema#>.
+@prefix cc: <http://creativecommons.org/ns#>.
+@prefix dc: <http://purl.org/dc/elements/1.1/>.
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#>.
+@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>.
+@prefix w3c: <http://www.w3.org/data#>.
+@prefix card: <http://www.w3.org/People/Berners-Lee/card#>.
+@prefix cert: <http://www.w3.org/ns/auth/cert#> .
+@prefix rsa: <http://www.w3.org/ns/auth/rsa#> .
+
+# About this document:
+# The <> (the empty URI) means "this document".
+
+ <> a foaf:PersonalProfileDocument;
+ cc:license <http://creativecommons.org/licenses/by-nc/3.0/>;
+ dc:title "Tim Berners-Lee's FOAF file";
+ foaf:maker card:i;
+ foaf:primaryTopic card:i.
+
+# Below we introduce a FOAF file I have write access to, which the tabulator
+# will let me edit.
+
+
+# Turn off this section to turn off the live editing of the FOAF file extension.
+# This is where my list of people I know is:
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf>
+ a foaf:PersonalProfileDocument; # Suitable place to edit
+ is rdfs:seeAlso of card:i; # Go fetch it
+ cc:license <http://creativecommons.org/licenses/by-nc/3.0/>;
+ dc:title "Tim Berners-Lee's editable FOAF file";
+ foaf:maker card:i;
+ foaf:primaryTopic card:i.
+
+############## Stuff about me
+
+card:i
+ s:label "Tim Berners-Lee"; # For generic user interfaces etc
+ a :Male;
+ foaf:based_near [geo:lat "42.361860"; geo:long "-71.091840"];
+
+ :office [
+ :phone <tel:+1-617-253-5702>;
+ geo:location [geo:lat "42.361860"; geo:long "-71.091840"];
+ :address [
+ :street "32 Vassar Street";
+ :street2 "MIT CSAIL Room 32-G524";
+ :city "Cambridge";
+ :postalCode "02139";
+ :country "USA"
+ ]
+ ];
+ :publicHomePage <../Berners-Lee/>;
+ :homePage <../Berners-Lee/>; # hack - follows by RDFS from line above
+ # The W3C structure data uses this as an IFP
+ is foaf:member of w3c:W3C;
+ :assistant card:amy;
+
+# Using FOAF vocabulary:
+
+ a foaf:Person;
+ # The idea is that this is the one I would suggest you use and
+ # I use for myself, which can lead to others.
+ :preferredURI "http://www.w3.org/People/Berners-Lee/card#i"; # experimental
+ foaf:mbox <mailto:timbl@w3.org>;
+ foaf:mbox_sha1sum "965c47c5a70db7407210cef6e4e6f5374a525c5c";
+ foaf:openid <http://www.w3.org/People/Berners-Lee/>;
+ foaf:img <http://www.w3.org/Press/Stock/Berners-Lee/2001-europaeum-eighth.jpg>;
+
+ foaf:family_name "Berners-Lee";
+ foaf:givenname "Timothy";
+ foaf:title "Sir";
+
+ foaf:homepage <http://www.w3.org/People/Berners-Lee/>;
+ is foaf:member of <http://dig.csail.mit.edu/data#DIG>;
+ foaf:mbox <mailto:timbl@w3.org>;
+ # foaf:mbox_sha1sum "1839a1cc2e719a85ea7d9007f587b2899cd94064";
+ foaf:name "Timothy Berners-Lee";
+ foaf:nick "TimBL", "timbl";
+ foaf:phone <tel:+1-(617)-253-5702>;
+ # foaf:schoolHomepage <http://www.w3.org/People/Berners-Lee>;
+
+
+ foaf:account <http://twitter.com/timberners_lee>,
+ <http://en.wikipedia.org/User:Timbl>,
+ <http://identi.ca/timbl>;
+
+ # foaf:workInfoHomepage <http://www.w3.org/People/Berners-Lee>;
+ foaf:workplaceHomepage <http://www.w3.org/>.
+
+
+
+
+### W3C's list of talks
+
+ card:i s:seeAlso <http://www.w3.org/2007/11/Talks/search/query?date=All+past+and+future+talks&event=None&activity=None&name=Tim+Berners-Lee&country=None&language=None&office=None&rdfOnly=yes&submit=Submit>.
+
+##### My Web ID cert
+
+card:i is cert:identity of [
+ a rsa:RSAPublicKey;
+ rsa:public_exponent "65537"^cert:decimal ;
+ rsa:modulus
+
+ """c111fbc68eccad2021acc16533fb7b81
+ 73505931694c476346c3254cf9706553
+ 7b2e17a6eb67fe4da1b9e2d6c9ec3867
+ bd9b0e7d362181c4f1bf6a2875b596ec
+ 99baa80b5c0f2ebf1dc6317bb835d8de
+ 7f71d7f8d4123f730c7bdf41e608db6e
+ 79bc490e9f89737b765d3a9a7494bbe6
+ de2c1af085b60ea82fecfb2a093b66ef
+ c01af8b37f77e0c5daad73a3f3848c44
+ 1347247f915dd3d57d63624e934a0af3
+ c0bc93b5f6172d8661e3c8fed2011494
+ 6fca3834262232c1d6d74e369f0e71f7
+ a348e652b48a77d9518ff7b776c07729
+ 7625c3bec947ef5aae40d2253255813f
+ bfd519a883556cc76f03f5b07e0bd3bf
+ 99359deb40417d6466908feeaa5c160f"""^cert:hex ;
+ ] .
+
+
+#old cert modulus:
+#"84554e39b67f5e3912068773655d855d222fa2c05cd9784693f8919aa46a61be703069c5f3266eebc21d6bb429ee47fac347b012eb7d#a8b1e4b02f7680e39767b0086f1fd48b9a420de3e70df9c2504c87006e7722ab6df210dec768dae454e65b31752379d7032dd22696465#62593d8b5c621860a0f929ad64b9dce1d6cb12f"^cert:hex ;
+
+
+
+
+
+
+##### Things I am involved in -- DOAP
+
+card:i is doap:developer of <http://www.w3.org/2000/10/swap/data#Cwm>,
+ <http://dig.csail.mit.edu/2005/ajar/ajaw/data#Tabulator>.
+
+
+# BBC Catalogue links: # Clumsy .. need to give people URIs. Now offline :-(
+# card:i foaf:homepage <http://open.bbc.co.uk/catalogue/infax/contributor/169456>;
+# s:seeAlso <http://open.bbc.co.uk/catalogue/xml/contributor/169456>.
+
+
+# Advogato is geek social netorking site (2008)
+card:i = <http://www.advogato.org/person/timbl/foaf.rdf#me>.
+
+##### Identi.ca identity
+card:i = <http://identi.ca/user/45563>.
+
+# The (2006/11) DBLP database
+card:i = <http://www4.wiwiss.fu-berlin.de/dblp/resource/person/100007>.
+
+# Bizer et al's RDF mashup of Amazon
+card:i = <http://www4.wiwiss.fu-berlin.de/bookmashup/persons/Tim+Berners-Lee>.
+
+<http://www4.wiwiss.fu-berlin.de/booksMeshup/books/006251587X> dc:title
+"Weaving the Web: The Original Design and Ultimate Destiny of the World Wide Web";
+ dc:creator card:i.
+
+# More from Chris Bizer: the dbpedia scrape of Wikipedia
+# @@@ Commented out temporaily as it was getting slow from redirecting each ontology term
+# <http://dbpedia.org/resource/Tim_Berners-Lee> = card:i.
+
+# MIT IAP course
+
+<http://dig.csail.mit.edu/2007/01/camp/data#course> foaf:maker card:i.
+
+# WWW2006 stuff:
+# <#i> = http://www.ecs.soton.ac.uk/~dt2/dlstuff/www2006_data#tim_berners-lee
+#
+
+<http://www.ecs.soton.ac.uk/~dt2/dlstuff/www2006_data#panel-panelk01>
+ s:label "The Next Wave of the Web (Plenary Panel)";
+ :participant card:i.
+
+<http://wiki.ontoworld.org/index.php/_IRW2006>
+ :participant card:i.
+
+<http://wiki.ontoworld.org/index.php/_IRW2006>
+ dc:title "Identity, Reference and the Web workshop 2006".
+
+<http://dig.csail.mit.edu/breadcrumbs/blog/4>
+ rdfs:seeAlso <http://dig.csail.mit.edu/breadcrumbs/blog/feed/4>; # Sigh
+ dc:title "timbl's blog";
+ is foaf:weblog of card:i;
+ foaf:maker card:i.
+
+<../../DesignIssues/Overview.html> # Has RDFA in it
+ dc:title "Design Issues for the World Wide Web";
+ foaf:maker card:i.
+
+#ends
+
View
68 license.txt
@@ -0,0 +1,68 @@
+Scute Licenses 2011-
+
+Summary
+=======
+
+ * The Scute Home Page is http://hyperdata.org/scute
+ * Contact: danny.ayers@gmail.com
+
+To encourage free distribution and reuse of Scute, the following open licenses apply to all source, binaries, documentation and data as appropriate. If any of these aren't suitable for your deployment environment, please let me know, I'll be happy to add alternatives.
+
+ * Apache License Version 2.0
+ * Creative Commons Attribution 3.0 Unported (CC BY 3.0)
+ * Open Data Commons Attribution License 1.0
+
+Feel free to use Scute as you see fit (although I won't be held responsible for any problems this may cause). If you find it useful, a link to the project home page will be appreciated.
+
+If you redistribute or modify the works, please include reference to these licenses. There should be a copy of this document in the software distribution called license.txt, and it appears on the Web at http://hyperdata.org/wiki/Scute:License
+
+Attribution may be provided simply via a link to the Scute Home Page.
+
+Applications and Source Code
+============================
+
+Copyright 2011 Danny Ayers
+
+Apache License Version 2.0
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+[edit] Documentation
+
+Documentation
+=============
+
+Copyright 2011 Danny Ayers
+
+Creative Commons Attribution 3.0 Unported (CC BY 3.0)
+
+You are free:
+
+ * to Share — to copy, distribute and transmit the work
+ * to Remix — to adapt the work
+
+Under the following conditions:
+
+ * Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
+
+Data
+====
+
+Copyright 2011 Danny Ayers
+
+Open Data Commons Attribution License 1.0
+
+You are free:
+
+ * To Share: To copy, distribute and use the database.
+ * To Create: To produce works from the database.
+ * To Adapt: To modify, transform and build upon the database.
+
+As long as you:
+
+ * Attribute: You must attribute any public use of the database, or works produced from the database, in the manner specified in the ODbL. For any use or redistribution of the database, or works produced from it, you must make clear to others the license of the database and keep intact any notices on the original database.
+ * Share-Alike: If you publicly use any adapted version of this database, or works produced from an adapted database, you must also offer that adapted database under the ODbL.
+ * Keep open: If you redistribute the database, or an adapted version of it, then you may use technological measures that restrict the work (such as DRM) as long as you also redistribute a version without such measures.
View
175 src/org/hyperdata/scute/graph/GraphDiagramPanel.java
@@ -31,6 +31,8 @@
/**
* The Class GraphDiagramPanel.
+ *
+ * @TODO add zoom & drag
*/
public class GraphDiagramPanel extends JPanel {
@@ -43,8 +45,7 @@
/** The graph layout. */
private final GraphLayout graphLayout;
- /** The running. */
- private boolean running = false;
+ private RdfInterpreter rdfInterpreter;
/**
* Instantiates a new graph diagram panel.
@@ -56,138 +57,28 @@ public GraphDiagramPanel(Model model) {
super();
setSize(800, 800);
+ // get your data in!
graphSet = new GraphSet();
- interpret(model);
+ rdfInterpreter = new RdfInterpreter(this, graphSet);
+ rdfInterpreter.interpret(model);
- graphLayout = new GraphLayout(this, graphSet);
setBackground(Color.white);
+
+ graphLayout = new GraphLayout(this, graphSet);
+ graphLayout.init();
+
addMouseListener(new MouseHandler(this));
}
-
- /**
- * Initialize.
- */
- public void initialize() {
- // @TODO scramble on startup kills display!
- // interpret(model);
- // scramble();
+
+ public boolean isRunning() {
+ return graphLayout.isRunning();
}
- /*
- * this was originally lifted from RDFNodeMap - can the two be merged?
- */
- /**
- * Interpret.
- *
- * @param sourceModel
- * the source model
- */
- public void interpret(Model sourceModel) {
- try {
- final StmtIterator iterator = sourceModel.listStatements();
- Statement statement;
- RDFNode object;
-
- while (iterator.hasNext()) {
- statement = iterator.next();
-
- addResource(statement.getSubject());
- object = statement.getObject();
-
- if (object.isResource()) {
- addResource((Resource) object);
- } else {
- addLiteral((Literal) object);
- }
- addStatement(statement);
- }
- } catch (final Exception exception) {
- exception.printStackTrace();
- }
- // requestFocusInWindow(false); // takes the focus off nodes - doesn't
- // work!
+ public void setRunning(boolean run) {
+ graphLayout.setRunning(run);
}
- /**
- * Scramble.
- */
- public synchronized void scramble() {
- Dimension d = getSize();
- Iterator<Node> nIterator = graphSet.nodeIterator();
- while (nIterator.hasNext()) {
- Node n = nIterator.next();
- if (!n.isFixed()) {
- n.setX(10 + (d.width - 20) * Math.random());
- n.setY(10 + (d.height - 20) * Math.random());
- }
- }
- }
- /**
- * Adds the literal.
- *
- * @param literal
- * the literal
- * @return the node
- */
- private Node addLiteral(Literal literal) {
- Node node = graphSet.getNodeContaining(literal);
- if (node == null) {
- JButton button = new JButton();
- node = new Node(literal, button);
- button.setText(node.getString());
- button.setBackground(Color.green);
- add(button);
- node.setX(getWidth() * Math.random());
- node.setY(getHeight() * Math.random());
- node.setLabel(node.getString());
- }
- return graphSet.addNode(node);
- }
-
- /**
- * Adds the resource.
- *
- * @param resource
- * the resource
- * @return the node
- */
- private Node addResource(Resource resource) {
- Node node = graphSet.getNodeContaining(resource);
- if (node == null) {
-
- JButton button = new RoundButton(); // ellipse for URI nodes
- node = new Node(resource, button);
- button.setText(node.getString());
- button.setBackground(Color.pink);
- add(button);
- node.setX(getWidth() * Math.random());
- node.setY(getHeight() * Math.random());
- node.setLabel(node.getString());
- if (resource.isAnon()) { // circular for bnodes
- ((RoundButton) button).setCircular();
- }
- }
- graphSet.addNode(node);
- return node;
- }
-
- /**
- * Adds the statement.
- *
- * @param statement
- * the statement
- * @return the edge
- */
- private Edge addStatement(Statement statement) {
- Property p = statement.getPredicate();
- Edge edge = new Edge(p);
- edge.from = graphSet.getNodeContaining(statement.getSubject());
- edge.to = graphSet.getNodeContaining(statement.getObject());
- ((JButton) edge.getComponent()).setText(edge.getString());
- add(edge.getComponent());
- return graphSet.addEdge(edge);
- }
/* (non-Javadoc)
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
@@ -220,16 +111,6 @@ public boolean isPickFixed() {
return graphLayout.isPickFixed();
}
- /**
- * Gets the node.
- *
- * @param i
- * the i
- * @return the node
- */
- public Node getNode(int i) {
- return graphSet.getNode(i);
- }
/**
* Gets the pick.
@@ -254,32 +135,6 @@ public void listNodes() { // for debugging
graphSet.listNodes();
}
- /**
- * Checks if is running.
- *
- * @return true, if is running
- */
- public synchronized boolean isRunning() {
- return running;
- }
-
- /**
- * Sets the running.
- *
- * @param b
- * the new running
- */
- public synchronized void setRunning(boolean b) {
- if (b) {
- scramble();
- graphLayout.start();
- this.running = true;
- } else {
- graphLayout.stop();
- this.running = false;
- // repaint();
- }
- }
/**
* Node iterator.
View
187 src/org/hyperdata/scute/graph/GraphLayout.java
@@ -10,82 +10,90 @@
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
+import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
/**
* The Class GraphLayout.
*
- * @author danny
+ * @author danja
+ *
+ * @FIXME threading isn't quite right, buttons in a row flash between start/stop
+ *
+ * @TODO add edge uncrossing
+ *
+ * @TODO check other algorithms
*/
public class GraphLayout implements Runnable {
/** The Constant EDGE_MIN_LENGTH. */
private static final double EDGE_MIN_LENGTH = .1;
-
+
/** The Constant CONSTANT2. */
private static final double CONSTANT2 = 1000;
-
+
/** The Constant CONSTANT3. */
private static final double CONSTANT3 = 10000;
-
+
/** The Constant CONSTANT4. */
private static final int CONSTANT4 = 500;
-
+
/** The Constant RANDOMIZE_NODE_PROBABILITY. */
private static final double RANDOMIZE_NODE_PROBABILITY = 0.1;
+ private boolean running = false;
+
/** The pick. */
private Node pick;
-
+
/** The pickfixed. */
private boolean pickfixed;
-
+
/** The off screen. */
private Image offScreen;
-
+
/** The off screen size. */
private Dimension offScreenSize;
-
+
/** The off graphics. */
private Graphics2D offGraphics;
/** The edge color. */
final Color edgeColor = Color.black;
-
+
/** The arc color1. */
final Color arcColor1 = Color.black;
-
+
/** The arc color2. */
final Color arcColor2 = Color.pink;
-
+
/** The arc color3. */
final Color arcColor3 = Color.red;
/** The springs. */
private Thread springs = null;
-
+
/** The stress. */
boolean stress;
-
+
/** The random. */
boolean random = true;
-
+
/** The graph set. */
private final GraphSet graphSet;
-
+
/** The panel. */
private final JPanel panel;
/** The arrow scale. */
private final double arrowScale = 10;
-
+
/** The origin arrow. */
private final Path2D.Double originArrow = getOriginArrow();
- // private static final Path2D.Double;
-
/**
* Instantiates a new graph layout.
*
@@ -98,92 +106,131 @@ public GraphLayout(JPanel panel, GraphSet graphSet) {
this.graphSet = graphSet;
this.panel = panel;
}
+
+ /**
+ *
+ */
+ public void init() {
+ scramble();
+ }
- /* (non-Javadoc)
+ public boolean isRunning() {
+ return this.running;
+ }
+
+ public void setRunning(boolean run) {
+ if (run) {
+ scramble();
+ start();
+ } else {
+ stop();
+ }
+ this.running = run;
+ }
+
+ /**
+ * Scramble.
+ */
+ public void scramble() {
+ Dimension d = panel.getSize();
+ Iterator<Node> nIterator = graphSet.nodeIterator();
+ while (nIterator.hasNext()) {
+ Node n = nIterator.next();
+ if (!n.isFixed()) {
+ n.setX(10 + (d.width - 20) * Math.random());
+ n.setY(10 + (d.height - 20) * Math.random());
+ }
+ }
+ }
+
+ private Runnable cleanup = new Runnable() {
+ public void run() {
+ relax();
+ }
+ };
+
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Runnable#run()
*/
public void run() {
- // Thread me = Thread.currentThread();
- // while (springs == me) {
- while (true) {
+ while (this.running) {
relax();
- if (random && (Math.random() < RANDOMIZE_NODE_PROBABILITY)) {
- Node n = graphSet.getRandomNode();
- randomizeNode(n);
- }
+ // if (random && (Math.random() < RANDOMIZE_NODE_PROBABILITY)) {
+ // Node n = graphSet.getRandomNode();
+ // randomizeNode(n);
+ // }
try {
Thread.sleep(100);
} catch (InterruptedException e) {
- // panel.repaint();
- relax();
+ // SwingUtilities.invokeLater(cleanupRunnable);
+ this.running = false;
break;
-
+ } finally {
+ // relax(); // meh
}
}
+ SwingUtilities.invokeLater(cleanup); // one last relax
+
}
-
+
/**
* Randomize node.
*
* @param node
* the node
*/
- private synchronized void randomizeNode(Node node){
+ private void randomizeNode(Node node) {
if (!node.isFixed()) {
node.setX(node.getX()
- + (panel.getWidth() * Math.random() - panel
- .getWidth() / 2));
+ + (panel.getWidth() * Math.random() - panel.getWidth() / 2));
node.setY(node.getY()
- + (panel.getHeight() * Math.random() - panel
- .getHeight() / 2));
+ + (panel.getHeight() * Math.random() - panel.getHeight() / 2));
}
}
- // @FIXME need to synchronize on container panel?
/**
* Relax.
*/
- private synchronized void relax() {
-doEdges();
-
-doNodes();
-
-doNodes2();
+ private void relax() {
+ doEdges(); // @TODO rename these
+ doNodes();
+ doNodes2();
}
-
/**
* Do edges.
*/
- private synchronized void doEdges() { // @TODO rename
+ private void doEdges() { // @TODO rename
Iterator<Edge> eIterator = graphSet.edgeIterator();
-
+
while (eIterator.hasNext()) {
Edge e = eIterator.next();
- double vx = e.to.getX() - e.from.getX();
- double vy = e.to.getY() - e.from.getY();
+ double vx = e.to.getX() - e.from.getX();
+ double vy = e.to.getY() - e.from.getY();
- double len = Math.sqrt(vx * vx + vy * vy);
-
- len = (len == 0) ? EDGE_MIN_LENGTH : len;
+ double len = Math.sqrt(vx * vx + vy * vy);
- double f = (e.len - len) / (len * CONSTANT2);
+ len = (len == 0) ? EDGE_MIN_LENGTH : len;
- double dx = f * vx;
- double dy = f * vy;
+ double f = (e.len - len) / (len * CONSTANT2);
- e.to.setDx(e.to.getDx() + dx);
- e.to.setDy(e.to.getDy() + dy);
- e.from.setDx(e.from.getDx() + (-dx));
- e.from.setDy(e.from.getDy() + (-dy));
- }
+ double dx = f * vx;
+ double dy = f * vy;
+
+ e.to.setDx(e.to.getDx() + dx);
+ e.to.setDy(e.to.getDy() + dy);
+ e.from.setDx(e.from.getDx() + (-dx));
+ e.from.setDy(e.from.getDy() + (-dy));
+ }
}
-
+
/**
* Do nodes.
*/
- private synchronized void doNodes() { // @TODO rename
+ private void doNodes() { // @TODO rename
Iterator<Node> nIterator1 = graphSet.nodeIterator();
while (nIterator1.hasNext()) {
Node n1 = nIterator1.next();
@@ -217,11 +264,11 @@ private synchronized void doNodes() { // @TODO rename
}
}
}
-
+
/**
* Do nodes2.
*/
- private synchronized void doNodes2() { // @TODO rename
+ private void doNodes2() { // @TODO rename
Dimension d = panel.getSize();
Iterator<Node> nIterator = graphSet.nodeIterator();
@@ -249,14 +296,12 @@ private synchronized void doNodes2() { // @TODO rename
}
}
-
-
/**
* Gets the image.
*
* @return the image
*/
- public synchronized Image getImage() {
+ public Image getImage() {
Dimension d = panel.getSize();
if ((offScreen == null) || (d.width != offScreenSize.width)
@@ -273,10 +318,10 @@ public synchronized Image getImage() {
offGraphics.setColor(panel.getBackground());
offGraphics.fillRect(0, 0, d.width, d.height);
- Iterator<Edge> eIterator = graphSet.edgeIterator();
- while (eIterator.hasNext()) {
- Edge e = eIterator.next();
-
+ Iterator<Edge> eIterator = graphSet.edgeIterator();
+ while (eIterator.hasNext()) {
+ Edge e = eIterator.next();
+
double xx1 = e.from.getX();
double yy1 = e.from.getY();
double xx2 = e.to.getX();
@@ -327,7 +372,7 @@ public void drawArrows(double xx1, double yy1, double xx2, double yy2) {
// Decided against having two arrows on the line, left here in just case
// double arrowOneX = xx1 + (xx2 - xx1)/4;
// double arrowOneY = yy1 + (yy2 - yy1)/4;
- //
+ //
// AffineTransform rotateOne =
// AffineTransform.getRotateInstance(xx2-xx1, yy2-yy1,
// arrowOneX,arrowOneY);
View
24 src/org/hyperdata/scute/graph/GraphPanel.java
@@ -53,7 +53,6 @@ public GraphPanel(Model model) {
toolBar = new JToolBar("Graph Tools");
addControls();
add(toolBar, BorderLayout.SOUTH);
- initialize();
}
/**
@@ -64,27 +63,4 @@ private void addControls() {
JButton toggle = new JButton(toggleAction);
toolBar.add(toggle);
}
-
- /**
- * Initialize.
- */
- public void initialize() {
- graphDiagramPanel.initialize();
- }
-
- /**
- * Sets the running.
- *
- * @param b
- * the new running
- */
- public synchronized void setRunning(boolean b) {
- graphDiagramPanel.setRunning(b);
- }
-
- // @Override
- // public void paintComponent(Graphics g) {
- // super.paintComponent(g);
- // graphDiagramPanel.paintComponent(g);
- // }
}
View
50 src/org/hyperdata/scute/graph/GraphSet.java
@@ -1,6 +1,14 @@
-/**
+/*
+ * Scute
+ *
+ * Homepage: http://hyperdata.org/scute
+ *
+ * License : http://www.apache.org/licenses/LICENSE-2.0
+ * See also license.txt or http://hyperdata.org/wiki/Scute:License
*
+ * Danny Ayers 2011
*/
+
package org.hyperdata.scute.graph;
import java.util.ArrayList;
@@ -13,17 +21,18 @@
* The Class GraphSet.
*
* @author danny
+ *
+ * @TODO give nodes weights L/R according to inlinks/outlinks (stick literals on the right!) - sort GraphSet?
+ *
*/
public class GraphSet {
-
- // Node nodes[] = new Node[100];
- // Edge edges[] = new Edge[200];
-
+
/** The nodes. */
List<Node> nodes = new ArrayList<Node>();
/** The edges. */
List<Edge> edges = new ArrayList<Edge>();
+
/**
* Instantiates a new graph set.
@@ -33,37 +42,6 @@ public GraphSet() {
}
/**
- * Gets the node.
- *
- * @param i
- * the i
- * @return the node
- */
- public Node getNode(int i) {
- // System.out.println("size = "+nodes.size()+" i = "+i);
- return nodes.get(i);
- }
-
- // public void setNode(int nnodes, Node n) {
- // nodes.set(nnodes,n);
- // }
-
- // public void setEdge(int i, Edge e) {
- // edges.set(i,e);
- // }
-
- /**
- * Gets the edge.
- *
- * @param i
- * the i
- * @return the edge
- */
- public Edge getEdge(int i) {
- return edges.get(i);
- }
-
- /**
* Adds the node.
*
* @param node
View
131 src/org/hyperdata/scute/graph/RdfInterpreter.java
@@ -0,0 +1,131 @@
+package org.hyperdata.scute.graph;
+
+import java.awt.Color;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+
+/**
+ * @author danny
+ *
+ * Reads the nodes & arcs in a Jena Model and
+ *
+ */
+public class RdfInterpreter {
+ private JPanel displayPanel;
+ private GraphSet graphSet;
+
+ public RdfInterpreter(JPanel displayPanel, GraphSet graphSet){
+ this.displayPanel = displayPanel;
+ this.graphSet = graphSet;
+ }
+
+ /*
+ * this was originally lifted from RDFNodeMap in RdfTree - can the two be merged?
+ */
+ /**
+ * Interpret.
+ *
+ * @param sourceModel
+ * the source model
+ */
+ public void interpret(Model sourceModel) {
+ try {
+ final StmtIterator iterator = sourceModel.listStatements();
+ Statement statement;
+ RDFNode object;
+
+ while (iterator.hasNext()) {
+ statement = iterator.next();
+
+ addResource(statement.getSubject());
+ object = statement.getObject();
+
+ if (object.isResource()) {
+ addResource((Resource) object);
+ } else {
+ addLiteral((Literal) object);
+ }
+ addStatement(statement);
+ }
+ } catch (final Exception exception) {
+ exception.printStackTrace();
+ }
+ // requestFocusInWindow(false); // takes the focus off nodes - doesn't
+ // work!
+ }
+
+ /**
+ * Adds the literal.
+ *
+ * @param literal
+ * the literal
+ * @return the node
+ */
+ private Node addLiteral(Literal literal) {
+ Node node = graphSet.getNodeContaining(literal);
+ if (node == null) {
+ JButton button = new JButton();
+ node = new Node(literal, button);
+ button.setText(node.getString());
+ button.setBackground(Color.green);
+ displayPanel.add(button);
+ node.setX(displayPanel.getWidth() * Math.random());
+ node.setY(displayPanel.getHeight() * Math.random());
+ node.setLabel(node.getString());
+ }
+ return graphSet.addNode(node);
+ }
+
+ /**
+ * Adds the resource.
+ *
+ * @param resource
+ * the resource
+ * @return the node
+ */
+ private Node addResource(Resource resource) {
+ Node node = graphSet.getNodeContaining(resource);
+ if (node == null) {
+
+ JButton button = new RoundButton(); // ellipse for URI nodes
+ node = new Node(resource, button);
+ button.setText(node.getString());
+ button.setBackground(Color.pink);
+ displayPanel.add(button);
+ node.setX(displayPanel.getWidth() * Math.random());
+ node.setY(displayPanel.getHeight() * Math.random());
+ node.setLabel(node.getString());
+ if (resource.isAnon()) { // circular for bnodes
+ ((RoundButton) button).setCircular();
+ }
+ }
+ graphSet.addNode(node);
+ return node;
+ }
+
+ /**
+ * Adds the statement.
+ *
+ * @param statement
+ * the statement
+ * @return the edge
+ */
+ private Edge addStatement(Statement statement) {
+ Property p = statement.getPredicate();
+ Edge edge = new Edge(p);
+ edge.from = graphSet.getNodeContaining(statement.getSubject());
+ edge.to = graphSet.getNodeContaining(statement.getObject());
+ ((JButton) edge.getComponent()).setText(edge.getString());
+ displayPanel.add(edge.getComponent());
+ return graphSet.addEdge(edge);
+ }
+}
View
6 src/org/hyperdata/scute/graph/VisibleEdge.java
@@ -18,13 +18,15 @@
/**
* The Class VisibleEdge.
+ *
+ * @TODO add popup menu
*/
public class VisibleEdge {
- /** The len. */
+ /** length of the edge */
double len;
- /** The component. */
+ /** component in middle of visible edge */
private final JButton component;
/**
View
3  src/org/hyperdata/scute/graph/VisibleNode.java
@@ -15,6 +15,9 @@
/**
* The Class VisibleNode.
+ *
+ * @TODO add popup menu
+ *
*/
public class VisibleNode {
View
58 src/org/hyperdata/scute/graph/ZoomPanel.java
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package org.hyperdata.scute.graph;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+
+import javax.swing.JPanel;
+
+/**
+ * @author danny
+ *
+ */
+public class ZoomPanel extends JPanel {
+
+ private double zoom = 1.0;
+
+ private double percentage;
+
+ private Image image;
+
+ public ZoomPanel(Image image, double zoomPercentage) {
+ this.image = image;
+ percentage = zoomPercentage / 100;
+ }
+
+ public void paintComponent(Graphics grp) {
+ Graphics2D g2D = (Graphics2D) grp;
+ g2D.scale(zoom, zoom);
+ g2D.drawImage(image, 0, 0, this);
+ }
+
+ public void setZoomPercentage(int zoomPercentage) {
+ percentage = ((double) zoomPercentage) / 100;
+ }
+
+ public void originalSize() {
+ zoom = 1;
+ }
+
+ public void zoomIn() {
+ zoom += percentage;
+ }
+
+ public void zoomOut() {
+ zoom -= percentage;
+
+ if (zoom < percentage) {
+ if (percentage > 1.0) {
+ zoom = 1.0;
+ } else {
+ zoomIn();
+ }
+ }
+ }
+}
View
6 src/org/hyperdata/scute/graph/actions/ToggleAction.java
@@ -14,6 +14,7 @@
import javax.swing.AbstractAction;
import javax.swing.JButton;
+import javax.swing.SwingUtilities;
import org.hyperdata.scute.graph.GraphDiagramPanel;
@@ -28,6 +29,8 @@
/** The diagram panel. */
private final GraphDiagramPanel diagramPanel;
+
+
/**
* Instantiates a new toggle action.
*
@@ -50,8 +53,7 @@ public void actionPerformed(ActionEvent event) {
} else {
button.setText("Scramble");
}
- diagramPanel.setRunning(!diagramPanel.isRunning()); // isSelected
- // available
+ diagramPanel.setRunning(!diagramPanel.isRunning());
}
}
View
2  src/org/hyperdata/scute/io/AutoSave.java
@@ -29,7 +29,7 @@
/**
* see http://esw.w3.org/IntegrityIsJobOne
*
- * Currently just saves stuff afresh every 6 seconds could do with being more
+ * Currently just saves stuff afresh every 6 seconds - could do with being
* intelligent about when things have changed
*
* @author danny
Please sign in to comment.
Something went wrong with that request. Please try again.