2020-11-21 19:46:43 +01:00
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
2020-11-22 23:34:44 +01:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
2020-11-21 19:46:43 +01:00
|
|
|
|
2020-11-22 15:55:26 +01:00
|
|
|
/**
|
|
|
|
|
* Affiche une barre d'actions en haut de la fenêtre.
|
|
|
|
|
* @author V.BOULANGER
|
|
|
|
|
*/
|
2020-11-21 19:46:43 +01:00
|
|
|
public class AppThinkerToolbar extends JPanel {
|
2020-11-22 23:34:44 +01:00
|
|
|
|
2020-11-23 15:44:41 +01:00
|
|
|
public static final int SELECT_TOOL = 0;
|
|
|
|
|
public static final int EDIT_TOOL = 1;
|
|
|
|
|
public static final int DELETE_TOOL = 2;
|
|
|
|
|
public static final int COPY_TOOL = 3;
|
|
|
|
|
public static final int PASTE_TOOL = 4;
|
|
|
|
|
public static final int CLASS_TOOL = 5;
|
|
|
|
|
public static final int ASSOCIATION_TOOL = 6;
|
|
|
|
|
public static final int LINK_TOOL = 7;
|
|
|
|
|
|
|
|
|
|
private int _currentTool = 0;
|
|
|
|
|
|
2020-11-22 23:34:44 +01:00
|
|
|
private JPanel _projectPanel;
|
|
|
|
|
private JButton _newProject;
|
|
|
|
|
private JButton _openProject;
|
|
|
|
|
private JButton _saveProject;
|
|
|
|
|
private JButton _saveAsProject;
|
|
|
|
|
|
|
|
|
|
private JPanel _editionPanel;
|
|
|
|
|
private JButton _select;
|
|
|
|
|
private JButton _edit;
|
|
|
|
|
private JButton _delete;
|
|
|
|
|
private JButton _copy;
|
|
|
|
|
private JButton _paste;
|
|
|
|
|
private JButton _undo;
|
|
|
|
|
private JButton _redo;
|
|
|
|
|
|
|
|
|
|
private JPanel _modelisationPanel;
|
|
|
|
|
private JButton _newClass;
|
|
|
|
|
private JButton _newAssociation;
|
|
|
|
|
private JButton _newLink;
|
|
|
|
|
|
|
|
|
|
private AppThinkerWindow _window;
|
|
|
|
|
|
2020-11-21 19:46:43 +01:00
|
|
|
/**
|
|
|
|
|
* Constructeur de la classe AppThinkerToolbar
|
|
|
|
|
*/
|
2020-11-29 18:56:04 +01:00
|
|
|
public AppThinkerToolbar(){
|
2020-11-21 19:46:43 +01:00
|
|
|
//Création de la Toolbar
|
|
|
|
|
this.setLayout(new GridLayout(2,3, 10, 0));
|
|
|
|
|
this.setBackground(new Color(69, 69, 72));
|
|
|
|
|
|
2020-11-22 23:34:44 +01:00
|
|
|
_projectPanel = new JPanel();
|
|
|
|
|
_projectPanel.setLayout(new GridLayout(1,4));
|
|
|
|
|
//Bouton ajout d'un nouveau projet
|
|
|
|
|
_newProject = new JButton();
|
|
|
|
|
_newProject.setSize(32, 32);
|
|
|
|
|
_newProject.setBorderPainted(false);
|
|
|
|
|
_newProject.setIcon(new ImageIcon(getClass().getResource("img/x32/newProject.png")));
|
|
|
|
|
_newProject.setToolTipText("Créer un nouveau projet.");
|
|
|
|
|
_newProject.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.newProject();
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_projectPanel.add(_newProject);
|
|
|
|
|
_openProject = new JButton();
|
|
|
|
|
_openProject.setSize(32, 32);
|
|
|
|
|
_openProject.setBorderPainted(false);
|
|
|
|
|
_openProject.setIcon(new ImageIcon(getClass().getResource("img/x32/importProject.png")));
|
|
|
|
|
_openProject.setToolTipText("Importer un projet existant.");
|
|
|
|
|
_projectPanel.add(_openProject);
|
|
|
|
|
_saveProject = new JButton();
|
|
|
|
|
_saveProject.setSize(32, 32);
|
|
|
|
|
_saveProject.setBorderPainted(false);
|
|
|
|
|
_saveProject.setIcon(new ImageIcon(getClass().getResource("img/x32/saveProject.png")));
|
|
|
|
|
_saveProject.setToolTipText("Sauvegarder le projet.");
|
|
|
|
|
_projectPanel.add(_saveProject);
|
|
|
|
|
_saveAsProject = new JButton();
|
|
|
|
|
_saveAsProject.setSize(32, 32);
|
|
|
|
|
_saveAsProject.setBorderPainted(false);
|
|
|
|
|
_saveAsProject.setIcon(new ImageIcon(getClass().getResource("img/x32/saveAsProject.png")));
|
|
|
|
|
_saveAsProject.setToolTipText("Sauvegarder le projet à un autre endroit.");
|
|
|
|
|
_projectPanel.add(_saveAsProject);
|
|
|
|
|
|
|
|
|
|
_editionPanel = new JPanel();
|
|
|
|
|
_editionPanel.setLayout(new GridLayout(1,7));
|
|
|
|
|
_select = new JButton();
|
|
|
|
|
_select.setSize(32, 32);
|
|
|
|
|
_select.setBorderPainted(false);
|
|
|
|
|
_select.setIcon(new ImageIcon(getClass().getResource("img/x32/select.png")));
|
|
|
|
|
_select.setToolTipText("Sélectionner un élément.");
|
|
|
|
|
_select.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.SELECT_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_editionPanel.add(_select);
|
|
|
|
|
_edit = new JButton();
|
|
|
|
|
_edit.setSize(32, 32);
|
|
|
|
|
_edit.setBorderPainted(false);
|
|
|
|
|
_edit.setIcon(new ImageIcon(getClass().getResource("img/x32/edit.png")));
|
|
|
|
|
_edit.setToolTipText("Éditer les propriétés d'un élément.");
|
|
|
|
|
_edit.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.EDIT_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_editionPanel.add(_edit);
|
|
|
|
|
_delete = new JButton();
|
|
|
|
|
_delete.setSize(32, 32);
|
|
|
|
|
_delete.setBorderPainted(false);
|
|
|
|
|
_delete.setIcon(new ImageIcon(getClass().getResource("img/x32/delete.png")));
|
|
|
|
|
_delete.setToolTipText("Supprimer un élément.");
|
|
|
|
|
_delete.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.DELETE_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_editionPanel.add(_delete);
|
|
|
|
|
_copy = new JButton();
|
|
|
|
|
_copy.setSize(32, 32);
|
|
|
|
|
_copy.setBorderPainted(false);
|
|
|
|
|
_copy.setIcon(new ImageIcon(getClass().getResource("img/x32/copy.png")));
|
|
|
|
|
_copy.setToolTipText("Copier un élément.");
|
|
|
|
|
_copy.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.COPY_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_editionPanel.add(_copy);
|
|
|
|
|
_paste = new JButton();
|
|
|
|
|
_paste.setSize(32, 32);
|
|
|
|
|
_paste.setBorderPainted(false);
|
|
|
|
|
_paste.setIcon(new ImageIcon(getClass().getResource("img/x32/paste.png")));
|
|
|
|
|
_paste.setToolTipText("Coller un élément.");
|
|
|
|
|
_paste.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.PASTE_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_editionPanel.add(_paste);
|
|
|
|
|
_undo = new JButton();
|
|
|
|
|
_undo.setSize(32, 32);
|
|
|
|
|
_undo.setBorderPainted(false);
|
|
|
|
|
_undo.setIcon(new ImageIcon(getClass().getResource("img/x32/undo.png")));
|
|
|
|
|
_undo.setToolTipText("Annuler le dernier changement.");
|
|
|
|
|
_editionPanel.add(_undo);
|
|
|
|
|
_redo = new JButton();
|
|
|
|
|
_redo.setSize(32, 32);
|
|
|
|
|
_redo.setBorderPainted(false);
|
|
|
|
|
_redo.setIcon(new ImageIcon(getClass().getResource("img/x32/redo.png")));
|
|
|
|
|
_redo.setToolTipText("Rétablir le dernier changement annulé.");
|
|
|
|
|
_editionPanel.add(_redo);
|
|
|
|
|
|
|
|
|
|
_modelisationPanel = new JPanel();
|
|
|
|
|
_modelisationPanel.setLayout(new GridLayout(1,3));
|
|
|
|
|
_newClass = new JButton();
|
|
|
|
|
_newClass.setSize(32, 32);
|
|
|
|
|
_newClass.setBorderPainted(false);
|
|
|
|
|
_newClass.setIcon(new ImageIcon(getClass().getResource("img/x32/newClass.png")));
|
|
|
|
|
_newClass.setToolTipText("Ajouter une classe.");
|
|
|
|
|
_newClass.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.CLASS_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_modelisationPanel.add(_newClass);
|
|
|
|
|
_newAssociation = new JButton();
|
|
|
|
|
_newAssociation.setSize(32, 32);
|
|
|
|
|
_newAssociation.setBorderPainted(false);
|
|
|
|
|
_newAssociation.setIcon(new ImageIcon(getClass().getResource("img/x32/newAssociation.png")));
|
|
|
|
|
_newAssociation.setToolTipText("Ajouter une association.");
|
|
|
|
|
_newAssociation.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.ASSOCIATION_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_modelisationPanel.add(_newAssociation);
|
|
|
|
|
_newLink = new JButton();
|
|
|
|
|
_newLink.setSize(32, 32);
|
|
|
|
|
_newLink.setBorderPainted(false);
|
|
|
|
|
_newLink.setIcon(new ImageIcon(getClass().getResource("img/x32/newLink.png")));
|
|
|
|
|
_newLink.setToolTipText("Ajouter un lien.");
|
|
|
|
|
_newLink.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-11-29 18:56:04 +01:00
|
|
|
setCurrentTool(AppThinkerToolbar.LINK_TOOL);
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_modelisationPanel.add(_newLink);
|
|
|
|
|
|
|
|
|
|
this.add(_projectPanel, BorderLayout.CENTER);
|
|
|
|
|
this.add(_editionPanel, BorderLayout.CENTER);
|
|
|
|
|
this.add(_modelisationPanel, BorderLayout.CENTER);
|
2020-11-21 19:46:43 +01:00
|
|
|
JLabel projectLabel = new JLabel("Projet");
|
|
|
|
|
projectLabel.setHorizontalAlignment(JLabel.CENTER);
|
|
|
|
|
projectLabel.setForeground(Color.WHITE);
|
|
|
|
|
this.add(projectLabel);
|
|
|
|
|
JLabel editLabel = new JLabel("Édition");
|
|
|
|
|
editLabel.setHorizontalAlignment(JLabel.CENTER);
|
|
|
|
|
editLabel.setForeground(Color.WHITE);
|
|
|
|
|
this.add(editLabel);
|
|
|
|
|
JLabel modelisationLabel = new JLabel("Modélisation");
|
|
|
|
|
modelisationLabel.setHorizontalAlignment(JLabel.CENTER);
|
|
|
|
|
modelisationLabel.setForeground(Color.WHITE);
|
|
|
|
|
this.add(modelisationLabel);
|
2020-11-22 23:34:44 +01:00
|
|
|
|
|
|
|
|
this.disableEditing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Active les boutons d'édition lorsqu'un projet est ouvert
|
|
|
|
|
*/
|
|
|
|
|
public void enableEditing(){
|
|
|
|
|
_newProject.setEnabled(true);
|
|
|
|
|
_openProject.setEnabled(true);
|
|
|
|
|
_saveProject.setEnabled(true);
|
|
|
|
|
_saveAsProject.setEnabled(true);
|
|
|
|
|
|
|
|
|
|
_select.setEnabled(true);
|
|
|
|
|
_edit.setEnabled(true);
|
|
|
|
|
_delete.setEnabled(true);
|
|
|
|
|
_copy.setEnabled(true);
|
|
|
|
|
_paste.setEnabled(true);
|
|
|
|
|
_undo.setEnabled(true);
|
|
|
|
|
_redo.setEnabled(true);
|
|
|
|
|
|
|
|
|
|
_newClass.setEnabled(true);
|
|
|
|
|
_newAssociation.setEnabled(true);
|
|
|
|
|
_newLink.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Désactive les boutons d'édition lorsqu'aucun projet n'est ouvert
|
|
|
|
|
*/
|
|
|
|
|
public void disableEditing(){
|
|
|
|
|
_newProject.setEnabled(true);
|
|
|
|
|
_openProject.setEnabled(true);
|
|
|
|
|
_saveProject.setEnabled(false);
|
|
|
|
|
_saveAsProject.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
_select.setEnabled(false);
|
|
|
|
|
_edit.setEnabled(false);
|
|
|
|
|
_delete.setEnabled(false);
|
|
|
|
|
_copy.setEnabled(false);
|
|
|
|
|
_paste.setEnabled(false);
|
|
|
|
|
_undo.setEnabled(false);
|
|
|
|
|
_redo.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
_newClass.setEnabled(false);
|
|
|
|
|
_newAssociation.setEnabled(false);
|
|
|
|
|
_newLink.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-29 18:56:04 +01:00
|
|
|
* Récupère l'outil actuellement en fonction.
|
|
|
|
|
* @return L'outil actuellement en fonction.
|
2020-11-22 23:34:44 +01:00
|
|
|
*/
|
2020-11-29 18:56:04 +01:00
|
|
|
public int getCurrentTool(){
|
|
|
|
|
return this._currentTool;
|
2020-11-22 23:34:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-23 15:44:41 +01:00
|
|
|
* Change d'outil pour l'édition du diagramme.
|
2020-11-29 18:56:04 +01:00
|
|
|
* @param currentTool L'outil cible.
|
2020-11-22 23:34:44 +01:00
|
|
|
*/
|
2020-11-29 18:56:04 +01:00
|
|
|
public void setCurrentTool(int currentTool){
|
|
|
|
|
this._currentTool = currentTool;
|
|
|
|
|
if(this._currentTool == AppThinkerToolbar.SELECT_TOOL) AppThinker.getProject().getGrid().getDiagram().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
|
|
|
|
else AppThinker.getProject().getGrid().getDiagram().setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
|
|
|
|
switch(currentTool){
|
2020-11-23 15:44:41 +01:00
|
|
|
case 1:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil édition - Cliquez sur un élément pour l'éditer.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2020-11-29 18:56:04 +01:00
|
|
|
Object a = AppThinker.getProject().getGrid().getDiagram().getSelected();
|
|
|
|
|
if(a instanceof Class){
|
|
|
|
|
AppThinker.getProject().getClasses().remove(a);
|
|
|
|
|
AppThinker.getProject().getGrid().getDiagram().displayDiagram();
|
|
|
|
|
}
|
|
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil suppression - Cliquez sur un élément pour le supprimer.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil copie - Cliquez sur un élément pour le copier.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
case 4:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil coller - Cliquez à un endroit pour coller l'élément.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
case 5:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil classe - Cliquez à un endroit pour ajouter une classe.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
case 6:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil association - Cliquez à un endroit pour ajouter une association.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
case 7:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil lien - Cliquez sur une classe, maintenez, puis relachez sur une autre.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2020-11-29 18:56:04 +01:00
|
|
|
AppThinker.getWindow().getStatusbar().setStatusMessage("Outil sélection - Cliquez sur un élément pour le sélectionner.");
|
2020-11-23 15:44:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2020-11-21 19:46:43 +01:00
|
|
|
}
|
|
|
|
|
}
|