Skip to content
Snippets Groups Projects
Commit d1522956 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Adding multiplicities

parent 3f0044cf
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,11 @@ import java.util.Vector; ...@@ -60,6 +60,11 @@ import java.util.Vector;
* @author Ludovic APVRILLE * @author Ludovic APVRILLE
*/ */
public abstract class TGConnectorWithMultiplicity extends TGConnectorWithCommentConnectionPoints { public abstract class TGConnectorWithMultiplicity extends TGConnectorWithCommentConnectionPoints {
public final static int MULTIPLICITY_X = 5;
public final static int MULTIPLICITY_Y = 5;
protected String originMultiplicity, destinationMultiplicity; 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) { 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 ...@@ -85,13 +90,16 @@ public abstract class TGConnectorWithMultiplicity extends TGConnectorWithComment
@Override @Override
public boolean editOndoubleClick(JFrame frame) { public boolean editOndoubleClick(JFrame frame) {
String [] labels = {"origin", "destination"}; String [] labels = new String[2];
String [] values = new String[2]; String [] values = new String[2];
labels[0] = "origin (" + getTGComponent1().getName() + ")";
labels[1] = "destination (" + getTGComponent2().getName() + ")";
values[0] = originMultiplicity; values[0] = originMultiplicity;
values[1] = destinationMultiplicity; values[1] = destinationMultiplicity;
JDialogMultiString jdms = new JDialogMultiString(frame, "Multiplicity", 2, labels, values); 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 jdms.setVisible(true); // blocked until dialog has been closed
if (jdms.hasBeenSet()) { if (jdms.hasBeenSet()) {
...@@ -145,4 +153,34 @@ public abstract class TGConnectorWithMultiplicity extends TGConnectorWithComment ...@@ -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;
}
} }
...@@ -161,7 +161,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S ...@@ -161,7 +161,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S
Font f = g.getFont(); Font f = g.getFont();
int currentHeight = f.getSize() * 2; int currentHeight = f.getSize() * 2;
g.setColor(new Color(avat.getRed(), avat.getGreen(), Math.min(255, avat.getBlue() + (getMyDepth() * 10)))); 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); g.setColor(c);
//Strings //Strings
...@@ -180,7 +180,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S ...@@ -180,7 +180,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S
if (currentHeight < height) { if (currentHeight < height) {
//g.drawLine(x, y+h, x+width, y+h); //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.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); g.setColor(c);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment