From d1522956cf8be0c068f628a3fa5340abfd09df05 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Tue, 5 Jan 2021 16:34:38 +0100 Subject: [PATCH] Adding multiplicities --- .../java/ui/TGConnectorWithMultiplicity.java | 42 ++++++++++++++++++- src/main/java/ui/avatarcd/AvatarCDBlock.java | 4 +- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/ui/TGConnectorWithMultiplicity.java b/src/main/java/ui/TGConnectorWithMultiplicity.java index 76ca846089..d60999d187 100644 --- a/src/main/java/ui/TGConnectorWithMultiplicity.java +++ b/src/main/java/ui/TGConnectorWithMultiplicity.java @@ -60,6 +60,11 @@ import java.util.Vector; * @author Ludovic APVRILLE */ public abstract class TGConnectorWithMultiplicity extends TGConnectorWithCommentConnectionPoints { + + public final static int MULTIPLICITY_X = 5; + public final static int MULTIPLICITY_Y = 5; + + protected String originMultiplicity, destinationMultiplicity; public TGConnectorWithMultiplicity(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector<Point> _listPoint) { @@ -85,13 +90,16 @@ public abstract class TGConnectorWithMultiplicity extends TGConnectorWithComment @Override public boolean editOndoubleClick(JFrame frame) { - String [] labels = {"origin", "destination"}; + String [] labels = new String[2]; String [] values = new String[2]; + + labels[0] = "origin (" + getTGComponent1().getName() + ")"; + labels[1] = "destination (" + getTGComponent2().getName() + ")"; values[0] = originMultiplicity; values[1] = destinationMultiplicity; JDialogMultiString jdms = new JDialogMultiString(frame, "Multiplicity", 2, labels, values); - GraphicLib.centerOnParent(jdms, 500, 300); + GraphicLib.centerOnParent(jdms, 300, 200); jdms.setVisible(true); // blocked until dialog has been closed if (jdms.hasBeenSet()) { @@ -145,4 +153,34 @@ public abstract class TGConnectorWithMultiplicity extends TGConnectorWithComment } } + protected void internalDrawing(Graphics g) { + super.internalDrawing(g); + + int length = g.getFontMetrics().stringWidth(originMultiplicity); + int modifierX = getModifierX(getTGComponent1(), getTGConnectingPointP1(), length); + int modifierY = getModifierY(getTGComponent1(), getTGConnectingPointP1(), g.getFont().getSize()); + + g.drawString(originMultiplicity, getTGConnectingPointP1().getX() + modifierX, getTGConnectingPointP1().getY() + modifierY); + + length = g.getFontMetrics().stringWidth(destinationMultiplicity); + modifierX = getModifierX(getTGComponent2(), getTGConnectingPointP2(), length); + modifierY = getModifierY(getTGComponent2(), getTGConnectingPointP2(), g.getFont().getSize()); + + g.drawString(destinationMultiplicity, getTGConnectingPointP2().getX() + modifierX, getTGConnectingPointP2().getY() + modifierY); + } + + protected int getModifierX(TGComponent tgc, TGConnectingPoint p, int length) { + if (p.getX() <= tgc.getX()+width/2) { + return -MULTIPLICITY_X - length; + } + return MULTIPLICITY_X; + } + + protected int getModifierY(TGComponent tgc, TGConnectingPoint p, int fontSize) { + if (p.getY() <= tgc.getY()+height/2) { + return -MULTIPLICITY_Y - fontSize; + } + return MULTIPLICITY_Y + fontSize; + } + } diff --git a/src/main/java/ui/avatarcd/AvatarCDBlock.java b/src/main/java/ui/avatarcd/AvatarCDBlock.java index d45591525f..88a011f2c2 100644 --- a/src/main/java/ui/avatarcd/AvatarCDBlock.java +++ b/src/main/java/ui/avatarcd/AvatarCDBlock.java @@ -161,7 +161,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S Font f = g.getFont(); int currentHeight = f.getSize() * 2; g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); - g.fill3DRect(x + 1, y + 1, width - 1, Math.min(currentHeight, height) - 1, true); + g.fill3DRect(x + 1, y + 1, width - 1, Math.min(currentHeight, height), true); g.setColor(c); //Strings @@ -180,7 +180,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S if (currentHeight < height) { //g.drawLine(x, y+h, x+width, y+h); g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); - g.fill3DRect(x + 1, y + currentHeight+2, width - 1, height - 1 - currentHeight, true); + g.fill3DRect(x + 1, y + currentHeight+1, width - 1, height - 1 - currentHeight, true); g.setColor(c); } } -- GitLab