From 41de99dd4b6f1a5b6e33312afa58ad22485f7cc7 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 13 Nov 2015 18:58:14 +0100 Subject: [PATCH] Fixed Styling and window system resource handling --- .../database/swt/internal/RulerPainter.java | 17 +- .../database/swt/internal/WaveformCanvas.java | 2 +- .../database/swt/internal/WaveformViewer.java | 13 +- .../Application.e4xmi | 4 + .../META-INF/MANIFEST.MF | 3 +- .../build.properties | 3 +- .../css/default.css | 227 ++++---------- com.minres.scviewer.e4.application/plugin.xml | 4 + .../application/handlers/ThemeSetHandler.java | 40 +++ .../internal/status/HeapStatus.java | 24 +- .../application/parts/WaveformViewerPart.java | 281 ++++++++++-------- .../SCViewer.launch | 6 +- 12 files changed, 286 insertions(+), 338 deletions(-) create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/ThemeSetHandler.java diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java index 2be9829..724b621 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RulerPainter.java @@ -14,24 +14,27 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Display; +import org.eclipse.wb.swt.SWTResourceManager; public class RulerPainter implements IPainter { protected WaveformCanvas waveCanvas; static final int rulerTickMinorC = 10; static final int rulerTickMajorC = 100; - - private Color headerBgColor; - private Color headerFgColor; - - public RulerPainter(WaveformCanvas waveCanvas, Color headerFgColor, Color headerBgColor) { + + public RulerPainter(WaveformCanvas waveCanvas) { this.waveCanvas=waveCanvas; - this.headerBgColor=headerBgColor; - this.headerFgColor=headerFgColor; } @Override public void paintArea(GC gc, Rectangle area) { + Color headerFgColor=waveCanvas.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND); + if(headerFgColor.isDisposed()) + headerFgColor=SWTResourceManager.getColor(0,0,0); + Color headerBgColor = waveCanvas.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); + if(headerBgColor.isDisposed()) + headerBgColor=SWTResourceManager.getColor(255,255,255); String unit=waveCanvas.getUnitStr(); int unitMultiplier=waveCanvas.getUnitMultiplier(); long scaleFactor=waveCanvas.getScaleFactor(); diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java index 19b2540..acd0171 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformCanvas.java @@ -111,7 +111,7 @@ public class WaveformCanvas extends Canvas { // order is important: it is bottom to top trackAreaPainter=new TrackAreaPainter(this); painterList.add(trackAreaPainter); - rulerPainter=new RulerPainter(this, getDisplay().getSystemColor(SWT.COLOR_BLACK), getDisplay().getSystemColor(SWT.COLOR_WHITE)); + rulerPainter=new RulerPainter(this); painterList.add(rulerPainter); CursorPainter cp = new CursorPainter(this, scaleFactor * 10, cursorPainters.size()-1); painterList.add(cp); diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java index f34d6e8..0605572 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java @@ -96,6 +96,8 @@ public class WaveformViewer implements IWaveformViewer { private ScrolledComposite valueListScrolled; + private Control namePaneHeader; + private Canvas nameList; private Canvas valueList; @@ -239,10 +241,11 @@ public class WaveformViewer implements IWaveformViewer { waveformCanvas = new WaveformCanvas(topSash, SWT.NONE); SashForm leftSash = new SashForm(composite, SWT.SMOOTH); - leftSash.setBackground(leftSash.getDisplay().getSystemColor(SWT.COLOR_GRAY)); + leftSash.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY)); Composite namePane = createTextPane(leftSash, "Name"); - namePane.setBackground(namePane.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + namePaneHeader= namePane.getChildren()[0]; + namePane.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND)); nameListScrolled = new ScrolledComposite(namePane, SWT.H_SCROLL | SWT.V_SCROLL); nameListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); @@ -275,7 +278,7 @@ public class WaveformViewer implements IWaveformViewer { nameListScrolled.setContent(nameList); Composite valuePane = createTextPane(leftSash, "Value"); - valuePane.setBackground(valuePane.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + valuePane.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND)); valueListScrolled = new ScrolledComposite(valuePane, SWT.H_SCROLL | SWT.V_SCROLL); valueListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); valueListScrolled.setExpandHorizontal(true); @@ -805,8 +808,8 @@ public class WaveformViewer implements IWaveformViewer { gc.fillRectangle(subArea.x, subArea.y + yOffset, subArea.width, subArea.height); gc.setFont(nameFontB); } else { - gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND)); - gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_FOREGROUND)); + gc.setBackground(namePaneHeader.getBackground()); + gc.setForeground(namePaneHeader.getForeground()); gc.setFont(nameFont); } gc.drawText(value, subArea.x + 5, subArea.y + yOffset + (waveformCanvas.getTrackHeight() - size.y) / 2, true); diff --git a/com.minres.scviewer.e4.application/Application.e4xmi b/com.minres.scviewer.e4.application/Application.e4xmi index 1d3f058..2c5175a 100644 --- a/com.minres.scviewer.e4.application/Application.e4xmi +++ b/com.minres.scviewer.e4.application/Application.e4xmi @@ -137,6 +137,7 @@ + @@ -212,6 +213,9 @@ + + + diff --git a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index 5ffb45e..c0c2edd 100644 --- a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -30,7 +30,8 @@ Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.e4.core.commands;bundle-version="0.11.0", org.eclipse.e4.ui.workbench.addons.swt, com.opcoach.e4.preferences, - org.eclipse.e4.core.di.extensions + org.eclipse.e4.core.di.extensions, + org.eclipse.e4.ui.css.swt.theme;bundle-version="0.10.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.minres.scviewer.database, javax.inject;version="1.0.0" diff --git a/com.minres.scviewer.e4.application/build.properties b/com.minres.scviewer.e4.application/build.properties index 25fb672..659bac7 100644 --- a/com.minres.scviewer.e4.application/build.properties +++ b/com.minres.scviewer.e4.application/build.properties @@ -5,7 +5,6 @@ bin.includes = META-INF/,\ plugin.xml,\ Application.e4xmi,\ icons/,\ - css/default.css,\ - OSGI-INF/l10n/bundle.properties,\ + css/,\ OSGI-INF/ source.. = src/ diff --git a/com.minres.scviewer.e4.application/css/default.css b/com.minres.scviewer.e4.application/css/default.css index 857a2b4..79ae20b 100644 --- a/com.minres.scviewer.e4.application/css/default.css +++ b/com.minres.scviewer.e4.application/css/default.css @@ -1,205 +1,78 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Lars Vogel - Bug 420836 - *******************************************************************************/ - -/* New ColorDefinitions for the E4 default theme */ -ThemesExtension { color-definition: - '#org-eclipse-ui-workbench-INACTIVE_UNSELECTED_TABS_COLOR_START', - '#org-eclipse-ui-workbench-INACTIVE_UNSELECTED_TABS_COLOR_END', - '#org-eclipse-ui-workbench-INACTIVE_TAB_OUTER_KEYLINE_COLOR', - '#org-eclipse-ui-workbench-INACTIVE_TAB_INNER_KEYLINE_COLOR', - '#org-eclipse-ui-workbench-INACTIVE_TAB_OUTLINE_COLOR', - '#org-eclipse-ui-workbench-ACTIVE_UNSELECTED_TABS_COLOR_START', - '#org-eclipse-ui-workbench-ACTIVE_UNSELECTED_TABS_COLOR_END', - '#org-eclipse-ui-workbench-ACTIVE_TAB_OUTER_KEYLINE_COLOR', - '#org-eclipse-ui-workbench-ACTIVE_TAB_INNER_KEYLINE_COLOR', - '#org-eclipse-ui-workbench-ACTIVE_TAB_OUTLINE_COLOR'; +Label, Button[style~='SWT.CHECK'] { + color: black; } -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_UNSELECTED_TABS_COLOR_START { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_UNSELECTED_TABS_COLOR_START') +Composite Label { + color: black; } -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_UNSELECTED_TABS_COLOR_END { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_UNSELECTED_TABS_COLOR_END'); +#SeparatorLabel { + color: #1d659f; } -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_OUTER_KEYLINE_COLOR { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_TAB_OUTER_KEYLINE_COLOR'); +/* +Text { + font: Verdana 8px; +} +*/ + +Composite Text { + background-color: white; + color: black; } -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_INNER_KEYLINE_COLOR { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_TAB_INNER_KEYLINE_COLOR'); +SashForm { + background-color: #dddddd; } -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_OUTLINE_COLOR { - color: #B6BCCC; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_TAB_OUTLINE_COLOR'); +#DetailsView { + background-color: #e8e8e8 #cccccc 60%; } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_UNSELECTED_TABS_COLOR_START { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_UNSELECTED_TABS_COLOR_START'); +Table { + /*background-color: #e8e8e8 #cccccc 60%;*/ + background-color: #f7f7f7 60%; + color: black; } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_UNSELECTED_TABS_COLOR_END { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_UNSELECTED_TABS_COLOR_END'); +Tree { + /*background-color: #e8e8e8 #cccccc 60%;*/ + background-color: #f7f7f7 60%; + color: black; } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_OUTER_KEYLINE_COLOR { - color: #CCCCCC; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_OUTER_KEYLINE_COLOR'); +.MTrimBar { + background-color: white #dddddd #eeeeee 35% 25% 25%; + color: white; } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_INNER_KEYLINE_COLOR { - color: #FFFFFF; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_INNER_KEYLINE_COLOR'); +CTabFolder { + /* The tab rendering background for the min/max toolbar pulls + * background from the tabfolder's background (or it's parent?) + * and so the gradient doesn't come through. So just set the + * tabfolder's background to a color */ + /*background-color: white #dddddd #eeeeee 35% 25% 25%;*/ + background-color: #eeeeee; + color: white; + swt-simple: true; } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_OUTLINE_COLOR { - color: #B6BCCC; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_OUTLINE_COLOR'); -} - -/* Already existing ColorDefinitions overridden for the E4 default theme */ -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_BG_START { - color: #dddfe5; -} - -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_BG_END { - color: #FFFFFF; -} - -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_BG_START{ - color: #FFFFFF; -} - -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_BG_END { - color: #FFFFFF; -} - -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_START { - color: #FFFFFF; -} - -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_END { - color: #FFFFFF; -} - -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_TEXT_COLOR { - color: #000000; -} - -.MTrimmedWindow.topLevel { - margin-top: 3px; - margin-bottom: 3px; - margin-left: 3px; - margin-right: 3px; -} - -.MPart.busy { - font-style: italic; -} - -.MPart.highlighted { - font-weight: bold; -} - -.MPartStack, .MPart { - font-family: '#org-eclipse-ui-workbench-TAB_TEXT_FONT'; +CTabItem { + color: black; } CTabItem:selected { - color: '#org-eclipse-ui-workbench-ACTIVE_TAB_TEXT_COLOR'; + background-color: #cccccc #e8e8e8 60%; + font-weight: normal; } -.MPartStack { - swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering'); - swt-selected-tab-fill: '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_END' 100% 100%; - swt-unselected-tabs-color: '#org-eclipse-ui-workbench-INACTIVE_UNSELECTED_TABS_COLOR_START' '#org-eclipse-ui-workbench-INACTIVE_UNSELECTED_TABS_COLOR_END' 100% 100%; - swt-outer-keyline-color: '#org-eclipse-ui-workbench-INACTIVE_TAB_OUTER_KEYLINE_COLOR'; - swt-inner-keyline-color: '#org-eclipse-ui-workbench-INACTIVE_TAB_INNER_KEYLINE_COLOR'; - swt-tab-outline: '#org-eclipse-ui-workbench-INACTIVE_TAB_OUTLINE_COLOR'; - padding: 0px 2px 2px; - swt-shadow-visible: false; - swt-mru-visible: false; - color: '#org-eclipse-ui-workbench-INACTIVE_TAB_TEXT_COLOR'; +CTabItem.active:selected { + background-color: #ffffff #cccccc #dddddd 50% 50%; + color: #1d659f; + font: bold; } -.MPartStack.active { - swt-selected-tab-fill: '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_END' 100% 100%; - swt-unselected-tabs-color: '#org-eclipse-ui-workbench-ACTIVE_UNSELECTED_TABS_COLOR_START' '#org-eclipse-ui-workbench-ACTIVE_UNSELECTED_TABS_COLOR_END' 100% 100%; - swt-outer-keyline-color: '#org-eclipse-ui-workbench-ACTIVE_TAB_OUTER_KEYLINE_COLOR'; - swt-inner-keyline-color: '#org-eclipse-ui-workbench-ACTIVE_TAB_INNER_KEYLINE_COLOR'; - swt-tab-outline: '#org-eclipse-ui-workbench-ACTIVE_TAB_OUTLINE_COLOR'; - swt-shadow-visible: false; -} - -.MPartStack.active.noFocus { - swt-selected-tab-fill: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_END' 100% 100%; -} - -.MPartStack.active.noFocus > CTabItem:selected { - color: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_TEXT_COLOR'; -} - -#PerspectiveSwitcher { - eclipse-perspective-keyline-color: #AAB0BF #AAB0BF; -} - -.MToolControl.TrimStack { - frame-image: url(./winXPTSFrame.png); - handle-image: url(./winXPHandle.png); - frame-cuts: 5px 1px 5px 16px; -} - -.MToolBar.Draggable { - handle-image: url(./dragHandle.png); -} - -.MToolControl.Draggable { - handle-image: url(./dragHandle.png); -} - -.DragFeedback { - background-color: COLOR-WIDGET-NORMAL-SHADOW; -} - -.ModifiedDragFeedback { - background-color: #A0A000; -} - -.MPartStack > Composite { - background-color: '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_END'; -} - -.MPartStack.active > Composite { - background-color: '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_END'; -} - -.MPartStack.active.noFocus > Composite { - background-color: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_END'; +Shell { + background-color: #e8e8e8 #cccccc 60%; + swt-background-mode: default; } diff --git a/com.minres.scviewer.e4.application/plugin.xml b/com.minres.scviewer.e4.application/plugin.xml index 3d6f766..f2a6d0d 100644 --- a/com.minres.scviewer.e4.application/plugin.xml +++ b/com.minres.scviewer.e4.application/plugin.xml @@ -20,6 +20,10 @@ name="windowImages" value="icons/SCViewer_16x32.png,icons/SCViewer_32x32.png,icons/SCViewer_48x32.png,icons/SCViewer_64x32.png,icons/SCViewer_128x32.png,icons/SCViewer_256x32.png"> + + (); + checkForUpdates = prefs.getBoolean(PreferenceConstants.DATABASE_RELOAD, true); + filesToLoad = new ArrayList(); persistedState = part.getPersistedState(); - Integer files = persistedState.containsKey(DATABASE_FILE+"S")?Integer.parseInt(persistedState.get(DATABASE_FILE+"S")):0; - for(int i=0; i0) + if (filesToLoad.size() > 0) loadDatabase(persistedState); eventBroker.post(WaveStatusBarControl.ZOOM_LEVEL, zoomLevel[waveformPane.getZoomLevel()]); - menuService.registerContextMenu(waveformPane.getNameControl(), "com.minres.scviewer.e4.application.popupmenu.namecontext"); - menuService.registerContextMenu(waveformPane.getValueControl(), "com.minres.scviewer.e4.application.popupmenu.namecontext"); - menuService.registerContextMenu(waveformPane.getWaveformControl(), "com.minres.scviewer.e4.application.popupmenu.wavecontext"); - ePartService.addPartListener(new PartListener(){ + menuService.registerContextMenu(waveformPane.getNameControl(), + "com.minres.scviewer.e4.application.popupmenu.namecontext"); + menuService.registerContextMenu(waveformPane.getValueControl(), + "com.minres.scviewer.e4.application.popupmenu.namecontext"); + menuService.registerContextMenu(waveformPane.getWaveformControl(), + "com.minres.scviewer.e4.application.popupmenu.wavecontext"); + ePartService.addPartListener(new PartListener() { @Override public void partActivated(MPart part) { if (part == myPart) { - if(fileChecker!=null) fileChecker.check(); + if (fileChecker != null) + fileChecker.check(); updateAll(); } } @@ -199,11 +210,12 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang @Override public void preferenceChange(PreferenceChangeEvent event) { - if(PreferenceConstants.DATABASE_RELOAD.equals(event.getKey())){ + if (PreferenceConstants.DATABASE_RELOAD.equals(event.getKey())) { checkForUpdates = (Boolean) event.getNewValue(); - fileChecker=null; - if(checkForUpdates) - fileChecker=fileMonitor.addFileChangeListener(WaveformViewerPart.this,filesToLoad, FILE_CHECK_INTERVAL); + fileChecker = null; + if (checkForUpdates) + fileChecker = fileMonitor.addFileChangeListener(WaveformViewerPart.this, filesToLoad, + FILE_CHECK_INTERVAL); else fileMonitor.removeFileChangeListener(this); } else { @@ -213,13 +225,13 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang protected void setupColors() { DefaultValuesInitializer initializer = new DefaultValuesInitializer(); - HashMap colorPref=new HashMap<>(); + HashMap colorPref = new HashMap<>(); for (WaveformColors c : WaveformColors.values()) { - String prefValue=prefs.get(c.name() + "_COLOR", + String prefValue = prefs.get(c.name() + "_COLOR", StringConverter.asString(initializer.colors[c.ordinal()].getRGB())); RGB rgb = StringConverter.asRGB(prefValue); colorPref.put(c, rgb); - } + } waveformPane.setColors(colorPref); } @@ -227,21 +239,22 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang fileMonitor.removeFileChangeListener(this); Job job = new Job(" My Job") { @Override - protected IStatus run( IProgressMonitor monitor) { + protected IStatus run(IProgressMonitor monitor) { // convert to SubMonitor and set total number of work units SubMonitor subMonitor = SubMonitor.convert(monitor, filesToLoad.size()); subMonitor.setTaskName("Loading database"); try { - for(File file: filesToLoad){ - //TimeUnit.SECONDS.sleep(2); + for (File file : filesToLoad) { + // TimeUnit.SECONDS.sleep(2); database.load(file); database.addPropertyChangeListener(waveformPane); subMonitor.worked(1); - if(monitor.isCanceled()) return Status.CANCEL_STATUS; + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; } // sleep a second } catch (Exception e) { - database=null; + database = null; e.printStackTrace(); return Status.CANCEL_STATUS; } @@ -250,18 +263,20 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang return Status.OK_STATUS; } }; - job.addJobChangeListener(new JobChangeAdapter(){ + job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(IJobChangeEvent event) { - if(event.getResult()==Status.OK_STATUS) - myParent.getDisplay().asyncExec(new Runnable() { + if (event.getResult() == Status.OK_STATUS) + myParent.getDisplay().asyncExec(new Runnable() { @Override public void run() { waveformPane.setMaxTime(database.getMaxTime()); - if(state!=null) restoreWaveformViewerState(state); - fileChecker=null; - if(checkForUpdates) fileChecker=fileMonitor.addFileChangeListener( - WaveformViewerPart.this,filesToLoad, FILE_CHECK_INTERVAL); + if (state != null) + restoreWaveformViewerState(state); + fileChecker = null; + if (checkForUpdates) + fileChecker = fileMonitor.addFileChangeListener(WaveformViewerPart.this, filesToLoad, + FILE_CHECK_INTERVAL); } }); } @@ -275,12 +290,14 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang display.asyncExec(new Runnable() { @Override public void run() { - if(MessageDialog.openQuestion(display.getActiveShell(), "Database re-load", "Would you like to reload the database?")){ + if (MessageDialog.openQuestion(display.getActiveShell(), "Database re-load", + "Would you like to reload the database?")) { Map state = new HashMap<>(); saveWaveformViewerState(state); waveformPane.getStreamList().clear(); database.clear(); - if(filesToLoad.size()>0) loadDatabase(state); + if (filesToLoad.size() > 0) + loadDatabase(state); } } }); @@ -288,29 +305,29 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang @Inject @Optional - public void setPartInput( @Named( "input" ) Object partInput ) { - if(partInput instanceof File){ - filesToLoad=new ArrayList(); + public void setPartInput(@Named("input") Object partInput) { + if (partInput instanceof File) { + filesToLoad = new ArrayList(); File file = (File) partInput; - if(file.exists()){ + if (file.exists()) { filesToLoad.add(file); try { String ext = getFileExtension(file.getName()); - if("vcd".equals(ext.toLowerCase())){ - if(askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txdb")))){ + if ("vcd".equals(ext.toLowerCase())) { + if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txdb")))) { filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txdb"))); - }else if(askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txlog")))){ + } else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txlog")))) { filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txlog"))); } - } else if("txdb".equals(ext.toLowerCase()) || "txlog".equals(ext.toLowerCase())){ - if(askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "vcd")))){ + } else if ("txdb".equals(ext.toLowerCase()) || "txlog".equals(ext.toLowerCase())) { + if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "vcd")))) { filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "vcd"))); } } } catch (IOException e) { // silently ignore any error } } - if(filesToLoad.size()>0) + if (filesToLoad.size() > 0) loadDatabase(persistedState); } } @@ -320,15 +337,14 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang myParent.setFocus(); } - @PersistState public void saveState(MPart part) { - // save changes + // save changes Map persistedState = part.getPersistedState(); - persistedState.put(DATABASE_FILE+"S", Integer.toString(filesToLoad.size())); - Integer index=0; - for(File file:filesToLoad){ - persistedState.put(DATABASE_FILE+index, file.getAbsolutePath()); + persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); + Integer index = 0; + for (File file : filesToLoad) { + persistedState.put(DATABASE_FILE + index, file.getAbsolutePath()); index++; } saveWaveformViewerState(persistedState); @@ -336,72 +352,75 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang protected void saveWaveformViewerState(Map persistedState) { Integer index; - persistedState.put(SHOWN_WAVEFORM+"S", Integer.toString(waveformPane.getStreamList().size())); - index=0; - for(TrackEntry trackEntry:waveformPane.getStreamList()){ - persistedState.put(SHOWN_WAVEFORM+index, trackEntry.waveform.getFullName()); + persistedState.put(SHOWN_WAVEFORM + "S", Integer.toString(waveformPane.getStreamList().size())); + index = 0; + for (TrackEntry trackEntry : waveformPane.getStreamList()) { + persistedState.put(SHOWN_WAVEFORM + index, trackEntry.waveform.getFullName()); index++; } List cursors = waveformPane.getCursorList(); - persistedState.put(SHOWN_CURSOR+"S", Integer.toString(cursors.size())); - index=0; - for(ICursor cursor:cursors){ - persistedState.put(SHOWN_CURSOR+index, Long.toString(cursor.getTime())); + persistedState.put(SHOWN_CURSOR + "S", Integer.toString(cursors.size())); + index = 0; + for (ICursor cursor : cursors) { + persistedState.put(SHOWN_CURSOR + index, Long.toString(cursor.getTime())); index++; } persistedState.put(ZOOM_LEVEL, Integer.toString(waveformPane.getZoomLevel())); - } + } protected void restoreWaveformViewerState(Map state) { updateAll(); - Integer waves = state.containsKey(SHOWN_WAVEFORM+"S")?Integer.parseInt(state.get(SHOWN_WAVEFORM+"S")):0; + Integer waves = state.containsKey(SHOWN_WAVEFORM + "S") ? Integer.parseInt(state.get(SHOWN_WAVEFORM + "S")) : 0; List res = new LinkedList<>(); - for(int i=0; i waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM+i)); - if(waveform!=null) res.add(new TrackEntry(waveform)); + for (int i = 0; i < waves; i++) { + IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i)); + if (waveform != null) + res.add(new TrackEntry(waveform)); } - if(res.size()>0) waveformPane.getStreamList().addAll(res); - Integer cursorLength = state.containsKey(SHOWN_CURSOR+"S")?Integer.parseInt(state.get(SHOWN_CURSOR+"S")):0; + if (res.size() > 0) + waveformPane.getStreamList().addAll(res); + Integer cursorLength = state.containsKey(SHOWN_CURSOR + "S") ? Integer.parseInt(state.get(SHOWN_CURSOR + "S")) + : 0; List cursors = waveformPane.getCursorList(); - if(cursorLength==cursors.size()){ - for(int i=0; i) + @Inject + @Optional + public void getAddWaveformEvent(@UIEventTopic(WaveformViewerPart.ADD_WAVEFORM) Object o) { + Object sel = o == null ? selectionService.getSelection() : o; + if (sel instanceof IStructuredSelection) + for (Object el : ((IStructuredSelection) sel).toArray()) { + if (el instanceof IWaveform) addStreamToList((IWaveform) el, false); } } - protected boolean askIfToLoad(File txFile) { - if(txFile.exists() && - MessageDialog.openQuestion(myParent.getDisplay().getActiveShell(), "Database open", - "Would you like to open the adjacent database "+txFile.getName()+" as well?")){ + if (txFile.exists() && MessageDialog.openQuestion(myParent.getDisplay().getActiveShell(), "Database open", + "Would you like to open the adjacent database " + txFile.getName() + " as well?")) { return true; } return false; @@ -410,10 +429,10 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang protected static String renameFileExtension(String source, String newExt) { String target; String currentExt = getFileExtension(source); - if (currentExt.equals("")){ - target=source+"."+newExt; + if (currentExt.equals("")) { + target = source + "." + newExt; } else { - target=source.replaceFirst(Pattern.quote("."+currentExt)+"$", Matcher.quoteReplacement("."+newExt)); + target = source.replaceFirst(Pattern.quote("." + currentExt) + "$", Matcher.quoteReplacement("." + newExt)); } return target; } @@ -421,7 +440,7 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang protected static String getFileExtension(String f) { String ext = ""; int i = f.lastIndexOf('.'); - if (i > 0 && i < f.length() - 1) { + if (i > 0 && i < f.length() - 1) { ext = f.substring(i + 1); } return ext; @@ -435,34 +454,35 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang return database; } - public void addStreamToList(IWaveform obj, boolean insert){ - addStreamsToList(new IWaveform[]{obj}, insert); + public void addStreamToList(IWaveform obj, boolean insert) { + addStreamsToList(new IWaveform[] { obj }, insert); } - public void addStreamsToList(IWaveform[] iWaveforms, boolean insert){ - List streams= new LinkedList<>(); - for(IWaveform stream:iWaveforms) + public void addStreamsToList(IWaveform[] iWaveforms, boolean insert) { + List streams = new LinkedList<>(); + for (IWaveform stream : iWaveforms) streams.add(new TrackEntry(stream)); IStructuredSelection selection = (IStructuredSelection) waveformPane.getSelection(); - if(selection.size()==0){ + if (selection.size() == 0) { waveformPane.getStreamList().addAll(streams); - }else { - Object first=selection.getFirstElement(); - IWaveform stream = (first instanceof ITx)?((ITx)first).getStream():(IWaveform)first; - TrackEntry trackEntry=waveformPane.getEntryForStream(stream); + } else { + Object first = selection.getFirstElement(); + IWaveform stream = (first instanceof ITx) ? ((ITx) first).getStream() : (IWaveform) first; + TrackEntry trackEntry = waveformPane.getEntryForStream(stream); int index = waveformPane.getStreamList().indexOf(trackEntry); - if(!insert) index++; + if (!insert) + index++; waveformPane.getStreamList().addAll(index, streams); } } - public void removeStreamFromList(IWaveform stream){ - TrackEntry trackEntry=waveformPane.getEntryForStream(stream); + public void removeStreamFromList(IWaveform stream) { + TrackEntry trackEntry = waveformPane.getEntryForStream(stream); waveformPane.getStreamList().remove(trackEntry); } - public void removeStreamsFromList(IWaveform[] iWaveforms){ - for(IWaveform stream:iWaveforms) + public void removeStreamsFromList(IWaveform[] iWaveforms) { + for (IWaveform stream : iWaveforms) removeStreamFromList(stream); } @@ -475,17 +495,22 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang } public void moveCursor(GotoDirection direction) { - waveformPane.moveCursor(direction); } + waveformPane.moveCursor(direction); + } public void setZoomLevel(Integer level) { - if(level<0) level=0; - if(level>zoomLevel.length-1) level=zoomLevel.length-1; + if (level < 0) + level = 0; + if (level > zoomLevel.length - 1) + level = zoomLevel.length - 1; waveformPane.setZoomLevel(level); - updateAll(); } + updateAll(); + } public void setZoomFit() { - waveformPane.setZoomLevel(6); - updateAll(); } + waveformPane.setZoomLevel(6); + updateAll(); + } public int getZoomLevel() { return waveformPane.getZoomLevel(); diff --git a/com.minres.scviewer.e4.product/SCViewer.launch b/com.minres.scviewer.e4.product/SCViewer.launch index 42c4138..cb90612 100644 --- a/com.minres.scviewer.e4.product/SCViewer.launch +++ b/com.minres.scviewer.e4.product/SCViewer.launch @@ -2,13 +2,13 @@ - + - + @@ -22,7 +22,7 @@ - +