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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
package partitionnement;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.RenderContext;
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.renderers.Renderer.VertexLabel.Position;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.util.FileManager;
/**
*
* @author
*/
public class AffichageGraphique {
JFrame fenetre;
String path;
public AffichageGraphique(String chemin) throws IOException {
path=chemin;
Model model = FileManager.get().loadModel(path);
//La Classe Mapping convertie notre graphe RDF sous forme de d'un fichier ".graph"
Mapping transforme=new Mapping(model);
Graph<RDFNode, Statement> g = new JenaJungGraph(model);
Layout<RDFNode, Statement> layout = new FRLayout(g);
int width = 1400;
int height = 800;
layout.setSize(new Dimension(width, height));
final VisualizationViewer<RDFNode, Statement> vv =
new VisualizationViewer(layout, new Dimension(width, height));
RenderContext context = vv.getRenderContext();
context.setEdgeLabelTransformer(Transformers.EDGE);
context.setVertexLabelTransformer(Transformers.NODE);
vv.setPreferredSize(new Dimension(width, height));
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO);
DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
vv.addKeyListener(gm.getModeKeyListener());
vv.setGraphMouse(gm);
JComboBox modeBox = gm.getModeComboBox();
final ScalingControl scaler = new CrossoverScalingControl();
GraphZoomScrollPane p1 = new GraphZoomScrollPane(vv);
// String imageLocation = "/home/hassiba/NetBeansProjects/partitiOnneme/Sandstone.jpg";
// ImageIcon sandstoneIcon = new ImageIcon(imageLocation);
// final ImageIcon icon = sandstoneIcon;
JButton png = new JButton("Enregistrer sous format png");
png.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
try {
//Execute when button is pressed
EnregistrementImg i=new EnregistrementImg(path);
} catch (IOException ex) {
Logger.getLogger(AffichageGraphique.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
JButton jtree = new JButton("Visualiser sous forme d'un JTree");
jtree.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
JTreeJung j=new JTreeJung(path);
}
});
JButton plus = new JButton("+");
plus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaler.scale(vv, 1.1f,vv.getCenter());
}
});
JButton minus = new JButton("-");
minus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaler.scale(vv, 1/1.1f, vv.getCenter());
}
});
JButton quitter = new JButton("Quitter");
quitter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// fenetre.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
fenetre.setVisible(false);
}
});
this.fenetre = new JFrame("Affichage graphique du document RDF");
this.fenetre.setSize(500, 500);
this.fenetre.setLocationRelativeTo(null);
this.fenetre.setVisible(true);
// this.fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = this.fenetre.getContentPane();
pane.setLayout(new BorderLayout());
JPanel controls = new JPanel();
controls.setSize(300, 150);
controls.setLayout(new FlowLayout());
controls.add(plus);
controls.add(minus);
controls.add(png);
controls.add(jtree);
controls.add(quitter);
controls.add(modeBox);
pane.add("South",controls);
pane.add("Center",p1);
}
} |
Partager