/**********************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * Copyright (c) 2011, 2012 Ericsson.
- *
+ * 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 org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
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;
/**
* The base UML2 syncMessages implementation.<br>
* representations (like asynchronous syncMessages) will be responsible to define the missing second eventOccurrence
* property.<br>
* <br>
- *
+ *
* @see Lifeline Lifeline for more event occurence details
* @version 1.0
* @author sveyrier
*/
public abstract class BaseMessage extends GraphNode {
-
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
/**
* The lifeline which send the message
*/
- protected Lifeline fStartLifeline = null;
+ private Lifeline fStartLifeline = null;
/**
* The lifeline which receive the message
*/
- protected Lifeline fEndLifeline = null;
+ private Lifeline fEndLifeline = null;
/**
- * The visiblitiy flag.
+ * The visiblitiy flag.
*/
- protected boolean fVisible = true;
+ private boolean fVisible = true;
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
- */
+
@Override
public int getX() {
// returns the exact x coordinate
return getX(false);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
- */
@Override
public int getY() {
/*
/*
* Regular message, both ends are attached to a lifeline
*/
- return fEndLifeline.getY() + fEndLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEndEventOccurrence;
+ return fEndLifeline.getY() + fEndLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getEndOccurrence();
- } else {
- /*
- * UML2 lost message kind
- */
- if (fStartLifeline != null) {
- return fStartLifeline.getY() + fStartLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEndEventOccurrence;
- }
+ }
+ /*
+ * UML2 lost message kind
+ */
+ if (fStartLifeline != null) {
+ return fStartLifeline.getY() + fStartLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getEndOccurrence();
+ }
- /*
- * UML2 found message kind
- */
- if (fEndLifeline != null) {
- return fEndLifeline.getY() + fEndLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEndEventOccurrence;
- }
+ /*
+ * UML2 found message kind
+ */
+ if (fEndLifeline != null) {
+ return fEndLifeline.getY() + fEndLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getEndOccurrence();
}
// return 0 by default
return 0;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
- */
@Override
public int getWidth() {
// Returns the exact width
return getWidth(false);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
- */
@Override
public int getHeight() {
return 0;
* <br>
* This method is typically used to faster execute none graphical operation like tooltip lookup.<br>
* <br>
- *
+ *
* @param quick true to get an approximative value<br>
* false to get the exact x value<br>
* @return the graph node x coordinate
activationWidth = -activationWidth;
}
- if (isMessageStartInActivation(fEndEventOccurrence)) {
+ if (isMessageStartInActivation(getEndOccurrence())) {
x = x + activationWidth;
}
* <br>
* This method is typically used to faster execute none graphical operation like tooltip lookup.<br>
* <br>
- *
+ *
* @param quick true to get an approximative value<br>
* false to get the exact x value
* @return the graph node width
activationWidth = -activationWidth;
}
- if (isMessageStartInActivation(fEndEventOccurrence)) {
+ if (isMessageStartInActivation(getEndOccurrence())) {
width = width - activationWidth;
}
- if (isMessageEndInActivation(fEndEventOccurrence)) {
+ if (isMessageEndInActivation(getEndOccurrence())) {
width = width - activationWidth;
}
return width;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
- */
@Override
public boolean isVisible(int x, int y, int width, int height) {
// ***Common*** syncMessages visibility
/**
* Sets the visibility value.
- *
+ *
* @param value The visibility to set.
*/
public void setVisible(boolean value) {
}
/**
- * @return the visibility value.
+ * @return the visibility value.
*/
public boolean isVisible() {
return fVisible;
/**
* Set the lifeline from which this message has been sent.
- *
+ *
* @param lifeline - the message sender
*/
public void setStartLifeline(Lifeline lifeline) {
/**
* Returns the lifeline from which this message has been sent.
- *
+ *
* @return the message sender
*/
public Lifeline getStartLifeline() {
/**
* Returns the lifeline which has received this message.
- *
+ *
* @return the message receiver
*/
public Lifeline getEndLifeline() {
/**
* Set the lifeline which has receive this message.
- *
+ *
* @param lifeline the message receiver
*/
public void setEndLifeline(Lifeline lifeline) {
/**
* Set the event occurrence when this message occurs.<br>
- *
+ *
* @param occurrence the event occurrence to assign to this message.<br>
* @see Lifeline Lifeline for more event occurence details
*/
protected void setEventOccurrence(int occurrence) {
- fEndEventOccurrence = occurrence;
+ setEndOccurrence(occurrence);
}
/**
* Returns the event occurence when is message occurs.<br>
- *
+ *
* @return the event occurrence assigned to this message.<br>
* @see Lifeline Lifeline for more event occurence details
*/
public int getEventOccurrence() {
- return fEndEventOccurrence;
+ return getEndOccurrence();
}
/**
* WARNING: this method will return a valid result only for execution occurrences which are visible in the View.<br>
* As consequence this method is only used for drawing purpose, especially to determine the exact message x
* coordinate and width.<br>
- *
+ *
* @see BaseMessage#getX(boolean)
* @param event the event occurrence to test
* @return true if occurs on a execution occurrence owned by the sending lifeine, false otherwise
int thisY = getY();
for (int i = 0; i < fStartLifeline.getExecutions().size(); i++) {
BasicExecutionOccurrence toDraw = (BasicExecutionOccurrence) fStartLifeline.getExecutions().get(i);
- if ((event >= toDraw.fStartEventOccurrence) && (event <= toDraw.fEndEventOccurrence)) {
+ if ((event >= toDraw.getStartOccurrence()) && (event <= toDraw.getEndOccurrence())) {
inActivation = true;
}
// if we are outside the visible area we stop right now
* WARNING: this method will return a valid result only for execution occurrences which are visible in the View.<br>
* As consequence this method is only used for drawing purpose, especially to determine the exact message x
* coordinate and width.<br>
- *
+ *
* @see BaseMessage#getX(boolean)
* @param event the event occurrence to test
* @return true if occurs on a execution occurrence owned by the receiving lifeline, false otherwise
// for drawing speed reason with only search on the visivle subset
for (int i = 0; i < fEndLifeline.getExecutions().size(); i++) {
BasicExecutionOccurrence toDraw = (BasicExecutionOccurrence) fEndLifeline.getExecutions().get(i);
- if ((event >= toDraw.fStartEventOccurrence) && (event <= toDraw.fEndEventOccurrence)) {
+ if ((event >= toDraw.getStartOccurrence()) && (event <= toDraw.getEndOccurrence())) {
inActivation = true;
}
// if we are outside the visible area we stop right now
return inActivation;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
- */
@Override
public boolean contains(int xValue, int yValue) {
int x = getX();
* rectangle width is negative.
*/
if (getName().length() * Metrics.getAverageCharWidth() > Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2 + -Metrics.INTERNAL_MESSAGE_WIDTH) {
- if (Frame.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH + 10, y, Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2 + -Metrics.INTERNAL_MESSAGE_WIDTH, Metrics.getMessageFontHeigth(), xValue, yValue)) {
+ if (GraphNode.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH + 10, y, Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2 + -Metrics.INTERNAL_MESSAGE_WIDTH, Metrics.getMessageFontHeigth(), xValue, yValue)) {
return true;
}
} else {
- if (Frame.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH + 10, y, getName().length() * Metrics.getAverageCharWidth(), Metrics.getMessageFontHeigth(), xValue, yValue)) {
+ if (GraphNode.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH + 10, y, getName().length() * Metrics.getAverageCharWidth(), Metrics.getMessageFontHeigth(), xValue, yValue)) {
return true;
}
}
// Test if the point is in part 1 of the self message
// see: "private void drawMessage (NGC context)" method for self message drawing schema
- if (Frame.contains(x, y - Metrics.MESSAGE_SELECTION_TOLERANCE / 2, Metrics.INTERNAL_MESSAGE_WIDTH / 2, Metrics.MESSAGE_SELECTION_TOLERANCE, xValue, yValue)) {
+ if (GraphNode.contains(x, y - Metrics.MESSAGE_SELECTION_TOLERANCE / 2, Metrics.INTERNAL_MESSAGE_WIDTH / 2, Metrics.MESSAGE_SELECTION_TOLERANCE, xValue, yValue)) {
return true;
}
// Test if the point is in part 3 of the self message
- if (Frame.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH - Metrics.MESSAGE_SELECTION_TOLERANCE / 2, y, Metrics.MESSAGE_SELECTION_TOLERANCE, height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, xValue, yValue)) {
+ if (GraphNode.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH - Metrics.MESSAGE_SELECTION_TOLERANCE / 2, y, Metrics.MESSAGE_SELECTION_TOLERANCE, height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, xValue, yValue)) {
return true;
}
// Test if the point is in part 5 of the self message
- if (Frame.contains(x, y + height - Metrics.MESSAGE_SELECTION_TOLERANCE / 2 + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, Metrics.INTERNAL_MESSAGE_WIDTH / 2, Metrics.MESSAGE_SELECTION_TOLERANCE, xValue, yValue)) {
+ if (GraphNode.contains(x, y + height - Metrics.MESSAGE_SELECTION_TOLERANCE / 2 + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, Metrics.INTERNAL_MESSAGE_WIDTH / 2, Metrics.MESSAGE_SELECTION_TOLERANCE, xValue, yValue)) {
return true;
}
// false otherwise
return false;
}
- if (Frame.contains(x, y - tempHeight, width, tempHeight, xValue, yValue)) {
+ if (GraphNode.contains(x, y - tempHeight, width, tempHeight, xValue, yValue)) {
return true;
}
// false otherwise
/**
* Method to draw the message using the graphical context.
- *
+ *
* @param context A graphical context to draw in.
*/
protected void drawMessage(IGC context) {
- int fX, fY, fW, fH;
- fX = fY = fW = fH = 0;
+ int fX = 0;
+ int fY = 0;
+ int fW = 0;
+ int fH = 0;
- // temporay store the coordinates to avoid more methods calls
+ // temporary store the coordinates to avoid more methods calls
int x = getX();
int y = getY();
int width = getWidth();
int height = getHeight();
+ ISDPreferences pref = SDViewPref.getInstance();
+
// UML2 found message (always drawn from left to right)
// or UML2 lost message (always drawn from left to right)
if ((fStartLifeline == null || fEndLifeline == null) && fStartLifeline != fEndLifeline) {
// The label is truncated if it cannot fit between the two message end
// 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
IColor temp = context.getForeground();
- context.setForeground(Frame.getUserPref().getFontColor(fPrefId));
+ context.setForeground(pref.getFontColor(getColorPrefId()));
context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected());
context.setForeground(temp);
int margin = 0;
context.fillOval(x + width - ray, y + height - ray, ray * 2, ray * 2);
}
context.setBackground(storedColor);
- context.setForeground(Frame.getUserPref().getFontColor(fPrefId));
+ context.setForeground(pref.getFontColor(getColorPrefId()));
fX = x;
fY = y - yt.intValue();
fW = width;
// 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
// the space available for the text is sorter if are drawing internal message on the last lifeline
- context.setForeground(Frame.getUserPref().getFontColor(fPrefId));
+ context.setForeground(pref.getFontColor(getColorPrefId()));
if (fStartLifeline.getIndex() == fStartLifeline.getFrame().getHorizontalIndex()) {
context.drawTextTruncated(getName(), x + width + Metrics.INTERNAL_MESSAGE_V_MARGIN / 2, y, Metrics.swimmingLaneWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH + -Metrics.INTERNAL_MESSAGE_WIDTH, +Metrics.MESSAGES_NAME_SPACING
- Metrics.getMessageFontHeigth(), !isSelected());
// Draw the message label above the message and centered
// The label is truncated if it cannot fit between the two message end
// 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
- context.setForeground(Frame.getUserPref().getFontColor(fPrefId));
+ context.setForeground(pref.getFontColor(getColorPrefId()));
if (spaceBTWStartEnd > 0) {
context.drawTextTruncatedCentred(getName(), x, y + height / 2 - (2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth()), width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected());
} else {
}
}
}
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNodee#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
- */
+
@Override
public void draw(IGC context) {
if (!isVisible()) {
return;
}
+
// Draw it selected?*/
if (isSelected()) {
-
+ ISDPreferences pref = SDViewPref.getInstance();
/*
* 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);
drawMessage(context);
- context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
- context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
+ context.setBackground(pref.getBackGroundColorSelection());
+ context.setForeground(pref.getForeGroundColorSelection());
// Second drawing is done after
}
context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
/**
* Determine if two messages are identical. This default implementation considers that overlapping messages with
* same coordinates are identical.
- *
+ *
* @param message - the message to compare with
* @return true if identical false otherwise
- *
+ *
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isSameAs(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode)
*/
@Override
/**
* Method drawRot.
- *
+ *
* @param x A x coordinate
* @param y A y coordinate
* @param w A width
context.drawPolygon(points);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#drawFocus(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
- */
@Override
public void drawFocus(IGC context) {
- if ((fStartLifeline != fEndLifeline) && (fStartEventOccurrence == fEndEventOccurrence)) {
+
+ ISDPreferences pref = SDViewPref.getInstance();
+
+ if ((fStartLifeline != fEndLifeline) && (getStartOccurrence() == getEndOccurrence())) {
context.setLineStyle(context.getLineDotStyle());
context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
- context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
- context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
+ context.setBackground(pref.getBackGroundColorSelection());
+ context.setForeground(pref.getForeGroundColorSelection());
context.drawFocus(getX(), getY() - 3, getWidth(), getHeight() + 6);
- } else if ((fStartLifeline == fEndLifeline) && (fStartEventOccurrence == fEndEventOccurrence)) {
+ } else if ((fStartLifeline == fEndLifeline) && (getStartOccurrence() == getEndOccurrence())) {
context.drawFocus(getX(), getY() - 3, getWidth(), Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT + 6);
- } else if ((fStartLifeline != fEndLifeline) && (fStartEventOccurrence != fEndEventOccurrence)) {
+ } else if ((fStartLifeline != fEndLifeline) && (getStartOccurrence() != getEndOccurrence())) {
context.setLineStyle(context.getLineDotStyle());
context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
- context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE_HEADER));
- context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_LIFELINE_HEADER));
+ context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE_HEADER));
+ context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_LIFELINE_HEADER));
drawRot(getX(), getY() - 5, getWidth(), 10, context);
} else {
super.drawFocus(context);