Résolution du ticket #5

This commit is contained in:
2020-11-29 22:58:19 +01:00
parent 9f99d30069
commit f091f236cb
3 changed files with 73 additions and 16 deletions

View File

@@ -31,32 +31,42 @@ public class UmlDiagram extends JPanel implements MouseListener, MouseMotionList
*/
@Override
public void paintComponent(Graphics g){
int fontSize = 14;
Font font = new Font("Arial", Font.PLAIN, fontSize);
Font font = new Font("Arial", Font.PLAIN, 14);
for(Class a : _classes){
int posX = a.getPosX()-(a.getSizeX()/2);
int posY = a.getPosY()-(a.getSizeY()/2);
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);
int posCounter = posY + font.getSize();
FontMetrics metrics = this.getFontMetrics(font);
g.setFont(font);
g.drawString(a.getName(), posX + metrics.stringWidth(a.getName())/4, posCounter);
g.drawString(a.getName(), posX + a.getSizeX()/2 - metrics.stringWidth(a.getName())/2, posCounter);
posCounter += 5;
//Ligne de séparation
g.drawLine(posX, posY + fontSize + 5, posX + a.getSizeX()-1, posY + fontSize + 5);
g.drawLine(posX, posY + font.getSize() + 5, posX + a.getSizeX()-1, posY + font.getSize() + 5);
//Affichage des attributs
for(Attribute b : a.getAttributes()){
posCounter += fontSize;
posCounter += font.getSize();
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));
//Dessin des méthodes
for(Method m : a.getMethods()){
posCounter += font.getSize();
String chain = m.getAccess() + " " + m.getName() + "(";
for(Argument ar : m.getArguments()){
chain += ar.getName() + " : " + ar.getType() + ", ";
}
chain = chain.substring(0, chain.length()-2);
chain += ") : " + m.getType();
g.drawString(chain, posX, posCounter);
}
//Si la classe est sélectionnée
if((Class)_selected == a){
AppThinker.getWindow().getStatusbar().setSizeLabel(a.getSizeX(), a.getSizeY());
@@ -126,7 +136,6 @@ public class UmlDiagram extends JPanel implements MouseListener, MouseMotionList
}
//Actions de la souris sur le diagramme UML
/**
* Action du clic de la souris sur le diagramme.
* @param e L'événement souris.
@@ -144,7 +153,6 @@ public class UmlDiagram extends JPanel implements MouseListener, MouseMotionList
*/
@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
@@ -169,8 +177,6 @@ public class UmlDiagram extends JPanel implements MouseListener, MouseMotionList
//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: