MVC partie 2 + résolution de bugs

This commit is contained in:
2021-04-23 12:32:43 +02:00
parent c70f15b6c2
commit 33ecce973e
20 changed files with 946 additions and 418 deletions

View File

@@ -1,3 +1,3 @@
#Tue Apr 20 14:42:09 CEST 2021
#Thu Apr 22 12:13:10 CEST 2021
version=1.0.0
showHomeAtStartup=true

View File

@@ -0,0 +1,92 @@
package com.thinkode.appthinker.controllers;
import com.thinkode.appthinker.models.Argument;
import com.thinkode.appthinker.models.Method;
import com.thinkode.appthinker.views.ArgumentsPropertiesWindow;
public class ArgumentsPropertiesController {
private ArgumentsPropertiesWindow _argumentsPropertiesWindow;
private UmlDiagramController _umlDiagramController;
private ClassPropertiesController _classPropertiesController;
private Method _method;
public ArgumentsPropertiesController(UmlDiagramController umlDiagramController, ClassPropertiesController classPropertiesController, Method method) {
_umlDiagramController = umlDiagramController;
_classPropertiesController = classPropertiesController;
_method = method;
_argumentsPropertiesWindow = new ArgumentsPropertiesWindow();
_argumentsPropertiesWindow.setController(this);
_argumentsPropertiesWindow.initializeGraphics();
}
public String getMethodName() {
return _method.getName();
}
/**
* Ajoute un argument à la méthode sélectionnée et rafraîchit la liste des arguments.
*/
public void addArgument() {
_argumentsPropertiesWindow.save();
_method.addArgument(new Argument());
_classPropertiesController.computeMinSize();
_umlDiagramController.refreshGraphics();
refreshArguments();
_umlDiagramController.needToSave();
}
/**
* Retire un argument à la méthode et rafraîchit la liste des arguments.
*/
public void removeArgument(int index) {
if (index != -1) {
_argumentsPropertiesWindow.save();
_method.removeArgument(index);
_classPropertiesController.computeMinSize();
_umlDiagramController.refreshGraphics();
refreshArguments();
_umlDiagramController.needToSave();
}
}
/**
* Monte l'argument
*/
public void goUpArgument(int index) {
if (_method.upArgument(index)) {
_umlDiagramController.refreshGraphics();
refreshArguments();
_argumentsPropertiesWindow.selectArgument(index - 1);
_umlDiagramController.needToSave();
}
}
/**
* Baisse l'argument
*/
public void goDownArgument(int index) {
if (_method.downArgument(index)) {
_umlDiagramController.refreshGraphics();
refreshArguments();
_argumentsPropertiesWindow.selectArgument(index + 1);
_umlDiagramController.needToSave();
}
}
public void refreshArguments() {
_argumentsPropertiesWindow.listArguments(_method.getArguments());
}
/**
* Sauvegarde les modifications pour la méthode en cours et ferme la fenêtre.
*/
public void save(int index, String type, String name) {
_method.getArguments().get(index).setType(type);
_method.getArguments().get(index).setName(name);
//Rafraichissement de l'affichage
_classPropertiesController.computeMinSize();
_umlDiagramController.refreshGraphics();
_umlDiagramController.needToSave();
}
}

View File

@@ -0,0 +1,264 @@
package com.thinkode.appthinker.controllers;
import com.thinkode.appthinker.models.Argument;
import com.thinkode.appthinker.models.Attribute;
import com.thinkode.appthinker.models.Method;
import com.thinkode.appthinker.views.ClassPropertiesWindow;
import java.util.ArrayList;
public class ClassPropertiesController {
private ClassPropertiesWindow _classPropertiesWindow;
private UmlDiagramController _umlDiagramController;
private com.thinkode.appthinker.models.Class _class;
public ClassPropertiesController(UmlDiagramController umlDiagramController, com.thinkode.appthinker.models.Class c) {
_class = c;
_umlDiagramController = umlDiagramController;
_classPropertiesWindow = new ClassPropertiesWindow();
_classPropertiesWindow.setController(this);
_classPropertiesWindow.initializeGraphics();
}
/**
* Donne à l'interface le nom de la classe
*/
public String getClassName() {
return _class.getName();
}
/**
* Paramètre la classe en cours d'édition comme classe principale
*/
public void setMainClass() {
_umlDiagramController.setMainClass(_class);
_umlDiagramController.needToSave();
refreshGraphics();
}
/**
* Retourne si la classe en cours d'édition est la classe principale
*
* @return
*/
public boolean isMainClass() {
return _umlDiagramController.getMainClass() == _class;
}
/**
* Recalcule les dimensions minimum de la classe
*/
public void computeMinSize() {
_class.computeMinSize();
}
/**
* Ajoute un attribut à la classe et rafraîchit la liste des attributs.
*/
public void addAttribute() {
_classPropertiesWindow.saveAttributes();
_class.addAttribute(new Attribute());
refreshAttributes();
_umlDiagramController.needToSave();
refreshGraphics();
}
/**
* Retire un attribut à la classe et rafraîchit la liste des attributs.
*/
public void removeAttribute(int index) {
if (index != -1) {
_classPropertiesWindow.saveAttributes();
_class.removeAttribute(index);
refreshAttributes();
_umlDiagramController.needToSave();
refreshGraphics();
}
}
/**
* Sauvegarde les informations d'un attribut
*/
public void saveAttribute(int index, String name, String access, String type, boolean isStatic, boolean isFinal, boolean isAbstract, boolean isSynchronized, boolean isVolatile, boolean isTransient) {
_class.getAttributes().get(index).setName(name);
_class.getAttributes().get(index).setAccess(access);
_class.getAttributes().get(index).setType(type);
_class.getAttributes().get(index).setStatic(isStatic);
_class.getAttributes().get(index).setFinal(isFinal);
_class.getAttributes().get(index).setAbstract(isAbstract);
_class.getAttributes().get(index).setSynchronized(isSynchronized);
_class.getAttributes().get(index).setVolatile(isVolatile);
_class.getAttributes().get(index).setTransient(isTransient);
}
/**
* Go up the selected attribute
*/
public void goUpAttribute(int attributeRow) {
if (_class.upAttribute(attributeRow)) {
refreshGraphics();
refreshAttributes();
_classPropertiesWindow.selectAttribute(attributeRow - 1);
_umlDiagramController.needToSave();
}
}
/**
* Go down the selected attribute
*/
public void goDownAttribute(int attributeRow) {
if (_class.downAttribute(attributeRow)) {
refreshGraphics();
refreshAttributes();
_classPropertiesWindow.selectAttribute(attributeRow + 1);
_umlDiagramController.needToSave();
}
}
/**
* Open the arguments properties window
*/
public void openArgumentsWindow(int methodRow) {
new ArgumentsPropertiesController(_umlDiagramController, this, _class.getMethods().get(methodRow));
}
/**
* Refresh attributes
*/
public void refreshAttributes() {
_classPropertiesWindow.listAttributes(_class.getAttributes());
}
/**
* Refresh methods
*/
public void refreshMethods() {
_classPropertiesWindow.listMethods(_class.getMethods());
}
/**
* Ajoute une méthode à la classe et rafraîchit la liste des méthodes.
*/
public void addMethod() {
_classPropertiesWindow.saveMethods();
_class.addMethod(new Method());
refreshMethods();
_umlDiagramController.needToSave();
refreshGraphics();
}
/**
* Ajoute une méthode à la classe à une position donnée et rafraîchit la liste des attributs.
*/
public void addMethod(int index) {
_classPropertiesWindow.saveMethods();
_class.addMethod(index, new Method());
refreshMethods();
_umlDiagramController.needToSave();
refreshGraphics();
}
/**
* Ajoute une méthode à la classe à une position donnée et rafraîchit la liste des attributs.
*/
private void addMethod(int index, Method m) {
_classPropertiesWindow.saveMethods();
_class.addMethod(index, m);
_umlDiagramController.needToSave();
refreshMethods();
refreshGraphics();
}
/**
* Retire une méthode à la classe et rafraîchit la liste des méthodes.
*/
public void removeMethod(int index) {
if (index != -1) {
_classPropertiesWindow.saveMethods();
_class.removeMethod(index);
_umlDiagramController.needToSave();
refreshMethods();
refreshGraphics();
}
}
/**
* Sauvegarde les informations d'une méthode
*/
public void saveMethod(int index, boolean isConstructor, String name, String access, String type, boolean isStatic, boolean isFinal, boolean isAbstract, boolean isSynchronized, boolean isVolatile, boolean isTransient) {
_class.getMethods().get(index).setConstructor(isConstructor);
_class.getMethods().get(index).setName(name);
_class.getMethods().get(index).setAccess(access);
_class.getMethods().get(index).setType(type);
_class.getMethods().get(index).setStatic(isStatic);
_class.getMethods().get(index).setFinal(isFinal);
_class.getMethods().get(index).setAbstract(isAbstract);
_class.getMethods().get(index).setSynchronized(isSynchronized);
_class.getMethods().get(index).setVolatile(isVolatile);
_class.getMethods().get(index).setTransient(isTransient);
}
/**
* Monter une méthode
*/
public void goUpMethod(int methodRow) {
if (_class.upMethod(methodRow)) {
refreshGraphics();
refreshMethods();
_classPropertiesWindow.selectMethod(methodRow - 1);
_umlDiagramController.needToSave();
}
}
/**
* Baisser une méthode
*/
public void goDownMethod(int methodRow) {
if (_class.downMethod(methodRow)) {
refreshGraphics();
refreshMethods();
_classPropertiesWindow.selectMethod(methodRow + 1);
_umlDiagramController.needToSave();
}
}
/**
* Surcharge la méthode sélectionnée
*/
public void overloadMethod(int index) {
if (index != -1) {
Method m = _class.getMethods().get(index);
java.util.List<Argument> args = new ArrayList<Argument>();
//On ajoute un argument de plus que la méthode à surcharger
args.addAll(m.getArguments());
args.add(new Argument());
Method m1 = new Method(m.getAccess(), m.getType(), m.getName(), args, m.isConstructor(), m.isStatic(), m.isFinal(), m.isAbstract(), m.isSynchronized(), m.isVolatile(), m.isTransient());
addMethod(index + 1, m1);
_umlDiagramController.needToSave();
//this.openArgumentsWindow(m1);
}
}
/**
* Sauvegarde l'ensemble de la classe.
*/
public void saveClass(String name) {
//Changement du nom de la classe
_class.setName(name);
//Sauvegarde des attributs et méthodes
_classPropertiesWindow.saveAttributes();
_classPropertiesWindow.saveMethods();
_umlDiagramController.needToSave();
}
/**
* Rafraîchit la classe graphiquement.
*/
public void refreshGraphics() {
this._class.computeMinSize();
_umlDiagramController.refreshGraphics();
}
}

View File

@@ -0,0 +1,106 @@
package com.thinkode.appthinker.controllers;
import com.thinkode.appthinker.models.Link;
import com.thinkode.appthinker.views.LinkPropertiesWindow;
public class LinkPropertiesController {
private LinkPropertiesWindow _linkPropertiesWindow;
private UmlDiagramController _umlDiagramController;
private Link _link;
public LinkPropertiesController(UmlDiagramController umlDiagramController, Link link) {
_umlDiagramController = umlDiagramController;
_link = link;
_linkPropertiesWindow = new LinkPropertiesWindow();
_linkPropertiesWindow.setController(this);
_linkPropertiesWindow.initializeGraphics();
}
public String getLinkName() {
return _link.getName();
}
public void setLinkName(String name) {
_link.setName(name);
_umlDiagramController.needToSave();
}
public String getLinkStartName() {
return _link.getStart().getName();
}
public String getLinkEndName() {
return _link.getEnd().getName();
}
public Link.LinkType getLinkType() {
return _link.getType();
}
public void setLinkType(Link.LinkType type) {
_link.setType(type);
_umlDiagramController.refreshGraphics();
_linkPropertiesWindow.fillWindow();
_umlDiagramController.needToSave();
}
public int getLinkId() {
return _link.getId();
}
public int getLinkMinCardinalityStart() {
return _link.getMinCardinalityStart();
}
public int getLinkMaxCardinalityStart() {
return _link.getMaxCardinalityStart();
}
public int getLinkMinCardinalityEnd() {
return _link.getMinCardinalityEnd();
}
public int getLinkMaxCardinalityEnd() {
return _link.getMaxCardinalityEnd();
}
public void setLinkMinCardinalityStart(int card) {
_link.setMinCardinalityStart(card);
_umlDiagramController.needToSave();
}
public void setLinkMaxCardinalityStart(int card) {
_link.setMaxCardinalityStart(card);
_umlDiagramController.needToSave();
}
public void setLinkMinCardinalityEnd(int card) {
_link.setMinCardinalityEnd(card);
_umlDiagramController.needToSave();
}
public void setLinkMaxCardinalityEnd(int card) {
_link.setMaxCardinalityEnd(card);
_umlDiagramController.needToSave();
}
public void switchDirection() {
_link.switchDirection();
_linkPropertiesWindow.save();
_linkPropertiesWindow.fillWindow();
_umlDiagramController.needToSave();
}
/**
* Rafraîchit l'affichage.
*/
public void refresh() {
//Rafraîchissement du diagramme
_linkPropertiesWindow.repaint();
_umlDiagramController.refreshGraphics();
}
}

View File

@@ -13,8 +13,8 @@ public class UmlDiagramController {
private UmlDiagram _umlDiagram;
public UmlDiagramController(UmlDiagramFrame umlDiagramFrame, UmlDiagram umlDiagram) {
_umlDiagram = umlDiagram;
_umlDiagramFrame = umlDiagramFrame;
_umlDiagram = umlDiagram;
_umlDiagramFrame.setController(this);
}
@@ -28,10 +28,12 @@ public class UmlDiagramController {
public void removeClass(Class a) {
_umlDiagram.removeClass(a);
needToSave();
}
public void clearClasses() {
_umlDiagram.clearClasses();
needToSave();
}
public List<Link> getLinksList() {
@@ -42,12 +44,64 @@ public class UmlDiagramController {
return _umlDiagram.getMainClass();
}
public void setMainClass(Class c) {
_umlDiagram.setMainClass(c);
}
public void addClass(int posX, int posY) {
_umlDiagram.addClass(new Class(posX, posY));
needToSave();
}
public void resizeUp(Class a, int posY) {
a.resizeUp(posY);
needToSave();
}
public void resizeRight(Class a, int posX) {
a.resizeRight(posX);
needToSave();
}
public void resizeDown(Class a, int posY) {
a.resizeDown(posY);
needToSave();
}
public void resizeLeft(Class a, int posX) {
a.resizeLeft(posX);
needToSave();
}
public void setPosX(Class a, int posX) {
a.setPosX(posX);
needToSave();
}
public void setPosY(Class a, int posY) {
a.setPosY(posY);
needToSave();
}
public void addLink(Class start, Class end, UmlDiagramFrame.ClassGrip gripStart, UmlDiagramFrame.ClassGrip gripEnd, int minCardStart, int maxCardStart, int minCardEnd, int maxCardEnd, Link.LinkType type) {
_umlDiagram.addLink(new Link(start, end, gripStart, gripEnd, minCardStart, maxCardStart, minCardEnd, maxCardEnd, type));
needToSave();
}
public void needToSave() {
_umlDiagram.needsToSave(true);
_umlDiagramFrame.needWorkspaceRefresh();
}
public void refreshGraphics() {
_umlDiagramFrame.redraw();
}
public void showClassWindow(Class c) {
new ClassPropertiesController(this, c);
}
public void showLinkWindow(Link l) {
new LinkPropertiesController(this, l);
}
}

View File

@@ -9,6 +9,7 @@ import com.thinkode.appthinker.views.HomeFrame;
import com.thinkode.appthinker.views.UmlDiagramFrame;
import com.thinkode.appthinker.views.Window;
import javax.swing.*;
import java.awt.*;
import java.io.FileInputStream;
import java.io.IOException;
@@ -40,10 +41,12 @@ public class WindowController {
* Ouvre une composition dans la fenêtre
*/
public void openComposition(int projectListId, int compositionListId) {
Composition composition = _projects.get(projectListId).getCompositions().get(compositionListId);
if (composition instanceof UmlDiagram) {
UmlDiagramFrame frame = new UmlDiagramFrame();
UmlDiagram comp = (UmlDiagram) _projects.get(projectListId).getCompositions().get(compositionListId);
UmlDiagramController umlController = new UmlDiagramController(frame, comp);
_atWindow.addCompositionFrame(comp.getName(), _projects.get(projectListId).getName(), frame);
new UmlDiagramController(frame, (UmlDiagram) composition);
_atWindow.addCompositionFrame(composition.getName(), _projects.get(projectListId).getName(), frame);
}
}
/**
@@ -105,6 +108,11 @@ public class WindowController {
*/
public void deleteProject(int projectListId) {
Project project = _projects.get(projectListId);
//Si le projet doit être sauvegardé
if (askForProjectSaved(project)) {
int response = _atWindow.showMessage("The project has not yet been saved or contains unsaved compositions. Do you want to save it before closing it ?", "Save before closing", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (response == JOptionPane.OK_OPTION) saveProject(projectListId);
}
for (Composition comp : project.getCompositions()) {
deleteCompositionFrame(project.getName(), comp.getName());
}
@@ -229,13 +237,37 @@ public class WindowController {
return _projects;
}
/**
* Retourne le nom du projet sélectionné dans le Workspace
*/
public String getProjectName(int projectListId) {
return _projects.get(projectListId).getName();
}
/**
* Retourne si le projet nécessite d'être sauvegardé ou non
*/
public boolean askForProjectSaved(Project project) {
if (project.getPath() == null || project.isNeededToSave()) return true;
for (Composition comp : project.getCompositions()) {
if (comp.isNeededToSave()) return true;
}
return false;
}
/**
* Retourne le nom de la composition sélectionnée dans le Workspace
*/
public String getCompositionName(int projectListId, int compositionListId) {
return _projects.get(projectListId).getCompositions().get(compositionListId).getName();
}
/**
* Sauvegarder le projet
*/
public void saveProject(int projectListId) {
System.out.println("test");
_projects.get(projectListId).saveProject();
refreshWorkspace();
}
/**
@@ -243,13 +275,26 @@ public class WindowController {
*/
public void saveAsProject(int projectListId) {
_projects.get(projectListId).saveAsProject();
refreshWorkspace();
}
/**
* Vérifie si la fenêtre contient des projets non-enregistrés avant la fermeture
*/
public boolean askForExit() {
boolean allProjectsSaved = true;
for (Project p : _projects) {
if (askForProjectSaved(p)) allProjectsSaved = false;
}
System.out.println(allProjectsSaved);
if (!allProjectsSaved) {
if (_atWindow.showMessage("The window contains unsaved projects. Do you want to force close ?", "Force closure ?", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.OK_OPTION)
return true;
else return false;
} else return true;
}
//Méthodes relatives à la barre de menu
public void exitApplication() {
System.exit(0);
}
public void launchAboutWindow() {
AboutWindowController _atAboutWindowController = new AboutWindowController(new AboutWindow());
}

View File

@@ -12,6 +12,7 @@ public class Composition implements Serializable {
protected int _id;
protected String _name;
protected boolean _needToSave = true;
public Composition() {
_id = _compositionId++;
@@ -33,6 +34,7 @@ public class Composition implements Serializable {
*/
public void setName(String name) {
_name = name;
needsToSave(true);
}
/**
@@ -43,4 +45,20 @@ public class Composition implements Serializable {
public int getId() {
return _id;
}
/**
* Retourne si la composition a besoin d'être sauvegardée
*
* @return Un booléen représentant l'affirmation
*/
public boolean isNeededToSave() {
return _needToSave;
}
/**
* Inscrit si la composition a besoin d'être sauvegardée ou non
*/
public void needsToSave(boolean save) {
_needToSave = save;
}
}

View File

@@ -25,6 +25,7 @@ public class Project implements Serializable {
private String _designation;
private String _path;
private List<Composition> _compositions;
protected boolean _needToSave = true;
/**
* Constructeur - Crée une instance de Projet.
@@ -92,6 +93,7 @@ public class Project implements Serializable {
*/
public void setName(String name) {
this._name = name;
needsToSave(true);
}
/**
@@ -110,6 +112,7 @@ public class Project implements Serializable {
*/
public void setAuthor(String author) {
this._author = author;
needsToSave(true);
}
/**
@@ -128,6 +131,7 @@ public class Project implements Serializable {
*/
public void setVersion(String version) {
this._version = version;
needsToSave(true);
}
/**
@@ -146,6 +150,7 @@ public class Project implements Serializable {
*/
public void setDesignation(String designation) {
this._designation = designation;
needsToSave(true);
}
/**
@@ -164,6 +169,7 @@ public class Project implements Serializable {
*/
public void setPath(String path) {
this._path = path;
needsToSave(true);
}
/**
@@ -192,8 +198,13 @@ public class Project implements Serializable {
try {
final FileOutputStream fichier = new FileOutputStream(path);
oos = new ObjectOutputStream(fichier);
for (Composition comp : this.getCompositions()) {
comp.needsToSave(false);
}
this.needsToSave(false);
oos.writeObject(this);
oos.flush();
} catch (final java.io.IOException e) {
e.printStackTrace();
} finally {
@@ -236,6 +247,10 @@ public class Project implements Serializable {
try {
final FileOutputStream fichier = new FileOutputStream(path);
oos = new ObjectOutputStream(fichier);
for (Composition comp : this.getCompositions()) {
comp.needsToSave(false);
}
this.needsToSave(false);
oos.writeObject(this);
oos.flush();
} catch (final java.io.IOException e) {
@@ -253,4 +268,20 @@ public class Project implements Serializable {
return false;
}
}
/**
* Retourne si le projet a besoin d'être sauvegardé
*
* @return Un booléen représentant l'affirmation
*/
public boolean isNeededToSave() {
return _needToSave;
}
/**
* Inscrit si le projet a besoin d'être sauvegardée ou non
*/
public void needsToSave(boolean save) {
_needToSave = save;
}
}

View File

@@ -1,8 +1,8 @@
package com.thinkode.appthinker.views;
import com.thinkode.appthinker.AppThinker;
import com.thinkode.appthinker.controllers.ArgumentsPropertiesController;
import com.thinkode.appthinker.models.Argument;
import com.thinkode.appthinker.models.Method;
import javax.imageio.ImageIO;
import javax.swing.*;
@@ -22,21 +22,22 @@ import java.util.Vector;
*/
public class ArgumentsPropertiesWindow extends JDialog {
private UmlDiagramFrame _umlDiagram;
private Method _method;
private ArgumentsPropertiesController _argumentsPropertiesController;
private JTable _argumentsTable;
private JScrollPane _scrollArguments;
private String[] _argumentsColumns = {"Name", "Type"};
private DefaultTableModel _argumentModel;
private ClassPropertiesWindow _classProp;
public ArgumentsPropertiesWindow(ClassPropertiesWindow classProp, UmlDiagramFrame diagram, Method m) {
_method = m;
_umlDiagram = diagram;
_classProp = classProp;
public ArgumentsPropertiesWindow() {
}
public void setController(ArgumentsPropertiesController argumentsPropertiesController) {
_argumentsPropertiesController = argumentsPropertiesController;
}
public void initializeGraphics() {
//Paramétrage de la fenêtre
this.setTitle("Edit arguments - " + m.getName());
this.setTitle("Edit arguments - " + _argumentsPropertiesController.getMethodName());
this.setModal(true);
this.setSize(new Dimension(800, 375));
Image img = null;
@@ -75,7 +76,7 @@ public class ArgumentsPropertiesWindow extends JDialog {
addArgument.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addArgument();
_argumentsPropertiesController.addArgument();
}
});
argumentsTableModifier.add(addArgument);
@@ -84,7 +85,7 @@ public class ArgumentsPropertiesWindow extends JDialog {
removeArgument.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeArgument();
_argumentsPropertiesController.removeArgument(_argumentsTable.getSelectedRow());
}
});
argumentsTableModifier.add(removeArgument);
@@ -93,12 +94,7 @@ public class ArgumentsPropertiesWindow extends JDialog {
upArgument.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selected = _argumentsTable.getSelectedRow();
if (_method.upArgument(selected)) {
_umlDiagram.repaint();
listArguments();
_argumentsTable.setRowSelectionInterval(selected - 1, selected - 1);
}
_argumentsPropertiesController.goUpArgument(_argumentsTable.getSelectedRow());
}
});
argumentsTableModifier.add(upArgument);
@@ -107,12 +103,7 @@ public class ArgumentsPropertiesWindow extends JDialog {
downArgument.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selected = _argumentsTable.getSelectedRow();
if (_method.downArgument(selected)) {
_umlDiagram.repaint();
listArguments();
_argumentsTable.setRowSelectionInterval(selected + 1, selected + 1);
}
_argumentsPropertiesController.goDownArgument(_argumentsTable.getSelectedRow());
}
});
argumentsTableModifier.add(downArgument);
@@ -124,7 +115,7 @@ public class ArgumentsPropertiesWindow extends JDialog {
this.add(generalPanel, BorderLayout.CENTER);
//Import des arguments dans le tableau
this.listArguments();
_argumentsPropertiesController.refreshArguments();
this.addWindowListener(new WindowListener() {
@Override
@@ -168,40 +159,21 @@ public class ArgumentsPropertiesWindow extends JDialog {
}
/**
* Ajoute un argument à la méthode sélectionnée et rafraîchit la liste des arguments.
* Sélectionne une ligne du tableau d'arguments
*/
public void addArgument() {
save();
_method.addArgument(new Argument());
_classProp.getEditingClass().computeMinSize();
_umlDiagram.repaint();
this.listArguments();
}
/**
* Retire un argument à la méthode et rafraîchit la liste des arguments.
*/
public void removeArgument() {
int i = _argumentsTable.getSelectedRow();
if (i != -1) {
save();
_method.removeArgument(i);
_classProp.getEditingClass().computeMinSize();
_umlDiagram.repaint();
this.listArguments();
}
public void selectArgument(int index) {
_argumentsTable.setRowSelectionInterval(index, index);
}
/**
* Affiche la liste des arguments de la méthode dans le tableau
*/
public void listArguments() {
public void listArguments(java.util.List<Argument> arguments) {
//Import des attributs dans la table
_argumentModel.setDataVector((Object[][]) null, _argumentsColumns);
for (Argument arg : _method.getArguments()) {
for (Argument arg : arguments) {
_argumentModel.addRow(new Object[]{arg.getName(), arg.getType()});
}
//On ajoute les contrôles pour chaque colonne
JComboBox typeComboBox = new JComboBox();
typeComboBox.setEditable(true);
@@ -227,12 +199,7 @@ public class ArgumentsPropertiesWindow extends JDialog {
//Enregistrement des attributs
for (int i = 0; i <= _argumentModel.getRowCount() - 1; i++) {
Vector vect = (Vector) _argumentModel.getDataVector().elementAt(i);
System.out.println(vect);
_method.getArguments().get(i).setType(vect.get(1).toString());
_method.getArguments().get(i).setName(vect.get(0).toString());
}
//Rafraichissement de l'affichage
_classProp.getEditingClass().computeMinSize();
_umlDiagram.repaint();
_argumentsPropertiesController.save(i, vect.get(1).toString(), vect.get(0).toString());
}
}
}

View File

@@ -1,7 +1,7 @@
package com.thinkode.appthinker.views;
import com.thinkode.appthinker.AppThinker;
import com.thinkode.appthinker.models.Argument;
import com.thinkode.appthinker.controllers.ClassPropertiesController;
import com.thinkode.appthinker.models.Attribute;
import com.thinkode.appthinker.models.Class;
import com.thinkode.appthinker.models.Method;
@@ -11,7 +11,6 @@ import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Vector;
/**
@@ -32,19 +31,19 @@ public class ClassPropertiesWindow extends JDialog {
private JScrollPane _scrollMethods;
private String[] _methodsColumns = {"C", "Name", "Access modifier", "Type", "Arguments", "Static", "Final", "Abstract", "Synchronised", "Volatile", "Transient"};
private DefaultTableModel _methodModel;
private JRadioButton _mainRadio;
private ClassPropertiesController _classPropertiesController;
/**
* Constructeur - Crée une instance de la fenêtre de propriétés de classe à partir d'un diagramme et de la classe à modifier.
*
* @param umlDiagram Le diagramme qui contient la classe.
* @param a La classe à modifier.
*/
public ClassPropertiesWindow(UmlDiagramFrame umlDiagram, Class a) {
_umlDiagram = umlDiagram;
_class = a;
public ClassPropertiesWindow() {
}
public void initializeGraphics() {
//Paramétrage de la fenêtre
this.setTitle("Edit properties - " + a.getName());
this.setTitle("Edit properties - " + _classPropertiesController.getClassName());
this.setModal(true);
this.setSize(new Dimension(800, 375));
Image img = null;
@@ -66,29 +65,26 @@ public class ClassPropertiesWindow extends JDialog {
namePan.setLayout(new BoxLayout(namePan, BoxLayout.X_AXIS));
JLabel nameLbl = new JLabel("Name : ");
_nameField = new JTextField();
_nameField.setText(_classPropertiesController.getClassName());
_nameField.setPreferredSize(new Dimension(300, 20));
_nameField.setText(a.getName());
namePan.add(nameLbl);
namePan.add(_nameField);
generalPanel.add(namePan);
//Radio bouton pour définir la classe principale
JRadioButton mainRadio = new JRadioButton("This is the main class");
mainRadio.setToolTipText("The main class is the entry point of the application. It appears in red on the diagram.");
mainRadio.addActionListener(new ActionListener() {
_mainRadio = new JRadioButton("This is the main class");
_mainRadio.setToolTipText("The main class is the entry point of the application. It appears in red on the diagram.");
_mainRadio.setSelected(_classPropertiesController.isMainClass());
_mainRadio.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
defineMainClass(a);
refreshGraphics();
_classPropertiesController.setMainClass();
}
});
ButtonGroup bg = new ButtonGroup();
bg.add(mainRadio);
//if (_umlDiagram.getMainClass() == a) mainRadio.setSelected(true);
//else mainRadio.setSelected(false);
generalPanel.add(mainRadio);
bg.add(_mainRadio);
generalPanel.add(_mainRadio);
JLabel attrLbl = new JLabel("Edit attributes");
generalPanel.add(attrLbl);
@@ -111,7 +107,7 @@ public class ClassPropertiesWindow extends JDialog {
addAttribute.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addAttribute();
_classPropertiesController.addAttribute();
}
});
attributesTableModifier.add(addAttribute);
@@ -120,7 +116,7 @@ public class ClassPropertiesWindow extends JDialog {
removeAttribute.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeAttribute();
_classPropertiesController.removeAttribute(_attributesTable.getSelectedRow());
}
});
attributesTableModifier.add(removeAttribute);
@@ -129,12 +125,7 @@ public class ClassPropertiesWindow extends JDialog {
upAttribute.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selected = _attributesTable.getSelectedRow();
if (_class.upAttribute(selected)) {
refreshGraphics();
listAttributes();
_attributesTable.setRowSelectionInterval(selected - 1, selected - 1);
}
_classPropertiesController.goUpAttribute(_attributesTable.getSelectedRow());
}
});
attributesTableModifier.add(upAttribute);
@@ -143,12 +134,7 @@ public class ClassPropertiesWindow extends JDialog {
downAttribute.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selected = _attributesTable.getSelectedRow();
if (_class.downAttribute(selected)) {
refreshGraphics();
listAttributes();
_attributesTable.setRowSelectionInterval(selected + 1, selected + 1);
}
_classPropertiesController.goDownAttribute(_attributesTable.getSelectedRow());
}
});
attributesTableModifier.add(downAttribute);
@@ -171,7 +157,7 @@ public class ClassPropertiesWindow extends JDialog {
Point p = e.getPoint();
int col = _methodsTable.columnAtPoint(p);
int row = _methodsTable.rowAtPoint(p);
if (col == 4) openArgumentsWindow(_class.getMethods().get(row));
if (col == 4) _classPropertiesController.openArgumentsWindow(_methodsTable.getSelectedRow());
}
});
@@ -186,7 +172,7 @@ public class ClassPropertiesWindow extends JDialog {
addMethod.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addMethod();
_classPropertiesController.addMethod();
}
});
methodsTableModifier.add(addMethod);
@@ -196,7 +182,7 @@ public class ClassPropertiesWindow extends JDialog {
removeMethod.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeMethod();
_classPropertiesController.removeMethod(_methodsTable.getSelectedRow());
}
});
methodsTableModifier.add(removeMethod);
@@ -205,12 +191,7 @@ public class ClassPropertiesWindow extends JDialog {
upMethod.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selected = _methodsTable.getSelectedRow();
if (_class.upMethod(selected)) {
refreshGraphics();
listMethods();
_methodsTable.setRowSelectionInterval(selected - 1, selected - 1);
}
_classPropertiesController.goUpMethod(_methodsTable.getSelectedRow());
}
});
methodsTableModifier.add(upMethod);
@@ -219,12 +200,7 @@ public class ClassPropertiesWindow extends JDialog {
downMethod.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selected = _methodsTable.getSelectedRow();
if (_class.downMethod(selected)) {
refreshGraphics();
listMethods();
_methodsTable.setRowSelectionInterval(selected + 1, selected + 1);
}
_classPropertiesController.goDownMethod(_methodsTable.getSelectedRow());
}
});
methodsTableModifier.add(downMethod);
@@ -233,7 +209,7 @@ public class ClassPropertiesWindow extends JDialog {
overloadMethod.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
overloadMethod();
_classPropertiesController.overloadMethod(_methodsTable.getSelectedRow());
}
});
methodsTableModifier.add(overloadMethod);
@@ -244,10 +220,6 @@ public class ClassPropertiesWindow extends JDialog {
this.add(generalPanel, BorderLayout.CENTER);
//Import des attributs et méthodes dans les tableaux
this.listAttributes();
this.listMethods();
this.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
@@ -257,8 +229,8 @@ public class ClassPropertiesWindow extends JDialog {
//On enregistre à la fermeture de la fenêtre
@Override
public void windowClosing(WindowEvent e) {
saveClass();
refreshGraphics();
_classPropertiesController.saveClass(_nameField.getText());
_classPropertiesController.refreshGraphics();
dispose();
}
@@ -288,120 +260,36 @@ public class ClassPropertiesWindow extends JDialog {
}
});
_classPropertiesController.refreshAttributes();
_classPropertiesController.refreshMethods();
this.setVisible(true);
}
/**
* Définit la classe principale du diagramme.
*
* @param a La classe principale du diagramme.
*/
public void defineMainClass(Class a) {
//_umlDiagram.setMainClass(a);
//refreshGraphics();
public void setController(ClassPropertiesController classPropertiesController) {
_classPropertiesController = classPropertiesController;
}
/**
* Ouvre une fenêtre d'édition des arguments pour la méthode sélectionnée
*
* @param m La méthode dans laquelle seront modifiés les arguments.
* Sélectionne une ligne dans le tableau d'attribut
*/
public void openArgumentsWindow(Method m) {
ArgumentsPropertiesWindow argsWin = new ArgumentsPropertiesWindow(this, _umlDiagram, m);
public void selectAttribute(int index) {
_attributesTable.setRowSelectionInterval(index, index);
}
/**
* Récupère la classe en cours d'édition.
*
* @return La classe en cours d'édition.
* Sélectionne une ligne dans le tableau des méthodes
*/
public Class getEditingClass() {
return _class;
}
/**
* Ajoute un attribut à la classe et rafraîchit la liste des attributs.
*/
public void addAttribute() {
this.saveAttributes();
_class.addAttribute(new Attribute());
this.listAttributes();
refreshGraphics();
}
/**
* Retire un attribut à la classe et rafraîchit la liste des attributs.
*/
public void removeAttribute() {
int i = _attributesTable.getSelectedRow();
if (i != -1) {
this.saveAttributes();
_class.removeAttribute(i);
this.listAttributes();
refreshGraphics();
}
}
/**
* Ajoute une méthode à la classe et rafraîchit la liste des méthodes.
*/
public void addMethod() {
this.saveMethods();
_class.addMethod(new Method());
this.listMethods();
refreshGraphics();
}
/**
* Ajoute une méthode à la classe et rafraîchit la liste des méthodes.
*
* @param index Le rang d'insertion de la méthode.
* @param m La méthode à insérer.
*/
public void addMethod(int index, Method m) {
this.saveMethods();
_class.addMethod(index, m);
this.listMethods();
refreshGraphics();
}
/**
* Retire une méthode à la classe et rafraîchit la liste des méthodes.
*/
public void removeMethod() {
int i = _methodsTable.getSelectedRow();
if (i != -1) {
this.saveMethods();
_class.removeMethod(i);
this.listMethods();
refreshGraphics();
}
}
/**
* On surcharge la méthode avec un argument en plus qui peut être modifié par la suite.
*/
public void overloadMethod() {
int index = _methodsTable.getSelectedRow();
if (index != -1) {
Method m = _class.getMethods().get(index);
java.util.List<Argument> args = new ArrayList<Argument>();
//On ajoute un argument de plus que la méthode à surcharger
args.addAll(m.getArguments());
args.add(new Argument());
Method m1 = new Method(m.getAccess(), m.getType(), m.getName(), args, m.isConstructor(), m.isStatic(), m.isFinal(), m.isAbstract(), m.isSynchronized(), m.isVolatile(), m.isTransient());
this.addMethod(index + 1, m1);
this.openArgumentsWindow(m1);
}
public void selectMethod(int index) {
_methodsTable.setRowSelectionInterval(index, index);
}
/**
* Affiche la liste des attributs de la classe dans le tableau
*/
public void listAttributes() {
public void listAttributes(java.util.List<Attribute> attributes) {
//Import des attributs dans la table
_attributeModel.setDataVector((Object[][]) null, _attributesColumns);
for (Attribute attr : _class.getAttributes()) {
for (Attribute attr : attributes) {
String access = (attr.getAccess() == "+") ? "PUBLIC" : (attr.getAccess() == "#") ? "PROTECTED" : "PRIVATE";
_attributeModel.addRow(new Object[]{attr.getName(), access, attr.getType(), attr.isStatic(), attr.isFinal(), attr.isAbstract(), attr.isSynchronized(), attr.isVolatile(), attr.isTransient()});
}
@@ -425,10 +313,10 @@ public class ClassPropertiesWindow extends JDialog {
/**
* Affiche la liste des méthodes de la classe dans le tableau.
*/
public void listMethods() {
public void listMethods(java.util.List<Method> methods) {
//Import des méthodes dans la table
_methodModel.setDataVector((Object[][]) null, _methodsColumns);
for (Method meth : _class.getMethods()) {
for (Method meth : methods) {
String access = (meth.getAccess() == "-") ? "PRIVATE" : (meth.getAccess() == "#") ? "PROTECTED" : "PUBLIC";
_methodModel.addRow(new Object[]{meth.isConstructor(), meth.getName(), access, meth.getType(), "[EDIT]", meth.isStatic(), meth.isFinal(), meth.isAbstract(), meth.isSynchronized(), meth.isVolatile(), meth.isTransient()});
}
@@ -463,15 +351,16 @@ public class ClassPropertiesWindow extends JDialog {
for (int i = 0; i <= _attributeModel.getRowCount() - 1; i++) {
Vector vect = (Vector) _attributeModel.getDataVector().elementAt(i);
String access = vect.get(1).toString();
_class.getAttributes().get(i).setName(vect.get(0).toString());
_class.getAttributes().get(i).setAccess((access == "PUBLIC") ? Attribute.PUBLIC : (access == "PROTECTED") ? Attribute.PROTECTED : Attribute.PRIVATE);
_class.getAttributes().get(i).setType(vect.get(2).toString());
_class.getAttributes().get(i).setStatic((boolean) vect.get(3));
_class.getAttributes().get(i).setFinal((boolean) vect.get(4));
_class.getAttributes().get(i).setAbstract((boolean) vect.get(5));
_class.getAttributes().get(i).setSynchronized((boolean) vect.get(6));
_class.getAttributes().get(i).setVolatile((boolean) vect.get(7));
_class.getAttributes().get(i).setTransient((boolean) vect.get(8));
_classPropertiesController.saveAttribute(i,
vect.get(0).toString(),
(access == "PUBLIC") ? Attribute.PUBLIC : (access == "PROTECTED") ? Attribute.PROTECTED : Attribute.PRIVATE,
vect.get(2).toString(),
(boolean) vect.get(3),
(boolean) vect.get(4),
(boolean) vect.get(5),
(boolean) vect.get(6),
(boolean) vect.get(7),
(boolean) vect.get(8));
}
}
@@ -484,35 +373,17 @@ public class ClassPropertiesWindow extends JDialog {
for (int i = 0; i <= _methodModel.getRowCount() - 1; i++) {
Vector vect = (Vector) _methodModel.getDataVector().elementAt(i);
String access = vect.get(2).toString();
_class.getMethods().get(i).setConstructor((boolean) vect.get(0));
_class.getMethods().get(i).setName(vect.get(1).toString());
_class.getMethods().get(i).setAccess((access == "PRIVATE") ? Method.PRIVATE : (access == "PROTECTED") ? Method.PROTECTED : Method.PUBLIC);
_class.getMethods().get(i).setType(vect.get(3).toString());
_class.getMethods().get(i).setStatic((boolean) vect.get(5));
_class.getMethods().get(i).setFinal((boolean) vect.get(6));
_class.getMethods().get(i).setAbstract((boolean) vect.get(7));
_class.getMethods().get(i).setSynchronized((boolean) vect.get(8));
_class.getMethods().get(i).setVolatile((boolean) vect.get(9));
_class.getMethods().get(i).setTransient((boolean) vect.get(10));
_classPropertiesController.saveMethod(i,
(boolean) vect.get(0),
vect.get(1).toString(),
(access == "PRIVATE") ? Method.PRIVATE : (access == "PROTECTED") ? Method.PROTECTED : Method.PUBLIC,
vect.get(3).toString(),
(boolean) vect.get(5),
(boolean) vect.get(6),
(boolean) vect.get(7),
(boolean) vect.get(8),
(boolean) vect.get(9),
(boolean) vect.get(10));
}
}
/**
* Sauvegarde l'ensemble de la classe.
*/
public void saveClass() {
//Changement du nom de la classe
_class.setName(_nameField.getText());
//Sauvegarde des attributs et méthodes
saveAttributes();
saveMethods();
}
/**
* Rafraîchit la classe graphiquement.
*/
public void refreshGraphics() {
this._class.computeMinSize();
_umlDiagram.repaint();
}
}

View File

@@ -27,6 +27,13 @@ public class CompositionFrame extends JPanel implements MouseListener, MouseMoti
_atCompositionListener = null;
}
/**
* Le workspace a besoin de se rafraîchir
*/
public void needWorkspaceRefresh() {
_atCompositionListener.refreshWorkspaceNeeded();
}
//Evenements souris
@Override
public void mouseClicked(MouseEvent e) {

View File

@@ -18,4 +18,9 @@ public interface CompositionListener {
* Element size updated
*/
void elementSizeUpdated(int sizeX, int sizeY);
/**
* Need composition save
*/
void refreshWorkspaceNeeded();
}

View File

@@ -3,24 +3,30 @@ package com.thinkode.appthinker.views;
import com.thinkode.appthinker.AppThinker;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class CompositionWidget extends JTabbedPane implements ActionListener, CompositionListener, ChangeListener {
public class CompositionWidget extends JTabbedPane implements CompositionListener {
private ArrayList<String> _titlePans;
private ArrayList<String> _projectPans;
private CompositionWidgetListener _listener;
public CompositionWidget() {
this.addChangeListener(this);
_titlePans = new ArrayList<String>();
_projectPans = new ArrayList<String>();
}
public void addCompositionWidgetListener(CompositionWidgetListener listener) {
_listener = listener;
}
public void removeCompositionWidgetListener() {
_listener = null;
}
/**
* Ajoute un nouvel onglet au composant contenant la composition à ajouter
*
@@ -63,7 +69,7 @@ public class CompositionWidget extends JTabbedPane implements ActionListener, Co
*
* @return
*/
private JPanel createTitlePan(String title) {
private JPanel createTitlePan(String title, int index) {
JPanel titlePan = new JPanel();
titlePan.setOpaque(false);
titlePan.setLayout(new BorderLayout());
@@ -77,7 +83,12 @@ public class CompositionWidget extends JTabbedPane implements ActionListener, Co
titleButton.setPreferredSize(new Dimension(20, 20));
titleButton.setToolTipText("<html>Close <b><i>" + title + "</i></b></html>");
titleButton.setBackground(new Color(105, 105, 114));
titleButton.addActionListener(this);
titleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteCompositionFrame(index);
}
});
titlePan.add(titleButton, BorderLayout.EAST);
return titlePan;
}
@@ -94,11 +105,12 @@ public class CompositionWidget extends JTabbedPane implements ActionListener, Co
if (_titlePans.get(j).equals(title)) occurence.add(j);
}
//La composition ouverte n'a pas de doublon
if (occurence.size() == 1) this.setTabComponentAt(occurence.get(0), createTitlePan(title));
if (occurence.size() == 1)
this.setTabComponentAt(occurence.get(0), createTitlePan(title, occurence.get(0)));
//La composition ouverte a plusieurs doublons
else {
for (int index : occurence) {
this.setTabComponentAt(index, createTitlePan(title + " - " + _projectPans.get(index)));
this.setTabComponentAt(index, createTitlePan(title + " - " + _projectPans.get(index), index));
}
}
}
@@ -132,6 +144,13 @@ public class CompositionWidget extends JTabbedPane implements ActionListener, Co
optimizeNames();
}
public void deleteCompositionFrame(int index) {
_titlePans.remove(index);
_projectPans.remove(index);
this.remove(index);
optimizeNames();
}
//Evenements de la composition
@Override
public void statusEmitted(String status) {
@@ -148,18 +167,8 @@ public class CompositionWidget extends JTabbedPane implements ActionListener, Co
/*setSizeLabel(sizeX, sizeY);*/
}
@Override
public void actionPerformed(ActionEvent e) {
JButton btn = (JButton) e.getSource();
_titlePans.remove(this.getSelectedIndex());
_projectPans.remove(this.getSelectedIndex());
this.remove(this.getSelectedIndex());
optimizeNames();
}
@Override
public void stateChanged(ChangeEvent e) {
//System.out.println("Onglet cliqué !");
@java.lang.Override
public void refreshWorkspaceNeeded() {
_listener.refreshWorkspaceNeeded();
}
}

View File

@@ -0,0 +1,8 @@
package com.thinkode.appthinker.views;
public interface CompositionWidgetListener {
/**
* Demande le rafraîchissement du Workspace
*/
void refreshWorkspaceNeeded();
}

View File

@@ -1,6 +1,7 @@
package com.thinkode.appthinker.views;
import com.thinkode.appthinker.AppThinker;
import com.thinkode.appthinker.controllers.LinkPropertiesController;
import com.thinkode.appthinker.models.Link;
import javax.imageio.ImageIO;
@@ -18,8 +19,8 @@ import java.awt.event.WindowListener;
*/
public class LinkPropertiesWindow extends JDialog {
private UmlDiagramFrame _umlDiagram;
private Link _link;
private LinkPropertiesController _linkPropertiesController;
private JPanel _generalPanel;
private JLabel _fromClass;
private JLabel _toClass;
@@ -41,15 +42,13 @@ public class LinkPropertiesWindow extends JDialog {
/**
* Constructeur - Crée une instance de la fenêtre de propriétés de lin à partir d'un diagramme et du lien à modifier.
*
* @param umlDiagram Le diagramme qui contient la classe.
* @param a Le lien à modifier.
*/
public LinkPropertiesWindow(UmlDiagramFrame umlDiagram, Link a) {
_umlDiagram = umlDiagram;
_link = a;
public LinkPropertiesWindow() {
}
public void initializeGraphics() {
//Paramétrage de la fenêtre
this.setTitle("Edit properties - " + a.getName());
this.setTitle("Edit properties - " + _linkPropertiesController.getLinkName());
this.setModal(true);
this.setSize(new Dimension(800, 375));
Image img = null;
@@ -107,6 +106,10 @@ public class LinkPropertiesWindow extends JDialog {
this.setVisible(true);
}
public void setController(LinkPropertiesController linkPropertiesController) {
_linkPropertiesController = linkPropertiesController;
}
/**
* Charge le contenu de la fenêtre en fonction du type de la relation.
*/
@@ -121,9 +124,9 @@ public class LinkPropertiesWindow extends JDialog {
switchPan.setLayout(new BoxLayout(switchPan, BoxLayout.X_AXIS));
JPanel classesPan = new JPanel();
classesPan.setLayout(new BoxLayout(classesPan, BoxLayout.Y_AXIS));
_fromClass = new JLabel("From : " + _link.getStart().getName());
_fromClass = new JLabel("From : " + _linkPropertiesController.getLinkStartName());
classesPan.add(_fromClass);
_toClass = new JLabel("To : " + _link.getEnd().getName());
_toClass = new JLabel("To : " + _linkPropertiesController.getLinkEndName());
classesPan.add(_toClass);
switchPan.add(classesPan);
_generalPanel.add(switchPan);
@@ -131,9 +134,7 @@ public class LinkPropertiesWindow extends JDialog {
_switchDirection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_link.switchDirection();
save();
fillWindow();
_linkPropertiesController.switchDirection();
}
});
switchPan.add(_switchDirection);
@@ -145,61 +146,52 @@ public class LinkPropertiesWindow extends JDialog {
typeRelation.setLayout(new FlowLayout());
ButtonGroup typeGroup = new ButtonGroup();
_strongRelation = new JRadioButton("Strong");
if (_link.getType() == Link.LinkType.STRONG) _strongRelation.setSelected(true);
Link.LinkType type = _linkPropertiesController.getLinkType();
if (type == Link.LinkType.STRONG) _strongRelation.setSelected(true);
_strongRelation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_link.setType(Link.LinkType.STRONG);
_umlDiagram.repaint();
fillWindow();
_linkPropertiesController.setLinkType(Link.LinkType.STRONG);
}
});
typeGroup.add(_strongRelation);
typeRelation.add(_strongRelation);
_weakRelation = new JRadioButton("Weak");
if (_link.getType() == Link.LinkType.WEAK) _weakRelation.setSelected(true);
if (type == Link.LinkType.WEAK) _weakRelation.setSelected(true);
_weakRelation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_link.setType(Link.LinkType.WEAK);
_umlDiagram.repaint();
fillWindow();
_linkPropertiesController.setLinkType(Link.LinkType.WEAK);
}
});
typeGroup.add(_weakRelation);
typeRelation.add(_weakRelation);
_compositionRelation = new JRadioButton("AppThinker.Application.UI.Composition");
if (_link.getType() == Link.LinkType.COMPOSITION) _compositionRelation.setSelected(true);
_compositionRelation = new JRadioButton("Composition");
if (type == Link.LinkType.COMPOSITION) _compositionRelation.setSelected(true);
_compositionRelation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_link.setType(Link.LinkType.COMPOSITION);
_umlDiagram.repaint();
fillWindow();
_linkPropertiesController.setLinkType(Link.LinkType.COMPOSITION);
}
});
typeGroup.add(_compositionRelation);
typeRelation.add(_compositionRelation);
_aggregationRelation = new JRadioButton("Aggregation");
if (_link.getType() == Link.LinkType.AGGREGATION) _aggregationRelation.setSelected(true);
if (type == Link.LinkType.AGGREGATION) _aggregationRelation.setSelected(true);
_aggregationRelation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_link.setType(Link.LinkType.AGGREGATION);
_umlDiagram.repaint();
fillWindow();
_linkPropertiesController.setLinkType(Link.LinkType.AGGREGATION);
}
});
typeGroup.add(_aggregationRelation);
typeRelation.add(_aggregationRelation);
_inheritanceRelation = new JRadioButton("Inheritance");
if (_link.getType() == Link.LinkType.INHERITANCE) _inheritanceRelation.setSelected(true);
if (type == Link.LinkType.INHERITANCE) _inheritanceRelation.setSelected(true);
_inheritanceRelation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_link.setType(Link.LinkType.INHERITANCE);
_umlDiagram.repaint();
fillWindow();
_linkPropertiesController.setLinkType(Link.LinkType.INHERITANCE);
}
});
typeGroup.add(_inheritanceRelation);
@@ -210,11 +202,11 @@ public class LinkPropertiesWindow extends JDialog {
_generalPanel.add(_contentPanel);
//Affichage du nom de la classe de départ et d'arrivée
_fromClass.setText("From : " + _link.getStart().getName());
_toClass.setText("To : " + _link.getEnd().getName());
_fromClass.setText("From : " + _linkPropertiesController.getLinkStartName());
_toClass.setText("To : " + _linkPropertiesController.getLinkEndName());
//Création du contenu selon le type de relation
_generalPanel.remove(_contentPanel);
if (_link.getType() == Link.LinkType.STRONG || _link.getType() == Link.LinkType.WEAK) {
if (type == Link.LinkType.STRONG || type == Link.LinkType.WEAK) {
_contentPanel = new JPanel();
_contentPanel.setLayout(new BoxLayout(_contentPanel, BoxLayout.Y_AXIS));
//Nom de la relation
@@ -222,19 +214,19 @@ public class LinkPropertiesWindow extends JDialog {
namePan.setLayout(new BoxLayout(namePan, BoxLayout.X_AXIS));
JLabel lblName = new JLabel("Name : ");
namePan.add(lblName);
_txtName = new JTextField(_link.getName());
_txtName = new JTextField(_linkPropertiesController.getLinkName());
namePan.add(_txtName);
_contentPanel.add(namePan);
//Cardinalités de départ et d'arrivée
JPanel cardsStart = new JPanel();
cardsStart.setLayout(new BoxLayout(cardsStart, BoxLayout.X_AXIS));
JLabel lblCardStart = new JLabel("Cardinality (" + _link.getStart().getName() + ") : ");
JLabel lblCardStart = new JLabel("Cardinality (" + _linkPropertiesController.getLinkStartName() + ") : ");
cardsStart.add(lblCardStart);
JLabel minStartLbl = new JLabel(" Min ", SwingConstants.RIGHT);
cardsStart.add(minStartLbl);
_minCardinalityStart = new JSpinner();
_minCardinalityStart.setModel(new SpinnerNumberModel(0, 0, 9999, 1));
_minCardinalityStart.setValue(_link.getMinCardinalityStart());
_minCardinalityStart.setValue(_linkPropertiesController.getLinkMinCardinalityStart());
cardsStart.add(_minCardinalityStart);
JLabel maxStartLbl = new JLabel(" Max ", SwingConstants.RIGHT);
cardsStart.add(maxStartLbl);
@@ -242,10 +234,10 @@ public class LinkPropertiesWindow extends JDialog {
_maxCardinalityStart.setModel(new SpinnerNumberModel(0, 0, 9999, 1));
cardsStart.add(_maxCardinalityStart);
_maxStartLimited = new JCheckBox("Unlimited");
if (_link.getMaxCardinalityStart() == Link.CARD_UNLIMITED) {
if (_linkPropertiesController.getLinkMaxCardinalityStart() == Link.CARD_UNLIMITED) {
_maxCardinalityStart.setEnabled(false);
_maxStartLimited.setSelected(true);
} else _maxCardinalityStart.setValue(_link.getMaxCardinalityStart());
} else _maxCardinalityStart.setValue(_linkPropertiesController.getLinkMaxCardinalityStart());
_maxStartLimited.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -256,13 +248,13 @@ public class LinkPropertiesWindow extends JDialog {
_contentPanel.add(cardsStart);
JPanel cardsEnd = new JPanel();
cardsEnd.setLayout(new BoxLayout(cardsEnd, BoxLayout.X_AXIS));
JLabel lblCardEnd = new JLabel("Cardinality (" + _link.getEnd().getName() + ") : ");
JLabel lblCardEnd = new JLabel("Cardinality (" + _linkPropertiesController.getLinkEndName() + ") : ");
cardsEnd.add(lblCardEnd);
JLabel minEndLbl = new JLabel(" Min ", SwingConstants.RIGHT);
cardsEnd.add(minEndLbl);
_minCardinalityEnd = new JSpinner();
_minCardinalityEnd.setModel(new SpinnerNumberModel(0, 0, 9999, 1));
_minCardinalityEnd.setValue(_link.getMinCardinalityEnd());
_minCardinalityEnd.setValue(_linkPropertiesController.getLinkMinCardinalityEnd());
cardsEnd.add(_minCardinalityEnd);
JLabel maxEndLbl = new JLabel(" Max ", SwingConstants.RIGHT);
cardsEnd.add(maxEndLbl);
@@ -270,10 +262,10 @@ public class LinkPropertiesWindow extends JDialog {
_maxCardinalityEnd.setModel(new SpinnerNumberModel(0, 0, 9999, 1));
cardsEnd.add(_maxCardinalityEnd);
_maxEndLimited = new JCheckBox("Unlimited");
if (_link.getMaxCardinalityEnd() == Link.CARD_UNLIMITED) {
if (_linkPropertiesController.getLinkMaxCardinalityEnd() == Link.CARD_UNLIMITED) {
_maxCardinalityEnd.setEnabled(false);
_maxEndLimited.setSelected(true);
} else _maxCardinalityEnd.setValue(_link.getMaxCardinalityEnd());
} else _maxCardinalityEnd.setValue(_linkPropertiesController.getLinkMaxCardinalityEnd());
_maxEndLimited.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -282,29 +274,29 @@ public class LinkPropertiesWindow extends JDialog {
});
cardsEnd.add(_maxEndLimited);
_contentPanel.add(cardsEnd);
} else if (_link.getType() == Link.LinkType.COMPOSITION || _link.getType() == Link.LinkType.AGGREGATION) {
} else if (type == Link.LinkType.COMPOSITION || type == Link.LinkType.AGGREGATION) {
_contentPanel = new JPanel();
_contentPanel.setLayout(new BoxLayout(_contentPanel, BoxLayout.Y_AXIS));
//Cardinalités de départ et d'arrivée
JPanel cardsEnd = new JPanel();
cardsEnd.setLayout(new BoxLayout(cardsEnd, BoxLayout.X_AXIS));
JLabel lblCardEnd = new JLabel("Cardinality (" + _link.getEnd().getName() + ") : ");
JLabel lblCardEnd = new JLabel("Cardinality (" + _linkPropertiesController.getLinkEndName() + ") : ");
cardsEnd.add(lblCardEnd);
JLabel minEndLbl = new JLabel("Min", SwingConstants.RIGHT);
cardsEnd.add(minEndLbl);
_minCardinalityEnd = new JSpinner();
_minCardinalityEnd.setModel(new SpinnerNumberModel(0, 0, 9999, 1));
_minCardinalityEnd.setValue(_link.getMinCardinalityEnd());
_minCardinalityEnd.setValue(_linkPropertiesController.getLinkMinCardinalityEnd());
cardsEnd.add(_minCardinalityEnd);
JLabel maxEndLbl = new JLabel("Max", SwingConstants.RIGHT);
cardsEnd.add(maxEndLbl);
_maxCardinalityEnd = new JSpinner();
_maxCardinalityEnd.setModel(new SpinnerNumberModel(0, 0, 9999, 1));
_maxEndLimited = new JCheckBox("Unlimited");
if (_link.getMaxCardinalityEnd() == Link.CARD_UNLIMITED) {
if (_linkPropertiesController.getLinkMaxCardinalityEnd() == Link.CARD_UNLIMITED) {
_maxCardinalityEnd.setEnabled(false);
_maxEndLimited.setSelected(true);
} else _maxCardinalityEnd.setValue(_link.getMaxCardinalityEnd());
} else _maxCardinalityEnd.setValue(_linkPropertiesController.getLinkMaxCardinalityEnd());
cardsEnd.add(_maxCardinalityEnd);
_maxEndLimited.addActionListener(new ActionListener() {
@@ -329,39 +321,39 @@ public class LinkPropertiesWindow extends JDialog {
*/
public void save() {
//Validation des changements pour les JSpinner et sauvegarde du nom de la relation et des cardinalités
if (_link.getType() == Link.LinkType.INHERITANCE) {
_link.setName("inheritance" + _link.getId());
_link.setMinCardinalityStart(Link.CARD_NULL);
_link.setMaxCardinalityStart(Link.CARD_NULL);
_link.setMinCardinalityEnd(Link.CARD_NULL);
_link.setMaxCardinalityEnd(Link.CARD_NULL);
Link.LinkType type = _linkPropertiesController.getLinkType();
if (type == Link.LinkType.INHERITANCE) {
_linkPropertiesController.setLinkName("inheritance" + _linkPropertiesController.getLinkId());
_linkPropertiesController.setLinkMinCardinalityStart(Link.CARD_NULL);
_linkPropertiesController.setLinkMaxCardinalityStart(Link.CARD_NULL);
_linkPropertiesController.setLinkMinCardinalityEnd(Link.CARD_NULL);
_linkPropertiesController.setLinkMaxCardinalityEnd(Link.CARD_NULL);
} else {
try {
_minCardinalityEnd.commitEdit();
_maxCardinalityEnd.commitEdit();
_link.setMinCardinalityEnd((Integer) _minCardinalityEnd.getValue());
_link.setMaxCardinalityEnd((_maxEndLimited.isSelected()) ? Link.CARD_UNLIMITED : (Integer) _maxCardinalityEnd.getValue());
if (_link.getType() == Link.LinkType.STRONG || _link.getType() == Link.LinkType.WEAK) {
_linkPropertiesController.setLinkMinCardinalityEnd((Integer) _minCardinalityEnd.getValue());
_linkPropertiesController.setLinkMaxCardinalityEnd((_maxEndLimited.isSelected()) ? Link.CARD_UNLIMITED : (Integer) _maxCardinalityEnd.getValue());
if (type == Link.LinkType.STRONG || type == Link.LinkType.WEAK) {
_minCardinalityStart.commitEdit();
_maxCardinalityStart.commitEdit();
_link.setName(_txtName.getText());
_link.setMinCardinalityStart((Integer) _minCardinalityStart.getValue());
_link.setMaxCardinalityStart((_maxStartLimited.isSelected()) ? Link.CARD_UNLIMITED : (Integer) _maxCardinalityStart.getValue());
} else if (_link.getType() == Link.LinkType.COMPOSITION) {
_link.setName("composition" + _link.getId());
_link.setMinCardinalityStart(Link.CARD_ONE);
_link.setMaxCardinalityStart(Link.CARD_ONE);
_linkPropertiesController.setLinkName(_txtName.getText());
_linkPropertiesController.setLinkMinCardinalityStart((Integer) _minCardinalityStart.getValue());
_linkPropertiesController.setLinkMaxCardinalityStart((_maxStartLimited.isSelected()) ? Link.CARD_UNLIMITED : (Integer) _maxCardinalityStart.getValue());
} else if (type == Link.LinkType.COMPOSITION) {
_linkPropertiesController.setLinkName("composition" + _linkPropertiesController.getLinkId());
_linkPropertiesController.setLinkMinCardinalityStart(Link.CARD_ONE);
_linkPropertiesController.setLinkMaxCardinalityStart(Link.CARD_ONE);
} else {
_link.setName("aggregation" + _link.getId());
_link.setMinCardinalityStart(Link.CARD_NULL);
_link.setMaxCardinalityStart(Link.CARD_ONE);
_linkPropertiesController.setLinkName("aggregation" + _linkPropertiesController.getLinkId());
_linkPropertiesController.setLinkMinCardinalityStart(Link.CARD_NULL);
_linkPropertiesController.setLinkMaxCardinalityStart(Link.CARD_ONE);
}
_linkPropertiesController.refresh();
} catch (java.text.ParseException e) {
JOptionPane.showMessageDialog(this, "Please verify values for cardinalities.");
}
}
//Rafraîchissement du diagramme
this.repaint();
_umlDiagram.repaint();
}
}

View File

@@ -16,7 +16,9 @@ public class Splashscreen extends JFrame {
*/
public Splashscreen() {
this.setTitle("AppThinker - Starting");
this.setMinimumSize(new Dimension(600, 350));
int sizeX = 600;
int sizeY = 350;
this.setMinimumSize(new Dimension(sizeX, sizeY));
Image img = null;
try {
img = ImageIO.read(AppThinker.class.getResource("/com/thinkode/appthinker/img/logoAppThinker.png"));
@@ -39,16 +41,16 @@ public class Splashscreen extends JFrame {
img = ImageIO.read(AppThinker.class.getResource("/com/thinkode/appthinker/img/splashscreen.png"));
} catch (Exception ex) {
}
g2.drawImage(img, 0, 0, 600, 350, this);
g2.drawImage(img, 0, 0, sizeX, sizeY, this);
/*Informations du logiciel*/
g2.setColor(new Color(63, 169, 245));
g2.setFont(new Font("Arial", Font.BOLD, 40));
g2.drawString("AppThinker", 305, 45);
g2.drawString("AppThinker", sizeX - 250, 45);
g2.setFont(new Font("Arial", Font.PLAIN, 20));
g2.drawString("Make your ideas come true", 285, 280);
g2.drawString("Make your ideas come true", sizeX - 250, sizeY - 20);
g2.setFont(new Font("Arial", Font.BOLD, 10));
g2.drawString("We're getting things ready...", 5, 295);
g2.drawString(AppThinker.developer + " © 2021 - Version " + AppThinker.version, 305, 295);
g2.drawString("We're getting things ready...", 5, sizeY - 5);
g2.drawString(AppThinker.developer + " © 2021 - Version " + AppThinker.version, sizeX - 250, sizeY - 5);
}
};

View File

@@ -10,7 +10,6 @@ import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Cette classe permet d'afficher les éléments UML de la composition.
@@ -25,7 +24,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
private boolean _viewGrips = false;
private int gripSize = 8;
private UmlDiagramController _compositionController;
private UmlDiagramController _umlDiagramController;
public enum ClassGrip {
GRIP_N,
@@ -62,8 +61,8 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
redraw();
}
public void setController(UmlDiagramController atUmlDiagramController) {
_compositionController = atUmlDiagramController;
public void setController(UmlDiagramController umlDiagramController) {
_umlDiagramController = umlDiagramController;
}
/**
@@ -85,15 +84,15 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
FontMetrics metrics2 = _drawPanel.getFontMetrics(font2);
g2.setColor(new Color(127, 158, 178));
g2.drawString(_compositionController.getName(), 10, 20);
for (Class a : _compositionController.getClassesList()) {
g2.drawString(_umlDiagramController.getName(), 10, 20);
for (Class a : _umlDiagramController.getClassesList()) {
g2.setFont(font1);
int posX = a.getPosX() - (a.getSizeX() / 2);
int posY = a.getPosY() - (a.getSizeY() / 2);
//Dessin du rectangle
g2.setColor(new Color(127, 158, 178));
g2.fillRect(posX, posY, a.getSizeX(), a.getSizeY());
if (a == _compositionController.getMainClass()) {
if (a == _umlDiagramController.getMainClass()) {
g2.setColor(new Color(173, 37, 8));
g2.drawRect(posX, posY, a.getSizeX(), a.getSizeY());
}
@@ -146,20 +145,20 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
if (_selected != null && _selected instanceof Class && _gripSelected != null) {
Class b = (Class) _selected;
System.out.println(b.getName());
List<ClassGrip> grips = Arrays.asList(ClassGrip.GRIP_N, ClassGrip.GRIP_NE, ClassGrip.GRIP_E, ClassGrip.GRIP_SE, ClassGrip.GRIP_S, ClassGrip.GRIP_SW, ClassGrip.GRIP_W, ClassGrip.GRIP_NW);
List<List<Integer>> gripsPositions = b.getGripsPosition();
java.util.List<ClassGrip> grips = Arrays.asList(ClassGrip.GRIP_N, ClassGrip.GRIP_NE, ClassGrip.GRIP_E, ClassGrip.GRIP_SE, ClassGrip.GRIP_S, ClassGrip.GRIP_SW, ClassGrip.GRIP_W, ClassGrip.GRIP_NW);
java.util.List<java.util.List<Integer>> gripsPositions = b.getGripsPosition();
g2.setColor(Color.RED);
g2.drawLine(gripsPositions.get(grips.indexOf(_gripSelected)).get(0) + gripSize / 2, gripsPositions.get(grips.indexOf(_gripSelected)).get(1) + gripSize / 2, _drawPanel.getMousePosition().x, _drawPanel.getMousePosition().y);
}
//Récupération de la liste des positions des points d'accroche pour la classe en cours
List<List<Integer>> gripsPositions = a.getGripsPosition();
for (Link l : _compositionController.getLinksList()) {
java.util.List<java.util.List<Integer>> gripsPositions = a.getGripsPosition();
for (Link l : _umlDiagramController.getLinksList()) {
//Si le lien est sélectionné, on le dessine en rouge, sinon en noir
if (_selected instanceof Link && (Link) _selected == l) g2.setColor(Color.RED);
else g2.setColor(Color.BLACK);
List<ClassGrip> grips = Arrays.asList(ClassGrip.GRIP_N, ClassGrip.GRIP_NE, ClassGrip.GRIP_E, ClassGrip.GRIP_SE, ClassGrip.GRIP_S, ClassGrip.GRIP_SW, ClassGrip.GRIP_W, ClassGrip.GRIP_NW);
List<List<Integer>> gripsPositionsStart = l.getStart().getGripsPosition();
List<List<Integer>> gripsPositionsEnd = l.getEnd().getGripsPosition();
java.util.List<ClassGrip> grips = Arrays.asList(ClassGrip.GRIP_N, ClassGrip.GRIP_NE, ClassGrip.GRIP_E, ClassGrip.GRIP_SE, ClassGrip.GRIP_S, ClassGrip.GRIP_SW, ClassGrip.GRIP_W, ClassGrip.GRIP_NW);
java.util.List<java.util.List<Integer>> gripsPositionsStart = l.getStart().getGripsPosition();
java.util.List<java.util.List<Integer>> gripsPositionsEnd = l.getEnd().getGripsPosition();
int startX = gripsPositionsStart.get(grips.indexOf(l.getGripStart())).get(0);
int startY = gripsPositionsStart.get(grips.indexOf(l.getGripStart())).get(1);
int endX = gripsPositionsEnd.get(grips.indexOf(l.getGripEnd())).get(0);
@@ -340,7 +339,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
*/
public void removeClass(Class c) {
//On supprime la classe principale
_compositionController.removeClass(c);
_umlDiagramController.removeClass(c);
_selected = null;
}
@@ -363,7 +362,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
*/
public void select(int getX, int getY) {
//Si un élément est survolé, on le sélectionne
for (Class c : _compositionController.getClassesList()) {
for (Class c : _umlDiagramController.getClassesList()) {
int posX = c.getPosX();
int posY = c.getPosY();
int sizeX = c.getSizeX();
@@ -381,10 +380,10 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
break;
}
}
for (Link l : _compositionController.getLinksList()) {
List<ClassGrip> grips = Arrays.asList(ClassGrip.GRIP_N, ClassGrip.GRIP_NE, ClassGrip.GRIP_E, ClassGrip.GRIP_SE, ClassGrip.GRIP_S, ClassGrip.GRIP_SW, ClassGrip.GRIP_W, ClassGrip.GRIP_NW);
List<List<Integer>> positionsStart = l.getStart().getGripsPosition();
List<List<Integer>> positionsEnd = l.getEnd().getGripsPosition();
for (Link l : _umlDiagramController.getLinksList()) {
java.util.List<ClassGrip> grips = Arrays.asList(ClassGrip.GRIP_N, ClassGrip.GRIP_NE, ClassGrip.GRIP_E, ClassGrip.GRIP_SE, ClassGrip.GRIP_S, ClassGrip.GRIP_SW, ClassGrip.GRIP_W, ClassGrip.GRIP_NW);
java.util.List<java.util.List<Integer>> positionsStart = l.getStart().getGripsPosition();
java.util.List<java.util.List<Integer>> positionsEnd = l.getEnd().getGripsPosition();
float startX = positionsStart.get(grips.indexOf(l.getGripStart())).get(0);
float endX = positionsEnd.get(grips.indexOf(l.getGripEnd())).get(0);
float startY = positionsStart.get(grips.indexOf(l.getGripStart())).get(1);
@@ -414,7 +413,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
* @param a La classe à modifier.
*/
public void editClass(Class a) {
ClassPropertiesWindow prop = new ClassPropertiesWindow(this, a);
_umlDiagramController.showClassWindow(a);
}
/**
@@ -423,7 +422,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
* @param l Le lien à modifier.
*/
public void editLink(Link l) {
LinkPropertiesWindow prop = new LinkPropertiesWindow(this, l);
_umlDiagramController.showLinkWindow(l);
}
/**
@@ -521,7 +520,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
break;
//On essaie d'ajouter une classe
case CLASS_TOOL:
_compositionController.addClass(e.getX(), e.getY());
_umlDiagramController.addClass(e.getX(), e.getY());
break;
case STRONG_TOOL:
System.out.println("On ajoute une relation forte.");
@@ -598,30 +597,30 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
if (_gripHovered != null) {
switch (_gripHovered) {
case GRIP_N:
a.resizeUp(posY);
_umlDiagramController.resizeUp(a, posY);
break;
case GRIP_NE:
a.resizeUp(posY);
a.resizeRight(posX);
_umlDiagramController.resizeUp(a, posY);
_umlDiagramController.resizeRight(a, posX);
case GRIP_E:
a.resizeRight(posX);
_umlDiagramController.resizeRight(a, posX);
break;
case GRIP_SE:
a.resizeDown(posY);
a.resizeRight(posX);
_umlDiagramController.resizeDown(a, posY);
_umlDiagramController.resizeRight(a, posX);
case GRIP_S:
a.resizeDown(posY);
_umlDiagramController.resizeDown(a, posY);
break;
case GRIP_SW:
a.resizeDown(posY);
a.resizeLeft(posX);
_umlDiagramController.resizeDown(a, posY);
_umlDiagramController.resizeLeft(a, posX);
break;
case GRIP_W:
a.resizeLeft(posX);
_umlDiagramController.resizeLeft(a, posX);
break;
case GRIP_NW:
a.resizeUp(posY);
a.resizeLeft(posX);
_umlDiagramController.resizeUp(a, posY);
_umlDiagramController.resizeLeft(a, posX);
break;
}
_atCompositionListener.elementSizeUpdated(a.getSizeX(), a.getSizeY());
@@ -629,8 +628,8 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
//Sinon on déplace
else {
//On repositionne la classe en prenant en compte le décalage mesuré au clic de la souris
a.setPosX(posX - _shiftX);
a.setPosY(posY - _shiftY);
_umlDiagramController.setPosX(a, posX - _shiftX);
_umlDiagramController.setPosY(a, posY - _shiftY);
this.setCursor(new Cursor(Cursor.MOVE_CURSOR));
}
}
@@ -638,7 +637,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
//On est en train de créer un lien, on recherche le point d'accroche d'arrivée
if (_selected != null && _gripSelected != null) {
Class selected = (Class) _selected;
for (Class hovered : _compositionController.getClassesList()) {
for (Class hovered : _umlDiagramController.getClassesList()) {
int posXSelected = hovered.getPosX();
int posYSelected = hovered.getPosY();
int sizeXSelected = hovered.getSizeX();
@@ -656,7 +655,7 @@ public class UmlDiagramFrame extends CompositionFrame implements UmlToolbarListe
//Récupération du type de lien
UmlToolbar.UmlTool tool = _umlToolbar.getCurrentTool();
Link.LinkType type = (tool == UmlToolbar.UmlTool.STRONG_TOOL) ? Link.LinkType.STRONG : (tool == UmlToolbar.UmlTool.WEAK_TOOL) ? Link.LinkType.WEAK : (tool == UmlToolbar.UmlTool.COMPOSITION_TOOL) ? Link.LinkType.COMPOSITION : (tool == UmlToolbar.UmlTool.AGGREGATION_TOOL) ? Link.LinkType.AGGREGATION : Link.LinkType.INHERITANCE;
_compositionController.addLink((Class) _selected, (Class) _hovered, _gripSelected, _gripHovered, 0, 0, 0, 0, type);
_umlDiagramController.addLink((Class) _selected, (Class) _hovered, _gripSelected, _gripHovered, 0, 0, 0, 0, type);
_selected = null;
_gripSelected = null;
_gripHovered = null;

View File

@@ -9,11 +9,13 @@ import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Affiche une fenêtre du logiciel.
*/
public class Window extends JFrame implements MenuBarListener, WorkspaceListener {
public class Window extends JFrame implements MenuBarListener, WorkspaceListener, CompositionWidgetListener {
private final MenuBar _menubar;
private final Statusbar _statusbar;
@@ -37,7 +39,13 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
throw new NotImplementedException();
}
this.setIconImage(img);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
quitClicked();
}
});
this.setLocationRelativeTo(null);
this.setLayout(new BorderLayout());
@@ -58,6 +66,7 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
//Ajout du Widget de visualisation des compositions
_compositionWidget = new CompositionWidget();
_compositionWidget.addCompositionWidgetListener(this);
this.add(_compositionWidget, BorderLayout.CENTER);
}
@@ -111,11 +120,6 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
public void addCompositionFrame(String compositionName, String projectName, CompositionFrame composition) {
//Ajout de la composition au widget central
_compositionWidget.addCompositionFrame(compositionName, projectName, composition);
//Modification de la barre de statut
//Modification du titre et activation des fonctionnalités d'édition
//String projectPath = _mainWindowController.getProjectPath();
//this.setTitle((projectPath == null) ? "AppThinker - " + projectName + "*" : "AppThinker - " + projectName + " (" + projectPath + ")");
this.revalidate();
}
@@ -126,6 +130,10 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
JOptionPane.showMessageDialog(this, message);
}
public int showMessage(String message, String title, int option, int type) {
return JOptionPane.showOptionDialog(this, message, title, option, type, null, null, null);
}
public void setStatusMessage(String message) {
_statusbar.setStatusMessage(message);
}
@@ -180,6 +188,16 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
_mainWindowController.addUmlComposition(projectListId);
}
@Override
public String askForProjectName(int projectListId) {
return _mainWindowController.getProjectName(projectListId);
}
@Override
public boolean askForProjectSaved(Project project) {
return _mainWindowController.askForProjectSaved(project);
}
@Override
public void renameProject(int projectListId, String newName) {
_mainWindowController.renameProject(projectListId, newName);
@@ -200,6 +218,11 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
_mainWindowController.deleteProject(projectListId);
}
@Override
public String askForCompositionName(int projectListId, int compositionListId) {
return _mainWindowController.getCompositionName(projectListId, compositionListId);
}
@Override
public void renameComposition(int projectListId, int compositionListId, String newName) {
_mainWindowController.renameComposition(projectListId, compositionListId, newName);
@@ -233,7 +256,7 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
@Override
public void quitClicked() {
_mainWindowController.exitApplication();
if (_mainWindowController.askForExit()) System.exit(0);
}
@Override
@@ -245,4 +268,10 @@ public class Window extends JFrame implements MenuBarListener, WorkspaceListener
public void checkUpdatesClicked() {
_mainWindowController.checkForUpdates();
}
//Evenement du CompositionWidget
@java.lang.Override
public void refreshWorkspaceNeeded() {
_mainWindowController.refreshWorkspace();
}
}

View File

@@ -7,6 +7,7 @@ import com.thinkode.appthinker.models.Project;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.*;
@@ -37,12 +38,12 @@ public class Workspace extends JPanel implements ActionListener, MouseListener,
this.setPreferredSize(new Dimension(300, 10000));
_actionPanel = new JPanel();
_actionPanel.setLayout(new BorderLayout());
_actionPanel.setBackground(new Color(222, 222, 222));
_actionPanel.setBackground(new Color(238, 238, 238));
Border panelBorder = BorderFactory.createLineBorder(new Color(105, 105, 114), 1);
_actionPanel.setBorder(panelBorder);
_homePage = new JPanel();
_homePage.setBackground(new Color(222, 222, 222));
_homePage.setBackground(new Color(238, 238, 238));
_homePage.setLayout(new FlowLayout(FlowLayout.LEFT));
JLabel imgHome = new JLabel(new ImageIcon(AppThinker.class.getResource("img/x16/homePage.png")));
_homePage.add(imgHome);
@@ -51,7 +52,7 @@ public class Workspace extends JPanel implements ActionListener, MouseListener,
_actionPanel.add(_homePage, BorderLayout.WEST);
_newProject = new JPanel();
_newProject.setBackground(new Color(222, 222, 222));
_newProject.setBackground(new Color(238, 238, 238));
_newProject.setLayout(new FlowLayout(FlowLayout.LEFT));
JLabel imgNewProject = new JLabel(new ImageIcon(AppThinker.class.getResource("img/x16/newProject.png")));
_newProject.add(imgNewProject);
@@ -73,7 +74,7 @@ public class Workspace extends JPanel implements ActionListener, MouseListener,
//Aucun projet n'est ouvert, on affiche le message par défaut
if (projects.size() == 0) {
_contentPanel = new JPanel();
_contentPanel.setBackground(new Color(222, 222, 222));
_contentPanel.setBackground(new Color(238, 238, 238));
JLabel lbl2 = new JLabel("No project is open. Click on + to add a project.");
_contentPanel.add(lbl2);
_scrollPane = new JScrollPane(_contentPanel);
@@ -82,15 +83,26 @@ public class Workspace extends JPanel implements ActionListener, MouseListener,
else {
_root = new DefaultMutableTreeNode("Opened projects");
for (Project proj : projects) {
DefaultMutableTreeNode project = new DefaultMutableTreeNode(proj.getName());
String projectName;
if (_listener.askForProjectSaved(proj)) projectName = proj.getName() + "*";
else projectName = proj.getName();
DefaultMutableTreeNode project = new DefaultMutableTreeNode(projectName);
for (Composition comp : proj.getCompositions()) {
DefaultMutableTreeNode composition = new DefaultMutableTreeNode(comp.getName());
String lbl = (comp.isNeededToSave()) ? "<html><i>" + comp.getName() + "</i> (<b>" + comp.getClass().getSimpleName() + "</b>)</html>" : "<html>" + comp.getName() + " (<b>" + comp.getClass().getSimpleName() + "</b>)</html>";
DefaultMutableTreeNode composition = new DefaultMutableTreeNode(lbl);
project.add(composition);
}
_root.add(project);
}
_tree = new JTree(_root);
_tree.expandPath(new TreePath(_root));
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) _tree.getCellRenderer();
renderer.setTextSelectionColor(Color.WHITE);
renderer.setBackgroundSelectionColor(new Color(63, 169, 245));
renderer.setBorderSelectionColor(new Color(63, 169, 245));
//Ouvrir tous les noeuds
for (int i = 0; i < _tree.getRowCount(); i++) {
_tree.expandRow(i);
}
JPopupMenu projectContextMenu = new JPopupMenu("Project actions");
JMenuItem addMenu = new JMenu("New");
addMenu.setIcon(new ImageIcon(AppThinker.class.getResource("img/x16/newComposition.png")));
@@ -115,7 +127,7 @@ public class Workspace extends JPanel implements ActionListener, MouseListener,
_saveAsProject.setIcon(new ImageIcon(AppThinker.class.getResource("img/x16/saveAsProject.png")));
_saveAsProject.addActionListener(this);
projectContextMenu.add(_saveAsProject);
_deleteProject = new JMenuItem("Delete project");
_deleteProject = new JMenuItem("Close project");
_deleteProject.setIcon(new ImageIcon(AppThinker.class.getResource("img/x16/closeProject.png")));
_deleteProject.addActionListener(this);
projectContextMenu.add(_deleteProject);
@@ -141,22 +153,22 @@ public class Workspace extends JPanel implements ActionListener, MouseListener,
TreePath selPath = _tree.getPathForLocation(e.getX(), e.getY());
if (selRow != -1) {
int path = selPath.getPathCount();
_tree.setSelectionPath(selPath);
DefaultMutableTreeNode selectedItem = (DefaultMutableTreeNode) _tree.getSelectionPath().getLastPathComponent();
if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) {
//Clic droit - Affichage des paramètres du projet/composition
_tree.setSelectionPath(selPath);
if (path == 2) {
projectContextMenu.show(_tree, e.getX(), e.getY());
_nameProject.setText(_tree.getSelectionPath().getLastPathComponent().toString());
_nameProject.setText(_listener.askForProjectName(_root.getIndex(selectedItem)));
} else {
compositionContextMenu.show(_tree, e.getX(), e.getY());
_nameComposition.setText(_tree.getSelectionPath().getLastPathComponent().toString());
_nameComposition.setText(_listener.askForCompositionName(_root.getIndex(selectedItem.getParent()), selectedItem.getParent().getIndex(selectedItem)));
}
} else if (e.getClickCount() == 2) {
if (path == 2) {
//Double-clic sur un projet
} else {
//Double clic sur une composition
DefaultMutableTreeNode selectedItem = (DefaultMutableTreeNode) _tree.getSelectionPath().getLastPathComponent();
int compositionId = selectedItem.getParent().getIndex(selectedItem);
int projectId = _root.getIndex(selectedItem.getParent());
_listener.compositionDoubleClick(projectId, compositionId);

View File

@@ -1,5 +1,7 @@
package com.thinkode.appthinker.views;
import com.thinkode.appthinker.models.Project;
public interface WorkspaceListener {
/**
@@ -22,6 +24,16 @@ public interface WorkspaceListener {
*/
void addUmlComposition(int projectListId);
/**
* Demande le nom du projet sélectionné dans le Workspace
*/
String askForProjectName(int projectListId);
/**
* Demande si le projet doit être sauvegardé ou non
*/
boolean askForProjectSaved(Project project);
/**
* Renomme le projet sélectionné
*/
@@ -42,6 +54,11 @@ public interface WorkspaceListener {
*/
void deleteProject(int projectListId);
/**
* Demande le nom d'une composition sélectionnée dans le Workspace
*/
String askForCompositionName(int projectListId, int compositionListId);
/**
* Renomme la composition d'un projet
*/