/**********************************************************************
- * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2011, 2012 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
- * $Id: BasicFrame.java,v 1.2 2008/01/24 02:28:49 apnan Exp $
*
* Contributors:
* IBM - Initial API and implementation
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
-import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences;
+import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
/**
*/
public class BasicFrame extends GraphNode {
+ // ------------------------------------------------------------------------
+ // Static Attributes/Constants
+ // ------------------------------------------------------------------------
+ /**
+ * The sequence diagram reference.
+ */
+ protected static ISDPreferences userPref = null;
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
/**
* Contains the max elapsed time between two consecutive messages in the whole frame
*/
* Contains the min elapsed time between two consecutive messages in the whole frame
*/
protected ITmfTimestamp minTime = new TmfTimestamp(0);
-
/**
* Indicate if the min and max elapsed time between two consecutive messages in the whole frame need to be computed
*/
protected boolean computeMinMax = true;
-
/**
* Store the preference set by the user regarding the external time. This flag is used determine if the min and max
* need to be recomputed in case this preference is changed.
*/
protected boolean lastExternalTimePref = SDViewPref.getInstance().excludeExternalTime();
-
/**
* The greater event occurrence created on graph nodes drawn in this Frame This directly impact the Frame height
*/
protected int verticalIndex = 0;
-
/**
* The index along the x axis where the next lifeline will is drawn This directly impact the Frame width
*/
protected int horizontalIndex = 0;
-
+ /**
+ * The information flag.
+ */
protected boolean timeInfo = false;
-
/**
- * The current Frame visible area
+ * The current Frame visible area - x coordinates
*/
protected int visibleAreaX;
+ /**
+ * The current Frame visible area - y coordinates
+ */
protected int visibleAreaY;
+ /**
+ * The current Frame visible area - width
+ */
protected int visibleAreaWidth;
+ /**
+ * The current Frame visible area - height
+ */
protected int visibleAreaHeight;
-
- static ISDPreferences userPref = null;
-
+ /**
+ * The event occurrence spacing (-1 for none)
+ */
protected int forceEventOccurrenceSpacing = -1;
-
+ /**
+ * Flag to indicate customized minumum and maximum.
+ */
protected boolean customMinMax = false;
-
+ /**
+ * The minimum time between messages of the sequence diagram frame.
+ */
protected ITmfTimestamp minSDTime = new TmfTimestamp();
+ /**
+ * The maximum time between messages of the sequence diagram frame.
+ */
protected ITmfTimestamp maxSDTime = new TmfTimestamp();
+ /**
+ * Flag to indicate that initial minimum has to be computed.
+ */
protected boolean initSDMin = true;
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
/**
* Creates an empty frame.
*/
Metrics.setForcedEventSpacing(forceEventOccurrenceSpacing);
}
+ // ------------------------------------------------------------------------
+ // Methods
+ // ------------------------------------------------------------------------
+
/**
*
* Returns the greater event occurence known by the Frame
return horizontalIndex;
}
- /**
- * Add a GraphNode into the frame
- *
- * @param nodeToAdd the node to add
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#addNode(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode)
*/
@Override
public void addNode(GraphNode nodeToAdd) {
super.addNode(nodeToAdd);
}
- /**
- * @return the frame x axis value in the containing view
+ /*
+ * (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
*/
@Override
return Metrics.FRAME_H_MARGIN;
}
- /**
- * @return the frame y axis value in the containing view
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
*/
@Override
public int getY() {
return Metrics.FRAME_V_MARGIN;
}
- /**
- * The frame width depends on the number of lifeline added in the frame
- *
- * @return the frame width
+ /*
+ * (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
*/
@Override
public int getWidth() {
- if (horizontalIndex == 0)
+ if (horizontalIndex == 0) {
return 3 * Metrics.swimmingLaneWidth() + Metrics.LIFELINE_H_MAGIN * 2 - Metrics.FRAME_H_MARGIN - Metrics.LIFELINE_SPACING / 2;
- else
+ } else {
return horizontalIndex * Metrics.swimmingLaneWidth() + Metrics.LIFELINE_H_MAGIN * 2 + 1 - Metrics.LIFELINE_SPACING;
+ }
}
- /**
- * The Frame height depends on the maximum number of messages added to a lifeline( Taking all lifelines into
- * account)
- *
- * @return the frame height
+ /*
+ * (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
*/
@Override
public int getHeight() {
- if (verticalIndex == 0)
+ // The Frame height depends on the maximum number of messages added to a lifeline
+ if (verticalIndex == 0) {
return 5 * (Metrics.getMessagesSpacing() + Metrics.getMessageFontHeigth()) + Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getFrameFontHeigth() + Metrics.LIFELINE_VT_MAGIN + Metrics.LIFELINE_VB_MAGIN
+ Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getLifelineFontHeigth() * 2;
- if (forceEventOccurrenceSpacing >= 0)
+ }
+ if (forceEventOccurrenceSpacing >= 0) {
Metrics.setForcedEventSpacing(forceEventOccurrenceSpacing);
+ }
return verticalIndex * (Metrics.getMessagesSpacing() + Metrics.getMessageFontHeigth()) + Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getFrameFontHeigth() + Metrics.LIFELINE_VT_MAGIN + Metrics.LIFELINE_VB_MAGIN
+ Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getLifelineFontHeigth() * 2;
}
* @param list the list to search in
* @param fromIndex list browsing starting point
* @return the graph node containing the point given in parameter, null otherwise
+ *
+ * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getNodeFromListAt(int, int, java.util.List, int)
*/
@Override
protected GraphNode getNodeFromListAt(int x, int y, List<GraphNode> list, int fromIndex) {
- if (list == null)
+ if (list == null) {
return null;
+ }
for (int i = fromIndex; i < list.size(); i++) {
GraphNode node = (GraphNode) list.get(i);
// only lifeline list is x ordered
// Stop browsing the list if the node is outside the visible area
// all others nodes will be not visible
- if ((node instanceof Lifeline) && (node.getX() > visibleAreaX + visibleAreaWidth))
+ if ((node instanceof Lifeline) && (node.getX() > visibleAreaX + visibleAreaWidth)) {
break;
+ }
if (node.getHeight() < 0) {
- if (node.getY() + node.getHeight() > visibleAreaY + visibleAreaHeight)
+ if (node.getY() + node.getHeight() > visibleAreaY + visibleAreaHeight) {
break;
+ }
} else {
- if (node.getY() > visibleAreaY + visibleAreaHeight)
+ if (node.getY() > visibleAreaY + visibleAreaHeight) {
break;
+ }
}
- if (node.contains(x, y))
+ if (node.contains(x, y)) {
return node;
+ }
}
return null;
}
int nameHeight = Metrics.getFrameFontHeigth() + +Metrics.FRAME_NAME_H_MARGIN * 2;
// Draw the frame name area
- if (nameWidth > w)
+ if (nameWidth > w) {
nameWidth = w;
+ }
int[] points = { x, y, x + nameWidth, y, x + nameWidth, y - 11 + nameHeight, x - 11 + nameWidth, y + nameHeight, x, y + nameHeight, x, y + nameHeight };
context.fillPolygon(points);
context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_FRAME));
}
- /**
- * Draws the Frame on the given context.<br>
- * This method start width GraphNodes ordering if needed.<br>
- * After, depending on the visible area, only visible GraphNodes are drawn.<br>
- *
- * @param context the context to draw to
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC)
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
*/
@Override
public void draw(IGC context) {
visibleAreaX = context.getContentsX();
visibleAreaY = context.getContentsY();
- if (forceEventOccurrenceSpacing >= 0)
+ if (forceEventOccurrenceSpacing >= 0) {
Metrics.setForcedEventSpacing(forceEventOccurrenceSpacing);
- else
+ } else {
Metrics.setForcedEventSpacing(-1);
- if (userPref == null)
+ }
+ if (userPref == null) {
return;
+ }
super.drawChildenNodes(context);
}
+ /**
+ * Sets the sequence diagram preferences.
+ *
+ * @param pref the preferences to set.
+ */
public static void setUserPref(ISDPreferences pref) {
userPref = pref;
}
+ /**
+ * Returns the sequence diagram preferences.
+ * @return the sequence diagram preferences.
+ */
public static ISDPreferences getUserPref() {
return userPref;
}
+ /**
+ * Sets the event occurrence spacing (-1 for none)
+ *
+ * @param space A spacing to set.
+ */
public void forceEventOccurrenceSpacing(int space) {
forceEventOccurrenceSpacing = space;
}
return maxTime;
}
+ /**
+ * Computes the minimum and maximum time between consecutive messages within the frame.
+ */
protected void computeMaxMinTime() {
- if (!initSDMin)
+ if (!initSDMin) {
return;
+ }
List<SDTimeEvent> timeArray = buildTimeArray();
- if (timeArray == null)
+ if (timeArray == null) {
return;
+ }
for (int i = 0; i < timeArray.size(); i++) {
SDTimeEvent m = (SDTimeEvent) timeArray.get(i);
}
}
+ /**
+ * Returns the minimum time between consecutive messages.
+ *
+ * @return the minimum time between consecutive messages
+ */
public ITmfTimestamp getSDMinTime() {
computeMaxMinTime();
return minSDTime;
}
+ /**
+ * Returns the maximum time between consecutive messages.
+ *
+ * @return the maximum time between consecutive messages
+ */
public ITmfTimestamp getSDMaxTime() {
computeMaxMinTime();
return maxSDTime;
*/
protected void computeMinMax() {
List<SDTimeEvent> timeArray = buildTimeArray();
- if (timeArray == null)
+ if (timeArray == null) {
return;
+ }
for (int i = 0; i < timeArray.size() - 1; i++) {
SDTimeEvent m1 = (SDTimeEvent) timeArray.get(i);
SDTimeEvent m2 = (SDTimeEvent) timeArray.get(i + 1);
updateMinMax(m1, m2);
-
}
}
+ /**
+ * Updates the minimum and maximum time between consecutive message within the frame based on the given values.
+ *
+ * @param m1 A first SD time event.
+ * @param m2 A second SD time event.
+ */
protected void updateMinMax(SDTimeEvent m1, SDTimeEvent m2) {
ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime());
if (computeMinMax) {
}
}
+ /**
+ * Builds the time array based on the list of graph nodes.
+ *
+ * @return the time array else <code>null</code>.
+ */
protected List<SDTimeEvent> buildTimeArray() {
- if (!hasChilden)
+ if (!hasChilden) {
return null;
+ }
Iterator<String> it = fSort.keySet().iterator();
List<SDTimeEvent> timeArray = new ArrayList<SDTimeEvent>();