Ajout de la fonction de sélection d'outils

This commit is contained in:
2020-11-23 15:44:41 +01:00
parent 8773354877
commit 72b018d957
4 changed files with 84 additions and 39 deletions

View File

@@ -23,6 +23,7 @@ public class AppThinkerMenuBar extends JMenuBar {
private JMenuItem _newClass; private JMenuItem _newClass;
private JMenuItem _newAssociation; private JMenuItem _newAssociation;
private JMenuItem _newLink; private JMenuItem _newLink;
private JMenuItem _selectElement;
private JMenuItem _editElement; private JMenuItem _editElement;
private JMenuItem _deleteElement; private JMenuItem _deleteElement;
private JMenuItem _projectOptions; private JMenuItem _projectOptions;
@@ -55,7 +56,6 @@ public class AppThinkerMenuBar extends JMenuBar {
} }
}); });
_fileMenu.add(_newProject); _fileMenu.add(_newProject);
_openProject = new JMenuItem("Ouvrir un projet existant"); _openProject = new JMenuItem("Ouvrir un projet existant");
_openProject.setIcon(new ImageIcon(getClass().getResource("img/x16/openProject.png"))); _openProject.setIcon(new ImageIcon(getClass().getResource("img/x16/openProject.png")));
_openProject.addActionListener(new ActionListener() { _openProject.addActionListener(new ActionListener() {
@@ -112,7 +112,7 @@ public class AppThinkerMenuBar extends JMenuBar {
_newClass.addActionListener(new ActionListener() { _newClass.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); _window.getToolbar().changeTool(AppThinkerToolbar.CLASS_TOOL);
} }
}); });
_projectMenu.add(_newClass); _projectMenu.add(_newClass);
@@ -121,7 +121,7 @@ public class AppThinkerMenuBar extends JMenuBar {
_newAssociation.addActionListener(new ActionListener() { _newAssociation.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); _window.getToolbar().changeTool(AppThinkerToolbar.ASSOCIATION_TOOL);
} }
}); });
_projectMenu.add(_newAssociation); _projectMenu.add(_newAssociation);
@@ -130,16 +130,25 @@ public class AppThinkerMenuBar extends JMenuBar {
_newLink.addActionListener(new ActionListener() { _newLink.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); _window.getToolbar().changeTool(AppThinkerToolbar.LINK_TOOL);
} }
}); });
_projectMenu.add(_newLink); _projectMenu.add(_newLink);
_selectElement = new JMenuItem("Sélectionner");
_selectElement.setIcon(new ImageIcon(getClass().getResource("img/x16/select.png")));
_selectElement.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_window.getToolbar().changeTool(AppThinkerToolbar.SELECT_TOOL);
}
});
_projectMenu.add(_selectElement);
_editElement = new JMenuItem("Éditer"); _editElement = new JMenuItem("Éditer");
_editElement.setIcon(new ImageIcon(getClass().getResource("img/x16/edit.png"))); _editElement.setIcon(new ImageIcon(getClass().getResource("img/x16/edit.png")));
_editElement.addActionListener(new ActionListener() { _editElement.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); _window.getToolbar().changeTool(AppThinkerToolbar.EDIT_TOOL);
} }
}); });
_projectMenu.add(_editElement); _projectMenu.add(_editElement);
@@ -148,7 +157,7 @@ public class AppThinkerMenuBar extends JMenuBar {
_deleteElement.addActionListener(new ActionListener() { _deleteElement.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); _window.getToolbar().changeTool(AppThinkerToolbar.DELETE_TOOL);
} }
}); });
_projectMenu.add(_deleteElement); _projectMenu.add(_deleteElement);
@@ -221,18 +230,4 @@ public class AppThinkerMenuBar extends JMenuBar {
_appInfo.setEnabled(true); _appInfo.setEnabled(true);
_appChangelog.setEnabled(true); _appChangelog.setEnabled(true);
} }
/**
* 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));
}
} }

View File

@@ -9,6 +9,17 @@ import java.awt.event.ActionListener;
*/ */
public class AppThinkerToolbar extends JPanel { 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 JPanel _projectPanel;
private JButton _newProject; private JButton _newProject;
private JButton _openProject; private JButton _openProject;
@@ -85,7 +96,7 @@ public class AppThinkerToolbar extends JPanel {
_select.addActionListener(new ActionListener() { _select.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showSelectMouse(); changeTool(AppThinkerToolbar.SELECT_TOOL);
} }
}); });
_editionPanel.add(_select); _editionPanel.add(_select);
@@ -97,7 +108,7 @@ public class AppThinkerToolbar extends JPanel {
_edit.addActionListener(new ActionListener() { _edit.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.EDIT_TOOL);
} }
}); });
_editionPanel.add(_edit); _editionPanel.add(_edit);
@@ -109,7 +120,7 @@ public class AppThinkerToolbar extends JPanel {
_delete.addActionListener(new ActionListener() { _delete.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.DELETE_TOOL);
} }
}); });
_editionPanel.add(_delete); _editionPanel.add(_delete);
@@ -121,7 +132,7 @@ public class AppThinkerToolbar extends JPanel {
_copy.addActionListener(new ActionListener() { _copy.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.COPY_TOOL);
} }
}); });
_editionPanel.add(_copy); _editionPanel.add(_copy);
@@ -133,7 +144,7 @@ public class AppThinkerToolbar extends JPanel {
_paste.addActionListener(new ActionListener() { _paste.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.PASTE_TOOL);
} }
}); });
_editionPanel.add(_paste); _editionPanel.add(_paste);
@@ -160,7 +171,7 @@ public class AppThinkerToolbar extends JPanel {
_newClass.addActionListener(new ActionListener() { _newClass.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.CLASS_TOOL);
} }
}); });
_modelisationPanel.add(_newClass); _modelisationPanel.add(_newClass);
@@ -172,7 +183,7 @@ public class AppThinkerToolbar extends JPanel {
_newAssociation.addActionListener(new ActionListener() { _newAssociation.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.ASSOCIATION_TOOL);
} }
}); });
_modelisationPanel.add(_newAssociation); _modelisationPanel.add(_newAssociation);
@@ -184,7 +195,7 @@ public class AppThinkerToolbar extends JPanel {
_newLink.addActionListener(new ActionListener() { _newLink.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showEditMouse(); changeTool(AppThinkerToolbar.LINK_TOOL);
} }
}); });
_modelisationPanel.add(_newLink); _modelisationPanel.add(_newLink);
@@ -211,6 +222,7 @@ public class AppThinkerToolbar extends JPanel {
/** /**
* Active les boutons d'édition lorsqu'un projet est ouvert * Active les boutons d'édition lorsqu'un projet est ouvert
*/ */
public void enableEditing(){ public void enableEditing(){
_newProject.setEnabled(true); _newProject.setEnabled(true);
_openProject.setEnabled(true); _openProject.setEnabled(true);
@@ -255,7 +267,7 @@ public class AppThinkerToolbar extends JPanel {
/** /**
* Rafraîchit les composants de la barre d'outils. * Rafraîchit les composants de la barre d'outils.
*/ */
public void refreshTollbar(){ public void refreshToolbar(){
this._projectPanel.updateUI(); this._projectPanel.updateUI();
this._editionPanel.updateUI(); this._editionPanel.updateUI();
this._modelisationPanel.updateUI(); this._modelisationPanel.updateUI();
@@ -283,16 +295,38 @@ public class AppThinkerToolbar extends JPanel {
} }
/** /**
* Change le curseur de la grille en curseur d'édition. * Change d'outil pour l'édition du diagramme.
* @param tool L'outil cible.
*/ */
public void showEditMouse(){ public void changeTool(int tool){
this._window.getGrid().setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); this._currentTool = tool;
} if(this._currentTool == AppThinkerToolbar.SELECT_TOOL) this._window.getGrid().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
else this._window.getGrid().setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
/** switch(tool){
* Change le curseur de la grille en curseur de sélection. case 1:
*/ _window.getStatusbar().setStatusMessage("Outil édition - Cliquez sur un élément pour l'éditer.");
public void showSelectMouse(){ break;
this._window.getGrid().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); case 2:
_window.getStatusbar().setStatusMessage("Outil suppression - Cliquez sur un élément pour le supprimer.");
break;
case 3:
_window.getStatusbar().setStatusMessage("Outil copie - Cliquez sur un élément pour le copier.");
break;
case 4:
_window.getStatusbar().setStatusMessage("Outil coller - Cliquez à un endroit pour coller l'élément.");
break;
case 5:
_window.getStatusbar().setStatusMessage("Outil classe - Cliquez à un endroit pour ajouter une classe.");
break;
case 6:
_window.getStatusbar().setStatusMessage("Outil association - Cliquez à un endroit pour ajouter une association.");
break;
case 7:
_window.getStatusbar().setStatusMessage("Outil lien - Cliquez sur une classe, maintenez, puis relachez sur une autre.");
break;
default:
_window.getStatusbar().setStatusMessage("Outil sélection - Cliquez sur un élément pour le sélectionner.");
break;
}
} }
} }

View File

@@ -98,6 +98,14 @@ public class AppThinkerWindow extends JFrame {
} }
/**
* Récupère la toolbar contenue dans la fenêtre.
* @return La toolbar contenue dans la fenêtre.
*/
public AppThinkerToolbar getToolbar(){
return this._toolbar;
}
/** /**
* Récupère la grille contenue dans la fenêtre. * Récupère la grille contenue dans la fenêtre.
* @return La grille contenue dans la fenêtre. * @return La grille contenue dans la fenêtre.
@@ -105,4 +113,12 @@ public class AppThinkerWindow extends JFrame {
public AppThinkerGrid getGrid(){ public AppThinkerGrid getGrid(){
return this._grid; return this._grid;
} }
/**
* Récupère la statusbar contenue dans la fenêtre.
* @return La statusbar contenue dans la fenêtre.
*/
public AppThinkerStatusbar getStatusbar(){
return this._statusbar;
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B