Files
Appthinker/AppThinker/src/AppThinkerToolbar.java

299 lines
10 KiB
Java
Raw Normal View History

2020-11-21 19:46:43 +01:00
import javax.swing.*;
import java.awt.*;
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 {
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
* @param window Une instance de AppThinkerWindow.
2020-11-21 19:46:43 +01:00
*/
public AppThinkerToolbar(AppThinkerWindow window){
this._window = window;
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));
_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) {
_window.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) {
showSelectMouse();
}
});
_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) {
showEditMouse();
}
});
_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) {
showEditMouse();
}
});
_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) {
showEditMouse();
}
});
_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) {
showEditMouse();
}
});
_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) {
showEditMouse();
}
});
_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) {
showEditMouse();
}
});
_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) {
showEditMouse();
}
});
_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);
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);
}
/**
* Rafraîchit les composants de la barre d'outils.
*/
public void refreshTollbar(){
this._projectPanel.updateUI();
this._editionPanel.updateUI();
this._modelisationPanel.updateUI();
}
/**
* Rafraîchit les composants du panel de projet.
*/
public void refreshProjectPanel(){
this._projectPanel.updateUI();
}
/**
* Rafraîchit les composants du panel d'édition.
*/
public void refreshEditionPanel(){
this._editionPanel.updateUI();
}
/**
* Rafraîchit les composants du panel de modélisation.
*/
public void refreshModelisationPanel(){
this._modelisationPanel.updateUI();
}
/**
* Change le curseur de la grille en curseur d'édition.
*/
public void showEditMouse(){
this._window.getGrid().setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}
/**
* Change le curseur de la grille en curseur de sélection.
*/
public void showSelectMouse(){
this._window.getGrid().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
2020-11-21 19:46:43 +01:00
}
}