Author: yradtsevich
Date: 2011-11-17 11:27:48 -0500 (Thu, 17 Nov 2011)
New Revision: 36409
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java
Removed:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF
Log:
https://issues.jboss.org/browse/JBIDE-9539 : Browsersim app for testing mobile/desktop web
apps
- added automatic saving of settings on window disposing
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF 2011-11-17
16:27:48 UTC (rev 36409)
@@ -6,4 +6,4 @@
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.swt;bundle-version="3.7.0",
org.jboss.tools.browsersim.webkit;bundle-version="1.0.0"
-Export-Package: org.jboss.tools.browsersim
+Export-Package: org.jboss.tools.browsersim.ui
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,4 @@
+0
+Apple iPhone 3 320 480 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us)
AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
+Apple iPhone 4 640 960 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us)
AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
+Samsung Galaxy S II 640 800 Mozilla/5.0 (Linux; U; Android 2.3; en-us; GT-I9100
Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,400 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Observable;
-import java.util.Observer;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.browser.LocationEvent;
-import org.eclipse.swt.browser.LocationListener;
-import org.eclipse.swt.browser.ProgressEvent;
-import org.eclipse.swt.browser.ProgressListener;
-import org.eclipse.swt.browser.StatusTextEvent;
-import org.eclipse.swt.browser.StatusTextListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-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.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-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;
-import org.jboss.tools.browsersim.webkit.AbstractWebKitBrowser;
-import org.jboss.tools.browsersim.webkit.WebKitBrowserFactory;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class BrowserSim implements Runnable {
- private static final String DEFAULT_URL =
"http://www.w3schools.com/js/tryit_view.asp?filename=try_nav_useragent";
//$NON-NLS-1$
- private AbstractWebKitBrowser browser;
- private Display display;
- private Shell shell;
- private Text locationText;
- private Label statusLabel;
- private ProgressBar progressBar;
- private String initialUrl;
- private Menu devicesMenu;
- private DevicesManager devicesManager;
-
- public static void main(String[] args) {
-
-
-
-
- String initialUrl;
- if (args.length > 0) {
- String lastArg = args[args.length - 1];
- try {
- new URI(lastArg); // validate URL
- initialUrl = lastArg;
- } catch (URISyntaxException e) {
- initialUrl = DEFAULT_URL;
- }
- } else {
- initialUrl = DEFAULT_URL;
- }
-
- new BrowserSim(new Display(), initialUrl).run();
- }
-
- public BrowserSim(Display display, String initialUrl) {
- this.display = display;
- this.initialUrl = initialUrl;
- }
-
- @Override
- public void run() {
- shell = new Shell(display);
- shell.setText(Messages.BrowserSim_BROWSER_SIM);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 3;
- shell.setLayout(gridLayout);
- Menu appMenuBar = display.getMenuBar();
- if (appMenuBar == null) {
- appMenuBar = new Menu(shell, SWT.BAR);
- shell.setMenuBar(appMenuBar);
- }
-
- ToolBar toolbar = createControlBar();
- GridData data = new GridData();
- data.horizontalSpan = 3;
- toolbar.setLayoutData(data);
-
- Label labelAddress = new Label(shell, SWT.NONE);
- labelAddress.setText(Messages.BrowserSim_ADDRESS);
-
- locationText = new Text(shell, SWT.BORDER);
- data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.horizontalSpan = 2;
- data.grabExcessHorizontalSpace = true;
- data.widthHint = 0;
- locationText.setLayoutData(data);
-
- try {
- browser = WebKitBrowserFactory.createWebKitBrowser(shell, SWT.NONE);
- } catch (SWTError e) {
- System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_BROWSER +
e.getMessage());
- display.dispose();
- return;
- }
-
- data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.FILL;
- data.horizontalSpan = 3;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- browser.setLayoutData(data);
-
- statusLabel = new Label(shell, SWT.NONE);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 2;
- data.widthHint = 0;
- statusLabel.setLayoutData(data);
-
- progressBar = new ProgressBar(shell, SWT.NONE);
- data = new GridData();
- data.horizontalAlignment = GridData.END;
- progressBar.setLayoutData(data);
-
- browser.addProgressListener(new ProgressListener() {
- public void changed(ProgressEvent event) {
- if (event.total == 0) return;
- int ratio = event.current * 100 / event.total;
- progressBar.setSelection(ratio);
- }
- public void completed(ProgressEvent event) {
- progressBar.setSelection(0);
- }
- });
- browser.addStatusTextListener(new StatusTextListener() {
- public void changed(StatusTextEvent event) {
- statusLabel.setText(event.text);
- }
- });
- browser.addLocationListener(new LocationListener() {
- public void changed(LocationEvent event) {
- if (event.top) locationText.setText(event.location);
- }
- public void changing(LocationEvent event) {
- }
- });
-
- fillMenuBar(appMenuBar);
-
- locationText.addListener(SWT.DefaultSelection, new Listener() {
- public void handleEvent(Event e) {
- browser.setUrl(locationText.getText());
- }
- });
-
- if (!DevicesManager.getInstance().getDevicesList().getDevices().isEmpty()) {
- setDevice(DevicesManager.getInstance().getDevicesList().getDevices().get(0));
- }
- shell.open();
- browser.setUrl(initialUrl);
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-
- public ToolBar createControlBar() {
- ToolBar toolbar = new ToolBar(shell, SWT.NONE);
- ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
-// itemBack.setText("Back");
- itemBack.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.back();
- }
- });
-
- ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
-// itemForward.setText("Forward");
- itemForward.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.forward();
- }
- });
-
- ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
-// itemStop.setText("Stop");
- itemStop.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.stop();
- }
- });
-
- ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
-// itemRefresh.setText("Refresh");
- itemRefresh.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.refresh();
- }
- });
-
- ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
-// itemGo.setText("Go");
- itemGo.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.setUrl(locationText.getText());
- }
- });
-
- final Image imageBack = new Image(display,
getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_backward.gif"));
//$NON-NLS-1$
- final Image imageForward = new Image(display,
getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_forward.gif"));
//$NON-NLS-1$
- final Image imageStop = new Image(display,
getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_stop.gif"));
//$NON-NLS-1$
- final Image imageRefresh = new Image(display,
getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_refresh.gif"));
//$NON-NLS-1$
- final Image imageGo = new Image(display,
getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_go.gif"));
//$NON-NLS-1$
-
- itemBack.setImage(imageBack);
- itemForward.setImage(imageForward);
- itemStop.setImage(imageStop);
- itemRefresh.setImage(imageRefresh);
- itemGo.setImage(imageGo);
- shell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- imageBack.dispose();
- imageForward.dispose();
- imageStop.dispose();
- imageRefresh.dispose();
- imageGo.dispose();
- }
- });
-
- itemForward.setImage(imageForward);
-
-
- return toolbar;
- }
-
- private InputStream getResourceAsStream(String name) {
- return this.getClass().getResourceAsStream(name);
- }
-
- private File getResourceAsFile(String name) {
- return new File(this.getClass().getResource(name).getFile());
- }
-
- public void fillMenuBar(Menu appMenuBar) {
- Menu file = createDropDownMenu(appMenuBar, Messages.BrowserSim_FILE);
- MenuItem exit = new MenuItem(file, SWT.PUSH);
- exit.setText(Messages.BrowserSim_EXIT);
- exit.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- display.dispose();
- };
- });
-
- devicesMenu = createDropDownMenu(appMenuBar, Messages.BrowserSim_DEVICES);
- devicesManager = DevicesManager.getInstance();
- devicesManager.addObserver(new Observer() {
- public void update(Observable o, Object arg) {
- DevicesManager devicesManager = (DevicesManager) o;
- DevicesList devicesList = devicesManager.getDevicesList();
- setDevicesListForMenu(devicesList);
- setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
- devicesList.addObserver(new Observer() {
- public void update(Observable o, Object arg) {
- setDevice(((DevicesList)o).getDevices().get(((DevicesList)o).getSelectedDeviceIndex()));
- }
- });
- }
- });
-
- DevicesList devicesList;
- try {
- devicesList = DevicesManager.loadDevicesList(getResourceAsStream(
- "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
- } catch (IOException e) {
- devicesList = new DevicesList(new ArrayList<Device>(), 0);
- }
- devicesManager.setDevicesList(devicesList);
- devicesManager.notifyObservers();
-
- new MenuItem(devicesMenu, SWT.BAR);
- MenuItem manageDevicesMenuItem = new MenuItem(devicesMenu, SWT.PUSH);
- manageDevicesMenuItem.setText(Messages.BrowserSim_MORE);
- manageDevicesMenuItem.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- DevicesList newDevicesList = new ManageDevicesDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM,
- devicesManager.getDevicesList()).open();
- if (newDevicesList != null) {
- devicesManager.setDevicesList(newDevicesList);
- devicesManager.notifyObservers();
- }
- }
- });
- }
-
- private void setDevicesListForMenu(DevicesList devicesList) {
- for (MenuItem item : devicesMenu.getItems()) {
- if (item.getData() instanceof Device) {
- item.dispose();
- }
- }
-
- int currentIndex = 0;
- for (Device device : devicesList.getDevices()) {
- MenuItem deviceMenuItem = new MenuItem(devicesMenu, SWT.RADIO, currentIndex);
- deviceMenuItem.setText(device.getName());
- deviceMenuItem.setData(device);
- deviceMenuItem.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- MenuItem menuItem = (MenuItem)e.widget;
- if (menuItem.getSelection()) {
- DevicesList devicesList = devicesManager.getDevicesList();
- int selectedDeviceIndex = devicesList.getDevices().indexOf(menuItem.getData());
- if (selectedDeviceIndex < 0) {
- selectedDeviceIndex = 0;
- }
- devicesList.setSelectedDeviceIndex(selectedDeviceIndex);
- devicesList.notifyObservers();
- }
- };
- });
-
- currentIndex++;
- }
- }
-
- private Menu createDropDownMenu(Menu menuBar, String name) {
- MenuItem manuItem = new MenuItem(menuBar, SWT.CASCADE);
- manuItem.setText(name);
- Menu dropdown = new Menu(menuBar);
- manuItem.setMenu(dropdown);
- return dropdown;
- }
-
- public void setDevice(final Device device) {
- for (MenuItem menuItem : devicesMenu.getItems()) {
- if (menuItem.getData() instanceof Device) {
- menuItem.setSelection(menuItem.getData() == device);
- }
- }
-
- browser.setDefaultUserAgent(device.getUserAgent());
- GridData data = (GridData) browser.getLayoutData();
- data.widthHint = device.getWidth();
- data.heightHint = device.getHeight();
- Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- Rectangle clientArea = display.getClientArea();
- shellSize.x = Math.min(shellSize.x, clientArea.width);
- shellSize.y = Math.min(shellSize.y, clientArea.height);
- shell.setSize(shellSize);
-
- Rectangle shellBounds = shell.getBounds();
- int bottomOverlap = shellBounds.y + shellBounds.height - (clientArea.y +
clientArea.height);
- if (bottomOverlap > 0) {
- if (shellBounds.y > bottomOverlap) {
- shellBounds.y -= bottomOverlap;
- } else {
- shellBounds.y = 0;
- }
- }
-
- int rightOverlap = shellBounds.x + shellBounds.width - (clientArea.x +
clientArea.width);
- if (rightOverlap > 0) {
- if (shellBounds.x > rightOverlap) {
- shellBounds.x -= rightOverlap;
- } else {
- shellBounds.x = 0;
- }
- }
-
- shell.setBounds(shellBounds);
- browser.refresh();
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class Device {
- public static final int DEFAULT_SIZE = -1;
-
- private String name;
- private int width;
- private int height;
- private String userAgent;
-
- public Device(String name, int width, int height, String userAgent) {
- this.name = name;
- this.width = width;
- this.height = height;
- this.userAgent = userAgent;
- }
-
- public int getWidth() {
- return width;
- }
-
- public int getHeight() {
- return height;
- }
-
- public String getUserAgent() {
- return userAgent;
- }
-
- public String getName() {
- return name;
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-import java.util.List;
-import java.util.Observable;
-
-/**
- * An unmodifiable list of {@link Device}s, with modifiable {@link
#selectedDeviceIndex}.
- *
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class DevicesList extends Observable {
- private List<Device> devices;
- private int selectedDeviceIndex;
-
- public DevicesList(List<Device> devices, int selectedDeviceIndex) {
- this.devices = devices;
- this.selectedDeviceIndex = selectedDeviceIndex;
- }
-
- public List<Device> getDevices() {
- return devices;
- }
-
- public int getSelectedDeviceIndex() {
- return selectedDeviceIndex;
- }
-
- public void setSelectedDeviceIndex(int currentDeviceIndex) {
- if (this.selectedDeviceIndex != currentDeviceIndex) {
- this.selectedDeviceIndex = currentDeviceIndex;
- setChanged();
- }
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Observable;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class DevicesManager extends Observable {
- private static DevicesManager instance;
- private DevicesList devicesList;
- public static final String IPHONE_OS_4_0_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU
iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5
Mobile/8A293 Safari/6531.22.7";
-
- protected DevicesManager() {
- }
-
- public static DevicesManager getInstance() {
- if (instance == null) {
- instance = new DevicesManager();
- }
- return instance;
- }
-
- public DevicesList getDevicesList() {
- return devicesList;
- }
-
- public void setDevicesList(DevicesList devicesList) {
- if (this.devicesList != devicesList) {
- this.devicesList = devicesList;
- setChanged();
- }
- }
-
-// List<Device> devices = new ArrayList<Device>();
-// devices.add(new Device("Apple iPhone 3", 320, 480,
IPHONE_OS_4_0_USER_AGENT));
-// devices.add(new Device("Apple iPhone 4", 640, 960,
IPHONE_OS_4_0_USER_AGENT));
-// devices.add(new Device("BlackBerry Bold Touch 9900", 640, 480,
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.1+ (KHTML, like
Gecko) Version/6.0.0.246 Mobile Safari/534.1+"));
-// devices.add(new Device("Samsung Galaxy S II", 640, 800, "Mozilla/5.0
(Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko)
Version/4.0 Mobile Safari/533.1"));
-
-
- public static String encode(String string) {
- return string.replace("\\", "\\\\").replace("\n",
"\\n").replace("\t", "\\t");
- }
-
- public static String decode(String string) {
- StringBuilder result = new StringBuilder();
-
- int i = 0;
- while (i < string.length() - 1) {
- char c0 = string.charAt(i);
- if (c0 == '\\') {
- char c1 = string.charAt(i + 1);
- switch (c1) {
- case '\\':
- result.append('\\');
- i++;
- break;
- case 'n':
- result.append('\n');
- i++;
- break;
- case 't':
- result.append('\t');
- i++;
- break;
- default:
- result.append(c0);
- break;
- }
- } else {
- result.append(c0);
- }
- i++;
- }
-
- if (i < string.length()) {
- result.append(string.charAt(i));
- }
-
- return result.toString();
- }
-
- public static void saveDevicesList(DevicesList devicesList, File file) throws
IOException {
- BufferedWriter writer = new BufferedWriter(new FileWriter(file));
-
- writer.write(String.valueOf(devicesList.getSelectedDeviceIndex()));
- writer.write('\n');
-
- for (Device device : devicesList.getDevices()) {
- writer.write( encode(device.getName() ));
- writer.write('\t');
- writer.write(encode( String.valueOf(device.getWidth()) ));
- writer.write('\t');
- writer.write(encode( String.valueOf(device.getHeight()) ));
- writer.write('\t');
- writer.write( encode(device.getUserAgent() ));
- writer.write('\n');
- }
-
- writer.close();
- }
-
- public static DevicesList loadDevicesList(InputStream inputStream) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-
- String nextLine = reader.readLine();
- int selectedDeviceIndex = 0;
- if (nextLine != null) {
- selectedDeviceIndex = Integer.parseInt(nextLine);
- }
- Pattern devicePattern =
Pattern.compile("^(.*)\\t([0-9]*)\\t([0-9]*)\\t(.*)$");
-
- List<Device> devices = new ArrayList<Device>();
- while ((nextLine = reader.readLine()) != null) {
- Matcher deviceMatcher = devicePattern.matcher(nextLine);
- if (deviceMatcher.matches()) {
- devices.add(new Device(
- decode(deviceMatcher.group(1)),
- Integer.parseInt(deviceMatcher.group(2)),
- Integer.parseInt(deviceMatcher.group(3)),
- decode(deviceMatcher.group(4))
- ));
- }
- }
-
- reader.close();
-
- return new DevicesList(devices, selectedDeviceIndex);
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,162 +0,0 @@
-package org.jboss.tools.browsersim;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.events.VerifyListener;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Dialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-public class EditDeviceDialog extends Dialog {
- protected Device resultDevice;
- protected Device initialDevice;
- protected Shell shell;
- private Text textName;
- private Text textWidth;
- private Text textHeight;
- private Text textUserAgent;
-
- /**
- * Create the dialog.
- * @param parent
- * @param style
- */
- public EditDeviceDialog(Shell parent, int style, Device initialDevice) {
- super(parent, style);
- setText(Messages.EditDeviceDialog_MANAGE_DEVICES);
- this.initialDevice = initialDevice;
- }
-
- /**
- * Open the dialog.
- * @return the newDevicesList
- */
- public Device open() {
- createContents();
- shell.open();
- shell.layout();
- shell.setSize(shell.computeSize(300, SWT.DEFAULT));
- Display display = getParent().getDisplay();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
-
- return resultDevice;
- }
-
- /**
- * Create contents of the dialog.
- */
- private void createContents() {
- shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX);
- shell.setSize(450, 300);
- shell.setText(Messages.EditDeviceDialog_EDIT_DEVICE);
- shell.setLayout(new GridLayout(2, false));
-
- Label labelName = new Label(shell, SWT.NONE);
- labelName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelName.setText(Messages.EditDeviceDialog_NAME);
-
- textName = new Text(shell, SWT.BORDER);
- textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- textName.addFocusListener(new FocusGainedTextListener());
- textName.setText(initialDevice.getName());
-
- Label labelWidth = new Label(shell, SWT.NONE);
- labelWidth.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelWidth.setText(Messages.EditDeviceDialog_WIDTH);
-
- textWidth = new Text(shell, SWT.BORDER);
- textWidth.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- textWidth.setTextLimit(4);
- textWidth.addVerifyListener(new VerifyDigitsListener());
- textWidth.addFocusListener(new FocusLostDigitsListener());
- textWidth.addFocusListener(new FocusGainedTextListener());
- textWidth.setText(String.valueOf(initialDevice.getWidth()));
-
- Label labelHeight = new Label(shell, SWT.NONE);
- labelHeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelHeight.setText(Messages.EditDeviceDialog_HEIGHT);
-
- textHeight = new Text(shell, SWT.BORDER);
- textHeight.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- textHeight.setTextLimit(4);
- textHeight.addVerifyListener(new VerifyDigitsListener());
- textHeight.addFocusListener(new FocusLostDigitsListener());
- textHeight.addFocusListener(new FocusGainedTextListener());
- textHeight.setText(String.valueOf(initialDevice.getHeight()));
-
- Label labelUseragent = new Label(shell, SWT.NONE);
- labelUseragent.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelUseragent.setText(Messages.EditDeviceDialog_USER_AGENT);
-
- textUserAgent = new Text(shell, SWT.BORDER);
- textUserAgent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- textUserAgent.addFocusListener(new FocusGainedTextListener());
- textUserAgent.setText(initialDevice.getUserAgent());
-
- Composite composite = new Composite(shell, SWT.NONE);
- composite.setLayout(new FillLayout(SWT.HORIZONTAL));
- composite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true, 2, 1));
-
- Button buttonOk = new Button(composite, SWT.NONE);
- buttonOk.setText(Messages.EditDeviceDialog_OK);
- buttonOk.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevice = new Device(textName.getText(), Integer.valueOf(textWidth.getText()),
- Integer.valueOf(textHeight.getText()), textUserAgent.getText());
- shell.close();
- }
- });
- shell.setDefaultButton(buttonOk);
-
- Button buttonCancel = new Button(composite, SWT.NONE);
- buttonCancel.setText(Messages.EditDeviceDialog_CANCEL);
- buttonCancel.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevice = null;
- shell.close();
- }
- });
- }
-}
-
-final class VerifyDigitsListener implements VerifyListener {
- public void verifyText(VerifyEvent e) {
- for (char c : e.text.toCharArray()) {
- if (!('0' <= c && c <= '9')) {
- e.doit = false;
- return;
- }
- }
- }
-}
-
-final class FocusLostDigitsListener extends FocusAdapter {
- public void focusLost(FocusEvent e) {
- Text text = ((Text) e.widget);
- if (text.getText().trim().isEmpty()) {
- text.setText("0"); //$NON-NLS-1$
- }
- }
-}
-
-final class FocusGainedTextListener extends FocusAdapter {
- public void focusGained(FocusEvent e) {
- Text text = ((Text) e.widget);
- text.setSelection(0, text.getText().length());
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-//package org.jboss.tools.browsersim;
-//import
org.eclipse.swt.internal.ole.win32.COM;
-//import org.eclipse.swt.internal.ole.win32.GUID;
-//import org.eclipse.swt.internal.webkit.IWebView;
-//import org.eclipse.swt.internal.win32.RECT;
-//
-///**
-// * @author Yahor Radtsevich (yradtsevich)
-// */
-//public class IWebViewProxy extends IWebView {
-// private IWebView webView;
-// private int defaultUserAgent;
-//
-// public void setDefaultUserAgent(String defaultUserAgentString) {
-// if (defaultUserAgentString == null) {
-// this.defaultUserAgent = 0;
-// } else {
-// char[] data = (defaultUserAgentString + '\0').toCharArray ();
-// this.defaultUserAgent = COM.SysAllocString(data);
-// }
-// setCustomUserAgent(this.defaultUserAgent);
-// }
-//
-// public int setCustomUserAgent(int valueString) {
-// if (valueString == 0) {
-// return webView.setCustomUserAgent(defaultUserAgent);
-// } else {
-// return webView.setCustomUserAgent(valueString);
-// }
-// }
-//
-// public IWebViewProxy(IWebView webView) {
-// super(webView.getAddress());
-// this.webView = webView;
-// }
-//
-// public int AddRef() {
-// return webView.AddRef();
-// }
-//
-// public int getAddress() {
-// return webView.getAddress();
-// }
-//
-// public int canShowMIMEType(int mimeType, int[] canShow) {
-// return webView.canShowMIMEType(mimeType, canShow);
-// }
-//
-// public int QueryInterface(GUID riid, int[] ppvObject) {
-// return webView.QueryInterface(riid, ppvObject);
-// }
-//
-// public int initWithFrame(RECT frame, int frameName, int groupName) {
-// return webView.initWithFrame(frame, frameName, groupName);
-// }
-//
-// public int Release() {
-// return webView.Release();
-// }
-//
-// public int setUIDelegate(int delegate) {
-// return webView.setUIDelegate(delegate);
-// }
-//
-// public int setResourceLoadDelegate(int delegate) {
-// return webView.setResourceLoadDelegate(delegate);
-// }
-//
-// public int setDownloadDelegate(int delegate) {
-// return webView.setDownloadDelegate(delegate);
-// }
-//
-// public int setFrameLoadDelegate(int delegate) {
-// return webView.setFrameLoadDelegate(delegate);
-// }
-//
-// public int setPolicyDelegate(int delegate) {
-// return webView.setPolicyDelegate(delegate);
-// }
-//
-// public int hashCode() {
-// return webView.hashCode();
-// }
-//
-// public int mainFrame(int[] frame) {
-// return webView.mainFrame(frame);
-// }
-//
-// public int goBack(int[] succeeded) {
-// return webView.goBack(succeeded);
-// }
-//
-// public int goForward(int[] succeeded) {
-// return webView.goForward(succeeded);
-// }
-//
-// public int setPreferences(int prefs) {
-// return webView.setPreferences(prefs);
-// }
-//
-// public int preferences(int[] prefs) {
-// return webView.preferences(prefs);
-// }
-//
-// public int setHostWindow(int window) {
-// return webView.setHostWindow(window);
-// }
-//
-// public int hostWindow(int[] window) {
-// return webView.hostWindow(window);
-// }
-//
-// public int estimatedProgress(int estimatedProgress) {
-// return webView.estimatedProgress(estimatedProgress);
-// }
-//
-// public boolean equals(Object obj) {
-// return webView.equals(obj);
-// }
-//
-// public String toString() {
-// return webView.toString();
-// }
-//}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,200 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Dialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class ManageDevicesDialog extends Dialog {
-
- protected DevicesList oldDevicesList;
- protected List<Device> devices;
- protected int selectedDeviceIndex;
- protected Shell shell;
- private Table table;
- private DevicesList resultDevicesList;
-
- /**
- * Create the dialog.
- * @param parent
- * @param style
- * @param oldDevicesList
- */
- public ManageDevicesDialog(Shell parent, int style, DevicesList oldDevicesList) {
- super(parent, style);
- setText(Messages.ManageDevicesDialog_DEVICES);
- this.oldDevicesList = oldDevicesList;
- this.devices = new ArrayList<Device>(oldDevicesList.getDevices());
- this.selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
- }
-
- /**
- * Open the dialog.
- * @return the newDevicesList
- */
- public DevicesList open() {
- createContents();
- shell.open();
- shell.layout();
- Display display = getParent().getDisplay();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- return resultDevicesList;
- }
-
- /**
- * Create contents of the dialog.
- */
- private void createContents() {
- shell = new Shell(getParent(), getStyle());
- shell.setSize(450, 300);
- shell.setText(getText());
- shell.setLayout(new GridLayout(2, false));
-
- table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- table.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- selectedDeviceIndex = ((Table)e.widget).getSelectionIndex();
- }
- });
-
- TableColumn tableColumnName = new TableColumn(table, SWT.NONE);
- tableColumnName.setWidth(100);
- tableColumnName.setText(Messages.ManageDevicesDialog_NAME);
-
- TableColumn tableColumnWidth = new TableColumn(table, SWT.NONE);
- tableColumnWidth.setWidth(100);
- tableColumnWidth.setText(Messages.ManageDevicesDialog_WIDTH);
-
- TableColumn tableColumnHeight = new TableColumn(table, SWT.NONE);
- tableColumnHeight.setWidth(100);
- tableColumnHeight.setText(Messages.ManageDevicesDialog_HEIGHT);
-
- TableColumn tableColumnUseragent = new TableColumn(table, SWT.NONE);
- tableColumnUseragent.setWidth(100);
- tableColumnUseragent.setText(Messages.ManageDevicesDialog_USER_AGENT);
-
- Composite compositeControls = new Composite(shell, SWT.NONE);
- compositeControls.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
- compositeControls.setLayout(new FillLayout(SWT.VERTICAL));
-
- Button buttonAdd = new Button(compositeControls, SWT.NONE);
- buttonAdd.setText(Messages.ManageDevicesDialog_ADD);
- buttonAdd.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM,
- new Device(Messages.ManageDevicesDialog_NEW_DEVICE, 480, 800,
Messages.ManageDevicesDialog_NEW_USER_AGENT)).open();
- if (newDevice != null) {
- devices.add(newDevice);
- selectedDeviceIndex = devices.size() - 1;
- updateDevices();
- }
- }
- });
-
- Button buttonEdit = new Button(compositeControls, SWT.NONE);
- buttonEdit.setText(Messages.ManageDevicesDialog_EDIT);
- buttonEdit.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM,
- devices.get(selectedDeviceIndex)).open();
- if (newDevice != null) {
- devices.remove(selectedDeviceIndex);
- devices.add(selectedDeviceIndex, newDevice);
- updateDevices();
- }
- }
- });
-
- Button buttonRemove = new Button(compositeControls, SWT.NONE);
- buttonRemove.setText(Messages.ManageDevicesDialog_REMOVE);
- buttonRemove.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- System.out.println(devices.size());
- if (devices.size() > 1) {
- devices.remove(selectedDeviceIndex);
- if (selectedDeviceIndex >= devices.size()) {
- selectedDeviceIndex = devices.size() - 1;
- }
- updateDevices();
- }
- }
- });
-
- Button buttonReset = new Button(compositeControls, SWT.NONE);
- buttonReset.setText(Messages.ManageDevicesDialog_RESET);
- buttonReset.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- devices = new ArrayList<Device>(oldDevicesList.getDevices());
- selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
- updateDevices();
- }
- });
-
- Composite compositeOkCancel = new Composite(shell, SWT.NONE);
- compositeOkCancel.setLayout(new FillLayout(SWT.HORIZONTAL));
- compositeOkCancel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2,
1));
-
- Button buttonOk = new Button(compositeOkCancel, SWT.NONE);
- buttonOk.setText(Messages.ManageDevicesDialog_OK);
- shell.setDefaultButton(buttonOk);
- buttonOk.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevicesList = new DevicesList(devices, selectedDeviceIndex);
- shell.close();
- }
- });
-
- Button buttonCancel = new Button(compositeOkCancel, SWT.NONE);
- buttonCancel.setText(Messages.ManageDevicesDialog_CANCEL);
- buttonCancel.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevicesList = null;
- shell.close();
- }
- });
-
-
- updateDevices();
- }
-
- public void updateDevices() {
- table.removeAll();
- for (Device device : devices) {
- TableItem tableItem = new TableItem(table, SWT.NONE);
- tableItem.setText(new String[] {device.getName(), String.valueOf(device.getWidth()),
String.valueOf(device.getHeight()), device.getUserAgent()});
- }
- table.setSelection(selectedDeviceIndex);
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,39 +0,0 @@
-package org.jboss.tools.browsersim;
-
-public class Messages {
- private static final String BUNDLE_NAME =
"org.jboss.tools.browsersim.messages"; //$NON-NLS-1$
- public static String BrowserSim_ADDRESS;
- public static String BrowserSim_BROWSER_SIM;
- public static String BrowserSim_COULD_NOT_INSTANTIATE_BROWSER;
- public static String BrowserSim_DEVICES;
- public static String BrowserSim_EXIT;
- public static String BrowserSim_FILE;
- public static String BrowserSim_MORE;
- public static String EditDeviceDialog_CANCEL;
- public static String EditDeviceDialog_EDIT_DEVICE;
- public static String EditDeviceDialog_HEIGHT;
- public static String EditDeviceDialog_MANAGE_DEVICES;
- public static String EditDeviceDialog_NAME;
- public static String EditDeviceDialog_OK;
- public static String EditDeviceDialog_USER_AGENT;
- public static String EditDeviceDialog_WIDTH;
- public static String ManageDevicesDialog_ADD;
- public static String ManageDevicesDialog_CANCEL;
- public static String ManageDevicesDialog_DEVICES;
- public static String ManageDevicesDialog_EDIT;
- public static String ManageDevicesDialog_HEIGHT;
- public static String ManageDevicesDialog_NAME;
- public static String ManageDevicesDialog_NEW_DEVICE;
- public static String ManageDevicesDialog_NEW_USER_AGENT;
- public static String ManageDevicesDialog_OK;
- public static String ManageDevicesDialog_REMOVE;
- public static String ManageDevicesDialog_RESET;
- public static String ManageDevicesDialog_USER_AGENT;
- public static String ManageDevicesDialog_WIDTH;
- static {
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,33 +0,0 @@
-package org.jboss.tools.browsersim;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-public class NLS {
- private static final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
-
- private NLS(){};
-
- public static void initializeMessages(String bundleName, Class<?> clazz) {
- ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleName);
-
- try {
- for (Field field : clazz.getDeclaredFields()) {
- // if it is a public static uninitialized String field
- if ((field.getModifiers() & MOD_EXPECTED) == MOD_EXPECTED
- && field.getType() == String.class
- && field.get(null) == null) {
- try {
- field.set(null, resourceBundle.getString(field.getName()));
- } catch (MissingResourceException e) {
- field.set(null, '!' + field.getName() + '!');
- }
- }
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-}
Deleted:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties 2011-11-17
16:27:48 UTC (rev 36409)
@@ -1,28 +0,0 @@
-BrowserSim_ADDRESS=Address
-BrowserSim_BROWSER_SIM=BrowserSim
-BrowserSim_COULD_NOT_INSTANTIATE_BROWSER=Could not instantiate Browser:
-BrowserSim_DEVICES=Devices
-BrowserSim_EXIT=Exit
-BrowserSim_FILE=File
-BrowserSim_MORE=More...
-EditDeviceDialog_CANCEL=Cancel
-EditDeviceDialog_EDIT_DEVICE=Edit Device
-EditDeviceDialog_HEIGHT=Height:
-EditDeviceDialog_MANAGE_DEVICES=Manage Devices
-EditDeviceDialog_NAME=Name:
-EditDeviceDialog_OK=OK
-EditDeviceDialog_USER_AGENT=User-Agent:
-EditDeviceDialog_WIDTH=Width:
-ManageDevicesDialog_ADD=Add
-ManageDevicesDialog_CANCEL=Cancel
-ManageDevicesDialog_DEVICES=Devices
-ManageDevicesDialog_EDIT=Edit
-ManageDevicesDialog_HEIGHT=Height
-ManageDevicesDialog_NAME=Name
-ManageDevicesDialog_NEW_DEVICE=New Device
-ManageDevicesDialog_NEW_USER_AGENT=New User-Agent
-ManageDevicesDialog_OK=OK
-ManageDevicesDialog_REMOVE=Remove
-ManageDevicesDialog_RESET=Reset
-ManageDevicesDialog_USER_AGENT=User-Agent
-ManageDevicesDialog_WIDTH=Width
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java
(from rev 36176,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class Device {
+ public static final int DEFAULT_SIZE = -1;
+
+ private String name;
+ private int width;
+ private int height;
+ private String userAgent;
+
+ public Device(String name, int width, int height, String userAgent) {
+ this.name = name;
+ this.width = width;
+ this.height = height;
+ this.userAgent = userAgent;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public String getUserAgent() {
+ return userAgent;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java
(from rev 36251,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+import java.util.List;
+import java.util.Observable;
+
+/**
+ * An unmodifiable list of {@link Device}s, with modifiable {@link
#selectedDeviceIndex}.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class DevicesList extends Observable {
+ private List<Device> devices;
+ private int selectedDeviceIndex;
+
+ public DevicesList(List<Device> devices, int selectedDeviceIndex) {
+ this.devices = devices;
+ this.selectedDeviceIndex = selectedDeviceIndex;
+ }
+
+ public List<Device> getDevices() {
+ return devices;
+ }
+
+ public int getSelectedDeviceIndex() {
+ return selectedDeviceIndex;
+ }
+
+ public void setSelectedDeviceIndex(int currentDeviceIndex) {
+ if (this.selectedDeviceIndex != currentDeviceIndex) {
+ this.selectedDeviceIndex = currentDeviceIndex;
+ setChanged();
+ }
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java
(from rev 36344,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Observable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class DevicesManager extends Observable {
+ private static DevicesManager instance;
+ private DevicesList devicesList;
+ public static final String IPHONE_OS_4_0_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU
iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5
Mobile/8A293 Safari/6531.22.7";
+
+ protected DevicesManager() {
+ }
+
+ public static DevicesManager getInstance() {
+ if (instance == null) {
+ instance = new DevicesManager();
+ }
+ return instance;
+ }
+
+ public DevicesList getDevicesList() {
+ return devicesList;
+ }
+
+ public void setDevicesList(DevicesList devicesList) {
+ if (this.devicesList != devicesList) {
+ this.devicesList = devicesList;
+ setChanged();
+ }
+ }
+
+// List<Device> devices = new ArrayList<Device>();
+// devices.add(new Device("Apple iPhone 3", 320, 480,
IPHONE_OS_4_0_USER_AGENT));
+// devices.add(new Device("Apple iPhone 4", 640, 960,
IPHONE_OS_4_0_USER_AGENT));
+// devices.add(new Device("BlackBerry Bold Touch 9900", 640, 480,
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.1+ (KHTML, like
Gecko) Version/6.0.0.246 Mobile Safari/534.1+"));
+// devices.add(new Device("Samsung Galaxy S II", 640, 800, "Mozilla/5.0
(Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko)
Version/4.0 Mobile Safari/533.1"));
+
+
+ public static String encode(String string) {
+ return string.replace("\\", "\\\\").replace("\n",
"\\n").replace("\t", "\\t");
+ }
+
+ public static String decode(String string) {
+ StringBuilder result = new StringBuilder();
+
+ int i = 0;
+ while (i < string.length() - 1) {
+ char c0 = string.charAt(i);
+ if (c0 == '\\') {
+ char c1 = string.charAt(i + 1);
+ switch (c1) {
+ case '\\':
+ result.append('\\');
+ i++;
+ break;
+ case 'n':
+ result.append('\n');
+ i++;
+ break;
+ case 't':
+ result.append('\t');
+ i++;
+ break;
+ default:
+ result.append(c0);
+ break;
+ }
+ } else {
+ result.append(c0);
+ }
+ i++;
+ }
+
+ if (i < string.length()) {
+ result.append(string.charAt(i));
+ }
+
+ return result.toString();
+ }
+
+ public static void saveDevicesList(DevicesList devicesList, File file) throws
IOException {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+
+ writer.write(String.valueOf(devicesList.getSelectedDeviceIndex()));
+ writer.write('\n');
+
+ for (Device device : devicesList.getDevices()) {
+ writer.write( encode(device.getName() ));
+ writer.write('\t');
+ writer.write(encode( String.valueOf(device.getWidth()) ));
+ writer.write('\t');
+ writer.write(encode( String.valueOf(device.getHeight()) ));
+ writer.write('\t');
+ writer.write( encode(device.getUserAgent() ));
+ writer.write('\n');
+ }
+
+ writer.close();
+ }
+
+ public static DevicesList loadDevicesList(File file) throws IOException {
+ InputStream inputStream = new FileInputStream(file);
+ return loadDevicesList(inputStream);
+ }
+
+ public static DevicesList loadDevicesList(InputStream inputStream) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+
+ String nextLine = reader.readLine();
+ int selectedDeviceIndex = 0;
+ if (nextLine != null) {
+ selectedDeviceIndex = Integer.parseInt(nextLine);
+ }
+ Pattern devicePattern =
Pattern.compile("^(.*)\\t([0-9]*)\\t([0-9]*)\\t(.*)$");
+
+ List<Device> devices = new ArrayList<Device>();
+ while ((nextLine = reader.readLine()) != null) {
+ Matcher deviceMatcher = devicePattern.matcher(nextLine);
+ if (deviceMatcher.matches()) {
+ devices.add(new Device(
+ decode(deviceMatcher.group(1)),
+ Integer.parseInt(deviceMatcher.group(2)),
+ Integer.parseInt(deviceMatcher.group(3)),
+ decode(deviceMatcher.group(4))
+ ));
+ }
+ }
+
+ reader.close();
+
+ return new DevicesList(devices, selectedDeviceIndex);
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java
(from rev 36347,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,410 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Observable;
+import java.util.Observer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.browser.LocationEvent;
+import org.eclipse.swt.browser.LocationListener;
+import org.eclipse.swt.browser.ProgressEvent;
+import org.eclipse.swt.browser.ProgressListener;
+import org.eclipse.swt.browser.StatusTextEvent;
+import org.eclipse.swt.browser.StatusTextListener;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+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.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+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;
+import org.jboss.tools.browsersim.model.Device;
+import org.jboss.tools.browsersim.model.DevicesList;
+import org.jboss.tools.browsersim.model.DevicesManager;
+import org.jboss.tools.browsersim.util.ResourcesUtil;
+import org.jboss.tools.browsersim.webkit.AbstractWebKitBrowser;
+import org.jboss.tools.browsersim.webkit.WebKitBrowserFactory;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class BrowserSim implements Runnable {
+ private static final String DEFAULT_URL =
"http://www.w3schools.com/js/tryit_view.asp?filename=try_nav_useragent";
//$NON-NLS-1$
+ private AbstractWebKitBrowser browser;
+ private Display display;
+ private Shell shell;
+ private Text locationText;
+ private Label statusLabel;
+ private ProgressBar progressBar;
+ private String initialUrl;
+ private Menu devicesMenu;
+ private DevicesManager devicesManager;
+
+ public static void main(String[] args) {
+ String initialUrl;
+ if (args.length > 0) {
+ String lastArg = args[args.length - 1];
+ try {
+ new URI(lastArg); // validate URL
+ initialUrl = lastArg;
+ } catch (URISyntaxException e) {
+ initialUrl = DEFAULT_URL;
+ }
+ } else {
+ initialUrl = DEFAULT_URL;
+ }
+
+ new BrowserSim(new Display(), initialUrl).run();
+ }
+
+ public BrowserSim(Display display, String initialUrl) {
+ this.display = display;
+ this.initialUrl = initialUrl;
+ }
+
+ @Override
+ public void run() {
+ shell = new Shell(display);
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ try {
+ File configFolder = new File(this.getClass().getPackage().getName());
+ configFolder.mkdir();
+ DevicesManager.saveDevicesList(devicesManager.getDevicesList(),
+ new File(configFolder, "devices.cfg"));
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ shell.setText(Messages.BrowserSim_BROWSER_SIM);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ shell.setLayout(gridLayout);
+ Menu appMenuBar = display.getMenuBar();
+ if (appMenuBar == null) {
+ appMenuBar = new Menu(shell, SWT.BAR);
+ shell.setMenuBar(appMenuBar);
+ }
+
+ ToolBar toolbar = createControlBar();
+ GridData data = new GridData();
+ data.horizontalSpan = 3;
+ toolbar.setLayoutData(data);
+
+ Label labelAddress = new Label(shell, SWT.NONE);
+ labelAddress.setText(Messages.BrowserSim_ADDRESS);
+
+ locationText = new Text(shell, SWT.BORDER);
+ data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.horizontalSpan = 2;
+ data.grabExcessHorizontalSpace = true;
+ data.widthHint = 0;
+ locationText.setLayoutData(data);
+
+ try {
+ browser = WebKitBrowserFactory.createWebKitBrowser(shell, SWT.NONE);
+ } catch (SWTError e) {
+ System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_BROWSER +
e.getMessage());
+ display.dispose();
+ return;
+ }
+
+ data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalSpan = 3;
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ browser.setLayoutData(data);
+
+ statusLabel = new Label(shell, SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+ data.widthHint = 0;
+ statusLabel.setLayoutData(data);
+
+ progressBar = new ProgressBar(shell, SWT.NONE);
+ data = new GridData();
+ data.horizontalAlignment = GridData.END;
+ progressBar.setLayoutData(data);
+
+ browser.addProgressListener(new ProgressListener() {
+ public void changed(ProgressEvent event) {
+ if (event.total == 0) return;
+ int ratio = event.current * 100 / event.total;
+ progressBar.setSelection(ratio);
+ }
+ public void completed(ProgressEvent event) {
+ progressBar.setSelection(0);
+ }
+ });
+ browser.addStatusTextListener(new StatusTextListener() {
+ public void changed(StatusTextEvent event) {
+ statusLabel.setText(event.text);
+ }
+ });
+ browser.addLocationListener(new LocationListener() {
+ public void changed(LocationEvent event) {
+ if (event.top) locationText.setText(event.location);
+ }
+ public void changing(LocationEvent event) {
+ }
+ });
+
+ fillMenuBar(appMenuBar);
+
+ locationText.addListener(SWT.DefaultSelection, new Listener() {
+ public void handleEvent(Event e) {
+ browser.setUrl(locationText.getText());
+ }
+ });
+
+ DevicesList devicesList = DevicesManager.getInstance().getDevicesList();
+ if (devicesList != null && devicesList.getDevices() != null
+ && devicesList.getSelectedDeviceIndex() < devicesList.getDevices().size())
{
+ setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
+ }
+ shell.open();
+ browser.setUrl(initialUrl);
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ public ToolBar createControlBar() {
+ ToolBar toolbar = new ToolBar(shell, SWT.NONE);
+ ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
+// itemBack.setText("Back");
+ itemBack.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.back();
+ }
+ });
+
+ ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
+// itemForward.setText("Forward");
+ itemForward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.forward();
+ }
+ });
+
+ ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
+// itemStop.setText("Stop");
+ itemStop.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.stop();
+ }
+ });
+
+ ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
+// itemRefresh.setText("Refresh");
+ itemRefresh.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.refresh();
+ }
+ });
+
+ ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
+// itemGo.setText("Go");
+ itemGo.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.setUrl(locationText.getText());
+ }
+ });
+
+ final Image imageBack = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_backward.gif"));
//$NON-NLS-1$
+ final Image imageForward = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_forward.gif"));
//$NON-NLS-1$
+ final Image imageStop = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_stop.gif"));
//$NON-NLS-1$
+ final Image imageRefresh = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_refresh.gif"));
//$NON-NLS-1$
+ final Image imageGo = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_go.gif"));
//$NON-NLS-1$
+
+ itemBack.setImage(imageBack);
+ itemForward.setImage(imageForward);
+ itemStop.setImage(imageStop);
+ itemRefresh.setImage(imageRefresh);
+ itemGo.setImage(imageGo);
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ imageBack.dispose();
+ imageForward.dispose();
+ imageStop.dispose();
+ imageRefresh.dispose();
+ imageGo.dispose();
+ }
+ });
+
+ itemForward.setImage(imageForward);
+
+
+ return toolbar;
+ }
+
+ public void fillMenuBar(Menu appMenuBar) {
+ Menu file = createDropDownMenu(appMenuBar, Messages.BrowserSim_FILE);
+ MenuItem exit = new MenuItem(file, SWT.PUSH);
+ exit.setText(Messages.BrowserSim_EXIT);
+ exit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ display.dispose();
+ };
+ });
+
+ devicesMenu = createDropDownMenu(appMenuBar, Messages.BrowserSim_DEVICES);
+ devicesManager = DevicesManager.getInstance();
+ devicesManager.addObserver(new Observer() {
+ public void update(Observable o, Object arg) {
+ DevicesManager devicesManager = (DevicesManager) o;
+ DevicesList devicesList = devicesManager.getDevicesList();
+ setDevicesListForMenu(devicesList);
+ setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
+ devicesList.addObserver(new Observer() {
+ public void update(Observable o, Object arg) {
+ setDevice(((DevicesList)o).getDevices().get(((DevicesList)o).getSelectedDeviceIndex()));
+ }
+ });
+ }
+ });
+
+ DevicesList devicesList;
+ try {
+ File customConfigFile = new File(this.getClass().getPackage().getName() +
"/devices.cfg");
+ if (customConfigFile.exists()) {
+ devicesList = DevicesManager.loadDevicesList(customConfigFile);
+ } else {
+ devicesList = DevicesManager.loadDevicesList(ResourcesUtil.getResourceAsStream(
+ "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
+ }
+ } catch (IOException e) {
+ devicesList = new DevicesList(new ArrayList<Device>(), 0);
+ }
+ devicesManager.setDevicesList(devicesList);
+ devicesManager.notifyObservers();
+
+ new MenuItem(devicesMenu, SWT.BAR);
+ MenuItem manageDevicesMenuItem = new MenuItem(devicesMenu, SWT.PUSH);
+ manageDevicesMenuItem.setText(Messages.BrowserSim_MORE);
+ manageDevicesMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DevicesList newDevicesList = new ManageDevicesDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM,
+ devicesManager.getDevicesList()).open();
+ if (newDevicesList != null) {
+ devicesManager.setDevicesList(newDevicesList);
+ devicesManager.notifyObservers();
+ }
+ }
+ });
+ }
+
+ private void setDevicesListForMenu(DevicesList devicesList) {
+ for (MenuItem item : devicesMenu.getItems()) {
+ if (item.getData() instanceof Device) {
+ item.dispose();
+ }
+ }
+
+ int currentIndex = 0;
+ for (Device device : devicesList.getDevices()) {
+ MenuItem deviceMenuItem = new MenuItem(devicesMenu, SWT.RADIO, currentIndex);
+ deviceMenuItem.setText(device.getName());
+ deviceMenuItem.setData(device);
+ deviceMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ MenuItem menuItem = (MenuItem)e.widget;
+ if (menuItem.getSelection()) {
+ DevicesList devicesList = devicesManager.getDevicesList();
+ int selectedDeviceIndex = devicesList.getDevices().indexOf(menuItem.getData());
+ if (selectedDeviceIndex < 0) {
+ selectedDeviceIndex = 0;
+ }
+ devicesList.setSelectedDeviceIndex(selectedDeviceIndex);
+ devicesList.notifyObservers();
+ }
+ };
+ });
+
+ currentIndex++;
+ }
+ }
+
+ private Menu createDropDownMenu(Menu menuBar, String name) {
+ MenuItem manuItem = new MenuItem(menuBar, SWT.CASCADE);
+ manuItem.setText(name);
+ Menu dropdown = new Menu(menuBar);
+ manuItem.setMenu(dropdown);
+ return dropdown;
+ }
+
+ public void setDevice(final Device device) {
+ for (MenuItem menuItem : devicesMenu.getItems()) {
+ if (menuItem.getData() instanceof Device) {
+ menuItem.setSelection(menuItem.getData() == device);
+ }
+ }
+
+ browser.setDefaultUserAgent(device.getUserAgent());
+ GridData data = (GridData) browser.getLayoutData();
+ data.widthHint = device.getWidth();
+ data.heightHint = device.getHeight();
+ Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Rectangle clientArea = display.getClientArea();
+ shellSize.x = Math.min(shellSize.x, clientArea.width);
+ shellSize.y = Math.min(shellSize.y, clientArea.height);
+ shell.setSize(shellSize);
+
+ Rectangle shellBounds = shell.getBounds();
+ int bottomOverlap = shellBounds.y + shellBounds.height - (clientArea.y +
clientArea.height);
+ if (bottomOverlap > 0) {
+ if (shellBounds.y > bottomOverlap) {
+ shellBounds.y -= bottomOverlap;
+ } else {
+ shellBounds.y = 0;
+ }
+ }
+
+ int rightOverlap = shellBounds.x + shellBounds.width - (clientArea.x +
clientArea.width);
+ if (rightOverlap > 0) {
+ if (shellBounds.x > rightOverlap) {
+ shellBounds.x -= rightOverlap;
+ } else {
+ shellBounds.x = 0;
+ }
+ }
+
+ shell.setBounds(shellBounds);
+ browser.refresh();
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java
(from rev 36281,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,163 @@
+package org.jboss.tools.browsersim.ui;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.browsersim.model.Device;
+
+public class EditDeviceDialog extends Dialog {
+ protected Device resultDevice;
+ protected Device initialDevice;
+ protected Shell shell;
+ private Text textName;
+ private Text textWidth;
+ private Text textHeight;
+ private Text textUserAgent;
+
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ */
+ public EditDeviceDialog(Shell parent, int style, Device initialDevice) {
+ super(parent, style);
+ setText(Messages.EditDeviceDialog_MANAGE_DEVICES);
+ this.initialDevice = initialDevice;
+ }
+
+ /**
+ * Open the dialog.
+ * @return the newDevicesList
+ */
+ public Device open() {
+ createContents();
+ shell.open();
+ shell.layout();
+ shell.setSize(shell.computeSize(300, SWT.DEFAULT));
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ return resultDevice;
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ private void createContents() {
+ shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX);
+ shell.setSize(450, 300);
+ shell.setText(Messages.EditDeviceDialog_EDIT_DEVICE);
+ shell.setLayout(new GridLayout(2, false));
+
+ Label labelName = new Label(shell, SWT.NONE);
+ labelName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelName.setText(Messages.EditDeviceDialog_NAME);
+
+ textName = new Text(shell, SWT.BORDER);
+ textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textName.addFocusListener(new FocusGainedTextListener());
+ textName.setText(initialDevice.getName());
+
+ Label labelWidth = new Label(shell, SWT.NONE);
+ labelWidth.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelWidth.setText(Messages.EditDeviceDialog_WIDTH);
+
+ textWidth = new Text(shell, SWT.BORDER);
+ textWidth.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textWidth.setTextLimit(4);
+ textWidth.addVerifyListener(new VerifyDigitsListener());
+ textWidth.addFocusListener(new FocusLostDigitsListener());
+ textWidth.addFocusListener(new FocusGainedTextListener());
+ textWidth.setText(String.valueOf(initialDevice.getWidth()));
+
+ Label labelHeight = new Label(shell, SWT.NONE);
+ labelHeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelHeight.setText(Messages.EditDeviceDialog_HEIGHT);
+
+ textHeight = new Text(shell, SWT.BORDER);
+ textHeight.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textHeight.setTextLimit(4);
+ textHeight.addVerifyListener(new VerifyDigitsListener());
+ textHeight.addFocusListener(new FocusLostDigitsListener());
+ textHeight.addFocusListener(new FocusGainedTextListener());
+ textHeight.setText(String.valueOf(initialDevice.getHeight()));
+
+ Label labelUseragent = new Label(shell, SWT.NONE);
+ labelUseragent.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelUseragent.setText(Messages.EditDeviceDialog_USER_AGENT);
+
+ textUserAgent = new Text(shell, SWT.BORDER);
+ textUserAgent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textUserAgent.addFocusListener(new FocusGainedTextListener());
+ textUserAgent.setText(initialDevice.getUserAgent());
+
+ Composite composite = new Composite(shell, SWT.NONE);
+ composite.setLayout(new FillLayout(SWT.HORIZONTAL));
+ composite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true, 2, 1));
+
+ Button buttonOk = new Button(composite, SWT.NONE);
+ buttonOk.setText(Messages.EditDeviceDialog_OK);
+ buttonOk.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevice = new Device(textName.getText(), Integer.valueOf(textWidth.getText()),
+ Integer.valueOf(textHeight.getText()), textUserAgent.getText());
+ shell.close();
+ }
+ });
+ shell.setDefaultButton(buttonOk);
+
+ Button buttonCancel = new Button(composite, SWT.NONE);
+ buttonCancel.setText(Messages.EditDeviceDialog_CANCEL);
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevice = null;
+ shell.close();
+ }
+ });
+ }
+}
+
+final class VerifyDigitsListener implements VerifyListener {
+ public void verifyText(VerifyEvent e) {
+ for (char c : e.text.toCharArray()) {
+ if (!('0' <= c && c <= '9')) {
+ e.doit = false;
+ return;
+ }
+ }
+ }
+}
+
+final class FocusLostDigitsListener extends FocusAdapter {
+ public void focusLost(FocusEvent e) {
+ Text text = ((Text) e.widget);
+ if (text.getText().trim().isEmpty()) {
+ text.setText("0"); //$NON-NLS-1$
+ }
+ }
+}
+
+final class FocusGainedTextListener extends FocusAdapter {
+ public void focusGained(FocusEvent e) {
+ Text text = ((Text) e.widget);
+ text.setSelection(0, text.getText().length());
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java
(from rev 36281,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.ui;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.jboss.tools.browsersim.model.Device;
+import org.jboss.tools.browsersim.model.DevicesList;
+import org.jboss.tools.browsersim.model.DevicesManager;
+import org.jboss.tools.browsersim.util.ResourcesUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class ManageDevicesDialog extends Dialog {
+
+ protected DevicesList oldDevicesList;
+ protected List<Device> devices;
+ protected int selectedDeviceIndex;
+ protected Shell shell;
+ private Table table;
+ private DevicesList resultDevicesList;
+
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ * @param oldDevicesList
+ */
+ public ManageDevicesDialog(Shell parent, int style, DevicesList oldDevicesList) {
+ super(parent, style);
+ setText(Messages.ManageDevicesDialog_DEVICES);
+ this.oldDevicesList = oldDevicesList;
+ this.devices = new ArrayList<Device>(oldDevicesList.getDevices());
+ this.selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
+ }
+
+ /**
+ * Open the dialog.
+ * @return the newDevicesList
+ */
+ public DevicesList open() {
+ createContents();
+ shell.open();
+ shell.layout();
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ return resultDevicesList;
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ private void createContents() {
+ shell = new Shell(getParent(), getStyle());
+ shell.setSize(450, 300);
+ shell.setText(getText());
+ shell.setLayout(new GridLayout(2, false));
+
+ table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ table.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ selectedDeviceIndex = ((Table)e.widget).getSelectionIndex();
+ }
+ });
+
+ TableColumn tableColumnName = new TableColumn(table, SWT.NONE);
+ tableColumnName.setWidth(100);
+ tableColumnName.setText(Messages.ManageDevicesDialog_NAME);
+
+ TableColumn tableColumnWidth = new TableColumn(table, SWT.NONE);
+ tableColumnWidth.setWidth(100);
+ tableColumnWidth.setText(Messages.ManageDevicesDialog_WIDTH);
+
+ TableColumn tableColumnHeight = new TableColumn(table, SWT.NONE);
+ tableColumnHeight.setWidth(100);
+ tableColumnHeight.setText(Messages.ManageDevicesDialog_HEIGHT);
+
+ TableColumn tableColumnUseragent = new TableColumn(table, SWT.NONE);
+ tableColumnUseragent.setWidth(100);
+ tableColumnUseragent.setText(Messages.ManageDevicesDialog_USER_AGENT);
+
+ Composite compositeControls = new Composite(shell, SWT.NONE);
+ compositeControls.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ compositeControls.setLayout(new FillLayout(SWT.VERTICAL));
+
+ Button buttonAdd = new Button(compositeControls, SWT.NONE);
+ buttonAdd.setText(Messages.ManageDevicesDialog_ADD);
+ buttonAdd.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM,
+ new Device(Messages.ManageDevicesDialog_NEW_DEVICE, 480, 800,
Messages.ManageDevicesDialog_NEW_USER_AGENT)).open();
+ if (newDevice != null) {
+ devices.add(newDevice);
+ selectedDeviceIndex = devices.size() - 1;
+ updateDevices();
+ }
+ }
+ });
+
+ Button buttonEdit = new Button(compositeControls, SWT.NONE);
+ buttonEdit.setText(Messages.ManageDevicesDialog_EDIT);
+ buttonEdit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM,
+ devices.get(selectedDeviceIndex)).open();
+ if (newDevice != null) {
+ devices.remove(selectedDeviceIndex);
+ devices.add(selectedDeviceIndex, newDevice);
+ updateDevices();
+ }
+ }
+ });
+
+ Button buttonRemove = new Button(compositeControls, SWT.NONE);
+ buttonRemove.setText(Messages.ManageDevicesDialog_REMOVE);
+ buttonRemove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ System.out.println(devices.size());
+ if (devices.size() > 1) {
+ devices.remove(selectedDeviceIndex);
+ if (selectedDeviceIndex >= devices.size()) {
+ selectedDeviceIndex = devices.size() - 1;
+ }
+ updateDevices();
+ }
+ }
+ });
+
+ Button buttonReset = new Button(compositeControls, SWT.NONE);
+ buttonReset.setText(Messages.ManageDevicesDialog_RESET);
+
+ buttonReset.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ devices = new ArrayList<Device>(oldDevicesList.getDevices());
+ selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
+ updateDevices();
+ }
+ });
+
+ new Label(compositeControls, SWT.NONE);
+
+ Button buttonLoadDefaults = new Button(compositeControls, SWT.NONE);
+ buttonLoadDefaults.setText(Messages.ManageDevicesDialog_LOAD_DEFAULTS);
+ buttonLoadDefaults.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DevicesList defaultDevicesList;
+ try {
+ defaultDevicesList =
DevicesManager.loadDevicesList(ResourcesUtil.getResourceAsStream(
+ "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
+ devices = defaultDevicesList.getDevices();
+ selectedDeviceIndex = defaultDevicesList.getSelectedDeviceIndex();
+ updateDevices();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+ });
+
+ Composite compositeOkCancel = new Composite(shell, SWT.NONE);
+ compositeOkCancel.setLayout(new FillLayout(SWT.HORIZONTAL));
+ compositeOkCancel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2,
1));
+
+ Button buttonOk = new Button(compositeOkCancel, SWT.NONE);
+ buttonOk.setText(Messages.ManageDevicesDialog_OK);
+ shell.setDefaultButton(buttonOk);
+ buttonOk.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevicesList = new DevicesList(devices, selectedDeviceIndex);
+ shell.close();
+ }
+ });
+
+ Button buttonCancel = new Button(compositeOkCancel, SWT.NONE);
+ buttonCancel.setText(Messages.ManageDevicesDialog_CANCEL);
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevicesList = null;
+ shell.close();
+ }
+ });
+
+
+ updateDevices();
+ }
+
+ public void updateDevices() {
+ table.removeAll();
+ for (Device device : devices) {
+ TableItem tableItem = new TableItem(table, SWT.NONE);
+ tableItem.setText(new String[] {device.getName(), String.valueOf(device.getWidth()),
String.valueOf(device.getHeight()), device.getUserAgent()});
+ }
+ table.setSelection(selectedDeviceIndex);
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java
(from rev 36281,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.ui;
+
+import org.jboss.tools.browsersim.util.NLS;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class Messages {
+ private static final String BUNDLE_NAME =
Messages.class.getName().toString().toLowerCase();
+ public static String BrowserSim_ADDRESS;
+ public static String BrowserSim_BROWSER_SIM;
+ public static String BrowserSim_COULD_NOT_INSTANTIATE_BROWSER;
+ public static String BrowserSim_DEVICES;
+ public static String BrowserSim_EXIT;
+ public static String BrowserSim_FILE;
+ public static String BrowserSim_MORE;
+ public static String EditDeviceDialog_CANCEL;
+ public static String EditDeviceDialog_EDIT_DEVICE;
+ public static String EditDeviceDialog_HEIGHT;
+ public static String EditDeviceDialog_MANAGE_DEVICES;
+ public static String EditDeviceDialog_NAME;
+ public static String EditDeviceDialog_OK;
+ public static String EditDeviceDialog_USER_AGENT;
+ public static String EditDeviceDialog_WIDTH;
+ public static String ManageDevicesDialog_ADD;
+ public static String ManageDevicesDialog_CANCEL;
+ public static String ManageDevicesDialog_DEVICES;
+ public static String ManageDevicesDialog_EDIT;
+ public static String ManageDevicesDialog_HEIGHT;
+ public static String ManageDevicesDialog_NAME;
+ public static String ManageDevicesDialog_NEW_DEVICE;
+ public static String ManageDevicesDialog_NEW_USER_AGENT;
+ public static String ManageDevicesDialog_OK;
+ public static String ManageDevicesDialog_REMOVE;
+ public static String ManageDevicesDialog_RESET;
+ public static String ManageDevicesDialog_LOAD_DEFAULTS;
+ public static String ManageDevicesDialog_USER_AGENT;
+ public static String ManageDevicesDialog_WIDTH;
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties
(from rev 36281,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,29 @@
+BrowserSim_ADDRESS=Address
+BrowserSim_BROWSER_SIM=BrowserSim
+BrowserSim_COULD_NOT_INSTANTIATE_BROWSER=Could not instantiate Browser:
+BrowserSim_DEVICES=Devices
+BrowserSim_EXIT=Exit
+BrowserSim_FILE=File
+BrowserSim_MORE=More...
+EditDeviceDialog_CANCEL=Cancel
+EditDeviceDialog_EDIT_DEVICE=Edit Device
+EditDeviceDialog_HEIGHT=Height:
+EditDeviceDialog_MANAGE_DEVICES=Manage Devices
+EditDeviceDialog_NAME=Name:
+EditDeviceDialog_OK=OK
+EditDeviceDialog_USER_AGENT=User-Agent:
+EditDeviceDialog_WIDTH=Width:
+ManageDevicesDialog_ADD=Add
+ManageDevicesDialog_CANCEL=Cancel
+ManageDevicesDialog_DEVICES=Devices
+ManageDevicesDialog_EDIT=Edit
+ManageDevicesDialog_HEIGHT=Height
+ManageDevicesDialog_NAME=Name
+ManageDevicesDialog_NEW_DEVICE=New Device
+ManageDevicesDialog_NEW_USER_AGENT=New User-Agent
+ManageDevicesDialog_OK=OK
+ManageDevicesDialog_REMOVE=Remove
+ManageDevicesDialog_RESET=Reset
+ManageDevicesDialog_LOAD_DEFAULTS=Load Defaults
+ManageDevicesDialog_USER_AGENT=User-Agent
+ManageDevicesDialog_WIDTH=Width
Copied:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java
(from rev 36281,
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java)
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class NLS {
+ private static final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
+
+ private NLS(){};
+
+ public static void initializeMessages(Class<?> clazz) {
+ String bundleName = clazz.getName().toLowerCase();
+ initializeMessages(bundleName, clazz);
+ }
+
+ public static void initializeMessages(String bundleName, Class<?> clazz) {
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleName);
+
+ try {
+ for (Field field : clazz.getDeclaredFields()) {
+ // if it is a public static uninitialized String field
+ if ((field.getModifiers() & MOD_EXPECTED) == MOD_EXPECTED
+ && field.getType() == String.class
+ && field.get(null) == null) {
+ try {
+ field.set(null, resourceBundle.getString(field.getName()));
+ } catch (MissingResourceException e) {
+ field.set(null, '!' + field.getName() + '!');
+ }
+ }
+ }
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+}
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.util;
+
+import java.io.InputStream;
+
+import org.jboss.tools.browsersim.ui.BrowserSim;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class ResourcesUtil {
+
+ public static InputStream getResourceAsStream(String name) {
+ return BrowserSim.class.getResourceAsStream(name);
+ }
+}
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -10,13 +10,13 @@
******************************************************************************/
package org.jboss.tools.browsersim.eclipse.util;
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.jboss.tools.browsersim.webkit.PlatformUtil;
/**
@@ -43,15 +43,16 @@
commandElements.add("-cp");
commandElements.add(classPath);
- commandElements.add("org.jboss.tools.browsersim.BrowserSim");
+ commandElements.add("org.jboss.tools.browsersim.ui.BrowserSim");
if (initialUrl != null) {
commandElements.add(initialUrl);
}
try {
ProcessBuilder processBuilder = new ProcessBuilder(commandElements);
+ processBuilder.directory(ConfigurationScope.INSTANCE.getLocation().toFile());
Process browserSimProcess = processBuilder.start();
- BufferedInputStream j;
+
final InputStream errorStream = browserSimProcess.getErrorStream();
final InputStream inputStream = browserSimProcess.getInputStream();
new Thread() {
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -30,7 +30,7 @@
} else if (PlatformUtil.CURRENT_PLATFORM.equals("win32.win32.x86")) {
return new WebKitBrowser_win32_win32_x86(parent, style);
}
-
+ //TODO: handle null properly in callers
return null;
}
}
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java 2011-11-17
14:54:19 UTC (rev 36408)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java 2011-11-17
16:27:48 UTC (rev 36409)
@@ -40,7 +40,7 @@
Method setCustomUserAgent =
webView.getClass().getDeclaredMethod("setCustomUserAgent", NSString);
if (userAgent == null) {
- setCustomUserAgent.invoke(webView, null);
+ setCustomUserAgent.invoke(webView, (Object) null);
} else {
Method NSString_stringWith = NSString.getDeclaredMethod("stringWith",
String.class);
//setCustomUserAgent.invoke(webView,
org.eclipse.swt.internal.cocoa.NSString.stringWith(userAgent));