/*
* Copyright (c) 2003, The JUNG Authors
* All rights reserved.
*
* This software is open-source under the BSD license; see either "license.txt"
* or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
*
*/
package edu.uci.ics.jung.samples;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.print.Printable;
import java.awt.print.PrinterJob;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import edu.uci.ics.jung.algorithms.layout.AbstractLayout;
import edu.uci.ics.jung.algorithms.layout.StaticLayout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.annotations.AnnotationControls;
import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
import edu.uci.ics.jung.visualization.control.EditingModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode;
import edu.uci.ics.jung.visualization.control.ScalingControl;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
/**
* Shows how to create a graph editor with JUNG.
* Mouse modes and actions are explained in the help text.
* The application version of GraphEditorDemo provides a
* File menu with an option to save the visible graph as
* a jpeg file.
*
* @author Tom Nelson
*
*/
public class GraphEditorDemo extends JApplet implements Printable {
/**
*
*/
private static final long serialVersionUID = -2023243689258876709L;
/**
* the graph
*/
Graph graph;
AbstractLayout layout;
/**
* the visual component and renderer for the graph
*/
VisualizationViewer vv;
String instructions =
""+
"All Modes:
"+
""+
"- Right-click an empty area for Create Vertex popup"+
"
- Right-click on a Vertex for Delete Vertex popup"+
"
- Right-click on a Vertex for Add Edge menus
(if there are selected Vertices)"+
" - Right-click on an Edge for Delete Edge popup"+
"
- Mousewheel scales with a crossover value of 1.0.
"+
" - scales the graph layout when the combined scale is greater than 1
"+
" - scales the graph view when the combined scale is less than 1"+
"
"+
"Editing Mode:
"+
""+
"- Left-click an empty area to create a new Vertex"+
"
- Left-click on a Vertex and drag to another Vertex to create an Undirected Edge"+
"
- Shift+Left-click on a Vertex and drag to another Vertex to create a Directed Edge"+
"
"+
"Picking Mode:
"+
""+
"- Mouse1 on a Vertex selects the vertex"+
"
- Mouse1 elsewhere unselects all Vertices"+
"
- Mouse1+Shift on a Vertex adds/removes Vertex selection"+
"
- Mouse1+drag on a Vertex moves all selected Vertices"+
"
- Mouse1+drag elsewhere selects Vertices in a region"+
"
- Mouse1+Shift+drag adds selection of Vertices in a new region"+
"
- Mouse1+CTRL on a Vertex selects the vertex and centers the display on it"+
"
- Mouse1 double-click on a vertex or edge allows you to edit the label"+
"
"+
"Transforming Mode:
"+
""+
"- Mouse1+drag pans the graph"+
"
- Mouse1+Shift+drag rotates the graph"+
"
- Mouse1+CTRL(or Command)+drag shears the graph"+
"
- Mouse1 double-click on a vertex or edge allows you to edit the label"+
"
"+
"Annotation Mode:
"+
""+
"- Mouse1 begins drawing of a Rectangle"+
"
- Mouse1+drag defines the Rectangle shape"+
"
- Mouse1 release adds the Rectangle as an annotation"+
"
- Mouse1+Shift begins drawing of an Ellipse"+
"
- Mouse1+Shift+drag defines the Ellipse shape"+
"
- Mouse1+Shift release adds the Ellipse as an annotation"+
"
- Mouse3 shows a popup to input text, which will become"+
"
- a text annotation on the graph at the mouse location"+
"
"+
"";
/**
* create an instance of a simple graph with popup controls to
* create a graph.
*
*/
public GraphEditorDemo() {
// create a simple graph for the demo
graph = new SparseMultigraph();
this.layout = new StaticLayout(graph,
new Dimension(600,600));
vv = new VisualizationViewer(layout);
vv.setBackground(Color.white);
Function
Ads help maintain this website.