From 8d4922b07d0c4dff56e4d2fda919d7bc0418495d Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 8 Feb 2010 15:26:41 -0800 Subject: ADT GLE2: support isMultipleSelection. Problem is easily solved by making this a parameter in the closure, so we don't need to ask rules to give us a different closure, they just need to redraw. Change-Id: I4445c826b03bbb978bf085905ccd67d5e03b0356 --- .../gscripts/android.view.View.groovy | 5 ++-- .../adt/editors/layout/gscripts/IViewRule.java | 12 +++++++-- .../editors/layout/gle2/CanvasSelection.java | 29 ++++++++++++++-------- .../internal/editors/layout/gle2/LayoutCanvas.java | 3 ++- 4 files changed, 34 insertions(+), 15 deletions(-) (limited to 'eclipse') diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.view.View.groovy b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.view.View.groovy index 3dba8d3..2171cf3 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.view.View.groovy +++ b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.view.View.groovy @@ -38,8 +38,9 @@ public class AndroidViewViewRule extends BaseViewRule { // Before that, make sure the engine can deal with the lack of a base class // fallback when navigating the hierarchy. + // TODO move all this to BaseViewRule Closure onSelected(INode node) { - def drawSelection = { gc, name, currentNode -> + def drawSelection = { gc, name, currentNode, isMultipleSelection -> Rect r = currentNode.getBounds(); if (!r.isValid()) { @@ -50,7 +51,7 @@ public class AndroidViewViewRule extends BaseViewRule { gc.setLineStyle(IGraphics.LineStyle.LINE_SOLID); gc.drawRect(r); - if (name == null) { + if (name == null || isMultipleSelection) { return; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/editors/layout/gscripts/IViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/editors/layout/gscripts/IViewRule.java index 68306e7..33ea938 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/editors/layout/gscripts/IViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/editors/layout/gscripts/IViewRule.java @@ -72,11 +72,19 @@ public interface IViewRule { /** + * Called by the canvas when a view is being selected. + * The callback must return a closure that is used to draw the actual selection. + *

+ * The closure takes 4 arguments:
+ * - An {@link IGraphics} instance, to perform drawing operations.
+ * - The name to display, as returned by {@link #getDisplayName()}.
+ * - The selected {@link INode}.
+ * - A boolean set to true if more than one element is selected. + *

* Context: foreground color already set to selection color, full opaque. - * Returns: a closure that takes gc, display_name and node as arguments. * * @param selectedNode The node selected. Never null. - * @return Null or a closure that expects gc, name, currentNode as input arguments. + * @return Null or a closure that expects graphics, name, currentNode as input arguments. */ Closure onSelected(INode selectedNode); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasSelection.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasSelection.java index c6766c4..2ba8e3f 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasSelection.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasSelection.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; +import com.android.ide.eclipse.adt.editors.layout.gscripts.IViewRule; import com.android.ide.eclipse.adt.internal.editors.layout.gre.NodeFactory; import com.android.ide.eclipse.adt.internal.editors.layout.gre.NodeProxy; import com.android.ide.eclipse.adt.internal.editors.layout.gre.RulesEngine; @@ -95,6 +96,24 @@ import groovy.lang.Closure; return mName; } + /** + * Calls the closure returned by + * {@link IViewRule#onSelected(com.android.ide.eclipse.adt.editors.layout.gscripts.INode)}. + * + * @param gcWrapper The GC to use for drawing. + * @param isMultipleSelection True if more than one view is selected. + */ + /*package*/ void paint(GCWrapper gcWrapper, boolean isMultipleSelection) { + if (mPaintClosure != null) { + try { + mPaintClosure.call( + new Object[] { gcWrapper, mName, mNodeProxy, isMultipleSelection }); + } catch (Exception e) { + mNodeProxy.debugPrintf("Selection Paint Closure: %s", e.toString()); + } + } + } + //---- private String initDisplayName(CanvasViewInfo canvasViewInfo, RulesEngine gre) { @@ -143,14 +162,4 @@ import groovy.lang.Closure; mNodeProxy = proxy; mPaintClosure = result; } - - public void paint(GCWrapper gcWrapper) { - if (mPaintClosure != null) { - try { - mPaintClosure.call(new Object[] { gcWrapper, mName, mNodeProxy }); - } catch (Exception e) { - mNodeProxy.debugPrintf("Selection Paint Closure: %s", e.toString()); - } - } - } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index e338864..8bb38eb 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -430,8 +430,9 @@ import java.util.ListIterator; } gc.setForeground(mSelectionFgColor); + boolean isMultipleSelection = mSelections.size() > 1; for (CanvasSelection s : mSelections) { - s.paint(mGCWrapper); + s.paint(mGCWrapper, isMultipleSelection); } drawDropZones(gc); -- cgit v1.1