1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
   |  
package fr.upmc.dsi.siview.view;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
 
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
 
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;
 
import com.jgraph.layout.JGraphFacade;
import com.jgraph.layout.tree.JGraphTreeLayout;
 
import fr.upmc.ent.siview.dao.impl.UIAlgo;
 
public class Panneau extends JPanel {
 
 
	/**
         * 
         */
	private static final long serialVersionUID = 1L;
	private JGraph graph;
	private JRadioButton north;
	private JRadioButton south;
	private JPanel radiopanel;
	private JPanel graphpanel;
	private JGraphTreeLayout layout;
	private UIAlgo algo;
 
 
 
	public Panneau(JGraph graph) {
		super();
		this.graph = graph;
		this.algo = new UIAlgo();
 
		makeGUI();
		configureGUI();
		bindGUI();
	}
 
 
	private void bindGUI() {
		this.north.addActionListener(new ActionListener(){
 
			@Override
			public void actionPerformed(ActionEvent e) {
				layout.setAlignment(SwingConstants.NORTH);
				graph.repaint();
			}
 
		});
		this.south.addActionListener(new ActionListener(){
 
			@Override
			public void actionPerformed(ActionEvent e) {
				layout.setOrientation(SwingConstants.WEST);
				graph.repaint();
			}
 
		});
 
 
	}
 
 
	private void configureGUI() {
		setLayout(new BorderLayout());
 
		ButtonGroup grp = new ButtonGroup();
		grp.add(this.north);
		grp.add(this.south);
		this.radiopanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.radiopanel.add(this.north);
		this.radiopanel.add(this.south);
 
 
		this.graphpanel.add(new JScrollPane(this.graph));
		DefaultGraphCell[] tab = this.algo.UI();
		Object[] racine = {tab[0] };
		JGraphFacade facade = new JGraphFacade(graph, racine);
		layout.setAlignment(SwingConstants.CENTER);
		layout.setOrientation(SwingConstants.WEST);
		layout.setNodeDistance(1*tab.length);
		layout.setLevelDistance(5*tab.length);
		this.graph.getGraphLayoutCache().insert(tab);
		layout.run(facade);
		Map  nested = facade.createNestedMap(true, true);
		graph.getGraphLayoutCache().edit(nested);
 
 
		add(this.radiopanel, BorderLayout.NORTH);
		add(this.graphpanel, BorderLayout.SOUTH);
	}
 
 
	private void makeGUI() {
 
 
		this.north = new JRadioButton("NORTH");
		this.south = new JRadioButton("SOUTH");
 
		this.south.setSelected(true);
		this.north.setSelected(false);
 
		this.radiopanel = new JPanel();
		this.graphpanel = new JPanel();
		this.layout = new JGraphTreeLayout();
 
	}
 
 
 
 
 
 
 
} | 
Partager