Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Sample programs using JUNG. Nearly all JUNG capabilities are demonstrated here.
Please study the source code for these examples prior to asking how to do something.
/*
* 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.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.Point2D;
import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import edu.uci.ics.jung.algorithms.layout.AggregateLayout;
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.KKLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.algorithms.layout.SpringLayout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Pair;
import edu.uci.ics.jung.graph.util.TestGraphs;
import edu.uci.ics.jung.visualization.DefaultVisualizationModel;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.VisualizationModel;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ScalingControl;
import edu.uci.ics.jung.visualization.decorators.PickableEdgePaintTransformer;
import edu.uci.ics.jung.visualization.decorators.PickableVertexPaintTransformer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.picking.PickedState;
/**
* Demonstrates the AggregateLayout
* class. In this demo, vertices are visually clustered as they
* are selected. The cluster is formed in a new Layout centered at the
* middle locations of the selected vertices. The size and layout
* algorithm for each new cluster is selectable.
*
* @author Tom Nelson
*
*/
@SuppressWarnings("serial")
public class SubLayoutDemo extends JApplet {
String instructions =
""+
"Use the Layout combobox to select the "+
"
underlying layout."+
"
Use the SubLayout combobox to select "+
"
the type of layout for any clusters you create."+
"
To create clusters, use the mouse to select "+
"
multiple vertices, either by dragging a region, "+
"
or by shift-clicking on multiple vertices."+
"
After you select vertices, use the "+
"
Cluster Picked button to cluster them using the "+
"
layout and size specified in the Sublayout comboboxen."+
"
Use the Uncluster All button to remove all"+
"
clusters."+
"
You can drag the cluster with the mouse." +
"
Use the 'Picking'/'Transforming' combo-box to switch"+
"
between picking and transforming mode.";
/**
* the graph
*/
Graph graph;
Map,Dimension> sizes = new HashMap,Dimension>();
@SuppressWarnings({ "unchecked", "rawtypes" })
Class[] layoutClasses = new Class[] {
CircleLayout.class,SpringLayout.class,FRLayout.class,KKLayout.class
};
/**
* the visual component and renderer for the graph
*/
VisualizationViewer vv;
AggregateLayout clusteringLayout;
Dimension subLayoutSize;
PickedState ps;
@SuppressWarnings("rawtypes")
Class subLayoutType = CircleLayout.class;
/**
* create an instance of a simple graph with controls to
* demo the zoomand hyperbolic features.
*
*/
public SubLayoutDemo() {
// create a simple graph for the demo
graph = TestGraphs.getOneComponentGraph();
// ClusteringLayout is a decorator class that delegates
// to another layout, but can also sepately manage the
// layout of sub-sets of vertices in circular clusters.
clusteringLayout = new AggregateLayout(new FRLayout(graph));
//new SubLayoutDecorator(new FRLayout(graph));
Dimension preferredSize = new Dimension(600,600);
final VisualizationModel visualizationModel =
new DefaultVisualizationModel(clusteringLayout, preferredSize);
vv = new VisualizationViewer(visualizationModel, preferredSize);
ps = vv.getPickedVertexState();
vv.getRenderContext().setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer(vv.getPickedEdgeState(), Color.black, Color.red));
vv.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer(vv.getPickedVertexState(),
Color.red, Color.yellow));
vv.setBackground(Color.white);
// add a listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller());
/**
* the regular graph mouse for the normal view
*/
final DefaultModalGraphMouse, ?> graphMouse = new DefaultModalGraphMouse