Author: yradtsevich
Date: 2012-05-02 11:04:42 -0400 (Wed, 02 May 2012)
New Revision: 40716
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/TextSelectionUtil.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/UIUtil.java
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/ResizableSkin.java
Log:
https://issues.jboss.org/browse/JBIDE-11334 : BrowserSim: provide a more appropriate stop
button
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-02
13:39:47 UTC (rev 40715)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/NativeSkin.java 2012-05-02
15:04:42 UTC (rev 40716)
@@ -171,7 +171,7 @@
}
});
- UIUtil.addSelectTextOnFocusListener(locationText);
+ TextSelectionUtil.addSelectTextOnFocusListener(locationText);
}
@Override
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkin.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkin.java 2012-05-02
13:39:47 UTC (rev 40715)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/ResizableSkin.java 2012-05-02
15:04:42 UTC (rev 40716)
@@ -62,7 +62,7 @@
controlHandler.goToAddress(((Text)e.widget).getText());
}
});
- UIUtil.addSelectTextOnFocusListener(deviceComposite.getUrlText());
+ TextSelectionUtil.addSelectTextOnFocusListener(deviceComposite.getUrlText());
Listener moveListener = new Listener() {
Point origin;
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/TextSelectionUtil.java
(from rev 40638,
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/UIUtil.java)
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/TextSelectionUtil.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/TextSelectionUtil.java 2012-05-02
15:04:42 UTC (rev 40716)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.vpe.browsersim.browser.PlatformUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class TextSelectionUtil {
+ public static void addSelectTextOnFocusListener(final Text targetText) {
+ SelectTextListener selectTextListener;
+ if (PlatformUtil.OS_MACOSX.equals(PlatformUtil.getOs())) {
+ selectTextListener = new OsXSelectTextListenerImpl();
+ } else {
+ selectTextListener = new SelectTextListenerImpl();
+ }
+
+ targetText.addFocusListener(selectTextListener);
+ targetText.addMouseListener(selectTextListener);
+ }
+}
+
+interface SelectTextListener extends FocusListener, MouseListener {
+}
+
+class SelectTextListenerImpl extends MouseAdapter implements SelectTextListener {
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ asyncSelectAllText((Text) e.widget, e.display);
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ asyncClearSelectionText((Text) e.widget, e.display);
+ };
+
+ protected void asyncSelectAllText(final Text text, Display display) {
+ display.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ text.selectAll();
+ }
+ });
+ }
+
+ protected void asyncClearSelectionText(final Text text, Display display) {
+ display.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ text.clearSelection();
+ }
+ });
+ }
+}
+
+class OsXSelectTextListenerImpl extends SelectTextListenerImpl {
+ private boolean focusJustGained = false;
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (focusJustGained) {
+ asyncSelectAllText((Text) e.widget, e.display);
+ focusJustGained = false;
+ }
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ focusJustGained = true;
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ focusJustGained = false;
+ }
+}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/UIUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/UIUtil.java 2012-05-02
13:39:47 UTC (rev 40715)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/skin/UIUtil.java 2012-05-02
15:04:42 UTC (rev 40716)
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * 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.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class UIUtil {
- public static void addSelectTextOnFocusListener(final Text targetText) {
- targetText.addFocusListener(new FocusAdapter() {
- @Override
- public void focusGained(FocusEvent e) {
- e.display.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (!targetText.isDisposed()) {
- targetText.selectAll();
- }
- }
- });
- }
- });
- }
-}