diff --git a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java
index a6e05ed..d677b73 100644
--- a/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java
+++ b/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/SQLiteDbLoader.java
@@ -14,6 +14,7 @@ import java.beans.IntrospectionException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -91,6 +92,8 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
if (buffer[i] != x[i]) return false;
} catch(FileNotFoundException e) {
return false;
+ } catch(IOException e) { //if an I/O error occurs
+ return false;
}
database=new SQLiteDatabase(file.getAbsolutePath());
database.setData("TIMERESOLUTION", 1L);
diff --git a/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF b/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF
index 1e8ad75..a11ba7f 100644
--- a/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF
+++ b/com.minres.scviewer.database.ui.swt/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SWT widget
Bundle-SymbolicName: com.minres.scviewer.database.ui.swt
-Bundle-Version: 2.1.0.qualifier
+Bundle-Version: 2.2.0.qualifier
Bundle-Vendor: MINRES Technologies GmbH
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.swt;bundle-version="3.103.1",
diff --git a/com.minres.scviewer.database.ui.swt/pom.xml b/com.minres.scviewer.database.ui.swt/pom.xml
index 95ddd22..34b8a4f 100644
--- a/com.minres.scviewer.database.ui.swt/pom.xml
+++ b/com.minres.scviewer.database.ui.swt/pom.xml
@@ -8,5 +8,5 @@
2.0.0-SNAPSHOT
../com.minres.scviewer.parent
- 2.1.0-SNAPSHOT
+ 2.2.0-SNAPSHOT
\ No newline at end of file
diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/Constants.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/Constants.java
index 679fc92..4abb67c 100644
--- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/Constants.java
+++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/Constants.java
@@ -2,8 +2,11 @@ package com.minres.scviewer.database.swt;
public class Constants {
- public final static String[] unitString={"fs", "ps", "ns", "us", "ms"};//, "s"};
+ public static final String[] unitString={"fs", "ps", "ns", "us", "ms"};//, "s"};
- public final static int[] unitMultiplier={1, 3, 10, 30, 100, 300};
+ public static final int[] unitMultiplier={1, 3, 10, 30, 100, 300};
+
+ public static final String CONTENT_PROVIDER_TAG = "TOOLTIP_CONTENT_PROVIDER";
+ public static final String HELP_PROVIDER_TAG = "TOOLTIP_HELP_PROVIDER";
}
diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/ToolTipContentProvider.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/ToolTipContentProvider.java
new file mode 100644
index 0000000..6d46a31
--- /dev/null
+++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/ToolTipContentProvider.java
@@ -0,0 +1,10 @@
+package com.minres.scviewer.database.swt;
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+
+public interface ToolTipContentProvider {
+
+ public boolean createContent(Composite parent, Point pt);
+
+}
\ No newline at end of file
diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/ToolTipHelpTextProvider.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/ToolTipHelpTextProvider.java
new file mode 100644
index 0000000..8892b80
--- /dev/null
+++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/ToolTipHelpTextProvider.java
@@ -0,0 +1,12 @@
+package com.minres.scviewer.database.swt;
+
+import org.eclipse.swt.widgets.Widget;
+
+public interface ToolTipHelpTextProvider {
+ /**
+ * Get help text
+ * @param widget the widget that is under help
+ * @return a help text string
+ */
+ public String getHelpText(Widget widget);
+}
\ No newline at end of file
diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RelSelectionDialog.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RelSelectionDialog.java
new file mode 100644
index 0000000..fc53660
--- /dev/null
+++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/RelSelectionDialog.java
@@ -0,0 +1,73 @@
+package com.minres.scviewer.database.swt.internal;
+
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
+import java.util.ArrayList;
+import java.util.stream.Collectors;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+
+import com.minres.scviewer.database.ITx;
+import com.minres.scviewer.database.ITxRelation;
+
+class RelSelectionDialog extends Dialog {
+ private java.util.List entries;
+
+ private java.util.List entryTx;
+
+ private ITxRelation selected = null;
+
+ public RelSelectionDialog(Shell shell, ArrayList candidates, boolean target) {
+ super(shell);
+ entries = candidates;
+ entryTx = entries.stream().map(r->target?r.getTarget():r.getSource()).collect(Collectors.toCollection(ArrayList::new));
+ }
+
+public ITxRelation open() {
+ Shell parent = getParent();
+ Shell dialog = new Shell(parent, SWT.SHEET | SWT.APPLICATION_MODAL);
+ dialog.setMinimumSize(10, 10);
+
+ RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
+ //rowLayout.fill = true; // Overriding default values.
+ rowLayout.marginWidth=3;
+ rowLayout.marginHeight=0;
+ rowLayout.marginLeft = 3;
+ rowLayout.marginTop = 0;
+ rowLayout.marginRight = 3;
+ rowLayout.marginBottom = 0;
+ dialog.setLayout(rowLayout);
+ final Label lbl = new Label(dialog,SWT.NONE);
+ lbl.setText("Select one:");
+ final List list = new List (dialog, SWT.NONE);
+ for (ITx iTx : entryTx) {
+ list.add ("#tx" + iTx.getId()+" ("+iTx.getStream().getFullName()+")");
+ }
+ list.addListener (SWT.Selection, e -> {
+ int selection = list.getSelectionIndex();
+ if(selection>=0) {
+ selected=entries.get(selection);
+ dialog.close();
+ }
+ });
+ final Button bt = new Button(dialog, SWT.PUSH | SWT.RIGHT);
+ bt.setText("Dismiss");
+ bt.setAlignment(SWT.CENTER);
+ bt.addSelectionListener(widgetSelectedAdapter(e -> dialog.close()));
+ dialog.pack();
+ dialog.open();
+ Display display = parent.getDisplay();
+ while (!dialog.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ return selected;
+ }
+}
\ No newline at end of file
diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ToolTipHandler.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ToolTipHandler.java
new file mode 100644
index 0000000..ea6b0d0
--- /dev/null
+++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/ToolTipHandler.java
@@ -0,0 +1,143 @@
+package com.minres.scviewer.database.swt.internal;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+
+import com.minres.scviewer.database.swt.Constants;
+import com.minres.scviewer.database.swt.ToolTipContentProvider;
+import com.minres.scviewer.database.swt.ToolTipHelpTextProvider;
+
+class ToolTipHandler {
+
+ private final Display display;
+ private Shell parentShell;
+ private Shell shell;
+
+ private Widget tipWidget; // widget this tooltip is hovering over
+ private Point tipPosition; // the position being hovered over
+
+ private static final int hoverYOffset = 1;
+
+ /**
+ * Creates a new tooltip handler
+ *
+ * @param parent the parent Shell
+ */
+ public ToolTipHandler(Shell parent) {
+ display = parent.getDisplay();
+ parentShell = parent;
+ }
+
+ /**
+ * Enables customized hover help for a specified control
+ *
+ * @control the control on which to enable hoverhelp
+ */
+ public void activateHoverHelp(final Control control) {
+ Listener listener = new Listener () {
+ Shell tip = null;
+ @Override
+ public void handleEvent (Event event) {
+ switch (event.type) {
+ case SWT.KeyDown:{
+ if (tip != null && tip.isVisible() && event.keyCode == SWT.F2) {
+ tip.setFocus();
+ break;
+ }
+ }
+ case SWT.Dispose:
+ case SWT.MouseMove:
+ case SWT.MouseDown: {
+ if (tip != null){
+ tip.dispose ();
+ tip = null;
+ tipWidget=null;
+ }
+ break;
+ }
+ case SWT.MouseHover: {
+ Object o = control.getData(Constants.CONTENT_PROVIDER_TAG);
+ if(o != null && o instanceof ToolTipContentProvider) {
+ ToolTipContentProvider provider = ((ToolTipContentProvider)o);
+ Point pt = new Point (event.x, event.y);
+ tipPosition = control.toDisplay(pt);
+ if (tip != null && !tip.isDisposed ()) tip.dispose ();
+ tip = new Shell (parentShell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
+ tip.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
+ GridLayout layout = new GridLayout(1, true);
+ layout.verticalSpacing=0;
+ layout.horizontalSpacing=0;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ tip.setLayout(layout);
+ boolean visible = provider.createContent(tip, pt);
+ tip.pack();
+ tip.setSize(tip.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ setHoverLocation(tip, tipPosition);
+ tip.setVisible (visible);
+ if(visible)
+ tipWidget=event.widget;
+ }
+ }
+ }
+ }
+ };
+ control.addListener (SWT.Dispose, listener);
+ control.addListener (SWT.KeyDown, listener);
+ //control.addListener (SWT.MouseMove, listener);
+ control.addListener (SWT.MouseHover, listener);
+ control.addListener (SWT.MouseDown, listener);
+
+ /*
+ * Trap F1 Help to pop up a custom help box
+ */
+ control.addHelpListener(event -> {
+ if (tipWidget == null) return;
+ ToolTipHelpTextProvider handler = (ToolTipHelpTextProvider)tipWidget.getData(Constants.HELP_PROVIDER_TAG);
+ if (handler == null) return;
+ String text = handler.getHelpText(tipWidget);
+ if (text == null) return;
+
+ if (shell.isVisible()) {
+ shell.setVisible(false);
+ Shell helpShell = new Shell(parentShell, SWT.SHELL_TRIM);
+ helpShell.setLayout(new FillLayout());
+ Label label = new Label(helpShell, SWT.NONE);
+ label.setText(text);
+ helpShell.pack();
+ setHoverLocation(helpShell, tipPosition);
+ helpShell.open();
+ }
+ });
+ // control.addKeyListener(KeyListener.keyPressedAdapter( e-> {
+ // if (e.keyCode == SWT.F2 && shell.isVisible()) {
+ // shell.setFocus();
+ // }
+ // }));
+ }
+
+ /**
+ * Sets the location for a hovering shell
+ * @param shell the object that is to hover
+ * @param position the position of a widget to hover over
+ * @return the top-left location for a hovering box
+ */
+ private void setHoverLocation(Shell shell, Point position) {
+ Rectangle displayBounds = shell.getDisplay().getBounds();
+ Rectangle shellBounds = shell.getBounds();
+ shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
+ shellBounds.y = Math.max(Math.min(position.y + hoverYOffset, displayBounds.height - shellBounds.height), 0);
+ shell.setBounds(shellBounds);
+ }
+}
\ No newline at end of file
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 06687bc..dd29137 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
@@ -426,7 +426,7 @@ public class WaveformCanvas extends Canvas{
}
}
- public List