| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2005, 2012 IBM Corporation, Ericsson |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM - Initial API and implementation |
| 10 | * Bernd Hufmann - Updated for TMF |
| 11 | **********************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; |
| 14 | |
| 15 | /** |
| 16 | * This class contains the metrics used to layout a sequence diagram on a view The class method are mostly used in |
| 17 | * combination with the preferences |
| 18 | * |
| 19 | * @version 1.0 |
| 20 | * @author sveyrier |
| 21 | * |
| 22 | */ |
| 23 | public class Metrics { |
| 24 | // ------------------------------------------------------------------------ |
| 25 | // Constants |
| 26 | // ------------------------------------------------------------------------ |
| 27 | |
| 28 | /** |
| 29 | * Space between the Frame and the top of the View This also represent the space between the frame and the bottom of |
| 30 | * the View |
| 31 | */ |
| 32 | public static final int FRAME_H_MARGIN = 10; |
| 33 | /** |
| 34 | * Space between the Frame and the left of the View This also represent the space between the Frame and the right of |
| 35 | * the View |
| 36 | */ |
| 37 | public static final int FRAME_V_MARGIN = 10; |
| 38 | /** |
| 39 | * Space between the Lifelines and the right of the Frame |
| 40 | */ |
| 41 | public static final int LIFELINE_H_MAGIN = 23; |
| 42 | /** |
| 43 | * Space between the Lifelines and the bottom of the Frame |
| 44 | */ |
| 45 | public static final int LIFELINE_VB_MAGIN = 20; |
| 46 | /** |
| 47 | * Space between the Lifelines and the top of the Frame |
| 48 | */ |
| 49 | public static final int LIFELINE_VT_MAGIN = 30;// 18 |
| 50 | /** |
| 51 | * Vertical space between the lifeline name and the rectangle which contains that name This is only for the |
| 52 | * "always visible" lifeline name rectangle |
| 53 | */ |
| 54 | public static final int LIFELINE_HEARDER_TEXT_V_MARGIN = 4; |
| 55 | /** |
| 56 | * Vertical spacing between messages |
| 57 | */ |
| 58 | public static final int MESSAGES_SPACING = 30; |
| 59 | /** |
| 60 | * Vertical spacing between the message and its name |
| 61 | */ |
| 62 | public static final int MESSAGES_NAME_SPACING = 10; |
| 63 | /** |
| 64 | * Horizontal spacing between the Frame name and its containing rectangle |
| 65 | */ |
| 66 | public static final int FRAME_NAME_H_MARGIN = 4; |
| 67 | /** |
| 68 | * Vertical spacing between the Frame name and its containing rectangle |
| 69 | */ |
| 70 | public static final int FRAME_NAME_V_MARGIN = 8; |
| 71 | /** |
| 72 | * Horizontal spacing between the lifeline name and its containing rectangle |
| 73 | */ |
| 74 | public static final int LIFELINE_NAME_H_MARGIN = 14; |
| 75 | /** |
| 76 | * Vertical spacing between the lifeline name and its containing rectangle |
| 77 | */ |
| 78 | public static final int LIFELINE_NAME_V_MARGIN = 20; |
| 79 | /** |
| 80 | * Space between the rectangles which contain the Lifelines name |
| 81 | */ |
| 82 | public static final int LIFELINE_SPACING = 45; |
| 83 | /** |
| 84 | * The circle ray used to draw the circle which compose Found and Lost messages |
| 85 | */ |
| 86 | public static final int MESSAGE_CIRCLE_RAY = 5; |
| 87 | /** |
| 88 | * Execution occurrence vertical width |
| 89 | */ |
| 90 | public static final int EXECUTION_OCCURRENCE_WIDTH = 8; |
| 91 | /** |
| 92 | * The square width which contains the Stop representation (a cross) |
| 93 | */ |
| 94 | public static final int STOP_WIDTH = 20; |
| 95 | /** |
| 96 | * The internal message width. |
| 97 | */ |
| 98 | public static final int INTERNAL_MESSAGE_WIDTH = 20; |
| 99 | /** |
| 100 | * The internal sychrounous message height. |
| 101 | */ |
| 102 | public static final int SYNC_INTERNAL_MESSAGE_HEIGHT = 10; |
| 103 | /** |
| 104 | * Line width used when drawing selected GraphNode |
| 105 | */ |
| 106 | public static final int SELECTION_LINE_WIDTH = 5; |
| 107 | /** |
| 108 | * Line width used when drawing non selected GraphNode |
| 109 | */ |
| 110 | public static final int NORMAL_LINE_WIDTH = 1; |
| 111 | /** |
| 112 | * The internal vertical message margin |
| 113 | */ |
| 114 | public static final int INTERNAL_MESSAGE_V_MARGIN = 10; |
| 115 | |
| 116 | /** |
| 117 | * Used to sample the diagram. When the lifeline spacing is smaller than this constant when zooming out then less |
| 118 | * lifelines are displayed to avoid lifelines overlapping and mainly saving some execution time |
| 119 | */ |
| 120 | public static final int LIFELINE_SIGNIFICANT_HSPACING = 10; |
| 121 | /** |
| 122 | * Used to sample the diagram. When the message spacing is smaller than this constant when zooming out then less |
| 123 | * message are displayed to avoid message overlapping and mainly saving some execution time |
| 124 | */ |
| 125 | public static final int MESSAGE_SIGNIFICANT_VSPACING = 1; |
| 126 | /** |
| 127 | * Message selection tolerance. Used for internal syncMessages only |
| 128 | */ |
| 129 | public static final int MESSAGE_SELECTION_TOLERANCE = 30; |
| 130 | /** |
| 131 | * The focus drawing margin. |
| 132 | */ |
| 133 | public static final int FOCUS_DRAWING_MARGIN = 10; |
| 134 | |
| 135 | // ------------------------------------------------------------------------ |
| 136 | // Attributes |
| 137 | // ------------------------------------------------------------------------ |
| 138 | /** |
| 139 | * The lifeline font height |
| 140 | */ |
| 141 | private static int fLifelineFontHeight = 0; |
| 142 | /** |
| 143 | * The message font height |
| 144 | */ |
| 145 | private static int fMessageFontHeight = 0; |
| 146 | /** |
| 147 | * The frame font height |
| 148 | */ |
| 149 | private static int fFrameFontHeight = 0; |
| 150 | /** |
| 151 | * The lifeline header font height |
| 152 | */ |
| 153 | private static int fLifelineHeaderFontHeight = 0; |
| 154 | /** |
| 155 | * The lifeline font widht |
| 156 | */ |
| 157 | private static int fLifelineFontWidth = 0; |
| 158 | /** |
| 159 | * The lifeline width |
| 160 | */ |
| 161 | private static int fLifeLineWidth = 119; |
| 162 | /** |
| 163 | * The (forced) event spacing |
| 164 | */ |
| 165 | private static int fForcedEventSpacing = -1; |
| 166 | |
| 167 | // ------------------------------------------------------------------------ |
| 168 | // Constructor |
| 169 | // ------------------------------------------------------------------------ |
| 170 | /** |
| 171 | * Constructor |
| 172 | * |
| 173 | * Hide private constructor |
| 174 | */ |
| 175 | private Metrics() { |
| 176 | } |
| 177 | |
| 178 | // ------------------------------------------------------------------------ |
| 179 | // Methods |
| 180 | // ------------------------------------------------------------------------ |
| 181 | |
| 182 | /** |
| 183 | * Set the character height used to draw the lifeline name |
| 184 | * |
| 185 | * @param height the character height |
| 186 | */ |
| 187 | static public void setLifelineFontHeight(int height) { |
| 188 | fLifelineFontHeight = height; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Set the character width used to draw the lifeline name |
| 193 | * |
| 194 | * @param width the character width |
| 195 | */ |
| 196 | static public void setLifelineFontWidth(int width) { |
| 197 | fLifelineFontWidth = width; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Set the character height used to draw the message name |
| 202 | * |
| 203 | * @param fontHeight the character height |
| 204 | */ |
| 205 | static public void setMessageFontHeight(int fontHeight) { |
| 206 | fMessageFontHeight = fontHeight; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Returns the character height used to draw the lifeline name |
| 211 | * |
| 212 | * @return the character height |
| 213 | */ |
| 214 | static public int getFrameFontHeigth() { |
| 215 | return fFrameFontHeight; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Set the character height used to draw the message name |
| 220 | * |
| 221 | * @param fontHeight the character height |
| 222 | */ |
| 223 | static public void setFrameFontHeight(int fontHeight) { |
| 224 | fFrameFontHeight = fontHeight; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Returns the character height used to draw the lifeline name |
| 229 | * |
| 230 | * @return the character height |
| 231 | */ |
| 232 | static public int getLifelineHeaderFontHeigth() { |
| 233 | return fLifelineHeaderFontHeight; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Set the character height used to draw the message name |
| 238 | * |
| 239 | * @param fontHeight the character height |
| 240 | */ |
| 241 | static public void setLifelineHeaderFontHeight(int fontHeight) { |
| 242 | fLifelineHeaderFontHeight = fontHeight; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Returns the character height used to draw the lifeline name |
| 247 | * |
| 248 | * @return the character height |
| 249 | */ |
| 250 | static public int getLifelineFontHeigth() { |
| 251 | return fLifelineFontHeight; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Returns the character height used to draw the message name |
| 256 | * |
| 257 | * @return the character height |
| 258 | */ |
| 259 | static public int getMessageFontHeigth() { |
| 260 | if (fForcedEventSpacing >= 0) { |
| 261 | return 0; |
| 262 | } |
| 263 | return fMessageFontHeight; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * This is the vertical space used by a Lifeline (mostly the rectangle which contain its name) |
| 268 | * |
| 269 | * @return the vertical space used by a Lifeline |
| 270 | */ |
| 271 | static public int getLifelineWidth() { |
| 272 | return fLifeLineWidth; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Set the vertical space used by a Lifeline (mostly the rectangle which contain its name) |
| 277 | * |
| 278 | * @param value the vertical space |
| 279 | */ |
| 280 | static public void setLifelineWidth(int value) { |
| 281 | fLifeLineWidth = value; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Returns the swimming lane width |
| 286 | * |
| 287 | * @return the swimming lane width |
| 288 | */ |
| 289 | static public int swimmingLaneWidth() { |
| 290 | return getLifelineWidth() + LIFELINE_SPACING; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Returns the character width used to draw the Lifelines name |
| 295 | * |
| 296 | * @return the average character width |
| 297 | */ |
| 298 | static public int getAverageCharWidth() { |
| 299 | return fLifelineFontWidth; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Returns the message spacing. |
| 304 | * |
| 305 | * @return the message spacing |
| 306 | */ |
| 307 | static public int getMessagesSpacing() { |
| 308 | if (fForcedEventSpacing >= 0) { |
| 309 | return fForcedEventSpacing; |
| 310 | } |
| 311 | return MESSAGES_SPACING; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Sets the forced event spacing value . |
| 316 | * |
| 317 | * @param eventSpacing |
| 318 | * The spacing value |
| 319 | */ |
| 320 | static public void setForcedEventSpacing(int eventSpacing) { |
| 321 | fForcedEventSpacing = eventSpacing; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Gets the forced event spacing value. |
| 326 | * |
| 327 | * @return forcedEventSpacing |
| 328 | */ |
| 329 | static public int getForcedEventSpacing() { |
| 330 | return fForcedEventSpacing; |
| 331 | } |
| 332 | } |