import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * Affiche une barre d'actions en haut de la fenêtre. * @author V.BOULANGER */ public class AppThinkerToolbar extends JPanel { 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; 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; /** * Constructeur de la classe AppThinkerToolbar */ public AppThinkerToolbar(){ //Création de la Toolbar this.setLayout(new GridLayout(2,3, 10, 0)); this.setBackground(new Color(69, 69, 72)); _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) { AppThinker.newProject(); } }); _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) { setCurrentTool(AppThinkerToolbar.SELECT_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.EDIT_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.DELETE_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.COPY_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.PASTE_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.CLASS_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.ASSOCIATION_TOOL); } }); _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) { setCurrentTool(AppThinkerToolbar.LINK_TOOL); } }); _modelisationPanel.add(_newLink); this.add(_projectPanel, BorderLayout.CENTER); this.add(_editionPanel, BorderLayout.CENTER); this.add(_modelisationPanel, BorderLayout.CENTER); 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); 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); } /** * Récupère l'outil actuellement en fonction. * @return L'outil actuellement en fonction. */ public int getCurrentTool(){ return this._currentTool; } /** * Change d'outil pour l'édition du diagramme. * @param currentTool L'outil cible. */ public void setCurrentTool(int currentTool){ this._currentTool = currentTool; if(this._currentTool == AppThinkerToolbar.SELECT_TOOL) AppThinker.getProject().getUmlDiagram().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); else AppThinker.getProject().getUmlDiagram().setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); switch(currentTool){ case 1: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil édition - Cliquez sur un élément pour l'éditer."); break; case 2: Object a = AppThinker.getProject().getUmlDiagram().getSelected(); if(a instanceof Class){ AppThinker.getProject().getClasses().remove(a); AppThinker.getProject().getUmlDiagram().displayDiagram(); } AppThinker.getWindow().getStatusbar().setStatusMessage("Outil suppression - Cliquez sur un élément pour le supprimer."); break; case 3: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil copie - Cliquez sur un élément pour le copier."); break; case 4: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil coller - Cliquez à un endroit pour coller l'élément."); break; case 5: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil classe - Cliquez à un endroit pour ajouter une classe."); break; case 6: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil association - Cliquez à un endroit pour ajouter une association."); break; case 7: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil lien - Cliquez sur une classe, maintenez, puis relachez sur une autre."); break; default: AppThinker.getWindow().getStatusbar().setStatusMessage("Outil sélection - Cliquez sur un élément pour le sélectionner."); break; } } }