diff --git a/AppThinker/src/AppThinker.java b/AppThinker/src/AppThinker.java index 47e3177..ce671f9 100644 --- a/AppThinker/src/AppThinker.java +++ b/AppThinker/src/AppThinker.java @@ -1,4 +1,6 @@ import javax.swing.*; +import java.awt.*; + /** * La classe principale du logiciel AppThinker. * @author V.BOULANGER @@ -6,12 +8,78 @@ import javax.swing.*; public class AppThinker { //JavaDoc tags : @param @return @throws @author @version @see @since @serial @deprecated + private static Project _project; + private static AppThinkerWindow _window; + /** * La méthode principale exécutée * @param args Les arguments de la méthode principale. */ public static void main(String[] args) { - AppThinkerWindow window = new AppThinkerWindow(); - window.setVisible(true); + _window = new AppThinkerWindow(); + } + + /** + * Récupère la fenêtre de l'application + * @return La fenêtre de l'application. + */ + public static AppThinkerWindow getWindow(){ + return _window; + } + + /** + * Crée un nouveau Projet. + */ + public static void newProject(){ + _project = new Project(); + _window.setTitle("AppThinker | " + _project.getName()); + _window.getMenubar().enableEditing(); + _window.getToolbar().enableEditing(); + _window.getStatusbar().setStatusMessage("Le projet a été créé."); + _window.getStatusbar().setFileMessage(_project.getName()); + _window.setGrid(_project.getGrid()); + AppThinker.getProject().getGrid().getDiagram().displayDiagram(); + } + + /** + * Ouvre un projet existant dans la fenêtre. + */ + public static void openProject(){ + //_window.getGrid().repaint(); + } + + /** + * Sauvegarde le projet en cours. + */ + public static void saveProject(){ + + } + + /** + * Sauvegarde le projet en cours à un autre emplacement. + */ + public static void saveAsProject(){ + + } + + /** + * Ferme le projet en cours. + */ + public static void closeProject(){ + _window.setTitle("AppThinker"); + _window.getMenubar().disableEditing(); + _window.getToolbar().disableEditing(); + _window.getStatusbar().setStatusMessage("Le projet a été fermé."); + _window.getStatusbar().setFileMessage("Aucun projet ouvert"); + _window.remove(_project.getGrid()); + _project = null; + } + + /** + * Récupère le projet en cours. + * @return Le projet en cours. + */ + public static Project getProject(){ + return _project; } } diff --git a/AppThinker/src/AppThinkerGrid.java b/AppThinker/src/AppThinkerGrid.java index d5939eb..67621d0 100644 --- a/AppThinker/src/AppThinkerGrid.java +++ b/AppThinker/src/AppThinkerGrid.java @@ -2,44 +2,40 @@ import javax.swing.*; import java.awt.*; /** - * Affiche une grille pour l'affichage du projet. + * Affiche une grille de projet pour l'affichage du diagramme. * @author V.BOULANGER */ public class AppThinkerGrid extends JPanel { + + private Project _project; + private UmlDiagram _umlDiagram; + /** - * Constructeur de la classe AppThinkerGrid + * Constructeur de la classe AppThinkerGrid. + * @param project Le projet associé. */ - public AppThinkerGrid(){ + public AppThinkerGrid(Project project){ + this._project = project; this.setBackground(new Color(192, 192, 192)); + this._umlDiagram = new UmlDiagram(_project); + + _umlDiagram.setPreferredSize(new Dimension(30000,30000)); + + this.setLayout(new BorderLayout()); + + JScrollPane scrollPane = new JScrollPane(_umlDiagram); + scrollPane.setVisible(true); + scrollPane.setBackground(new Color(60, 158, 163)); + + this.add(scrollPane, BorderLayout.CENTER); + this._umlDiagram.displayDiagram(); } /** - * Affiche les éléments du projet dans la grille. - * @param project Projet à afficher. + * Récupère le diagramme de la grille. + * @return Le diagramme de la grille. */ - public void displayProject(Project project){ - - } - - /** - * Détruit tous les éléments de la grille. - */ - public void cleanProject(){ - - } - - /** - * Applique un zoom sur la grille. - * @param percent Pourcentage du zoom (1 - 500). - */ - public void zoom(int percent){ - - } - - /** - * Rafraîchit les modifications sur la grille. - */ - public void refresh(){ - this.updateUI(); + public UmlDiagram getDiagram(){ + return _umlDiagram; } } diff --git a/AppThinker/src/AppThinkerMenuBar.java b/AppThinker/src/AppThinkerMenuBar.java index bfffb87..8941b5f 100644 --- a/AppThinker/src/AppThinkerMenuBar.java +++ b/AppThinker/src/AppThinkerMenuBar.java @@ -35,14 +35,10 @@ public class AppThinkerMenuBar extends JMenuBar { private AppThinkerWindow _window; - /** * Constructeur de la classe AppThinkerMenuBar - * @param window Une instance de AppThinkerWindow. */ - public AppThinkerMenuBar(AppThinkerWindow window){ - this._window = window; - + public AppThinkerMenuBar(){ //Création de la barre menu _fileMenu = new JMenu("Fichier"); _fileMenu.setMnemonic( 'F' ); @@ -52,7 +48,7 @@ public class AppThinkerMenuBar extends JMenuBar { _newProject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.newProject(); + AppThinker.newProject(); } }); _fileMenu.add(_newProject); @@ -61,7 +57,7 @@ public class AppThinkerMenuBar extends JMenuBar { _openProject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.openProject(); + AppThinker.openProject(); } }); _fileMenu.add(_openProject); @@ -70,7 +66,7 @@ public class AppThinkerMenuBar extends JMenuBar { _saveProject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.saveProject(); + AppThinker.saveProject(); } }); _fileMenu.add(_saveProject); @@ -79,7 +75,7 @@ public class AppThinkerMenuBar extends JMenuBar { _saveAsProject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.saveAsProject(); + AppThinker.saveAsProject(); } }); _fileMenu.add(_saveAsProject); @@ -88,7 +84,7 @@ public class AppThinkerMenuBar extends JMenuBar { _closeProject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.closeProject(); + AppThinker.closeProject(); } }); _fileMenu.add(_closeProject); @@ -112,7 +108,7 @@ public class AppThinkerMenuBar extends JMenuBar { _newClass.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.getToolbar().changeTool(AppThinkerToolbar.CLASS_TOOL); + _window.getToolbar().setCurrentTool(AppThinkerToolbar.CLASS_TOOL); } }); _projectMenu.add(_newClass); @@ -121,7 +117,7 @@ public class AppThinkerMenuBar extends JMenuBar { _newAssociation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.getToolbar().changeTool(AppThinkerToolbar.ASSOCIATION_TOOL); + _window.getToolbar().setCurrentTool(AppThinkerToolbar.ASSOCIATION_TOOL); } }); _projectMenu.add(_newAssociation); @@ -130,7 +126,7 @@ public class AppThinkerMenuBar extends JMenuBar { _newLink.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.getToolbar().changeTool(AppThinkerToolbar.LINK_TOOL); + _window.getToolbar().setCurrentTool(AppThinkerToolbar.LINK_TOOL); } }); _projectMenu.add(_newLink); @@ -139,7 +135,7 @@ public class AppThinkerMenuBar extends JMenuBar { _selectElement.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.getToolbar().changeTool(AppThinkerToolbar.SELECT_TOOL); + _window.getToolbar().setCurrentTool(AppThinkerToolbar.SELECT_TOOL); } }); _projectMenu.add(_selectElement); @@ -148,7 +144,7 @@ public class AppThinkerMenuBar extends JMenuBar { _editElement.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.getToolbar().changeTool(AppThinkerToolbar.EDIT_TOOL); + _window.getToolbar().setCurrentTool(AppThinkerToolbar.EDIT_TOOL); } }); _projectMenu.add(_editElement); @@ -157,7 +153,7 @@ public class AppThinkerMenuBar extends JMenuBar { _deleteElement.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.getToolbar().changeTool(AppThinkerToolbar.DELETE_TOOL); + _window.getToolbar().setCurrentTool(AppThinkerToolbar.DELETE_TOOL); } }); _projectMenu.add(_deleteElement); diff --git a/AppThinker/src/AppThinkerStatusbar.java b/AppThinker/src/AppThinkerStatusbar.java index 0c7146c..efd16ab 100644 --- a/AppThinker/src/AppThinkerStatusbar.java +++ b/AppThinker/src/AppThinkerStatusbar.java @@ -23,7 +23,7 @@ public class AppThinkerStatusbar extends JPanel { this.setBorder(new BevelBorder(BevelBorder.LOWERED)); this.setLayout(new GridLayout(1,3)); - _statusLabel = new JLabel("Prêt."); + _statusLabel = new JLabel("Créez ou importez un projet pour commencer."); this.add(_statusLabel); JPanel actionBar = new JPanel(); @@ -46,34 +46,18 @@ public class AppThinkerStatusbar extends JPanel { /** * Met à jour le texte de statut de la barre de statut. - * @param msg Le message à afficher. + * @param statusMessage Le message à afficher. */ - public void setStatusMessage(String msg){ - this._statusLabel.setText(msg); + public void setStatusMessage(String statusMessage){ + this._statusLabel.setText(statusMessage); } /** * Met à jour le nom du fichier dans la barre de statut. - * @param file Le nom du fichier à afficher. + * @param fileMessage Le nom du fichier à afficher. */ - public void setFileMessage(String file){ - this._fileLabel.setText(file); - } - - /** - * Met à jour le label de position X. - * @param posX La position X. - */ - public void setPosXLabel(int posX){ - this._posXLabel.setText(Integer.toString(posX)); - } - - /** - * Met à jour le label de position Y. - * @param posY La position Y. - */ - public void setPosYLabel(int posY){ - this._posYLabel.setText(Integer.toString(posY)); + public void setFileMessage(String fileMessage){ + this._fileLabel.setText(fileMessage); } /** @@ -82,24 +66,8 @@ public class AppThinkerStatusbar extends JPanel { * @param posY La position Y. */ public void setPosLabel(int posX, int posY){ - this._posXLabel.setText(Integer.toString(posX)); - this._posYLabel.setText(Integer.toString(posY)); - } - - /** - * Met à jour le label de taille X. - * @param sizeX La taille X. - */ - public void setSizeXLabel(int sizeX){ - this._sizeXLabel.setText(Integer.toString(sizeX)); - } - - /** - * Met à jour le label de taille Y. - * @param sizeY La taille Y. - */ - public void setSizeYLabel(int sizeY){ - this._sizeYLabel.setText(Integer.toString(sizeY)); + this._posXLabel.setText("X : " + Integer.toString(posX) + " |"); + this._posYLabel.setText("Y : " + Integer.toString(posY) + " |"); } /** @@ -108,9 +76,7 @@ public class AppThinkerStatusbar extends JPanel { * @param sizeY La taille Y. */ public void setSizeLabel(int sizeX, int sizeY){ - this._sizeXLabel.setText(Integer.toString(sizeX)); - this._sizeYLabel.setText(Integer.toString(sizeY)); + this._sizeXLabel.setText("SX : " + Integer.toString(sizeX)); + this._sizeYLabel.setText("SY : " + Integer.toString(sizeY)); } - - } diff --git a/AppThinker/src/AppThinkerToolbar.java b/AppThinker/src/AppThinkerToolbar.java index 9bc528b..2882595 100644 --- a/AppThinker/src/AppThinkerToolbar.java +++ b/AppThinker/src/AppThinkerToolbar.java @@ -44,10 +44,8 @@ public class AppThinkerToolbar extends JPanel { /** * Constructeur de la classe AppThinkerToolbar - * @param window Une instance de AppThinkerWindow. */ - public AppThinkerToolbar(AppThinkerWindow window){ - this._window = window; + public AppThinkerToolbar(){ //Création de la Toolbar this.setLayout(new GridLayout(2,3, 10, 0)); this.setBackground(new Color(69, 69, 72)); @@ -63,7 +61,7 @@ public class AppThinkerToolbar extends JPanel { _newProject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - _window.newProject(); + AppThinker.newProject(); } }); _projectPanel.add(_newProject); @@ -96,7 +94,7 @@ public class AppThinkerToolbar extends JPanel { _select.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.SELECT_TOOL); + setCurrentTool(AppThinkerToolbar.SELECT_TOOL); } }); _editionPanel.add(_select); @@ -108,7 +106,7 @@ public class AppThinkerToolbar extends JPanel { _edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.EDIT_TOOL); + setCurrentTool(AppThinkerToolbar.EDIT_TOOL); } }); _editionPanel.add(_edit); @@ -120,7 +118,7 @@ public class AppThinkerToolbar extends JPanel { _delete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.DELETE_TOOL); + setCurrentTool(AppThinkerToolbar.DELETE_TOOL); } }); _editionPanel.add(_delete); @@ -132,7 +130,7 @@ public class AppThinkerToolbar extends JPanel { _copy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.COPY_TOOL); + setCurrentTool(AppThinkerToolbar.COPY_TOOL); } }); _editionPanel.add(_copy); @@ -144,7 +142,7 @@ public class AppThinkerToolbar extends JPanel { _paste.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.PASTE_TOOL); + setCurrentTool(AppThinkerToolbar.PASTE_TOOL); } }); _editionPanel.add(_paste); @@ -171,7 +169,7 @@ public class AppThinkerToolbar extends JPanel { _newClass.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.CLASS_TOOL); + setCurrentTool(AppThinkerToolbar.CLASS_TOOL); } }); _modelisationPanel.add(_newClass); @@ -183,7 +181,7 @@ public class AppThinkerToolbar extends JPanel { _newAssociation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.ASSOCIATION_TOOL); + setCurrentTool(AppThinkerToolbar.ASSOCIATION_TOOL); } }); _modelisationPanel.add(_newAssociation); @@ -195,7 +193,7 @@ public class AppThinkerToolbar extends JPanel { _newLink.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - changeTool(AppThinkerToolbar.LINK_TOOL); + setCurrentTool(AppThinkerToolbar.LINK_TOOL); } }); _modelisationPanel.add(_newLink); @@ -222,7 +220,6 @@ public class AppThinkerToolbar extends JPanel { /** * Active les boutons d'édition lorsqu'un projet est ouvert */ - public void enableEditing(){ _newProject.setEnabled(true); _openProject.setEnabled(true); @@ -265,67 +262,50 @@ public class AppThinkerToolbar extends JPanel { } /** - * Rafraîchit les composants de la barre d'outils. + * Récupère l'outil actuellement en fonction. + * @return L'outil actuellement en fonction. */ - public void refreshToolbar(){ - 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(); + public int getCurrentTool(){ + return this._currentTool; } /** * Change d'outil pour l'édition du diagramme. - * @param tool L'outil cible. + * @param currentTool L'outil cible. */ - public void changeTool(int tool){ - 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){ + 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){ case 1: - _window.getStatusbar().setStatusMessage("Outil édition - Cliquez sur un élément pour l'éditer."); + AppThinker.getWindow().getStatusbar().setStatusMessage("Outil édition - Cliquez sur un élément pour l'éditer."); break; case 2: - _window.getStatusbar().setStatusMessage("Outil suppression - Cliquez sur un élément pour le supprimer."); + 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."); break; case 3: - _window.getStatusbar().setStatusMessage("Outil copie - Cliquez sur un élément pour le copier."); + AppThinker.getWindow().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."); + AppThinker.getWindow().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."); + AppThinker.getWindow().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."); + AppThinker.getWindow().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."); + AppThinker.getWindow().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."); + AppThinker.getWindow().getStatusbar().setStatusMessage("Outil sélection - Cliquez sur un élément pour le sélectionner."); break; } } diff --git a/AppThinker/src/AppThinkerWindow.java b/AppThinker/src/AppThinkerWindow.java index 4053574..8ee0b7e 100644 --- a/AppThinker/src/AppThinkerWindow.java +++ b/AppThinker/src/AppThinkerWindow.java @@ -7,11 +7,9 @@ import java.awt.*; * @author V.BOULANGER */ public class AppThinkerWindow extends JFrame { - private Project _project; - private AppThinkerMenuBar _menu; + private AppThinkerMenuBar _menubar; private AppThinkerToolbar _toolbar; - private AppThinkerGrid _grid; private AppThinkerStatusbar _statusbar; /** @@ -21,81 +19,41 @@ public class AppThinkerWindow extends JFrame { //Paramétrage de la fenêtre this.setTitle("AppThinker"); this.setExtendedState(JFrame.MAXIMIZED_BOTH); + this.setMinimumSize(new Dimension(750, 500)); Image img = null; try { img = ImageIO.read(AppThinker.class.getResource("img/logoAppThinker.png")); } catch (Exception ex) { } this.setIconImage(img); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); + this.setLayout(new BorderLayout()); + //Ajout du menu à la fenêtre - _menu = new AppThinkerMenuBar(this); - this.setJMenuBar(_menu); + _menubar = new AppThinkerMenuBar(); + this.setJMenuBar(_menubar); //Ajout de la toolbar à la fenêtre - _toolbar = new AppThinkerToolbar(this); + _toolbar = new AppThinkerToolbar(); this.add(_toolbar, BorderLayout.NORTH); - //Ajout de la grille à la fenêtre - _grid = new AppThinkerGrid(); - this.add(_grid, BorderLayout.CENTER); - //Ajout de la statusbar à la fenêtre _statusbar = new AppThinkerStatusbar(); this.add(_statusbar, BorderLayout.SOUTH); this.pack(); + this.setVisible(true); } /** - * Crée un nouveau Projet. + * Récupère la menubar contenue dans la fenêtre. + * @return La menubar contenue dans la fenêtre. */ - public void newProject(){ - this._project = new Project(); - this.setTitle("AppThinker | " + _project.getName()); - this._menu.enableEditing(); - this._toolbar.enableEditing(); - this._statusbar.setStatusMessage("Le projet a été créé."); - this._statusbar.setFileMessage(this._project.getName()); + public AppThinkerMenuBar getMenubar(){ + return this._menubar; } - /** - * Ouvre un projet existant dans la fenêtre. - */ - public void openProject(){ - - } - - /** - * Ferme le projet en cours. - */ - public void closeProject(){ - this._project = null; - this.setTitle("AppThinker"); - this._menu.disableEditing(); - this._toolbar.disableEditing(); - this._statusbar.setStatusMessage("Le projet a été fermé."); - this._statusbar.setFileMessage("Aucun projet ouvert"); - } - - /** - * Convertit le projet actuel en chaîne XML. - */ - public void convertToXml(){ - - } - - /** - * Sauvegarde le projet en cours. - */ - public void saveProject(){ - - } - - /** - * Sauvegarde le projet en cours à un autre emplacement. - */ - public void saveAsProject(){ - + public void setGrid(AppThinkerGrid grid){ + this.add(grid, BorderLayout.CENTER); } /** @@ -106,14 +64,6 @@ public class AppThinkerWindow extends JFrame { return this._toolbar; } - /** - * Récupère la grille contenue dans la fenêtre. - * @return La grille contenue dans la fenêtre. - */ - public AppThinkerGrid getGrid(){ - return this._grid; - } - /** * Récupère la statusbar contenue dans la fenêtre. * @return La statusbar contenue dans la fenêtre. diff --git a/AppThinker/src/Argument.java b/AppThinker/src/Argument.java index a5950e4..aa4d1d8 100644 --- a/AppThinker/src/Argument.java +++ b/AppThinker/src/Argument.java @@ -5,7 +5,7 @@ import java.util.List; */ public class Argument { - public static int _argumentsId; + public static int _argumentId; private int _id; private String _type; @@ -15,8 +15,8 @@ public class Argument { * Constructeur - Crée une instance de Argument. */ public Argument(){ - _argumentsId++; - this._id = _argumentsId; + _argumentId++; + this._id = _argumentId; this._type = null; this._name = "argument" + this._id; } @@ -27,8 +27,8 @@ public class Argument { * @param name Le nom de l'argument. */ public Argument(String type, String name){ - _argumentsId++; - this._id = _argumentsId; + _argumentId++; + this._id = _argumentId; this._type = type; this._name = name; } @@ -45,7 +45,7 @@ public class Argument { * Récupère le type de l'argument. * @return Le type de l'argument. */ - public String get_type() { + public String getType() { return _type; } diff --git a/AppThinker/src/Attribute.java b/AppThinker/src/Attribute.java index 78e1367..fc5152c 100644 --- a/AppThinker/src/Attribute.java +++ b/AppThinker/src/Attribute.java @@ -1,10 +1,15 @@ +import org.w3c.dom.Attr; + /** * Gère un attribut. * @author V.BOULANGER */ public class Attribute { - public static int _attributesId = 0; + public static int _attributeId = 0; + public static final String PRIVATE = "-"; + public static final String PROTECTED = "#"; + public static final String PUBLIC = "+"; private int _id; private String _access; @@ -15,10 +20,10 @@ public class Attribute { * Constructeur - Crée une instance de Attribute. */ public Attribute(){ - _attributesId++; - this._id = _attributesId; - this._access = "private"; - this._type = null; + _attributeId++; + this._id = _attributeId; + this._access = Attribute.PRIVATE; + this._type = "int"; this._name = "attribut" + this._id; } @@ -29,8 +34,8 @@ public class Attribute { * @param type Le type de l'attribut. */ public Attribute(String name, String access, String type){ - _attributesId++; - this._id = _attributesId; + _attributeId++; + this._id = _attributeId; this._access = access; this._type = type; this._name = name; diff --git a/AppThinker/src/Class.java b/AppThinker/src/Class.java index 478d36c..061ea42 100644 --- a/AppThinker/src/Class.java +++ b/AppThinker/src/Class.java @@ -17,7 +17,10 @@ public class Class { private int _posY; private int _sizeX; private int _sizeY; + private int _minSizeX; + private int _minSizeY; private int _shape; + private List _attributes; private List _methods; @@ -33,8 +36,8 @@ public class Class { this._name = "Classe" + _id; this._posX = posX; this._posY = posY; - this._sizeX = 30; - this._sizeY = 60; + this._sizeX = 90; + this._sizeY = 50; this._shape = shape; this._attributes = new ArrayList(); this._methods = new ArrayList(); @@ -153,13 +156,35 @@ public class Class { } /** - * Paramètre la taille sur l'axe X et Y de la classe. - * @param sizeX La taille sur l'axe X de la classe. - * @param sizeY La taille sur l'axe Y de la classe. + * Récupère la taille minimale sur l'axe X de la classe. + * @return La taille minimale sur l'axe X de la classe. */ - public void resize(int sizeX, int sizeY){ - this._sizeX = sizeX; - this._sizeY = sizeY; + public int getMinSizeX(){ + return this._minSizeX; + } + + /** + * Paramètre la taille minimale sur l'axe X de la classe. + * @param minSizeX La taille minimale sur l'axe X de la classe. + */ + public void setMinSizeX(int minSizeX){ + this._minSizeX = minSizeX; + } + + /** + * Récupère la taille minimale sur l'axe Y de la classe. + * @return La taille minimale sur l'axe Y de la classe. + */ + public int getMinSizeY(){ + return this._minSizeY; + } + + /** + * Paramètre la taille minimale sur l'axe Y de la classe. + * @param minSizeY La taille minimale sur l'axe Y de la classe. + */ + public void setMinSizeY(int minSizeY){ + this._minSizeY = minSizeY; } /** @@ -178,20 +203,6 @@ public class Class { this._shape = shape; } - /** - * Sélectionne la classe dans l'espace graphique. - */ - public void select(){ - - } - - /** - * Désélectionne la classe dans l'espace graphique. - */ - public void deselect(){ - - } - /** * Récupère tous les attributs de la classe. * @return Les attributs de la classe. @@ -203,16 +214,22 @@ public class Class { /** * Ajoute un attribut à la classe. * @param a L'attribut à ajouter. - * @author V.BOULANGER */ public void addAttribute(Attribute a){ this._attributes.add(a); } + /** + * Supprime un attribut de la classe. + * @param a L'attribut à supprimer. + */ + public void removeAttribute(Attribute a){ + this._attributes.remove(a); + } + /** * Supprime un attribut de la classe. * @param index L'index de l'attribut à supprimer. - * @author V.BOULANGER */ public void removeAttribute(int index){ this._attributes.remove(index); @@ -220,7 +237,6 @@ public class Class { /** * Supprime tous les attributs de la classe. - * @author V.BOULANGER */ public void clearAttributes(){ this._attributes.clear(); @@ -237,16 +253,22 @@ public class Class { /** * Ajoute une méthode à la classe. * @param m La méthode à ajouter. - * @author V.BOULANGER */ public void addMethod(Method m){ this._methods.add(m); } + /** + * Supprime une méthode de la classe. + * @param m La méthode à supprimer. + */ + public void removeMethod(Method m){ + this._methods.remove(m); + } + /** * Supprime une méthode de la classe. * @param index L'index de la méthode à supprimer. - * @author V.BOULANGER */ public void removeMethod(int index){ this._methods.remove(index); @@ -254,7 +276,6 @@ public class Class { /** * Supprime toutes les méthodes de la classe. - * @author V.BOULANGER */ public void clearMethods(){ this._methods.clear(); diff --git a/AppThinker/src/Link.java b/AppThinker/src/Link.java index d32f585..60df2ce 100644 --- a/AppThinker/src/Link.java +++ b/AppThinker/src/Link.java @@ -4,7 +4,7 @@ */ public class Link { - public static int _linksId = 0; + public static int _linkId = 0; public static final int STRONG = 0; public static final int WEAK = 1; public static final int COMPOSITION = 2; @@ -29,8 +29,8 @@ public class Link { * @param end La classe d'arrivée. */ public Link(Class start, Class end){ - _linksId++; - this._id = _linksId; + _linkId++; + this._id = _linkId; this._start = start; this._end = end; this._minCardinalityStart = Link.CARD_NULL; @@ -51,8 +51,8 @@ public class Link { * @param type Le type de lien. */ public Link(Class start, Class end, int minCardinalityStart, int maxCardinalityStart, int minCardinalityEnd, int maxCardinalityEnd, int type){ - _linksId++; - this._id = _linksId; + _linkId++; + this._id = _linkId; this._start = start; this._end = end; this._minCardinalityStart = minCardinalityStart; @@ -86,6 +86,22 @@ public class Link { this._start = start; } + /** + * Récupère la classe d'arrivée du lien. + * @return La classe d'arrivée du lien. + */ + public Class getEnd() { + return _end; + } + + /** + * Paramètre la classe d'arrivée. + * @param end La classe d'arrivée. + */ + public void setEnd(Class end) { + this._end = end; + } + /** * Récupère la cardinalité minimum de la classe de départ. * @return La cardinalité minimum de la classe de départ. @@ -118,37 +134,6 @@ public class Link { this._maxCardinalityStart = maxCardinalityStart; } - /** - * Récupère la classe d'arrivée du lien. - * @return La classe d'arrivée du lien. - */ - public Class getEnd() { - return _end; - } - - /** - * Paramètre la classe d'arrivée. - * @param end La classe d'arrivée. - */ - public void setEnd(Class end) { - this._end = end; - } - - /** - * Modifie la direction du lien (permute les classes de départ et d'arrivée). - */ - public void switchDirection(){ - Class start = this._start; - int minStart = this._minCardinalityStart; - int maxStart = this._maxCardinalityStart; - this._start = _end; - this._end = start; - this._minCardinalityStart = _minCardinalityEnd; - this._maxCardinalityStart = _maxCardinalityEnd; - this._minCardinalityEnd = minStart; - this._maxCardinalityEnd = maxStart; - } - /** * Récupère la cardinalité minimum de la classe d'arrivée. * @return La cardinalité minimum de la classe d'arrivée. @@ -198,16 +183,17 @@ public class Link { } /** - * Sélectionne le lien dans l'espace graphique. + * Modifie la direction du lien (permute les classes de départ et d'arrivée). */ - public void select(){ - - } - - /** - * Désélectionne le lien dans l'espace graphique. - */ - public void deselect(){ - + public void switchDirection(){ + Class start = this._start; + int minStart = this._minCardinalityStart; + int maxStart = this._maxCardinalityStart; + this._start = _end; + this._end = start; + this._minCardinalityStart = _minCardinalityEnd; + this._maxCardinalityStart = _maxCardinalityEnd; + this._minCardinalityEnd = minStart; + this._maxCardinalityEnd = maxStart; } } diff --git a/AppThinker/src/Method.java b/AppThinker/src/Method.java index 5806814..875e23f 100644 --- a/AppThinker/src/Method.java +++ b/AppThinker/src/Method.java @@ -6,7 +6,7 @@ import java.util.List; */ public class Method { - public static int _methodsId = 0; + public static int _methodId = 0; private int _id; private String _access; @@ -18,8 +18,8 @@ public class Method { * Constructeur - Crée une instance de Method. */ public Method(){ - _methodsId++; - this._id = _methodsId; + _methodId++; + this._id = _methodId; this._access = "public"; this._type = null; this._name = "methode" + this._id; @@ -34,8 +34,8 @@ public class Method { * @param arguments Les arguments de la méthode. */ public Method(String access, String type, String name, ArrayList arguments){ - _methodsId++; - this._id = _methodsId; + _methodId++; + this._id = _methodId; this._access = access; this._type = type; this._name = name; @@ -114,6 +114,14 @@ public class Method { this._arguments.add(a); } + /** + * Retire un argument de la méthode. + * @param a L'argument à retirer. + */ + public void removeArgument(Argument a){ + this._arguments.remove(a); + } + /** * Retire un argument de la méthode. * @param index L'index de l'argument à retirer. diff --git a/AppThinker/src/Project.java b/AppThinker/src/Project.java index f27dd06..67e3025 100644 --- a/AppThinker/src/Project.java +++ b/AppThinker/src/Project.java @@ -16,6 +16,8 @@ public class Project { private String _designation; private String _path; + private AppThinkerGrid _grid; + private List _classes; private List _links; @@ -32,6 +34,7 @@ public class Project { _path = null; _classes = new ArrayList(); _links = new ArrayList(); + _grid = new AppThinkerGrid(this); } /** @@ -56,6 +59,14 @@ public class Project { _links = links; } + /** + * Récupère l'objet grille du projet. + * @return L'objet grille du projet. + */ + public AppThinkerGrid getGrid(){ + return this._grid; + } + /** * Récupère le numéro du Projet. * @return Le numéro du projet. @@ -160,6 +171,14 @@ public class Project { this._classes.add(c); } + /** + * Retire une classe du projet. + * @param c La classe à retirer. + */ + public void removeClass(Class c){ + this._classes.remove(c); + } + /** * Retire une classe du projet. * @param index L'index de la classe à retirer. @@ -191,6 +210,14 @@ public class Project { this._links.add(l); } + /** + * Retire un lien du projet. + * @param l Le lien à retirer. + */ + public void removeLink(Link l){ + this._links.remove(l); + } + /** * Retire un lien du projet. * @param index L'index du lien à retirer. diff --git a/AppThinker/src/UmlDiagram.java b/AppThinker/src/UmlDiagram.java new file mode 100644 index 0000000..4611aa4 --- /dev/null +++ b/AppThinker/src/UmlDiagram.java @@ -0,0 +1,227 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.List; + +/** + * Cette classe permet d'afficher l'ensemble des éléments du projet sous la forme d'un diagramme UML. + */ +public class UmlDiagram extends JPanel implements MouseListener, MouseMotionListener { + + private Project _project; + private List _classes; + private List _links; + private Object _selected; + + /** + * Constructeur - Crée un nouveau diagramme UML à partir d'un projet. + * @param p Le projet associé. + */ + public UmlDiagram(Project p){ + _project = p; + this.addMouseListener(this); + this.addMouseMotionListener(this); + } + + /** + * Dessine les éléments du projet sous la forme d'un diagramme UML. + * @param g L'objet graphique + */ + @Override + public void paintComponent(Graphics g){ + int fontSize = 14; + Font font = new Font("Arial", Font.PLAIN, fontSize); + for(Class a : _classes){ + int posX = a.getPosX()-(a.getSizeX()/2); + int posY = a.getPosY()-(a.getSizeY()/2); + //Dessin du rectangle + g.setColor(Color.GRAY); + g.fillRoundRect(posX, posY, a.getSizeX(), a.getSizeY(), 10, 10); + g.setColor(Color.BLACK); + //Dessin du nom de la classe + int posCounter = posY + fontSize; + FontMetrics metrics = g.getFontMetrics(font); + g.setFont(font); + g.drawString(a.getName(), posX + metrics.stringWidth(a.getName())/4, posCounter); + posCounter += 5; + //Ligne de séparation + g.drawLine(posX, posY + fontSize + 5, posX + a.getSizeX()-1, posY + fontSize + 5); + //Affichage des attributs + for(Attribute b : a.getAttributes()){ + posCounter += fontSize; + g.drawString(b.getAccess() + " " + b.getName() + " : " + b.getType(), posX, posCounter); + } + posCounter += 5; + //Ligne de séparation + g.drawLine(posX, posCounter, posX + a.getSizeX()-1, posCounter); + g.setColor(new Color(69, 69, 72)); + //Si la classe est sélectionnée + if((Class)_selected == a){ + AppThinker.getWindow().getStatusbar().setSizeLabel(a.getSizeX(), a.getSizeY()); + //Top Left + g.fillOval(posX-4, posY-4, 8, 8); + //Top + g.fillRect(posX + (a.getSizeX()/2)-4, posY-4, 8, 8); + //Top Right + g.fillOval(posX + a.getSizeX()-4, posY-4, 8, 8); + //Right + g.fillRect(posX + a.getSizeX()-4, posY + (a.getSizeY()/2)-4, 8, 8); + //Bottom Right + g.fillOval(posX + a.getSizeX()-4, posY + a.getSizeY()-4, 8, 8); + //Bottom + g.fillRect(posX + (a.getSizeX()/2)-4, posY + a.getSizeY()-4,8, 8); + //Bottom Left + g.fillOval(posX - 4, posY + a.getSizeY()-4, 8, 8); + //Left + g.fillRect(posX -4, posY + (a.getSizeY()/2)-4, 8, 8); + //Total rectangle + g.drawRect(posX, posY, a.getSizeX(), a.getSizeY()); + } + else AppThinker.getWindow().getStatusbar().setSizeLabel(0, 0); + } + AppThinker.getProject().getGrid().updateUI(); + } + + /** + * Mets à jour graphiquement le diagramme UML. + */ + public void displayDiagram(){ + _classes = _project.getClasses(); + _links = _project.getLinks(); + this.repaint(); + } + + /** + * Récupère l'élément sélectionné dans la grille. + * @return L'élément sélectionné dan sla grille. + */ + public Object getSelected(){ + return this._selected; + } + + /** + * Récupération de l'objet cliqué + * @param getX Les coordonnées de la souris sur l'axe X. + * @param getY Les coordonnées de la souris sur l'axe Y. + */ + public void select(int getX, int getY){ + //On cherche l'objet sélectionné + boolean classSelected = false; + boolean linkSelected = false; + for(Class a : _classes){ + int posX = a.getPosX()-(a.getSizeX()/2); + int posY = a.getPosY()-(a.getSizeY()/2); + if(getX >= posX && getX <= (posX + a.getSizeX())){ + if(getY >= posY && getY <= (posY + a.getSizeY())){ + classSelected = true; + _selected = a; + break; + } + } + } + if(classSelected == false && linkSelected == false) _selected = null; + this.repaint(); + } + + //Actions de la souris sur le diagramme UML + + /** + * Action du clic de la souris sur le diagramme. + * @param e L'événement souris. + */ + @Override + public void mouseClicked(MouseEvent e) { + if(e.getClickCount() == 2){ + System.out.println("Modification des propriétés"); + } + } + + /** + * Bouton de la souris pressé sur la grille. On récupère l'outil sélectionné pour parvenir à l'action. + * @param e L'événement souris. + */ + @Override + public void mousePressed(MouseEvent e) { + System.out.println("ok"); + int tool = AppThinker.getWindow().getToolbar().getCurrentTool(); + switch(tool){ + //On essaie de sélectionner un élément + case AppThinkerToolbar.EDIT_TOOL: + System.out.println("On édite un élément."); + break; + case AppThinkerToolbar.DELETE_TOOL: + System.out.println("On supprime un élément."); + this.select(e.getX(), e.getY()); + if(_selected instanceof Class){ + Class a = (Class)_selected; + AppThinker.getProject().getClasses().remove(a); + } + this.displayDiagram(); + break; + case AppThinkerToolbar.COPY_TOOL: + System.out.println("On copie un élément."); + break; + case AppThinkerToolbar.PASTE_TOOL: + System.out.println("On colle un élément."); + break; + //On essaie d'ajouter une classe + case AppThinkerToolbar.CLASS_TOOL: + Class newClass = new Class(e.getX(), e.getY(), Class.RECTANGLE); + newClass.addAttribute(new Attribute("testAttribut", Attribute.PROTECTED, "String")); + newClass.addAttribute(new Attribute("bonjour", Attribute.PUBLIC, "Date")); + AppThinker.getProject().addClass(newClass); + break; + case AppThinkerToolbar.ASSOCIATION_TOOL: + System.out.println("On ajoute une association"); + break; + case AppThinkerToolbar.LINK_TOOL: + System.out.println("On ajoute un lien"); + break; + default: + this.select(e.getX(), e.getY()); + break; + } + this.displayDiagram(); + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + + /** + * Déplacer un élément en cliquant et déplaçant la souris. + * @param e Evénement souris + */ + @Override + public void mouseDragged(MouseEvent e) { + if(_selected instanceof Class){ + Class a = (Class)_selected; + a.setPosX(e.getX()); + a.setPosY(e.getY()); + } + this.repaint(); + } + + /** + * La souris bouge dans la grille. On affiche les coordonnées de la souris dans la statusbar. + * @param e L'événement souris. + */ + @Override + public void mouseMoved(MouseEvent e) { + AppThinker.getWindow().getStatusbar().setPosLabel(e.getX(), e.getY()); + } +}