Author: yradtsevich
Date: 2012-01-04 10:47:31 -0500 (Wed, 04 Jan 2012)
New Revision: 37646
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/BrowserSimBrowser.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/IBrowserSimBrowserFactory.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/back-selected.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/back.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/forward-selected.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/forward.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/iPhone3.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/refresh-selected.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/refresh.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/stop-selected.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/stop.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/native_skin/
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ControlHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/AppleIPhone3Skin.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/BrowserSimSkin.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/icons/
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/AbstractWebKitBrowser.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/WebKitBrowserFactory.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesListStorage.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/EditDeviceDialog.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/util/ResourcesUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-10431 : browsersim should be sexy
- created interfaces for skins
- created native skin
- created iPhone3 skin
- refactored code
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesListStorage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesListStorage.java 2012-01-04
15:23:01 UTC (rev 37645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesListStorage.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -30,7 +30,7 @@
*/
public class DevicesListStorage {
- private static final String DEFAULT_PREFERENCES_RESOURCE =
"/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg";
+ private static final String DEFAULT_PREFERENCES_RESOURCE =
"config/devices.cfg";
private static final String USER_PREFERENCES_FOLDER =
"org.jboss.tools.vpe.browsersim";
private static final String USER_PREFERENCES_FILE = "devices.cfg";
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/back-selected.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/back-selected.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/back.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/back.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/forward-selected.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/forward-selected.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/forward.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/forward.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/iPhone3.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/iPhone3.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/refresh-selected.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/refresh-selected.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/refresh.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/refresh.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/stop-selected.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/stop-selected.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/stop.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/stop.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-01-04
15:23:01 UTC (rev 37645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -17,6 +17,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
+import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.ProgressEvent;
@@ -27,47 +28,35 @@
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.MessageBox;
-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.vpe.browsersim.browser.AbstractWebKitBrowser;
+import org.jboss.tools.vpe.browsersim.browser.BrowserSimBrowser;
import org.jboss.tools.vpe.browsersim.browser.WebKitBrowserFactory;
import org.jboss.tools.vpe.browsersim.model.Device;
import org.jboss.tools.vpe.browsersim.model.DeviceOrientation;
import org.jboss.tools.vpe.browsersim.model.DevicesList;
import org.jboss.tools.vpe.browsersim.model.DevicesListHolder;
import org.jboss.tools.vpe.browsersim.model.DevicesListStorage;
-import org.jboss.tools.vpe.browsersim.util.ResourcesUtil;
+import org.jboss.tools.vpe.browsersim.ui.skin.BrowserSimSkin;
+import org.jboss.tools.vpe.browsersim.ui.skin.NativeSkin;
/**
* @author Yahor Radtsevich (yradtsevich)
*/
public class BrowserSim implements Runnable {
private static final String DEFAULT_URL = "about:blank";
//"http://www.w3schools.com/js/tryit_view.asp?filename=try_nav_useragent";
//$NON-NLS-1$
- private AbstractWebKitBrowser browser;
+ private BrowserSimBrowser browser;
private Display display;
private Shell shell;
- private Text locationText;
- private Label statusLabel;
- private ProgressBar progressBar;
private String initialUrl;
private Menu devicesMenu;
private DevicesListHolder devicesListHolder;
private DeviceOrientation deviceOrientation;
+ private BrowserSimSkin skin;
public static void main(String[] args) {
String initialUrl;
@@ -93,46 +82,15 @@
@Override
public void run() {
- shell = new Shell(display);
- shell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- if (devicesListHolder != null) {
- DevicesListStorage.saveUserDefinedDevicesList(devicesListHolder.getDevicesList());
- }
- }
- });
- 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);
- }
+ skin = new NativeSkin();//new AppleIPhone3Skin();
+ skin.setBrowserFactory(new WebKitBrowserFactory());
- 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);
+ skin.createControls(display);
} catch (SWTError e) {
System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER +
e.getMessage());
- MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ MessageBox messageBox = new MessageBox(new Shell(display), SWT.OK | SWT.ICON_ERROR);
messageBox.setText("Error");
messageBox.setMessage(Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER +
e.getMessage());
messageBox.open();
@@ -140,165 +98,90 @@
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);
-
+
+ shell = skin.getShell();
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ if (devicesListHolder != null) {
+ DevicesListStorage.saveUserDefinedDevicesList(devicesListHolder.getDevicesList());
+ }
+ }
+ });
+ shell.setText(Messages.BrowserSim_BROWSER_SIM);
+
+ browser = skin.getBrowser();
+
browser.addProgressListener(new ProgressListener() {
public void changed(ProgressEvent event) {
- if (event.total == 0) return;
- int ratio = event.current * 100 / event.total;
- progressBar.setSelection(ratio);
+ if (event.total == 0) return;
+ int ratio = event.current * 100 / event.total;
+ skin.progressChanged(ratio);
}
public void completed(ProgressEvent event) {
- progressBar.setSelection(0);
+ skin.progressChanged(-1);
}
});
browser.addStatusTextListener(new StatusTextListener() {
public void changed(StatusTextEvent event) {
- statusLabel.setText(event.text);
+ skin.statusTextChanged(event.text);
}
});
browser.addLocationListener(new LocationListener() {
public void changed(LocationEvent event) {
if (event.top) {
- locationText.setText(event.location);
+ skin.locationChanged(event.location);
}
+ }
+ public void changing(LocationEvent event) {
+ }
+ });
+
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalSpan = 3;
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ browser.setLayoutData(data);
+
+ browser.addLocationListener(new LocationListener() {
+ public void changed(LocationEvent event) {
initOrientation(deviceOrientation.getOrientationAngle());
}
public void changing(LocationEvent event) {
}
});
+ skin.setControlHandler(new ControlHandlerImpl(browser));
+
devicesListHolder = new DevicesListHolder();
- fillMenuBar(appMenuBar);
+ Menu appMenuBar = skin.getMenuBar();
+ if (appMenuBar != null) {
+ fillMenuBar(appMenuBar);
+ }
- locationText.addListener(SWT.DefaultSelection, new Listener() {
- public void handleEvent(Event e) {
- browser.setUrl(locationText.getText());
- }
- });
+ DevicesList devicesList = DevicesListStorage.loadUserDefinedDevicesList();
+ if (devicesList == null) {
+ devicesList = DevicesListStorage.loadDefaultDevicesList();
+ }
- DevicesList devicesList = devicesListHolder.getDevicesList();
+ devicesListHolder.setDevicesList(devicesList);
+ devicesListHolder.notifyObservers();
+
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()) {
+ while (!this.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());
- }
- });
-
- ToolItem itemRotateCounterclockwise = new ToolItem(toolbar, SWT.PUSH);
-// itemGo.setText("Rotate Counterclockwise");
- itemRotateCounterclockwise.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- rotateDevice(true);
- }
- });
-
- ToolItem itemRotateClockwise = new ToolItem(toolbar, SWT.PUSH);
-// itemGo.setText("Rotate Clockwise");
- itemRotateClockwise.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- rotateDevice(false);
- }
- });
-
- final Image imageBack = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/nav_backward.gif"));
//$NON-NLS-1$
- final Image imageForward = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/nav_forward.gif"));
//$NON-NLS-1$
- final Image imageStop = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/nav_stop.gif"));
//$NON-NLS-1$
- final Image imageRefresh = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/nav_refresh.gif"));
//$NON-NLS-1$
- final Image imageGo = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/nav_go.gif"));
//$NON-NLS-1$
- final Image imageRotateClockwise = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/rotate_clockwise.png"));
//$NON-NLS-1$
- final Image imageRotateCounterclockwise = new Image(display,
ResourcesUtil.getResourceAsStream("/org/jboss/tools/vpe/browsersim/resources/icons/rotate_counterclockwise.png"));
//$NON-NLS-1$
-
- itemBack.setImage(imageBack);
- itemForward.setImage(imageForward);
- itemStop.setImage(imageStop);
- itemRefresh.setImage(imageRefresh);
- itemGo.setImage(imageGo);
- itemRotateClockwise.setImage(imageRotateClockwise);
- itemRotateCounterclockwise.setImage(imageRotateCounterclockwise);
-
- shell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- imageBack.dispose();
- imageForward.dispose();
- imageStop.dispose();
- imageRefresh.dispose();
- imageGo.dispose();
- imageRotateClockwise.dispose();
- imageRotateCounterclockwise.dispose();
- }
- });
-
- return toolbar;
- }
-
public void fillMenuBar(Menu appMenuBar) {
Menu file = createDropDownMenu(appMenuBar, Messages.BrowserSim_FILE);
MenuItem exit = new MenuItem(file, SWT.PUSH);
@@ -325,15 +208,7 @@
});
}
});
-
- DevicesList devicesList = DevicesListStorage.loadUserDefinedDevicesList();
- if (devicesList == null) {
- devicesList = DevicesListStorage.loadDefaultDevicesList();
- }
-
- devicesListHolder.setDevicesList(devicesList);
- devicesListHolder.notifyObservers();
-
+
new MenuItem(devicesMenu, SWT.BAR);
MenuItem manageDevicesMenuItem = new MenuItem(devicesMenu, SWT.PUSH);
manageDevicesMenuItem.setText(Messages.BrowserSim_MORE);
@@ -389,13 +264,15 @@
}
public void setDevice(final Device device) {
- for (MenuItem menuItem : devicesMenu.getItems()) {
- if (menuItem.getData() instanceof Device) {
- menuItem.setSelection(menuItem.getData() == device);
+ if (devicesMenu != null) {
+ for (MenuItem menuItem : devicesMenu.getItems()) {
+ if (menuItem.getData() instanceof Device) {
+ menuItem.setSelection(menuItem.getData() == device);
+ }
}
}
- setBrowserSize(device.getWidth(), device.getHeight());
+ skin.setBrowserSize(device.getWidth(), device.getHeight());
deviceOrientation = new DeviceOrientation(device.getWidth() < device.getHeight()
? DeviceOrientation.PORTRAIT
: DeviceOrientation.LANDSCAPE);
@@ -408,9 +285,9 @@
if (orientationAngle == DeviceOrientation.LANDSCAPE
|| orientationAngle == DeviceOrientation.LANDSCAPE_INVERTED) {
- setBrowserSize(maxSize, minSize);
+ skin.setBrowserSize(maxSize, minSize);
} else {
- setBrowserSize(minSize, maxSize);
+ skin.setBrowserSize(minSize, maxSize);
}
fireOrientationChangeEvent(orientationAngle);
@@ -420,62 +297,6 @@
browser.setDefaultUserAgent(device.getUserAgent());
browser.refresh();
}
-
- private void setBrowserSize(int width, int height) {
- GridData data = (GridData) browser.getLayoutData();
-
- Rectangle clientArea = getMonitorClientArea();
- int shellWidthHint = SWT.DEFAULT;
- if (width != Device.DEFAULT_SIZE) {
- data.widthHint = width;
- } else if (data.widthHint == SWT.DEFAULT) {
- shellWidthHint = clientArea.width;
- }
- int shellHeightHint = SWT.DEFAULT;
- if (height != Device.DEFAULT_SIZE) {
- data.heightHint = height;
- } else if (data.heightHint == SWT.DEFAULT) {
- shellHeightHint = clientArea.height;
- }
- Point shellSize = shell.computeSize(shellWidthHint, shellHeightHint);
- 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);
- }
-
- private Rectangle getMonitorClientArea() {
- Rectangle clientArea = shell.getMonitor().getClientArea();
-
- /* on Linux returned monitor client area may be bigger
- * than the monitor bounds when multiple monitors are used.
- * The following code fixes this */
- Rectangle bounds = shell.getMonitor().getBounds();
- clientArea.width = Math.min(clientArea.width, bounds.width);
- clientArea.height = Math.min(clientArea.height, bounds.height);
-
- return clientArea;
- }
private void initOrientation(int orientation) {
browser.execute("window.onorientationchange = null;"
@@ -499,4 +320,52 @@
deviceOrientation.turnDevice(counterclockwise);
deviceOrientation.notifyObservers();
}
+
+ class ControlHandlerImpl implements ControlHandler {
+ private Browser browser;
+
+ public ControlHandlerImpl(Browser browser) {
+ this.browser = browser;
+ }
+
+ @Override
+ public void goBack() {
+ browser.back();
+ }
+
+ @Override
+ public void goForward() {
+ browser.forward();
+ }
+
+ @Override
+ public void goHome() {
+ browser.setUrl("about:blank");//XXX
+ }
+
+ @Override
+ public void goToAddress(String address) {
+ browser.setUrl(address);
+ }
+
+ @Override
+ public void showContextMenu() {
+ // TODO Auto-generated method stub//XXX
+ }
+
+ @Override
+ public void rotate(boolean counterclockwise) {
+ BrowserSim.this.rotateDevice(counterclockwise);
+ }
+
+ @Override
+ public void stop() {
+ browser.stop();
+ }
+
+ @Override
+ public void refresh() {
+ browser.refresh();
+ }
+ }
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ControlHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ControlHandler.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ControlHandler.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -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.vpe.browsersim.ui;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public interface ControlHandler {
+ void goBack();
+ void goForward();
+ void goHome();
+ void goToAddress(String address);
+ void showContextMenu();
+ void rotate(boolean counterclockwise);
+ void stop();
+ void refresh();
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/EditDeviceDialog.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/EditDeviceDialog.java 2012-01-04
15:23:01 UTC (rev 37645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/EditDeviceDialog.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * 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.vpe.browsersim.ui;
import org.eclipse.swt.SWT;
@@ -19,6 +29,9 @@
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.vpe.browsersim.model.Device;
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
public class EditDeviceDialog extends Dialog {
protected Device resultDevice;
protected Device initialDevice;
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/AppleIPhone3Skin.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/AppleIPhone3Skin.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/AppleIPhone3Skin.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * 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.vpe.browsersim.ui.skin;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+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.graphics.Region;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.ProgressBar;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.vpe.browsersim.browser.BrowserSimBrowser;
+import org.jboss.tools.vpe.browsersim.browser.IBrowserSimBrowserFactory;
+import org.jboss.tools.vpe.browsersim.ui.ControlHandler;
+import org.jboss.tools.vpe.browsersim.util.ResourcesUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class AppleIPhone3Skin implements BrowserSimSkin {
+ private static final Point FORWARD_LOCATION = new Point(115, 571);
+ private static final Rectangle BROWSER_RECTANGLE = new Rectangle(33, 206, 320, 355);
+ private static final Rectangle URL_RECTANGLE = new Rectangle(45, 178, 245, 17);
+ private static final int URL_BACKGROUND_COLOR = SWT.COLOR_WHITE;
+ private static final Rectangle PROGRESS_BAR_RECTANGLE = new Rectangle(40, 200, 277, 5);
+ private static final Point STOP_LOCATION = new Point(294, 178);
+ private static final Point REFRESH_LOCATION = new Point(323, 173);
+ private static final Point BACK_LOCATION = new Point(52, 571);
+
+ private static final int[] VISIBLE_REGION = {
+ 62, 3, 257, 3, 258, 2, 258, 0, 320, 0, 320, 2, 321, 3, 330, 3, 331, 4, 334, 4, 335, 5,
338, 5, 339, 6, 341, 6,
+ 342, 7, 344, 7, 345, 8, 347, 8, 348, 9, 349, 9, 350, 10, 351, 10, 353, 12, 354, 12,
355, 13, 356, 13, 359, 16,
+ 360, 16, 368, 24, 368, 25, 371, 28, 371, 29, 373, 31, 373, 32, 374, 33, 374, 34, 375,
35, 375, 36, 376, 37,
+ 376, 38, 377, 39, 377, 41, 378, 42, 378, 43, 379, 44, 379, 46, 380, 47, 380, 50, 381,
51, 381, 54, 382, 55, 382,
+ 60, 383, 61, 383, 668, 382, 669, 382, 673, 381, 674, 381, 678, 380, 679, 380, 682, 379,
683, 379, 685, 378, 686, 378,
+ 687, 377, 688, 377, 690, 376, 691, 376, 692, 375, 693, 375, 694, 374, 695, 374, 696,
373, 697, 373, 698, 371, 700, 371,
+ 701, 368, 704, 368, 705, 360, 713, 359, 713, 356, 716, 355, 716, 354, 717, 353, 717,
351, 719, 350, 719, 349, 720, 348,
+ 720, 347, 721, 345, 721, 344, 722, 341, 722, 340, 723, 337, 723, 336, 724, 334, 724,
333, 725, 329, 725, 328, 726, 59,
+ 726, 58, 725, 54, 725, 53, 724, 47, 724, 46, 723, 44, 723, 43, 722, 41, 722, 40, 721,
39, 721, 38, 720, 37, 720, 36, 719,
+ 35, 719, 34, 718, 33, 718, 31, 716, 30, 716, 28, 714, 27, 714, 17, 704, 17, 703, 14,
700, 14, 699, 13, 698, 13, 697, 12,
+ 696, 12, 695, 11, 694, 11, 693, 10, 692, 10, 691, 9, 690, 9, 689, 8, 688, 8, 686, 7,
685, 7, 683, 6, 682, 6, 680, 5, 679,
+ 5, 676, 4, 675, 4, 670, 3, 669, 3, 660, 2, 659, 2, 258, 1, 257, 1, 256, 0, 255, 0, 220,
1, 219, 1, 212, 2, 211, 2, 177, 1,
+ 176, 1, 169, 0, 168, 0, 132, 2, 130, 2, 108, 3, 107, 2, 106, 1, 106, 1, 74, 2, 73, 2,
67, 3, 66, 3, 59, 4, 58, 4, 54, 5, 53,
+ 5, 50, 6, 49, 6, 47, 7, 46, 7, 44, 8, 43, 8, 41, 9, 40, 9, 39, 10, 38, 10, 37, 11, 36,
11, 35, 12, 34, 12, 33, 13, 32, 13, 31,
+ 14, 30, 14, 29, 17, 26, 17, 25, 26, 16, 27, 16, 30, 13, 31, 13, 33, 11, 34, 11, 35, 10,
36, 10, 37, 9, 38, 9, 39, 8, 41, 8,
+ 42, 7, 43, 7, 44, 6, 47, 6, 48, 5, 50, 5, 51, 4, 61, 4
+ };
+
+ private IBrowserSimBrowserFactory browserFactory;
+ private Shell shell;
+ private BrowserSimBrowser browser;
+ private Display display;
+ private ControlHandler controlHandler;
+ private Text locationText;
+ private ProgressBar progressBar;
+
+ @Override
+ public void setBrowserFactory(IBrowserSimBrowserFactory browserFactory) {
+ this.browserFactory = browserFactory;
+ }
+
+ @Override
+ public void createControls(Display display) {
+ this.display = display;
+ shell = new Shell(display, SWT.NO_TRIM | SWT.NO_BACKGROUND);
+ Region region = new Region();
+ region.add(VISIBLE_REGION);
+ shell.setRegion(region);
+ final Image shellImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/iPhone3.png"));
+ final Image backImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/back.png"));
+ final Image backSelectedImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/back-selected.png"));
+ final Image forwardImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/forward.png"));
+ final Image forwardSelectedImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/forward-selected.png"));
+ final Image refreshImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/refresh.png"));
+ final Image refreshSelectedImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/refresh-selected.png"));
+ final Image stopImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/stop.png"));
+ final Image stopSelectedImage = new Image(display,
ResourcesUtil.getResourceAsStream("iphone_skin/stop-selected.png"));
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ shellImage.dispose();
+ backImage.dispose();
+ backSelectedImage.dispose();
+ forwardImage.dispose();
+ forwardSelectedImage.dispose();
+ refreshImage.dispose();
+ refreshSelectedImage.dispose();
+ stopImage.dispose();
+ stopSelectedImage.dispose();
+ }
+ });
+
+ PhoneButton backButton = new PhoneButton(shell, backImage, backSelectedImage);
+ backButton.setLocation(BACK_LOCATION);
+ backButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ controlHandler.goBack();
+ };
+ });
+
+ PhoneButton forwardButton = new PhoneButton(shell, forwardImage,
forwardSelectedImage);
+ forwardButton.setLocation(FORWARD_LOCATION);
+ forwardButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ controlHandler.goForward();
+ }
+ });
+
+ PhoneButton refreshButton = new PhoneButton(shell, refreshImage,
refreshSelectedImage);
+ refreshButton.setLocation(REFRESH_LOCATION);
+ refreshButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ controlHandler.refresh();
+ }
+ });
+ PhoneButton stopButton = new PhoneButton(shell, stopImage, stopSelectedImage);
+ stopButton.setLocation(STOP_LOCATION);
+ stopButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ controlHandler.stop();
+ }
+ });
+
+ Listener l = new Listener() {
+ Point origin;
+
+ public void handleEvent(Event e) {
+ switch (e.type) {
+ case SWT.MouseDown:
+ origin = new Point(e.x, e.y);
+ break;
+ case SWT.MouseUp:
+ origin = null;
+ break;
+ case SWT.MouseMove:
+ if (origin != null) {
+ Point p = AppleIPhone3Skin.this.display.map(shell, null, e.x, e.y);
+ shell.setLocation(p.x - origin.x, p.y - origin.y);
+ }
+ break;
+ }
+ }
+ };
+
+ shell.addListener(SWT.MouseDown, l);
+ shell.addListener(SWT.MouseUp, l);
+ shell.addListener(SWT.MouseMove, l);
+ // define a region
+ Rectangle imageSize = shellImage.getBounds();
+ // shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ shell.setSize(imageSize.width, imageSize.height);
+ // shell.setBackgroundImage(image);
+ shell.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ Rectangle bounds = shellImage.getBounds();
+ Point size = shell.getSize();
+ e.gc.drawImage(shellImage, 0, 0, bounds.width, bounds.height, 0, 0,
+ size.x, size.y);
+ }
+ });
+
+ locationText = new Text(shell, SWT.NONE);
+ locationText.setBackground(display.getSystemColor(URL_BACKGROUND_COLOR));
+ locationText.setBounds(URL_RECTANGLE);
+
+ progressBar = new ProgressBar(shell, SWT.NONE);
+ progressBar.setBounds(PROGRESS_BAR_RECTANGLE);
+
+ browser = browserFactory.createBrowser(shell, SWT.NONE);
+ browser.setBounds(BROWSER_RECTANGLE);
+
+ locationText.addListener(SWT.DefaultSelection, new Listener() {
+ public void handleEvent(Event e) {
+ controlHandler.goToAddress(locationText.getText());
+ }
+ });
+
+ shell.open();
+ }
+
+ @Override
+ public BrowserSimBrowser getBrowser() {
+ return browser;
+ }
+
+ @Override
+ public Shell getShell() {
+ return shell;
+ }
+
+ @Override
+ public Menu getMenuBar() {
+ return display.getMenuBar();
+ }
+
+ @Override
+ public void setControlHandler(ControlHandler controlHandler) {
+ this.controlHandler = controlHandler;
+ }
+
+ @Override
+ public void setBrowserSize(int width, int height) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void locationChanged(String location) {
+ locationText.setText(location);
+ }
+
+ @Override
+ public void progressChanged(int percents) {
+ if (percents > 0) {
+ progressBar.setVisible(true);
+ progressBar.setSelection(percents);
+ } else {
+ progressBar.setVisible(false);
+ }
+ }
+
+ @Override
+ public void statusTextChanged(String newStatusText) {
+ // TODO Auto-generated method stub
+ }
+}
+
+class PhoneButton extends Button {
+ private Image enabledImage;
+ private Image selectedImage;
+
+ public PhoneButton(Composite parent, Image enabledImage, Image selectedImage) {
+ super(parent, SWT.FLAT);
+ this.enabledImage = enabledImage;
+ this.selectedImage = selectedImage;
+
+ Rectangle imageBounds = enabledImage.getBounds();
+ setSize(imageBounds.width, imageBounds.height);
+ setImage(enabledImage);
+
+ this.addMouseTrackListener(new MouseTrackListener() {
+ @Override
+ public void mouseHover(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExit(MouseEvent e) {
+ setImage(PhoneButton.this.enabledImage);
+ }
+
+ @Override
+ public void mouseEnter(MouseEvent e) {
+ if (PhoneButton.this.selectedImage != null) {
+ setImage(PhoneButton.this.selectedImage);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ setVisible(enabled);
+ }
+
+ @Override
+ protected void checkSubclass() {
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/BrowserSimSkin.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/BrowserSimSkin.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/BrowserSimSkin.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.vpe.browsersim.ui.skin;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.vpe.browsersim.browser.BrowserSimBrowser;
+import org.jboss.tools.vpe.browsersim.browser.IBrowserSimBrowserFactory;
+import org.jboss.tools.vpe.browsersim.ui.ControlHandler;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public interface BrowserSimSkin {
+ void setBrowserFactory(IBrowserSimBrowserFactory browserFactory);
+ void createControls(Display display);
+ BrowserSimBrowser getBrowser();
+ Shell getShell();
+ Menu getMenuBar();
+ void setControlHandler(ControlHandler controlHandler);
+ void setBrowserSize(int width, int height);
+
+ void locationChanged(String newLocation);
+ void progressChanged(int percents); // -1 for completed
+ void statusTextChanged(String newStatusText);
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -0,0 +1,316 @@
+/*******************************************************************************
+ * 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.vpe.browsersim.ui.skin;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.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.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.vpe.browsersim.browser.BrowserSimBrowser;
+import org.jboss.tools.vpe.browsersim.browser.IBrowserSimBrowserFactory;
+import org.jboss.tools.vpe.browsersim.model.Device;
+import org.jboss.tools.vpe.browsersim.ui.ControlHandler;
+import org.jboss.tools.vpe.browsersim.ui.Messages;
+import org.jboss.tools.vpe.browsersim.util.ResourcesUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class NativeSkin implements BrowserSimSkin {
+ private ProgressBar progressBar;
+ private Label statusLabel;
+ private Text locationText;
+ private Shell shell;
+ private BrowserSimBrowser browser;
+ private Menu menuBar;
+ private ControlHandler controlHandler;
+ private ToolItem itemBack;
+ private ToolItem itemForward;
+ private ToolItem itemStop;
+ private ToolItem itemRefresh;
+ private ToolItem itemGo;
+ private ToolItem itemRotateCounterclockwise;
+ private ToolItem itemRotateClockwise;
+ private Composite skinComposite;
+ private IBrowserSimBrowserFactory browserFactory;
+
+ public NativeSkin() {
+ }
+
+ @Override
+ public void setBrowserFactory(IBrowserSimBrowserFactory browserFactory) {
+ this.browserFactory = browserFactory;
+ };
+
+ @Override
+ public void createControls(Display display) {
+ shell = new Shell(display);
+ shell.setLayout(new FillLayout(SWT.VERTICAL | SWT.HORIZONTAL));
+
+ menuBar = display.getMenuBar();
+ if (menuBar == null) {
+ menuBar = new Menu(shell, SWT.BAR);
+ shell.setMenuBar(menuBar);
+ }
+
+ skinComposite = new Composite(shell, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ skinComposite.setLayout(gridLayout);
+
+ ToolBar toolbar = createControlBar();
+ GridData toolbarData = new GridData();
+ toolbarData.horizontalSpan = 3;
+ toolbar.setLayoutData(toolbarData);
+
+ Label labelAddress = new Label(skinComposite, SWT.NONE);
+ labelAddress.setText(Messages.BrowserSim_ADDRESS);
+
+ locationText = new Text(skinComposite, SWT.BORDER);
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.horizontalSpan = 2;
+ data.grabExcessHorizontalSpace = true;
+ data.widthHint = 0;
+ locationText.setLayoutData(data);
+
+ browser = browserFactory.createBrowser(skinComposite, SWT.NONE);
+
+ statusLabel = new Label(skinComposite, SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+ data.widthHint = 0;
+ statusLabel.setLayoutData(data);
+
+ progressBar = new ProgressBar(skinComposite, SWT.NONE);
+ data = new GridData();
+ data.horizontalAlignment = GridData.END;
+ progressBar.setLayoutData(data);
+
+ addControlListeners();
+
+ shell.open();
+ }
+
+ private void addControlListeners() {
+ locationText.addListener(SWT.DefaultSelection, new Listener() {
+ public void handleEvent(Event e) {
+ controlHandler.goToAddress(locationText.getText());
+ }
+ });
+
+ itemBack.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.goBack();
+ }
+ });
+
+ itemForward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.goForward();
+ }
+ });
+
+ itemStop.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.stop();
+ }
+ });
+
+ itemRefresh.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.refresh();
+ }
+ });
+
+ itemRotateCounterclockwise.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.rotate(true);
+ }
+ });
+
+ itemRotateClockwise.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.rotate(false);
+ }
+ });
+
+ itemGo.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ controlHandler.goToAddress(locationText.getText());
+ }
+ });
+ }
+
+ @Override
+ public void setControlHandler(ControlHandler controlHandler) {
+ this.controlHandler = controlHandler;
+ }
+
+ private ToolBar createControlBar() {
+ ToolBar toolbar = new ToolBar(skinComposite, SWT.NONE);
+
+ itemBack = new ToolItem(toolbar, SWT.PUSH);
+// itemBack.setText("Back");
+ itemForward = new ToolItem(toolbar, SWT.PUSH);
+// itemForward.setText("Forward");
+ itemStop = new ToolItem(toolbar, SWT.PUSH);
+// itemStop.setText("Stop");
+ itemRefresh = new ToolItem(toolbar, SWT.PUSH);
+// itemRefresh.setText("Refresh");
+ itemGo = new ToolItem(toolbar, SWT.PUSH);
+// itemGo.setText("Go");
+ itemRotateCounterclockwise = new ToolItem(toolbar, SWT.PUSH);
+// itemGo.setText("Rotate Counterclockwise");
+ itemRotateClockwise = new ToolItem(toolbar, SWT.PUSH);
+// itemGo.setText("Rotate Clockwise");
+
+ Display display = skinComposite.getDisplay();
+ final Image imageBack = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/nav_backward.gif"));
//$NON-NLS-1$
+ final Image imageForward = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/nav_forward.gif"));
//$NON-NLS-1$
+ final Image imageStop = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/nav_stop.gif")); //$NON-NLS-1$
+ final Image imageRefresh = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/nav_refresh.gif"));
//$NON-NLS-1$
+ final Image imageGo = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/nav_go.gif")); //$NON-NLS-1$
+ final Image imageRotateClockwise = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/rotate_clockwise.png"));
//$NON-NLS-1$
+ final Image imageRotateCounterclockwise = new Image(display,
ResourcesUtil.getResourceAsStream("native_skin/rotate_counterclockwise.png"));
//$NON-NLS-1$
+
+ itemBack.setImage(imageBack);
+ itemForward.setImage(imageForward);
+ itemStop.setImage(imageStop);
+ itemRefresh.setImage(imageRefresh);
+ itemGo.setImage(imageGo);
+ itemRotateClockwise.setImage(imageRotateClockwise);
+ itemRotateCounterclockwise.setImage(imageRotateCounterclockwise);
+
+ skinComposite.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ imageBack.dispose();
+ imageForward.dispose();
+ imageStop.dispose();
+ imageRefresh.dispose();
+ imageGo.dispose();
+ imageRotateClockwise.dispose();
+ imageRotateCounterclockwise.dispose();
+ }
+ });
+
+ return toolbar;
+ }
+
+ public void setBrowserSize(int width, int height) {
+ GridData data = (GridData) browser.getLayoutData();
+
+ Rectangle clientArea = getMonitorClientArea();
+ int shellWidthHint = SWT.DEFAULT;
+ if (width != Device.DEFAULT_SIZE) {
+ data.widthHint = width;
+ } else if (data.widthHint == SWT.DEFAULT) {
+ shellWidthHint = clientArea.width;
+ }
+ int shellHeightHint = SWT.DEFAULT;
+ if (height != Device.DEFAULT_SIZE) {
+ data.heightHint = height;
+ } else if (data.heightHint == SWT.DEFAULT) {
+ shellHeightHint = clientArea.height;
+ }
+ Point shellSize = shell.computeSize(shellWidthHint, shellHeightHint);
+ 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);
+ }
+
+ private Rectangle getMonitorClientArea() {
+ Rectangle clientArea = skinComposite.getMonitor().getClientArea();
+
+ /* on Linux returned monitor client area may be bigger
+ * than the monitor bounds when multiple monitors are used.
+ * The following code fixes this */
+ Rectangle bounds = skinComposite.getMonitor().getBounds();
+ clientArea.width = Math.min(clientArea.width, bounds.width);
+ clientArea.height = Math.min(clientArea.height, bounds.height);
+
+ return clientArea;
+ }
+
+ @Override
+ public BrowserSimBrowser getBrowser() {
+ return browser;
+ }
+
+ @Override
+ public Shell getShell() {
+ return shell;
+ }
+
+ @Override
+ public Menu getMenuBar() {
+ return menuBar;
+ }
+
+ @Override
+ public void locationChanged(String location) {
+ locationText.setText(location);
+ }
+
+ @Override
+ public void progressChanged(int percents) {
+ if (percents > 0) {
+ progressBar.setEnabled(true);
+ progressBar.setSelection(percents);
+ } else {
+ progressBar.setSelection(0);
+ progressBar.setEnabled(false);
+ }
+
+ }
+
+ @Override
+ public void statusTextChanged(String statusText) {
+ statusLabel.setText(statusText);
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/util/ResourcesUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/util/ResourcesUtil.java 2012-01-04
15:23:01 UTC (rev 37645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/util/ResourcesUtil.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -19,7 +19,13 @@
*/
public class ResourcesUtil {
+ private static final String RESOURCES_ROOT_FOLDER =
"/org/jboss/tools/vpe/browsersim/resources/"; //$NON-NLS-1$
+
public static InputStream getResourceAsStream(String name) {
- return BrowserSim.class.getResourceAsStream(name);
+ if (name.startsWith("/")) {
+ return BrowserSim.class.getResourceAsStream(name);
+ } else {
+ return BrowserSim.class.getResourceAsStream(RESOURCES_ROOT_FOLDER + name);
+ }
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/AbstractWebKitBrowser.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/AbstractWebKitBrowser.java 2012-01-04
15:23:01 UTC (rev 37645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/AbstractWebKitBrowser.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -11,13 +11,12 @@
package org.jboss.tools.vpe.browsersim.browser;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
/**
* @author Yahor Radtsevich (yradtsevich)
*/
-public abstract class AbstractWebKitBrowser extends Browser {
+public abstract class AbstractWebKitBrowser extends BrowserSimBrowser {
private String defaultUserAgent;
@@ -26,10 +25,6 @@
}
@Override
- protected void checkSubclass() {
- }
-
- @Override
public boolean setUrl(String url, String postData, String[] headers) {
setCustomUserAgent(defaultUserAgent);
boolean result = super.setUrl(url, postData, headers);
@@ -37,6 +32,7 @@
return result;
}
+ @Override
public void setDefaultUserAgent(String defaultUserAgent) {
this.defaultUserAgent = defaultUserAgent;
setCustomUserAgent(defaultUserAgent);
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/BrowserSimBrowser.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/BrowserSimBrowser.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/BrowserSimBrowser.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -0,0 +1,17 @@
+package org.jboss.tools.vpe.browsersim.browser;
+
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.widgets.Composite;
+
+public abstract class BrowserSimBrowser extends Browser {
+
+ public BrowserSimBrowser(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ public abstract void setDefaultUserAgent(String defaultUserAgent);
+
+ @Override
+ protected void checkSubclass() {
+ }
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/IBrowserSimBrowserFactory.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/IBrowserSimBrowserFactory.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/IBrowserSimBrowserFactory.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -0,0 +1,7 @@
+package org.jboss.tools.vpe.browsersim.browser;
+
+import org.eclipse.swt.widgets.Composite;
+
+public interface IBrowserSimBrowserFactory {
+ BrowserSimBrowser createBrowser(Composite parent, int style);
+}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/WebKitBrowserFactory.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/WebKitBrowserFactory.java 2012-01-04
15:23:01 UTC (rev 37645)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/WebKitBrowserFactory.java 2012-01-04
15:47:31 UTC (rev 37646)
@@ -20,8 +20,9 @@
/**
* @author "Yahor Radtsevich (yradtsevich)"
*/
-public class WebKitBrowserFactory {
- public static AbstractWebKitBrowser createWebKitBrowser(Composite parent, int style) {
+public class WebKitBrowserFactory implements IBrowserSimBrowserFactory {
+ @Override
+ public AbstractWebKitBrowser createBrowser(Composite parent, int style) {
if (PlatformUtil.CURRENT_PLATFORM.equals("gtk.linux.x86")) {
return new WebKitBrowser_gtk_linux_x86(parent, style);
} else if (PlatformUtil.CURRENT_PLATFORM.equals("gtk.linux.x86_64")) {