Author: yradtsevich
Date: 2012-05-14 19:50:54 -0400 (Mon, 14 May 2012)
New Revision: 41011
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/CustomMessageBox.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/SizeWarningDialog.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkinSizeAdvisor.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesList.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/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/ExceptionNotifier.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ManageDevicesDialog.java
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
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ios/AppleIPhone3ResizableSkin.java
Log:
https://issues.jboss.org/browse/JBIDE-11739 : browsersim does not set the right height if
monitor has lower resolution - should handle/warn about it
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesList.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesList.java 2012-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesList.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -22,11 +22,13 @@
private List<Device> devices;
private int selectedDeviceIndex;
private boolean useSkins;
+ private Boolean truncateWindow;
- public DevicesList(List<Device> devices, int selectedDeviceIndex, boolean
useSkins) {
+ public DevicesList(List<Device> devices, int selectedDeviceIndex, boolean
useSkins, Boolean truncateWindow) {
this.devices = devices;
this.selectedDeviceIndex = selectedDeviceIndex;
this.useSkins = useSkins;
+ this.truncateWindow = truncateWindow;
}
public List<Device> getDevices() {
@@ -54,4 +56,16 @@
setChanged();
}
}
+
+ public Boolean getTruncateWindow() {
+ return truncateWindow;
+ }
+
+ public void setTruncateWindow(Boolean truncateWindow) {
+ if ( (this.truncateWindow != null &&
!this.truncateWindow.equals(truncateWindow))
+ || (this.truncateWindow == null && truncateWindow != null)) {
+ this.truncateWindow = truncateWindow;
+ setChanged();
+ }
+ }
}
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-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/model/DevicesListStorage.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -33,7 +33,7 @@
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";
- private static final int CURRENT_CONFIG_VERSION = 4;
+ private static final int CURRENT_CONFIG_VERSION = 5;
public static void saveUserDefinedDevicesList(DevicesList devicesList) {
File configFolder = new File(USER_PREFERENCES_FOLDER);
@@ -74,7 +74,7 @@
Device device = new Device("Default", 1024, 768, null, null);
List<Device> devices = new ArrayList<Device>();
devices.add(device);
- devicesList = new DevicesList(devices, 0, true);
+ devicesList = new DevicesList(devices, 0, true, null);
}
return devicesList;
@@ -86,6 +86,9 @@
writer.write("ConfigVersion=" + String.valueOf(CURRENT_CONFIG_VERSION) +
"\n");
writer.write("SelectedDeviceIndex=" +
String.valueOf(devicesList.getSelectedDeviceIndex()) + "\n");
writer.write("UseSkins=" + String.valueOf(devicesList.getUseSkins()) +
"\n");
+ Boolean truncateWindow = devicesList.getTruncateWindow();
+ String truncateWindowString = truncateWindow == null ? "" :
truncateWindow.toString();
+ writer.write("TruncateWindow=" + truncateWindowString + "\n");
for (Device device : devicesList.getDevices()) {
writer.write( encode(device.getName() ));
@@ -118,6 +121,7 @@
List<Device> devices = null;
int selectedDeviceIndex = 0;
boolean useSkins = true;
+ Boolean truncateWindow = true;
try {
String nextLine;
@@ -147,6 +151,18 @@
}
}
+ if ((nextLine = reader.readLine()) != null) {
+ Pattern pattern = Pattern.compile("TruncateWindow=(true|false|)");
+ Matcher matcher = pattern.matcher(nextLine);
+ if (matcher.matches()) {
+ if ( "".equals(matcher.group(1)) ) {
+ truncateWindow = null;
+ } else {
+ truncateWindow = Boolean.parseBoolean(matcher.group(1));
+ }
+ }
+ }
+
Pattern devicePattern =
Pattern.compile("^(.*)\\t(\\-?[0-9]+)\\t(\\-?[0-9]+)\\t(.+)?\\t(.+)?$");
devices = new ArrayList<Device>();
@@ -174,7 +190,7 @@
if (devices == null || devices.size() <= selectedDeviceIndex) {
return null;
} else {
- return new DevicesList(devices, selectedDeviceIndex, useSkins);
+ return new DevicesList(devices, selectedDeviceIndex, useSkins, truncateWindow);
}
}
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-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg 2012-05-14
23:50:54 UTC (rev 41011)
@@ -1,6 +1,7 @@
-ConfigVersion=4
+ConfigVersion=5
SelectedDeviceIndex=2
UseSkins=true
+TruncateWindow=
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 iPhone
4
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 iPhone
3
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-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -58,7 +58,9 @@
import org.jboss.tools.vpe.browsersim.model.DevicesListStorage;
import org.jboss.tools.vpe.browsersim.model.SkinMap;
import org.jboss.tools.vpe.browsersim.ui.skin.BrowserSimSkin;
+import org.jboss.tools.vpe.browsersim.ui.skin.ResizableSkinSizeAdvisor;
import org.jboss.tools.vpe.browsersim.util.ResourcesUtil;
+import org.w3c.dom.DOMConfiguration;
/**
* @author Yahor Radtsevich (yradtsevich)
@@ -79,6 +81,7 @@
private BrowserSimSkin skin;
private ControlHandler controlHandler;
private Image[] icons;
+ private ResizableSkinSizeAdvisor sizeAdvisor;
public static void main(String[] args) {
if (PlatformUtil.OS_MACOSX.equals(PlatformUtil.getOs())) {
@@ -478,9 +481,8 @@
? DeviceOrientation.PORTRAIT
: DeviceOrientation.LANDSCAPE);
Rectangle clientArea = getMonitorClientArea();
- skin.setOrientationAndSize(new Point(clientArea.width, clientArea.height),
- deviceOrientation.getOrientationAngle(),
- new Point(device.getWidth(), device.getHeight()));
+ skin.setOrientationAndSize( deviceOrientation.getOrientationAngle(), new
Point(device.getWidth(), device.getHeight()),
+ getSizeAdvisor());
fixShellLocation(clientArea);
deviceOrientation.addObserver(new Observer() {
public void update(Observable o, Object arg) {
@@ -520,7 +522,7 @@
private void fireOrientationChangeEvent(int orientation, Point browserSize) {
Rectangle clientArea = getMonitorClientArea();
- skin.setOrientationAndSize(new Point(clientArea.width, clientArea.height), orientation,
browserSize);
+ skin.setOrientationAndSize(orientation, browserSize, getSizeAdvisor());
fixShellLocation(clientArea);
skin.getBrowser().execute("window.orientation = " + orientation +
";"
+ "(function(){"
@@ -631,4 +633,43 @@
browser.setFocus();
}
}
+
+ private ResizableSkinSizeAdvisor getSizeAdvisor() {
+ if (sizeAdvisor == null) {
+ sizeAdvisor = new ResizableSkinSizeAdvisor() {
+ @Override
+ public Point checkWindowSize(int orientation, Point prefferedSize,
+ Point prefferedShellSize) {
+ DevicesList devicesList = devicesListHolder.getDevicesList();
+ Rectangle clientArea = getMonitorClientArea();
+
+ boolean truncateWindow = false;
+ if (devicesList.getTruncateWindow() == null) {
+ if (prefferedShellSize.x > clientArea.width || prefferedShellSize.y >
clientArea.height) {
+ SizeWarningDialog dialog = new SizeWarningDialog(skin.getShell(), new
Point(clientArea.width, clientArea.height), prefferedShellSize, "[TODO]",
+ orientation == DeviceOrientation.PORTRAIT || orientation ==
DeviceOrientation.PORTRAIT_INVERTED);
+ dialog.open();
+
+ truncateWindow = dialog.getTruncateWindow();
+ if (dialog.getRememberDecision()) {
+ devicesList.setTruncateWindow(truncateWindow);
+ }
+ }
+ } else {
+ truncateWindow = devicesList.getTruncateWindow();
+ }
+
+ Point size = new Point(prefferedShellSize.x, prefferedShellSize.y);
+ if (truncateWindow) {
+ size.x = Math.min(prefferedShellSize.x, clientArea.width);
+ size.y = Math.min(prefferedShellSize.y, clientArea.height);
+ }
+
+ return size;
+ }
+ };
+ }
+
+ return sizeAdvisor;
+ }
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/CustomMessageBox.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/CustomMessageBox.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/CustomMessageBox.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -0,0 +1,87 @@
+package org.jboss.tools.vpe.browsersim.ui;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+class CustomMessageBox extends Dialog {
+ private Shell shell;
+ private Composite messageComposite;
+ private Composite buttonsComposite;
+ private Image icon;
+
+ public CustomMessageBox(Shell parent, Image icon) {
+ super(parent, SWT.NONE);
+ this.icon = icon;
+ }
+
+ public void open() {
+ createWidgets();
+ shell.open();
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+
+ protected void createWidgets() {
+ shell = new Shell(getParent(), SWT.DIALOG_TRIM);
+ GridLayout shellLayout = new GridLayout(1, true);
+ shellLayout.marginHeight = 0;
+ shellLayout.marginWidth = 0;
+ shellLayout.verticalSpacing = 0;
+ shell.setLayout(shellLayout);
+ shell.setText(getText());
+
+ messageComposite = new Composite(shell, SWT.NONE);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ messageComposite.setLayoutData(gridData);
+ RowLayout messageCompositeLayout = new RowLayout(SWT.HORIZONTAL);
+ messageCompositeLayout.marginHeight = 22;
+ messageCompositeLayout.marginWidth = 22;
+ messageCompositeLayout.spacing = 10;
+ messageCompositeLayout.center = true;
+ messageComposite.setLayout(messageCompositeLayout);
+ messageComposite.setBackground(getMessageCompositeBackground());
+
+ if (icon != null) {
+ Label iconLabel = new Label(messageComposite, SWT.NONE);
+ iconLabel.setImage(icon);
+ iconLabel.setBackground(getMessageCompositeBackground());
+ }
+
+ buttonsComposite = new Composite(shell, SWT.NONE);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ buttonsComposite.setLayoutData(gridData);
+ GridLayout buttonsCompositeLayout = new GridLayout(1, false);
+ buttonsCompositeLayout.marginHeight = 10;
+ buttonsCompositeLayout.marginWidth = 10;
+ buttonsComposite.setLayout(buttonsCompositeLayout);
+ }
+
+ protected Composite getMessageComposite() {
+ return messageComposite;
+ }
+
+ protected Composite getButtonsComposite() {
+ return buttonsComposite;
+ }
+
+ protected Color getMessageCompositeBackground() {
+ return getParent().getDisplay().getSystemColor(SWT.COLOR_WHITE);
+ }
+
+ protected Shell getShell() {
+ return shell;
+ }
+}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java 2012-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -16,18 +16,10 @@
import org.eclipse.swt.SWTError;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Dialog;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
@@ -38,7 +30,6 @@
* @author Yahor Radtsevich (yradtsevich)
*/
public class ExceptionNotifier {
-
/**
* Should be used to notify user about WebKit-loading errors
*/
@@ -79,84 +70,47 @@
}
}
+
/**
* Behaves like MessageBox with styles SWT.OK and SWT.ICON_ERROR, but allows HTML links
is messages.
* @author Yahor Radtsevich (yradtsevich)
*
*/
-class ErrorMessageBoxWithLinks extends Dialog {
- private Shell shell;
+class ErrorMessageBoxWithLinks extends CustomMessageBox {
+
private String message;
public ErrorMessageBoxWithLinks(Shell parent) {
- super(parent, SWT.NONE);
+ super(parent, parent.getDisplay().getSystemImage(SWT.ICON_ERROR));
message = "";
}
- public void open() {
- shell = new Shell(getParent(), SWT.DIALOG_TRIM);
- GridLayout shellLayout = new GridLayout(1, true);
- shellLayout.marginHeight = 0;
- shellLayout.marginWidth = 0;
- shellLayout.verticalSpacing = 0;
- shell.setLayout(shellLayout);
- shell.setText(getText());
-
- Color whiteColor = getParent().getDisplay().getSystemColor(SWT.COLOR_WHITE);
- Composite messageComposite = new Composite(shell, SWT.NONE);
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- messageComposite.setLayoutData(gridData);
- RowLayout messageCompositeLayout = new RowLayout(SWT.HORIZONTAL);
- messageCompositeLayout.marginHeight = 22;
- messageCompositeLayout.marginWidth = 22;
- messageCompositeLayout.spacing = 10;
- messageCompositeLayout.center = true;
- messageComposite.setLayout(messageCompositeLayout);
- messageComposite.setBackground(whiteColor);
-
- Image errorImage = shell.getDisplay().getSystemImage(SWT.ICON_ERROR);
- Label imageLabel = new Label(messageComposite, SWT.NONE);
- imageLabel.setImage(errorImage);
- imageLabel.setBackground(whiteColor);
- Link link = new Link(messageComposite, SWT.WRAP);
+ @Override
+ protected void createWidgets() {
+ super.createWidgets();
+
+ Link link = new Link(getMessageComposite(), SWT.WRAP);
link.setText(message);
- link.setBackground(whiteColor);
+ link.setBackground(getMessageCompositeBackground());
link.addListener (SWT.Selection, new Listener () {
public void handleEvent(Event event) {
Program.launch(event.text);
}
});
- Composite okComposite = new Composite(shell, SWT.NONE);
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- okComposite.setLayoutData(gridData);
- GridLayout okCompositeLayout = new GridLayout(1, false);
- okCompositeLayout.marginHeight = 10;
- okCompositeLayout.marginWidth = 10;
- okComposite.setLayout(okCompositeLayout);
-
- Button ok = new Button(okComposite, SWT.PUSH);
+ Button ok = new Button(getButtonsComposite(), SWT.PUSH);
ok.setText("OK");
ok.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- shell.close();
+ getShell().close();
}
});
GridData okLayoutData = new GridData(SWT.END, SWT.CENTER, true, true);
okLayoutData.widthHint = 88;
ok.setLayoutData(okLayoutData);
- shell.setDefaultButton(ok);
-
-
- shell.pack();
- shell.open();
- Display display = getParent().getDisplay();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
+ getShell().setDefaultButton(ok);
+ getShell().pack();
}
public void setMessage(String message) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ManageDevicesDialog.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ManageDevicesDialog.java 2012-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ManageDevicesDialog.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -15,13 +15,17 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
@@ -40,8 +44,14 @@
protected List<Device> devices;
protected int selectedDeviceIndex;
protected Shell shell;
- private Table table;
- private DevicesList resultDevicesList;
+ protected Table table;
+ protected DevicesList resultDevicesList;
+ protected boolean useSkins;
+ protected Boolean truncateWindow;
+ protected Button askBeforeTruncateRadio;
+ protected Button alwaysTruncateRadio;
+ protected Button neverTruncateRadio;
+ protected Button useSkinsCheckbox;
/**
* Create the dialog.
@@ -55,6 +65,8 @@
this.oldDevicesList = oldDevicesList;
this.devices = new ArrayList<Device>(oldDevicesList.getDevices());
this.selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
+ this.useSkins = oldDevicesList.getUseSkins();
+ this.truncateWindow = oldDevicesList.getTruncateWindow();
}
/**
@@ -81,18 +93,23 @@
shell = new Shell(getParent(), getStyle());
shell.setSize(650, 450);
shell.setText(getText());
- shell.setLayout(new GridLayout(2, false));
+ shell.setLayout(new GridLayout(1, false));
+
+ Group devicesGroup = new Group(shell, SWT.NONE);
+ devicesGroup.setText("Devices");
+ devicesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ devicesGroup.setLayout(new GridLayout(2, false));
- table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ table = new Table(devicesGroup, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setHeaderVisible(true);
- table.setLinesVisible(true);
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
selectedDeviceIndex = ((Table)e.widget).getSelectionIndex();
}
});
+
TableColumn tableColumnName = new TableColumn(table, SWT.NONE);
tableColumnName.setWidth(100);
tableColumnName.setText(Messages.ManageDevicesDialog_NAME);
@@ -113,11 +130,12 @@
tableColumnSkin.setWidth(100);
tableColumnSkin.setText(Messages.ManageDevicesDialog_SKIN);
- Composite compositeControls = new Composite(shell, SWT.NONE);
+ Composite compositeControls = new Composite(devicesGroup, SWT.NONE);
compositeControls.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
compositeControls.setLayout(new FillLayout(SWT.VERTICAL));
Button buttonAdd = new Button(compositeControls, SWT.NONE);
+ buttonAdd.setSize(88, SWT.DEFAULT);
buttonAdd.setText(Messages.ManageDevicesDialog_ADD);
buttonAdd.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@@ -169,36 +187,90 @@
updateDevices();
}
});
+
+ Group useSkinsGroup = new Group(shell, SWT.NONE);
+ useSkinsGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ useSkinsGroup.setLayout(new RowLayout(SWT.VERTICAL));
+ useSkinsGroup.setText("Skins options");
+ useSkinsCheckbox = new Button(useSkinsGroup, SWT.CHECK);
+ useSkinsCheckbox.setText("Use skins");
+ useSkinsCheckbox.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button checkbox = (Button) e.widget;
+ useSkins = checkbox.getSelection();
+ }
+ });
+
+ Group truncateWindowGroup = new Group(shell, SWT.NONE);
+ truncateWindowGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2,
1));
+ truncateWindowGroup.setText("Truncate the browser window when it does not fit
display");
+ truncateWindowGroup.setLayout(new RowLayout(SWT.HORIZONTAL));
+
+
+ alwaysTruncateRadio = new Button(truncateWindowGroup, SWT.RADIO);
+ alwaysTruncateRadio.setText("Always truncate");
+
+ neverTruncateRadio = new Button(truncateWindowGroup, SWT.RADIO);
+ neverTruncateRadio.setText("Never truncate");
- new Label(compositeControls, SWT.NONE);
+ askBeforeTruncateRadio = new Button(truncateWindowGroup, SWT.RADIO);
+ askBeforeTruncateRadio.setText("Prompt");
- Button buttonLoadDefaults = new Button(compositeControls, SWT.NONE);
+ SelectionListener truncateSelectionListener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button radio = (Button) e.widget;
+ if (radio.getSelection()) {
+ if (radio == askBeforeTruncateRadio) {
+ truncateWindow = null;
+ } else if (radio == alwaysTruncateRadio) {
+ truncateWindow = true;
+ } else if (radio == neverTruncateRadio) {
+ truncateWindow = false;
+ }
+ }
+ }
+ };
+
+ askBeforeTruncateRadio.addSelectionListener(truncateSelectionListener);
+ alwaysTruncateRadio.addSelectionListener(truncateSelectionListener);
+ neverTruncateRadio.addSelectionListener(truncateSelectionListener);
+
+
+ Composite compositeOkCancel = new Composite(shell, SWT.NONE);
+ compositeOkCancel.setLayout(new GridLayout(2, true));
+ compositeOkCancel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2,
1));
+
+ new Label(compositeOkCancel, SWT.NONE);
+
+ Button buttonLoadDefaults = new Button(compositeOkCancel, SWT.NONE);
buttonLoadDefaults.setText(Messages.ManageDevicesDialog_LOAD_DEFAULTS);
buttonLoadDefaults.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DevicesList defaultDevicesList = DevicesListStorage.loadDefaultDevicesList();
devices = defaultDevicesList.getDevices();
selectedDeviceIndex = defaultDevicesList.getSelectedDeviceIndex();
+ useSkins = defaultDevicesList.getUseSkins();
+ truncateWindow = defaultDevicesList.getTruncateWindow();
updateDevices();
}
});
- Composite compositeOkCancel = new Composite(shell, SWT.NONE);
- compositeOkCancel.setLayout(new FillLayout(SWT.HORIZONTAL));
- compositeOkCancel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2,
1));
-
Button buttonOk = new Button(compositeOkCancel, SWT.NONE);
buttonOk.setText(Messages.ManageDevicesDialog_OK);
+ buttonOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
shell.setDefaultButton(buttonOk);
buttonOk.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- resultDevicesList = new DevicesList(devices, selectedDeviceIndex,
oldDevicesList.getUseSkins());
+ resultDevicesList = new DevicesList(devices, selectedDeviceIndex, useSkins,
truncateWindow);
shell.close();
}
});
Button buttonCancel = new Button(compositeOkCancel, SWT.NONE);
buttonCancel.setText(Messages.ManageDevicesDialog_CANCEL);
+ buttonCancel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
buttonCancel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resultDevicesList = null;
@@ -210,7 +282,7 @@
updateDevices();
}
- public void updateDevices() {
+ public void updateDevices() {//TODO
table.removeAll();
for (Device device : devices) {
TableItem tableItem = new TableItem(table, SWT.NONE);
@@ -223,5 +295,11 @@
});
}
table.setSelection(selectedDeviceIndex);
+
+ useSkinsCheckbox.setSelection(useSkins);
+
+ askBeforeTruncateRadio.setSelection(truncateWindow == null);
+ alwaysTruncateRadio.setSelection(truncateWindow != null &&
Boolean.TRUE.equals(truncateWindow));
+ neverTruncateRadio.setSelection(truncateWindow != null &&
Boolean.FALSE.equals(truncateWindow));
}
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/SizeWarningDialog.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/SizeWarningDialog.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/SizeWarningDialog.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -0,0 +1,101 @@
+package org.jboss.tools.vpe.browsersim.ui;
+
+import java.text.MessageFormat;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+class SizeWarningDialog extends CustomMessageBox {
+ private Point actualSize;
+ private Point requiredSize;
+ private String deviceName;
+ private boolean vertical;
+ private boolean truncateWindow = false;
+ private boolean rememberDecision = false;
+
+ public SizeWarningDialog(Shell parent, Point actualSize, Point requiredSize, String
deviceName, boolean vertical) {
+ super(parent, parent.getDisplay().getSystemImage(SWT.ICON_INFORMATION));
+ this.actualSize = actualSize;
+ this.requiredSize = requiredSize;
+ this.deviceName = deviceName;
+ this.vertical = vertical;
+ setText("Device size will be truncated");
+ }
+
+ @Override
+ protected void createWidgets() {
+ super.createWidgets();
+
+ Composite messageRow = new Composite(getMessageComposite(), SWT.NONE);
+ messageRow.setLayout(new RowLayout(SWT.VERTICAL));
+ messageRow.setBackground(getMessageCompositeBackground());
+
+ Label message = new Label(messageRow, SWT.WRAP);
+ String messageText;
+ if (vertical) {
+ messageText = MessageFormat.format("Your desktop size ({0}x{1} pixels) is smaller
than what {2} needs in vertical layout ({3}x{4}).\n" +
+ "Device size will be truncated to fit your desktop.",
+ actualSize.x, actualSize.y, deviceName, requiredSize.x, requiredSize.y);
+ } else {
+ messageText = MessageFormat.format("Your desktop size ({0}x{1} pixels) is smaller
than what {2} needs in horizontal layout ({3}x{4}).\n" +
+ "Device size will be truncated to fit your desktop.",
+ actualSize.x, actualSize.y, deviceName, requiredSize.x, requiredSize.y);
+ }
+ message.setText(messageText);
+ message.setBackground(getMessageCompositeBackground());
+
+ Button rememberDecisionCheckbox = new Button(messageRow, SWT.CHECK);
+ rememberDecisionCheckbox.setText("Remember my decision (this can be changed in the
Preferences dialog later).");
+ rememberDecisionCheckbox.setBackground(getMessageCompositeBackground());
+ rememberDecisionCheckbox.setSelection(rememberDecision);
+ rememberDecisionCheckbox.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ rememberDecision = ((Button)e.widget).getSelection();
+ }
+ });
+
+ Composite buttonRow = new Composite(getButtonsComposite(), SWT.NONE);
+ buttonRow.setLayout(new RowLayout(SWT.HORIZONTAL));
+ GridData buttonRowLayoutData = new GridData(SWT.END, SWT.CENTER, true, true);
+ buttonRow.setLayoutData(buttonRowLayoutData);
+
+ Button okButton = new Button(buttonRow, SWT.PUSH);
+ okButton.setText("Yes (recommended)");
+ okButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ truncateWindow = true;
+ getShell().close();
+ }
+ });
+
+ Button noButton = new Button(buttonRow, SWT.PUSH);
+ noButton.setText("No, show me actual size");
+ noButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ getShell().close();
+ }
+ });
+
+ getShell().setDefaultButton(okButton);
+ getShell().pack();
+ }
+
+ public boolean getTruncateWindow() {
+ return truncateWindow;
+ }
+
+ public boolean getRememberDecision() {
+ return rememberDecision;
+ }
+}
\ No newline at end of file
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-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/AppleIPhone3Skin.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -345,7 +345,7 @@
@Override
- public void setOrientationAndSize(Point maximumShellSize, int orientation, Point
browserSize) {
+ public void setOrientationAndSize(int orientation, Point browserSize,
ResizableSkinSizeAdvisor sizeAdvisor) {
// browserSize is ignored by this skin
if ((this.orientation == DeviceOrientation.PORTRAIT || this.orientation ==
DeviceOrientation.PORTRAIT_INVERTED) &&
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-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/BrowserSimSkin.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -33,7 +33,7 @@
void pageTitleChanged(String newTitle);
void progressChanged(int percents); // -1 for completed
void statusTextChanged(String newStatusText);
- void setOrientationAndSize(Point maximumShellSize, int orientation, Point browserSize);
+ void setOrientationAndSize(int orientation, Point browserSize, ResizableSkinSizeAdvisor
sizeAdvisor);
void setAddressBarVisible(boolean visible);
void setContextMenu(Menu contextMenu);
}
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-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -230,24 +230,26 @@
}
@Override
- public void setOrientationAndSize(Point maximumShellSize, int orientation, Point
browserSize) {
+ public void setOrientationAndSize(int orientation, Point browserSize,
ResizableSkinSizeAdvisor sizeAdvisor) {
GridData data = (GridData) browser.getLayoutData();
int shellWidthHint = SWT.DEFAULT;
if (browserSize.x != Device.DEFAULT_SIZE) {
data.widthHint = browserSize.x;
- } else if (data.widthHint == SWT.DEFAULT) {
- shellWidthHint = maximumShellSize.x;
- }
+ }
+// else if (data.widthHint == SWT.DEFAULT) {
+// shellWidthHint = maximumShellSize.x;
+// }
int shellHeightHint = SWT.DEFAULT;
if (browserSize.y != Device.DEFAULT_SIZE) {
data.heightHint = browserSize.y;
- } else if (data.heightHint == SWT.DEFAULT) {
- shellHeightHint = maximumShellSize.y;
}
- Point shellSize = shell.computeSize(shellWidthHint, shellHeightHint);
- shellSize.x = Math.min(shellSize.x, maximumShellSize.x);
- shellSize.y = Math.min(shellSize.y, maximumShellSize.y);
+// else if (data.heightHint == SWT.DEFAULT) {
+// shellHeightHint = maximumShellSize.y;
+// }
+ Point prefferedShellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+
+ Point shellSize = sizeAdvisor.checkWindowSize(orientation, browserSize,
prefferedShellSize);
shell.setSize(shellSize);
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkinSizeAdvisor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkinSizeAdvisor.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkinSizeAdvisor.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -0,0 +1,7 @@
+package org.jboss.tools.vpe.browsersim.ui.skin;
+
+import org.eclipse.swt.graphics.Point;
+
+public interface ResizableSkinSizeAdvisor {
+ public Point checkWindowSize(int orientation, Point prefferedSize, Point
prefferedShellSize);
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ios/AppleIPhone3ResizableSkin.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ios/AppleIPhone3ResizableSkin.java 2012-05-14
23:21:13 UTC (rev 41010)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ios/AppleIPhone3ResizableSkin.java 2012-05-14
23:50:54 UTC (rev 41011)
@@ -21,6 +21,7 @@
import org.jboss.tools.vpe.browsersim.ui.skin.DeviceComposite;
import org.jboss.tools.vpe.browsersim.ui.skin.ImageDescriptor;
import org.jboss.tools.vpe.browsersim.ui.skin.ResizableSkin;
+import org.jboss.tools.vpe.browsersim.ui.skin.ResizableSkinSizeAdvisor;
public class AppleIPhone3ResizableSkin extends ResizableSkin {
private static final Point NORMAL_SKREEN_SIZE = new Point(320, 480);
@@ -234,7 +235,7 @@
}
@Override
- public void setOrientationAndSize(Point maximumShellSize, int orientation, Point
browserSize) {
+ public void setOrientationAndSize(int orientation, Point browserSize,
ResizableSkinSizeAdvisor sizeAdvisor) {
vertical = (orientation == DeviceOrientation.PORTRAIT || orientation ==
DeviceOrientation.PORTRAIT_INVERTED);
String urlTextText = deviceComposite.getUrlText().getText();
String pageTitle = deviceComposite.getPageTitleStyledText() != null ?
deviceComposite.getPageTitleStyledText().getText() : "";
@@ -252,20 +253,22 @@
browser.setParent(browserContainer);
oldDeviceComposite.dispose();
Point bordersSize = getBordersSize(vertical);
- int shellWidth;
+ int shellWidthHint;
if (browserSize.x == SWT.DEFAULT) {
- shellWidth = SWT.DEFAULT;
+ shellWidthHint = SWT.DEFAULT;
} else {
- shellWidth = Math.min(bordersSize.x + browserSize.x, maximumShellSize.x);
+ shellWidthHint = bordersSize.x + browserSize.x;
}
- int shellHeight;
+ int shellHeightHint;
if (browserSize.y == SWT.DEFAULT) {
- shellHeight = SWT.DEFAULT;
+ shellHeightHint = SWT.DEFAULT;
} else {
- shellHeight = Math.min(bordersSize.y + browserSize.y, maximumShellSize.y);
+ shellHeightHint = bordersSize.y + browserSize.y;
}
- shell.setSize(shell.computeSize(shellWidth, shellHeight));
+ Point prefferedShellSize = shell.computeSize(shellWidthHint, shellHeightHint);
+ Point shellSize = sizeAdvisor.checkWindowSize(orientation, browserSize,
prefferedShellSize);
+ shell.setSize(shellSize);
shell.layout(true);
setShellRegion();