From 6c3e630b93bf69edb8ff8d29f0a1e9384bc3c701 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Tue, 12 Jul 2011 10:59:59 -0700 Subject: [PATCH] Describe GridLayout matches in drag tooltip This CL adds a description of the current best match (horizontal and vertical) in a drag tooltip, such as "Insert into bottom of row 5" or "Align right at x=120". Change-Id: I08d6b158c5e48d1881ec946037389609d8be9d83 --- .../ide/common/layout/grid/GridDropHandler.java | 14 ++++++ .../android/ide/common/layout/grid/GridMatch.java | 52 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridDropHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridDropHandler.java index 3093f1742..75e69d929 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridDropHandler.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridDropHandler.java @@ -154,6 +154,20 @@ public class GridDropHandler { mColumnMatch = columnMatches.size() > 0 ? columnMatches.get(0) : null; mRowMatch = rowMatches.size() > 0 ? rowMatches.get(0) : null; + String columnDescription = mColumnMatch != null ? mColumnMatch.getDisplayName() : null; + String rowDescription = mRowMatch != null ? mRowMatch.getDisplayName() : null; + if (columnDescription != null) { + if (rowDescription != null) { + feedback.tooltip = columnDescription + '\n' + rowDescription; + } else { + feedback.tooltip = columnDescription; + } + } else if (rowDescription != null) { + feedback.tooltip = rowDescription; + } else { + feedback.tooltip = null; + } + feedback.invalidTarget = mColumnMatch == null || mRowMatch == null; } else { // Find which cell we're inside. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridMatch.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridMatch.java index ce9fdc809..bf1981e2a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridMatch.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/grid/GridMatch.java @@ -15,6 +15,8 @@ */ package com.android.ide.common.layout.grid; +import static com.android.ide.common.layout.grid.GridModel.UNDEFINED; + import com.android.ide.common.api.SegmentType; /** @@ -76,6 +78,56 @@ class GridMatch implements Comparable { } /** + * Describes the match for the user + * + * @return a short description for the user of the match + */ + public String getDisplayName() { + switch (type) { + case BASELINE: + return String.format("Align baseline in row %1$d", cellIndex); + case CENTER_HORIZONTAL: + return "Center horizontally"; + case LEFT: + if (!createCell) { + return String.format("Insert into column %1$d", cellIndex); + } + if (margin != UNDEFINED) { + if (cellIndex == 0) { + return "Add one margin distance from the left"; + } + return String.format("Add next to column %1$d", cellIndex); + } + return String.format("Align left at x=%1$d", matchedLine); + case RIGHT: + if (!createCell) { + return String.format("Insert right-aligned into column %1$d", cellIndex); + } + return String.format("Align right at x=%1$d", matchedLine); + case TOP: + if (!createCell) { + return String.format("Insert into row %1$d", cellIndex); + } + if (margin != UNDEFINED) { + if (cellIndex == 0) { + return "Add one margin distance from the top"; + } + return String.format("Add below row %1$d", cellIndex); + } + return String.format("Align top at y=%1d", matchedLine); + case BOTTOM: + if (!createCell) { + return String.format("Insert into bottom of row %1$d", cellIndex); + } + return String.format("Align bottom at y=%1d", matchedLine); + case CENTER_VERTICAL: + case UNKNOWN: + default: + return null; + } + } + + /** * Computes the sorting priority of this match, giving baseline matches higher * precedence than centering which in turn is ordered before external edge matches */ -- 2.11.0