[graphl-cvs] graphl/src/org/mediavirus/graphl GraphlApplication.java GraphlRegistry.java GraphlPane
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2006-06-08 13:15:32
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv17343/src/org/mediavirus/graphl Modified Files: GraphlApplication.java GraphlRegistry.java GraphlPane.java GraphlApplet.java GraphlPanel.java Log Message: a lot of changes done a long time ago... changelog has to be updated another time :( Index: GraphlPanel.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlPanel.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** GraphlPanel.java 18 Dec 2005 11:11:40 -0000 1.25 --- GraphlPanel.java 8 Jun 2006 13:14:58 -0000 1.26 *************** *** 10,15 **** import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - import java.awt.event.KeyEvent; - import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; --- 10,13 ---- *************** *** 17,36 **** import java.awt.event.MouseWheelListener; import java.util.Collection; ! import java.util.Collections; ! import java.util.Iterator; ! import java.util.Vector; ! import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; ! import org.mediavirus.graphl.graph.*; import org.mediavirus.graphl.graph.filter.FilteredGraph; import org.mediavirus.graphl.graph.rdf.RDFGraph; import org.mediavirus.graphl.interaction.DefaultNodeManipulator; import org.mediavirus.graphl.interaction.GraphlManipulator; - import org.mediavirus.graphl.selection.SelectionListener; - import org.mediavirus.graphl.selection.SelectionModel; - - import javax.swing.JPanel; /** --- 15,34 ---- import java.awt.event.MouseWheelListener; import java.util.Collection; ! ! import javax.swing.JCheckBox; ! import javax.swing.JLabel; ! import javax.swing.JPanel; ! import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; ! import org.mediavirus.graphl.graph.Edge; ! import org.mediavirus.graphl.graph.Graph; ! import org.mediavirus.graphl.graph.GraphListener; ! import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.graph.filter.FilteredGraph; import org.mediavirus.graphl.graph.rdf.RDFGraph; import org.mediavirus.graphl.interaction.DefaultNodeManipulator; import org.mediavirus.graphl.interaction.GraphlManipulator; /** *************** *** 38,42 **** * */ ! public class GraphlPanel extends JPanel implements GraphListener, KeyListener, SelectionListener { private static final int WHEEL_ZOOM_FACTOR = 3; --- 36,40 ---- * */ ! public class GraphlPanel extends JPanel implements GraphListener { private static final int WHEEL_ZOOM_FACTOR = 3; *************** *** 71,75 **** graphPane.addManipulator(new DefaultNodeManipulator()); graphPane.getFilteredGraph().addGraphListener(this); - graphPane.addKeyListener(this); graphPane.addMouseWheelListener(new MouseWheelListener () { public void mouseWheelMoved(MouseWheelEvent e) { --- 69,72 ---- *************** *** 268,322 **** } - /** - * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) - */ - public void keyPressed(KeyEvent e) { - } - - /** - * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) - */ - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE || e.getKeyCode() == KeyEvent.VK_DELETE) { - - Iterator<Node> nodes = graphPane.getSelection().getSelectedNodes().iterator(); - while (nodes.hasNext()) { - Node node = nodes.next(); - Vector<Edge> edges = new Vector<Edge>(); - edges.addAll(node.getEdgesFrom()); - edges.addAll(node.getEdgesTo()); - ((DefaultGraph)graphPane.getSourceGraph()).deleteElements(Collections.singleton(node),edges); - } - - ((DefaultGraph)graphPane.getSourceGraph()).deleteElements(null,graphPane.getSelection().getSelectedEdges()); - } - - } - - public void keyTyped(KeyEvent e) { - - } - - public void nodesAddedToSelection(SelectionModel nodeSelectionModel, Collection<Node> nodes) { - } - - public void nodesRemovedFromSelection(SelectionModel nodeSelectionModel, Collection<Node> nodes) { - } - - public void selectionCleared(SelectionModel nodeSelectionModel) { - } - - /** - * @see org.mediavirus.graphl.selection.SelectionListener#edgesAddedToSelection(org.mediavirus.graphl.selection.SelectionModel, java.util.Collection) - */ - public void edgesAddedToSelection(SelectionModel nodeSelectionModel, Collection<Edge> edges) { - } - - /** - * @see org.mediavirus.graphl.selection.SelectionListener#edgesRemovedFromSelection(org.mediavirus.graphl.selection.SelectionModel, java.util.Collection) - */ - public void edgesRemovedFromSelection(SelectionModel nodeSelectionModel, Collection<Edge> edges) { - } - private JPanel getSpacerPanel() { if (spacerPanel == null) { --- 265,268 ---- Index: GraphlRegistry.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlRegistry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GraphlRegistry.java 18 Dec 2005 11:11:40 -0000 1.1 --- GraphlRegistry.java 8 Jun 2006 13:14:58 -0000 1.2 *************** *** 13,16 **** --- 13,18 ---- public class GraphlRegistry extends HashMap<String, Object>{ + public static final boolean DEBUG = false; + protected static GraphlRegistry instance; Index: GraphlApplet.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlApplet.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GraphlApplet.java 18 Dec 2005 11:11:40 -0000 1.13 --- GraphlApplet.java 8 Jun 2006 13:14:58 -0000 1.14 *************** *** 6,9 **** --- 6,10 ---- import java.awt.BorderLayout; + import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; *************** *** 18,27 **** --- 19,34 ---- import java.util.Iterator; + import javax.swing.ButtonGroup; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JPanel; + import javax.swing.JRadioButtonMenuItem; + import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; + import org.mediavirus.graphl.graph.Graph; import org.mediavirus.graphl.graph.Node; + import org.mediavirus.graphl.graph.filter.SourceFilter; import org.mediavirus.graphl.graph.rdf.RDFGraph; + import org.mediavirus.graphl.jxpath.JXPathFactory; import org.mediavirus.graphl.vocabulary.NS; *************** *** 37,47 **** private JButton saveButton; private JPanel bottomPanel; ! ! private RDFGraph settingsGraph = new RDFGraph(); ! /** A List with all configuration nodes in the settings graph */ ! //private List configurations = new ArrayList(); ! public GraphlApplet() { this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(getMainPanel(),BorderLayout.CENTER); --- 44,54 ---- private JButton saveButton; private JPanel bottomPanel; ! ! Font menuFont = new Font(null, Font.PLAIN, 12); ! public GraphlApplet() { + JXPathContextReferenceImpl.addNodePointerFactory(new JXPathFactory()); + this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(getMainPanel(),BorderLayout.CENTER); *************** *** 84,88 **** protected JPanel getMainPanel() { if (mainPanel == null) { ! mainPanel = new GraphlPanel(); } --- 91,103 ---- protected JPanel getMainPanel() { if (mainPanel == null) { ! ! Graph graph = new RDFGraph(); ! ! SourceFilter filter = new SourceFilter(); ! // TODO (2) we should model datasources as a class for UI access etc. ! filter.addSource(NS.graphl + "SYSTEM"); ! ! mainPanel = new GraphlPanel(graph); ! mainPanel.graphPane.getFilteredGraph().addFilter(filter); } *************** *** 97,104 **** String str = getParameter("toolbar"); ! if (str.equalsIgnoreCase("off") || str.equalsIgnoreCase("false")) { mainPanel.setToolbarVisible(false); } String savestr = getParameter("saveurl"); if (savestr != null) { --- 112,125 ---- String str = getParameter("toolbar"); ! if (str != null && (str.equalsIgnoreCase("off") || str.equalsIgnoreCase("false"))) { mainPanel.setToolbarVisible(false); } + int refresh = -1; + str = getParameter("refresh"); + if (str != null) { + refresh = Integer.parseInt(getParameter("refresh")); + } + String savestr = getParameter("saveurl"); if (savestr != null) { *************** *** 124,145 **** try { URL settingsurl = new URL(getDocumentBase(), urlstr); ! settingsGraph.clear(); ! ((RDFGraph)mainPanel.getGraph()).readFromURL(settingsurl); ! ! Node defaultSettings = null; ! int i = 0; ! for (Iterator settings = mainPanel.graphPane.getConfigurations().iterator(); settings.hasNext();) { ! Node node = (Node) settings.next(); ! if ((i == 0) || node.getProperty(NS.graphl + "default","").equalsIgnoreCase("true")) { ! defaultSettings = node; } ! i++; } - - if (defaultSettings != null) { - mainPanel.graphPane.setConfiguration(defaultSettings); - } } catch (IOException ex) { --- 145,187 ---- try { URL settingsurl = new URL(getDocumentBase(), urlstr); ! RDFGraph settingsGraph = (RDFGraph)mainPanel.graphPane.getSourceGraph(); ! Iterator<URL> urls = settingsGraph.readFromURL(settingsurl).iterator(); ! if (urls.hasNext()) { ! SourceFilter filter = new SourceFilter(); ! while (urls.hasNext()) { ! URL url = urls.next(); ! System.out.println(" filtering: " + url); ! filter.addSource(url.toString()); } ! mainPanel.graphPane.getFilteredGraph().addFilter(filter); } + JRadioButtonMenuItem defaultItem = null; + Node defaultSettings = null; + ButtonGroup settingsGroup = new ButtonGroup(); + + int i = 0; + for (Iterator settings = mainPanel.graphPane.getConfigurations().iterator(); settings.hasNext();) { + Node node = (Node) settings.next(); + if (! node.getProperty(NS.graphl + "public","true").equalsIgnoreCase("false")){ + JRadioButtonMenuItem item = new JRadioButtonMenuItem(node.getProperty(NS.graphl + "name","<unnamed>")); + //item.addActionListener(new SettingsAdapter(node)); + item.setFont(menuFont); + // TODO implement this + //configConfigurationMenu.add(item); + settingsGroup.add(item); + if ((i == 0) || node.getProperty(NS.graphl + "default","").equalsIgnoreCase("true")) { + defaultItem = item; + defaultSettings = node; + } + i++; + } + } + + if (defaultItem != null) { + mainPanel.graphPane.setConfiguration(defaultSettings); + defaultItem.setSelected(true); + } } catch (IOException ex) { *************** *** 160,164 **** try { URL rdfurl = new URL(getDocumentBase(), urlstr); ! ((RDFGraph)mainPanel.getGraph()).readFromURL(rdfurl); } catch (IOException e) { --- 202,209 ---- try { URL rdfurl = new URL(getDocumentBase(), urlstr); ! mainPanel.getGraphPane().loadURL(rdfurl); ! if (refresh > 0) { ! mainPanel.getGraphPane().scheduleRefresh(rdfurl, refresh); ! } } catch (IOException e) { Index: GraphlApplication.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlApplication.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** GraphlApplication.java 18 Dec 2005 11:11:40 -0000 1.23 --- GraphlApplication.java 8 Jun 2006 13:14:58 -0000 1.24 *************** *** 40,51 **** import org.mediavirus.graphl.gui.GenericDialog; import org.mediavirus.graphl.gui.OpenURLPanel; ! import org.mediavirus.graphl.jxpath.GraphPointerFactory; import org.mediavirus.graphl.painter.NodePainter; - import org.mediavirus.graphl.vocabulary.DC; - import org.mediavirus.graphl.vocabulary.FOAF; - import org.mediavirus.graphl.vocabulary.Graphl; import org.mediavirus.graphl.vocabulary.NS; - import org.mediavirus.graphl.vocabulary.RDF; - import org.mediavirus.graphl.vocabulary.RDFS; --- 40,46 ---- import org.mediavirus.graphl.gui.GenericDialog; import org.mediavirus.graphl.gui.OpenURLPanel; ! import org.mediavirus.graphl.jxpath.JXPathFactory; import org.mediavirus.graphl.painter.NodePainter; import org.mediavirus.graphl.vocabulary.NS; *************** *** 76,88 **** Font menuFont = new Font(null, Font.PLAIN, 12); - - private File currentFile; - private URL currentURL; - - private int sleeptime; - - private boolean doReload; - /** * Constructs a new instance of GraphlApplication. All the GUI is set up here. --- 71,75 ---- *************** *** 105,110 **** SourceFilter filter = new SourceFilter(); // TODO (2) we should model datasources as a class for UI access etc. - //filter.addSource("file:/C:/data/projects/graphl/config/vocabs/foaf-owl.rdf"); - //filter.addSource("file:/C:/data/projects/graphl/config/vocabs/rdf+rdfs.rdf"); filter.addSource(NS.graphl + "SYSTEM"); --- 92,95 ---- *************** *** 190,204 **** menuBar.add(configMenu); ! this.getContentPane().add(menuBar, BorderLayout.NORTH); ! ! // TODO (Future) the whole vocab. registration should be defined in RDF files ! GraphlRegistry.instance().getVocabularyRegistry().registerVocabulary(Graphl.getVocabulary()); ! GraphlRegistry.instance().getVocabularyRegistry().registerVocabulary(RDF.getVocabulary()); ! GraphlRegistry.instance().getVocabularyRegistry().registerVocabulary(RDFS.getVocabulary()); ! GraphlRegistry.instance().getVocabularyRegistry().registerVocabulary(DC.getVocabulary()); ! GraphlRegistry.instance().getVocabularyRegistry().registerVocabulary(FOAF.getVocabulary()); ! ! GraphlRegistry.instance().getVocabularyRegistry().registerNamespace("ff", "http://www.funkfeuer.at/vocab#"); ! } --- 175,179 ---- menuBar.add(configMenu); ! this.getContentPane().add(menuBar, BorderLayout.NORTH); } *************** *** 232,254 **** if (p.getURLString() != null) { try { ! currentURL = new URL(p.getURLString()); ! if (p.getDoReload()) { ! doReload = true; ! sleeptime = p.getReloadDuration() * 1000; ! Thread t = new Thread() { ! public void run() { ! while (doReload) { ! try { ! sleep(sleeptime); ! reload(); ! } ! catch (InterruptedException e) { ! } ! } ! } ! }; ! t.start(); ! } ! loadURL(currentURL); } catch (IOException e) { --- 207,215 ---- if (p.getURLString() != null) { try { ! URL url = new URL(p.getURLString()); ! mainPanel.getGraphPane().loadURL(url); ! if (p.getDoReload()) { ! mainPanel.getGraphPane().scheduleRefresh(url, p.getReloadDuration()); ! } } catch (IOException e) { *************** *** 280,286 **** mainPanel.getGraphPane().pauseLayouter(); mainPanel.getGraph().clear(); ! mainPanel.getGraph().resetDirty(); - currentFile = null; setTitle("Graphl - untitled"); --- 241,246 ---- mainPanel.getGraphPane().pauseLayouter(); mainPanel.getGraph().clear(); ! mainPanel.getGraph().setDirty(false); setTitle("Graphl - untitled"); *************** *** 301,310 **** } }); ! if (currentFile == null){ ! chooser.setCurrentDirectory(new File(System.getProperty("user.dir") + "/graphs")); ! } ! else { ! chooser.setCurrentDirectory(currentFile.getParentFile()); ! } int option = chooser.showSaveDialog(this); --- 261,270 ---- } }); ! //if (currentFile == null){ ! chooser.setCurrentDirectory(new File(System.getProperty("user.dir") + "/graphs")); ! //} ! //else { ! // chooser.setCurrentDirectory(currentFile.getParentFile()); ! //} int option = chooser.showSaveDialog(this); *************** *** 312,317 **** if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null){ ! currentFile = chooser.getSelectedFile(); ! boolean result = doSave(currentFile); if (result) setTitle("Graphl - " + chooser.getSelectedFile().getName()); return result; --- 272,277 ---- if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null){ ! File f = chooser.getSelectedFile(); ! boolean result = doSave(f); if (result) setTitle("Graphl - " + chooser.getSelectedFile().getName()); return result; *************** *** 326,335 **** */ public boolean doSave() { ! if (currentFile == null) { return doSaveAs(); ! } ! else { ! return doSave(currentFile); ! } } --- 286,295 ---- */ public boolean doSave() { ! //if (currentFile == null) { return doSaveAs(); ! //} ! //else { ! // return doSave(currentFile); ! //} } *************** *** 353,358 **** fgraph.addFilter(filter); ! RDFGraph.writeToRDF(fgraph, new FileOutputStream(currentFile), urlstr); ! mainPanel.getGraph().resetDirty(); } catch (IOException ioex) { --- 313,318 ---- fgraph.addFilter(filter); ! RDFGraph.writeToRDF(fgraph, new FileOutputStream(file), urlstr); ! mainPanel.getGraph().setDirty(false); } catch (IOException ioex) { *************** *** 379,388 **** } }); ! if (currentFile == null){ chooser.setCurrentDirectory(new File(System.getProperty("user.dir") + "/graphs")); ! } ! else { ! chooser.setCurrentDirectory(currentFile.getParentFile()); ! } int option = chooser.showOpenDialog(this); --- 339,348 ---- } }); ! //if (currentFile == null){ chooser.setCurrentDirectory(new File(System.getProperty("user.dir") + "/graphs")); ! //} ! //else { ! // chooser.setCurrentDirectory(currentFile.getParentFile()); ! //} int option = chooser.showOpenDialog(this); *************** *** 424,480 **** * @throws IOException If an error during reading occurs. */ ! public void loadFile(File file) throws IOException { ! try { ! if (file != null){ ! ! mainPanel.getGraphPane().pauseLayouter(); ! //mainPanel.getGraph().clear(); ! ! mainPanel.getGraph().readFromFile(file); ! //setTitle("Graphl - " + file.getName()); ! currentFile = file; ! } ! } ! finally { ! mainPanel.getGraphPane().resumeLayouter(); ! } ! ! } ! ! /** ! * Loads the graph from the specified URL. ! * @param url The URL of the RDF file to load. ! */ ! public void loadURL(URL url) throws IOException{ ! if (url != null) { ! mainPanel.getGraphPane().pauseLayouter(); ! mainPanel.getGraph().clear(); ! mainPanel.getGraph().readFromURL(url); ! setTitle("Graphl - " + url.getFile()); ! currentURL = url; ! mainPanel.getGraphPane().resumeLayouter(); ! } ! } ! ! /** ! * Reloads the current graph from its source. ! * ! */ ! public void reload() { ! if (currentURL != null) { ! try { ! mainPanel.getGraph().readFromURL(currentURL); ! } ! catch (IOException e) { ! System.err.println("Error reloading URL: " + e.getMessage()); ! } } ! else if (currentFile != null){ ! try { ! mainPanel.getGraph().readFromFile(currentFile); ! } ! catch (IOException ioex) { ! System.err.println("Error reloading file: " + ioex.getMessage()); ! } } } --- 384,395 ---- * @throws IOException If an error during reading occurs. */ ! public URL loadFile(File file) throws IOException { ! try { ! URL url = new URL("file:///" + file.getAbsolutePath()); ! mainPanel.getGraphPane().loadURL(url); ! return url; } ! catch (MalformedURLException e) { ! throw new IOException("Cannot construct URL from filename " + file.getAbsolutePath()); } } *************** *** 513,517 **** RDFGraph settingsGraph = (RDFGraph)mainPanel.graphPane.getSourceGraph(); ! Iterator<URL> urls = settingsGraph.readFromFile(new File(filename)); if (urls.hasNext()) { --- 428,432 ---- RDFGraph settingsGraph = (RDFGraph)mainPanel.graphPane.getSourceGraph(); ! Iterator<URL> urls = settingsGraph.readFromFile(new File(filename)).iterator(); if (urls.hasNext()) { *************** *** 572,576 **** System.setProperty("swing.metalTheme", "steel"); ! JXPathContextReferenceImpl.addNodePointerFactory(new GraphPointerFactory()); GraphlApplication app = new GraphlApplication(); --- 487,491 ---- System.setProperty("swing.metalTheme", "steel"); ! JXPathContextReferenceImpl.addNodePointerFactory(new JXPathFactory()); GraphlApplication app = new GraphlApplication(); *************** *** 631,643 **** app.loadSettings(configfile); if (filename != null) { try { ! URL url = new URL(filename); app.loadURL(url); } catch (MalformedURLException muex) { ! app.loadFile(new File(filename)); } if (refresh > 0) { ! app.scheduleRefresh(refresh * 1000); } --- 546,559 ---- app.loadSettings(configfile); if (filename != null) { + URL url; try { ! url = new URL(filename); app.loadURL(url); } catch (MalformedURLException muex) { ! url = app.loadFile(new File(filename)); } if (refresh > 0) { ! app.scheduleRefresh(url, refresh); } *************** *** 650,653 **** --- 566,573 ---- } + private void loadURL(URL url) throws IOException{ + mainPanel.getGraphPane().loadURL(url); + } + /** * *************** *** 761,780 **** * @param duration The duration in seconds between two reloads. */ ! private void scheduleRefresh(int duration) { ! doReload = true; ! sleeptime = duration; ! Thread t = new Thread() { ! public void run() { ! while (doReload) { ! try { ! sleep(sleeptime); ! reload(); ! } ! catch (InterruptedException e) { ! } ! } ! } ! }; ! t.start(); } --- 681,686 ---- * @param duration The duration in seconds between two reloads. */ ! private void scheduleRefresh(URL url, int duration) { ! mainPanel.getGraphPane().scheduleRefresh(url, duration); } Index: GraphlPane.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlPane.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** GraphlPane.java 18 Dec 2005 11:11:40 -0000 1.23 --- GraphlPane.java 8 Jun 2006 13:14:58 -0000 1.24 *************** *** 15,22 **** --- 15,25 ---- import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; + import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; + import java.io.IOException; + import java.net.URL; import java.util.ArrayList; import java.util.Collection; *************** *** 44,47 **** --- 47,51 ---- import org.mediavirus.graphl.painter.NodePainter; import org.mediavirus.graphl.selection.DefaultSelectionModel; + import org.mediavirus.graphl.selection.SelectionListener; import org.mediavirus.graphl.selection.SelectionModel; import org.mediavirus.graphl.view.FacetRegistry; *************** *** 54,58 **** * @author Flo Ledermann <led...@im...> */ ! public class GraphlPane extends JPanel implements GraphListener { private Set<String> registeredEdgeTypes = new HashSet<String>(); --- 58,62 ---- * @author Flo Ledermann <led...@im...> */ ! public class GraphlPane extends JPanel implements GraphListener, KeyListener, SelectionListener { private Set<String> registeredEdgeTypes = new HashSet<String>(); *************** *** 105,108 **** --- 109,113 ---- updateTransform(); + addKeyListener(this); layouter = new Layouter(new GraphlLayoutStrategy(getFilteredGraph(), getFacetRegistry())); *************** *** 400,403 **** --- 405,409 ---- } selection = new DefaultSelectionModel(filteredGraph); + selection.addSelectionListener(this); /*Graph oldGraph = filteredGraph.getSource(); if (oldGraph != null) { *************** *** 802,806 **** currentConfiguration = configuration; setFacetRegistry(new GraphFacetRegistry(getSourceGraph(),configuration)); ! setVocabularies(configuration.getFirstNeighbour(NS.graphl + "vocabularies",true)); configuration.setProperty(NS.graphl + "active","true"); setComment(configuration.getProperty(NS.graphl + "comment")); --- 808,812 ---- currentConfiguration = configuration; setFacetRegistry(new GraphFacetRegistry(getSourceGraph(),configuration)); ! setVocabularies(configuration.getFirstNeighbour(NS.graphl + "vocabularies", Node.FORWARD)); configuration.setProperty(NS.graphl + "active","true"); setComment(configuration.getProperty(NS.graphl + "comment")); *************** *** 825,828 **** --- 831,989 ---- return centerXF; } + + class ReloadThread extends Thread { + URL url; + GraphlPane graphlPane; + int sleeptime; + + ReloadThread(GraphlPane graphlPane, URL url, int durationInSeconds) { + this.url = url; + this.graphlPane = graphlPane; + this.sleeptime = durationInSeconds; + } + + public void run() { + while (true) { + try { + sleep(sleeptime * 1000); + try { + graphlPane.loadURL(url); + } + catch (IOException e) { + System.err.println("Error reloading URL: " + e.getMessage()); + } + } + catch (InterruptedException e) { + } + } + } + } + + /** + * Loads the graph from the specified URL. + * @param url The URL of the RDF file to load. + */ + public void loadURL(URL url) throws IOException{ + if (url != null) { + pauseLayouter(); + ((RDFGraph)getSourceGraph()).readFromURL(url); + resumeLayouter(); + } + } + + /** + * Starts a Thread to reload the graph every <em>duration</em> seconds. + * + * @param durationInSeconds The duration in seconds between two reloads. + */ + public void scheduleRefresh(URL url, int durationInSeconds) { + ReloadThread t = new ReloadThread(this, url, durationInSeconds); + t.start(); + } + + /** + * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) + */ + public void keyPressed(KeyEvent e) { + } + + /** + * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) + */ + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DELETE) { + pauseLayouter(); + getSourceGraph().deleteElements(getSelection().getSelectedNodes(),getSelection().getSelectedEdges()); + getSelection().clear(); + resumeLayouter(); + } + else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + if (findInput.length() > 0) { + findInput = findInput.substring(0,findInput.length()-1); + if (findInput.length() > 0) { + processFindInput(); + } + else { + getSelection().clear(); + } + } + } + } + + String findInput = ""; + Thread findInputClearer; + + public void keyTyped(KeyEvent e) { + if (!Character.isISOControl(e.getKeyChar())) { + findInput += e.getKeyChar(); + processFindInput(); + } + } + + /** + * + */ + protected void processFindInput() { + selectNodesBeginningWith(findInput); + if (findInputClearer != null) { + findInputClearer.stop(); + findInputClearer = null; + } + findInputClearer = new Thread() { + public void run() { + try { + sleep(4000); + findInput = ""; + //System.out.println("clearing input"); + } + catch (InterruptedException iex) {} + } + }; + findInputClearer.start(); + } + + public void selectNodesBeginningWith(String input) { + selection.clear(); + List<Node> matchingNodes = new ArrayList<Node>(); + for (Iterator<Node> nodesI = getSourceGraph().getNodes().iterator(); nodesI.hasNext();) { + Node node = nodesI.next(); + if (node.getCurrentPainter() != null) { + String label = node.getCurrentPainter().getLabel(node); + if (label != null && label.startsWith(input)) { + matchingNodes.add(node); + } + } + } + //if (matchingNodes.size() < 4) { + selection.addNodes(matchingNodes); + //} + } + + public void nodesAddedToSelection(SelectionModel nodeSelectionModel, Collection<Node> nodes) { + repaint(); + } + + public void nodesRemovedFromSelection(SelectionModel nodeSelectionModel, Collection<Node> nodes) { + repaint(); + } + + public void selectionCleared(SelectionModel nodeSelectionModel) { + repaint(); + } + + /** + * @see org.mediavirus.graphl.selection.SelectionListener#edgesAddedToSelection(org.mediavirus.graphl.selection.SelectionModel, java.util.Collection) + */ + public void edgesAddedToSelection(SelectionModel nodeSelectionModel, Collection<Edge> edges) { + repaint(); + } + + /** + * @see org.mediavirus.graphl.selection.SelectionListener#edgesRemovedFromSelection(org.mediavirus.graphl.selection.SelectionModel, java.util.Collection) + */ + public void edgesRemovedFromSelection(SelectionModel nodeSelectionModel, Collection<Edge> edges) { + repaint(); + } + } |