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 9158736..23360c2 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 @@ -164,7 +164,7 @@ public class WaveformView implements IWaveformView { setSelection(new StructuredSelection(res), (e.stateMask & SWT.CTRL) != 0, false); } else setSelection(new StructuredSelection(entry.getValue()), (e.stateMask & SWT.CTRL) != 0, - false); + false); } else { setSelection(new StructuredSelection(entry.getValue()), (e.stateMask & SWT.CTRL) != 0, false); } @@ -197,59 +197,64 @@ public class WaveformView implements IWaveformView { down = false; if (start == null) return; - if ((e.stateMask & SWT.MODIFIER_MASK & ~SWT.SHIFT) != 0) - return; // don't react on modifier except shift - if (e.button == 1 && Math.abs(e.x - start.x) > 3) { - asyncUpdate(e.widget); - long startTime = waveformCanvas.getTimeForOffset(start.x); - long endTime = waveformCanvas.getTimeForOffset(end.x); - long targetTimeRange = endTime - startTime; - long currentTimeRange = waveformCanvas.getMaxVisibleTime() - waveformCanvas.getMinVisibleTime(); - if (targetTimeRange == 0) - return; - long relation = currentTimeRange / targetTimeRange; - long i = 1; - int level = 0; - do { - if (relation < 0) { - if (-relation < i) { - break; - } - level--; - if (-relation < i * 3) { - break; - } - level--; - } else { - if (relation < i) { - break; - } - level++; - if (relation < i * 3) { - break; - } - level++; - } - i = i * 10; - } while (i < 10000); - if (i < 10000) { - int curLevel = waveformCanvas.getZoomLevel(); - waveformCanvas.setZoomLevel(curLevel - level, (startTime + endTime) / 2); - } - } else if (e.button == 1 && ((e.stateMask & SWT.SHIFT) == 0)) { - // set cursor (button 1 and no shift) - if (Math.abs(e.x - start.x) < 3 && Math.abs(e.y - start.y) < 3) { - // first set cursor time - setCursorTime(snapOffsetToEvent(start)); - // then set selection and reveal - setSelection(new StructuredSelection(initialSelected)); + if ((e.stateMask & SWT.MODIFIER_MASK & ~(SWT.SHIFT | SWT.CTRL)) != 0) + return; // don't react on modifier except shift and control + boolean isCtrl = (e.stateMask & SWT.CTRL)!=0; + boolean isShift = (e.stateMask & SWT.SHIFT)!=0; + if (e.button == 1) { + if (Math.abs(e.x - start.x) > 3) { // was drag event asyncUpdate(e.widget); + long startTime = waveformCanvas.getTimeForOffset(start.x); + long endTime = waveformCanvas.getTimeForOffset(end.x); + long targetTimeRange = endTime - startTime; + long currentTimeRange = waveformCanvas.getMaxVisibleTime() - waveformCanvas.getMinVisibleTime(); + if (targetTimeRange == 0) + return; + long relation = currentTimeRange / targetTimeRange; + long i = 1; + int level = 0; + do { + if (relation < 0) { + if (-relation < i) { + break; + } + level--; + if (-relation < i * 3) { + break; + } + level--; + } else { + if (relation < i) { + break; + } + level++; + if (relation < i * 3) { + break; + } + level++; + } + i = i * 10; + } while (i < 10000); + if (i < 10000) { + int curLevel = waveformCanvas.getZoomLevel(); + waveformCanvas.setZoomLevel(curLevel - level, (startTime + endTime) / 2); + } + } else if( isShift) { // set marker (button 1 and shift) + setMarkerTime(snapOffsetToEvent(start), selectedMarker); + } else if(isCtrl) { // set cursor (button 1 and ctrl) + setCursorTime(snapOffsetToEvent(start)); + } else { // set cursor (button 1 only) + if (Math.abs(e.y - start.y) < 3) { + // first set cursor time + setCursorTime(snapOffsetToEvent(start)); + // then set selection and reveal + setSelection(new StructuredSelection(initialSelected)); + } } - } else if (e.button == 2 || (e.button == 1 && (e.stateMask & SWT.SHIFT) != 0)) { - // set marker (button 1 and shift) + } else if (e.button == 2) { // set marker (button 2) setMarkerTime(snapOffsetToEvent(start), selectedMarker); - asyncUpdate(e.widget); } + asyncUpdate(e.widget); } protected long snapOffsetToEvent(Point p) { @@ -287,8 +292,8 @@ public class WaveformView implements IWaveformView { @Override public void handleEvent(Event e) { switch (e.type) { - case SWT.MouseWheel: - break; +// case SWT.MouseWheel: +// break; case SWT.MouseDown: start = new Point(e.x, e.y); end = new Point(e.x, e.y); @@ -756,7 +761,7 @@ public class WaveformView implements IWaveformView { ITx txSel = (ITx) selList.get(0); TrackEntry trackEntry = selList.size() == 2 && selList.get(1) instanceof TrackEntry ? (TrackEntry) selList.get(1) - : null; + : null; if (trackEntry == null) { trackEntry = getEntryFor(txSel); if (trackEntry == null && addIfNeeded) { @@ -930,7 +935,7 @@ public class WaveformView implements IWaveformView { return candidates.get(0); default: ArrayList visibleCandidates = candidates.stream().filter(this::streamsVisible) - .collect(Collectors.toCollection(ArrayList::new)); + .collect(Collectors.toCollection(ArrayList::new)); if (visibleCandidates.isEmpty()) { return new RelSelectionDialog(waveformCanvas.getShell(), candidates, target).open(); } else if (visibleCandidates.size() == 1) { @@ -1230,7 +1235,7 @@ public class WaveformView implements IWaveformView { if (event.y < tracksVerticalHeight) { event.doit = true; LocalSelectionTransfer.getTransfer() - .setSelection(new StructuredSelection(currentWaveformSelection)); + .setSelection(new StructuredSelection(currentWaveformSelection)); } } diff --git a/plugins/com.minres.scviewer.e4.application/Application.e4xmi b/plugins/com.minres.scviewer.e4.application/Application.e4xmi index bdf9b97..85f4ea6 100644 --- a/plugins/com.minres.scviewer.e4.application/Application.e4xmi +++ b/plugins/com.minres.scviewer.e4.application/Application.e4xmi @@ -9,6 +9,7 @@ + @@ -55,7 +56,8 @@ - + + @@ -139,6 +141,7 @@ + type:user @@ -280,6 +283,7 @@ + diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/HelpHandler.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/HelpHandler.java new file mode 100644 index 0000000..8602148 --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/HelpHandler.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.e4.application.handlers; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.swt.widgets.Shell; + +public class HelpHandler { + + static final String DIALOG_ID="com.minres.scviewer.e4.application.dialog.onlinehelp"; + + @Execute + public void execute(Shell shell, MApplication app, MWindow window, EModelService ms /*@Named("mdialog01.dialog.0") MDialog dialog*/) { + MPart mel = (MPart) ms.find(DIALOG_ID, app); //$NON-NLS-1$ + mel.setToBeRendered(true); + mel.setToBeRendered(false); + } + +} diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java index c5a96bf..caccf88 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java @@ -131,7 +131,9 @@ public class AboutDialog extends Dialog { if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { Desktop.getDesktop().browse(new java.net.URI(style.data.toString())); } - } catch (IOException | URISyntaxException | IllegalArgumentException e) {} + } catch (IOException | URISyntaxException | IllegalArgumentException e) { + } catch (UnsupportedOperationException e) { + } }); styleRange.start = 0; diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/HelpDialog.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/HelpDialog.java new file mode 100644 index 0000000..e6b97f4 --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/HelpDialog.java @@ -0,0 +1,175 @@ +package com.minres.scviewer.e4.application.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTError; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.LocationListener; +import org.eclipse.swt.browser.ProgressEvent; +import org.eclipse.swt.browser.ProgressListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.ProgressBar; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; + +public class HelpDialog extends Dialog { + /** + * Create the dialog. + * + * @param parentShell the parent shell + */ + @Inject + public HelpDialog(Shell parentShell) { + super(parentShell); + setShellStyle(getShellStyle() | SWT.MODELESS | SWT.MAX | SWT.BORDER | SWT.TITLE); + setBlockOnOpen(false); + } + + @Override + protected boolean isResizable() { + return true; + } + + @Override + protected Point getInitialSize() { + return new Point(800, 600); + } + + /** + * Create contents of the dialog. + * + * @param parent the parent + * @return the control + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 3; + container.setLayout(gridLayout); + ToolBar toolbar = new ToolBar(container, SWT.NONE); + ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH); + itemBack.setText("Back"); + ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH); + itemForward.setText("Forward"); + ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH); + itemStop.setText("Stop"); + ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH); + itemRefresh.setText("Refresh"); + ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH); + itemGo.setText("Go"); + + GridData data = new GridData(); + data.horizontalSpan = 3; + toolbar.setLayoutData(data); + + Label labelAddress = new Label(container, SWT.NONE); + labelAddress.setText("Address"); + + final Text location = new Text(container, SWT.BORDER); + data = new GridData(); + data.horizontalAlignment = GridData.FILL; + data.horizontalSpan = 2; + data.grabExcessHorizontalSpace = true; + location.setLayoutData(data); + + final Browser browser; + try { + browser = new Browser(container, SWT.NONE); + data = new GridData(); + // data.widthHint = 800; + // data.heightHint =600; + data.horizontalAlignment = GridData.FILL; + data.verticalAlignment = GridData.FILL; + data.horizontalSpan = 3; + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = true; + browser.setLayoutData(data); + + final Label status = new Label(container, SWT.NONE); + data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + status.setLayoutData(data); + + final ProgressBar progressBar = new ProgressBar(container, SWT.NONE); + data = new GridData(); + data.horizontalAlignment = GridData.END; + progressBar.setLayoutData(data); + + /* event handling */ + Listener listener = event -> { + ToolItem item = (ToolItem) event.widget; + String string = item.getText(); + if (string.equals("Back")) + browser.back(); + else if (string.equals("Forward")) + browser.forward(); + else if (string.equals("Stop")) + browser.stop(); + else if (string.equals("Refresh")) + browser.refresh(); + else if (string.equals("Go")) + browser.setUrl(location.getText()); + }; + browser.addProgressListener(new ProgressListener() { + @Override + public void changed(ProgressEvent event) { + if (event.total == 0) return; + int ratio = event.current * 100 / event.total; + progressBar.setSelection(ratio); + } + @Override + public void completed(ProgressEvent event) { + progressBar.setSelection(0); + } + }); + browser.addStatusTextListener(event -> status.setText(event.text)); + browser.addLocationListener(LocationListener.changedAdapter(event -> { + if (event.top) location.setText(event.location); + } + )); + itemBack.addListener(SWT.Selection, listener); + itemForward.addListener(SWT.Selection, listener); + itemStop.addListener(SWT.Selection, listener); + itemRefresh.addListener(SWT.Selection, listener); + itemGo.addListener(SWT.Selection, listener); + location.addListener(SWT.DefaultSelection, e -> browser.setUrl(location.getText())); + + browser.setUrl("http://eclipse.org"); + } catch (SWTError e) { + System.out.println("Could not instantiate Browser: " + e.getMessage()); + } + return container; + } + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + // create OK button + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true); + } + + /** + * Open the dialog. + * @return the result + */ + @PostConstruct + @Override + public int open() { + return super.open(); + } + +} \ No newline at end of file