From b83af2c3da542d3ba4b07f93292afeec9958863e Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Tue, 22 May 2012 10:04:38 -0400 Subject: [PATCH] Bug 378401: Implementation of time graph widget. --- .../test/stub/adaption/TsfImplProvider.java | 65 +- .../timegraph/test/stub/model/TraceImpl.java | 2 +- .../stub/model/TraceModelImplFactory.java | 2 +- .../test/stub/views/TsfTraceAnalysisView.java | 4 +- .../icons/elcl16/show_legend.gif | Bin 0 -> 200 bytes .../internal/tmf/ui/ITmfImageConstants.java | 9 +- .../linuxtools/internal/tmf/ui/Messages.java | 17 + .../internal/tmf/ui/messages.properties | 19 + .../tmf/ui/views/colors/ColorsView.java | 843 +++++++++--------- .../tmf/ui/views/colors/TickColorDialog.java | 163 ++-- .../timechart/TimeChartAnalysisEntry.java | 2 +- .../timechart/TimeChartAnalysisProvider.java | 137 +-- .../ITimeGraphPresentationProvider.java | 121 +++ .../widgets/timegraph/ITimeGraphProvider.java | 109 --- .../tmf/ui/widgets/timegraph/StateItem.java | 105 +++ .../ui/widgets/timegraph/TimeGraphCombo.java | 49 +- .../TimeGraphPresentationProvider.java | 172 ++++ .../widgets/timegraph/TimeGraphProvider.java | 223 ----- .../ui/widgets/timegraph/TimeGraphViewer.java | 246 +++-- .../timegraph/dialogs/TimeGraphLegend.java | 152 +--- .../timegraph/model/ITimeGraphEntry.java | 6 +- .../widgets/TimeGraphBaseControl.java | 2 +- .../widgets/TimeGraphColorScheme.java | 12 - .../timegraph/widgets/TimeGraphControl.java | 518 +++++------ .../timegraph/widgets/TimeGraphItem.java | 1 + .../timegraph/widgets/TimeGraphScale.java | 26 +- .../widgets/TimeGraphTooltipHandler.java | 56 +- .../ui/widgets/timegraph/widgets/Utils.java | 66 +- 28 files changed, 1619 insertions(+), 1508 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/icons/elcl16/show_legend.gif create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/StateItem.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java delete mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/adaption/TsfImplProvider.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/adaption/TsfImplProvider.java index b470f68057..6580d88d4e 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/adaption/TsfImplProvider.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/adaption/TsfImplProvider.java @@ -14,76 +14,21 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.adaption; import java.util.HashMap; import java.util.Map; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.EventImpl; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.TraceImpl; @SuppressWarnings("nls") -public class TsfImplProvider extends TimeGraphProvider { +public class TsfImplProvider extends TimeGraphPresentationProvider { // ======================================================================== // Methods // ======================================================================== @Override - public StateColor getEventColor(ITimeEvent event) { - if (event instanceof EventImpl) { - EventImpl devent = (EventImpl) event; - switch (devent.getType()) { - case ALARM: - return StateColor.DARK_GREEN; - case ERROR: - return StateColor.DARK_YELLOW; - case EVENT: - return StateColor.MAGENTA3; - case INFORMATION: - return StateColor.PURPLE1; - case TIMEADJUSTMENT: - return StateColor.PINK1; - case WARNING: - return StateColor.AQUAMARINE; - case INFO1: - return StateColor.RED; - case INFO2: - return StateColor.GREEN; - case INFO3: - return StateColor.DARK_BLUE; - case INFO4: - return StateColor.GOLD; - case INFO5: - return StateColor.ORANGE; - case INFO6: - return StateColor.GRAY; - case INFO7: - return StateColor.LIGHT_BLUE; - case INFO8: - return StateColor.CADET_BLUE; - case INFO9: - return StateColor.OLIVE; - } - } - return StateColor.BLACK; - } - - @Override - public String getStateName(StateColor color) { - switch (color) { - case GOLD: - return "ALARM"; - case RED: - return "ERROR"; - case DARK_BLUE: - return "EVENT"; - case GREEN: - return "INFORMATION"; - case GRAY: - return "TIME ADJUSTMENT DKDKDKDKL"; - case ORANGE: - return "WARNING"; - default: - return "UNKNOWN"; - } + public int getEventTableIndex(ITimeEvent event) { + return 0; } @Override @@ -98,7 +43,7 @@ public class TsfImplProvider extends TimeGraphProvider { } @Override - public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { + public String getEventName(ITimeEvent event) { String name = "Unknown"; if (event instanceof EventImpl) { EventImpl devent = (EventImpl) event; diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceImpl.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceImpl.java index 2f2b5486cd..5e40b43344 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceImpl.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceImpl.java @@ -74,7 +74,7 @@ public class TraceImpl implements ITimeGraphEntry { } @Override - public long getStopTime() { + public long getEndTime() { return stopTime; } diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java index 60e5464479..1d296e0428 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/model/TraceModelImplFactory.java @@ -72,7 +72,7 @@ public class TraceModelImplFactory { Long eventTime; int numEvents = 5000; long sTime = trace.getStartTime(); - long eTime = trace.getStopTime(); + long eTime = trace.getEndTime(); long duration = (long) ((eTime - sTime)/numEvents); for (int i = 0; i < numEvents; i++) { eventTime = sTime + (i * duration); diff --git a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java index 87f0261730..09635ea480 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/test/stub/views/TsfTraceAnalysisView.java @@ -425,7 +425,7 @@ public class TsfTraceAnalysisView extends ViewPart implements public void run() { TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { - inFocusViewer.selectNextTrace(); + inFocusViewer.selectNextItem(); } } }; @@ -438,7 +438,7 @@ public class TsfTraceAnalysisView extends ViewPart implements public void run() { TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); if (inFocusViewer != null) { - inFocusViewer.selectPrevTrace(); + inFocusViewer.selectPrevItem(); } } }; diff --git a/org.eclipse.linuxtools.tmf.ui/icons/elcl16/show_legend.gif b/org.eclipse.linuxtools.tmf.ui/icons/elcl16/show_legend.gif new file mode 100644 index 0000000000000000000000000000000000000000..f40ce6b1796b2283b981d46894f0861edefe3401 GIT binary patch literal 200 zcmZ?wbhEHb6krfwI3mrk<-~^v*>UDG5-cnCt~j^-eRW=N?u_b*JFh?fGHdt!qK=Ij z^((6<>};5_r>K2nc;W2$ibdhQCo<|+#g{K^n7X%N%HEnCweRLl4lkG!U%oiJaL)h# z{~3^g;!hSv1_o&c9grBvP6k%j2WovOne)_z6fbY>*nTqMJ5`9|r%|AuJ=!5S=W uiw-^AVVI$|&ABxtg{j^{#L?jdmk!fSW~D*{jU~C|#a~nJe+cGaum%9=Hd5ID literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/ITmfImageConstants.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/ITmfImageConstants.java index a197763d34..8b907fabf8 100755 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/ITmfImageConstants.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/ITmfImageConstants.java @@ -31,7 +31,14 @@ public interface ITmfImageConstants { public static final String IMG_UI_SEARCH_MATCH = ICONS_PATH + "elcl16/search_match.gif"; public static final String IMG_UI_FIRST_PAGE = ICONS_PATH + "elcl16/backward_nav.gif"; public static final String IMG_UI_LAST_PAGE = ICONS_PATH + "elcl16/forward_nav.gif"; - + public static final String IMG_UI_SHOW_LEGEND = ICONS_PATH + "elcl16/show_legend.gif"; + public static final String IMG_UI_NEXT_EVENT = ICONS_PATH + "elcl16/next_event.gif"; + public static final String IMG_UI_PREV_EVENT = ICONS_PATH + "elcl16/prev_event.gif"; +// public static final String IMG_UI_NEXT_ITEM = ICONS_PATH + "elcl16/next_item.gif"; +// public static final String IMG_UI_PREV_ITEM = ICONS_PATH + "elcl16/prev_item.gif"; + public static final String IMG_UI_NEXT_ITEM = IMG_UI_NEXT_PAGE; + public static final String IMG_UI_PREV_ITEM = IMG_UI_PREV_PAGE; + /* eview16 */ public static final String IMG_UI_SEQ_DIAGRAM_OBJ = ICONS_PATH + "eview16/sequencediagram_view.gif"; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java index 1e752ca2dd..1db6b50f57 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java @@ -93,6 +93,23 @@ public class Messages extends NLS { public static String TmfTimeTipHandler_TRACE_STATE; public static String TmfTimeTipHandler_TRACE_STOP_TIME; + public static String TmfTimeGraphViewer_ResetScaleActionNameText; + public static String TmfTimeGraphViewer_ResetScaleActionToolTipText; + public static String TmfTimeGraphViewer_LegendActionNameText; + public static String TmfTimeGraphViewer_LegendActionToolTipText; + public static String TmfTimeGraphViewer_NextEventActionNameText; + public static String TmfTimeGraphViewer_NextEventActionToolTipText; + public static String TmfTimeGraphViewer_PreviousEventActionNameText; + public static String TmfTimeGraphViewer_PreviousEventActionToolTipText; + public static String TmfTimeGraphViewer_NextItemActionNameText; + public static String TmfTimeGraphViewer_NextItemActionToolTipText; + public static String TmfTimeGraphViewer_PreviousItemActionNameText; + public static String TmfTimeGraphViewer_PreviousItemActionToolTipText; + public static String TmfTimeGraphViewer_ZoomInActionNameText; + public static String TmfTimeGraphViewer_ZoomInActionToolTipText; + public static String TmfTimeGraphViewer_ZoomOutActionNameText; + public static String TmfTimeGraphViewer_ZoomOutActionToolTipText; + public static String ColorsView_AddActionToolTipText; public static String ColorsView_BackgroundButtonText; public static String ColorsView_BackgroundDialogText; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties index bc7467a02d..c766c0606a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties @@ -91,6 +91,25 @@ TmfTimeTipHandler_TRACE_START_TIME=Start Time TmfTimeTipHandler_TRACE_STATE=State TmfTimeTipHandler_TRACE_STOP_TIME=Stop Time + +TmfTimeGraphViewer_ResetScaleActionNameText=Reset +TmfTimeGraphViewer_ResetScaleActionToolTipText=Reset the Time Scale to Default +TmfTimeGraphViewer_LegendActionNameText=Legend +TmfTimeGraphViewer_LegendActionToolTipText=Show Legend +TmfTimeGraphViewer_NextEventActionNameText=Next Event +TmfTimeGraphViewer_NextEventActionToolTipText=Select Next Event +TmfTimeGraphViewer_PreviousEventActionNameText=Previous Event +TmfTimeGraphViewer_PreviousEventActionToolTipText=Select Previous Event +TmfTimeGraphViewer_NextItemActionNameText=Next Item +TmfTimeGraphViewer_NextItemActionToolTipText=Select Next Item +TmfTimeGraphViewer_PreviousItemActionNameText=Previous Item +TmfTimeGraphViewer_PreviousItemActionToolTipText=Select Previous Item +TmfTimeGraphViewer_ZoomInActionNameText=Zoom In +TmfTimeGraphViewer_ZoomInActionToolTipText=Zoom In +TmfTimeGraphViewer_ZoomOutActionNameText=Zoom Out +TmfTimeGraphViewer_ZoomOutActionToolTipText=Zoom Out + + # org.eclipse.linuxtools.tmf.ui.views.colors ColorsView_AddActionToolTipText=Insert new color setting ColorsView_BackgroundButtonText=BG diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java index e1ac645bd2..1592de784a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java @@ -15,7 +15,6 @@ package org.eclipse.linuxtools.tmf.ui.views.colors; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; @@ -27,10 +26,6 @@ import org.eclipse.linuxtools.internal.tmf.ui.Messages; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; import org.eclipse.linuxtools.tmf.ui.views.TmfView; import org.eclipse.linuxtools.tmf.ui.views.filter.FilterDialog; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; @@ -61,7 +56,7 @@ import org.eclipse.ui.IActionBars; public class ColorsView extends TmfView { - public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.colors"; //$NON-NLS-1$ + public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.colors"; //$NON-NLS-1$ private static final Image ADD_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$ private static final Image DELETE_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$ @@ -69,50 +64,29 @@ public class ColorsView extends TmfView { private static final Image MOVE_DOWN_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$ private static final Image IMPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$ private static final Image EXPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$ - + // ------------------------------------------------------------------------ // Main data structures // ------------------------------------------------------------------------ protected Shell fShell; - protected ScrolledComposite fScrolledComposite; - protected Composite fListComposite; - protected Composite fFillerComposite; - - private ColorSettingRow fSelectedRow = null; - - private TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); - private ITimeGraphProvider timeAnalysisProvider = new TimeGraphProvider() { - @Override - public StateColor getEventColor(ITimeEvent event) { - return null; - } - @Override - public String getTraceClassName(ITimeGraphEntry trace) { - return null; - } - @Override - public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { - return null; - } - @Override - public Map getEventHoverToolTipInfo(ITimeEvent event) { - return null; - } - @Override - public String getStateName(StateColor color) { - return null; - }}; - - Action fAddAction; - Action fDeleteAction; - Action fMoveUpAction; - Action fMoveDownAction; - Action fImportAction; - Action fExportAction; - - protected List fColorSettings; - + protected ScrolledComposite fScrolledComposite; + protected Composite fListComposite; + protected Composite fFillerComposite; + + private ColorSettingRow fSelectedRow = null; + + private TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); + + Action fAddAction; + Action fDeleteAction; + Action fMoveUpAction; + Action fMoveDownAction; + Action fImportAction; + Action fExportAction; + + protected List fColorSettings; + // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ @@ -120,34 +94,34 @@ public class ColorsView extends TmfView { /** * Default Constructor */ - public ColorsView() { - super("Colors"); //$NON-NLS-1$ - } + public ColorsView() { + super("Colors"); //$NON-NLS-1$ + } /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composite) */ - @Override - public void createPartControl(Composite parent) { - fShell = parent.getShell(); + @Override + public void createPartControl(Composite parent) { + fShell = parent.getShell(); fScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); fScrolledComposite.setExpandHorizontal(true); fScrolledComposite.setExpandVertical(true); fListComposite = new Composite(fScrolledComposite, SWT.NONE); fScrolledComposite.setContent(fListComposite); - + GridLayout gl = new GridLayout(); gl.marginHeight = 0; gl.marginWidth = 0; gl.verticalSpacing = 1; fListComposite.setLayout(gl); - fColorSettings = new ArrayList(Arrays.asList(ColorSettingsManager.getColorSettings())); + fColorSettings = new ArrayList(Arrays.asList(ColorSettingsManager.getColorSettings())); for (ColorSetting colorSetting : fColorSettings) { - new ColorSettingRow(fListComposite, colorSetting); + new ColorSettingRow(fListComposite, colorSetting); } - + fFillerComposite = new Composite(fListComposite, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = 0; @@ -159,33 +133,33 @@ public class ColorsView extends TmfView { Label fillerLabel = new Label(fFillerComposite, SWT.NONE); fillerLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); fillerLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - + fFillerComposite.addPaintListener(new PaintListener() { - @Override + @Override public void paintControl(PaintEvent e) { - if (fSelectedRow == null) { - Color lineColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); - Point p = fFillerComposite.getSize(); - GC gc = e.gc; - gc.setForeground(lineColor); - gc.drawLine(0, 0, p.x - 1, 0); - } - } - }); + if (fSelectedRow == null) { + Color lineColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + Point p = fFillerComposite.getSize(); + GC gc = e.gc; + gc.setForeground(lineColor); + gc.drawLine(0, 0, p.x - 1, 0); + } + } + }); MouseListener mouseListener = new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - fSelectedRow = null; - refresh(); - } + @Override + public void mouseDown(MouseEvent e) { + fSelectedRow = null; + refresh(); + } }; fillerLabel.addMouseListener(mouseListener); - + fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - + fillToolBar(); - } + } /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#setFocus() @@ -195,369 +169,370 @@ public class ColorsView extends TmfView { fScrolledComposite.setFocus(); } - public void refresh() { - fListComposite.layout(); + public void refresh() { + fListComposite.layout(); fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - fListComposite.redraw(0, 0, fListComposite.getBounds().width, fListComposite.getBounds().height, true); - if (fSelectedRow == null) { - fDeleteAction.setEnabled(false); - fMoveUpAction.setEnabled(false); - fMoveDownAction.setEnabled(false); - } else { - fDeleteAction.setEnabled(true); - fMoveUpAction.setEnabled(true); - fMoveDownAction.setEnabled(true); - } - } - - private void fillToolBar() { - - fAddAction = new AddAction(); - fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE)); - fAddAction.setToolTipText(Messages.ColorsView_AddActionToolTipText); - - fDeleteAction = new DeleteAction(); - fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE)); - fDeleteAction.setToolTipText(Messages.ColorsView_DeleteActionToolTipText); - fDeleteAction.setEnabled(false); - - fMoveUpAction = new MoveUpAction(); - fMoveUpAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_UP_IMAGE)); - fMoveUpAction.setToolTipText(Messages.ColorsView_MoveUpActionToolTipText); - fMoveUpAction.setEnabled(false); - - fMoveDownAction = new MoveDownAction(); - fMoveDownAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_DOWN_IMAGE)); - fMoveDownAction.setToolTipText(Messages.ColorsView_MoveDownActionToolTipText); - fMoveDownAction.setEnabled(false); - - fExportAction = new ExportAction(); - fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE)); - fExportAction.setToolTipText(Messages.ColorsView_ExportActionToolTipText); - - fImportAction = new ImportAction(); - fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE)); - fImportAction.setToolTipText(Messages.ColorsView_ImportActionToolTipText); - - IActionBars bars = getViewSite().getActionBars(); - IToolBarManager manager = bars.getToolBarManager(); - manager.add(fAddAction); - manager.add(fDeleteAction); - manager.add(fMoveUpAction); - manager.add(fMoveDownAction); - manager.add(new Separator()); - manager.add(fExportAction); - manager.add(fImportAction); - } - - private class AddAction extends Action { - @Override - public void run() { - ColorSetting colorSetting = new ColorSetting( - Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), - Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), - TimeGraphColorScheme.BLACK_STATE, - null); - ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); - if (fSelectedRow == null) { - fColorSettings.add(colorSetting); - row.moveAbove(fFillerComposite); - } else { - fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); - row.moveAbove(fSelectedRow); - } - fSelectedRow = row; - refresh(); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - } - } - - private class DeleteAction extends Action { - @Override - public void run() { - if (fSelectedRow != null) { - int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); - fColorSettings.remove(index); - fSelectedRow.fColorSetting.dispose(); - fSelectedRow.dispose(); - if (index < fColorSettings.size()) { - fSelectedRow = (ColorSettingRow) fListComposite.getChildren()[index]; - } else { - fSelectedRow = null; - } - refresh(); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - } - } - } - - private class MoveUpAction extends Action { - @Override - public void run() { - if (fSelectedRow != null) { - int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); - if (index > 0) { - fColorSettings.add(index - 1, fColorSettings.remove(index)); - fSelectedRow.moveAbove(fListComposite.getChildren()[index - 1]); - refresh(); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - } - } - } - } - - private class MoveDownAction extends Action { - @Override - public void run() { - if (fSelectedRow != null) { - int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); - if (index < fColorSettings.size() - 1) { - fColorSettings.add(index + 1, fColorSettings.remove(index)); - fSelectedRow.moveBelow(fListComposite.getChildren()[index + 1]); - refresh(); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - } - } - } - } - - private class ExportAction extends Action { - @Override - public void run() { - FileDialog fileDialog = new FileDialog(fShell, SWT.SAVE); - fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ - fileDialog.setOverwrite(true); - String pathName = fileDialog.open(); - if (pathName != null) { - ColorSettingsXML.save(pathName, fColorSettings.toArray(new ColorSetting[0])); - } - } - } - - private class ImportAction extends Action { - @Override - public void run() { - FileDialog fileDialog = new FileDialog(fShell, SWT.OPEN); - fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ - String pathName = fileDialog.open(); - if (pathName != null) { - ColorSetting[] colorSettings = ColorSettingsXML.load(pathName); - if (colorSettings.length > 0) { - if (fColorSettings.size() > 0) { - boolean overwrite = MessageDialog.openQuestion(fShell, - Messages.ColorsView_ImportOverwriteDialogTitle, - Messages.ColorsView_ImportOverwriteDialogMessage1 + - Messages.ColorsView_ImportOverwriteDialogMessage2); - if (overwrite) { - for (Control control : fListComposite.getChildren()) { - if (control instanceof ColorSettingRow) { - ((ColorSettingRow) control).fColorSetting.dispose(); - control.dispose(); - } - } - fColorSettings = new ArrayList(); - fSelectedRow = null; - } - } - for (ColorSetting colorSetting : colorSettings) { - ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); - if (fSelectedRow == null) { - fColorSettings.add(colorSetting); - row.moveAbove(fFillerComposite); - } else { - fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); - row.moveAbove(fSelectedRow); - } - } - refresh(); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - } - } - } - } - - private class ColorSettingRow extends Composite { - - ColorSetting fColorSetting; - - public ColorSettingRow(final Composite parent, final ColorSetting colorSetting) { - super(parent, SWT.NONE); - fColorSetting = colorSetting; - - setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - - setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - GridLayout gl = new GridLayout(7, false); - gl.marginHeight = 1; - gl.marginWidth = 1; - gl.horizontalSpacing = 1; - gl.verticalSpacing = 0; - setLayout(gl); - - final Button fgButton = new Button(this, SWT.PUSH); - fgButton.setText(Messages.ColorsView_ForegroundButtonText); - fgButton.setSize(fgButton.computeSize(SWT.DEFAULT, 19)); - fgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - - final Button bgButton = new Button(this, SWT.PUSH); - bgButton.setText(Messages.ColorsView_BackgroundButtonText); - bgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - - final Composite labelComposite = new Composite(this, SWT.NONE); - labelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); - gl = new GridLayout(); - gl.marginHeight = 0; - gl.marginWidth = 0;; - labelComposite.setLayout(gl); - labelComposite.setBackground(colorSetting.getBackgroundColor()); - - final Label label = new Label(labelComposite, SWT.NONE); - label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true)); - label.setText(" Text "); //$NON-NLS-1$ - label.setForeground(colorSetting.getForegroundColor()); - label.setBackground(colorSetting.getBackgroundColor()); - - fgButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - fSelectedRow = ColorSettingRow.this; - refresh(); - ColorDialog dialog = new ColorDialog(fShell); - dialog.setRGB(colorSetting.getForegroundRGB()); - dialog.setText(Messages.ColorsView_ForegroundDialogText); - dialog.open(); - colorSetting.setForegroundRGB(dialog.getRGB()); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - label.setForeground(colorSetting.getForegroundColor()); - }}); - - bgButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - fSelectedRow = ColorSettingRow.this; - refresh(); - ColorDialog dialog = new ColorDialog(fShell); - dialog.setRGB(colorSetting.getBackgroundRGB()); - dialog.setText(Messages.ColorsView_BackgroundDialogText); - dialog.open(); - colorSetting.setBackgroundRGB(dialog.getRGB()); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - labelComposite.setBackground(colorSetting.getBackgroundColor()); - label.setBackground(colorSetting.getBackgroundColor()); - }}); - - final Button tickButton = new Button(this, SWT.PUSH); - tickButton.setText(Messages.ColorsView_TickButtonText); - tickButton.setSize(tickButton.computeSize(SWT.DEFAULT, 19)); - tickButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - - final Canvas tickCanvas = new Canvas(this, SWT.NONE); - GridData gd = new GridData(SWT.CENTER, SWT.FILL, false, false); - gd.widthHint = 12; - gd.heightHint = bgButton.getSize().y; - tickCanvas.setLayoutData(gd); - tickCanvas.setBackground(traceColorScheme.getBkColor(false, false, false)); - tickCanvas.addPaintListener(new PaintListener() { - @Override + fListComposite.redraw(0, 0, fListComposite.getBounds().width, fListComposite.getBounds().height, true); + if (fSelectedRow == null) { + fDeleteAction.setEnabled(false); + fMoveUpAction.setEnabled(false); + fMoveDownAction.setEnabled(false); + } else { + fDeleteAction.setEnabled(true); + fMoveUpAction.setEnabled(true); + fMoveDownAction.setEnabled(true); + } + } + + private void fillToolBar() { + + fAddAction = new AddAction(); + fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE)); + fAddAction.setToolTipText(Messages.ColorsView_AddActionToolTipText); + + fDeleteAction = new DeleteAction(); + fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE)); + fDeleteAction.setToolTipText(Messages.ColorsView_DeleteActionToolTipText); + fDeleteAction.setEnabled(false); + + fMoveUpAction = new MoveUpAction(); + fMoveUpAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_UP_IMAGE)); + fMoveUpAction.setToolTipText(Messages.ColorsView_MoveUpActionToolTipText); + fMoveUpAction.setEnabled(false); + + fMoveDownAction = new MoveDownAction(); + fMoveDownAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_DOWN_IMAGE)); + fMoveDownAction.setToolTipText(Messages.ColorsView_MoveDownActionToolTipText); + fMoveDownAction.setEnabled(false); + + fExportAction = new ExportAction(); + fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE)); + fExportAction.setToolTipText(Messages.ColorsView_ExportActionToolTipText); + + fImportAction = new ImportAction(); + fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE)); + fImportAction.setToolTipText(Messages.ColorsView_ImportActionToolTipText); + + IActionBars bars = getViewSite().getActionBars(); + IToolBarManager manager = bars.getToolBarManager(); + manager.add(fAddAction); + manager.add(fDeleteAction); + manager.add(fMoveUpAction); + manager.add(fMoveDownAction); + manager.add(new Separator()); + manager.add(fExportAction); + manager.add(fImportAction); + } + + private class AddAction extends Action { + @Override + public void run() { + ColorSetting colorSetting = new ColorSetting( + Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), + TimeGraphColorScheme.BLACK_STATE, + null); + ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); + if (fSelectedRow == null) { + fColorSettings.add(colorSetting); + row.moveAbove(fFillerComposite); + } else { + fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); + row.moveAbove(fSelectedRow); + } + fSelectedRow = row; + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + + private class DeleteAction extends Action { + @Override + public void run() { + if (fSelectedRow != null) { + int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); + fColorSettings.remove(index); + fSelectedRow.fColorSetting.dispose(); + fSelectedRow.dispose(); + if (index < fColorSettings.size()) { + fSelectedRow = (ColorSettingRow) fListComposite.getChildren()[index]; + } else { + fSelectedRow = null; + } + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + + private class MoveUpAction extends Action { + @Override + public void run() { + if (fSelectedRow != null) { + int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); + if (index > 0) { + fColorSettings.add(index - 1, fColorSettings.remove(index)); + fSelectedRow.moveAbove(fListComposite.getChildren()[index - 1]); + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + } + + private class MoveDownAction extends Action { + @Override + public void run() { + if (fSelectedRow != null) { + int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); + if (index < fColorSettings.size() - 1) { + fColorSettings.add(index + 1, fColorSettings.remove(index)); + fSelectedRow.moveBelow(fListComposite.getChildren()[index + 1]); + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + } + + private class ExportAction extends Action { + @Override + public void run() { + FileDialog fileDialog = new FileDialog(fShell, SWT.SAVE); + fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ + fileDialog.setOverwrite(true); + String pathName = fileDialog.open(); + if (pathName != null) { + ColorSettingsXML.save(pathName, fColorSettings.toArray(new ColorSetting[0])); + } + } + } + + private class ImportAction extends Action { + @Override + public void run() { + FileDialog fileDialog = new FileDialog(fShell, SWT.OPEN); + fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ + String pathName = fileDialog.open(); + if (pathName != null) { + ColorSetting[] colorSettings = ColorSettingsXML.load(pathName); + if (colorSettings.length > 0) { + if (fColorSettings.size() > 0) { + boolean overwrite = MessageDialog.openQuestion(fShell, + Messages.ColorsView_ImportOverwriteDialogTitle, + Messages.ColorsView_ImportOverwriteDialogMessage1 + + Messages.ColorsView_ImportOverwriteDialogMessage2); + if (overwrite) { + for (Control control : fListComposite.getChildren()) { + if (control instanceof ColorSettingRow) { + ((ColorSettingRow) control).fColorSetting.dispose(); + control.dispose(); + } + } + fColorSettings = new ArrayList(); + fSelectedRow = null; + } + } + for (ColorSetting colorSetting : colorSettings) { + ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); + if (fSelectedRow == null) { + fColorSettings.add(colorSetting); + row.moveAbove(fFillerComposite); + } else { + fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); + row.moveAbove(fSelectedRow); + } + } + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + } + + private class ColorSettingRow extends Composite { + + ColorSetting fColorSetting; + + public ColorSettingRow(final Composite parent, final ColorSetting colorSetting) { + super(parent, SWT.NONE); + fColorSetting = colorSetting; + + setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + GridLayout gl = new GridLayout(7, false); + gl.marginHeight = 1; + gl.marginWidth = 1; + gl.horizontalSpacing = 1; + gl.verticalSpacing = 0; + setLayout(gl); + + final Button fgButton = new Button(this, SWT.PUSH); + fgButton.setText(Messages.ColorsView_ForegroundButtonText); + fgButton.setSize(fgButton.computeSize(SWT.DEFAULT, 19)); + fgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Button bgButton = new Button(this, SWT.PUSH); + bgButton.setText(Messages.ColorsView_BackgroundButtonText); + bgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Composite labelComposite = new Composite(this, SWT.NONE); + labelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); + gl = new GridLayout(); + gl.marginHeight = 0; + gl.marginWidth = 0;; + labelComposite.setLayout(gl); + labelComposite.setBackground(colorSetting.getBackgroundColor()); + + final Label label = new Label(labelComposite, SWT.NONE); + label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true)); + label.setText(" Text "); //$NON-NLS-1$ + label.setForeground(colorSetting.getForegroundColor()); + label.setBackground(colorSetting.getBackgroundColor()); + + fgButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + ColorDialog dialog = new ColorDialog(fShell); + dialog.setRGB(colorSetting.getForegroundRGB()); + dialog.setText(Messages.ColorsView_ForegroundDialogText); + dialog.open(); + colorSetting.setForegroundRGB(dialog.getRGB()); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + label.setForeground(colorSetting.getForegroundColor()); + }}); + + bgButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + ColorDialog dialog = new ColorDialog(fShell); + dialog.setRGB(colorSetting.getBackgroundRGB()); + dialog.setText(Messages.ColorsView_BackgroundDialogText); + dialog.open(); + colorSetting.setBackgroundRGB(dialog.getRGB()); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + labelComposite.setBackground(colorSetting.getBackgroundColor()); + label.setBackground(colorSetting.getBackgroundColor()); + }}); + + final Button tickButton = new Button(this, SWT.PUSH); + tickButton.setText(Messages.ColorsView_TickButtonText); + tickButton.setSize(tickButton.computeSize(SWT.DEFAULT, 19)); + tickButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Canvas tickCanvas = new Canvas(this, SWT.NONE); + GridData gd = new GridData(SWT.CENTER, SWT.FILL, false, false); + gd.widthHint = 12; + gd.heightHint = bgButton.getSize().y; + tickCanvas.setLayoutData(gd); + tickCanvas.setBackground(traceColorScheme.getBkColor(false, false, false)); + tickCanvas.addPaintListener(new PaintListener() { + @Override public void paintControl(PaintEvent e) { - Rectangle bounds = tickCanvas.getBounds(); - e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); - int midy = bounds.y + bounds.height / 2 - 1; - //int midy = e.y + e.height / 2; - e.gc.drawLine(e.x, midy, e.x + e.width, midy); - Rectangle rect = new Rectangle(e.x + 1, bounds.y + 2, 0, bounds.height - 6); - for (int i = 1; i <= 3; i++) { - rect.x += i; - rect.width = i; - timeAnalysisProvider.drawState(traceColorScheme, fColorSetting.getTickColorIndex(), rect, e.gc, false, false, false); - } + Rectangle bounds = tickCanvas.getBounds(); + e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); + int midy = bounds.y + bounds.height / 2 - 1; + //int midy = e.y + e.height / 2; + e.gc.drawLine(e.x, midy, e.x + e.width, midy); + Rectangle rect = new Rectangle(e.x + 1, bounds.y + 2, 0, bounds.height - 6); + for (int i = 1; i <= 3; i++) { + rect.x += i; + rect.width = i; + e.gc.setBackground(traceColorScheme.getColor(fColorSetting.getTickColorIndex())); + e.gc.fillRectangle(rect); + } + }}); + + tickButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + TickColorDialog dialog = new TickColorDialog(fShell); + dialog.setColorIndex(colorSetting.getTickColorIndex()); + dialog.open(); + if (dialog.getReturnCode() == Dialog.OK) { + if (dialog.getColorIndex() != colorSetting.getTickColorIndex()) { + colorSetting.setTickColorIndex(dialog.getColorIndex()); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + refresh(); + } + } + }}); + + final Button filterButton = new Button(this, SWT.PUSH); + filterButton.setText(Messages.ColorsView_FilterButtonText); + filterButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Label filterText = new Label(this, SWT.NONE); + if (colorSetting.getFilter() != null) { + filterText.setText(colorSetting.getFilter().toString()); + filterText.setToolTipText(colorSetting.getFilter().toString()); + } + filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + filterButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + FilterDialog dialog = new FilterDialog(fShell); + dialog.setFilter(colorSetting.getFilter()); + dialog.open(); + if (dialog.getReturnCode() == Dialog.OK) { + if (dialog.getFilter() != null) { + colorSetting.setFilter(dialog.getFilter()); + filterText.setText(dialog.getFilter().toString()); + filterText.setToolTipText(dialog.getFilter().toString()); + } else { + colorSetting.setFilter(null); + filterText.setText(""); //$NON-NLS-1$ + filterText.setToolTipText(""); //$NON-NLS-1$ + } + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + refresh(); + } }}); - tickButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - fSelectedRow = ColorSettingRow.this; - refresh(); - TickColorDialog dialog = new TickColorDialog(fShell); - dialog.setColorIndex(colorSetting.getTickColorIndex()); - dialog.open(); - if (dialog.getReturnCode() == Dialog.OK) { - if (dialog.getColorIndex() != colorSetting.getTickColorIndex()) { - colorSetting.setTickColorIndex(dialog.getColorIndex()); - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - refresh(); - } - } - }}); - - final Button filterButton = new Button(this, SWT.PUSH); - filterButton.setText(Messages.ColorsView_FilterButtonText); - filterButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - - final Label filterText = new Label(this, SWT.NONE); - if (colorSetting.getFilter() != null) { - filterText.setText(colorSetting.getFilter().toString()); - filterText.setToolTipText(colorSetting.getFilter().toString()); - } - filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - - filterButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - fSelectedRow = ColorSettingRow.this; - refresh(); - FilterDialog dialog = new FilterDialog(fShell); - dialog.setFilter(colorSetting.getFilter()); - dialog.open(); - if (dialog.getReturnCode() == Dialog.OK) { - if (dialog.getFilter() != null) { - colorSetting.setFilter(dialog.getFilter()); - filterText.setText(dialog.getFilter().toString()); - filterText.setToolTipText(dialog.getFilter().toString()); - } else { - colorSetting.setFilter(null); - filterText.setText(""); //$NON-NLS-1$ - filterText.setToolTipText(""); //$NON-NLS-1$ - } - ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); - refresh(); - } - }}); - - addPaintListener(new PaintListener() { - @Override + addPaintListener(new PaintListener() { + @Override public void paintControl(PaintEvent e) { - if (fSelectedRow == ColorSettingRow.this) { - Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); - Point p = ColorSettingRow.this.getSize(); - Rectangle rect = new Rectangle(0, 0, p.x - 1, p.y - 1); - GC gc = e.gc; - gc.setForeground(borderColor); - gc.drawRectangle(rect); - } - } - }); - - MouseListener mouseListener = new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - fSelectedRow = ColorSettingRow.this; - refresh(); - } - }; - addMouseListener(mouseListener); - label.addMouseListener(mouseListener); - tickCanvas.addMouseListener(mouseListener); - filterText.addMouseListener(mouseListener); - } - - /** - * @return the ColorSetting - */ - public ColorSetting getColorSetting() { - return fColorSetting; - } - - } + if (fSelectedRow == ColorSettingRow.this) { + Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + Point p = ColorSettingRow.this.getSize(); + Rectangle rect = new Rectangle(0, 0, p.x - 1, p.y - 1); + GC gc = e.gc; + gc.setForeground(borderColor); + gc.drawRectangle(rect); + } + } + }); + + MouseListener mouseListener = new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + } + }; + addMouseListener(mouseListener); + label.addMouseListener(mouseListener); + tickCanvas.addMouseListener(mouseListener); + filterText.addMouseListener(mouseListener); + } + + /** + * @return the ColorSetting + */ + public ColorSetting getColorSetting() { + return fColorSetting; + } + + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java index 8a58338882..7398423cfd 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java @@ -12,14 +12,8 @@ package org.eclipse.linuxtools.tmf.ui.views.colors; -import java.util.Map; - import org.eclipse.jface.dialogs.Dialog; import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; @@ -40,116 +34,97 @@ import org.eclipse.swt.widgets.Shell; public class TickColorDialog extends Dialog { - int selectedIndex = 0; - Composite colorComposite; - - TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); - private ITimeGraphProvider timeAnalysisProvider = new TimeGraphProvider() { - @Override - public StateColor getEventColor(ITimeEvent event) { - return null; - } - @Override - public String getTraceClassName(ITimeGraphEntry trace) { - return null; - } - @Override - public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { - return null; - } - @Override - public Map getEventHoverToolTipInfo(ITimeEvent event) { - return null; - } - @Override - public String getStateName(StateColor color) { - return null; - }}; - - protected TickColorDialog(Shell shell) { - super(shell); - setShellStyle(getShellStyle() | SWT.MAX); - } - - /* (non-Javadoc) + int selectedIndex = 0; + Composite colorComposite; + + TimeGraphColorScheme traceColorScheme = new TimeGraphColorScheme(); + + protected TickColorDialog(Shell shell) { + super(shell); + setShellStyle(getShellStyle() | SWT.MAX); + } + + /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ @Override protected Control createDialogArea(Composite parent) { getShell().setText(Messages.TickColorDialog_TickColorDialogTitle); - //getShell().setMinimumSize(getShell().computeSize(500, 200)); + //getShell().setMinimumSize(getShell().computeSize(500, 200)); Composite composite = (Composite) super.createDialogArea(parent); colorComposite = new Composite(composite, SWT.NONE); colorComposite.setLayout(new GridLayout(4, false)); - + for (int i = 0; i < 16; i++) { - TickColorCanvas tickColorCanvas = new TickColorCanvas(colorComposite, SWT.NONE); - tickColorCanvas.setColorIndex(i); + TickColorCanvas tickColorCanvas = new TickColorCanvas(colorComposite, SWT.NONE); + tickColorCanvas.setColorIndex(i); } return composite; } public void setColorIndex(int colorIndex) { - selectedIndex = colorIndex; + selectedIndex = colorIndex; } - + public int getColorIndex() { - return selectedIndex; + return selectedIndex; } - + private class TickColorCanvas extends Canvas { - int colorIndex; - - public TickColorCanvas(Composite parent, int style) { - super(parent, style); - - GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, false); - gd.widthHint = 40; - gd.heightHint = 25; - setLayoutData(gd); - setBackground(traceColorScheme.getBkColor(false, false, false)); - - addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); - int midy = e.y + e.height / 2; - e.gc.drawLine(e.x, midy, e.x + e.width, midy); - int midx = e.x + e.width / 2; - Rectangle rect = new Rectangle(midx - 10, e.y + 3, 0, e.height - 6); - for (int i = 1; i <= 3; i++) { - rect.x += i; - rect.width = i; - timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false); - } - for (int i = 3; i > 0; i--) { - rect.x += i + 2; - rect.width = i; - timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false); - } - if (selectedIndex == colorIndex) { - Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); - Point p = TickColorCanvas.this.getSize(); - rect = new Rectangle(0, 0, p.x - 1, p.y - 1); - GC gc = e.gc; - gc.setForeground(borderColor); - gc.drawRectangle(rect); - } - }}); - - addMouseListener(new MouseAdapter() { - @Override + int colorIndex; + + public TickColorCanvas(Composite parent, int style) { + super(parent, style); + + GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, false); + gd.widthHint = 40; + gd.heightHint = 25; + setLayoutData(gd); + setBackground(traceColorScheme.getBkColor(false, false, false)); + + addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + e.gc.setForeground(traceColorScheme.getColor(TimeGraphColorScheme.MID_LINE)); + int midy = e.y + e.height / 2; + e.gc.drawLine(e.x, midy, e.x + e.width, midy); + int midx = e.x + e.width / 2; + Rectangle rect = new Rectangle(midx - 10, e.y + 3, 0, e.height - 6); + for (int i = 1; i <= 3; i++) { + rect.x += i; + rect.width = i; + e.gc.setBackground(traceColorScheme.getColor(colorIndex)); + e.gc.fillRectangle(rect); + } + for (int i = 3; i > 0; i--) { + rect.x += i + 2; + rect.width = i; + e.gc.setBackground(traceColorScheme.getColor(colorIndex)); + e.gc.fillRectangle(rect); + } + if (selectedIndex == colorIndex) { + Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + Point p = TickColorCanvas.this.getSize(); + rect = new Rectangle(0, 0, p.x - 1, p.y - 1); + GC gc = e.gc; + gc.setForeground(borderColor); + gc.drawRectangle(rect); + } + }}); + + addMouseListener(new MouseAdapter() { + @Override public void mouseUp(MouseEvent e) { - selectedIndex = colorIndex; - colorComposite.redraw(0, 0, colorComposite.getBounds().width, colorComposite.getBounds().height, true); + selectedIndex = colorIndex; + colorComposite.redraw(0, 0, colorComposite.getBounds().width, colorComposite.getBounds().height, true); }}); - } + } - public void setColorIndex(int index) { - colorIndex = index; + public void setColorIndex(int index) { + colorIndex = index; } } - - + + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java index 3a9a24a2ac..68e1edb88f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisEntry.java @@ -61,7 +61,7 @@ public class TimeChartAnalysisEntry implements ITimeGraphEntry { } @Override - public long getStopTime() { + public long getEndTime() { return fStopTime; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java index 1e70ffa7c1..9d9e55db20 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java @@ -15,49 +15,68 @@ package org.eclipse.linuxtools.tmf.ui.views.timechart; import java.util.Map; import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.themes.ColorUtil; -public class TimeChartAnalysisProvider extends TimeGraphProvider { +public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider { + + private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224); + private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140); + private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14); + + private int lastX = Integer.MIN_VALUE; + private int currX = Integer.MIN_VALUE; + private int lastPriority; + private int lastBookmarkX = Integer.MIN_VALUE; - private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224); - private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140); - private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14); - - private int lastX = Integer.MIN_VALUE; - private int currX = Integer.MIN_VALUE; - private int lastPriority; - private int lastBookmarkX = Integer.MIN_VALUE; - @Override - public StateColor getEventColor(ITimeEvent event) { - return StateColor.BLACK; + public StateItem[] getStateTable() { + return new StateItem[] { + new StateItem(new RGB(100, 100, 100)), + new StateItem(new RGB(174, 200, 124)), + new StateItem(ColorUtil.blend(Display.getDefault().getSystemColor(SWT.COLOR_BLUE).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB())), + new StateItem(new RGB(210, 150, 60)), + new StateItem(new RGB(242, 225, 168)), + new StateItem(ColorUtil.blend(Display.getDefault().getSystemColor(SWT.COLOR_RED).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB())), + new StateItem(new RGB(200, 200, 200)), + new StateItem(new RGB(35, 107, 42)), + new StateItem(new RGB(205,205,0)), + new StateItem(new RGB(205, 0, 205)), + new StateItem(new RGB(171, 130, 255)), + new StateItem(new RGB(255, 181, 197)), + new StateItem(new RGB(112, 219, 147)), + new StateItem(new RGB(198, 226, 255)), + new StateItem(new RGB(95, 158, 160)), + new StateItem(new RGB(107, 142, 35)) + }; } @Override - public int getEventColorVal(ITimeEvent event) { - int priority = ((TimeChartEvent) event).getColorSettingPriority(); - if (currX == lastX) { - priority = Math.min(priority, lastPriority); - } - lastPriority = priority; - return ColorSettingsManager.getColorSetting(priority).getTickColorIndex(); + public int getEventTableIndex(ITimeEvent event) { + int priority = ((TimeChartEvent) event).getColorSettingPriority(); + if (currX == lastX) { + priority = Math.min(priority, lastPriority); + } + lastPriority = priority; + return ColorSettingsManager.getColorSetting(priority).getTickColorIndex(); } - @Override + @Override public String getTraceClassName(ITimeGraphEntry entry) { return null; } @Override - public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { + public String getEventName(ITimeEvent event) { return null; } @@ -67,49 +86,43 @@ public class TimeChartAnalysisProvider extends TimeGraphProvider { } @Override - public String getStateName(StateColor color) { - return null; - } - - @Override - public void drawState(TimeGraphColorScheme colors, ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected) { - if (! ((TimeChartEvent) event).isVisible()) { - return; - } - lastX = currX; - currX = rect.x; - super.drawState(colors, event, rect, gc, selected, rectBound, timeSelected); - if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) { - drawBookmark(rect, gc); - lastBookmarkX = rect.x; - } else if (lastBookmarkX == rect.x - 1) { - Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height); - drawBookmark(r, gc); - } else { - lastBookmarkX = Integer.MIN_VALUE; - } - if (((TimeChartEvent) event).isSearchMatch()) { - drawSearchMatch(rect, gc); - } + public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) { + if (! ((TimeChartEvent) event).isVisible()) { + return; + } + lastX = currX; + currX = rect.x; + if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) { + drawBookmark(rect, gc); + lastBookmarkX = rect.x; + } else if (lastBookmarkX == rect.x - 1) { + Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height); + drawBookmark(r, gc); + } else { + lastBookmarkX = Integer.MIN_VALUE; + } + if (((TimeChartEvent) event).isSearchMatch()) { + drawSearchMatch(rect, gc); + } } private void drawBookmark(Rectangle r, GC gc) { - gc.setForeground(BOOKMARK_OUTER_COLOR); - gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2); - gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2); - gc.drawPoint(r.x, r.y - 2); - gc.setForeground(BOOKMARK_INNER_COLOR); - gc.drawLine(r.x, r.y - 1, r.x, r.y + 1); - gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); - gc.drawPoint(r.x - 1, r.y + 3); - gc.drawPoint(r.x, r.y + 2); - gc.drawPoint(r.x + 1, r.y + 3); + gc.setForeground(BOOKMARK_OUTER_COLOR); + gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2); + gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2); + gc.drawPoint(r.x, r.y - 2); + gc.setForeground(BOOKMARK_INNER_COLOR); + gc.drawLine(r.x, r.y - 1, r.x, r.y + 1); + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); + gc.drawPoint(r.x - 1, r.y + 3); + gc.drawPoint(r.x, r.y + 2); + gc.drawPoint(r.x + 1, r.y + 3); } - + private void drawSearchMatch(Rectangle r, GC gc) { - gc.setForeground(SEARCH_MATCH_COLOR); - gc.drawPoint(r.x, r.y + r.height); - gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1); - gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2); + gc.setForeground(SEARCH_MATCH_COLOR); + gc.drawPoint(r.x, r.y + r.height); + gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1); + gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java new file mode 100644 index 0000000000..a77ca908c0 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 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 + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.Map; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; + +public interface ITimeGraphPresentationProvider { + + + /** + * Returns the name of state types. + * + * @return the name of state types + */ + public String getStateTypeName(); + + /** + * Called after drawing the control + * + * @bounds the drawing rectangle + * @param gc the graphics context + */ + public void postDrawControl(Rectangle bounds, GC gc); + + /** + * Called after drawing an entry + * + * @param entry the entry that was drawn + * @bounds the drawing rectangle + * @param gc the graphics context + */ + public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc); + + /** + * Called after drawing an event + * + * @param event the event that was drawn + * @bounds the drawing rectangle + * @param gc the graphics context + */ + public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc); + + + /** + * Returns table of states with state name to state color relationship + * + * @return table of states with state name to state color relationship + */ + public StateItem[] getStateTable(); + + /** + * Returns the index in the event color table and event name table corresponding to this time event. + * The index should correspond to a RGB value in the event color table, + * otherwise the color SWT.COLOR_BLACK will be used. + * + * @param event the time event + * @return the corresponding event table index + * + * @see #getEventColorTable + * @see #getEventNameTable + */ + public int getEventTableIndex(ITimeEvent event); + + /** + * Returns the height of this item. This value is ignored if the time graph has a fixed item height. + * + * @return the entry height + * + * @see TimeGraphViewer#setItemHeight + */ + public int getItemHeight(ITimeGraphEntry entry); + + /** + * This values is appended between braces to the right of Trace Name e.g. + * Trace And Error Log [Board 17] or for a Thread trace e.g. State Server + * [java.lang.Thread] + * + * @param trace + * @return the trace class name + */ + public String getTraceClassName(ITimeGraphEntry trace); + + /** + * Returns the name of this event. + * + * @return the event name + */ + public String getEventName(ITimeEvent event); + + public String composeTraceName(ITimeGraphEntry trace, boolean inclState); + + public String composeEventName(ITimeEvent event); + + public Map getEventHoverToolTipInfo(ITimeEvent event); + + /** + * Provides the image icon for a given Event or Trace e.g. customize to use + * different icons according to specific event /state combination + * + * @param obj + * @return the image icon + */ + public Image getItemImage(Object obj); + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java deleted file mode 100644 index de98ea345f..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphProvider.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - * - * Contributors: - * Patrick Tasse - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.Map; - -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphItem; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; - -public interface ITimeGraphProvider { - - public abstract void setTimeGraphControl(TimeGraphControl timeGraphControl); - - public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc); - - /** - * Draws the item - * - * @param item the item to draw - * @param bounds the container rectangle - * @param timeProvider the time provider - * @param i the item index - * @param nameSpace the name space - * @param gc - */ - public abstract void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc); - - public abstract void drawState(TimeGraphColorScheme colors, ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected); - - public abstract void drawState(TimeGraphColorScheme colors, int colorIdx, Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected); - - /** - * Uses the abstract method getEventcolor to obtain an enum value and - * convert it to an internal color index - * - * @param event - * @return the internal color index - */ - public abstract int getEventColorVal(ITimeEvent event); - - /** - * Select the color for the different internal variants of events. - * - * @param event - * @return the corresponding event color - */ - public abstract StateColor getEventColor(ITimeEvent event); - - /** - * This values is appended between braces to the right of Trace Name e.g. - * Trace And Error Log [Board 17] or for a Thread trace e.g. State Server - * [java.lang.Thread] - * - * @param trace - * @return the trace class name - */ - public abstract String getTraceClassName(ITimeGraphEntry trace); - - public abstract String getEventName(ITimeEvent event); - - /** - * Specify a Name for the event depending on its type or state e.g. blocked, - * running, etc.. - * - * @param event - * @param upper - * True return String value in Upper case - * @param extInfo - * Verbose, add additional information if applicable - * @return the event name - */ - public abstract String getEventName(ITimeEvent event, boolean upper, boolean extInfo); - - public abstract String composeTraceName(ITimeGraphEntry trace, boolean inclState); - - public abstract String composeEventName(ITimeEvent event); - - public abstract Map getEventHoverToolTipInfo(ITimeEvent event); - - /** - * Provides the image icon for a given Event or Trace e.g. customize to use - * different icons according to specific event /state combination - * - * @param obj - * @return the image icon - */ - public abstract Image getItemImage(Object obj); - - public abstract String getStateName(StateColor color); - -} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/StateItem.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/StateItem.java new file mode 100644 index 0000000000..5ab0afffc0 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/StateItem.java @@ -0,0 +1,105 @@ +/********************************************************************** + * Copyright (c) 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 + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import org.eclipse.swt.graphics.RGB; + +/** + *

+ * Class that contains the color of a state and the corresponding state string to display. + *

+ */ +public class StateItem { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Name of state if not known + */ + public static final String UNDEFINED_STATE_NAME = "Undefined"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The State color + */ + private RGB fStateColor; + /** + * The State string. + */ + private String fStateString; + + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Creates a state item with given color and unspecified name. + * + * @param stateColor A state color + */ + public StateItem(RGB stateColor) { + this(stateColor, UNDEFINED_STATE_NAME); + } + + /** + * Creates a state color - state string pair. + * + * @param stateColor A state color + * @param stateString A state string + */ + public StateItem(RGB stateColor, String stateString) { + fStateColor = stateColor; + fStateString = stateString; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * Returns the state color. + * + * @return Returns the state color. + */ + public RGB getStateColor() { + return fStateColor; + } + + /** + * Sets the state color. + * + * @param stateColor A state color to set + */ + public void setStateColor(RGB stateColor) { + fStateColor = stateColor; + } + + /** + * Returns the state string. + * + * @return the state string. + */ + public String getStateString() { + return fStateString; + } + + /** + * Sets the state string + * @param stateString A state string to set + */ + public void setStateString(String stateString) { + fStateString = stateString; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java index 6545aa6e5d..2419c1168d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphCombo.java @@ -32,6 +32,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseWheelListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionAdapter; @@ -202,10 +204,13 @@ public class TimeGraphCombo extends Composite { if (fInhibitTreeSelection) { return; } - ITimeGraphEntry entry = (ITimeGraphEntry) ((IStructuredSelection) event.getSelection()).getFirstElement(); - if (entry != selection) { - selection = entry; - listener.selectionChanged(new TimeGraphSelectionEvent(event.getSource(), selection)); + Object element = ((IStructuredSelection) event.getSelection()).getFirstElement(); + if (element instanceof ITimeGraphEntry) { + ITimeGraphEntry entry = (ITimeGraphEntry) element; + if (entry != selection) { + selection = entry; + listener.selectionChanged(new TimeGraphSelectionEvent(event.getSource(), selection)); + } } } @@ -245,6 +250,8 @@ public class TimeGraphCombo extends Composite { tree.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { + fTreeViewer.getTree().getVerticalBar().setEnabled(false); + fTreeViewer.getTree().getVerticalBar().setVisible(false); fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight()); } }); @@ -282,6 +289,8 @@ public class TimeGraphCombo extends Composite { event.doit = false; ArrayList treeItems = getVisibleExpandedItems(tree); if (treeItems.size() == 0) { + fTreeViewer.setSelection(new StructuredSelection()); + fTimeGraphViewer.setSelection(null); return; } // this prevents from scrolling up when selecting @@ -314,6 +323,8 @@ public class TimeGraphCombo extends Composite { public void handleEvent(Event event) { ArrayList treeItems = getVisibleExpandedItems(tree); if (treeItems.size() == 0) { + fTreeViewer.setSelection(new StructuredSelection()); + event.doit = false; return; } if (event.keyCode == SWT.ARROW_DOWN) { @@ -360,10 +371,10 @@ public class TimeGraphCombo extends Composite { } if (event.getSelection() instanceof IStructuredSelection) { Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement(); - ArrayList treeItems = getVisibleExpandedItems(tree); if (selection instanceof ITimeGraphEntry) { fTimeGraphViewer.setSelection((ITimeGraphEntry) selection); } + ArrayList treeItems = getVisibleExpandedItems(tree); if (treeItems.size() == 0) { return; } @@ -406,6 +417,18 @@ public class TimeGraphCombo extends Composite { } }); + fTimeGraphViewer.getTimeGraphControl().addMouseWheelListener(new MouseWheelListener() { + @Override + public void mouseScrolled(MouseEvent e) { + ArrayList treeItems = getVisibleExpandedItems(tree); + if (treeItems.size() == 0) { + return; + } + TreeItem treeItem = treeItems.get(fTimeGraphViewer.getTopIndex()); + tree.setTopItem(treeItem); + } + }); + fNumFillerRows = Display.getDefault().getBounds().height / getItemHeight(tree); sash.setWeights(new int[] { 1, 1 }); @@ -458,6 +481,19 @@ public class TimeGraphCombo extends Composite { return fTimeGraphViewer; } + // ------------------------------------------------------------------------ + // Control + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.swt.widgets.Control#redraw() + */ + @Override + public void redraw() { + fTimeGraphViewer.getControl().redraw(); + super.redraw(); + } + // ------------------------------------------------------------------------ // Internal // ------------------------------------------------------------------------ @@ -537,12 +573,13 @@ public class TimeGraphCombo extends Composite { * * @param timeGraphProvider the time graph provider */ - public void setTimeGraphProvider(ITimeGraphProvider timeGraphProvider) { + public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) { fTimeGraphViewer.setTimeGraphProvider(timeGraphProvider); } /** * Sets or clears the input for this time graph combo. + * The input array should only contain top-level elements. * * @param input the input of this time graph combo, or null if none */ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java new file mode 100644 index 0000000000..841ed2a888 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010, 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 + * + * Contributors: + * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.Map; + +import org.eclipse.linuxtools.internal.tmf.ui.Messages; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; + +public abstract class TimeGraphPresentationProvider implements ITimeGraphPresentationProvider { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + private static final int DEFAULT_ITEM_HEIGHT = 19; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTypeName() + */ + @Override + public String getStateTypeName() { + return Messages.TmfTimeLegend_TRACE_STATES; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#postDrawItems(org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) + */ + @Override + public void postDrawControl(Rectangle bounds, GC gc) { + // Override to add own drawing code + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#postDrawItem(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) + */ + @Override + public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) { + // Override to add own drawing code + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawState(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) + */ + @Override + public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { + // Override to add own drawing code + } + +// /* (non-Javadoc) +// * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventColorTable() +// */ +// @Override +// public RGB[] getEventColorTable() { +// return null; +// } +// +// /* +// * (non-Javadoc) +// * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventNameTable() +// */ +// @Override +// public String[] getEventNameTable() { +// return null; +// } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateItems() + */ + @Override + public StateItem[] getStateTable() { + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventTableIndex(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public int getEventTableIndex(ITimeEvent event) { + return 0; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getItemHeight(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) + */ + @Override + public int getItemHeight(ITimeGraphEntry entry) { + return DEFAULT_ITEM_HEIGHT; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getTraceClassName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) + */ + @Override + public String getTraceClassName(ITimeGraphEntry trace) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public abstract String getEventName(ITimeEvent event); + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#composeTraceName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry, boolean) + */ + @Override + public String composeTraceName(ITimeGraphEntry trace, boolean inclState) { + String name = trace.getName(); + String threadClass = getTraceClassName(trace); + if (threadClass != null && threadClass.length() > 0) { + name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#composeEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public String composeEventName(ITimeEvent event) { + String name = event.getEntry().getName(); + String threadClass = getTraceClassName(event.getEntry()); + if (threadClass != null && threadClass.length() > 0) { + name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + name += " (" + getEventName(event) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public abstract Map getEventHoverToolTipInfo(ITimeEvent event); + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getItemImage(java.lang.Object) + */ + @Override + public Image getItemImage(Object obj) { + return null; + } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java deleted file mode 100644 index 453676064f..0000000000 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphProvider.java +++ /dev/null @@ -1,223 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010, 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 - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - * Patrick Tasse - Refactoring - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.Map; - -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphItem; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; - -public abstract class TimeGraphProvider implements ITimeGraphProvider { - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - public enum StateColor { - GREEN, DARK_BLUE, RED, GOLD, ORANGE, GRAY, BLACK, DARK_GREEN, DARK_YELLOW, MAGENTA3, PURPLE1, PINK1, AQUAMARINE, LIGHT_BLUE, CADET_BLUE, OLIVE; - - private String stateName; - - StateColor() { - String undef = "Undefined"; //$NON-NLS-1$ - this.stateName = undef; - } - - public String getStateName() { - return stateName; - } - - public void setStateName(String stateName) { - this.stateName = stateName; - } - } - - // ------------------------------------------------------------------------ - // Fields - // ------------------------------------------------------------------------ - - protected TimeGraphControl fTimeGraphControl; - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - public void setTimeGraphControl(TimeGraphControl timeGraphControl) { - fTimeGraphControl = timeGraphControl; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawItems(org.eclipse.swt.graphics.Rectangle, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider.Item[], int, int, org.eclipse.swt.graphics.GC) - */ - public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc) { - fTimeGraphControl.drawItems(bounds, timeProvider, items, topIndex, nameSpace, gc); - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawItem(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider.Item, org.eclipse.swt.graphics.Rectangle, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider, int, int, org.eclipse.swt.graphics.GC) - */ - @Override - public void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) { - fTimeGraphControl.drawItem(item, bounds, timeProvider, i, nameSpace, gc); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawState(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC, boolean, boolean, boolean) - */ - @Override - public void drawState(TimeGraphColorScheme colors, ITimeEvent event, - Rectangle rect, GC gc, boolean selected, boolean rectBound, - boolean timeSelected) { - int colorIdx = getEventColorVal(event); - drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected); - - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#drawState(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TraceColorScheme, int, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC, boolean, boolean, boolean) - */ - @Override - public void drawState(TimeGraphColorScheme colors, int colorIdx, - Rectangle rect, GC gc, boolean selected, boolean rectBound, - boolean timeSelected) { - fTimeGraphControl.drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventColorVal(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public int getEventColorVal(ITimeEvent event) { - StateColor colors = getEventColor(event); - if (colors == StateColor.GREEN) { - return TimeGraphColorScheme.GREEN_STATE; - } else if (colors == StateColor.DARK_BLUE) { - return TimeGraphColorScheme.DARK_BLUE_STATE; - } else if (colors == StateColor.RED) { - return TimeGraphColorScheme.RED_STATE; - } else if (colors == StateColor.GOLD) { - return TimeGraphColorScheme.GOLD_STATE; - } else if (colors == StateColor.ORANGE) { - return TimeGraphColorScheme.ORANGE_STATE; - } else if (colors == StateColor.GRAY) { - return TimeGraphColorScheme.GRAY_STATE; - } else if (colors == StateColor.DARK_GREEN) { - return TimeGraphColorScheme.DARK_GREEN_STATE; - } else if (colors == StateColor.DARK_YELLOW) { - return TimeGraphColorScheme.DARK_YELLOW_STATE; - } else if (colors == StateColor.MAGENTA3) { - return TimeGraphColorScheme.MAGENTA3_STATE; - } else if (colors == StateColor.PURPLE1) { - return TimeGraphColorScheme.PURPLE1_STATE; - } else if (colors == StateColor.PINK1) { - return TimeGraphColorScheme.PINK1_STATE; - } else if (colors == StateColor.AQUAMARINE) { - return TimeGraphColorScheme.AQUAMARINE_STATE; - } else if (colors == StateColor.LIGHT_BLUE) { - return TimeGraphColorScheme.LIGHT_BLUE_STATE; - } else if (colors == StateColor.CADET_BLUE) { - return TimeGraphColorScheme.CADET_BLUE_STATE_SEL; - } else if (colors == StateColor.OLIVE) { - return TimeGraphColorScheme.OLIVE_STATE; - } - - return TimeGraphColorScheme.BLACK_STATE; - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventColor(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public abstract StateColor getEventColor(ITimeEvent event); - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getTraceClassName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) - */ - @Override - public abstract String getTraceClassName(ITimeGraphEntry trace); - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public String getEventName(ITimeEvent event) { - return getEventName(event, true, false); - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, boolean, boolean) - */ - @Override - public abstract String getEventName(ITimeEvent event, boolean upper, - boolean extInfo); - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#composeTraceName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry, boolean) - */ - @Override - public String composeTraceName(ITimeGraphEntry trace, boolean inclState) { - String name = trace.getName(); - String threadClass = getTraceClassName(trace); - if (threadClass != null && threadClass.length() > 0) { - name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - return name; - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#composeEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public String composeEventName(ITimeEvent event) { - String name = event.getEntry().getName(); - String threadClass = getTraceClassName(event.getEntry()); - if (threadClass != null && threadClass.length() > 0) { - name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - name += " (" + getEventName(event, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - return name; - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public abstract Map getEventHoverToolTipInfo(ITimeEvent event); - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getItemImage(java.lang.Object) - */ - @Override - public Image getItemImage(Object obj) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider#getStateName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TmfTimeAnalysisProvider.StateColor) - */ - @Override - public abstract String getStateName(StateColor color); - -} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java index 914dbf3ef4..b5feb40abe 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -18,19 +18,27 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; import java.util.ArrayList; +import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; +import org.eclipse.linuxtools.internal.tmf.ui.Messages; +import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseWheelListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -68,7 +76,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { private Slider _verticalScrollBar; private TimeGraphTooltipHandler _threadTip; private TimeGraphColorScheme _colors; - private ITimeGraphProvider fTimeGraphProvider; + private ITimeGraphPresentationProvider fTimeGraphProvider; ArrayList fSelectionListeners = new ArrayList(); ArrayList fTimeListeners = new ArrayList(); @@ -80,6 +88,15 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { private int borderWidth = 4; private int timeScaleHeight = 22; + private Action resetScale; + private Action showLegendAction; + private Action nextEventAction; + private Action prevEventAction; + private Action nextItemAction; + private Action previousItemAction; + private Action zoomInAction; + private Action zoomOutAction; + /** ctor */ public TimeGraphViewer(Composite parent, int style) { createDataViewer(parent, style); @@ -90,13 +107,19 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { * * @param timeGraphProvider the timegraph provider */ - public void setTimeGraphProvider(ITimeGraphProvider timeGraphProvider) { + public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) { fTimeGraphProvider = timeGraphProvider; _stateCtrl.setTimeGraphProvider(timeGraphProvider); _threadTip = new TimeGraphTooltipHandler(_dataViewer.getShell(), fTimeGraphProvider, this); _threadTip.activateHoverHelp(_stateCtrl); } + /** + * Sets or clears the input for this time graph viewer. + * The input array should only contain top-level elements. + * + * @param input the input of this time graph viewer, or null if none + */ public void setInput(ITimeGraphEntry[] input) { if (null != _stateCtrl) { if (null == input) { @@ -110,8 +133,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } public void refresh() { - _stateCtrl.redraw(); - _timeScaleCtrl.redraw(); + setInput(_stateCtrl.getTraces()); } public void controlMoved(ControlEvent e) { @@ -138,9 +160,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } } - public void selectionChanged() { - } - protected String getViewTypeStr() { return "viewoption.threads"; //$NON-NLS-1$ } @@ -167,7 +186,13 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { protected Control createDataViewer(Composite parent, int style) { loadOptions(); _colors = new TimeGraphColorScheme(); - _dataViewer = new Composite(parent, style); + _dataViewer = new Composite(parent, style) { + @Override + public void redraw() { + _stateCtrl.redraw(); + super.redraw(); + } + }; GridLayout gl = new GridLayout(2, false); gl.marginHeight = borderWidth; gl.marginWidth = 0; @@ -195,6 +220,18 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { _stateCtrl.setTimeProvider(this); _stateCtrl.addSelectionListener(this); _stateCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2)); + _stateCtrl.addMouseWheelListener(new MouseWheelListener() { + @Override + public void mouseScrolled(MouseEvent e) { + adjustVerticalScrollBar(); + } + }); + _stateCtrl.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + adjustVerticalScrollBar(); + } + }); Composite filler = new Composite(_dataViewer, SWT.NONE); GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false); @@ -239,43 +276,27 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } /** Tries to set most convenient time range for display. */ - void setTimeRange(Object traces[]) { + public void setTimeRange(ITimeGraphEntry traces[]) { _endTime = 0; _beginTime = -1; - // ITimeEvent event; for (int i = 0; i < traces.length; i++) { - ITimeGraphEntry entry = (ITimeGraphEntry) traces[i]; - if (entry.getStopTime() >= entry.getStartTime() && entry.getStopTime() > 0) { + ITimeGraphEntry entry = traces[i]; + if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) { if (_beginTime < 0 || entry.getStartTime() < _beginTime) { _beginTime = entry.getStartTime(); } - if (entry.getStopTime() > _endTime) { - _endTime = entry.getStopTime(); + if (entry.getEndTime() > _endTime) { + _endTime = entry.getEndTime(); } } - /* - * This is not needed if entry startTime and stopTime are properly set! - List list = entry.getTraceEvents(); - int len = list.size(); - if (len > 0) { - event = (ITimeEvent) list.get(0); - if (_beginTime < 0 || event.getTime() < _beginTime) { - _beginTime = event.getTime(); - } - event = (ITimeEvent) list.get(list.size() - 1); - long eventEndTime = event.getTime() + (event.getDuration() > 0 ? event.getDuration() : 0); - if (eventEndTime > _endTime) { - _endTime = eventEndTime; - } - } - */ } - if (_beginTime < 0) + if (_beginTime < 0) { _beginTime = 0; + } } - void setTimeBounds() { + public void setTimeBounds() { //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02); _time0_ = _beginTime; if (_time0_ < 0) @@ -324,6 +345,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { _selectedTime = _endTime; } _stateCtrl.refreshData(traces); + _timeScaleCtrl.redraw(); adjustVerticalScrollBar(); } @@ -473,15 +495,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { @Override public void setSelectedTimeInt(long time, boolean ensureVisible) { - // Trace.debug("currentTime:" + _selectedTime + " new time:" + time); - if (time > _endTime) { - _endTime = time; - _time1_ = time; - } - if (time < _beginTime) { - _beginTime = time; - _time0_ = time; - } long time0 = _time0; long time1 = _time1; if (ensureVisible) { @@ -545,12 +558,12 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { adjustVerticalScrollBar(); } - public void selectNextTrace() { + public void selectNextItem() { _stateCtrl.selectNextTrace(); adjustVerticalScrollBar(); } - public void selectPrevTrace() { + public void selectPrevItem() { _stateCtrl.selectPrevTrace(); adjustVerticalScrollBar(); } @@ -641,10 +654,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { if (event == null || source == this) { return; } - ITimeGraphEntry trace = event.getEntry(); - if (trace != null) { - _stateCtrl.selectItem(trace, false); - } + _selectedEntry = event.getEntry(); + _stateCtrl.selectItem(_selectedEntry, false); setSelectedTimeInt(event.getTime(), true); adjustVerticalScrollBar(); @@ -654,15 +665,14 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { if (trace == null || source == this) { return; } - - if (trace != null) { - _stateCtrl.selectItem(trace, false); - } + _selectedEntry = trace; + _stateCtrl.selectItem(trace, false); setSelectedTimeInt(time, true); } public void setSelection(ITimeGraphEntry trace) { + _selectedEntry = trace; _stateCtrl.selectItem(trace, false); adjustVerticalScrollBar(); } @@ -819,7 +829,137 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { public void removeTreeListener(ITimeGraphTreeListener listener) { _stateCtrl.removeTreeListener(listener); } + + public Action getResetScaleAction() { + if (resetScale == null) { + // resetScale + resetScale = new Action() { + @Override + public void run() { + resetStartFinishTime(); + } + }; + resetScale.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText); + resetScale.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText); + resetScale.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU)); + } + return resetScale; + } + + public Action getShowLegendAction() { + if (showLegendAction == null) { + // showLegend + showLegendAction = new Action() { + @Override + public void run() { + showLegend(); + } + }; + showLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText); + showLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText); + showLegendAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND)); + } + + return showLegendAction; + } + + public Action getNextEventAction() { + if (nextEventAction == null) { + nextEventAction = new Action() { + @Override + public void run() { + selectNextEvent(); + } + }; + + nextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText); + nextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText); + nextEventAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT)); + } + + return nextEventAction; + } + + public Action getPreviousEventAction() { + if (prevEventAction == null) { + prevEventAction = new Action() { + @Override + public void run() { + selectPrevEvent(); + } + }; + + prevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText); + prevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText); + prevEventAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT)); + } + + return prevEventAction; + } + + public Action getNextItemAction() { + if (nextItemAction == null) { + nextItemAction = new Action() { + @Override + public void run() { + selectNextItem(); + } + }; + nextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText); + nextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText); + nextItemAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM)); + } + return nextItemAction; + } + + public Action getPreviousItemAction() { + if (previousItemAction == null) { + + previousItemAction = new Action() { + @Override + public void run() { + selectPrevItem(); + } + }; + previousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText); + previousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText); + previousItemAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM)); + } + return previousItemAction; + } + + public Action getZoomInAction() { + if (zoomInAction == null) { + zoomInAction = new Action() { + @Override + public void run() { + zoomIn(); + } + }; + zoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText); + zoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText); + zoomInAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU)); + } + return zoomInAction; + } + + public Action getZoomOutAction() { + if (zoomOutAction == null) { + zoomOutAction = new Action() { + @Override + public void run() { + zoomOut(); + } + }; + zoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText); + zoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText); + zoomOutAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU)); + } + return zoomOutAction; + } + + private void adjustVerticalScrollBar() { int topIndex = _stateCtrl.getTopIndex(); int countPerPage = _stateCtrl.countPerPage(); @@ -836,5 +976,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { int pageIncrement = Math.max(1, countPerPage); _verticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement); } + + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java index c8668b76de..8d4cf0165d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/dialogs/TimeGraphLegend.java @@ -15,19 +15,22 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -37,22 +40,17 @@ import org.eclipse.swt.widgets.Shell; public class TimeGraphLegend extends TitleAreaDialog { - public static final int interactionColors[] = { - TimeGraphColorScheme.TI_START_THREAD, - TimeGraphColorScheme.TI_NOTIFY_JOINED, TimeGraphColorScheme.TI_NOTIFY, - TimeGraphColorScheme.TI_INTERRUPT, TimeGraphColorScheme.TI_HANDOFF_LOCK }; + private ITimeGraphPresentationProvider provider; + private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources()); - protected TimeGraphColorScheme colors; - private ITimeGraphProvider ifUtil; - - public static void open(Shell parent, ITimeGraphProvider rifUtil) { - (new TimeGraphLegend(parent, rifUtil)).open(); + public static void open(Shell parent, ITimeGraphPresentationProvider provider) { + (new TimeGraphLegend(parent, provider)).open(); } - public TimeGraphLegend(Shell parent, ITimeGraphProvider rifUtil) { + public TimeGraphLegend(Shell parent, ITimeGraphPresentationProvider provider) { super(parent); - colors = new TimeGraphColorScheme(); - this.ifUtil = rifUtil; + this.provider = provider; + this.setShellStyle(getShellStyle()); } @Override @@ -66,19 +64,18 @@ public class TimeGraphLegend extends TitleAreaDialog { GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(gd); - createThreadStatesGroup(composite); + createStatesGroup(composite); - setMessage(Messages.TmfTimeLegend_LEGEND); - setTitle(Messages.TmfTimeLegend_TRACE_STATES_TITLE); + setTitle(Messages.TmfTimeLegend_LEGEND); setDialogHelpAvailable(false); setHelpAvailable(false); return composite; } - private void createThreadStatesGroup(Composite composite) { + private void createStatesGroup(Composite composite) { Group gs = new Group(composite, SWT.NONE); - gs.setText(Messages.TmfTimeLegend_TRACE_STATES); + gs.setText(provider.getStateTypeName()); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gs.setLayoutData(gd); @@ -88,35 +85,35 @@ public class TimeGraphLegend extends TitleAreaDialog { layout.marginBottom = 10; gs.setLayout(layout); - // Go through all the defined colors and only add the ones you need. - // This will not handle several colors assigned to a color, we have - // 16 mil colors, and should not pick two to mean the same thing. - for (int i = 0; i < TimeGraphColorScheme.getStateColors().length; i++) { - //Get the color enum related to the index - StateColor stateColor = TimeGraphColorScheme.getStateColors()[i]; + // Go through all the defined pairs of state color and state name and display them. + StateItem[] stateItems = provider.getStateTable(); + for (int i = 0; i < stateItems.length; i++) { + //Get the color related to the index + RGB rgb = stateItems[i].getStateColor(); + //Get the given name, provided by the interface to the application - String stateName = ifUtil.getStateName(stateColor); - if( stateName != "Not mapped" ) { //$NON-NLS-1$ - Bar bar = new Bar(gs, i); - gd = new GridData(); - gd.widthHint = 40; - gd.heightHint = 20; - gd.verticalIndent = 8; - bar.setLayoutData(gd); - Label name = new Label(gs, SWT.NONE); - name.setText(stateName); - gd = new GridData(); - gd.horizontalIndent = 10; - gd.verticalIndent = 8; - name.setLayoutData(gd); - } + String stateName = stateItems[i].getStateString(); + + // draw color with name + Bar bar = new Bar(gs, rgb); + gd = new GridData(); + gd.widthHint = 40; + gd.heightHint = 20; + gd.verticalIndent = 8; + bar.setLayoutData(gd); + Label name = new Label(gs, SWT.NONE); + name.setText(stateName); + gd = new GridData(); + gd.horizontalIndent = 10; + gd.verticalIndent = 8; + name.setLayoutData(gd); } } @Override protected void configureShell(Shell shell) { super.configureShell(shell); - shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE); + shell.setText(Messages.TmfTimeLegend_TRACE_STATES_TITLE); } @Override @@ -128,10 +125,10 @@ public class TimeGraphLegend extends TitleAreaDialog { class Bar extends Canvas { private Color color; - public Bar(Composite parent, int colorIdx) { + public Bar(Composite parent, RGB rgb) { super(parent, SWT.NONE); - color = colors.getColor(colorIdx); + color = fResourceManager.createColor(rgb); addListener(SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { @@ -144,73 +141,16 @@ public class TimeGraphLegend extends TitleAreaDialog { Rectangle r = getClientArea(); gc.setBackground(color); gc.fillRectangle(r); - gc.setForeground(colors.getColor(TimeGraphColorScheme.BLACK)); + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); gc.drawRectangle(0, 0, r.width - 1, r.height - 1); } - } - - class Arrow extends Canvas { - public final static int HEIGHT = 12; - public final static int DX = 3; - - private Color color; - - public Arrow(Composite parent, int colorIdx) { - super(parent, SWT.NONE); - color = colors.getColor(colorIdx); - addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - draw(event.gc); - } - }); + @Override + public void dispose() { + super.dispose(); + color.dispose(); } - private void draw(GC gc) { - Rectangle r = getClientArea(); - gc.setForeground(color); - - int y0, y1; - if (r.height > HEIGHT) { - y0 = (r.height - HEIGHT) / 2; - y1 = y0 + HEIGHT; - } else { - y0 = 0; - y1 = r.height; - } - - gc.drawLine(DX, y0, DX, y1); - - gc.drawLine(0, y0 + 3, DX, y0); - gc.drawLine(2 * DX, y0 + 3, DX, y0); - } } - class Mark extends Canvas { - public final static int DX = 3; - - private Color color; - - public Mark(Composite parent, int colorIdx) { - super(parent, SWT.NONE); - - color = colors.getColor(colorIdx); - addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - draw(event.gc); - } - }); - } - - private void draw(GC gc) { - Rectangle r = getClientArea(); - gc.setBackground(color); - - int y = (r.height - DX) / 2; - int c[] = { 0, y, DX, y + DX, 2 * DX, y }; - gc.fillPolygon(c); - } - } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java index e34ef01528..ca86ce90d7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/ITimeGraphEntry.java @@ -54,11 +54,11 @@ public interface ITimeGraphEntry { public long getStartTime(); /** - * Returns the stop time of this entry in nanoseconds. + * Returns the end time of this entry in nanoseconds. * - * @return the stop time + * @return the end time */ - public long getStopTime(); + public long getEndTime(); /** * Get an iterator which returns all timeevents diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java index d974b4bb32..c6abcedfa3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphBaseControl.java @@ -27,7 +27,7 @@ public abstract class TimeGraphBaseControl extends Canvas implements PaintListen static public final int MARGIN = 4; static public final int EXPAND_SIZE = 9; // the [+] or [-] control size - static public final int RIGHT_MARGIN = 2; // 2 pixels less to make sure end time is visible + static public final int RIGHT_MARGIN = 1; // 1 pixels less to make sure end time is visible static public final int SMALL_ICON_SIZE = 16; protected TimeGraphColorScheme _colors; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java index 3572c98e9b..ebd35f5749 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphColorScheme.java @@ -15,7 +15,6 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; @@ -43,13 +42,6 @@ public class TimeGraphColorScheme { static public final int STATES0 = 0; static public final int STATES1 = 15; - // State element index to name mapping, must keep the same order as above - public static final StateColor stateColors[] = { StateColor.BLACK, - StateColor.GREEN, StateColor.DARK_BLUE, StateColor.ORANGE, - StateColor.GOLD, StateColor.RED, StateColor.GRAY, StateColor.DARK_GREEN, StateColor.DARK_YELLOW, StateColor.MAGENTA3, StateColor.PURPLE1, - StateColor.PINK1, StateColor.AQUAMARINE, StateColor.LIGHT_BLUE, StateColor.CADET_BLUE, StateColor.OLIVE - }; - // selected state elements color indices static public final int BLACK_STATE_SEL = 16; static public final int GREEN_STATE_SEL = 17; @@ -369,8 +361,4 @@ public class TimeGraphColorScheme { return getColor(GR_FOREGROUND_SEL_NOFOCUS); return getColor(GR_FOREGROUND); } - - public static StateColor[] getStateColors() { - return stateColors; - } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java index c49332aead..baf6824271 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -20,11 +20,14 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTreeListener; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTreeExpansionEvent; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; @@ -45,12 +48,14 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.ScrollBar; @@ -64,6 +69,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe public static final boolean DEFAULT_DRAW_THREAD_WAIT = true; public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true; public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1; + private static final int CUSTOM_ITEM_HEIGHT = -1; // get item height from provider private static final double zoomCoeff = 1.5; @@ -72,8 +78,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe private boolean _isDragCursor3 = false; private boolean _isWaitCursor = true; private boolean _mouseOverSplitLine = false; - private int _itemHeightDefault = 19; - private int _itemHeight = _itemHeightDefault; + private int _itemHeight = CUSTOM_ITEM_HEIGHT; private int _minimumItemWidth = 0; private int _topIndex = 0; private int _dragState = DRAG_NONE; @@ -83,7 +88,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe // private double _timeStep = 10000000; private long _time0bak; private long _time1bak; - private ITimeGraphProvider fTimeGraphProvider = null; + private ITimeGraphPresentationProvider fTimeGraphProvider = null; private ItemData _data = null; private List _selectionListeners; private List _selectionChangedListeners = new ArrayList(); @@ -98,6 +103,9 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe private Listener mouseScrollFilterListener; + protected LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources()); + protected Color[] fEventColorMap = null; + public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) { super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.DOUBLE_BUFFERED); @@ -127,6 +135,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe super.dispose(); _dragCursor3.dispose(); _WaitCursor.dispose(); + fResourceManager.dispose(); } /** @@ -134,9 +143,30 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe * * @param timeGraphProvider the timegraph provider */ - public void setTimeGraphProvider(ITimeGraphProvider timeGraphProvider) { + public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) { fTimeGraphProvider = timeGraphProvider; - fTimeGraphProvider.setTimeGraphControl(this); + _data.provider = timeGraphProvider; +// RGB[] eventColorTable = fTimeGraphProvider.getEventColorTable(); +// if (eventColorTable != null) { +// fEventColorMap = new Color[eventColorTable.length]; +// for (int i = 0; i < eventColorTable.length; i++) { +// fEventColorMap[i] = fResourceManager.createColor(eventColorTable[i]); +// } +// } else { +// fEventColorMap = new Color[] { }; +// } + + StateItem[] stateItems = fTimeGraphProvider.getStateTable(); + if (stateItems != null) { + fEventColorMap = new Color[stateItems.length]; + for (int i = 0; i < stateItems.length; i++) { + fEventColorMap[i] = fResourceManager.createColor(stateItems[i].getStateColor()); + } + } else { + fEventColorMap = new Color[] { }; + } + + } public void setTimeProvider(ITimeDataProvider timeProvider) { @@ -178,7 +208,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } } - public Object[] getTraces() { + public ITimeGraphEntry[] getTraces() { return _data.getTraces(); } @@ -240,7 +270,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe if (idx >= _data._expandedItems.length) return changed; if (idx < _topIndex) { - _topIndex = idx; + setTopIndex(idx); //FIXME:getVerticalBar().setSelection(_topItem); if (redraw) redraw(); @@ -248,7 +278,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } else { int page = countPerPage(); if (idx >= _topIndex + page) { - _topIndex = idx - page + 1; + setTopIndex(idx - page + 1); //FIXME:getVerticalBar().setSelection(_topItem); if (redraw) redraw(); @@ -570,6 +600,16 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe if (y < 0) { return -1; } + if (_itemHeight == CUSTOM_ITEM_HEIGHT) { + int ySum = 0; + for (int idx = _topIndex; idx < _data._expandedItems.length; idx++) { + ySum += _data._expandedItems[idx].itemHeight; + if (y < ySum) { + return idx; + } + } + return -1; + } int idx = y / _itemHeight; idx += _topIndex; if (idx < _data._expandedItems.length) { @@ -647,8 +687,27 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe public int countPerPage() { int height = getCtrlSize().y; int count = 0; - if (height > 0) + if (_itemHeight == CUSTOM_ITEM_HEIGHT) { + int ySum = 0; + for (int idx = _topIndex; idx < _data._expandedItems.length; idx++) { + ySum += _data._expandedItems[idx].itemHeight; + if (ySum >= height) { + return count; + } + count++; + } + for (int idx = _topIndex - 1; idx >= 0; idx--) { + ySum += _data._expandedItems[idx].itemHeight; + if (ySum >= height) { + return count; + } + count++; + } + return count; + } + if (height > 0) { count = height / _itemHeight; + } return count; } @@ -669,45 +728,37 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } Rectangle getNameRect(Rectangle bound, int idx, int nameWidth) { - idx -= _topIndex; int x = bound.x; - int y = bound.y + idx * _itemHeight; + int y = bound.y + (idx - _topIndex) * _itemHeight; int width = nameWidth; int height = _itemHeight; + if (_itemHeight == CUSTOM_ITEM_HEIGHT) { + int ySum = 0; + for (int i = _topIndex; i < idx; i++) { + ySum += _data._expandedItems[i].itemHeight; + } + y = bound.y + ySum; + height = _data._expandedItems[idx].itemHeight; + } return new Rectangle(x, y, width, height); } Rectangle getStatesRect(Rectangle bound, int idx, int nameWidth) { - idx -= _topIndex; int x = bound.x + nameWidth; - int y = bound.y + idx * _itemHeight; + int y = bound.y + (idx - _topIndex) * _itemHeight; int width = bound.width - x; int height = _itemHeight; + if (_itemHeight == CUSTOM_ITEM_HEIGHT) { + int ySum = 0; + for (int i = _topIndex; i < idx; i++) { + ySum += _data._expandedItems[i].itemHeight; + } + y = bound.y + ySum; + height = _data._expandedItems[idx].itemHeight; + } return new Rectangle(x, y, width, height); } - public void drawTraceEvent(Rectangle bound, ITimeEvent e, int nItem, int color, GC gc) { - int nameWidth = _timeProvider.getNameSpace(); - - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - if (time0 == time1) - return; - - int xr = bound.x + nameWidth; - double pixelsPerNanoSec = (bound.width - xr <= RIGHT_MARGIN) ? 0 : (double) (bound.width - xr - RIGHT_MARGIN) / (time1 - time0); - - int x0 = xr + (int) ((e.getTime() - time0) * pixelsPerNanoSec); - if (x0 < xr) - return; - - int y0 = bound.y + (nItem - _topIndex) * _itemHeight + 3; - - gc.setBackground(_colors.getColor(color)); - int c[] = { x0 - 3, y0 - 3, x0, y0, x0 + 3, y0 - 3 }; - gc.fillPolygon(c); - } - @Override void paint(Rectangle bounds, PaintEvent e) { GC gc = e.gc; @@ -721,13 +772,10 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe int nameSpace = _timeProvider.getNameSpace(); // draw empty name space background - int nbDrawn = _data._expandedItems.length - _topIndex; - if (_itemHeight * nbDrawn < bounds.height) { - gc.setBackground(_colors.getBkColor(false, false, true)); - drawBackground(gc, bounds.x, _itemHeight * nbDrawn, nameSpace, bounds.height - _itemHeight * nbDrawn); - } + gc.setBackground(_colors.getBkColor(false, false, true)); + drawBackground(gc, bounds.x, bounds.y, nameSpace, bounds.height); - fTimeGraphProvider.drawItems(bounds, _timeProvider, _data._expandedItems, _topIndex, nameSpace, gc); + drawItems(bounds, _timeProvider, _data._expandedItems, _topIndex, nameSpace, gc); // draw selected time long time0 = _timeProvider.getTime0(); @@ -751,11 +799,11 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc) { - // draw trace states for (int i = topIndex; i < items.length; i++) { TimeGraphItem item = (TimeGraphItem) items[i]; - fTimeGraphProvider.drawItem(item, bounds, timeProvider, i, nameSpace, gc); + drawItem(item, bounds, timeProvider, i, nameSpace, gc); } + fTimeGraphProvider.postDrawControl(bounds, gc); } /** @@ -767,10 +815,10 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe * @param nameSpace the name space * @param gc */ - public void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) { + protected void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) { + ITimeGraphEntry entry = item._trace; long time0 = timeProvider.getTime0(); long time1 = timeProvider.getTime1(); - long endTime = timeProvider.getEndTime(); long selectedTime = timeProvider.getSelectedTime(); Rectangle nameRect = getNameRect(bounds, i, nameSpace); @@ -786,11 +834,14 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe drawName(item, nameRect, gc); } Rectangle rect = getStatesRect(bounds, i, nameSpace); - if (rect.isEmpty()) + if (rect.isEmpty()) { + fTimeGraphProvider.postDrawEntry(entry, bounds, gc); return; + } if (time1 <= time0) { gc.setBackground(_colors.getBkColor(false, false, false)); gc.fillRectangle(rect); + fTimeGraphProvider.postDrawEntry(entry, bounds, gc); return; } @@ -802,99 +853,45 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe boolean group = item._trace.getTimeEventsIterator() == null; - if (group) { - // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); - // gc.fillRectangle(rect); - } else { - ITimeGraphEntry trace = item._trace; - - double x0 = rect.x; - long maxDuration = (timeProvider.getTimeSpace() == 0) ? Long.MAX_VALUE : 1 * (time1 - time0) / timeProvider.getTimeSpace(); - Iterator iterator = trace.getTimeEventsIterator(time0, time1, maxDuration); + if (!group) { + fillSpace(rect, gc, selected); // Drawing rectangle is smaller than reserved space stateRect.y += 3; stateRect.height -= 6; - // Clean up to empty line to draw on top - int xEnd = rect.x + rect.width; - fillSpace(rect, gc, selected); - if (iterator.hasNext()) { - ITimeEvent currEvent = iterator.next(); - ITimeEvent nextEvent = null; - long currEventTime = currEvent.getTime(); - long currEventDuration = currEvent.getDuration(); - // initial value - long nextEventTime = currEventTime; - // x0 - Points to the beginning of the event being drawn - double step = (double) ((currEventTime - time0) * pixelsPerNanoSec); - x0 = rect.x + step; - // xEnd - Points to the end of the events rectangle - double x1 = -1; - double xNext = 0; - - // draw event states - while (/* x0 <= xEnd && */null != currEvent) { - boolean stopped = false;// currEvent instanceof - // refresh current event duration as the loop moves - currEventDuration = currEvent.getDuration(); - // TsfTmTraceDeadEvent; - if (iterator.hasNext()) { - nextEvent = iterator.next(); - nextEventTime = nextEvent.getTime(); - } else if (stopped) { - nextEvent = null; - nextEventTime = time1; - } else { - nextEvent = null; - nextEventTime = endTime; - } - - // Calculate position to next event - xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - - // Calculate end position of current event - if (currEventDuration < 0) { - x1 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); - } else if (currEventDuration == 0) { - x1 = x0; - } else { - x1 = x0 + (double) ((currEventDuration) * pixelsPerNanoSec); - } - - // If event end position x1 further away than start position - // of next event, cut width till next event - if (currEventDuration != 0) { - x1 = x1 > xNext ? xNext : x1; - } - // if event end boundary is within time range - if (x1 >= rect.x && x0 <= xEnd) { - if (currEventDuration != 0) { - x0 = (double) (x0 >= rect.x ? x0 : rect.x); - stateRect.width = (int) ((x1 <= xEnd ? x1 : xEnd) - x0); - } else { - stateRect.width = 1; - } - stateRect.width = Math.max(getMinimumItemWidth(), stateRect.width); - stateRect.x = (int) x0; - boolean timeSelected = currEventTime <= selectedTime && selectedTime < nextEventTime; - fTimeGraphProvider.drawState(_colors, currEvent, stateRect, gc, selected, false, timeSelected); - // Advance rectangle to next start position and Fill - // with space until next event - stateRect.x += stateRect.width; - x0 = stateRect.x; + long maxDuration = (timeProvider.getTimeSpace() == 0) ? Long.MAX_VALUE : 1 * (time1 - time0) / timeProvider.getTimeSpace(); + Iterator iterator = entry.getTimeEventsIterator(time0, time1, maxDuration); + + int lastX = -1; + while (iterator.hasNext()) { + ITimeEvent event = iterator.next(); + int x = rect.x + (int) ((event.getTime() - time0) * pixelsPerNanoSec); + int xEnd = rect.x + (int) ((event.getTime() + event.getDuration() - time0) * pixelsPerNanoSec); + if (x >= rect.x + rect.width || xEnd < rect.x) { + // event is out of bounds + continue; + } + xEnd = Math.min(rect.x + rect.width, xEnd); + stateRect.x = Math.max(rect.x, x); + stateRect.width = Math.max(0, xEnd - stateRect.x + 1); + if (stateRect.x == lastX) { + stateRect.width -= 1; + if (stateRect.width > 0) { + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); + gc.drawPoint(stateRect.x, stateRect.y - 2); + stateRect.x += 1; } - - // lastEvent = currEvent; - currEvent = nextEvent; - currEventTime = nextEventTime; - // Move x0 to the beginning of next event - x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec); + } else { + lastX = x; } + boolean timeSelected = selectedTime >= event.getTime() && selectedTime < event.getTime() + event.getDuration(); + drawState(_colors, event, stateRect, gc, selected, timeSelected); } } + fTimeGraphProvider.postDrawEntry(entry, bounds, gc); } - void drawName(TimeGraphItem item, Rectangle bounds, GC gc) { + protected void drawName(TimeGraphItem item, Rectangle bounds, GC gc) { boolean group = item._trace.getTimeEventsIterator() == null; if (group) { gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus)); @@ -967,7 +964,8 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe rect.width -= leftMargin; // draw text if (rect.width > 0) { - rect.y += 2; + rect.y += (bounds.height - gc.stringExtent(name).y) / 2; + gc.setForeground(_colors.getFgColor(item._selected, _isInFocus)); int textWidth = Utils.drawText(gc, name, rect, true); leftMargin += textWidth + MARGIN; rect.y -= 2; @@ -983,64 +981,71 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } } - public void drawState(TimeGraphColorScheme colors, int colorIdx, - Rectangle rect, GC gc, boolean selected, boolean rectBound, - boolean timeSelected) { + protected void drawState(TimeGraphColorScheme colors, ITimeEvent event, + Rectangle rect, GC gc, boolean selected, boolean timeSelected) { - boolean visible = rect.width == 0 ? false : true; - int colorIdx1 = colorIdx; - - timeSelected = timeSelected && selected; - if (timeSelected) { - colorIdx1 = colorIdx + TimeGraphColorScheme.STATES_SEL0 - TimeGraphColorScheme.STATES0; + int colorIdx = fTimeGraphProvider.getEventTableIndex(event); + if (colorIdx < 0) { + return; } + boolean visible = rect.width == 0 ? false : true; if (visible) { + Color stateColor = null; + if (colorIdx < fEventColorMap.length) { + stateColor = fEventColorMap[colorIdx]; + } else { + stateColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + } + + timeSelected = timeSelected && selected; + if (timeSelected) { + // modify the color? + } // fill all rect area - if (rect.isEmpty()) - return; - - gc.setBackground(colors.getColor(colorIdx1)); + gc.setBackground(stateColor); gc.fillRectangle(rect); - colorIdx1 = colorIdx + TimeGraphColorScheme.STATES_BORDER0 - TimeGraphColorScheme.STATES0; - gc.setForeground(colors.getColor(colorIdx1)); + // get the border color? + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); // draw bounds if (!timeSelected) { - if (rectBound && rect.width >= 3) { - gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); - } else { - // Draw the top and bottom borders i.e. no side borders - // top - gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y); - // bottom - gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1); - } + // Draw the top and bottom borders i.e. no side borders + // top + gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y); + // bottom + gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1); } } else { + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); + gc.drawPoint(rect.x, rect.y - 2); + /* // selected rectangle area is not visible but can be represented // with a broken vertical line of specified width. - int width = 2; + int width = 1; rect.width = width; - // check if height is greater than zero. - if (rect.isEmpty()) - return; - // colorIdx1 = TraceColorScheme.BLACK; - gc.setForeground(colors.getColor(colorIdx)); + gc.setForeground(stateColor); int s = gc.getLineStyle(); int w = gc.getLineWidth(); gc.setLineStyle(SWT.LINE_DOT); gc.setLineWidth(width); - // Trace.debug("Reactangle not visible, drawing vertical line with: " + // Trace.debug("Rectangle not visible, drawing vertical line with: " // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y // + rect.height); - gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height); + gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height - 1); gc.setLineStyle(s); gc.setLineWidth(w); + if (!timeSelected) { + gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); + gc.drawPoint(rect.x, rect.y); + gc.drawPoint(rect.x, rect.y + rect.height - 1); + } + */ } + fTimeGraphProvider.postDrawEvent(event, rect, gc); } - private void fillSpace(Rectangle rect, GC gc, boolean selected) { + protected void fillSpace(Rectangle rect, GC gc, boolean selected) { gc.setBackground(_colors.getBkColor(selected, _isInFocus, false)); gc.fillRectangle(rect); // draw middle line @@ -1138,6 +1143,52 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe return _isInFocus; } + /** + * Provide the possibilty to control the wait cursor externally e.g. data + * requests in progress + * + * @param waitInd + */ + public void waitCursor(boolean waitInd) { + // Update cursor as indicated + if (waitInd) { + setCursor(_WaitCursor); + _isWaitCursor = true; + } else { + setCursor(null); + _isWaitCursor = false; + } + + // Get ready for next mouse move + _isDragCursor3 = false; + } + + /** + *

+ * If the x, y position is over the vertical split line (name to time + * ranges), then change the cursor to a drag cursor to indicate the user the + * possibility of resizing + *

+ * + * @param x + * @param y + */ + void updateCursor(int x, int y) { + // if Wait cursor not active, check for the need to change to a drag + // cursor + if (_isWaitCursor == false) { + boolean isSplitLine = isOverSplitLine(x); + // No dragcursor is name space is fixed to zero + if (isSplitLine && !_isDragCursor3 && _timeProvider.getNameSpace() > 0) { + setCursor(_dragCursor3); + _isDragCursor3 = true; + } else if (!isSplitLine && _isDragCursor3) { + setCursor(null); + _isDragCursor3 = false; + } + } + } + @Override public void mouseMove(MouseEvent e) { if (null == _timeProvider) @@ -1200,52 +1251,6 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } } - /** - *

- * If the x, y position is over the vertical split line (name to time - * ranges), then change the cursor to a drag cursor to indicate the user the - * possibility of resizing - *

- * - * @param x - * @param y - */ - void updateCursor(int x, int y) { - // if Wait cursor not active, check for the need to change to a drag - // cursor - if (_isWaitCursor == false) { - boolean isSplitLine = isOverSplitLine(x); - // No dragcursor is name space is fixed to zero - if (isSplitLine && !_isDragCursor3 && _timeProvider.getNameSpace() > 0) { - setCursor(_dragCursor3); - _isDragCursor3 = true; - } else if (!isSplitLine && _isDragCursor3) { - setCursor(null); - _isDragCursor3 = false; - } - } - } - - /** - * Provide the possibilty to control the wait cursor externally e.g. data - * requests in progress - * - * @param waitInd - */ - public void waitCursor(boolean waitInd) { - // Update cursor as indicated - if (waitInd) { - setCursor(_WaitCursor); - _isWaitCursor = true; - } else { - setCursor(null); - _isWaitCursor = false; - } - - // Get ready for next mouse move - _isDragCursor3 = false; - } - @Override public void mouseDown(MouseEvent e) { if (null == _timeProvider) @@ -1309,50 +1314,6 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } } - @Override - public void controlMoved(ControlEvent e) { - } - - @Override - public void controlResized(ControlEvent e) { - adjustScrolls(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - - @Override - public void widgetSelected(SelectionEvent e) { - if (e.widget == getVerticalBar()) { - _topIndex = getVerticalBar().getSelection(); - if (_topIndex < 0) - _topIndex = 0; - redraw(); - } else if (e.widget == getHorizontalBar() && null != _timeProvider) { - int start = getHorizontalBar().getSelection(); - long time0 = _timeProvider.getTime0(); - long time1 = _timeProvider.getTime1(); - long timeMin = _timeProvider.getMinTime(); - long timeMax = _timeProvider.getMaxTime(); - long delta = timeMax - timeMin; - - long range = time1 - time0; - // _timeRangeFixed = true; - time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX)); - time1 = time0 + range; - - // TODO: Follow-up with Bug 310310 - // In Linux SWT.DRAG is the only value received - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310 - if (e.detail == SWT.DRAG) { - _timeProvider.setStartFinishTime(time0, time1); - } else { - _timeProvider.setStartFinishTimeNotify(time0, time1); - } - } - } - @Override public void mouseEnter(MouseEvent e) { if (mouseScrollFilterListener == null) { @@ -1389,9 +1350,9 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe if ((mouseScrollFilterListener == null) || _dragState != DRAG_NONE) { return; } - if (e.x < _timeProvider.getNameSpace()) { + if (e.x < _timeProvider.getNameSpace() || e.x > getSize().x) { setTopIndex(getTopIndex() - e.count); - } else { + } else if (_timeProvider.getTime0() != _timeProvider.getTime1()) { if (e.count > 0) { zoom(true); } else if (e.count < 0) { @@ -1400,6 +1361,47 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe } } + @Override + public void controlMoved(ControlEvent e) { + } + + @Override + public void controlResized(ControlEvent e) { + adjustScrolls(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + + @Override + public void widgetSelected(SelectionEvent e) { + if (e.widget == getVerticalBar()) { + setTopIndex(getVerticalBar().getSelection()); + } else if (e.widget == getHorizontalBar() && null != _timeProvider) { + int start = getHorizontalBar().getSelection(); + long time0 = _timeProvider.getTime0(); + long time1 = _timeProvider.getTime1(); + long timeMin = _timeProvider.getMinTime(); + long timeMax = _timeProvider.getMaxTime(); + long delta = timeMax - timeMin; + + long range = time1 - time0; + // _timeRangeFixed = true; + time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX)); + time1 = time0 + range; + + // TODO: Follow-up with Bug 310310 + // In Linux SWT.DRAG is the only value received + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310 + if (e.detail == SWT.DRAG) { + _timeProvider.setStartFinishTime(time0, time1); + } else { + _timeProvider.setStartFinishTimeNotify(time0, time1); + } + } + } + public boolean isVisibleVerticalScroll() { return _visibleVerticalScroll; } @@ -1481,6 +1483,7 @@ class ItemData { private ITimeGraphEntry _traces[] = new ITimeGraphEntry[0]; private boolean traceFilter[] = new boolean[0]; private Vector filteredOut = new Vector(); + public ITimeGraphPresentationProvider provider; public ItemData() { } @@ -1529,6 +1532,7 @@ class ItemData { if (parent != null) { parent.children.add(item); } + item.itemHeight = provider.getItemHeight(entry); itemList.add(item); if (entry.hasChildren()) { item._expanded = true; @@ -1580,7 +1584,7 @@ class ItemData { refreshData(); } - public Object[] getTraces() { + public ITimeGraphEntry[] getTraces() { return _traces; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java index c93643b009..5cf98121ee 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphItem.java @@ -21,6 +21,7 @@ public class TimeGraphItem { public boolean _expanded; public boolean _selected; public boolean _hasChildren; + public int itemHeight; public int level; public List children; public String _name; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java index 4a1d96d842..00574caf6d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java @@ -31,8 +31,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; -public class TimeGraphScale extends TimeGraphBaseControl implements MouseListener, -MouseMoveListener { +public class TimeGraphScale extends TimeGraphBaseControl implements MouseListener, MouseMoveListener { public TimeGraphScale(Composite parent, TimeGraphColorScheme colors) { super(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS @@ -358,20 +357,20 @@ MouseMoveListener { } } - // Trace.debug("timeRange: " + timeRange + " numDigits: " + numDigits); return numDigits; } @Override public void mouseDown(MouseEvent e) { + getParent().setFocus(); if (_dragState == 0 && null != _timeProvider) { - if (1 == e.button) { + int x = e.x - _timeProvider.getNameSpace(); + if (1 == e.button && x > 0) { setCapture(true); _dragState = 1; } else if (3 == e.button) { _dragState = 3; } - int x = e.x - _timeProvider.getNameSpace(); if (x < 0) { x = 0; } else if (x > getSize().x - _timeProvider.getNameSpace()) { @@ -390,12 +389,12 @@ MouseMoveListener { _dragState = 0; // Notify time provider to check the need for listener notification - if (_dragX != _dragX0) { + if (_dragX != _dragX0 && _timeProvider.getTime0() != _timeProvider.getTime1()) { _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1()); } } else if (e.button == 3 && _dragState == 3 && null != _timeProvider) { _dragState = 0; - if (_dragX0 == _dragX) { + if (_dragX0 == _dragX || _timeProvider.getTime0() == _timeProvider.getTime1()) { return; } int timeSpace = _timeProvider.getTimeSpace(); @@ -429,6 +428,9 @@ MouseMoveListener { if (1 == _dragState) { if (x > 0 && size.x > leftSpace && _dragX != x) { _dragX = x; + if (_timeProvider.getTime0() == _timeProvider.getTime1()) { + return; + } long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX)); _timeProvider.setStartFinishTime(_time0bak, time1); } @@ -446,7 +448,7 @@ MouseMoveListener { @Override public void mouseDoubleClick(MouseEvent e) { - if (null != _timeProvider) { + if (null != _timeProvider && _timeProvider.getTime0() != _timeProvider.getTime1()) { _timeProvider.resetStartFinishTime(); _time0bak = _timeProvider.getTime0(); _time1bak = _timeProvider.getTime1(); @@ -462,7 +464,7 @@ abstract class TimeDraw { protected static final SimpleDateFormat stimeformatheader = new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$ protected static final SimpleDateFormat sminformat = new SimpleDateFormat("HH:mm"); //$NON-NLS-1$ protected static final SimpleDateFormat sminformatheader = new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$ - protected static final SimpleDateFormat shrsformat = new SimpleDateFormat("MMM dd HH:mm"); //$NON-NLS-1$ + protected static final SimpleDateFormat shrsformat = new SimpleDateFormat("MMM dd HH:mm"); //$NON-NLS-1$ protected static final SimpleDateFormat shrsformatheader = new SimpleDateFormat("yyyy"); //$NON-NLS-1$ protected static final SimpleDateFormat sdayformat = new SimpleDateFormat("MMM dd"); //$NON-NLS-1$ protected static final SimpleDateFormat sdayformatheader = new SimpleDateFormat("yyyy"); //$NON-NLS-1$ @@ -698,7 +700,7 @@ class TimeDrawAbsMillisec extends TimeDraw { String stime = stimeformat.format(new Date((long) (time / 1000000))); String ns = Utils.formatNs(time, Resolution.MILLISEC); - Utils.drawText(gc, stime + " " + ns, rect, true); //$NON-NLS-1$ + Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$ } @Override @@ -724,7 +726,7 @@ class TimeDrawAbsMicroSec extends TimeDraw { public void draw(GC gc, long time, Rectangle rect) { String stime = stimeformat.format(new Date((long) (time / 1000000))); String micr = Utils.formatNs(time, Resolution.MICROSEC); - Utils.drawText(gc, stime + " " + micr, rect, true); //$NON-NLS-1$ + Utils.drawText(gc, stime + "." + micr, rect, true); //$NON-NLS-1$ } @Override @@ -750,7 +752,7 @@ class TimeDrawAbsNanoSec extends TimeDraw { public void draw(GC gc, long time, Rectangle rect) { String stime = stimeformat.format(new Date((long) (time / 1000000))); String ns = Utils.formatNs(time, Resolution.NANOSEC); - Utils.drawText(gc, stime + " " + ns, rect, true); //$NON-NLS-1$ + Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$ } @Override diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java index 265b08f1a1..40359a273a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java @@ -18,7 +18,7 @@ import java.util.Iterator; import java.util.Map; import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; @@ -26,6 +26,7 @@ import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseMoveListener; import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; @@ -47,9 +48,9 @@ public class TimeGraphTooltipHandler { private TimeGraphItem _tipItem; private Point _tipPosition; private ITimeDataProvider _timeDataProvider; - ITimeGraphProvider _utilImp = null; + ITimeGraphPresentationProvider _utilImp = null; - public TimeGraphTooltipHandler(Shell parent, ITimeGraphProvider rUtilImpl, + public TimeGraphTooltipHandler(Shell parent, ITimeGraphPresentationProvider rUtilImpl, ITimeDataProvider timeProv) { final Display display = parent.getDisplay(); @@ -68,6 +69,8 @@ public class TimeGraphTooltipHandler { .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); _tipTable = new Table(_tipShell, SWT.NONE); + new TableColumn(_tipTable, SWT.NONE); + new TableColumn(_tipTable, SWT.NONE); _tipTable.setForeground(display .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); _tipTable.setBackground(display @@ -84,18 +87,28 @@ public class TimeGraphTooltipHandler { control.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { - if (_tipShell.isVisible()) + if (_tipShell.isVisible()) { _tipShell.setVisible(false); + } + } + }); + + control.addMouseMoveListener(new MouseMoveListener() { + @Override + public void mouseMove(MouseEvent e) { + if (_tipShell.isVisible()) { + _tipShell.setVisible(false); + } } }); control.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseExit(MouseEvent e) { - if (_tipShell.isVisible()) + if (_tipShell.isVisible()) { _tipShell.setVisible(false); + } _tipItem = null; - } private void addItem(String name, String value) { @@ -122,6 +135,9 @@ public class TimeGraphTooltipHandler { if (traceClass != null) { addItem(Messages.TmfTimeTipHandler_TRACE_CLASS_NAME, traceClass); } + if (threadEvent == null) { + return; + } // thread state String state = _utilImp.getEventName(threadEvent); if (state != null) { @@ -205,26 +221,14 @@ public class TimeGraphTooltipHandler { @Override public void mouseHover(MouseEvent event) { Point pt = new Point(event.x, event.y); - Widget widget = event.widget; - TimeGraphItem item = null; - if (widget instanceof TimeGraphControl) { - TimeGraphControl threadStates = (TimeGraphControl) widget; - item = (TimeGraphItem) threadStates.getItem(pt); - _tipTable.remove(0, _tipTable.getItemCount() - 1); - new TableColumn(_tipTable, SWT.NONE); - new TableColumn(_tipTable, SWT.NONE); - fillValues(pt, threadStates, item); - _tipTable.getColumn(0).setWidth(200); - _tipTable.getColumn(1).pack(); - _tipTable.setSize(_tipTable.computeSize(SWT.DEFAULT, 200)); - _tipShell.pack(); - } else if (widget == null) { - _tipShell.setVisible(false); - _tipItem = null; - return; - } - if (item == _tipItem) - return; + TimeGraphControl threadStates = (TimeGraphControl) event.widget; + TimeGraphItem item = threadStates.getItem(pt); + _tipTable.remove(0, _tipTable.getItemCount() - 1); + fillValues(pt, threadStates, item); + _tipTable.getColumn(0).setWidth(200); + _tipTable.getColumn(1).pack(); + _tipTable.setSize(_tipTable.computeSize(SWT.DEFAULT, 200)); + _tipShell.pack(); _tipItem = item; _tipPosition = control.toDisplay(pt); _tipShell.pack(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java index a26afe66c5..4bd608abf9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java @@ -157,7 +157,7 @@ public class Utils { str.append(sec); String ns = formatNs(time, resolution); if (!ns.equals("")) { //$NON-NLS-1$ - str.append(':'); + str.append('.'); str.append(ns); } @@ -186,7 +186,8 @@ public class Utils { // format time from nanoseconds to calendar time HH:MM:SS String stime = stimeformat.format(new Date((long) (time * 1E-6))); - str.append(stime + " "); //$NON-NLS-1$ + str.append(stime); + str.append('.'); // append the Milliseconds, MicroSeconds and NanoSeconds as specified in // the Resolution str.append(formatNs(time, res)); @@ -204,7 +205,7 @@ public class Utils { * @return the formatted nanosec */ public static String formatNs(long time, Resolution res) { - StringBuffer temp = new StringBuffer(); + StringBuffer str = new StringBuffer(); boolean neg = time < 0; if (neg) { time = -time; @@ -215,60 +216,35 @@ public class Utils { // String strVal = String.format("%09d", time); // String tmp = strVal.substring(strVal.length() - 9); - // number of segments to be included - int segments = 0; - switch (res) { - case MILLISEC: - segments = 1; - break; - case MICROSEC: - segments = 2; - break; - case NANOSEC: - segments = 3; - break; - default: - break; - } - long ns = time; ns %= 1000000000; if (ns < 10) { - temp.append("00000000"); //$NON-NLS-1$ + str.append("00000000"); //$NON-NLS-1$ } else if (ns < 100) { - temp.append("0000000"); //$NON-NLS-1$ + str.append("0000000"); //$NON-NLS-1$ } else if (ns < 1000) { - temp.append("000000"); //$NON-NLS-1$ + str.append("000000"); //$NON-NLS-1$ } else if (ns < 10000) { - temp.append("00000"); //$NON-NLS-1$ + str.append("00000"); //$NON-NLS-1$ } else if (ns < 100000) { - temp.append("0000"); //$NON-NLS-1$ + str.append("0000"); //$NON-NLS-1$ } else if (ns < 1000000) { - temp.append("000"); //$NON-NLS-1$ + str.append("000"); //$NON-NLS-1$ } else if (ns < 10000000) { - temp.append("00"); //$NON-NLS-1$ + str.append("00"); //$NON-NLS-1$ } else if (ns < 100000000) { - temp.append("0"); //$NON-NLS-1$ + str.append("0"); //$NON-NLS-1$ } - temp.append(ns); - - StringBuffer str = new StringBuffer(); - if (segments > 0) { - // append ms - str.append(temp.substring(0, 3)); + str.append(ns); + + if (res == Resolution.MILLISEC) { + return str.substring(0, 3); + } else if (res == Resolution.MICROSEC) { + return str.substring(0, 6); + } else if (res == Resolution.NANOSEC) { + return str.substring(0, 9); } - if (segments > 1) { - // append Micro secs - str.append("."); //$NON-NLS-1$ - str.append(temp.substring(3, 6)); - } - if (segments > 2) { - // append Nano seconds - str.append("."); //$NON-NLS-1$ - str.append(temp.substring(6)); - } - - return str.toString(); + return ""; //$NON-NLS-1$ } static public int loadIntOption(String opt, int def, int min, int max) { -- 2.34.1