use of org.eclipse.swt.browser.LocationEvent in project BiglyBT by BiglySoftware.
the class BrowserWrapperFake method setUrl.
@Override
public void setUrl(final String _url) {
url = _url;
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
String url_str = _url;
int pos = url_str.indexOf('?');
if (pos != -1) {
url_str = url_str.substring(0, pos);
}
link_label.setText(url_str);
browser.layout();
for (LocationListener l : location_listeners) {
try {
LocationEvent event = new LocationEvent(browser);
event.top = true;
event.location = _url;
l.changed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
for (ProgressListener l : progress_listeners) {
try {
ProgressEvent event = new ProgressEvent(browser);
l.completed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
for (TitleListener l : title_listeners) {
try {
TitleEvent event = new TitleEvent(browser);
event.title = "Browser Disabled";
l.changed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
use of org.eclipse.swt.browser.LocationEvent in project epp.mpc by eclipse.
the class OverviewToolTip method createToolTipContentArea.
@Override
protected Composite createToolTipContentArea(Event event, final Composite parent) {
Shell shell = parent.getShell();
setData(Shell.class.getName(), shell);
AbstractMarketplaceDiscoveryItem.setWidgetId(shell, DiscoveryItem.WIDGET_ID_OVERVIEW);
GridLayoutFactory.fillDefaults().applyTo(parent);
Color backgroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_WHITE);
final Composite container = new Composite(parent, SWT.NULL);
container.setBackground(backgroundColor);
boolean hasImage = false;
if (overview.getScreenshot() != null) {
hasImage = true;
}
final boolean addLearnMoreLink = browser != null && overview.getUrl() != null && overview.getUrl().length() > 0;
final int borderWidth = 1;
final int heightHint = SCREENSHOT_HEIGHT + (borderWidth * 2);
final int widthHint = SCREENSHOT_WIDTH;
final int containerWidthHintWithImage = 650;
final int containerWidthHintWithoutImage = 500;
GridDataFactory.fillDefaults().grab(true, true).hint(hasImage ? containerWidthHintWithImage : containerWidthHintWithoutImage, SWT.DEFAULT).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns((leftImage != null) ? 3 : 2).margins(5, 5).spacing(3, 0).applyTo(container);
if (leftImage != null) {
Label imageLabel = new Label(container, SWT.NONE);
imageLabel.setImage(leftImage);
imageLabel.setBackground(backgroundColor);
int imageWidthHint = leftImage.getBounds().width + 5;
GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).hint(imageWidthHint, SWT.DEFAULT).applyTo(imageLabel);
}
String summary = overview.getSummary();
Composite summaryContainer = new Composite(container, SWT.NULL);
summaryContainer.setBackground(backgroundColor);
GridLayoutFactory.fillDefaults().applyTo(summaryContainer);
GridDataFactory gridDataFactory = GridDataFactory.fillDefaults().grab(true, true).span(hasImage ? 1 : 2, 1);
if (hasImage) {
gridDataFactory.hint(widthHint, heightHint);
}
gridDataFactory.applyTo(summaryContainer);
Browser summaryLabel = new Browser(summaryContainer, SWT.NULL);
Font dialogFont = JFaceResources.getDialogFont();
FontData[] fontData = dialogFont.getFontData();
// $NON-NLS-1$
String attr = "";
// $NON-NLS-1$
String fontSizeUnitOfMeasure = "pt";
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
// $NON-NLS-1$
fontSizeUnitOfMeasure = "px";
} else if (Platform.OS_WIN32.equals(Platform.getOS())) {
// $NON-NLS-1$
attr = "overflow: auto; ";
}
String cssStyle = // $NON-NLS-1$ //$NON-NLS-2$
"body, p, div, * {" + attr + "font-family:\"" + fontData[0].getName() + "\",Arial,sans-serif !important;font-size:" + fontData[0].getHeight() + fontSizeUnitOfMeasure + // $NON-NLS-1$ //$NON-NLS-2$
" !important;" + // $NON-NLS-1$
"} body { margin: 0px; background-color: white;}";
summaryLabel.setFont(dialogFont);
String html = // $NON-NLS-1$//$NON-NLS-2$
"<html><style>" + cssStyle + "</style><body>" + TextUtil.cleanInformalHtmlMarkup(summary) + // $NON-NLS-1$
"</body></html>";
summaryLabel.setText(html);
summaryLabel.setBackground(backgroundColor);
// instead of opening links in the tooltip, open a new browser window
summaryLabel.addLocationListener(new LocationListener() {
public void changing(LocationEvent event) {
if (event.location.equals("about:blank")) {
// $NON-NLS-1$
return;
}
event.doit = false;
OverviewToolTip.this.hide();
WorkbenchUtil.openUrl(event.location, IWorkbenchBrowserSupport.AS_EXTERNAL);
}
public void changed(LocationEvent event) {
}
});
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, hasImage ? SWT.DEFAULT : SCREENSHOT_HEIGHT).applyTo(summaryLabel);
if (hasImage) {
final Composite imageContainer = new Composite(container, SWT.BORDER);
GridLayoutFactory.fillDefaults().applyTo(imageContainer);
GridDataFactory.fillDefaults().grab(false, false).align(SWT.CENTER, SWT.BEGINNING).hint(widthHint + (borderWidth * 2), heightHint).applyTo(imageContainer);
Label imageLabel = new Label(imageContainer, SWT.NULL);
GridDataFactory.fillDefaults().hint(widthHint, SCREENSHOT_HEIGHT).indent(borderWidth, borderWidth).applyTo(imageLabel);
imageLabel.setBackground(backgroundColor);
imageLabel.setSize(widthHint, SCREENSHOT_HEIGHT);
provideImage(imageLabel, source, overview.getScreenshot());
final Cursor handCursor = new Cursor(imageLabel.getDisplay(), SWT.CURSOR_HAND);
imageLabel.setCursor(handCursor);
imageLabel.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
handCursor.dispose();
}
});
imageLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
OverviewToolTip.this.hide();
WorkbenchUtil.openUrl(overview.getScreenshot(), IWorkbenchBrowserSupport.AS_EXTERNAL);
}
});
// creates a border
imageContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
}
if (addLearnMoreLink) {
Link link = new Link(summaryContainer, SWT.NULL);
AbstractMarketplaceDiscoveryItem.setWidgetId(link, DiscoveryItem.WIDGET_ID_LEARNMORE);
GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
link.setText(Messages.OverviewToolTip_learnMoreLink);
link.setBackground(backgroundColor);
link.setToolTipText(NLS.bind(Messages.OverviewToolTip_openUrlInBrowser, overview.getUrl()));
link.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
OverviewToolTip.this.hide();
browser.openUrl(overview.getUrl());
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
}
if (!hasImage) {
// prevent overviews with no image from providing unlimited text.
Point optimalSize = summaryContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
if (optimalSize.y > (heightHint + 10)) {
((GridData) summaryContainer.getLayoutData()).heightHint = heightHint;
container.layout(true);
}
}
// hack: cause the tooltip to gain focus so that we can capture the escape key
// this must be done async since the tooltip is not yet visible.
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
if (!parent.isDisposed()) {
parent.setFocus();
}
}
});
return container;
}
use of org.eclipse.swt.browser.LocationEvent in project eclipse-integration-commons by spring-projects.
the class HtmlTooltip method createToolTipContentArea.
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(GridLayoutFactory.fillDefaults().create());
Browser browser = new Browser(composite, SWT.NONE);
browser.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
browser.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
browser.setJavascriptEnabled(false);
browser.addOpenWindowListener(new OpenWindowListener() {
@Override
public void open(WindowEvent event) {
// Cancel opening of new windows
event.required = true;
}
});
// Replace browser's built-in context menu with none
browser.setMenu(new Menu(browser.getShell(), SWT.NONE));
String htmlContent = html.get();
browser.setText(htmlContent);
Point size = computeSizeHint(browser, htmlContent);
browser.setLayoutData(GridDataFactory.swtDefaults().hint(size.x, size.y).create());
// Add after HTML content is set to avoid event fired after the content is set
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent event) {
super.changing(event);
event.doit = false;
try {
PlatformUI.getWorkbench().getBrowserSupport().createBrowser(null).openURL(new URL(event.location));
hide();
} catch (PartInitException | MalformedURLException e) {
UiPlugin.log(e);
}
}
});
return composite;
}
use of org.eclipse.swt.browser.LocationEvent in project bndtools by bndtools.
the class JPMBrowserView method createPartControl.
@Override
public void createPartControl(Composite parent) {
StackLayout stack = new StackLayout();
parent.setLayout(stack);
JpmPreferences prefs = new JpmPreferences();
if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
external = true;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
new Label(composite, SWT.NONE).setText("Searchable Repository is configured to open in an external browser.");
Hyperlink linkToPrefs = new Hyperlink(composite, SWT.NONE);
linkToPrefs.setText("Open Preference Page");
linkToPrefs.setUnderlined(true);
linkToPrefs.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getViewSite().getShell(), "bndtools.prefPages.jpm", new String[] { "bndtools.prefPages.jpm" }, null);
dialog.open();
}
});
// linkToPrefs.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
stack.topControl = composite;
} else {
if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_PLATFORM_DEFAULT) {
browser = new Browser(parent, SWT.NONE);
stack.topControl = browser;
} else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_WEBKIT) {
browser = new Browser(parent, SWT.WEBKIT);
stack.topControl = browser;
} else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_MOZILLA) {
browser = new Browser(parent, SWT.MOZILLA);
stack.topControl = browser;
}
createActions();
// Prevent navigation away from JPM4J.org, and redirect from HTTP back to HTTPS
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent event) {
setContentDescription(event.location);
/*
* if (event.location.startsWith(HTTPS_URL)) return; if (event.location.startsWith(HTTP_URL))
* event.location = event.location.replaceFirst(HTTP_URL, HTTP_URL); else event.doit = false;
*/
}
});
}
selectionService = getViewSite().getWorkbenchWindow().getSelectionService();
selectionService.addSelectionListener(this);
handleWorkbenchSelection(selectionService.getSelection());
}
use of org.eclipse.swt.browser.LocationEvent in project pentaho-kettle by pentaho.
the class ShowHelpDialog method addProgressAndLocationListener.
private void addProgressAndLocationListener() {
ProgressListener progressListener = new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
}
@Override
public void completed(ProgressEvent event) {
if (fromPrint) {
wBrowser.execute(PRINT_SCRIPT);
fromPrint = false;
}
setForwardBackEnable();
}
};
LocationListener listener = new LocationListener() {
@Override
public void changing(LocationEvent event) {
if (event.location.endsWith(".pdf")) {
Program.launch(event.location);
event.doit = false;
}
}
@Override
public void changed(LocationEvent event) {
textURL.setText(event.location);
}
};
wBrowser.addProgressListener(progressListener);
wBrowser.addLocationListener(listener);
}
Aggregations