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
|
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import weka.core.Instances;
import weka.gui.explorer.ClassifierPanel;
import weka.gui.explorer.PreprocessPanel;
public class Graph {
public static JLabel []label ;
public static JProgressBar [] barede ;
public Graph(){
int nbrind ;
int colo=0;
int compteur=0;
Instances echant ;
ArrayList facti = new ArrayList();
build bui = new build();
facti = bui.factichek;
matriceincidence mat = new matriceincidence();
mat = bui.automatecéllulaire;
PreprocessPanel gg = new PreprocessPanel();
echant = gg.monechantillon;
nbrind = echant.numInstances();
label = new JLabel[2];
barede = new JProgressBar [2];
for (int i=0;i<label.length;i++){
label[i]= new JLabel();
barede[i]= new JProgressBar();
}
int jj= 0;
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new
MyCellViewFactory());
JGraph graph = new JGraph(model, view);
DefaultGraphCell[] cells = new DefaultGraphCell[facti.size()];
/**for(int d=0;d<label.length;d++){
if (d==0){
for (int nbrmod = 0;nbrmod<echant.classAttribute().numValues();nbrmod++){
for (int nbrins =0;nbrins<echant.numInstances();nbrins++){
if (echant.instance(nbrins).classValue()==((double) echant.classAttribute().indexOfValue(echant.classAttribute().value(nbrmod)))){
compteur++;
}
}barede[colo].setValue((compteur*100)/echant.numInstances());
label[colo].setText(echant.classAttribute().value(nbrmod)+" "+(compteur*100)/echant.numInstances()+"%");
compteur =0;
colo++;
}
}
}**/
for (int i=0;i<facti.size();i=i+2){
cells[i]= new DefaultGraphCell();
GraphConstants.setBounds(cells[i].getAttributes(), new
Rectangle2D.Double(20+i*15,20+i*10,135,65));
GraphConstants.setGradientColor(
cells[i].getAttributes(),
Color.orange);
GraphConstants.setOpaque(cells[i].getAttributes(), true);
DefaultPort port0 = new DefaultPort();
cells[i].add(port0);
}
do{
for (int j=0;j<mat.donnernbrcolonnes(mat);j++){
if (mat.donnervaleurentrée(mat,jj,j)==true){
for(int k=0;k<mat.donnernbrlignes(mat);k++){
if (mat.donnervaleursortie(mat,k,j)==true){
DefaultEdge edge = new DefaultEdge(facti.get(k));
edge.setSource(cells[jj].getChildAt(0));
edge.setTarget(cells[k+1].getChildAt(0));
cells[k]= edge;
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true);
break;
}
}
}
}jj=jj+2;
}while(jj<facti.size());
graph.getGraphLayoutCache().insert(cells);
JFrame frame = new JFrame("L'arbre de décision");
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
}
} |
Partager