Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

73
LINES

< > BotCompany Repo | #1007170 // JGraphT Graphical Demo [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 2086K of libraries. Click here for Pure Java version (5618L/40K).

!7

import java.awt.geom.*;

lib 1007171

import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.GraphConstants;

import org.jgrapht.ListenableGraph;
import org.jgrapht.ext.JGraphModelAdapter;
import org.jgrapht.graph.ListenableDirectedGraph;
import org.jgrapht.graph.DefaultEdge;

/**
 * A demo that shows how to use JGraph to visualize JGraphT graphs.
 *
 * @author Barak Naveh / adapted by Stefan Reich
 */
 
static final Color     DEFAULT_BG_COLOR = Color.decode( "#FAFBFF" );
static final Dimension DEFAULT_SIZE = new Dimension( 530, 320 );

static JGraphModelAdapter m_jgAdapter;

p-awt {
  // create a JGraphT graph
  ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );

  // create a visualization using JGraph, via an adapter
  m_jgAdapter = new JGraphModelAdapter( g );

  JGraph jgraph = new JGraph( m_jgAdapter );

  adjustDisplaySettings( jgraph );
  frameInnerSize(showFrame(jgraph), DEFAULT_SIZE);

  // add some sample data (graph manipulated via JGraphT)
  g.addVertex( "v1" );
  g.addVertex( "v2" );
  g.addVertex( "v3" );
  g.addVertex( "v4" );

  g.addEdge( "v1", "v2" );
  g.addEdge( "v2", "v3" );
  g.addEdge( "v3", "v1" );
  g.addEdge( "v4", "v3" );

  // position vertices nicely within JGraph component
  positionVertexAt( "v1", 130, 40 );
  positionVertexAt( "v2", 60, 200 );
  positionVertexAt( "v3", 310, 230 );
  positionVertexAt( "v4", 380, 70 );

  // that's all there is to it!...
  }

static void adjustDisplaySettings( JGraph jg ) {
  jg.setPreferredSize(DEFAULT_SIZE);
  jg.setBackground(DEFAULT_BG_COLOR);
}

static void positionVertexAt( Object vertex, int x, int y ) {
  DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex );
  Map              attr = cell.getAttributes(  );
  Rectangle2D        b    = GraphConstants.getBounds( attr );

  GraphConstants.setBounds( attr, new Rectangle2D.Double( x, y, b.getWidth(), b.getHeight() ) );

  Map cellAttr = lithashmap(cell, attr);
  m_jgAdapter.edit( cellAttr, null, null, null);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007170
Snippet name: JGraphT Graphical Demo [OK]
Eternal ID of this version: #1007170/14
Text MD5: 4737a666ed7f5e80e75277c50643a838
Transpilation MD5: 711121503e276c9e035f26499ef8d258
Author: stefan
Category: javax / imaging
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-20 14:34:39
Source code size: 2101 bytes / 73 lines
Pitched / IR pitched: No / No
Views / Downloads: 443 / 877
Version history: 13 change(s)
Referenced in: [show references]