From f64a1baf022da3a1ffec07cb06dfaac43ac4ef57 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Wed, 1 Mar 2023 09:21:11 +0100 Subject: [PATCH] rename BLANK to EMPY, enhances separator render, fixes menu selection --- .../scviewer/database/ui/WaveformColors.java | 2 +- .../ui/swt/DefaultWaveformStyleProvider.java | 2 +- .../ui/swt/internal/BlankPainter.java | 45 ---------- .../ui/swt/internal/EmptyPainter.java | 85 +++++++++++++++++++ .../ui/swt/internal/WaveformView.java | 23 ++++- .../scviewer/database/EmptyWaveform.java | 13 ++- .../scviewer/database/WaveformType.java | 2 +- .../Application.e4xmi | 2 +- .../scviewer/e4/application/Messages.java | 2 +- .../e4/application/messages.properties | 2 +- .../e4/application/parts/WaveformViewer.java | 37 +++++--- 11 files changed, 149 insertions(+), 66 deletions(-) delete mode 100644 plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/BlankPainter.java create mode 100644 plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/EmptyPainter.java diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/WaveformColors.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/WaveformColors.java index 090d28a..4bbbd33 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/WaveformColors.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/WaveformColors.java @@ -16,5 +16,5 @@ public enum WaveformColors { TX_BG, TX_BG_HIGHLITE, TX_BORDER, SIGNAL0, SIGNAL1, SIGNALZ, SIGNALX, SIGNAL_CHANGE, SIGNALU, SIGNAL_TEXT, SIGNAL_REAL, SIGNAL_NAN, CURSOR, CURSOR_DRAG, CURSOR_TEXT, - MARKER, MARKER_TEXT, REL_ARROW, REL_ARROW_HIGHLITE, BLANK + MARKER, MARKER_TEXT, REL_ARROW, REL_ARROW_HIGHLITE, SEPARATOR } \ No newline at end of file diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java index 8bd7cfb..cc993ce 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java @@ -50,7 +50,7 @@ public class DefaultWaveformStyleProvider implements IWaveformStyleProvider { colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE); colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_MAGENTA); colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()] = SWTResourceManager.getColor(255, 128, 255); - colors[WaveformColors.BLANK.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_RED); + colors[WaveformColors.SEPARATOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_RED); } /** * needs redraw() afterwards diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/BlankPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/BlankPainter.java deleted file mode 100644 index d704615..0000000 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/BlankPainter.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2021 MINRES Technologies GmbH 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: - * MINRES Technologies GmbH - initial API and implementation - *******************************************************************************/ -package com.minres.scviewer.database.ui.swt.internal; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Rectangle; - -import com.minres.scviewer.database.ui.TrackEntry; -import com.minres.scviewer.database.ui.WaveformColors; - -public class BlankPainter extends TrackPainter { - /** - * - */ - private final WaveformCanvas waveCanvas; - - public BlankPainter(WaveformCanvas txDisplay, boolean even, TrackEntry trackEntry) { - super(trackEntry, even); - this.waveCanvas = txDisplay; - } - - public void paintArea(Projection proj, Rectangle area) { - if (trackEntry.selected) - proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_HIGHLITE)); - else - proj.setBackground(this.waveCanvas.styleProvider.getColor(even ? WaveformColors.TRACK_BG_EVEN : WaveformColors.TRACK_BG_ODD)); - proj.setFillRule(SWT.FILL_EVEN_ODD); - proj.fillRectangle(area); - int trackHeight=trackEntry.height; - int txBase=trackHeight*2/5; - int txHeight=trackHeight/5; - Rectangle bb = new Rectangle(area.x, area.y+txBase, area.width, txHeight); - proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.BLANK)); - proj.fillRectangle(bb); - - } -} diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/EmptyPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/EmptyPainter.java new file mode 100644 index 0000000..6e3824f --- /dev/null +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/EmptyPainter.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2015-2021 MINRES Technologies GmbH 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: + * MINRES Technologies GmbH - initial API and implementation + *******************************************************************************/ +package com.minres.scviewer.database.ui.swt.internal; + +import javax.swing.JPanel; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; + +import com.minres.scviewer.database.ui.TrackEntry; +import com.minres.scviewer.database.ui.WaveformColors; + +public class EmptyPainter extends TrackPainter { + /** + * + */ + private final WaveformCanvas waveCanvas; + + private static final JPanel DUMMY_PANEL = new JPanel(); + + public EmptyPainter(WaveformCanvas txDisplay, boolean even, TrackEntry trackEntry) { + super(trackEntry, even); + this.waveCanvas = txDisplay; + } + + public void paintArea(Projection proj, Rectangle area) { + Color bgColor = trackEntry.selected?this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_HIGHLITE):this.waveCanvas.styleProvider.getColor(even ? WaveformColors.TRACK_BG_EVEN : WaveformColors.TRACK_BG_ODD); + GC gc = proj.getGC(); + proj.setBackground(bgColor); + proj.setFillRule(SWT.FILL_EVEN_ODD); + proj.fillRectangle(area); + Color drawColor = this.waveCanvas.styleProvider.getColor(WaveformColors.SEPARATOR); + int trackHeight=trackEntry.height; + int txBase=trackHeight*2/5; + int txHeight=trackHeight/5; + proj.setBackground(drawColor); + proj.fillRectangle(new Rectangle(area.x, area.y+txBase, area.width, txHeight)); + + String label = trackEntry.waveform.getName(); + if(label.length()>0) { + Color textColor=waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_TEXT); + FontData fd = gc.getFont().getFontData()[0]; + int height = gc.getDevice().getDPI().y * fd.getHeight() / 72; + java.awt.Font tmpAwtFont = new java.awt.Font(fd.getName(), fd.getStyle(), height); + int width = DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(label); + + int xBegin = (area.width-width)/2-5; + xBegin = xBegin<0?0:xBegin; + int xEnd = (area.width+width)/2+5; + xEnd = xEnd>area.width?area.width:xEnd; + int yOffsetT = this.waveCanvas.styleProvider.getTrackHeight() / 5 + area.y; + int yOffsetM = this.waveCanvas.styleProvider.getTrackHeight() / 2 + area.y; + int yOffsetB = 4 * this.waveCanvas.styleProvider.getTrackHeight() / 5 + area.y; + int[] points = { + xBegin, yOffsetM, + xBegin + 1, yOffsetT, + xEnd - 1, yOffsetT, + xEnd, yOffsetM, + xEnd - 1, yOffsetB, + xBegin + 1, yOffsetB + }; + gc.setBackground(bgColor); + gc.fillPolygon(points); + gc.setForeground(drawColor); + gc.drawPolygon(points); + Rectangle old = gc.getClipping(); + gc.setForeground(textColor); + gc.setClipping(xBegin + 3, yOffsetT, xEnd - xBegin - 5, yOffsetB - yOffsetT); + gc.drawText(label, xBegin + 3, yOffsetM - height / 2 - 1); + gc.setClipping(old); + } + } +} diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java index 2c68d80..dbd4823 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java @@ -149,6 +149,24 @@ public class WaveformView implements IWaveformView { if (entry != null) entry.getValue().selected = true; } else if (e.button == 3) { + ISelection sel = getSelection(); + if(sel instanceof StructuredSelection) { + if(((StructuredSelection)sel).isEmpty()) { + Entry entry = trackVerticalOffset.floorEntry(e.y); + setSelection(new StructuredSelection(entry.getValue()), false, false); + lastClickedEntry = entry.getValue(); + } else { + StructuredSelection structuredSelection = (StructuredSelection) sel; + if(structuredSelection.size()== 1 && structuredSelection.getFirstElement() instanceof TrackEntry) { + Entry entry = trackVerticalOffset.floorEntry(e.y); + TrackEntry selEntry = (TrackEntry) structuredSelection.getFirstElement(); + if(!entry.getValue().equals(selEntry)) { + setSelection(new StructuredSelection(entry.getValue()), false, false); + lastClickedEntry = entry.getValue(); + } + } + } + } Menu topMenu = top.getMenu(); if (topMenu != null) topMenu.setVisible(true); @@ -182,6 +200,7 @@ public class WaveformView implements IWaveformView { Entry entry = trackVerticalOffset.floorEntry(e.y); if(entry != null) setSelection(new StructuredSelection(entry.getValue()), false, false); + lastClickedEntry = entry.getValue(); for (IWaveformviewEventListener listner : eventListener) { listner.onTrackEntryDoubleClickEvent(entry.getValue()); } @@ -613,9 +632,9 @@ public class WaveformView implements IWaveformView { } else if (streamEntry.waveform.getType() == WaveformType.SIGNAL) { streamEntry.currentValue = "---"; waveformCanvas.addWaveformPainter(new SignalPainter(waveformCanvas, even, streamEntry), false); - } else if (streamEntry.waveform.getType() == WaveformType.BLANK) { + } else if (streamEntry.waveform.getType() == WaveformType.EMPTY) { streamEntry.currentValue = ""; - waveformCanvas.addWaveformPainter(new BlankPainter(waveformCanvas, even, streamEntry), false); + waveformCanvas.addWaveformPainter(new EmptyPainter(waveformCanvas, even, streamEntry), false); } } diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/EmptyWaveform.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/EmptyWaveform.java index 9fe311f..dcf7d74 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/EmptyWaveform.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/EmptyWaveform.java @@ -18,6 +18,15 @@ import java.util.List; public class EmptyWaveform implements IWaveform { private String label = ""; + + + public EmptyWaveform() { + } + + public EmptyWaveform(String label) { + this.label = label; + } + @Override public void addPropertyChangeListener(PropertyChangeListener l) { } @@ -96,12 +105,12 @@ public class EmptyWaveform implements IWaveform { @Override public WaveformType getType() { - return WaveformType.BLANK; + return WaveformType.EMPTY; } @Override public String getKind() { - return "BLANK"; + return "separator"; } @Override diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java index 6da5ed6..4ca0753 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java @@ -22,5 +22,5 @@ public enum WaveformType { /** The filter. */ FILTER, /** The blank line. */ - BLANK + EMPTY } diff --git a/plugins/com.minres.scviewer.e4.application/Application.e4xmi b/plugins/com.minres.scviewer.e4.application/Application.e4xmi index f7d3384..107c4ec 100644 --- a/plugins/com.minres.scviewer.e4.application/Application.e4xmi +++ b/plugins/com.minres.scviewer.e4.application/Application.e4xmi @@ -66,7 +66,7 @@ - + diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/Messages.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/Messages.java index 9712d99..d7bff25 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/Messages.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/Messages.java @@ -89,7 +89,7 @@ public class Messages extends NLS { public static String marker_text; public static String rel_arrow; public static String rel_arrow_highlite; - public static String blank; + public static String separator; public static String HelpBrowser_0; public static String HelpBrowser_1; public static String HelpBrowser_2; diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties index 8c31e4f..cf5d91b 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties @@ -83,7 +83,7 @@ marker=Marker marker_text=Marker TExt rel_arrow=Relation arrow rel_arrow_highlite=highlighted Relation arrorw -blank=separator +separator=separator UpdateHandler_URI=http://https://minres.github.io/SCViewer/repository UpdateHandler_10=Information UpdateHandler_11=Error diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 8f46d01..79e964a 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -84,6 +84,7 @@ import org.eclipse.wb.swt.SWTResourceManager; import org.osgi.service.prefs.BackingStoreException; import com.minres.scviewer.database.DataType; +import com.minres.scviewer.database.EmptyWaveform; import com.minres.scviewer.database.IHierNode; import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveformDb; @@ -132,6 +133,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis /** The Constant SHOWN_WAVEFORM. */ protected static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM"; //$NON-NLS-1$ + protected static final String WAVEFORM_TYPE = ".WAVEFORM_TYPE"; //$NON-NLS-1$ + protected static final String VALUE_DISPLAY = ".VALUE_DISPLAY"; //$NON-NLS-1$ protected static final String WAVE_DISPLAY = ".WAVE_DISPLAY"; //$NON-NLS-1$ @@ -749,9 +752,12 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis Integer index = 0; for (TrackEntry trackEntry : waveformPane.getStreamList()) { persistingState.put(SHOWN_WAVEFORM + index, trackEntry.waveform.getFullName()); - persistingState.put(SHOWN_WAVEFORM + index + VALUE_DISPLAY, trackEntry.valueDisplay.toString()); - persistingState.put(SHOWN_WAVEFORM + index + WAVE_DISPLAY, trackEntry.waveDisplay.toString()); + persistingState.put(SHOWN_WAVEFORM + index + WAVEFORM_TYPE, trackEntry.waveform.getType().toString()); persistingState.put(SHOWN_WAVEFORM + index + WAVEFORM_SELECTED, String.valueOf(trackEntry.selected).toUpperCase()); + if (trackEntry.waveform.getType()!=WaveformType.EMPTY) { + persistingState.put(SHOWN_WAVEFORM + index + VALUE_DISPLAY, trackEntry.valueDisplay.toString()); + persistingState.put(SHOWN_WAVEFORM + index + WAVE_DISPLAY, trackEntry.waveDisplay.toString()); + } index++; } List cursors = waveformPane.getCursorList(); @@ -807,19 +813,28 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis List trackEntries = new LinkedList<>(); List selectedTrackEntries = new LinkedList<>(); for (int i = 0; i < waves; i++) { - IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i)); - if (waveform != null) { - TrackEntry trackEntry = waveformPane.addWaveform(waveform, -1); + String wtString = state.get(SHOWN_WAVEFORM + i + WAVEFORM_TYPE); + if(wtString!=null && WaveformType.valueOf(wtString)==WaveformType.EMPTY) { + TrackEntry trackEntry = waveformPane.addWaveform(new EmptyWaveform(state.get(SHOWN_WAVEFORM + i)), -1); //check if t is selected trackEntries.add(trackEntry); if(Boolean.parseBoolean(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED))) selectedTrackEntries.add(trackEntry); - String v = state.get(SHOWN_WAVEFORM + i + VALUE_DISPLAY); - if(v!=null) - trackEntry.valueDisplay=ValueDisplay.valueOf(v); - String s = state.get(SHOWN_WAVEFORM + i + WAVE_DISPLAY); - if(s!=null) - trackEntry.waveDisplay=WaveDisplay.valueOf(s); + } else { + IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i)); + if (waveform != null) { + TrackEntry trackEntry = waveformPane.addWaveform(waveform, -1); + //check if t is selected + trackEntries.add(trackEntry); + if(Boolean.parseBoolean(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED))) + selectedTrackEntries.add(trackEntry); + String v = state.get(SHOWN_WAVEFORM + i + VALUE_DISPLAY); + if(v!=null) + trackEntry.valueDisplay=ValueDisplay.valueOf(v); + String s = state.get(SHOWN_WAVEFORM + i + WAVE_DISPLAY); + if(s!=null) + trackEntry.waveDisplay=WaveDisplay.valueOf(s); + } } } Integer cursorLength = state.containsKey(SHOWN_CURSOR+"S")?Integer.parseInt(state.get(SHOWN_CURSOR + "S")):0; //$NON-NLS-1$ //$NON-NLS-2$