tmf: API clean-up of sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / AsyncMessage.java
index 4e8dc37d34cc3a718d4bdc8006b00294b5dc60c3..31867f8be4f789bb2d020789276766bd4934eed4 100755 (executable)
@@ -1,22 +1,24 @@
 /**********************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
  * All rights reserved.   This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors: 
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF
+ *
+ * Contributors:
+ *     IBM - Initial API and implementation
+ *     Bernd Hufmann - Updated for TMF
  **********************************************************************/
+
 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
 
 import java.util.Comparator;
 
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
+import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SortAsyncForBackward;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SortAsyncMessageComparator;
 
@@ -26,12 +28,12 @@ import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SortAsyncMessageComparato
  * <br>
  * <br>
  * Usage example:
- * 
+ *
  * <pre>
  * Frame frame;
  * Lifeline lifeLine1;
  * Lifeline lifeLine2;
- * 
+ *
  * AsyncMessage message = new AsyncMessage();
  * // Create a new event occurrence on each lifeline
  * lifeline1.getNewOccurrenceIndex();
@@ -43,11 +45,11 @@ import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SortAsyncMessageComparato
  * // add the message to the frame
  * frame.addMessage(message);
  * </pre>
- * 
+ *
  * @see Lifeline Lifeline for more event occurence details
- * @version 1.0 
+ * @version 1.0
  * @author sveyrier
- * 
+ * @since 2.0
  */
 public class AsyncMessage extends BaseMessage implements ITimeRange {
 
@@ -65,19 +67,19 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
     /**
      * Flag whether message has time information or not.
      */
-    protected boolean hasTime = false;
+    private boolean fHasTime = false;
     /**
      * The time when the message begin
      */
-    protected ITmfTimestamp endTime = new TmfTimestamp();
+    private ITmfTimestamp fEndTime = new TmfTimestamp();
     /**
      * The time when the message end
      */
-    protected ITmfTimestamp startTime = new TmfTimestamp();
+    private ITmfTimestamp fStartTime = new TmfTimestamp();
     /**
      * The associated message.
      */
-    protected AsyncMessageReturn messageReturn = null;
+    protected AsyncMessageReturn fMessageReturn = null;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -86,104 +88,92 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
      * Default constructor
      */
     public AsyncMessage() {
-        prefId = ISDPreferences.PREF_ASYNC_MESS;
+        setColorPrefId(ISDPreferences.PREF_ASYNC_MESS);
     }
 
     // ------------------------------------------------------------------------
     // Methods
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#getX()
-     */
+
     @Override
     public int getX() {
         int x = super.getX(true);
         int activationWidth = Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
-        if ((startLifeline != null) && (endLifeline != null) && (startLifeline.getX() > endLifeline.getX())) {
+        if ((getStartLifeline() != null) && (getEndLifeline() != null) && (getStartLifeline().getX() > getEndLifeline().getX())) {
             activationWidth = -activationWidth;
         }
 
-        if (isMessageStartInActivation(startEventOccurrence)) {
+        if (isMessageStartInActivation(getStartOccurrence())) {
             x = x + activationWidth;
         }
         return x;
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#getY()
-     */
+
     @Override
     public int getY() {
-        if ((startLifeline != null) && (endLifeline != null)) {
-            return endLifeline.getY() + endLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEventOccurrence;
+        if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
+            return getEndLifeline().getY() + getEndLifeline().getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getStartOccurrence();
         }
         return super.getY();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#getWidth()
-     */
     @Override
     public int getWidth() {
         int width = super.getWidth(true);
         int activationWidth = Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
-        if ((startLifeline != null) && (endLifeline != null) && (startLifeline.getX() > endLifeline.getX())) {
+        if ((getStartLifeline() != null) && (getEndLifeline() != null) && (getStartLifeline().getX() > getEndLifeline().getX())) {
             activationWidth = -activationWidth;
         }
 
-        if (isMessageStartInActivation(startEventOccurrence)) {
+        if (isMessageStartInActivation(getStartOccurrence())) {
             width = width - activationWidth;
         }
 
-        if (isMessageEndInActivation(endEventOccurrence)) {
+        if (isMessageEndInActivation(getEndOccurrence())) {
             width = width - activationWidth;
         }
 
         return width;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#getHeight()
-     */
     @Override
     public int getHeight() {
-        if ((startLifeline != null) && (endLifeline != null)) {
-            return (endLifeline.getY() + endLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * endEventOccurrence) - getY();
+        if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
+            return (getEndLifeline().getY() + getEndLifeline().getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getEndOccurrence()) - getY();
         }
         return super.getHeight();
     }
 
     /**
      * Set the message return associated with this message.
-     * 
+     *
      * @param message the message return to associate
      */
     protected void setMessageReturn(AsyncMessageReturn message) {
-        messageReturn = message;
+        fMessageReturn = message;
     }
 
     /**
      * Set the event occurrence attached to this message for its end lifeline
-     * 
+     *
      * @param occurrence the event occurrence to set
      */
+    @Override
     public void setEndOccurrence(int occurrence) {
-        endEventOccurrence = occurrence;
+        super.setEndOccurrence(occurrence);
         if (getStartLifeline() == null) {
-            startEventOccurrence = occurrence;
+            setStartOccurrence(occurrence);
         }
         informFrame(getEndLifeline(), occurrence);
     }
 
     /**
      * Informs the given lifeline about the maximum occurrence if applicable.
-     * 
+     *
      * @param lifeLine
+     *            Concerned lifeline
      * @param occurrence
+     *            Occurrence number
      */
     protected void informFrame(Lifeline lifeLine, int occurrence) {
         if ((lifeLine != null) && (lifeLine.getFrame() != null) && (lifeLine.getFrame().getMaxEventOccurrence() < occurrence)) {
@@ -193,13 +183,14 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
 
     /**
      * Set the event occurrence attached to this message for its start lifeline
-     * 
+     *
      * @param occurrence the event occurrence to set
      */
+    @Override
     public void setStartOccurrence(int occurrence) {
-        startEventOccurrence = occurrence;
+        super.setStartOccurrence(occurrence);
         if (getEndLifeline() == null) {
-            endEventOccurrence = startEventOccurrence;
+            setEndOccurrence(getStartOccurrence());
         }
         informFrame(getStartLifeline(), occurrence);
     }
@@ -207,7 +198,7 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
     /**
      * Set the lifeLine which has sent the message.<br>
      * A new EventOccurence will be create on this lifeLine.<br>
-     * 
+     *
      * @param lifeline the message sender
      */
     public void autoSetStartLifeline(Lifeline lifeline) {
@@ -218,7 +209,7 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
     /**
      * Set the lifeLine which has received the message.<br>
      * A new EventOccurence will be create on this lifeLine.<br>
-     * 
+     *
      * @param lifeline the message receiver
      */
     public void autoSetEndLifeline(Lifeline lifeline) {
@@ -226,23 +217,15 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
         setEndLifeline(lifeline);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#setStartLifeline(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline)
-     */
     @Override
     public void setStartLifeline(Lifeline lifeline) {
         super.setStartLifeline(lifeline);
         setStartOccurrence(getStartLifeline().getEventOccurrence());
         if (getEndLifeline() == null) {
-            endEventOccurrence = startEventOccurrence;
+            setEndOccurrence(getStartOccurrence());
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#setEndLifeline(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline)
-     */
     @Override
     public void setEndLifeline(Lifeline lifeline) {
         super.setEndLifeline(lifeline);
@@ -251,7 +234,7 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
 
     /**
      * Returns true if the point C is on the segment defined with the point A and B
-     * 
+     *
      * @param xA point A x coordinate
      * @param yA point A y coordinate
      * @param xB point B x coordinate
@@ -283,26 +266,23 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
         return false;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#contains(int, int)
-     */
     @Override
     public boolean contains(int x, int y) {
         // Is it a self message?
-        if (startLifeline == endLifeline) {
+        if (getStartLifeline() == getEndLifeline()) {
             return super.contains(x, y);
         }
-        if (isNearSegment(getX(), getY(), getX() + getWidth(), getY() + getHeight(), x, y))
+        if (isNearSegment(getX(), getY(), getX() + getWidth(), getY() + getHeight(), x, y)) {
             return true;
+        }
         int messageMaxWidth = Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH;
         int nameWidth = getName().length() * Metrics.getAverageCharWidth();
         if (getName().length() * Metrics.getAverageCharWidth() > messageMaxWidth) {
-            if (Frame.contains(getX(), getY() - Metrics.MESSAGES_NAME_SPACING - Metrics.getMessageFontHeigth(), messageMaxWidth, Metrics.getMessageFontHeigth(), x, y)) {
+            if (GraphNode.contains(getX(), getY() - Metrics.MESSAGES_NAME_SPACING - Metrics.getMessageFontHeigth(), messageMaxWidth, Metrics.getMessageFontHeigth(), x, y)) {
                 return true;
             }
         } else {
-            if (Frame.contains(getX() + (messageMaxWidth - nameWidth) / 2, getY() + getHeight() / 2 - Metrics.MESSAGES_NAME_SPACING - Metrics.getMessageFontHeigth(), nameWidth, Metrics.getMessageFontHeigth(), x, y)) {
+            if (GraphNode.contains(getX() + (messageMaxWidth - nameWidth) / 2, getY() + getHeight() / 2 - Metrics.MESSAGES_NAME_SPACING - Metrics.getMessageFontHeigth(), nameWidth, Metrics.getMessageFontHeigth(), x, y)) {
                 return true;
             }
         }
@@ -311,17 +291,17 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
 
     /**
      * Draws the asynchronous message using giving graphical context.
-     * 
+     *
      * @param context A graphical context to draw in.
      */
     protected void drawAsyncMessage(IGC context) {
-        if (startLifeline != null && endLifeline != null && startLifeline == endLifeline && (startEventOccurrence != endEventOccurrence)) {
+        if (getStartLifeline() != null && getEndLifeline() != null && getStartLifeline() == getEndLifeline() && (getStartOccurrence() != getEndOccurrence())) {
             int x = getX();
             int y = getY();
             int height = getHeight();
             int tempx = 0;
-            boolean startInActivation = isMessageStartInActivation(startEventOccurrence);
-            boolean endInActivation = isMessageEndInActivation(endEventOccurrence);
+            boolean startInActivation = isMessageStartInActivation(getStartOccurrence());
+            boolean endInActivation = isMessageEndInActivation(getEndOccurrence());
 
             if (endInActivation && !startInActivation) {
                 tempx = Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
@@ -339,8 +319,8 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
             context.drawLine(x + Metrics.INTERNAL_MESSAGE_WIDTH, y + tempy, x + Metrics.INTERNAL_MESSAGE_WIDTH, y + height - tempy);
             context.drawLine(x + tempx, y + height, x + Metrics.INTERNAL_MESSAGE_WIDTH / 2, y + height);
 
-            Double xt = new Double(Math.cos(0.75) * 7);
-            Double yt = new Double(Math.sin(0.75) * 7);
+            Double xt = Double.valueOf(Math.cos(0.75) * 7);
+            Double yt = Double.valueOf(Math.sin(0.75) * 7);
 
             context.drawLine(x + xt.intValue() + tempx, y + height + yt.intValue(), x + tempx, y + height);
             context.drawArc(x, y, Metrics.INTERNAL_MESSAGE_WIDTH, 2 * tempy, 0, 90);
@@ -354,30 +334,29 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
-     */
     @Override
     public void draw(IGC context) {
         if (!isVisible()) {
             return;
         }
+
+        ISDPreferences pref = SDViewPref.getInstance();
+
         // Draw it selected?
-        if (isSelected() && (startLifeline != null && endLifeline != null && startLifeline == endLifeline && (startEventOccurrence != endEventOccurrence))) {
+        if (isSelected() && (getStartLifeline() != null && getEndLifeline() != null && getStartLifeline() == getEndLifeline() && (getStartOccurrence() != getEndOccurrence()))) {
             /*
              * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection
              * colors This create the highlight effect
              */
-            context.setForeground(Frame.getUserPref().getBackGroundColorSelection());
+            context.setForeground(pref.getBackGroundColorSelection());
             context.setLineWidth(Metrics.SELECTION_LINE_WIDTH);
             drawAsyncMessage(context);
-            context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
-            context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
+            context.setBackground(pref.getBackGroundColorSelection());
+            context.setForeground(pref.getForeGroundColorSelection());
             // Second drawing is done after the else
         } else {
-            context.setBackground(Frame.getUserPref().getBackGroundColor(prefId));
-            context.setForeground(Frame.getUserPref().getForeGroundColor(prefId));
+            context.setBackground(pref.getBackGroundColor(getColorPrefId()));
+            context.setForeground(pref.getForeGroundColor(getColorPrefId()));
         }
         if (hasFocus()) {
             context.setDrawTextWithFocusStyle(true);
@@ -391,12 +370,13 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
 
     /**
      * Set the time when the message end
-     * 
+     *
      * @param time the time when the message end
+     * @since 2.0
      */
     public void setEndTime(ITmfTimestamp time) {
-        endTime = time.clone();
-        hasTime = true;
+        fEndTime = time;
+        fHasTime = true;
         if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
             getStartLifeline().getFrame().setHasTimeInfo(true);
         } else if (getEndLifeline() != null && getEndLifeline().getFrame() != null) {
@@ -406,12 +386,13 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
 
     /**
      * Set the time when the message start
-     * 
+     *
      * @param time the time when the message start
+     * @since 2.0
      */
     public void setStartTime(ITmfTimestamp time) {
-        startTime = time.clone();
-        hasTime = true;
+        fStartTime = time;
+        fHasTime = true;
         if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
             getStartLifeline().getFrame().setHasTimeInfo(true);
         } else if (getEndLifeline() != null && getEndLifeline().getFrame() != null) {
@@ -419,37 +400,35 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#getEndTime()
+    /**
+     * @since 2.0
      */
     @Override
     public ITmfTimestamp getEndTime() {
-        return endTime;
+        return fEndTime;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#getStartTime()
+    /**
+     * @since 2.0
      */
     @Override
     public ITmfTimestamp getStartTime() {
-        return startTime;
+        return fStartTime;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#hasTimeInfo()
-     */
     @Override
     public boolean hasTimeInfo() {
-        return hasTime;
+        return fHasTime;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#isVisible(int, int, int, int)
+    /**
+     *  @return message return instance or null
+     *  @since 2.0
      */
+    public AsyncMessageReturn getMessageReturn() {
+        return fMessageReturn;
+    }
+
     @Override
     public boolean isVisible(int x, int y, int width, int height) {
         int toDrawY = getY();
@@ -463,37 +442,21 @@ public class AsyncMessage extends BaseMessage implements ITimeRange {
         return super.isVisible(x, y, width, height);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getComparator()
-     */
     @Override
     public Comparator<GraphNode> getComparator() {
         return new SortAsyncMessageComparator();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
-     */
     @Override
     public String getArrayId() {
         return ASYNC_MESS_TAG;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getBackComparator()
-     */
     @Override
     public Comparator<GraphNode> getBackComparator() {
         return new SortAsyncForBackward();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
-     */
     @Override
     public boolean positiveDistanceToPoint(int x, int y) {
         int mY = getY();
This page took 0.032989 seconds and 5 git commands to generate.