Author: yradtsevich
Date: 2012-01-12 13:06:29 -0500 (Thu, 12 Jan 2012)
New Revision: 37791
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/org.jboss.tools.vpe.browsersim/
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/address-bar-horizontal.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/address-bar.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/iPhone3-horizontal.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/show-address-bar-horizontal.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/show-address-bar.png
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ButtonImageDecorator.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/CompositeImageDecorator.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ControlImageDecorator.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ImageList.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/Device.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg
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/Messages.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties
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
Log:
https://issues.jboss.org/browse/JBIDE-10431 : browsersim should be sexy
- added iPhone3 horizontal orientation
- added possibility to turn skins
- refactored code
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/Device.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/Device.java 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/Device.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -10,6 +10,10 @@
******************************************************************************/
package org.jboss.tools.vpe.browsersim.model;
+import org.jboss.tools.vpe.browsersim.ui.skin.AppleIPhone3Skin;
+import org.jboss.tools.vpe.browsersim.ui.skin.BrowserSimSkin;
+import org.jboss.tools.vpe.browsersim.ui.skin.NativeSkin;
+
/**
* @author Yahor Radtsevich (yradtsevich)
*/
@@ -20,6 +24,7 @@
private int width;
private int height;
private String userAgent;
+ private Class<? extends BrowserSimSkin> skinClass;
public Device(String name, int width, int height, String userAgent) {
this.name = name;
@@ -43,4 +48,13 @@
public String getName() {
return name;
}
+
+ public Class<? extends BrowserSimSkin> getSkinClass() {
+ //XXX
+ if (name != null && name.equals("Apple iPhone 3 (skinned!)")) {
+ return AppleIPhone3Skin.class;
+ } else {
+ return NativeSkin.class;
+ }
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg 2012-01-12
18:06:29 UTC (rev 37791)
@@ -1,7 +1,8 @@
-3
+4
Desktop (Default User-Agent) 1024 768
Apple iPad 2 768 1024 Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us)
AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5
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 3 (skinned!) 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
RIM 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+
Samsung Galaxy S 480 800 Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; GT-I9000
Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/address-bar-horizontal.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/address-bar-horizontal.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/address-bar.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/address-bar.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-horizontal.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-horizontal.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/show-address-bar-horizontal.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/show-address-bar-horizontal.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/show-address-bar.png
===================================================================
(Binary files differ)
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/iphone_skin/show-address-bar.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-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -12,6 +12,7 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.List;
import java.util.Observable;
import java.util.Observer;
@@ -26,9 +27,10 @@
import org.eclipse.swt.browser.StatusTextListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.MenuAdapter;
+import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
@@ -47,48 +49,77 @@
/**
* @author Yahor Radtsevich (yradtsevich)
*/
-public class BrowserSim implements Runnable {
+public class BrowserSim {
private static final String DEFAULT_URL = "about:blank";
//"http://www.w3schools.com/js/tryit_view.asp?filename=try_nav_useragent";
//$NON-NLS-1$
- private BrowserSimBrowser browser;
+ private static final Class<? extends BrowserSimSkin> DEFAULT_SKIN_CLASS =
NativeSkin.class;
private Display display;
- private Shell shell;
- private String initialUrl;
- private Menu devicesMenu;
+ private String homeUrl;
private DevicesListHolder devicesListHolder;
private DeviceOrientation deviceOrientation;
private BrowserSimSkin skin;
+// private BrowserSimBrowser browser;
+ private ControlHandler controlHandler;
public static void main(String[] args) {
- String initialUrl;
+ String homeUrl;
if (args.length > 0) {
String lastArg = args[args.length - 1];
try {
new URI(lastArg); // validate URL
- initialUrl = lastArg;
+ homeUrl = lastArg;
} catch (URISyntaxException e) {
- initialUrl = DEFAULT_URL;
+ homeUrl = DEFAULT_URL;
}
} else {
- initialUrl = DEFAULT_URL;
+ homeUrl = DEFAULT_URL;
}
- new BrowserSim(new Display(), initialUrl).run();
+
+ DevicesList devicesList = DevicesListStorage.loadUserDefinedDevicesList();
+ if (devicesList == null) {
+ devicesList = DevicesListStorage.loadDefaultDevicesList();
+ }
+ Device defaultDevice =
devicesList.getDevices().get(devicesList.getSelectedDeviceIndex());
+ Display display = new Display();
+ BrowserSim browserSim = new BrowserSim(display, homeUrl);
+ browserSim.initSkin(defaultDevice);
+ browserSim.initDevicesListHolder();
+ browserSim.devicesListHolder.setDevicesList(devicesList);
+ browserSim.devicesListHolder.notifyObservers();
+
+ while (browserSim.skin!= null && browserSim.skin.getShell() != null &&
!browserSim.skin.getShell().isDisposed()) {//XXX
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
}
- public BrowserSim(Display display, String initialUrl) {
+ public BrowserSim(Display display, String homeUrl) {
this.display = display;
- this.initialUrl = initialUrl;
+ this.homeUrl = homeUrl;
}
- @Override
- public void run() {
- skin = new NativeSkin();//new AppleIPhone3Skin();
+ public void initSkin(Device device) {
+ Class<? extends BrowserSimSkin> skinClass = device.getSkinClass();
+ if (skinClass == null) {
+ skinClass = DEFAULT_SKIN_CLASS;
+ }
+
+ try {
+ skin = skinClass.newInstance();//new AppleIPhone3Skin();//new NativeSkin();
+ } catch (InstantiationException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IllegalAccessException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
skin.setBrowserFactory(new WebKitBrowserFactory());
-
try {
skin.createControls(display);
} catch (SWTError e) {
- System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER +
e.getMessage());
+ System.err.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER +
e.getMessage());
MessageBox messageBox = new MessageBox(new Shell(display), SWT.OK | SWT.ICON_ERROR);
messageBox.setText("Error");
@@ -99,7 +130,7 @@
return;
}
- shell = skin.getShell();
+ Shell shell = skin.getShell();
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (devicesListHolder != null) {
@@ -109,11 +140,22 @@
});
shell.setText(Messages.BrowserSim_BROWSER_SIM);
- browser = skin.getBrowser();
+ BrowserSimBrowser browser = skin.getBrowser();
+ controlHandler = new ControlHandlerImpl(browser);
+ skin.setControlHandler(controlHandler);
+ Menu appMenuBar = skin.getMenuBar();
+ if (appMenuBar != null) {
+ createMenusForMenuBar(appMenuBar);
+ }
+
+ Menu contextMenu = new Menu(shell);
+ shell.setMenu(contextMenu);
+ createMenuItemsForContextMenu(contextMenu);
+
browser.addProgressListener(new ProgressListener() {
public void changed(ProgressEvent event) {
- if (event.total == 0) return;
+ if (event.total == 0) return;
int ratio = event.current * 100 / event.total;
skin.progressChanged(ratio);
}
@@ -136,14 +178,6 @@
}
});
- 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());
@@ -151,53 +185,14 @@
public void changing(LocationEvent event) {
}
});
-
- skin.setControlHandler(new ControlHandlerImpl(browser));
-
- devicesListHolder = new DevicesListHolder();
- Menu appMenuBar = skin.getMenuBar();
- if (appMenuBar != null) {
- fillMenuBar(appMenuBar);
- }
-
- DevicesList devicesList = DevicesListStorage.loadUserDefinedDevicesList();
- if (devicesList == null) {
- devicesList = DevicesListStorage.loadDefaultDevicesList();
- }
-
- devicesListHolder.setDevicesList(devicesList);
- devicesListHolder.notifyObservers();
-
- if (devicesList != null && devicesList.getDevices() != null
- && devicesList.getSelectedDeviceIndex() < devicesList.getDevices().size())
{
- setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
- }
-
- browser.setUrl(initialUrl);
-
- while (!this.shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
}
- 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);
+ private void initDevicesListHolder() {
+ devicesListHolder = new DevicesListHolder();
devicesListHolder.addObserver(new Observer() {
public void update(Observable o, Object arg) {
DevicesListHolder devicesManager = (DevicesListHolder) o;
DevicesList devicesList = devicesManager.getDevicesList();
- setDevicesListForMenu(devicesList);
if (devicesList.getSelectedDeviceIndex() < devicesList.getDevices().size()) {
setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
}
@@ -208,13 +203,51 @@
});
}
});
+ }
- new MenuItem(devicesMenu, SWT.BAR);
+ private void createMenuItemsForContextMenu(Menu contextMenu) {
+ contextMenu.addMenuListener(new MenuAdapter() {
+ public void menuShown(MenuEvent e) {
+ Menu contextMenu = (Menu) e.widget;
+ for (MenuItem item : contextMenu.getItems()) {
+ item.dispose();
+ }
+
+ addDevicesMenuItems(contextMenu);
+ new MenuItem(contextMenu, SWT.BAR);
+ addTurnMenuItems(contextMenu);
+ new MenuItem(contextMenu, SWT.BAR);
+ addFileMenuItems(contextMenu);
+ }
+ });
+ }
+
+ private void createMenusForMenuBar(Menu appMenuBar) {
+ Menu file = createDropDownMenu(appMenuBar, Messages.BrowserSim_FILE);
+ addFileMenuItems(file);
+
+ Menu devicesMenu = createDropDownMenu(appMenuBar, Messages.BrowserSim_DEVICES);
+ devicesMenu.addMenuListener(new MenuAdapter() {
+ public void menuShown(MenuEvent e) {
+ Menu devicesMenu = (Menu)e.widget;
+ for (MenuItem item : devicesMenu.getItems()) {
+ item.dispose();
+ }
+ addDevicesMenuItems(devicesMenu);
+ new MenuItem(devicesMenu, SWT.BAR);
+ addTurnMenuItems(devicesMenu);
+ }
+ });
+ }
+
+ private void addDevicesMenuItems(final Menu devicesMenu) {
+ addDevicesListForMenu(devicesListHolder.getDevicesList(), devicesMenu);
+
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,
+ DevicesList newDevicesList = new ManageDevicesDialog(e.display.getActiveShell(),
SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
devicesListHolder.getDevicesList()).open();
if (newDevicesList != null) {
devicesListHolder.setDevicesList(newDevicesList);
@@ -224,23 +257,49 @@
});
}
- private void setDevicesListForMenu(DevicesList devicesList) {
- for (MenuItem item : devicesMenu.getItems()) {
- if (item.getData() instanceof Device) {
- item.dispose();
+ private void addFileMenuItems(Menu file) {
+ MenuItem exit = new MenuItem(file, SWT.PUSH);
+ exit.setText(Messages.BrowserSim_EXIT);
+ exit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ display.dispose();
+ };
+ });
+ }
+
+ private void addTurnMenuItems(Menu menu) {
+ MenuItem turnLeft = new MenuItem(menu, SWT.PUSH);
+ turnLeft.setText(Messages.BrowserSim_TURN_LEFT);
+ turnLeft.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ controlHandler.rotate(true);
}
- }
+ });
- int currentIndex = 0;
- for (Device device : devicesList.getDevices()) {
- MenuItem deviceMenuItem = new MenuItem(devicesMenu, SWT.RADIO, currentIndex);
+ MenuItem turnRight = new MenuItem(menu, SWT.PUSH);
+ turnRight.setText(Messages.BrowserSim_TURN_RIGHT);
+ turnRight.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ controlHandler.rotate(false);
+ }
+ });
+ }
+
+ private void addDevicesListForMenu(final DevicesList devicesList, Menu devicesMenu) {
+ List<Device> devices = devicesList.getDevices();
+ for (int i = 0; i < devices.size(); i++) {
+ Device device = devices.get(i);
+ MenuItem deviceMenuItem = new MenuItem(devicesMenu, SWT.RADIO);
deviceMenuItem.setText(device.getName());
deviceMenuItem.setData(device);
+ if (i == devicesList.getSelectedDeviceIndex()) {
+ deviceMenuItem.setSelection(true);
+ }
+
deviceMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
MenuItem menuItem = (MenuItem)e.widget;
if (menuItem.getSelection()) {
- DevicesList devicesList = devicesListHolder.getDevicesList();
int selectedDeviceIndex = devicesList.getDevices().indexOf(menuItem.getData());
if (selectedDeviceIndex < 0) {
selectedDeviceIndex = 0;
@@ -250,30 +309,28 @@
}
};
});
-
- currentIndex++;
}
}
private Menu createDropDownMenu(Menu menuBar, String name) {
- MenuItem manuItem = new MenuItem(menuBar, SWT.CASCADE);
- manuItem.setText(name);
+ MenuItem menuItem = new MenuItem(menuBar, SWT.CASCADE);
+ menuItem.setText(name);
Menu dropdown = new Menu(menuBar);
- manuItem.setMenu(dropdown);
+ menuItem.setMenu(dropdown);
return dropdown;
}
public void setDevice(final Device device) {
- if (devicesMenu != null) {
- for (MenuItem menuItem : devicesMenu.getItems()) {
- if (menuItem.getData() instanceof Device) {
- menuItem.setSelection(menuItem.getData() == device);
- }
- }
+ String oldSkinUrl = null;
+ if (device.getSkinClass() != skin.getClass()
+ || (device.getSkinClass() == null && skin.getClass() != DEFAULT_SKIN_CLASS))
{
+ oldSkinUrl = skin.getBrowser().getUrl();
+ skin.getBrowser().getShell().dispose();//XXX
+ initSkin(device);
}
skin.setBrowserSize(device.getWidth(), device.getHeight());
- deviceOrientation = new DeviceOrientation(device.getWidth() < device.getHeight()
+ deviceOrientation = new DeviceOrientation(device.getWidth() < device.getHeight()
? DeviceOrientation.PORTRAIT
: DeviceOrientation.LANDSCAPE);
deviceOrientation.addObserver(new Observer() {
@@ -285,26 +342,32 @@
if (orientationAngle == DeviceOrientation.LANDSCAPE
|| orientationAngle == DeviceOrientation.LANDSCAPE_INVERTED) {
- skin.setBrowserSize(maxSize, minSize);
+ skin.setBrowserSize(maxSize, minSize);
} else {
- skin.setBrowserSize(minSize, maxSize);
+ skin.setBrowserSize(minSize, maxSize);
}
fireOrientationChangeEvent(orientationAngle);
}
});
- browser.setDefaultUserAgent(device.getUserAgent());
- browser.refresh();
+ skin.getBrowser().setDefaultUserAgent(device.getUserAgent());
+
+ if (oldSkinUrl != null) {
+ skin.getBrowser().setUrl(oldSkinUrl);
+ } else {
+ skin.getBrowser().setUrl(homeUrl);
+ }
}
-
+
private void initOrientation(int orientation) {
- browser.execute("window.onorientationchange = null;"
- + "window.orientation = " + orientation + ";");
+ skin.getBrowser().execute("window.onorientationchange = null;"
+ + "window.orientation = " + orientation + ";");
}
private void fireOrientationChangeEvent(int orientation) {
- browser.execute("window.orientation = " + orientation + ";"
+ skin.setOrientation(orientation);
+ skin.getBrowser().execute("window.orientation = " + orientation +
";"
+ "(function(){"
+ "var event = document.createEvent('Event');"
+ "event.initEvent('orientationchange', false, false);" //
http://jsbin.com/azefow/6 https://developer.mozilla.org/en/DOM/document.createEvent
@@ -340,7 +403,7 @@
@Override
public void goHome() {
- browser.setUrl("about:blank");//XXX
+ browser.setUrl(homeUrl);
}
@Override
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -25,6 +25,8 @@
public static String BrowserSim_EXIT;
public static String BrowserSim_FILE;
public static String BrowserSim_MORE;
+ public static String BrowserSim_TURN_LEFT;
+ public static String BrowserSim_TURN_RIGHT;
public static String EditDeviceDialog_CANCEL;
public static String EditDeviceDialog_EDIT_DEVICE;
public static String EditDeviceDialog_HEIGHT;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties 2012-01-12
18:06:29 UTC (rev 37791)
@@ -6,6 +6,8 @@
BrowserSim_EXIT=Exit
BrowserSim_FILE=File
BrowserSim_MORE=More...
+BrowserSim_TURN_LEFT=Turn Left
+BrowserSim_TURN_RIGHT=Turn Right
EditDeviceDialog_CANCEL=Cancel
EditDeviceDialog_EDIT_DEVICE=Edit Device
EditDeviceDialog_HEIGHT=Height:
Modified:
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 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/AppleIPhone3Skin.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Copyright (c) 2007-2012 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,
@@ -10,11 +10,11 @@
******************************************************************************/
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.browser.BrowserFunction;
+import org.eclipse.swt.browser.LocationEvent;
+import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -34,23 +34,34 @@
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.model.DeviceOrientation;
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 String[] SHELL_IMAGE = {"iphone_skin/iPhone3.png",
"iphone_skin/iPhone3-horizontal.png"};
+ private static final String[] ADDRESS_BAR_IMAGE =
{"iphone_skin/address-bar.png",
"iphone_skin/address-bar-horizontal.png"};
+ private static final String[] SHOW_ADDRESS_BAR_IMAGE =
{"iphone_skin/show-address-bar.png",
"iphone_skin/show-address-bar-horizontal.png"};
+ private static final int VERTICAL = 0;
+ private static final int HORIZONTAL = 1;
+ private static final Point[] FORWARD_LOCATION = {new Point(115, 571), new Point(248,
324)};
+ private static final Rectangle[] BROWSER_RECTANGLE = {new Rectangle(33, 206, 320, 355),
new Rectangle(125, 111, 480, 208)};
+ private static final Rectangle[] BROWSER_RECTANGLE_MAXIMIZED = {new Rectangle(33, 145,
320, 416), new Rectangle(125, 50, 480, 269)};
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 Point[] BACK_LOCATION = {new Point(52, 571), new Point(145, 324)};
+ private static final Point[] SHOW_ADDRESS_BAR_LOCATION = {new Point(33, 126), new
Point(125, 31)};
- private static final int[] VISIBLE_REGION = {
+ private static final Point[] ADDRESS_BAR_LOCATION = {new Point(33, 145), new Point(125,
50)};
+
+ // the following four coordinates are related to ADDRESS_BAR_LOCATION
+ private static final Rectangle[] URL_RECTANGLE = {new Rectangle(12, 33, 245, 17), new
Rectangle(11, 33, 401, 17)};
+ private static final Rectangle[] PROGRESS_BAR_RECTANGLE = {new Rectangle(7, 55, 277, 5),
new Rectangle(7, 55, 430, 5)};
+ private static final Point[] REFRESH_LOCATION = {new Point(290, 28), new Point(447,
28)};
+ private static final Point[] STOP_LOCATION = {new Point(261, 33), new Point(412, 33)};
+
+ 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,
@@ -67,7 +78,25 @@
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
- };
+ },{
+ 100, 0, 668, 0, 669, 1, 673, 1, 674, 2, 678, 2, 679, 3, 682, 3, 683, 4, 685, 4, 686, 5,
687, 5, 688, 6, 690, 6, 691, 7, 692, 7, 693, 8,
+ 694, 8, 695, 9, 696, 9, 697, 10, 698, 10, 700, 12, 701, 12, 704, 15, 705, 15, 713, 23,
713, 24, 716, 27, 716, 28, 717, 29, 717,
+ 30, 719, 32, 719, 33, 720, 34, 720, 35, 721, 36, 721, 38, 722, 39, 722, 42, 723, 43,
723, 46, 724, 47, 724, 49, 725, 50, 725, 54,
+ 726, 55, 726, 324, 725, 325, 725, 329, 724, 330, 724, 336, 723, 337, 723, 339, 722,
340, 722, 342, 721, 343, 721, 344, 720, 345,
+ 720, 346, 719, 347, 719, 348, 718, 349, 718, 350, 716, 352, 716, 353, 714, 355, 714,
356, 704, 366, 703, 366, 700, 369, 699, 369,
+ 698, 370, 697, 370, 696, 371, 695, 371, 694, 372, 693, 372, 692, 373, 691, 373, 690,
374, 689, 374, 688, 375, 686, 375, 685, 376,
+ 683, 376, 682, 377, 680, 377, 679, 378, 676, 378, 675, 379, 670, 379, 669, 380, 660,
380, 659, 381, 258, 381, 257, 382, 256, 382,
+ 255, 383, 220, 383, 219, 382, 212, 382, 211, 381, 177, 381, 176, 382, 169, 382, 168,
383, 132, 383, 130, 381, 108, 381, 107, 380,
+ 106, 381, 106, 382, 74, 382, 73, 381, 67, 381, 66, 380, 59, 380, 58, 379, 54, 379, 53,
378, 50, 378, 49, 377, 47, 377, 46, 376,
+ 44, 376, 43, 375, 41, 375, 40, 374, 39, 374, 38, 373, 37, 373, 36, 372, 35, 372, 34,
371, 33, 371, 32, 370, 31, 370, 30, 369, 29,
+ 369, 26, 366, 25, 366, 16, 357, 16, 356, 13, 353, 13, 352, 11, 350, 11, 349, 10, 348,
10, 347, 9, 346, 9, 345, 8, 344, 8, 342, 7,
+ 341, 7, 340, 6, 339, 6, 336, 5, 335, 5, 333, 4, 332, 4, 322, 3, 321, 3, 126, 2, 125, 0,
125, 0, 63, 2, 63, 3, 62, 3, 53, 4, 52,
+ 4, 49, 5, 48, 5, 45, 6, 44, 6, 42, 7, 41, 7, 39, 8, 38, 8, 36, 9, 35, 9, 34, 10, 33,
10, 32, 12, 30, 12, 29, 13, 28, 13, 27, 16,
+ 24, 16, 23, 24, 15, 25, 15, 28, 12, 29, 12, 31, 10, 32, 10, 33, 9, 34, 9, 35, 8, 36, 8,
37, 7, 38, 7, 39, 6, 41, 6, 42, 5, 43, 5,
+ 44, 4, 46, 4, 47, 3, 50, 3, 51, 2, 54, 2, 55, 1, 60, 1, 61, 0
+ }};
+
+
private IBrowserSimBrowserFactory browserFactory;
private Shell shell;
@@ -76,6 +105,19 @@
private ControlHandler controlHandler;
private Text locationText;
private ProgressBar progressBar;
+ private int orientation;
+ private ButtonImageDecorator backButtonDecorator;
+ private ButtonImageDecorator forwardButtonDecorator;
+ private ButtonImageDecorator refreshButtonDecorator;
+ private ButtonImageDecorator stopButtonDecorator;
+ private Image shellImage;
+ private Region shellRegion;
+ private ButtonImageDecorator showAddressBarButtonDecorator;
+ private boolean addressBarVisible = true;
+ private int currentOrientationIndex;
+ private CompositeImageDecorator addressBarDecorator;
+ private ImageList imageList;
+ private BrowserFunction scrollListener = null;
@Override
public void setBrowserFactory(IBrowserSimBrowserFactory browserFactory) {
@@ -86,80 +128,101 @@
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();
- }
- });
+ imageList = new ImageList(shell);
- PhoneButton backButton = new PhoneButton(shell, backImage, backSelectedImage);
- backButton.setLocation(BACK_LOCATION);
+ Image backImage = imageList.getImage("iphone_skin/back.png");
+ Image backSelectedImage =
imageList.getImage("iphone_skin/back-selected.png");
+ Image forwardImage = imageList.getImage("iphone_skin/forward.png");
+ Image forwardSelectedImage =
imageList.getImage("iphone_skin/forward-selected.png");
+ Image refreshImage = imageList.getImage("iphone_skin/refresh.png");
+ Image refreshSelectedImage =
imageList.getImage("iphone_skin/refresh-selected.png");
+ Image stopImage = imageList.getImage("iphone_skin/stop.png");
+ Image stopSelectedImage =
imageList.getImage("iphone_skin/stop-selected.png");
+
+ Button backButton = new Button(shell, SWT.FLAT);
backButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
controlHandler.goBack();
};
});
+ backButtonDecorator = new ButtonImageDecorator(backButton);
+ backButtonDecorator.setImages(backImage, backSelectedImage);
+ backButtonDecorator.setLocations(BACK_LOCATION[VERTICAL], BACK_LOCATION[HORIZONTAL]);
- PhoneButton forwardButton = new PhoneButton(shell, forwardImage,
forwardSelectedImage);
- forwardButton.setLocation(FORWARD_LOCATION);
+ Button forwardButton = new Button(shell, SWT.FLAT);
forwardButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
controlHandler.goForward();
}
});
+ forwardButtonDecorator = new ButtonImageDecorator(forwardButton);
+ forwardButtonDecorator.setImages(forwardImage, forwardSelectedImage);
+ forwardButtonDecorator.setLocations(FORWARD_LOCATION[VERTICAL],
FORWARD_LOCATION[HORIZONTAL]);
- PhoneButton refreshButton = new PhoneButton(shell, refreshImage,
refreshSelectedImage);
- refreshButton.setLocation(REFRESH_LOCATION);
+ Composite addressBar = new Composite(shell, SWT.NONE);
+ addressBarDecorator = new CompositeImageDecorator(addressBar);
+ addressBarDecorator.setImages(imageList.getImage(ADDRESS_BAR_IMAGE[VERTICAL]),
imageList.getImage(ADDRESS_BAR_IMAGE[VERTICAL]),
+ imageList.getImage(ADDRESS_BAR_IMAGE[HORIZONTAL]),
imageList.getImage(ADDRESS_BAR_IMAGE[HORIZONTAL]));
+ addressBarDecorator.setLocations(ADDRESS_BAR_LOCATION[VERTICAL],
ADDRESS_BAR_LOCATION[HORIZONTAL]);
+
+ locationText = new Text(addressBar, SWT.NONE);
+ locationText.setBackground(display.getSystemColor(URL_BACKGROUND_COLOR));
+
+ progressBar = new ProgressBar(addressBar, SWT.NONE);
+ progressBar.setVisible(false);
+
+
+ Button refreshButton = new Button(addressBar, SWT.FLAT);
refreshButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
controlHandler.refresh();
}
});
- PhoneButton stopButton = new PhoneButton(shell, stopImage, stopSelectedImage);
- stopButton.setLocation(STOP_LOCATION);
+ refreshButtonDecorator = new ButtonImageDecorator(refreshButton);
+ refreshButtonDecorator.setImages(refreshImage, refreshSelectedImage);
+ refreshButtonDecorator.setLocations(REFRESH_LOCATION[VERTICAL],
REFRESH_LOCATION[HORIZONTAL]);
+
+ Button stopButton = new Button(addressBar, SWT.FLAT);
+ stopButtonDecorator = new ButtonImageDecorator(stopButton);
+ stopButtonDecorator.setImages(stopImage, stopSelectedImage);
+ stopButtonDecorator.setLocations(STOP_LOCATION[VERTICAL], STOP_LOCATION[HORIZONTAL]);
stopButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
controlHandler.stop();
}
});
+
+ Button showAddressBarButton = new Button(shell, SWT.FLAT);
+ showAddressBarButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ setAddressBarVisible(!addressBarVisible);
+ }
+ });
+ showAddressBarButtonDecorator = new ButtonImageDecorator(showAddressBarButton);
+ Image showAddressBarVerticalImage =
imageList.getImage(SHOW_ADDRESS_BAR_IMAGE[VERTICAL]);
+ Image showAddressBarHorizontalImage =
imageList.getImage(SHOW_ADDRESS_BAR_IMAGE[HORIZONTAL]);
+ showAddressBarButtonDecorator.setImages(showAddressBarVerticalImage,
showAddressBarVerticalImage, showAddressBarHorizontalImage,
showAddressBarHorizontalImage);
+ showAddressBarButtonDecorator.setLocations(SHOW_ADDRESS_BAR_LOCATION[VERTICAL],
SHOW_ADDRESS_BAR_LOCATION[HORIZONTAL]);
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);
+ if ((e.stateMask & SWT.BUTTON1) != 0 || e.button == 1) { // left mouse button
+ 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;
}
- break;
}
}
};
@@ -167,11 +230,6 @@
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();
@@ -181,25 +239,93 @@
}
});
- 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);
-
+// Label showAddressBarLabel = new Label(shell, SWT.NONE);
+// showAddressBarLabel.setBounds(new Rectangle(33, 126, 320, 18));
browser = browserFactory.createBrowser(shell, SWT.NONE);
- browser.setBounds(BROWSER_RECTANGLE);
+ browser.addLocationListener(new LocationListener() {
+ public void changed(LocationEvent event) {
+ if (scrollListener != null) {
+ scrollListener.dispose();
+ }
+ scrollListener = new BrowserFunction(browser, "_browserSim_scrollListener")
{
+ public Object function(Object[] arguments) {
+ double pageYOffset = (Double) arguments[VERTICAL];
+ if (pageYOffset > 0.0) {
+ setAddressBarVisible(false);
+ }
+ return null;
+ }
+ };
+
+ browser.execute(
+ "(function() {" +
+ "var scrollListener = function(e){" +
+ "window._browserSim_scrollListener(window.pageYOffset)" +
+ "};" +
+ "window.addEventListener('scroll', scrollListener);" +
+ "window.addEventListener('beforeunload', function(e){" +
+ "window.removeEventListener('scroll', scrollListener);" +
+ "delete window._browserSim_scrollListener;" +
+ "})" +
+ "})();");
+ }
+ public void changing(LocationEvent event) {
+ setAddressBarVisible(true);
+ }
+ });
locationText.addListener(SWT.DefaultSelection, new Listener() {
public void handleEvent(Event e) {
controlHandler.goToAddress(locationText.getText());
}
});
-
+
+ currentOrientationIndex = AppleIPhone3Skin.VERTICAL;
+ setWidgetsBounds(currentOrientationIndex);
shell.open();
}
+
+ private void setAddressBarVisible(boolean visible) {
+ Rectangle browserBounds;
+ if (visible) {
+ browserBounds = BROWSER_RECTANGLE[currentOrientationIndex];
+ } else {
+ browserBounds = BROWSER_RECTANGLE_MAXIMIZED[currentOrientationIndex];
+ }
+ browser.setBounds(browserBounds);
+
+ addressBarDecorator.setVisible(visible);
+ addressBarVisible = visible;
+ }
+ private void setWidgetsBounds(int orientationIndex) {
+ boolean vertical = orientationIndex == VERTICAL;
+ addressBarDecorator.setVertical(vertical);
+ backButtonDecorator.setVertical(vertical);
+ forwardButtonDecorator.setVertical(vertical);
+ refreshButtonDecorator.setVertical(vertical);
+ stopButtonDecorator.setVertical(vertical);
+ showAddressBarButtonDecorator.setVertical(vertical);
+
+ locationText.setBounds(URL_RECTANGLE[orientationIndex]);
+ progressBar.setBounds(PROGRESS_BAR_RECTANGLE[orientationIndex]);
+ browser.setBounds(BROWSER_RECTANGLE[orientationIndex]);
+ setAddressBarVisible(addressBarVisible);
+
+ if (shellRegion != null) {
+ shellRegion.dispose();
+ }
+ shellRegion = new Region();
+ shellRegion.add(VISIBLE_REGION[orientationIndex]);
+ shell.setRegion(shellRegion);
+ shellImage = imageList.getImage(SHELL_IMAGE[orientationIndex]);
+ // define a region
+ Rectangle imageSize = shellImage.getBounds();
+ // shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ shell.setSize(imageSize.width, imageSize.height);
+ // shell.setBackgroundImage(image);
+ }
+
@Override
public BrowserSimBrowser getBrowser() {
return browser;
@@ -237,6 +363,7 @@
progressBar.setSelection(percents);
} else {
progressBar.setVisible(false);
+ progressBar.setSelection(0);
}
}
@@ -244,47 +371,21 @@
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;
+ @Override
+ public void setOrientation(int orientation) {
+ if ((this.orientation == DeviceOrientation.PORTRAIT || this.orientation ==
DeviceOrientation.PORTRAIT_INVERTED) &&
+ (orientation == DeviceOrientation.LANDSCAPE || orientation ==
DeviceOrientation.LANDSCAPE_INVERTED)) {
+ //changed from portrait to landscape
+ currentOrientationIndex = HORIZONTAL;
+ } else if ((this.orientation == DeviceOrientation.LANDSCAPE || this.orientation ==
DeviceOrientation.LANDSCAPE_INVERTED) &&
+ (orientation == DeviceOrientation.PORTRAIT || orientation ==
DeviceOrientation.PORTRAIT_INVERTED)) {
+ //changed from landscape to portrait
+ currentOrientationIndex = VERTICAL;
+ }
+ setWidgetsBounds(currentOrientationIndex);
- 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);
- }
- }
- });
+ this.orientation = orientation;
}
+}
- @Override
- public void setEnabled(boolean enabled) {
- super.setEnabled(enabled);
- setVisible(enabled);
- }
-
- @Override
- protected void checkSubclass() {
- }
-}
Modified:
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 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/BrowserSimSkin.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -32,4 +32,5 @@
void locationChanged(String newLocation);
void progressChanged(int percents); // -1 for completed
void statusTextChanged(String newStatusText);
+ void setOrientation(int orientation);
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ButtonImageDecorator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ButtonImageDecorator.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ButtonImageDecorator.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 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.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+
+/**
+ * Allows to render buttons using provided images.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+class ButtonImageDecorator extends ControlImageDecorator<Button> {
+ public ButtonImageDecorator(Button control) {
+ super(control);
+ }
+
+ @Override
+ protected void setImage(Image image) {
+ control.setImage(image);
+ }
+}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/CompositeImageDecorator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/CompositeImageDecorator.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/CompositeImageDecorator.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 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.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Allows to render composites using provided images.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+class CompositeImageDecorator extends ControlImageDecorator<Composite> {
+
+ public CompositeImageDecorator(Composite control) {
+ super(control);
+ }
+
+ @Override
+ protected void setImage(Image image) {
+ control.setBackgroundImage(image);
+ }
+}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ControlImageDecorator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ControlImageDecorator.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ControlImageDecorator.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 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.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Abstract class that allows to render concrete controls using provided images.
+ * A typical usage (anyway a subclass should be used):
+ * <pre><code> Button myButton = new Button(shell, SWT.FLAT);
+ * backButton.addSelectionListener(new SelectionAdapter() {
+ * public void widgetSelected(SelectionEvent e) {
+ * doMyAction();
+ * };
+ * });
+ * ButtonImageDecorator myButtonDecorator = new ButtonImageDecorator(myButton);
+ * myButtonDecorator.setImages(imageForVerticalLayout, imageForVerticalLayoutSelected,
+ * imageForHorizontalLayout, imageForHorizontalLayoutSelected);
+ * myButtonDecorator.setLocations(locationForVerticalLayout,
locationForHorizontalLayout);
+ * myButtonDecorator.setVertical(true);
+ * </code></pre>
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+abstract class ControlImageDecorator<T extends Control> {
+ protected T control;
+ private Point verticalOrientationLocation;
+ private Point horizontalOrientationLocation;
+
+ private Image verticalOrientationEnabledImage;
+ private Image verticalOrientationSelectedImage;
+ private Image horizontalOrientationEnabledImage;
+ private Image horizontalOrientationSelectedImage;
+
+ private boolean vertical = true;
+
+ private MouseTrackListener mouseTrackListener;
+
+ public ControlImageDecorator(T control) {
+ this.control = control;
+ }
+ public void setLocations(Point verticalOrientationLocation, Point
horizontalOrientationLocation) {
+ this.verticalOrientationLocation = verticalOrientationLocation;
+ this.horizontalOrientationLocation = horizontalOrientationLocation;
+ }
+
+ /**
+ * All params must be not null.
+ */
+ public void setImages(Image verticalOrientationEnabledImage,
+ Image verticalOrientationSelectedImage,
+ Image horizontalOrientationEnabledImage,
+ Image horizontalOrientationSelectedImage) {
+ this.verticalOrientationEnabledImage = verticalOrientationEnabledImage;
+ this.verticalOrientationSelectedImage = verticalOrientationSelectedImage;
+ this.horizontalOrientationEnabledImage = horizontalOrientationEnabledImage;
+ this.horizontalOrientationSelectedImage = horizontalOrientationSelectedImage;
+
+ if (mouseTrackListener != null) {
+ control.removeMouseTrackListener(mouseTrackListener);
+ mouseTrackListener = null;
+ }
+ if (verticalOrientationEnabledImage != verticalOrientationSelectedImage
+ || horizontalOrientationEnabledImage != horizontalOrientationSelectedImage) {
+ control.addMouseTrackListener(getMouseTrackListener());
+ }
+ }
+
+ public void setImages(Image enabledImage, Image selectedImage) {
+ setImages(enabledImage, selectedImage, enabledImage, selectedImage);
+ }
+
+ public void setImages(Image image) {
+ setImages(image, image);
+ }
+
+ private MouseTrackListener getMouseTrackListener() {
+ if (mouseTrackListener == null) {
+ mouseTrackListener = new MouseTrackListener() {
+ @Override
+ public void mouseHover(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExit(MouseEvent e) {
+ setSelected(false);
+ }
+
+ @Override
+ public void mouseEnter(MouseEvent e) {
+ setSelected(true);
+ }
+ };
+ }
+ return mouseTrackListener;
+ }
+
+ /**
+ * Changes image of the control
+ */
+ private void setSelected(boolean selected) {
+ if (selected) {
+ if (vertical) {
+ setImageCommon(verticalOrientationSelectedImage);
+ } else {
+ setImageCommon(horizontalOrientationSelectedImage);
+ }
+ } else {
+ if (vertical) {
+ setImageCommon(verticalOrientationEnabledImage);
+ } else {
+ setImageCommon(horizontalOrientationEnabledImage);
+ }
+ }
+ }
+
+ /**
+ * Changes image of the control and its position
+ */
+ public void setVertical(boolean vertical) {
+ this.vertical = vertical;
+ if (vertical) {
+ control.setLocation(verticalOrientationLocation);
+ setImageCommon(verticalOrientationEnabledImage);
+ } else {
+ control.setLocation(horizontalOrientationLocation);
+ setImageCommon(horizontalOrientationEnabledImage);
+ }
+
+ setSelected(false);
+ }
+
+ public void setVisible(boolean enabled) {
+ control.setVisible(enabled);
+ }
+
+ public boolean isVisible() {
+ return control.isVisible();
+ }
+
+ private void setImageCommon(Image image) {
+ Rectangle imageBounds = image.getBounds();
+ control.setSize(imageBounds.width, imageBounds.height);
+ setImage(image);
+ }
+
+ protected abstract void setImage(Image image);
+}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ImageList.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ImageList.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ImageList.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 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 java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Widget;
+import org.jboss.tools.vpe.browsersim.util.ResourcesUtil;
+
+/**
+ * A cache of images. All created images are disposed automatically
+ * together with given {@link #disposable}.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+class ImageList {
+ private Widget disposable;
+ private Map<String, Image> imageMap = new HashMap<String, Image>();
+
+ public ImageList(Widget disposable) {
+ this.disposable = disposable;
+ disposable.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ }
+ });
+ }
+
+ public Image getImage(String location) {
+ Image image = imageMap.get(location);
+ if (image == null) {
+ image = new Image(disposable.getDisplay(),
ResourcesUtil.getResourceAsStream(location));
+ imageMap.put(location, image);
+ }
+
+ return image;
+ }
+
+ private void dispose() {
+ for (Image image : imageMap.values()) {
+ image.dispose();
+ }
+ imageMap.clear();
+ }
+}
Modified:
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 2012-01-12
15:18:12 UTC (rev 37790)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java 2012-01-12
18:06:29 UTC (rev 37791)
@@ -99,6 +99,13 @@
locationText.setLayoutData(data);
browser = browserFactory.createBrowser(skinComposite, SWT.NONE);
+ GridData browserData = new GridData();
+ browserData.horizontalAlignment = GridData.FILL;
+ browserData.verticalAlignment = GridData.FILL;
+ browserData.horizontalSpan = 3;
+ browserData.grabExcessHorizontalSpace = true;
+ browserData.grabExcessVerticalSpace = true;
+ browser.setLayoutData(browserData);
statusLabel = new Label(skinComposite, SWT.NONE);
data = new GridData(GridData.FILL_HORIZONTAL);
@@ -313,4 +320,10 @@
public void statusTextChanged(String statusText) {
statusLabel.setText(statusText);
}
+
+ @Override
+ public void setOrientation(int orientation) {
+ // do nothing, only browser size should change it should
+ // be done by calling setBrowserSize(int width, int height)
+ }
}