[graphl-cvs] graphl/src/org/mediavirus/graphl GraphlApplication.java GraphlApplet.java GraphlPane.ja
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2004-12-29 14:31:46
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19091/src/org/mediavirus/graphl Modified Files: GraphlApplication.java GraphlApplet.java GraphlPane.java GraphlPanel.java Log Message: - FEATURE: updated applets parameters to match application command line options - FEATURE: GraphlPane now maintains a pointer to node+edge the mouse is currently over - FEATURE: started implementation of generic type menu - FEATURE: started implementation of node manipulator - BUG: fixed graph context menu - CODE: moved AbstractManipulator to correct package - CODE: added setHeight + setWidth in node interface - CODE: replaced zoomButton with a label - DOC: some documentation Index: GraphlPanel.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlPanel.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** GraphlPanel.java 10 Dec 2004 16:13:04 -0000 1.19 --- GraphlPanel.java 29 Dec 2004 14:31:33 -0000 1.20 *************** *** 12,15 **** --- 12,17 ---- import java.awt.event.KeyEvent; import java.awt.event.KeyListener; + import java.awt.event.MouseAdapter; + import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; *************** *** 24,27 **** --- 26,30 ---- import org.mediavirus.graphl.graph.*; 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; *************** *** 30,34 **** import javax.swing.JPanel; - import javax.swing.JButton; /** * @author Flo Ledermann --- 33,36 ---- *************** *** 49,53 **** private JPanel spacerPanel = null; ! private JButton jButton = null; public GraphlPanel(){ --- 51,55 ---- private JPanel spacerPanel = null; ! private JLabel zoomLabel = null; public GraphlPanel(){ *************** *** 136,140 **** topPanel.add(getZoomSlider(), c2); topPanel.add(getSpacerPanel(), gridBagConstraints6); ! topPanel.add(getJButton(), gridBagConstraints11); } --- 138,142 ---- topPanel.add(getZoomSlider(), c2); topPanel.add(getSpacerPanel(), gridBagConstraints6); ! topPanel.add(getZoomLabel(), gridBagConstraints11); } *************** *** 157,161 **** public void stateChanged(ChangeEvent e) { graphPane.setScaleFactor(zoomSlider.getValue()/100.0f); ! getJButton().setText("Zoom: " + zoomSlider.getValue() + "%"); } }); --- 159,163 ---- public void stateChanged(ChangeEvent e) { graphPane.setScaleFactor(zoomSlider.getValue()/100.0f); ! getZoomLabel().setText("Zoom: " + zoomSlider.getValue() + "%"); } }); *************** *** 193,196 **** --- 195,199 ---- graphPane.setEnabled(true); graphPane.addManipulator(new GraphlManipulator()); + graphPane.addManipulator(new DefaultNodeManipulator()); graphPane.getGraph().addGraphListener(this); graphPane.addKeyListener(this); *************** *** 309,329 **** } ! private JButton getJButton() { ! if (jButton == null) { ! jButton = new JButton(); ! jButton.setText("Zoom: 100%"); ! jButton.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 9)); ! jButton.setPreferredSize(new java.awt.Dimension(60,12)); ! jButton.setMargin(new java.awt.Insets(0,0,0,0)); ! jButton.setMaximumSize(new java.awt.Dimension(60,12)); ! jButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); ! jButton.setFocusPainted(false); ! jButton.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent e) { getZoomSlider().setValue(100); } }); } ! return jButton; } --- 312,330 ---- } ! private JLabel getZoomLabel() { ! if (zoomLabel == null) { ! zoomLabel = new JLabel(); ! zoomLabel.setText("Zoom: 100%"); ! zoomLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 9)); ! zoomLabel.setPreferredSize(new java.awt.Dimension(60,12)); ! zoomLabel.setMaximumSize(new java.awt.Dimension(60,12)); ! zoomLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); ! zoomLabel.addMouseListener(new MouseAdapter() { ! public void mouseClicked(MouseEvent e) { getZoomSlider().setValue(100); } }); } ! return zoomLabel; } *************** *** 331,335 **** * @param visible */ ! public void setControlsVisible(boolean visible) { getTopPanel().setVisible(visible); } --- 332,336 ---- * @param visible */ ! public void setToolbarVisible(boolean visible) { getTopPanel().setVisible(visible); } Index: GraphlApplet.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlApplet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GraphlApplet.java 14 Oct 2004 13:03:04 -0000 1.8 --- GraphlApplet.java 29 Dec 2004 14:31:33 -0000 1.9 *************** *** 26,30 **** import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.graph.rdf.RDFGraph; - import org.mediavirus.graphl.view.GraphFacetRegistry; --- 26,29 ---- *************** *** 40,44 **** private JPanel bottomPanel; ! private RDFGraph settings = new RDFGraph(); /** A List with all configuration nodes in the settings graph */ private List configurations = new ArrayList(); --- 39,43 ---- private JPanel bottomPanel; ! private RDFGraph settingsGraph = new RDFGraph(); /** A List with all configuration nodes in the settings graph */ private List configurations = new ArrayList(); *************** *** 98,101 **** --- 97,105 ---- super.init(); + String str = getParameter("toolbar"); + if (str.equalsIgnoreCase("off") || str.equalsIgnoreCase("false")) { + mainPanel.setToolbarVisible(false); + } + String savestr = getParameter("saveurl"); if (savestr != null) { *************** *** 110,114 **** } ! String urlstr = getParameter("configuration"); if (urlstr != null) { try { --- 114,118 ---- } ! String urlstr = getParameter("config"); if (urlstr != null) { try { *************** *** 121,137 **** try { URL settingsurl = new URL(getDocumentBase(), urlstr); ! System.out.println("Config URL: " + urlstr); ! settings.clear(); ! settings.readFromURL(settingsurl); ! for (Iterator nodes = settings.getNodes().iterator(); nodes.hasNext();) { ! Node node = (Node) nodes.next(); ! if (node.hasType("http://www.mediavirus.org/graphl#Configuration")) { ! configurations.add(node); } } ! if (configurations.size() > 0) { ! mainPanel.graphPane.setFacetRegistry(new GraphFacetRegistry(settings,(Node)configurations.get(0))); } --- 125,145 ---- try { URL settingsurl = new URL(getDocumentBase(), urlstr); ! settingsGraph.clear(); ! settingsGraph.readFromURL(settingsurl); ! mainPanel.graphPane.setConfigurationGraph(settingsGraph); ! 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("http://www.mediavirus.org/graphl#default","").equalsIgnoreCase("true")) { ! defaultSettings = node; } + i++; } ! if (defaultSettings != null) { ! mainPanel.graphPane.setConfiguration(defaultSettings); } *************** *** 153,157 **** try { URL rdfurl = new URL(getDocumentBase(), urlstr); - System.out.println("URL: " + urlstr); ((RDFGraph)mainPanel.getGraph()).readFromURL(rdfurl); } --- 161,164 ---- Index: GraphlApplication.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlApplication.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GraphlApplication.java 10 Dec 2004 16:13:04 -0000 1.16 --- GraphlApplication.java 29 Dec 2004 14:31:30 -0000 1.17 *************** *** 34,39 **** import org.mediavirus.graphl.gui.OpenURLPanel; import org.mediavirus.graphl.painter.NodePainter; - import org.mediavirus.graphl.view.FacetRegistry; - import org.mediavirus.graphl.view.GraphFacetRegistry; import org.mediavirus.graphl.vocabulary.DC; import org.mediavirus.graphl.vocabulary.FOAF; --- 34,37 ---- *************** *** 77,81 **** /** ! * @throws java.awt.HeadlessException */ public GraphlApplication() { --- 75,79 ---- /** ! * Constructs a new instance of GraphlApplication. All the GUI is set up here. */ public GraphlApplication() { *************** *** 190,194 **** /** ! * */ protected void doExit() { --- 188,192 ---- /** ! * Exits the application. If the graph has not been saved, the user is asked if it should be saved. */ protected void doExit() { *************** *** 208,212 **** /** ! * */ protected void showURLDialog() { --- 206,210 ---- /** ! * Shows the dialog to load a graph from an URL, and loads the graph from that URL. */ protected void showURLDialog() { *************** *** 214,218 **** GenericDialog d = new GenericDialog(this, p, "Enter URL to open"); d.pack(); ! d.show(); if (d.getResult() == GenericDialog.OK_OPTION) { if (p.getURLString() != null) { --- 212,216 ---- GenericDialog d = new GenericDialog(this, p, "Enter URL to open"); d.pack(); ! d.setVisible(true); if (d.getResult() == GenericDialog.OK_OPTION) { if (p.getURLString() != null) { *************** *** 248,252 **** /** ! * */ protected void doNew() { --- 246,251 ---- /** ! * Clears the graph and resets the filename. If the graph has been changed, ! * the user is asked if the graph should be saved first. */ protected void doNew() { *************** *** 272,277 **** mainPanel.getGraphPane().resumeLayouter(); } /** ! * */ protected boolean doSaveAs() { --- 271,277 ---- mainPanel.getGraphPane().resumeLayouter(); } + /** ! * Shows the "Save As..." Dialog and saves the graph to the specified file. */ protected boolean doSaveAs() { *************** *** 306,310 **** /** ! * */ public boolean doSave() { --- 306,311 ---- /** ! * Saves the graph. If the graph was created from scratch, the "Save As..." dialog ! * is shown. */ public boolean doSave() { *************** *** 317,321 **** } ! protected boolean doSave(File f) { try { mainPanel.getGraph().writeToRDF(new FileOutputStream(currentFile)); --- 318,327 ---- } ! /** ! * Saves the graph to the specified file. ! * @param file The file to save the graph to. ! * @return Whether saving was successful. ! */ ! protected boolean doSave(File file) { try { mainPanel.getGraph().writeToRDF(new FileOutputStream(currentFile)); *************** *** 332,336 **** /** ! * */ protected void doLoad() { --- 338,342 ---- /** ! * Shows the "Open File" Dialog. */ protected void doLoad() { *************** *** 378,391 **** } ! public void loadFile(File f) throws IOException { try { ! if (f != null){ mainPanel.getGraphPane().pauseLayouter(); mainPanel.getGraph().clear(); ! mainPanel.getGraph().readFromFile(f.getAbsolutePath()); ! setTitle("Graphl - " + f.getName()); ! currentFile = f; } } --- 384,402 ---- } ! /** ! * Loads the graph from the specified file. ! * @param file The RDF file to load the graph from. ! * @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.getAbsolutePath()); ! setTitle("Graphl - " + file.getName()); ! currentFile = file; } } *************** *** 396,399 **** --- 407,414 ---- } + /** + * Loads the graph from the specified URL. + * @param url The URL of the RDF file to load. + */ public void loadURL(URL url) { if (url != null) { *************** *** 407,410 **** --- 422,429 ---- } + /** + * Reloads the current graph from its source. + * + */ public void reload() { if (currentURL != null) { *************** *** 429,434 **** public void actionPerformed(ActionEvent e) { ! FacetRegistry newRegistry = new GraphFacetRegistry(mainPanel.graphPane.getConfigurationGraph(),node); ! mainPanel.graphPane.setFacetRegistry(newRegistry); } } --- 448,452 ---- public void actionPerformed(ActionEvent e) { ! mainPanel.graphPane.setConfiguration(node); } } *************** *** 446,449 **** --- 464,473 ---- } + /** + * Loads the facet settings from the specified file. If a default configuration is + * found, it is set, otherwise the first configuration is set. + * @param filename The filename of the settings file. + * @throws IOException If file cannot be read. + */ public void loadSettings(String filename) throws IOException { *************** *** 453,458 **** --- 477,484 ---- 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(); *************** *** 462,475 **** configConfigurationMenu.add(item); settingsGroup.add(item); ! if (node.getProperty("http://www.mediavirus.org/graphl#default","").equalsIgnoreCase("true")) { defaultItem = item; ! } } ! ! if (defaultItem != null) defaultItem.setSelected(true); } ! public static void main(String[] args) { GraphlApplication app = new GraphlApplication(); --- 488,524 ---- configConfigurationMenu.add(item); settingsGroup.add(item); ! if ((i == 0) || node.getProperty("http://www.mediavirus.org/graphl#default","").equalsIgnoreCase("true")) { defaultItem = item; ! defaultSettings = node; ! } ! i++; } ! ! if (defaultItem != null) { ! mainPanel.graphPane.setConfiguration(defaultSettings); ! defaultItem.setSelected(true); ! } ! } ! /** ! * Starts an instance of GraphlApplication. The following command line arguments are supported: ! * <table> ! * <tr><td>size=<width>,<height></td><td>Opens the main application window in the specified size.</td></tr> ! * <tr><td>pos=<x>,<y></td><td>Positions the upper left corner of the main application window at the specified screen position.</td></tr> ! * <tr><td>config=<filename.rdf></td><td>Loads the specified file as configuration file.</td></tr> ! * <tr><td>refresh=<seconds></td><td>Reloads the graph every n seconds.</td></tr> ! * <tr><td>decorations={on|off}</td><td>Controls the window border and titlebar.</td></tr> ! * <tr><td>toolbar={on|off}</td><td>Controls the main application toolbar.</td></tr> ! * <tr><td>menubar={on|off}</td><td>Controls the menubar.</td></tr> ! * <tr><td>{<filename>|<url>}</td><td>Loads the specified file or URL.</td></tr> ! * ! * @param args The command line arguments received from the console. ! */ public static void main(String[] args) { + + // try { + // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + // } catch (Exception e) { } GraphlApplication app = new GraphlApplication(); *************** *** 518,524 **** app.setLocation(pos[0], pos[1]); app.setUndecorated(!decorations); ! app.setControlsVisible(controls); app.setMenubarVisible(menubar); ! app.show(); try { --- 567,573 ---- app.setLocation(pos[0], pos[1]); app.setUndecorated(!decorations); ! app.setToolbarVisible(controls); app.setMenubarVisible(menubar); ! app.setVisible(true); try { *************** *** 543,547 **** /** ! * @param visible */ private void setMenubarVisible(boolean visible) { --- 592,597 ---- /** ! * Controls the visibility of the menu bar. ! * @param visible The new visibility setting. */ private void setMenubarVisible(boolean visible) { *************** *** 550,561 **** /** ! * @param visible */ ! private void setControlsVisible(boolean visible) { ! mainPanel.setControlsVisible(visible); } /** ! * @param i */ private void scheduleRefresh(int duration) { --- 600,614 ---- /** ! * Controls the visibility of the toolbar. ! * @param visible The new visibility setting. */ ! private void setToolbarVisible(boolean visible) { ! mainPanel.setToolbarVisible(visible); } /** ! * Starts a Thread to reload the graph every <em>duration</em> seconds. ! * ! * @param duration The duration in seconds between two reloads. */ private void scheduleRefresh(int duration) { *************** *** 577,580 **** --- 630,638 ---- } + /** + * Prints usage information to the console. + * + * @param exit Whether the application should quit after printing the usage information. + */ public static void usage(boolean exit){ System.out.println("-------------------------------------------------------------------"); Index: GraphlPane.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlPane.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GraphlPane.java 10 Dec 2004 16:13:04 -0000 1.16 --- GraphlPane.java 29 Dec 2004 14:31:33 -0000 1.17 *************** *** 84,87 **** --- 84,90 ---- private boolean layouterRunning; + + Node hoverNode = null; + Edge hoverEdge = null; /** *************** *** 540,549 **** --- 543,584 ---- switch (e.getID()) { case MouseEvent.MOUSE_MOVED: + Point p = new Point(); + screenToGraphPoint(e.getPoint(),p); + Node node = getNodeAtPoint(p); + if (node != null) { + if (node != hoverNode) { + hoverNode = node; + } + } + else { + if (hoverNode != null) { + hoverNode = null; + } + } + if (hoverNode == null) { + Edge edge = getNearestEdge(p); + if (edge != null) { + if (edge != hoverEdge) { + hoverEdge = edge; + } + } + else { + if (hoverEdge != null) { + hoverEdge = null; + } + } + + } + for (int i=0;i<manipulators.size() && !e.isConsumed();i++) ((Manipulator)manipulators.get(i)).mouseMoved(e); + break; + case MouseEvent.MOUSE_DRAGGED: + for (int i=0;i<manipulators.size() && !e.isConsumed();i++) ((Manipulator)manipulators.get(i)).mouseDragged(e); + break; } *************** *** 695,698 **** --- 730,735 ---- /** A List with all configuration nodes in the settings graph */ private List configurations = new ArrayList(); + + private Node currentConfiguration = null; public void setConfigurationGraph(Graph settingsGraph) { *************** *** 706,723 **** if (node.hasType("http://www.mediavirus.org/graphl#Configuration")) { configurations.add(node); ! if (node.getProperty("http://www.mediavirus.org/graphl#default","").equalsIgnoreCase("true")) { ! defaultConfiguration = node; ! } } } - - if (configurations.size() > 0) { - if (defaultConfiguration != null) { - setFacetRegistry(new GraphFacetRegistry(settingsGraph,defaultConfiguration)); - } - else { - setFacetRegistry(new GraphFacetRegistry(settingsGraph,(Node)configurations.get(0))); - } - } } --- 743,749 ---- if (node.hasType("http://www.mediavirus.org/graphl#Configuration")) { configurations.add(node); ! node.setProperty("http://www.mediavirus.org/graphl#active","false"); } } } *************** *** 730,732 **** --- 756,783 ---- return configurations; } + + public Node getCurrentConfiguration() { + return currentConfiguration; + } + + public void setConfiguration(Node configuration){ + if (currentConfiguration != null) { + currentConfiguration.setProperty("http://www.mediavirus.org/graphl#active","false"); + } + currentConfiguration = configuration; + setFacetRegistry(new GraphFacetRegistry(settingsGraph,configuration)); + configuration.setProperty("http://www.mediavirus.org/graphl#active","true"); + } + /** + * @return Returns the hoverNode. + */ + public Node getHoverNode() { + return hoverNode; + } + /** + * @return Returns the hoverEdge. + */ + public Edge getHoverEdge() { + return hoverEdge; + } } |