use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Bug326117_EmbeddedBrowser method installBrowser.
public static Browser installBrowser(Composite parent, String homeURL) {
Browser browser = new Browser(parent, SWT.EMBEDDED);
browser.setUrl(homeURL);
return browser;
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Bug326117_EmbeddedBrowser method main.
public static void main(String[] args) {
final Display display = Display.getDefault();
Frame frm = new Frame("MyBrowser");
Canvas embedded = new Canvas();
frm.add(embedded, BorderLayout.CENTER);
frm.pack();
final Shell composite = SWT_AWT.new_Shell(display, embedded);
composite.setLayout(new FillLayout(SWT.VERTICAL));
final Browser browser = installBrowser(composite, "http://www.baidu.com");
frm.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
// composite.dispose();
// display.dispose();
}
});
JTextField addr = new JTextField(80);
addr.addActionListener(e -> display.syncExec(() -> browser.setUrl(((JTextComponent) e.getSource()).getText())));
frm.add(addr, BorderLayout.NORTH);
frm.setSize(800, 600);
frm.setVisible(true);
while (frm.isDisplayable()) if (!display.readAndDispatch())
display.sleep();
// display.dispose();
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Bug510905_Browser_TwoJsConsoles method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(500, 600);
shell.setLayout(new RowLayout());
Composite leftBrowser = new Composite(shell, SWT.NONE);
Composite rightBrowser = new Composite(shell, SWT.None);
Button button = new Button(rightBrowser, SWT.PUSH);
button.setText("my button");
final Browser browser = makeBrowserWithConsole(leftBrowser, "theJavaFunction");
new CustomFunction(browser, "theJavaFunction");
final Browser browser2 = makeBrowserWithConsole(rightBrowser, "theJavaFunction");
new CustomFunction(browser2, "theJavaFunction");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Bug525305_Browser_OpenUrl method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(500, 600);
shell.setLayout(new FillLayout());
final Browser browser = new Browser(shell, SWT.NONE);
browser.setText("hello <b>world!</b>");
display.addListener(SWT.OpenUrl, e -> {
System.out.println("OpenUrl with:" + e.text);
browser.setUrl(e.text);
});
display.addListener(SWT.OpenDocument, e -> {
System.out.println("OpenDocument with: " + e.text);
browser.setText("OpenDocument was called with arg: " + e.text);
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Bug528549_browser_MouseFocusEventListeners method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(500, 200);
final Browser browser = new Browser(shell, SWT.NONE);
browser.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
System.out.println("Browser Focus lost " + e.toString());
}
@Override
public void focusGained(FocusEvent e) {
System.out.println("Browser Focus gained " + e.toString());
}
});
browser.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
System.out.println("Browser Mouse Up " + e.toString());
}
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Browser Mouse Down " + e.toString());
}
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("Browse Mouse Double click " + e.toString());
}
});
// Below listeners already worked before bug. But good to have around.
browser.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
System.out.println("Browser key released " + e.toString());
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Browser key pressed " + e.toString());
}
});
browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString()));
// Generates a lot of events...
browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString()));
Button jsOnButton = new Button(shell, SWT.PUSH);
jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOnButton.setText("JS Off");
jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false)));
Button jsOffButton = new Button(shell, SWT.PUSH);
jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOffButton.setText("JS On");
jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true)));
Button loadNextPage = new Button(shell, SWT.PUSH);
loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
loadNextPage.setText("Load next page");
loadNextPage.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText())));
browser.setText(getNewText());
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Aggregations