Commit 6210d9d9 authored by Alex Bowen's avatar Alex Bowen

refactored view to use generic interface; view panel is now base swing view

parent ce2476c1
......@@ -37,8 +37,8 @@ import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.stream.file.FileSourcePajek;
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.swingViewer.Viewer.CloseFramePolicy;
import org.graphstream.ui.view.Viewer;
import org.graphstream.ui.view.Viewer.CloseFramePolicy;
import org.junit.Ignore;
@Ignore
......
......@@ -31,14 +31,13 @@
*/
package org.graphstream.ui.viewer.test;
import java.awt.BorderLayout;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.ui.view.Viewer;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.ui.swingViewer.Viewer;
import java.awt.BorderLayout;
public class DemoAllInSwing {
public static void main(String args[]) {
......@@ -53,7 +52,7 @@ public class DemoAllInSwing {
// On demande au viewer de consid�rer que le graphe ne sera lu et modifi� que
// dans le thread Swing.
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_SWING_THREAD);
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
// � Partir de l�, le viewer consid�re que le graphe est dans son propre thread,
// c'est-�-dire le thread Swing. Il est donc dangereux d'y toucher dans la thread
......
......@@ -44,7 +44,7 @@ import org.graphstream.stream.thread.ThreadProxyPipe;
import org.graphstream.ui.geom.Point3;
import org.graphstream.ui.graphicGraph.GraphPosLengthUtils;
import org.graphstream.ui.layout.springbox.implementations.LinLog;
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.view.Viewer;
/**
* This test creates a layout (instead of using the default layout of
......
......@@ -37,7 +37,7 @@ import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
import org.graphstream.stream.file.FileSourceDGS;
import org.graphstream.stream.thread.*;
import org.graphstream.ui.swingViewer.*;
import org.graphstream.ui.view.Viewer;
public class DemoTwoGraphsInOneViewer {
public static final String GRAPH = "data/dorogovtsev_mendes6000.dgs";
......
......@@ -34,8 +34,8 @@ package org.graphstream.ui.viewer.test;
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.ui.swingViewer.ViewerListener;
import org.graphstream.ui.swingViewer.ViewerPipe;
import org.graphstream.ui.view.ViewerListener;
import org.graphstream.ui.view.ViewerPipe;
/**
* Test the viewer.
......
......@@ -41,7 +41,7 @@ import org.graphstream.stream.thread.ThreadProxyPipe;
import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants;
import org.graphstream.ui.spriteManager.Sprite;
import org.graphstream.ui.spriteManager.SpriteManager;
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.view.Viewer;
public class DemoViewerJComponents {
public static void main(String args[]) {
......
......@@ -39,6 +39,7 @@ import org.graphstream.stream.GraphParseException;
import org.graphstream.stream.Pipe;
import org.graphstream.stream.file.FileSink;
import org.graphstream.stream.file.FileSource;
import org.graphstream.ui.view.Viewer;
/**
......@@ -616,12 +617,12 @@ public interface Graph extends Element, Pipe, Iterable<Node>, Structure {
* automatically launch a graph layout algorithm in its own thread to
* compute best node positions.
*
* @see org.graphstream.ui.swingViewer.Viewer
* @see org.graphstream.ui.view.Viewer
* @see #display(boolean )
* @return a graph viewer that allows to command the viewer (it often run in
* another thread).
*/
org.graphstream.ui.swingViewer.Viewer display();
Viewer display();
/**
* Utility method that creates a new graph viewer, and register the graph in
......@@ -631,12 +632,12 @@ public interface Graph extends Element, Pipe, Iterable<Node>, Structure {
* @param autoLayout
* If true a layout algorithm is launched in its own thread to
* compute best node positions.
* @see org.graphstream.ui.swingViewer.Viewer
* @see org.graphstream.ui.view.Viewer
* @see #display()
* @return a graph viewer that allows to command the viewer (it often run in
* another thread).
*/
org.graphstream.ui.swingViewer.Viewer display(boolean autoLayout);
Viewer display(boolean autoLayout);
// New methods
......
......@@ -31,6 +31,10 @@
*/
package org.graphstream.graph.implementations;
import org.graphstream.graph.CompoundAttribute;
import org.graphstream.graph.Element;
import org.graphstream.graph.NullAttributeException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
......@@ -38,10 +42,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.graphstream.graph.CompoundAttribute;
import org.graphstream.graph.Element;
import org.graphstream.graph.NullAttributeException;
/**
* A base implementation of an element.
*
......@@ -138,10 +138,6 @@ public abstract class AbstractElement implements Element {
* implemented by sub-elements in order to send events to the graph
* listeners.
*
* @param sourceId
* The source of the change.
* @param timeId
* The source time of the change, for synchronization.
* @param attribute
* The attribute name that changed.
* @param event
......@@ -249,12 +245,12 @@ public abstract class AbstractElement implements Element {
* @complexity O(log(n)) with n being the number of attributes of this
* element.
*/
public CharSequence getLabel(String key) {
public String getLabel(String key) {
if (attributes != null) {
Object o = attributes.get(key);
if (o != null && o instanceof CharSequence)
return (CharSequence) o;
return o.toString();
}
if (nullAttributesAreErrors())
......
......@@ -31,11 +31,6 @@
*/
package org.graphstream.graph.implementations;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import org.graphstream.graph.Edge;
import org.graphstream.graph.EdgeFactory;
import org.graphstream.graph.EdgeRejectedException;
......@@ -57,9 +52,14 @@ import org.graphstream.stream.file.FileSourceFactory;
import org.graphstream.ui.layout.Layout;
import org.graphstream.ui.layout.Layouts;
import org.graphstream.ui.swingViewer.GraphRenderer;
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.view.Viewer;
import org.graphstream.util.GraphListeners;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
/**
* <p>
* This class provides a basic implementation of
......
......@@ -57,7 +57,7 @@ import org.graphstream.stream.GraphReplay;
import org.graphstream.stream.Sink;
import org.graphstream.stream.file.FileSink;
import org.graphstream.stream.file.FileSource;
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.view.Viewer;
public class Graphs {
......
......@@ -62,6 +62,7 @@ import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units;
import org.graphstream.ui.graphicGraph.stylesheet.StyleSheet;
import org.graphstream.ui.graphicGraph.stylesheet.Value;
import org.graphstream.ui.graphicGraph.stylesheet.Values;
import org.graphstream.ui.view.Viewer;
import org.graphstream.util.GraphListeners;
/**
......@@ -835,12 +836,12 @@ public class GraphicGraph extends AbstractElement implements Graph,
return (T) node;
}
public org.graphstream.ui.swingViewer.Viewer display() {
public Viewer display() {
throw new RuntimeException(
"GraphicGraph is used by display() and cannot recursively define display()");
}
public org.graphstream.ui.swingViewer.Viewer display(boolean autoLayout) {
public Viewer display(boolean autoLayout) {
throw new RuntimeException(
"GraphicGraph is used by display() and cannot recursively define display()");
}
......
......@@ -33,11 +33,12 @@ package org.graphstream.ui.swingViewer;
import org.graphstream.ui.graphicGraph.GraphicElement;
import org.graphstream.ui.graphicGraph.GraphicGraph;
import org.graphstream.ui.swingViewer.util.Camera;
import org.graphstream.ui.swingViewer.util.DefaultMouseManager;
import org.graphstream.ui.swingViewer.util.DefaultShortcutManager;
import org.graphstream.ui.swingViewer.util.MouseManager;
import org.graphstream.ui.swingViewer.util.ShortcutManager;
import org.graphstream.ui.view.Viewer;
import org.graphstream.ui.view.Camera;
import org.graphstream.ui.view.util.DefaultMouseManager;
import org.graphstream.ui.view.util.DefaultShortcutManager;
import org.graphstream.ui.view.util.MouseManager;
import org.graphstream.ui.view.util.ShortcutManager;
import javax.swing.JFrame;
import java.awt.BorderLayout;
......@@ -101,7 +102,7 @@ import java.util.Collection;
* graph attribute is the identifier of the view.
* </p>
*/
public class DefaultView extends View implements WindowListener, ComponentListener
public class DefaultView extends ViewPanel implements WindowListener, ComponentListener
{
private static final long serialVersionUID = - 4489484861592064398L;
......@@ -155,12 +156,12 @@ public class DefaultView extends View implements WindowListener, ComponentListen
// Command
@Override
public Camera getCamera() {
return renderer.getCamera();
}
@Override
public void display(GraphicGraph graph, boolean graphChanged) {
repaint();
}
......@@ -190,7 +191,6 @@ public class DefaultView extends View implements WindowListener, ComponentListen
}
}
@Override
public void close(GraphicGraph graph) {
renderer.close();
graph.addAttribute("ui.viewClosed", getId());
......@@ -202,14 +202,12 @@ public class DefaultView extends View implements WindowListener, ComponentListen
openInAFrame(false);
}
@Override
public void resizeFrame(int width, int height) {
if (frame != null) {
frame.setSize(width, height);
}
}
@Override
public void openInAFrame(boolean on) {
if (on) {
if (frame == null) {
......@@ -250,19 +248,16 @@ public class DefaultView extends View implements WindowListener, ComponentListen
// Selection
@Override
public void beginSelectionAt(double x1, double y1) {
renderer.beginSelectionAt(x1, y1);
repaint();
}
@Override
public void selectionGrowsAt(double x, double y) {
renderer.selectionGrowsAt(x, y);
repaint();
}
@Override
public void endSelectionAt(double x2, double y2) {
renderer.endSelectionAt(x2, y2);
repaint();
......@@ -331,18 +326,15 @@ public class DefaultView extends View implements WindowListener, ComponentListen
// Methods deferred to the renderer
@Override
public Collection<GraphicElement> allNodesOrSpritesIn(double x1, double y1,
double x2, double y2) {
return renderer.allNodesOrSpritesIn(x1, y1, x2, y2);
}
@Override
public GraphicElement findNodeOrSpriteAt(double x, double y) {
return renderer.findNodeOrSpriteAt(x, y);
}
@Override
public void moveElementAtPx(GraphicElement element, double x, double y) {
// The feedback on the node positions is often off since not needed
// and generating lots of events. We activate it here since the
......@@ -353,8 +345,7 @@ public class DefaultView extends View implements WindowListener, ComponentListen
renderer.moveElementAtPx(element, x, y);
graph.feedbackXYZ(on);
}
@Override
public void freezeElement(GraphicElement element, boolean frozen) {
if(frozen) {
element.addAttribute("layout.frozen");
......@@ -363,19 +354,16 @@ public class DefaultView extends View implements WindowListener, ComponentListen
}
}
@Override
public void setBackLayerRenderer(LayerRenderer renderer) {
this.renderer.setBackLayerRenderer(renderer);
repaint();
}
@Override
public void setForeLayoutRenderer(LayerRenderer renderer) {
this.renderer.setForeLayoutRenderer(renderer);
repaint();
}
@Override
public void setMouseManager(MouseManager manager) {
if(mouseClicks != null)
mouseClicks.release();
......@@ -388,7 +376,6 @@ public class DefaultView extends View implements WindowListener, ComponentListen
mouseClicks = manager;
}
@Override
public void setShortcutManager(ShortcutManager manager) {
if(shortcuts != null)
shortcuts.release();
......
......@@ -33,7 +33,7 @@ package org.graphstream.ui.swingViewer;
import org.graphstream.ui.graphicGraph.GraphicElement;
import org.graphstream.ui.graphicGraph.GraphicGraph;
import org.graphstream.ui.swingViewer.util.Camera;
import org.graphstream.ui.view.Camera;
import java.awt.Container;
import java.awt.Graphics2D;
......
......@@ -31,13 +31,14 @@
*/
package org.graphstream.ui.swingViewer;
import org.graphstream.ui.graphicGraph.GraphicGraph;
import org.graphstream.ui.graphicGraph.StyleGroupListener;
import org.graphstream.ui.view.Selection;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics2D;
import org.graphstream.ui.graphicGraph.GraphicGraph;
import org.graphstream.ui.graphicGraph.StyleGroupListener;
public abstract class GraphRendererBase implements GraphRenderer,
StyleGroupListener {
// Attribute
......
......@@ -31,16 +31,16 @@
*/
package org.graphstream.ui.swingViewer;
import java.awt.Graphics2D;
import org.graphstream.ui.graphicGraph.GraphicGraph;
import java.awt.Graphics2D;
/**
* A specific rendering class that can be plugged in any view and is called to
* draw under or above the graph.
*
* @see View#setForeLayoutRenderer(LayerRenderer)
* @see View#setBackLayerRenderer(LayerRenderer)
* @see org.graphstream.ui.view.View#setForeLayoutRenderer(LayerRenderer)
* @see org.graphstream.ui.view.View#setBackLayerRenderer(LayerRenderer)
*/
public interface LayerRenderer {
/**
......
/*
* Copyright 2006 - 2013
* Stefan Balev <stefan.balev@graphstream-project.org>
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of GraphStream <http://graphstream-project.org>.
*
* GraphStream is a library whose purpose is to handle static or dynamic
* graph, create them from scratch, file or any source and display them.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.ui.swingViewer;
import org.graphstream.ui.graphicGraph.GraphicElement;
import org.graphstream.ui.graphicGraph.GraphicGraph;
import org.graphstream.ui.swingViewer.util.Camera;
import org.graphstream.ui.swingViewer.util.MouseManager;
import org.graphstream.ui.swingViewer.util.ShortcutManager;
import javax.swing.JPanel;
import java.util.Collection;
/**
* A view on a graphic graph.
*
* <p>
* Basically a view is a Swing panel where a {@link GraphRenderer} renders the
* graphic graph. If you are in the Swing thread, you can change the view on the
* graphic graph using methods to translate, zoom and rotate the view.
* </p>
*/
public abstract class View extends JPanel {
private static final long serialVersionUID = 4372240131578395549L;
// Attribute
/**
* The view identifier.
*/
private String id;
// Construction
/**
* New view.
*
* @param identifier
* The view unique identifier.
*/
public View(String identifier) {
id = identifier;
}
// Access
public String getId() {
return id;
}
/**
* Get a camera object to provide control commands on the view.
*
* @return a Camera instance
*/
public abstract Camera getCamera();
/**
* Search for the first node or sprite (in that order) that contains the
* point at coordinates (x, y).
*
* @param x
* The point abscissa.
* @param y
* The point ordinate.
* @return The first node or sprite at the given coordinates or null if
* nothing found.
*/
public abstract GraphicElement findNodeOrSpriteAt(double x, double y);
/**
* Search for all the nodes and sprites contained inside the rectangle
* (x1,y1)-(x2,y2).
*
* @param x1
* The rectangle lowest point abscissa.
* @param y1
* The rectangle lowest point ordinate.
* @param x2
* The rectangle highest point abscissa.
* @param y2
* The rectangle highest point ordinate.
* @return The set of sprites and nodes in the given rectangle.
*/
public abstract Collection<GraphicElement> allNodesOrSpritesIn(double x1,
double y1, double x2, double y2);
// Command
/**
* Redisplay or update the view contents. Called by the Viewer.
*
* @param graph
* The graphic graph to represent.
* @param graphChanged
* True if the graph changed since the last call to this method.
*/
public abstract void display(GraphicGraph graph, boolean graphChanged);
/**
* Close definitively this view. Called by the Viewer.
*
* @param graph
* The graphic graph.
*/
public abstract void close(GraphicGraph graph);
/**
* Open this view JPanel in a frame. The argument allows to put the panel in
* a new frame or to remove it from the frame (if it already exists). Called
* by the Viewer.
*
* @param on
* Add the panel in its own frame or remove it if it already was
* in its own frame.
*/
public abstract void openInAFrame(boolean on);
/**
* Set the size of the view frame, if any. If this view has been open in a frame, this changes
* the size of the frame containing it.
*
* @param width The new width.
* @param height The new height.
*/
public abstract void resizeFrame(int width, int height);
/**
* Called by the mouse manager to specify where a node and sprite selection
* started.
*
* @param x1
* The selection start abscissa.
* @param y1
* The selection start ordinate.
*/
public abstract void beginSelectionAt(double x1, double y1);
/**
* The selection already started grows toward position (x, y).
*
* @param x
* The new end selection abscissa.
* @param y
* The new end selection ordinate.
*/
public abstract void selectionGrowsAt(double x, double y);
/**
* Called by the mouse manager to specify where a node and spite selection
* stopped.
*
* @param x2
* The selection stop abscissa.
* @param y2
* The selection stop ordinate.
*/
public abstract void endSelectionAt(double x2, double y2);
/**
* Freeze an element so that the optional layout cannot move it.
*
* @param element
* The element.
* @param frozen
* If true the element cannot be moved automatically.
*/
public abstract void freezeElement(GraphicElement element, boolean frozen);
/**
* Force an element to move at the given location in pixels.
*
* @param element
* The element.
* @param x
* The requested position abscissa in pixels.
* @param y
* The requested position ordinate in pixels.
*/
public abstract void moveElementAtPx(GraphicElement element, double x,
double y);
/**
* Set a layer renderer that will be called each time the graph needs to be
* redrawn before the graph is rendered. Pass "null" to remove the layer
* renderer.
*
* @param renderer
* The renderer (or null to remove it).
*/
public abstract void setBackLayerRenderer(LayerRenderer renderer);
/**
* Set a layer renderer that will be called each time the graph needs to be
* redrawn after the graph is rendered. Pass "null" to remove the layer
* renderer.
*
* @param renderer
* The renderer (or null to remove it).
*/
public abstract void setForeLayoutRenderer(LayerRenderer renderer);
/**
* Change the manager for mouse events on this view. If the value for the new manager is
* null, a default manager is installed. The {@link MouseManager#init(GraphicGraph, View)}
* method must not yet have been called.
* @param manager The new manager, or null to set the default manager.
* @see MouseManager
*/
public abstract void setMouseManager(MouseManager manager);
/**
* Change the manager for key and shortcuts events on this view. If the value for the new
* manager is null, a default manager is installed. The {@link ShortcutManager#init(GraphicGraph, View)}
* method must not yet have been called.
* @param manager The new manager, or null to set the default manager
* @see ShortcutManager
*/
public abstract void setShortcutManager(ShortcutManager manager);
}
\ No newline at end of file
/*
* Copyright 2006 - 2013
* Stefan Balev <stefan.balev@graphstream-project.org>
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of GraphStream <http://graphstream-project.org>.
*
* GraphStream is a library whose purpose is to handle static or dynamic
* graph, create them from scratch, file or any source and display them.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.ui.swingViewer;
import org.graphstream.ui.view.View;
import javax.swing.JPanel;
/**
* A view on a graphic graph.
* <p>
* <p>
* Basically a view is a Swing panel where a {@link org.graphstream.ui.swingViewer.GraphRenderer} renders the
* graphic graph. If you are in the Swing thread, you can change the view on the
* graphic graph using methods to translate, zoom and rotate the view.
* </p>
*/
public abstract class ViewPanel extends JPanel implements View
{
private static final long serialVersionUID = 4372240131578395549L;
/**