X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=rcp%2Forg.argeo.eclipse.ui.rcp%2Fsrc%2Forg%2Fargeo%2Fswt%2Fdesktop%2FMiniBrowser.java;fp=rcp%2Forg.argeo.eclipse.ui.rcp%2Fsrc%2Forg%2Fargeo%2Fswt%2Fdesktop%2FMiniBrowser.java;h=0000000000000000000000000000000000000000;hb=2669e5797bdf4bcfa3a15b273ca4239e215d9cd4;hp=3152db1a9704fd97917053e27d6a0fc3c8e76b27;hpb=9b60a87396b76e794032a259609d845e52b757b7;p=lgpl%2Fargeo-commons.git diff --git a/rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniBrowser.java b/rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniBrowser.java deleted file mode 100644 index 3152db1a9..000000000 --- a/rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniBrowser.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.argeo.swt.desktop; - -import java.util.Observable; -import java.util.function.BiFunction; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.browser.Browser; -import org.eclipse.swt.browser.LocationAdapter; -import org.eclipse.swt.browser.LocationEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.FillLayout; -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.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** A minimalistic web browser based on {@link Browser}. */ -public class MiniBrowser implements BiFunction { - @Override - public Control apply(Composite parent, MiniBrowser.Context context) { - parent.setLayout(new GridLayout()); - Control toolBar = createToolBar(parent, context); - toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - Control body = createBody(parent, context); - body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - return body; - } - - public Control createToolBar(Composite parent, MiniBrowser.Context context) { - Composite toolBar = new Composite(parent, SWT.NONE); - toolBar.setLayout(new FillLayout()); - Text addressT = new Text(toolBar, SWT.SINGLE | SWT.BORDER); - addressT.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - String url = addressT.getText().trim(); - context.setUrl(url); - } - }); - context.addObserver((o, v) -> addressT.setText(((Context) o).getUrl().toString())); - return toolBar; - } - - public Control createBody(Composite parent, MiniBrowser.Context context) { - Browser browser = new Browser(parent, SWT.WEBKIT); - browser.addLocationListener(new LocationAdapter() { - @Override - public void changing(LocationEvent event) { - if (!context.getUrl().equals(event.location)) - context.setUrl(event.location); - } - }); - browser.addTitleListener(e -> context.setTitle(e.title)); - context.addObserver((o, v) -> { - String url = ((Context) o).getUrl(); - if (!url.equals(browser.getUrl())) - browser.setUrl(url.toString()); - }); - return browser; - } - - /** The observable context of this web browser. */ - public static class Context extends Observable { - private String url; - private String title = ""; - - public void setUrl(String url) { - this.url = url; - System.out.println(url); - setChanged(); - notifyObservers(url); - } - - public String getUrl() { - return url; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - setChanged(); - notifyObservers(title); - } - - } - - public static void main(String[] args) { - Display display = Display.getCurrent() == null ? new Display() : Display.getCurrent(); - Shell shell = new Shell(display, SWT.SHELL_TRIM); - - MiniBrowser miniBrowser = new MiniBrowser(); - MiniBrowser.Context context = new MiniBrowser.Context(); - miniBrowser.apply(shell, context); - context.addObserver((o, v) -> shell.setText(((Context) o).getTitle())); - String url = args.length > 0 ? args[0] : "http://www.argeo.org"; - context.setUrl(url); - - shell.open(); - shell.setSize(new Point(800, 480)); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - -}