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
|
public Fenetre(String nom){
super(nom);
panel = new JPanel();
panel.setLayout(new BorderLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.centre = new Centre();
this.connexion = new Connexion();
this.cardLayout = new CardLayout();
this.myActionListener = new MyActionListener(centre,connexion,this);
this.myDocumentListener = new MyDocumentListener(centre);
this.control = new Control(centre,connexion,myActionListener,this,myDocumentListener);
myActionListener.addControl(control);
myDocumentListener.addControl(control);
buildTree();
DefaultTreeCellRenderer myRenderer = new DefaultTreeCellRenderer();
// Changement de l'icône pour les feuilles de l'arbre.
myRenderer.setLeafIcon(new ImageIcon("./add.png"));
// Changement de l'icône pour les nuds fermés.
myRenderer.setClosedIcon(new ImageIcon("closedBookIcon.png"));
// Changement de l'icône pour les nuds ouverts.
myRenderer.setOpenIcon(new ImageIcon("openBookIcon.png"));
// Application de l'afficheur à l'arbre.
arbre.setCellRenderer(myRenderer);
panel.add(centre,BorderLayout.CENTER);
arbre.setPreferredSize(new Dimension(300,750));
panel.add(arbre,BorderLayout.WEST);
menuBar.add(file);
menuBar.add(param);
menuBar.add(jeu);
this.menuItem1.setBackground(new Color(253,147,198));
this.menuItem2.setBackground(new Color(253,147,198));
this.menuItem3.setBackground(new Color(253,147,198));
this.menuItem4.setBackground(new Color(253,147,198));
this.menuItem5.setBackground(new Color(253,147,198));
this.menuItem6.setBackground(new Color(253,147,198));
this.menuItem7.setBackground(new Color(253,147,198));
this.menuItem8.setBackground(new Color(253,147,198));
this.menuItem9.setBackground(new Color(253,147,198));
file.add(menuItem1);
file.add(menuItem2);
file.add(menuItem3);
file.add(menuItem4);
file.add(menuItem5);
param.add(menuItem6);
param.add(menuItem7);
param.add(menuItem8);
param.add(menuItem9);
this.menuBar.setBackground(new Color(252,73,158));
setJMenuBar(menuBar);
main = new JPanel (cardLayout);
main.add("connexion",connexion);
main.add("panel",panel);
this.add(main);
this.setResizable(false);
this.pack();
this.setSize(400,250);
this.setVisible(true);
}
private void buildTree(){
//Nous créons, avec notre hiérarchie, un arbre
arbre = new JTree(racine);
//Que nous plaçons sur le ContentPane de notre JFrame à l'aide d'un scroll
this.getContentPane().add(new JScrollPane(arbre));
}
public void addTable(String nomTable){//Marche pour une table
DefaultMutableTreeNode nomTable = new DefaultMutableTreeNode(nomTable);
racine.add(table);
this.repaint();
this.setVisible(true);
}
public void addAttibute(String nomTable, String nomAttribut, String type, ArrayList<String> contraintes){
DefaultMutableTreeNode attribut = new DefaultMutableTreeNode(nomAttribut);
attribut.setParent(nomTable);
DefaultMutableTreeNode type = new DefaultMutableTreeNode(type);
attribut.add(type);
for(String s : contraintes){
DefaultMutableTreeNode s = new DefaultMutableTreeNode(s);
attribut.add(s);
}
nomTable.add(attribut);
} |
Partager