tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / TimeCompressionBar.java
index ed4555bde442b082db85f9e3b4e08551b28afcf7..5e2eba1d355edc625eb3167e84d64884536dadaa 100755 (executable)
@@ -1,28 +1,24 @@
 /**********************************************************************
- * 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;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessageReturn;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage;
@@ -64,10 +60,9 @@ import org.eclipse.swt.widgets.Display;
  * <p>
  * The time compression bar implementation.
  * </p>
- * 
+ *
  * @version 1.0
  * @author sveyrier
- * 
  */
 public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
@@ -104,7 +99,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
      */
     protected DrawableToolTip fTooltip = null;
     /**
-     *  Array of colors for displaying wight of time deltas. 
+     *  Array of colors for displaying wight of time deltas.
      */
     protected ColorImpl[] fColors;
     /**
@@ -116,7 +111,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
      */
     protected int fFocusedWidget = -1;
     /**
-     * The sequence diagram view reference. 
+     * The sequence diagram view reference.
      */
     protected SDView view = null;
     /**
@@ -132,15 +127,15 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
      */
     protected int fLifelineNumEvents = 0;
     /**
-     * The Current color of range to display. 
+     * The Current color of range to display.
      */
     protected IColor fLifelineColor = null;
     /**
-     *  The next graph node y coordinate. 
+     *  The next graph node y coordinate.
      */
     protected int fNextNodeY = 0;
     /**
-     *  The previous graph node y coordinate. 
+     *  The previous graph node y coordinate.
      */
     protected int fPrevNodeY = 0;
 
@@ -149,7 +144,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
     // ------------------------------------------------------------------------
     /**
      * Standard constructor
-     * 
+     *
      * @param parent The parent composite
      * @param s The style bits
      */
@@ -242,35 +237,9 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
             }
         });
 
-        getViewControl().addTraverseListener(new TraverseListener() {
-
-            /*
-             * (non-Javadoc)
-             * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
-             */
-            @Override
-            public void keyTraversed(TraverseEvent e) {
-                if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
-                    e.doit = true;
-                }
-            }
-
-        });
-
-        addTraverseListener(new TraverseListener() {
+        getViewControl().addTraverseListener(new LocalTraverseListener());
 
-            /*
-             * (non-Javadoc)
-             * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
-             */
-            @Override
-            public void keyTraversed(TraverseEvent e) {
-                if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
-                    e.doit = true;
-                }
-            }
-
-        });
+        addTraverseListener(new LocalTraverseListener());
 
         getViewControl().addFocusListener(new FocusListener() {
 
@@ -300,7 +269,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
     /**
      * Sets the focus widget
-     * 
+     *
      * @param newFocusShape widget reference to set
      */
     void setFocus(int newFocusShape) {
@@ -314,7 +283,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
     /**
      * Sets the current frame.
-     * 
+     *
      * @param theFrame The frame to set
      */
     public void setFrame(Frame theFrame) {
@@ -346,7 +315,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         for (int i = firstVisible; i < fFrame.syncMessageCount(); i = i + messageArraysStep) {
             SyncMessage m = fFrame.getSyncMessage(i);
             if (m.hasTimeInfo()) {
-                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getEventOccurrence(), (ITimeRange) m);
+                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getEventOccurrence(), m);
                 fNodeList.add(t);
                 if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) {
                     break;
@@ -361,7 +330,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         for (int i = firstVisible; i < fFrame.syncMessageReturnCount(); i = i + messageArraysStep) {
             SyncMessage m = fFrame.getSyncMessageReturn(i);
             if (m.hasTimeInfo()) {
-                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getEventOccurrence(), (ITimeRange) m);
+                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getEventOccurrence(), m);
                 fNodeList.add(t);
                 if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) {
                     break;
@@ -376,9 +345,9 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         for (int i = firstVisible; i < fFrame.asyncMessageCount(); i = i + messageArraysStep) {
             AsyncMessage m = fFrame.getAsyncMessage(i);
             if (m.hasTimeInfo()) {
-                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getStartOccurrence(), (ITimeRange) m);
+                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getStartOccurrence(), m);
                 fNodeList.add(t);
-                t = new SDTimeEvent(m.getEndTime(), m.getEndOccurrence(), (ITimeRange) m);
+                t = new SDTimeEvent(m.getEndTime(), m.getEndOccurrence(), m);
                 fNodeList.add(t);
                 if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) {
                     break;
@@ -393,9 +362,9 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         for (int i = firstVisible; i < fFrame.asyncMessageReturnCount(); i = i + messageArraysStep) {
             AsyncMessageReturn m = fFrame.getAsyncMessageReturn(i);
             if (m.hasTimeInfo()) {
-                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getStartOccurrence(), (ITimeRange) m);
+                SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getStartOccurrence(), m);
                 fNodeList.add(t);
-                t = new SDTimeEvent(m.getEndTime(), m.getEndOccurrence(), (ITimeRange) m);
+                t = new SDTimeEvent(m.getEndTime(), m.getEndOccurrence(), m);
                 fNodeList.add(t);
                 if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) {
                     break;
@@ -417,12 +386,12 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         try {
             dbuffer = new Image(getDisplay(), getClientArea().width, getClientArea().height);
         } catch (Exception e) {
-            TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR,TmfUiPlugin.PLUGIN_ID, "Error creating image", e)); //$NON-NLS-1$
+            Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$
         }
         gcim = new GC(dbuffer);
         for (int i = 0; i < fNodeList.size() - 1; i++) {
-            SDTimeEvent m1 = (SDTimeEvent) fNodeList.get(i);
-            SDTimeEvent m2 = (SDTimeEvent) fNodeList.get(i + 1);
+            SDTimeEvent m1 = fNodeList.get(i);
+            SDTimeEvent m2 = fNodeList.get(i + 1);
 
             if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) {
                 BaseMessage mes1 = (BaseMessage) m1.getGraphNode();
@@ -439,7 +408,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
             ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()).getDelta(fMinTime);
             long absDelta = Math.abs(delta.getValue());
-            
+
             ColorImpl color;
             if (gr != 0) {
                 int colIndex = Math.round((float) (absDelta / gr));
@@ -501,7 +470,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         try {
             gc.drawImage(dbuffer, 0, 0, getClientArea().width, getClientArea().height, 0, 0, getClientArea().width, getClientArea().height);
         } catch (Exception e) {
-            TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR,TmfUiPlugin.PLUGIN_ID, "Error drawing image", e)); //$NON-NLS-1$
+            Activator.getDefault().logError("Error drawing image", e); //$NON-NLS-1$
         }
         gcim.dispose();
         if (dbuffer != null) {
@@ -512,19 +481,19 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
     /**
      * Checks for focus of children.
-     * 
-     * @param children Control to check
+     *
+     * @param children
+     *            Control to check
      * @return true if child is on focus else false
      */
-    protected boolean checkFocusOnChilds(Control childs) {
-        if (childs instanceof Composite) {
-            Control[] child = ((Composite) childs).getChildren();
+    protected boolean checkFocusOnChilds(Control children) {
+        if (children instanceof Composite) {
+            Control[] child = ((Composite) children).getChildren();
             for (int i = 0; i < child.length; i++) {
                 if (child[i].isFocusControl()) {
                     return true;
-                } else {
-                    checkFocusOnChilds(child[i]);
                 }
+                checkFocusOnChilds(child[i]);
             }
         }
         return false;
@@ -540,9 +509,8 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         for (int i = 0; i < child.length; i++) {
             if (child[i].isFocusControl()) {
                 return true;
-            } else {
-                checkFocusOnChilds(child[i]);
             }
+            checkFocusOnChilds(child[i]);
         }
         return false;
     }
@@ -580,8 +548,8 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         if (fFrame != null) {
             setFocus(0);
             for (int i = 0; i < fNodeList.size() - 1; i++) {
-                SDTimeEvent m1 = (SDTimeEvent) fNodeList.get(i);
-                SDTimeEvent m2 = (SDTimeEvent) fNodeList.get(i + 1);
+                SDTimeEvent m1 = fNodeList.get(i);
+                SDTimeEvent m2 = fNodeList.get(i + 1);
 
                 if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) {
                     BaseMessage mes1 = (BaseMessage) m1.getGraphNode();
@@ -637,8 +605,9 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
      */
     @Override
     protected void contentsMouseExit(MouseEvent e) {
-        if (fTooltip != null)
+        if (fTooltip != null) {
             fTooltip.hideToolTip();
+        }
     }
 
     /*
@@ -653,16 +622,19 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
     }
 
     /**
-     * Force the time compression bar to highlight the event occurrences between the two given messages. The event
-     * occurrences are highlighted on the first message's end lifeline
-     * 
-     * @param mes1 the first message
-     * @param localMes2 the second message
+     * Force the time compression bar to highlight the event occurrences between
+     * the two given messages. The event occurrences are highlighted on the
+     * first message's end lifeline
+     *
+     * @param mes1
+     *            the first message
+     * @param mes2
+     *            the second message
      */
     public void highlightRegion(BaseMessage mes1, BaseMessage mes2) {
-        BaseMessage localMes1 = mes1; 
+        BaseMessage localMes1 = mes1;
         BaseMessage localMes2 = mes2;
-        
+
         if (fFrame == null) {
             return;
         }
@@ -744,7 +716,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
             colIndex = 0;
         }
         for (int j = 0; j < fListenerList.size(); j++) {
-            ITimeCompressionListener list = (ITimeCompressionListener) fListenerList.get(j);
+            ITimeCompressionListener list = fListenerList.get(j);
             if (localMes1.getEndLifeline() != null) {
                 list.deltaSelected(localMes1.getEndLifeline(), event1, event2 - event1, fColors[colIndex]);
             } else if (localMes2.getStartLifeline() != null) {
@@ -758,7 +730,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
     /**
      * Force the time compression bar to highlight the event occurrences between the two given messages. The event
      * occurrences are highlighted on the first message's end lifeline
-     * 
+     *
      * @param mes1 the first message
      * @param mes2 the second message
      */
@@ -781,7 +753,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
     /**
      * Sets the zoom value.
-     * 
+     *
      * @param value The zoom value to set.
      */
     public void setZoom(float value) {
@@ -791,7 +763,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
     /**
      * Adds a listener to the time compression listener list to be notified about selected deltas.
-     *  
+     *
      * @param listener The listener to add
      */
     public void addTimeCompressionListener(ITimeCompressionListener listener) {
@@ -802,7 +774,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
     /**
      * Removes a time compression listener.
-     * 
+     *
      * @param listener The listener to remove.
      */
     public void removeSelectionChangedListener(ITimeCompressionListener listener) {
@@ -850,8 +822,8 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         }
         if ((fFrame != null) && (fNextNodeY == 0)) {
             for (int i = 0; i < fNodeList.size() - 1 && i < 1; i++) {
-                SDTimeEvent m1 = (SDTimeEvent) fNodeList.get(i);
-                SDTimeEvent m2 = (SDTimeEvent) fNodeList.get(i + 1);
+                SDTimeEvent m1 = fNodeList.get(i);
+                SDTimeEvent m2 = fNodeList.get(i + 1);
                 if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) {
                     BaseMessage mes1 = (BaseMessage) m1.getGraphNode();
                     BaseMessage mes2 = (BaseMessage) m2.getGraphNode();
@@ -895,7 +867,7 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
 
         if (fLifeline != null) {
             for (int j = 0; j < fListenerList.size(); j++) {
-                ITimeCompressionListener list = (ITimeCompressionListener) fListenerList.get(j);
+                ITimeCompressionListener list = fListenerList.get(j);
                 list.deltaSelected(fLifeline, fLifelineStart, fLifelineNumEvents, fLifelineColor);
             }
         }
@@ -917,19 +889,10 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         super.keyPressedEvent(event);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyReleasedEvent(org.eclipse.swt.events.KeyEvent)
-     */
-    @Override
-    protected void keyReleasedEvent(KeyEvent event) {
-        super.keyReleasedEvent(event);
-    }
-
     /**
      * Selects the time delta for given delta y coordinate and direction.
-     * 
-     * @param dy The delta in y coordinate. 
+     *
+     * @param dy The delta in y coordinate.
      * @param direction 0 no direction, 1 = down, 2 = up
      */
     protected void selectTimeDelta(int dy, int direction) {
@@ -940,8 +903,8 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         boolean done = false;
         if (fFrame != null) {
             for (int i = 0; i < fNodeList.size() - 1; i++) {
-                SDTimeEvent m1 = (SDTimeEvent) fNodeList.get(i);
-                SDTimeEvent m2 = (SDTimeEvent) fNodeList.get(i + 1);
+                SDTimeEvent m1 = fNodeList.get(i);
+                SDTimeEvent m2 = fNodeList.get(i + 1);
                 if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) {
                     BaseMessage mes1 = (BaseMessage) m1.getGraphNode();
                     BaseMessage mes2 = (BaseMessage) m2.getGraphNode();
@@ -1041,22 +1004,21 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
                         }
                     }
                     for (int j = 0; j < fListenerList.size(); j++) {
-                        ITimeCompressionListener list = (ITimeCompressionListener) fListenerList.get(j);
+                        ITimeCompressionListener list = fListenerList.get(j);
                         list.deltaSelected(fLifeline, fLifelineStart, fLifelineNumEvents, fLifelineColor);
                     }
                     break;
-                } else {
-                    lastM1 = m1;
-                    lastM2 = m2;
-                    lastY1 = m1Y;
-                    lastY2 = m2Y;
                 }
+                lastM1 = m1;
+                lastM2 = m2;
+                lastY1 = m1Y;
+                lastY2 = m2Y;
             }
         }
     }
 
     /**
-     * Creates a fake tool tip. 
+     * Creates a fake tool tip.
      */
     protected void createFakeTooltip() {
         if (fTooltip == null) {
@@ -1066,8 +1028,8 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
         if (fFrame != null) {
             setFocus(0);
             for (int i = 0; i < fNodeList.size() - 1; i++) {
-                SDTimeEvent m1 = (SDTimeEvent) fNodeList.get(i);
-                SDTimeEvent m2 = (SDTimeEvent) fNodeList.get(i + 1);
+                SDTimeEvent m1 = fNodeList.get(i);
+                SDTimeEvent m2 = fNodeList.get(i + 1);
 
                 if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) {
                     BaseMessage mes1 = (BaseMessage) m1.getGraphNode();
@@ -1116,4 +1078,21 @@ public class TimeCompressionBar extends ScrollView implements DisposeListener {
             }
         }
     }
+
+    /**
+     * Traverse Listener implementation.
+     */
+    protected static class LocalTraverseListener implements TraverseListener {
+
+        /*
+         * (non-Javadoc)
+         * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
+         */
+        @Override
+        public void keyTraversed(TraverseEvent e) {
+            if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
+                e.doit = true;
+            }
+        }
+    }
 }
This page took 0.030105 seconds and 5 git commands to generate.