[graphl-cvs] graphl/src/org/mediavirus/graphl GraphlApplication.java GraphlPane.java GraphlApplet.ja
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2004-10-14 13:03:51
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12051/src/org/mediavirus/graphl Modified Files: GraphlApplication.java GraphlPane.java GraphlApplet.java GraphlPanel.java Log Message: - FEATURE: added z-index support for painting nodes & edges - FEATURE: BoxNodePainter draws rounded rectangles - FEATURE: Font for boxnodepainter is configurable - FEATURE: labelcolor of edgepainter is configurable - FEATURE: added utility functions for namespace compression/expansion - REFACTOR: moved layouter to graphpane - BUG: removed value property from graphelements - BUG: stopping layouter when displaying contextmenus etc. - BUG: fixed panning after startup - removed obsolete commented-out code Index: GraphlPanel.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlPanel.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GraphlPanel.java 4 Oct 2004 10:21:04 -0000 1.14 --- GraphlPanel.java 14 Oct 2004 13:03:04 -0000 1.15 *************** *** 27,32 **** import org.mediavirus.graphl.gui.GenericDialog; import org.mediavirus.graphl.interaction.GraphlManipulator; - import org.mediavirus.graphl.layout.GraphlLayoutStrategy; - import org.mediavirus.graphl.layout.Layouter; import org.mediavirus.graphl.painter.EdgePainter; import org.mediavirus.graphl.painter.NodePainter; --- 27,30 ---- *************** *** 53,58 **** JCheckBox layoutBox; - Layouter layouter; - private JSlider zoomSlider; private JComboBox nodePainterMenu; --- 51,54 ---- *************** *** 65,73 **** private JButton edgePainterConfigureButton = null; private JButton jButton = null; public GraphlPanel(){ initialize(); - - layouter = new Layouter(new GraphlLayoutStrategy(graphPane.getGraph(), graphPane.getFacetRegistry())); - layouter.start(); } --- 61,67 ---- private JButton edgePainterConfigureButton = null; private JButton jButton = null; + public GraphlPanel(){ initialize(); } *************** *** 80,83 **** --- 74,79 ---- add(getTopPanel(), BorderLayout.NORTH); + getTopPanel().setVisible(false); + } *************** *** 204,211 **** public void actionPerformed(ActionEvent e) { if (layoutBox.isSelected()) { ! layouter.start(); } else { ! layouter.stop(); } } --- 200,207 ---- public void actionPerformed(ActionEvent e) { if (layoutBox.isSelected()) { ! graphPane.startLayouter(); } else { ! graphPane.stopLayouter(); } } *************** *** 219,223 **** } ! private GraphlPane getGraphPane() { if (graphPane == null) { graphPane = new GraphlPane(); --- 215,219 ---- } ! public GraphlPane getGraphPane() { if (graphPane == null) { graphPane = new GraphlPane(); *************** *** 295,299 **** return edgePainterMenu; } ! public boolean nodeRemove(Node n) { return true; --- 291,295 ---- return edgePainterMenu; } ! public boolean nodeRemove(Node n) { return true; *************** *** 308,324 **** } - public void stopLayout() { - layouter.stop(); - } - - public void resumeLayout(){ - if (layoutBox.isSelected()) { - layouter.start(); - } - else { - layouter.stop(); - } - } - public RDFGraph getGraph() { return (RDFGraph) graphPane.getGraph(); --- 304,307 ---- Index: GraphlApplet.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlApplet.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GraphlApplet.java 4 Oct 2004 10:21:03 -0000 1.7 --- GraphlApplet.java 14 Oct 2004 13:03:04 -0000 1.8 *************** *** 206,210 **** super.start(); ! mainPanel.resumeLayout(); } --- 206,210 ---- super.start(); ! mainPanel.getGraphPane().resumeLayouter(); } *************** *** 215,219 **** super.stop(); ! mainPanel.stopLayout(); } --- 215,219 ---- super.stop(); ! mainPanel.getGraphPane().stopLayouter(); } Index: GraphlApplication.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlApplication.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GraphlApplication.java 5 Oct 2004 07:54:20 -0000 1.9 --- GraphlApplication.java 14 Oct 2004 13:03:04 -0000 1.10 *************** *** 46,49 **** --- 46,51 ---- */ public class GraphlApplication extends JFrame { + + public static final String DEFAULT_FILE = null; GraphlPanel mainPanel; *************** *** 252,256 **** } ! mainPanel.stopLayout(); mainPanel.getGraph().clear(); mainPanel.getGraph().resetDirty(); --- 254,258 ---- } ! mainPanel.getGraphPane().pauseLayouter(); mainPanel.getGraph().clear(); mainPanel.getGraph().resetDirty(); *************** *** 259,263 **** setTitle("Graphl - untitled"); ! mainPanel.resumeLayout(); } /** --- 261,265 ---- setTitle("Graphl - untitled"); ! mainPanel.getGraphPane().resumeLayouter(); } /** *************** *** 355,377 **** if (option == JFileChooser.APPROVE_OPTION) { - if (chooser.getSelectedFile() != null){ - currentFile = chooser.getSelectedFile(); - } - - mainPanel.stopLayout(); ! mainPanel.getGraph().clear(); ! try { ! mainPanel.getGraph().readFromFile(chooser.getSelectedFile().getAbsolutePath()); ! setTitle("Graphl - " + chooser.getSelectedFile().getName()); ! } catch (IOException ioex) { ioex.printStackTrace(); JOptionPane.showMessageDialog(this, "Error while loading file:\n" + ioex.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } ! finally { ! mainPanel.resumeLayout(); ! } } } --- 357,388 ---- if (option == JFileChooser.APPROVE_OPTION) { ! try { ! loadFile(chooser.getSelectedFile()); ! } catch (IOException ioex) { ioex.printStackTrace(); JOptionPane.showMessageDialog(this, "Error while loading file:\n" + ioex.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } ! ! } ! } ! ! 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; ! } } + finally { + mainPanel.getGraphPane().resumeLayouter(); + } + } *************** *** 399,403 **** int[] pos = {0,0}; boolean decorations = true; ! String filename = System.getProperty("user.dir") + "/graphs/default.rdf"; String configfile = System.getProperty("user.dir") + "/config/config.rdf"; --- 410,414 ---- int[] pos = {0,0}; boolean decorations = true; ! String filename = System.getProperty("user.dir") + DEFAULT_FILE; String configfile = System.getProperty("user.dir") + "/config/config.rdf"; *************** *** 433,438 **** try { app.loadSettings(configfile); ! app.mainPanel.getGraph().readFromFile(filename); ! app.setTitle("Graphl - default.rdf"); } catch (IOException ioex) { --- 444,450 ---- try { app.loadSettings(configfile); ! if (filename != null) { ! app.loadFile(new File(filename)); ! } } catch (IOException ioex) { *************** *** 449,453 **** System.out.println("usage:"); System.out.println("graphl [size=<width>,<height>] [pos=<x>,<y>] [decorations={on|off}]\n" + ! " [settings=<filename.rdf>] [<filename.rdf>]"); System.out.println("-------------------------------------------------------------------"); if (exit) System.exit(0); --- 461,465 ---- System.out.println("usage:"); System.out.println("graphl [size=<width>,<height>] [pos=<x>,<y>] [decorations={on|off}]\n" + ! " [config=<filename.rdf>] [<filename.rdf>]"); System.out.println("-------------------------------------------------------------------"); if (exit) System.exit(0); Index: GraphlPane.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/GraphlPane.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GraphlPane.java 4 Oct 2004 10:21:03 -0000 1.12 --- GraphlPane.java 14 Oct 2004 13:03:04 -0000 1.13 *************** *** 40,57 **** import org.mediavirus.graphl.graph.rdf.RDFGraph; import org.mediavirus.graphl.interaction.Manipulator; ! import org.mediavirus.graphl.layout.AbsoluteNodeLayouter; ! import org.mediavirus.graphl.layout.NeutralEdgeLayouter; ! import org.mediavirus.graphl.layout.RepulsionNodeLayouter; ! import org.mediavirus.graphl.layout.SortedNodeLayouter; ! import org.mediavirus.graphl.layout.SpringEdgeLayouter; ! import org.mediavirus.graphl.layout.UnconstrainedNodeLayouter; ! import org.mediavirus.graphl.painter.BoxNodePainter; import org.mediavirus.graphl.painter.EdgePainter; - import org.mediavirus.graphl.painter.ImageNodePainter; - import org.mediavirus.graphl.painter.InvisibleEdgePainter; - import org.mediavirus.graphl.painter.InvisibleNodePainter; - import org.mediavirus.graphl.painter.ManhattanEdgePainter; import org.mediavirus.graphl.painter.NodePainter; - import org.mediavirus.graphl.painter.StraightLineEdgePainter; import org.mediavirus.graphl.selection.DefaultSelectionModel; import org.mediavirus.graphl.selection.SelectionModel; --- 40,47 ---- import org.mediavirus.graphl.graph.rdf.RDFGraph; import org.mediavirus.graphl.interaction.Manipulator; ! import org.mediavirus.graphl.layout.GraphlLayoutStrategy; ! import org.mediavirus.graphl.layout.Layouter; import org.mediavirus.graphl.painter.EdgePainter; import org.mediavirus.graphl.painter.NodePainter; import org.mediavirus.graphl.selection.DefaultSelectionModel; import org.mediavirus.graphl.selection.SelectionModel; *************** *** 71,78 **** private boolean autoRegisterTypes = true; AffineTransform transform = null; AffineTransform translationXF = null; AffineTransform scaleXF = null; ! private Point2D.Double translationPoint; FacetRegistry facetRegistry = new SimpleFacetRegistry(); --- 61,70 ---- private boolean autoRegisterTypes = true; + Layouter layouter; + AffineTransform transform = null; AffineTransform translationXF = null; AffineTransform scaleXF = null; ! private Point2D translationPoint = new Point2D.Double(0,0); FacetRegistry facetRegistry = new SimpleFacetRegistry(); *************** *** 82,86 **** protected Graph graph; /** The listener for the graph. */ ! protected GraphListener graphListner; /** The map of node positions. */ protected Map nodePositions; --- 74,78 ---- protected Graph graph; /** The listener for the graph. */ ! protected GraphListener graphListener; /** The map of node positions. */ protected Map nodePositions; *************** *** 89,96 **** /** The map of rigestered manipulators keyed by their name. */ protected Map manipulatorsByName; - private NodePainter defaultNodePainter; protected SelectionModel selection; /** * Creates a graph pane. --- 81,89 ---- /** The map of rigestered manipulators keyed by their name. */ protected Map manipulatorsByName; protected SelectionModel selection; + private boolean layouterRunning; + /** * Creates a graph pane. *************** *** 100,104 **** public GraphlPane(Graph graph) { super(null); ! graphListner=new GraphHandler(); nodePositions=new HashMap(); manipulators=new ArrayList(); --- 93,97 ---- public GraphlPane(Graph graph) { super(null); ! graphListener=new GraphHandler(); nodePositions=new HashMap(); manipulators=new ArrayList(); *************** *** 108,112 **** setBackground(Color.white); ToolTipManager.sharedInstance().registerComponent(this); - defaultNodePainter = new BoxNodePainter(); updateTransform(); --- 101,104 ---- *************** *** 114,119 **** graph.addGraphListener(this); ! setupDefaultPainters(); ! } public GraphlPane() { --- 106,113 ---- graph.addGraphListener(this); ! layouter = new Layouter(new GraphlLayoutStrategy(getGraph(), getFacetRegistry())); ! startLayouter(); ! //setupDefaultPainters(); ! } public GraphlPane() { *************** *** 145,174 **** */ ! private void setupDefaultPainters() { ! ! // register the available painter classes (for user selection) ! facetRegistry.registerEdgePainter(new StraightLineEdgePainter()); ! facetRegistry.registerEdgePainter(new ManhattanEdgePainter()); ! facetRegistry.registerEdgePainter(new InvisibleEdgePainter()); ! ! facetRegistry.registerNodePainter(new BoxNodePainter()); ! facetRegistry.registerNodePainter(new ImageNodePainter()); ! facetRegistry.registerNodePainter(new InvisibleNodePainter()); ! ! facetRegistry.registerEdgeLayouter(new SpringEdgeLayouter()); ! facetRegistry.registerEdgeLayouter(new NeutralEdgeLayouter()); ! ! facetRegistry.registerNodeLayouter(new UnconstrainedNodeLayouter()); ! facetRegistry.registerNodeLayouter(new RepulsionNodeLayouter()); ! facetRegistry.registerNodeLayouter(new AbsoluteNodeLayouter()); ! facetRegistry.registerNodeLayouter(new SortedNodeLayouter()); ! ! // set default painters ! facetRegistry.setDefaultEdgePainter(new StraightLineEdgePainter()); ! facetRegistry.setDefaultNodePainter(new BoxNodePainter()); ! facetRegistry.setDefaultEdgeLayouter(new SpringEdgeLayouter()); ! facetRegistry.setDefaultNodeLayouter(new RepulsionNodeLayouter()); ! ! } private void updateTransform() { --- 139,168 ---- */ ! // private void setupDefaultPainters() { ! // ! // // register the available painter classes (for user selection) ! // facetRegistry.registerEdgePainter(new StraightLineEdgePainter()); ! // facetRegistry.registerEdgePainter(new ManhattanEdgePainter()); ! // facetRegistry.registerEdgePainter(new InvisibleEdgePainter()); ! // ! // facetRegistry.registerNodePainter(new BoxNodePainter()); ! // facetRegistry.registerNodePainter(new ImageNodePainter()); ! // facetRegistry.registerNodePainter(new InvisibleNodePainter()); ! // ! // facetRegistry.registerEdgeLayouter(new SpringEdgeLayouter()); ! // facetRegistry.registerEdgeLayouter(new NeutralEdgeLayouter()); ! // ! // facetRegistry.registerNodeLayouter(new UnconstrainedNodeLayouter()); ! // facetRegistry.registerNodeLayouter(new RepulsionNodeLayouter()); ! // facetRegistry.registerNodeLayouter(new AbsoluteNodeLayouter()); ! // facetRegistry.registerNodeLayouter(new SortedNodeLayouter()); ! // ! // // set default painters ! // facetRegistry.setDefaultEdgePainter(new StraightLineEdgePainter()); ! // facetRegistry.setDefaultNodePainter(new BoxNodePainter()); ! // facetRegistry.setDefaultEdgeLayouter(new SpringEdgeLayouter()); ! // facetRegistry.setDefaultNodeLayouter(new RepulsionNodeLayouter()); ! // ! // } private void updateTransform() { *************** *** 206,229 **** if (graph!=null) synchronized (graph) { Rectangle bounds=new Rectangle(); ! long edgesStart=System.currentTimeMillis(); ! Iterator iterator=graph.getEdges().iterator(); ! while (iterator.hasNext()) { ! Edge edge=(Edge)iterator.next(); ! getEdgeScreenBounds(edge,bounds); ! if (clipRectangle.intersects(bounds)) ! paintEdge(g2,edge); ! } ! long edgesDur=System.currentTimeMillis()-edgesStart; ! long nodesStart=System.currentTimeMillis(); ! iterator=graph.getNodes().iterator(); ! while (iterator.hasNext()) { ! Node node=(Node)iterator.next(); ! getNodeScreenBounds(node,bounds); ! if (clipRectangle.intersects(bounds)) ! paintNode(g2,node); } for (int i=0;i<manipulators.size();i++) ((Manipulator)manipulators.get(i)).paint(g2); } } --- 200,245 ---- if (graph!=null) synchronized (graph) { + // this is the main rendering loop + //TODO (2, 1h) we have to store zMin somewhere (GraphView?) and get it here to save 1 loop + int nextZ = 0, curZ = 0; Rectangle bounds=new Rectangle(); ! Iterator iterator; ! long renderStartTime=System.currentTimeMillis(); ! while (nextZ < Integer.MAX_VALUE) { ! curZ = nextZ; ! nextZ = Integer.MAX_VALUE; ! iterator=graph.getEdges().iterator(); ! while (iterator.hasNext()) { ! Edge edge=(Edge)iterator.next(); ! int z = edge.getZIndex(); ! if (z == curZ) { ! getEdgeScreenBounds(edge,bounds); ! if (clipRectangle.intersects(bounds)) { ! paintEdge(g2,edge); ! } ! } ! else if (z>curZ && z<nextZ){ ! nextZ = z; ! } ! } ! iterator=graph.getNodes().iterator(); ! while (iterator.hasNext()) { ! Node node=(Node)iterator.next(); ! int z = node.getZIndex(); ! if (z == curZ) { ! getNodeScreenBounds(node,bounds); ! if (clipRectangle.intersects(bounds)) { ! paintNode(g2,node); ! } ! } ! else if (z>curZ && z<nextZ){ ! nextZ = z; ! } ! } ! // System.out.println("curZ: " + curZ + " nextZ: " + nextZ + " dur: " + (System.currentTimeMillis()-renderStartTime)); } for (int i=0;i<manipulators.size();i++) ((Manipulator)manipulators.get(i)).paint(g2); + //long renderDuration = System.currentTimeMillis()-renderStartTime; } } *************** *** 402,409 **** Graph oldGraph = this.graph; if (this.graph!=null) ! this.graph.removeGraphListener(graphListner); this.graph=graph; if (this.graph!=null) ! this.graph.addGraphListener(graphListner); nodePositions.clear(); repaint(); --- 418,425 ---- Graph oldGraph = this.graph; if (this.graph!=null) ! this.graph.removeGraphListener(graphListener); this.graph=graph; if (this.graph!=null) ! this.graph.addGraphListener(graphListener); nodePositions.clear(); repaint(); *************** *** 437,447 **** /** - * @return - */ - private NodePainter getDefaultNodePainter() { - return defaultNodePainter; - } - - /** * Returns the node at given point, or <code>null</code> if there is no such node. * --- 453,456 ---- *************** *** 778,780 **** --- 787,825 ---- } + /** + * @return Returns the layouter. + */ + public Layouter getLayouter() { + return layouter; + } + + public void startLayouter() { + if (layouter != null) { + layouter.start(); + layouterRunning = true; + } + } + + public void stopLayouter() { + if (layouter != null) { + layouter.stop(); + layouterRunning = false; + } + } + + public void pauseLayouter() { + if (layouterRunning && layouter != null) { + layouter.stop(); + } + } + + public void resumeLayouter() { + if (layouterRunning && layouter != null) { + layouter.start(); + } + } + + public boolean isLayouterRunning() { + return layouterRunning; + } } |