svn commit: r16376 - trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/ModeCreateMessage.java
Bob Tarling <[email protected]>
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bobtarling
Date: 2008-12-18 21:42:02-0800
New Revision: 16376
Modified:
trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/ModeCreateMessage.java
Log:
First commit toward issue 5530.
If there is not enough room to fit a call/return pair then shift messages down to make space.Working but I'm not quite happy with the maths for the spacing.
Modified: trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/ModeCreateMessage.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/ModeCreateMessage.java?view=diff&pathrev=16376&r1=16375&r2=16376
==============================================================================
--- trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/ModeCreateMessage.java (original)
+++ trunk/src/argouml-core-diagrams-sequence2/src/org/argouml/uml/diagram/sequence2/ui/ModeCreateMessage.java 2008-12-18 21:42:02-0800
@@ -25,6 +25,7 @@
package org.argouml.uml.diagram.sequence2.ui;
import java.awt.Point;
+import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
@@ -49,6 +50,8 @@
private static final Logger LOG =
Logger.getLogger(ModeCreateMessage.class);
+ private static final int DEFAULT_ACTIVATION_HEIGHT = 50;
+
/**
* The constructor.
*
@@ -77,12 +80,15 @@
final SequenceDiagramGraphModel gm =
(SequenceDiagramGraphModel) getEditor().getGraphModel();
+ final FigMessage figMessage = (FigMessage) fe;
+
Object message = fe.getOwner();
FigClassifierRole dcr = (FigClassifierRole) fe.getDestFigNode();
FigClassifierRole scr = (FigClassifierRole) fe.getSourceFigNode();
- final Object action = Model.getFacade().getAction(message);
- if (Model.getFacade().isACallAction(action)) {
+ if (figMessage.isCallAction()) {
+
+ ensureSpace(figMessage);
// get the source of the return message
final Object returnMessageSource =
@@ -122,7 +128,7 @@
// TODO: this shouldn't be hardcoded
// 20 is the height of the spline
// 50 is the default activation height
- points[i].y = fe.getY() + 50 + 20;
+ points[i].y = fe.getFirstPoint().y + DEFAULT_ACTIVATION_HEIGHT;
}
returnEdge.setPoints(points);
@@ -138,6 +144,7 @@
FigPoly poly = (FigPoly) returnEdge.getFig();
poly.setComplete(true);
}
+
dcr.createActivations();
dcr.renderingChanged();
if (dcr != scr) {
@@ -145,4 +152,94 @@
scr.renderingChanged();
}
}
+
+ /**
+ * Called for a call message. Make sure there is enough space to fit the
+ * return message that will be created below.
+ * @param figMessage
+ */
+ private void ensureSpace(final FigMessage figMessage) {
+ final FigMessage firstMessageBelow = getFirstMessageBelow(
+ (FigClassifierRole) getSourceFigNode(),
+ figMessage);
+
+ final int defaultMessageGap = 20;
+ final int heightPlusGap =
+ DEFAULT_ACTIVATION_HEIGHT + defaultMessageGap;
+
+ if (firstMessageBelow != null
+ && firstMessageBelow.getFirstPoint().y
+ < figMessage.getFirstPoint().y + heightPlusGap) {
+
+ final int dy =
+ (figMessage.getFirstPoint().y
+ + heightPlusGap)
+ - firstMessageBelow.getFirstPoint().y;
+
+ for (FigMessage fig : getMessagesBelow(figMessage)) {
+ fig.translateEdge(0, dy);
+ }
+ }
+ }
+
+ /**
+ * Get a list of FigMessages below (higher Y position) than the FigMessage
+ * provided.
+ * @param figMessage
+ * @return a list of FigMessage
+ */
+ private List<FigMessage> getMessagesBelow(FigMessage figMessage) {
+ final List<FigMessage> messagesBelow = new ArrayList<FigMessage>();
+ for (Fig f : getEditor().getLayerManager().getContents()) {
+ if (f instanceof FigMessage
+ && f != figMessage) {
+ FigMessage fm = (FigMessage) f;
+ if (fm.getFirstPoint().y >= figMessage.getFirstPoint().y) {
+ messagesBelow.add((FigMessage) f);
+ }
+ }
+ }
+ return messagesBelow;
+ }
+
+ /**
+ * Get the first FigMessage below (higher Y position) the given
+ * FigMessage.
+ * @param figMessage
+ * @return the FigMessage below or null
+ */
+ private FigMessage getFirstMessageBelow(
+ final FigClassifierRole figClassifierRole,
+ final FigMessage figMessage) {
+
+ final int figMessageY = figMessage.getFirstPoint().y;
+
+ FigMessage firstMessageBelow = null;
+
+ for (FigEdge fe : figClassifierRole.getFigEdges()) {
+ if (fe instanceof FigMessage && fe != figMessage) {
+ final FigMessage fm = (FigMessage) fe;
+ final int y = fm.getFirstPoint().y;
+ if (firstMessageBelow == null
+ || isBetween (y,
+ figMessageY,
+ firstMessageBelow.getFirstPoint().y)) {
+ firstMessageBelow = fm;
+ }
+ }
+ }
+
+ return firstMessageBelow;
+ }
+
+ /**
+ * Return true if a value is in a given range (exclusive)
+ * @param val the value to test
+ * @param lowerVal the lowest value to check
+ * @param upperVal the upper value to check
+ * @return
+ */
+ private boolean isBetween(int val, int lowerVal, int upperVal) {
+ return (val > lowerVal && val < upperVal);
+ }
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=987176
To unsubscribe from this discussion, e-mail: [[email protected]].