* An {@link IViewRule} for android.widget.AbsoluteLayout and all its derived
* classes.
*/
-public class AbsoluteLayoutRule extends BaseLayout {
+public class AbsoluteLayoutRule extends BaseLayoutRule {
// ==== Drag'n'drop support ====
// The AbsoluteLayout accepts any drag'n'drop anywhere on its surface.
import java.util.Map;
import java.util.Set;
-public class BaseLayout extends BaseView {
+public class BaseLayoutRule extends BaseViewRule {
@Override
public boolean onInitialize(String fqcn, IClientRulesEngine engine) {
}
/**
- * For use by {@link BaseLayout#addAttributes} A filter should return a
+ * For use by {@link BaseLayoutRule#addAttributes} A filter should return a
* valid replacement string.
*/
public static interface AttributeFilter {
/**
* Common IViewRule processing to all view and layout classes.
*/
-public class BaseView implements IViewRule {
+public class BaseViewRule implements IViewRule {
protected IClientRulesEngine mRulesEngine;
// Cache of attributes. Key is FQCN of a node mixed with its view hierarchy
String parentFqcn = parent.getFqcn();
IViewRule parentRule = mRulesEngine.loadRule(parentFqcn);
- if (parentRule instanceof BaseLayout) {
- ((BaseLayout) parentRule).onPasteBeforeChild(parent, targetNode, elements);
+ if (parentRule instanceof BaseLayoutRule) {
+ ((BaseLayoutRule) parentRule).onPasteBeforeChild(parent, targetNode, elements);
}
}
}
/**
* An {@link IViewRule} for android.widget.DialerFilterRule.
*/
-public class DialerFilterRule extends BaseView {
+public class DialerFilterRule extends BaseViewRule {
@Override
public void onCreate(INode node, INode parent, InsertType insertType) {
* An {@link IViewRule} for android.widget.FrameLayout and all its derived
* classes.
*/
-public class FrameLayoutRule extends BaseLayout {
+public class FrameLayoutRule extends BaseLayoutRule {
// ==== Drag'n'drop support ====
// The FrameLayout accepts any drag'n'drop anywhere on its surface.
/**
* An {@link IViewRule} for android.widget.HorizontalScrollView.
*/
-public class HorizontalScrollViewRule extends BaseView {
+public class HorizontalScrollViewRule extends BaseViewRule {
@Override
public void onChildInserted(INode child, INode parent, InsertType insertType) {
* LinearLayout even though it extends it. Our ZoomControls rule is therefore a
* subclass of this {@link IgnoredLayoutRule} class.
*/
-public abstract class IgnoredLayoutRule extends BaseLayout {
+public abstract class IgnoredLayoutRule extends BaseLayoutRule {
@Override
public DropFeedback onDropEnter(INode targetNode, IDragElement[] elements) {
// Do nothing; this layout rule corresponds to a layout that
/**
* An {@link IViewRule} for android.widget.ImageButtonRule.
*/
-public class ImageButtonRule extends BaseView {
+public class ImageButtonRule extends BaseViewRule {
@Override
public void onCreate(INode node, INode parent, InsertType insertType) {
/**
* An {@link IViewRule} for android.widget.ImageViewRule.
*/
-public class ImageViewRule extends BaseView {
+public class ImageViewRule extends BaseViewRule {
@Override
public void onCreate(INode node, INode parent, InsertType insertType) {
* An {@link IViewRule} for android.widget.LinearLayout and all its derived
* classes.
*/
-public class LinearLayoutRule extends BaseLayout {
+public class LinearLayoutRule extends BaseLayoutRule {
/**
* Add an explicit Orientation toggle to the context menu.
*/
* This is the "root" rule, that is used whenever there is not more specific
* rule to apply.
*/
-public class ListViewRule extends BaseView {
+public class ListViewRule extends BaseViewRule {
@Override
public void onCreate(INode node, INode parent, InsertType insertType) {
* TODO: This class should be pulled out of the ADT and bundled with the add ons
* (not the core jar but an optional tool jar)
*/
-public class MapViewRule extends BaseView {
+public class MapViewRule extends BaseViewRule {
@Override
public void onCreate(INode node, INode parent, InsertType insertType) {
* An {@link IViewRule} for android.widget.RelativeLayout and all its derived
* classes.
*/
-public class RelativeLayoutRule extends BaseLayout {
+public class RelativeLayoutRule extends BaseLayoutRule {
// ==== Selection ====
/**
* An {@link IViewRule} for android.widget.ScrollView.
*/
-public class ScrollViewRule extends BaseView {
+public class ScrollViewRule extends BaseViewRule {
@Override
public void onChildInserted(INode child, INode parent, InsertType insertType) {
/**
* An {@link IViewRule} for android.widget.SeekBar
*/
-public class SeekBarRule extends BaseView {
+public class SeekBarRule extends BaseViewRule {
@Override
public void onCreate(INode node, INode parent, InsertType insertType) {
* There is no customization here, everything that is common to all views is
* simply implemented in BaseView.
*/
-public class ViewRule extends BaseView {
+public class ViewRule extends BaseViewRule {
}
import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors;
import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart;
-import com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage2;
-import com.android.ide.eclipse.adt.internal.editors.layout.gle2.PropertySheetPage2;
+import com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage;
+import com.android.ide.eclipse.adt.internal.editors.layout.gle2.PropertySheetPage;
import com.android.ide.eclipse.adt.internal.editors.layout.gre.RulesEngine;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
if (IContentOutlinePage.class == adapter && mGraphicalEditor != null) {
if (mOutline == null && mGraphicalEditor != null) {
- mOutline = new OutlinePage2(mGraphicalEditor);
+ mOutline = new OutlinePage(mGraphicalEditor);
}
return mOutline;
if (IPropertySheetPage.class == adapter && mGraphicalEditor != null) {
if (mPropertyPage == null) {
- mPropertyPage = new PropertySheetPage2();
+ mPropertyPage = new PropertySheetPage();
}
return mPropertyPage;
* Helper class to convert between control pixel coordinates and canvas coordinates.
* Takes care of the zooming and offset of the canvas.
*/
-public class ScaleInfo implements ICanvasTransform {
+public class CanvasTransform implements ICanvasTransform {
/**
* The canvas which controls the zooming.
*/
/** Scrollbar widget. */
private ScrollBar mScrollbar;
- public ScaleInfo(LayoutCanvas layoutCanvas, ScrollBar scrollbar) {
+ public CanvasTransform(LayoutCanvas layoutCanvas, ScrollBar scrollbar) {
mCanvas = layoutCanvas;
mScrollbar = scrollbar;
mScale = 1.0;
public void widgetSelected(SelectionEvent e) {
// User requested scrolling. Changes translation and redraw canvas.
mTranslate = mScrollbar.getSelection();
- ScaleInfo.this.mCanvas.redraw();
+ CanvasTransform.this.mCanvas.redraw();
}
});
}
* <b>this should be a copy already - this method will not make a
* copy</b>
*/
- public void copySelectionToClipboard(List<CanvasSelection> selection) {
+ public void copySelectionToClipboard(List<SelectionItem> selection) {
SelectionManager.sanitize(selection);
if (selection.isEmpty()) {
}
Object[] data = new Object[] {
- CanvasSelection.getAsElements(selection),
- CanvasSelection.getAsText(mCanvas, selection)
+ SelectionItem.getAsElements(selection),
+ SelectionItem.getAsText(mCanvas, selection)
};
Transfer[] types = new Transfer[] {
* <b>this should be a copy already - this method will not make a
* copy</b>
*/
- public void cutSelectionToClipboard(List<CanvasSelection> selection) {
+ public void cutSelectionToClipboard(List<SelectionItem> selection) {
copySelectionToClipboard(selection);
deleteSelection(
mCanvas.getCutLabel(),
* case nothing happens. The selection list will be sanitized so
* the caller should pass in a copy.
*/
- public void deleteSelection(String verb, final List<CanvasSelection> selection) {
+ public void deleteSelection(String verb, final List<SelectionItem> selection) {
SelectionManager.sanitize(selection);
if (selection.isEmpty()) {
// If all selected items have the same *kind* of parent, display that in the undo title.
String title = null;
- for (CanvasSelection cs : selection) {
+ for (SelectionItem cs : selection) {
CanvasViewInfo vi = cs.getViewInfo();
if (vi != null && vi.getParent() != null) {
if (title == null) {
// resetting the selection.
mCanvas.getLayoutEditor().wrapUndoEditXmlModel(title, new Runnable() {
public void run() {
- for (CanvasSelection cs : selection) {
+ for (SelectionItem cs : selection) {
CanvasViewInfo vi = cs.getViewInfo();
// You can't delete the root element
if (vi != null && !vi.isRoot()) {
* <b>this should be a copy already - this method will not make a
* copy</b>
*/
- public void pasteSelection(List<CanvasSelection> selection) {
+ public void pasteSelection(List<SelectionItem> selection) {
SimpleXmlTransfer sxt = SimpleXmlTransfer.getInstance();
SimpleElement[] pasted = (SimpleElement[]) mClipboard.getContents(sxt);
SelectionManager.sanitize(selection);
CanvasViewInfo target = lastRoot;
if (selection.size() > 0) {
- CanvasSelection cs = selection.get(0);
+ SelectionItem cs = selection.get(0);
target = cs.getViewInfo();
}
* This class is tied to a specific {@link LayoutCanvas} instance and a root {@link MenuManager}.
* <p/>
* Two instances of this are used: one created by {@link LayoutCanvas} and the other one
- * created by {@link OutlinePage2}. Different root {@link MenuManager}s are populated, however
+ * created by {@link OutlinePage}. Different root {@link MenuManager}s are populated, however
* they are both linked to the current selection state of the {@link LayoutCanvas}.
*/
/* package */ class DynamicContextMenu {
* @param canvas The {@link LayoutCanvas} providing the selection, the node factory and
* the rules engine.
* @param rootMenu The root of the context menu displayed. In practice this may be the
- * context menu manager of the {@link LayoutCanvas} or the one from {@link OutlinePage2}.
+ * context menu manager of the {@link LayoutCanvas} or the one from {@link OutlinePage}.
*/
public DynamicContextMenu(LayoutEditor editor, LayoutCanvas canvas, MenuManager rootMenu) {
mEditor = editor;
final TreeMap<String, ArrayList<MenuAction>> outActionsMap,
final TreeMap<String, MenuAction.Group> outGroupsMap) {
int maxMenuSelection = 0;
- for (CanvasSelection selection : mCanvas.getSelectionManager().getSelections()) {
+ for (SelectionItem selection : mCanvas.getSelectionManager().getSelections()) {
List<MenuAction> viewActions = null;
if (selection != null) {
CanvasViewInfo vi = selection.getViewInfo();
private Color mBorderColor;
/** Vertical scaling & scrollbar information. */
- private ScaleInfo mVScale;
+ private CanvasTransform mVScale;
/** Horizontal scaling & scrollbar information. */
- private ScaleInfo mHScale;
+ private CanvasTransform mHScale;
/**
* Constructs a new {@link EmptyViewsOverlay} linked to the given view hierarchy.
*
* @param viewHierarchy The {@link ViewHierarchy} to render.
- * @param hScale The {@link ScaleInfo} to use to transfer horizontal layout
+ * @param hScale The {@link CanvasTransform} to use to transfer horizontal layout
* coordinates to screen coordinates.
- * @param vScale The {@link ScaleInfo} to use to transfer vertical layout coordinates
+ * @param vScale The {@link CanvasTransform} to use to transfer vertical layout coordinates
* to screen coordinates.
*/
- public EmptyViewsOverlay(ViewHierarchy viewHierarchy, ScaleInfo hScale, ScaleInfo vScale) {
+ public EmptyViewsOverlay(
+ ViewHierarchy viewHierarchy,
+ CanvasTransform hScale,
+ CanvasTransform vScale) {
super();
this.mViewHierarchy = viewHierarchy;
this.mHScale = hScale;
* canvas selection due to the "sanitize" pass. Can be empty but never
* null.
*/
- private final ArrayList<CanvasSelection> mDragSelection = new ArrayList<CanvasSelection>();
+ private final ArrayList<SelectionItem> mDragSelection = new ArrayList<SelectionItem>();
private SimpleElement[] mDragElements;
// element, *change* the selection to match the element under the
// cursor and use that. If nothing can be selected, abort the drag
// operation.
- List<CanvasSelection> selections = mCanvas.getSelectionManager().getSelections();
+ List<SelectionItem> selections = mCanvas.getSelectionManager().getSelections();
mDragSelection.clear();
if (!selections.isEmpty()) {
// Is the cursor on top of a selected element?
boolean insideSelection = false;
- for (CanvasSelection cs : selections) {
+ for (SelectionItem cs : selections) {
if (!cs.isRoot() && cs.getRect().contains(p.x, p.y)) {
insideSelection = true;
break;
mDragSelection.addAll(selections);
} else {
// Only drag non-root items.
- for (CanvasSelection cs : selections) {
+ for (SelectionItem cs : selections) {
if (!cs.isRoot()) {
mDragSelection.add(cs);
}
e.doit = !mDragSelection.isEmpty();
int imageCount = mDragSelection.size();
if (e.doit) {
- mDragElements = CanvasSelection.getAsElements(mDragSelection);
+ mDragElements = SelectionItem.getAsElements(mDragSelection);
GlobalCanvasDragInfo.getInstance().startDrag(mDragElements,
- mDragSelection.toArray(new CanvasSelection[imageCount]),
+ mDragSelection.toArray(new SelectionItem[imageCount]),
mCanvas, new Runnable() {
public void run() {
mCanvas.getClipboardSupport().deleteSelection("Remove",
if (imageCount > 0) {
ImageData data = image.getImageData();
Rectangle imageRectangle = new Rectangle(0, 0, data.width, data.height);
- for (CanvasSelection item : mDragSelection) {
+ for (SelectionItem item : mDragSelection) {
Rectangle bounds = item.getRect();
// Some bounds can be outside the rendered rectangle (for
// example, in an absolute layout, you can have negative
*/
public void dragSetData(DragSourceEvent e) {
if (TextTransfer.getInstance().isSupportedType(e.dataType)) {
- e.data = CanvasSelection.getAsText(mCanvas, mDragSelection);
+ e.data = SelectionItem.getAsText(mCanvas, mDragSelection);
return;
}
private static final GlobalCanvasDragInfo sInstance = new GlobalCanvasDragInfo();
private SimpleElement[] mCurrentElements = null;
- private CanvasSelection[] mCurrentSelection;
+ private SelectionItem[] mCurrentSelection;
private Object mSourceCanvas = null;
private Runnable mRemoveSourceHandler;
* source. It should only be invoked if the drag operation is a
* move, not a copy.
*/
- public void startDrag(SimpleElement[] elements, CanvasSelection[] selection,
+ public void startDrag(SimpleElement[] elements, SelectionItem[] selection,
Object sourceCanvas, Runnable removeSourceHandler) {
mCurrentElements = elements;
mCurrentSelection = selection;
/** Returns the selection originally dragged.
* Can be null if the drag did not start in a canvas.
*/
- public CanvasSelection[] getCurrentSelection() {
+ public SelectionItem[] getCurrentSelection() {
return mCurrentSelection;
}
/**
- * Returns the object that call {@link #startDrag(SimpleElement[], CanvasSelection[], Object)}.
+ * Returns the object that call {@link #startDrag(SimpleElement[], SelectionItem[], Object)}.
* Can be null.
* This is not meant to access the object indirectly, it is just meant to compare if the
* source and the destination of the drag'n'drop are the same, so object identity
private Color mHoverFillColor;
/** Vertical scaling & scrollbar information. */
- private ScaleInfo mVScale;
+ private CanvasTransform mVScale;
/** Horizontal scaling & scrollbar information. */
- private ScaleInfo mHScale;
+ private CanvasTransform mHScale;
/**
* Current mouse hover border rectangle. Null when there's no mouse hover.
/**
* Constructs a new {@link HoverOverlay} linked to the given view hierarchy.
*
- * @param hScale The {@link ScaleInfo} to use to transfer horizontal layout
+ * @param hScale The {@link CanvasTransform} to use to transfer horizontal layout
* coordinates to screen coordinates.
- * @param vScale The {@link ScaleInfo} to use to transfer vertical layout
+ * @param vScale The {@link CanvasTransform} to use to transfer vertical layout
* coordinates to screen coordinates.
*/
- public HoverOverlay(ScaleInfo hScale, ScaleInfo vScale) {
+ public HoverOverlay(CanvasTransform hScale, CanvasTransform vScale) {
super();
this.mHScale = hScale;
this.mVScale = vScale;
private LayoutCanvas mCanvas;
/** Vertical scaling & scrollbar information. */
- private ScaleInfo mVScale;
+ private CanvasTransform mVScale;
/** Horizontal scaling & scrollbar information. */
- private ScaleInfo mHScale;
+ private CanvasTransform mHScale;
/**
* Constructs an {@link ImageOverlay} tied to the given canvas.
* @param hScale The horizontal scale information.
* @param vScale The vertical scale information.
*/
- public ImageOverlay(LayoutCanvas canvas, ScaleInfo hScale, ScaleInfo vScale) {
+ public ImageOverlay(LayoutCanvas canvas, CanvasTransform hScale, CanvasTransform vScale) {
this.mCanvas = canvas;
this.mHScale = hScale;
this.mVScale = vScale;
gc_setAlpha(gc, 128); // half-transparent
}
- ScaleInfo hi = mHScale;
- ScaleInfo vi = mVScale;
+ CanvasTransform hi = mHScale;
+ CanvasTransform vi = mVScale;
// we only anti-alias when reducing the image size.
int oldAlias = -2;
private final NodeFactory mNodeFactory = new NodeFactory();
/** Vertical scaling & scrollbar information. */
- private ScaleInfo mVScale;
+ private CanvasTransform mVScale;
/** Horizontal scaling & scrollbar information. */
- private ScaleInfo mHScale;
+ private CanvasTransform mHScale;
/** Drag source associated with this canvas. */
private DragSource mDragSource;
* when page's widget is already disposed.
* Added the DisposeListener to OutlinePage2 in order to correctly dispose this page.
**/
- private OutlinePage2 mOutlinePage;
+ private OutlinePage mOutlinePage;
/** Delete action for the Edit or context menu. */
private Action mDeleteAction;
mRulesEngine = rulesEngine;
mClipboardSupport = new ClipboardSupport(this, parent);
- mHScale = new ScaleInfo(this, getHorizontalBar());
- mVScale = new ScaleInfo(this, getVerticalBar());
+ mHScale = new CanvasTransform(this, getHorizontalBar());
+ mVScale = new CanvasTransform(this, getVerticalBar());
mGCWrapper = new GCWrapper(mHScale, mVScale);
// --- setup outline ---
// Get the outline associated with this editor, if any and of the right type.
Object outline = layoutEditor.getAdapter(IContentOutlinePage.class);
- if (outline instanceof OutlinePage2) {
- mOutlinePage = (OutlinePage2) outline;
+ if (outline instanceof OutlinePage) {
+ mOutlinePage = (OutlinePage) outline;
}
}
/**
* Returns our {@link DragSourceListener}.
- * This is used by {@link OutlinePage2} to delegate drag source events.
+ * This is used by {@link OutlinePage} to delegate drag source events.
*/
/* package */ DragSourceListener getDragListener() {
return mGestureManager.getDragSourceListener();
/**
* Returns our {@link DropTargetListener}.
- * This is used by {@link OutlinePage2} to delegate drop target events.
+ * This is used by {@link OutlinePage} to delegate drop target events.
*/
/* package */ DropTargetListener getDropListener() {
return mGestureManager.getDropTargetListener();
}
/**
- * Returns the horizontal {@link ScaleInfo} transform object, which can map
+ * Returns the horizontal {@link CanvasTransform} transform object, which can map
* a layout point into a control point.
*
- * @return A {@link ScaleInfo} for mapping between layout and control
+ * @return A {@link CanvasTransform} for mapping between layout and control
* coordinates in the horizontal dimension.
*/
- /* package */ ScaleInfo getHorizontalTransform() {
+ /* package */ CanvasTransform getHorizontalTransform() {
return mHScale;
}
/**
- * Returns the vertical {@link ScaleInfo} transform object, which can map a
+ * Returns the vertical {@link CanvasTransform} transform object, which can map a
* layout point into a control point.
*
- * @return A {@link ScaleInfo} for mapping between layout and control
+ * @return A {@link CanvasTransform} for mapping between layout and control
* coordinates in the vertical dimension.
*/
- /* package */ ScaleInfo getVerticalTransform() {
+ /* package */ CanvasTransform getVerticalTransform() {
return mVScale;
}
// see if any of the selected items are among the invisible nodes, and if so
// add them to a lazily constructed set which we pass back for rendering.
Set<UiElementNode> result = null;
- List<CanvasSelection> selections = mSelectionManager.getSelections();
+ List<SelectionItem> selections = mSelectionManager.getSelections();
if (selections.size() > 0) {
List<CanvasViewInfo> invisibleParents = mViewHierarchy.getInvisibleViews();
if (invisibleParents.size() > 0) {
- for (CanvasSelection item : selections) {
+ for (SelectionItem item : selections) {
CanvasViewInfo viewInfo = item.getViewInfo();
// O(n^2) here, but both the selection size and especially the
// invisibleParents size are expected to be small
/**
* Helper to create the drag source for the given control.
* <p/>
- * This is static with package-access so that {@link OutlinePage2} can also
+ * This is static with package-access so that {@link OutlinePage} can also
* create an exact copy of the source with the same attributes.
*/
/* package */static DragSource createDragSource(Control control) {
/**
* Helper to create the drop target for the given control.
* <p/>
- * This is static with package-access so that {@link OutlinePage2} can also
+ * This is static with package-access so that {@link OutlinePage} can also
* create an exact copy of the drop target with the same attributes.
*/
/* package */static DropTarget createDropTarget(Control control) {
manager.add(new Action("Run My Test", IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
- List<CanvasSelection> selection = mSelectionManager.getSelections();
- CanvasSelection canvasSelection = selection.get(0);
+ List<SelectionItem> selection = mSelectionManager.getSelections();
+ SelectionItem canvasSelection = selection.get(0);
CanvasViewInfo info = canvasSelection.getViewInfo();
Object viewObject = info.getViewObject();
this.mCanvas = canvas;
if (toggle) {
- List<CanvasSelection> selection = canvas.getSelectionManager().getSelections();
+ List<SelectionItem> selection = canvas.getSelectionManager().getSelections();
mInitialSelection = new ArrayList<CanvasViewInfo>(selection.size());
- for (CanvasSelection item : selection) {
+ for (SelectionItem item : selection) {
mInitialSelection.add(item.getViewInfo());
}
} else {
// layout itself: a copy would be ok but not a move operation of the
// layout into himself.
- CanvasSelection[] selection = mGlobalDragInfo.getCurrentSelection();
+ SelectionItem[] selection = mGlobalDragInfo.getCurrentSelection();
if (selection != null) {
- for (CanvasSelection cs : selection) {
+ for (SelectionItem cs : selection) {
if (cs.getViewInfo() == targetVi) {
// The node that responded is one of the selection roots.
// Simply invalidate the drop feedback and move on the
private Color mOutlineColor;
/** Vertical scaling & scrollbar information. */
- private ScaleInfo mVScale;
+ private CanvasTransform mVScale;
/** Horizontal scaling & scrollbar information. */
- private ScaleInfo mHScale;
+ private CanvasTransform mHScale;
/**
* Constructs a new {@link OutlineOverlay} linked to the given view
* hierarchy.
*
* @param viewHierarchy The {@link ViewHierarchy} to render
- * @param hScale The {@link ScaleInfo} to use to transfer horizontal layout
+ * @param hScale The {@link CanvasTransform} to use to transfer horizontal layout
* coordinates to screen coordinates
- * @param vScale The {@link ScaleInfo} to use to transfer vertical layout
+ * @param vScale The {@link CanvasTransform} to use to transfer vertical layout
* coordinates to screen coordinates
*/
- public OutlineOverlay(ViewHierarchy viewHierarchy, ScaleInfo hScale, ScaleInfo vScale) {
+ public OutlineOverlay(
+ ViewHierarchy viewHierarchy,
+ CanvasTransform hScale,
+ CanvasTransform vScale) {
super();
this.mViewHierarchy = viewHierarchy;
this.mHScale = hScale;
*
* @since GLE2
*/
-public class OutlinePage2 extends ContentOutlinePage
+public class OutlinePage extends ContentOutlinePage
implements ISelectionListener, INullSelectionListener {
/**
*/
private DropTarget mDropTarget;
- public OutlinePage2(GraphicalEditorPart graphicalEditorPart) {
+ public OutlinePage(GraphicalEditorPart graphicalEditorPart) {
super();
mGraphicalEditorPart = graphicalEditorPart;
}
AndroidTargetData data = layoutEditor.getTargetData();
DocumentDescriptor documentDescriptor;
if (data == null) {
- documentDescriptor = new DocumentDescriptor("temp", null /*children*/); //$NON-NLS-1$
+ documentDescriptor = new DocumentDescriptor("temp", null/*children*/);//$NON-NLS-1$
} else {
documentDescriptor = data.getLayoutDescriptors().getDescriptor();
}
&& !ImageUtils.containsDarkPixels(cropped);
cropped = ImageUtils.createDropShadow(cropped,
hasTransparency ? 3 : 5 /* shadowSize */,
- !hasTransparency ? 0.6f : needsContrast ? 0.8f : 0.7f /* alpha */,
+ !hasTransparency ? 0.6f : needsContrast ? 0.8f : 0.7f/*alpha*/,
0x000000 /* shadowRgb */);
Display display = getControl().getDisplay();
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.views.properties.PropertySheetEntry;
-import org.eclipse.ui.views.properties.PropertySheetPage;
/**
* A customized property sheet page for the graphical layout editor v2.
*
* @since GLE2
*/
-public class PropertySheetPage2 extends PropertySheetPage {
+public class PropertySheetPage extends org.eclipse.ui.views.properties.PropertySheetPage {
- public PropertySheetPage2() {
+ public PropertySheetPage() {
super();
}
/**
* Represents one selection in {@link LayoutCanvas}.
*/
-/* package */ class CanvasSelection {
+/* package */ class SelectionItem {
/** Current selected view info. Can be null. */
private final CanvasViewInfo mCanvasViewInfo;
private final String mName;
/**
- * Creates a new {@link CanvasSelection} object.
+ * Creates a new {@link SelectionItem} object.
* @param canvasViewInfo The view info being selected. Must not be null.
* @param gre the rules engine
* @param nodeFactory the node factory
*/
- public CanvasSelection(CanvasViewInfo canvasViewInfo,
+ public SelectionItem(CanvasViewInfo canvasViewInfo,
RulesEngine gre,
NodeFactory nodeFactory) {
* Gets the XML text from the given selection for a text transfer.
* The returned string can be empty but not null.
*/
- /* package */ static String getAsText(LayoutCanvas canvas, List<CanvasSelection> selection) {
+ /* package */ static String getAsText(LayoutCanvas canvas, List<SelectionItem> selection) {
StringBuilder sb = new StringBuilder();
LayoutEditor layoutEditor = canvas.getLayoutEditor();
- for (CanvasSelection cs : selection) {
+ for (SelectionItem cs : selection) {
CanvasViewInfo vi = cs.getViewInfo();
UiViewElementNode key = vi.getUiViewNode();
Node node = key.getXmlNode();
* @param items Items to wrap in elements
* @return An array of wrapper elements. Never null.
*/
- /* package */ static SimpleElement[] getAsElements(List<CanvasSelection> items) {
+ /* package */ static SimpleElement[] getAsElements(List<SelectionItem> items) {
ArrayList<SimpleElement> elements = new ArrayList<SimpleElement>();
- for (CanvasSelection cs : items) {
+ for (SelectionItem cs : items) {
CanvasViewInfo vi = cs.getViewInfo();
SimpleElement e = vi.toSimpleElement();
private LayoutCanvas mCanvas;
/** The current selection list. The list is never null, however it can be empty. */
- private final LinkedList<CanvasSelection> mSelections = new LinkedList<CanvasSelection>();
+ private final LinkedList<SelectionItem> mSelections = new LinkedList<SelectionItem>();
/** An unmodifiable view of {@link #mSelections}. */
- private final List<CanvasSelection> mUnmodifiableSelection =
+ private final List<SelectionItem> mUnmodifiableSelection =
Collections.unmodifiableList(mSelections);
/** Barrier set when updating the selection to prevent from recursively
}
/**
- * Returns the native {@link CanvasSelection} list.
+ * Returns the native {@link SelectionItem} list.
*
- * @return An immutable list of {@link CanvasSelection}. Can be empty but not null.
+ * @return An immutable list of {@link SelectionItem}. Can be empty but not null.
* @see #getSelection() {@link #getSelection()} to retrieve a {@link TreeViewer}
* compatible {@link ISelection}.
*/
- /* package */ List<CanvasSelection> getSelections() {
+ /* package */ List<SelectionItem> getSelections() {
return mUnmodifiableSelection;
}
*
* @return A copy of the current selection. Never null.
*/
- /* package */ List<CanvasSelection> getSnapshot() {
- return new ArrayList<CanvasSelection>(mSelections);
+ /* package */ List<SelectionItem> getSnapshot() {
+ return new ArrayList<SelectionItem>(mSelections);
}
/**
ArrayList<TreePath> paths = new ArrayList<TreePath>();
- for (CanvasSelection cs : mSelections) {
+ for (SelectionItem cs : mSelections) {
CanvasViewInfo vi = cs.getViewInfo();
if (vi != null) {
ArrayList<Object> segments = new ArrayList<Object>();
// Create a list of all currently selected view infos
Set<CanvasViewInfo> oldSelected = new HashSet<CanvasViewInfo>();
- for (CanvasSelection cs : mSelections) {
+ for (SelectionItem cs : mSelections) {
oldSelected.add(cs.getViewInfo());
}
// Otherwise we select the item under the cursor.
if (!isCycleClick && !isMultiClick) {
- for (CanvasSelection cs : mSelections) {
+ for (SelectionItem cs : mSelections) {
if (cs.getRect().contains(p.x, p.y)) {
// The cursor is inside the selection. Don't change anything.
return;
/** Returns true if the view hierarchy is showing exploded items. */
private boolean hasExplodedItems() {
- for (CanvasSelection item : mSelections) {
+ for (SelectionItem item : mSelections) {
if (item.getViewInfo().isExploded()) {
return true;
}
return false;
}
- for (ListIterator<CanvasSelection> it = mSelections.listIterator(); it.hasNext(); ) {
- CanvasSelection s = it.next();
+ for (ListIterator<SelectionItem> it = mSelections.listIterator(); it.hasNext(); ) {
+ SelectionItem s = it.next();
if (canvasViewInfo == s.getViewInfo()) {
it.remove();
return true;
* Callers are responsible for calling redraw() and updateOulineSelection() after.
*/
private void deselectAll(List<CanvasViewInfo> canvasViewInfos) {
- for (ListIterator<CanvasSelection> it = mSelections.listIterator(); it.hasNext(); ) {
- CanvasSelection s = it.next();
+ for (ListIterator<SelectionItem> it = mSelections.listIterator(); it.hasNext(); ) {
+ SelectionItem s = it.next();
if (canvasViewInfos.contains(s.getViewInfo())) {
it.remove();
}
/* package */ void sync(CanvasViewInfo lastValidViewInfoRoot) {
// Check if the selection is still the same (based on the object keys)
// and eventually recompute their bounds.
- for (ListIterator<CanvasSelection> it = mSelections.listIterator(); it.hasNext(); ) {
- CanvasSelection s = it.next();
+ for (ListIterator<SelectionItem> it = mSelections.listIterator(); it.hasNext(); ) {
+ SelectionItem s = it.next();
// Check if the selected object still exists
ViewHierarchy viewHierarchy = mCanvas.getViewHierarchy();
* given list is going to be altered and we should never alter the user-made selection.
* Instead the caller should provide its own copy.
*/
- /* package */ static void sanitize(List<CanvasSelection> selection) {
+ /* package */ static void sanitize(List<SelectionItem> selection) {
if (selection.isEmpty()) {
return;
}
- for (Iterator<CanvasSelection> it = selection.iterator(); it.hasNext(); ) {
- CanvasSelection cs = it.next();
+ for (Iterator<SelectionItem> it = selection.iterator(); it.hasNext(); ) {
+ SelectionItem cs = it.next();
CanvasViewInfo vi = cs.getViewInfo();
UiViewElementNode key = vi == null ? null : vi.getUiViewNode();
Node node = key == null ? null : key.getXmlNode();
}
if (vi != null) {
- for (Iterator<CanvasSelection> it2 = selection.iterator();
+ for (Iterator<SelectionItem> it2 = selection.iterator();
it2.hasNext(); ) {
- CanvasSelection cs2 = it2.next();
+ SelectionItem cs2 = it2.next();
if (cs != cs2) {
CanvasViewInfo vi2 = cs2.getViewInfo();
if (vi.isParent(vi2)) {
mCanvas.redraw();
}
- private CanvasSelection createSelection(CanvasViewInfo vi) {
- return new CanvasSelection(vi, mCanvas.getRulesEngine(),
+ private SelectionItem createSelection(CanvasViewInfo vi) {
+ return new SelectionItem(vi, mCanvas.getRulesEngine(),
mCanvas.getNodeFactory());
}
}
*/
public void paint(SelectionManager selectionManager, GCWrapper gcWrapper,
RulesEngine rulesEngine) {
- List<CanvasSelection> selections = selectionManager.getSelections();
+ List<SelectionItem> selections = selectionManager.getSelections();
int n = selections.size();
if (n > 0) {
boolean isMultipleSelection = n > 1;
- for (CanvasSelection s : selections) {
+ for (SelectionItem s : selections) {
if (s.isRoot()) {
// The root selection is never painted
continue;
import com.android.ide.common.api.IDragElement;
import com.android.ide.common.api.INode;
import com.android.ide.common.api.Rect;
-import com.android.ide.common.layout.BaseLayout.AttributeFilter;
+import com.android.ide.common.layout.BaseLayoutRule.AttributeFilter;
import java.util.Arrays;
import java.util.HashMap;
// TODO: Check equals() but not == strings by using new String("") to prevent interning
// TODO: Rename BaseLayout to BaseLayoutRule, and tests too of course
-public class BaseLayoutTest extends LayoutTestBase {
+public class BaseLayoutRuleTest extends LayoutTestBase {
/** Provides test data used by other test cases */
private IDragElement[] createSampleElements() {
return elements;
}
- /** Test {@link BaseLayout#collectIds}: Check that basic lookup of id works */
+ /** Test {@link BaseLayoutRule#collectIds}: Check that basic lookup of id works */
public final void testCollectIds1() {
IDragElement[] elements = TestDragElement.create(TestDragElement.create(
"android.widget.Button", new Rect(0, 0, 100, 80)).id("@+id/Button01"));
Map<String, Pair<String, String>> idMap = new HashMap<String, Pair<String, String>>();
- Map<String, Pair<String, String>> ids = new BaseLayout().collectIds(idMap, elements);
+ Map<String, Pair<String, String>> ids = new BaseLayoutRule().collectIds(idMap, elements);
assertEquals(1, ids.size());
assertEquals("@+id/Button01", ids.keySet().iterator().next());
}
/**
- * Test {@link BaseLayout#collectIds}: Check that with the wrong URI we
+ * Test {@link BaseLayoutRule#collectIds}: Check that with the wrong URI we
* don't pick up the ID
*/
public final void testCollectIds2() {
"@+id/Button01"));
Map<String, Pair<String, String>> idMap = new HashMap<String, Pair<String, String>>();
- Map<String, Pair<String, String>> ids = new BaseLayout().collectIds(idMap, elements);
+ Map<String, Pair<String, String>> ids = new BaseLayoutRule().collectIds(idMap, elements);
assertEquals(0, ids.size());
}
/**
- * Test {@link BaseLayout#normalizeId(String)}
+ * Test {@link BaseLayoutRule#normalizeId(String)}
*/
public final void testNormalizeId() {
- assertEquals("foo", new BaseLayout().normalizeId("foo"));
- assertEquals("@+id/name", new BaseLayout().normalizeId("@id/name"));
- assertEquals("@+id/name", new BaseLayout().normalizeId("@+id/name"));
+ assertEquals("foo", new BaseLayoutRule().normalizeId("foo"));
+ assertEquals("@+id/name", new BaseLayoutRule().normalizeId("@id/name"));
+ assertEquals("@+id/name", new BaseLayoutRule().normalizeId("@+id/name"));
}
/**
- * Test {@link BaseLayout#collectExistingIds}
+ * Test {@link BaseLayoutRule#collectExistingIds}
*/
public final void testCollectExistingIds1() {
Set<String> existing = new HashSet<String>();
INode node = TestNode.create("android.widget.Button").id("@+id/Button012").add(
TestNode.create("android.widget.Button").id("@+id/Button2"));
- new BaseLayout().collectExistingIds(node, existing);
+ new BaseLayoutRule().collectExistingIds(node, existing);
assertEquals(2, existing.size());
assertContainsSame(Arrays.asList("@+id/Button2", "@+id/Button012"), existing);
}
/**
- * Test {@link BaseLayout#collectIds}: Check that with multiple elements and
+ * Test {@link BaseLayoutRule#collectIds}: Check that with multiple elements and
* some children we still pick up all the right id's
*/
public final void testCollectIds3() {
Map<String, Pair<String, String>> idMap = new HashMap<String, Pair<String, String>>();
IDragElement[] elements = createSampleElements();
- Map<String, Pair<String, String>> ids = new BaseLayout().collectIds(idMap, elements);
+ Map<String, Pair<String, String>> ids = new BaseLayoutRule().collectIds(idMap, elements);
assertEquals(5, ids.size());
assertContainsSame(Arrays.asList("@+id/Button01", "@+id/Button02", "@+id/Button011",
"@+id/Button012", "@+id/LinearLayout01"), ids.keySet());
}
/**
- * Test {@link BaseLayout#remapIds}: Ensure that it identifies a conflict
+ * Test {@link BaseLayoutRule#remapIds}: Ensure that it identifies a conflict
*/
public final void testRemapIds1() {
Map<String, Pair<String, String>> idMap = new HashMap<String, Pair<String, String>>();
- BaseLayout baseLayout = new BaseLayout();
+ BaseLayoutRule baseLayout = new BaseLayoutRule();
IDragElement[] elements = createSampleElements();
baseLayout.collectIds(idMap, elements);
INode node = TestNode.create("android.widget.Button").id("@+id/Button012").add(
/**
- * Test {@link BaseLayout#getDropIdMap}
+ * Test {@link BaseLayoutRule#getDropIdMap}
*/
public final void testGetDropIdMap() {
- BaseLayout baseLayout = new BaseLayout();
+ BaseLayoutRule baseLayout = new BaseLayoutRule();
IDragElement[] elements = createSampleElements();
INode node = TestNode.create("android.widget.Button").id("@+id/Button012").add(
TestNode.create("android.widget.Button").id("@+id/Button2"));
}
public final void testAddAttributes1() {
- BaseLayout layout = new BaseLayout();
+ BaseLayoutRule layout = new BaseLayoutRule();
// First try with no filter
IDragElement oldElement = TestDragElement.create("a.w.B").id("@+id/foo");
public final void testAddAttributes2() {
// Test filtering
- BaseLayout layout = new BaseLayout();
+ BaseLayoutRule layout = new BaseLayoutRule();
// First try with no filter
IDragElement oldElement = TestDragElement.create("a.w.B").id("@+id/foo");
}
public final void testFindNewId() {
- BaseLayout baseLayout = new BaseLayout();
+ BaseLayoutRule baseLayout = new BaseLayoutRule();
Set<String> existing = new HashSet<String>();
assertEquals("@+id/Widget01", baseLayout.findNewId("a.w.Widget", existing));
}
public final void testDefaultAttributeFilter() {
- assertEquals("true", BaseLayout.DEFAULT_ATTR_FILTER.replace("myuri", "layout_alignRight",
+ assertEquals("true", BaseLayoutRule.DEFAULT_ATTR_FILTER.replace("myuri", "layout_alignRight",
"true"));
- assertEquals(null, BaseLayout.DEFAULT_ATTR_FILTER.replace(ANDROID_URI,
+ assertEquals(null, BaseLayoutRule.DEFAULT_ATTR_FILTER.replace(ANDROID_URI,
"layout_alignRight", "true"));
- assertEquals("true", BaseLayout.DEFAULT_ATTR_FILTER.replace(ANDROID_URI,
+ assertEquals("true", BaseLayoutRule.DEFAULT_ATTR_FILTER.replace(ANDROID_URI,
"myproperty", "true"));
}
"value2a").set("uri", "childprop2b", "value2b"));
INode newNode = TestNode.create("a.w.B").id("@+id/foo");
Map<String, Pair<String, String>> idMap = new HashMap<String, Pair<String, String>>();
- BaseLayout layout = new BaseLayout();
+ BaseLayoutRule layout = new BaseLayoutRule();
layout.addInnerElements(newNode, oldElement, idMap);
assertEquals(2, newNode.getChildren().length);
import junit.framework.TestCase;
-public class BaseViewTest extends TestCase {
+public class BaseViewRuleTest extends TestCase {
public final void testPrettyName() {
- assertEquals(null, BaseView.prettyName(null));
- assertEquals("", BaseView.prettyName(""));
- assertEquals("Foo", BaseView.prettyName("foo"));
- assertEquals("Foo bar", BaseView.prettyName("foo_bar"));
+ assertEquals(null, BaseViewRule.prettyName(null));
+ assertEquals("", BaseViewRule.prettyName(""));
+ assertEquals("Foo", BaseViewRule.prettyName("foo"));
+ assertEquals("Foo bar", BaseViewRule.prettyName("foo_bar"));
// TODO: We should check this to capitalize each initial word
// assertEquals("Foo Bar", BaseView.prettyName("foo_bar"));
// TODO: We should also handle camelcase properties
}
public final void testJoin() {
- assertEquals("foo", BaseView.join('|', Arrays.asList("foo")));
- assertEquals("", BaseView.join('|', Collections.<String>emptyList()));
- assertEquals("foo,bar", BaseView.join(',', Arrays.asList("foo", "bar")));
- assertEquals("foo|bar", BaseView.join('|', Arrays.asList("foo", "bar")));
+ assertEquals("foo", BaseViewRule.join('|', Arrays.asList("foo")));
+ assertEquals("", BaseViewRule.join('|', Collections.<String>emptyList()));
+ assertEquals("foo,bar", BaseViewRule.join(',', Arrays.asList("foo", "bar")));
+ assertEquals("foo|bar", BaseViewRule.join('|', Arrays.asList("foo", "bar")));
}
}
*/
package com.android.ide.common.layout;
+import static junit.framework.Assert.fail;
+
import com.android.ide.common.api.IAttributeInfo;
/** Test/mock implementation of {@link IAttributeInfo} */
}
public String getDeprecatedDoc() {
- BaseLayoutTest.fail("Not supported yet in tests");
+ fail("Not supported yet in tests");
return null;
}
public String[] getEnumValues() {
- BaseLayoutTest.fail("Not supported yet in tests");
+ fail("Not supported yet in tests");
return null;
}
public String[] getFlagValues() {
- BaseLayoutTest.fail("Not supported yet in tests");
+ fail("Not supported yet in tests");
return null;
}
public Format[] getFormats() {
- BaseLayoutTest.fail("Not supported yet in tests");
+ fail("Not supported yet in tests");
return null;
}
public String getJavaDoc() {
- BaseLayoutTest.fail("Not supported yet in tests");
+ fail("Not supported yet in tests");
return null;
}
}
@Override
- ScaleInfo getHorizontalTransform() {
+ CanvasTransform getHorizontalTransform() {
ScrollBar scrollBar = new List(this, SWT.V_SCROLL|SWT.H_SCROLL).getHorizontalBar();
- return new TestScaleInfo(scrollBar, mScaleX, mTranslateX);
+ return new TestCanvasTransform(scrollBar, mScaleX, mTranslateX);
}
@Override
- ScaleInfo getVerticalTransform() {
+ CanvasTransform getVerticalTransform() {
ScrollBar scrollBar = new List(this, SWT.V_SCROLL|SWT.H_SCROLL).getVerticalBar();
- return new TestScaleInfo(scrollBar, mScaleY, mTranslateY);
+ return new TestCanvasTransform(scrollBar, mScaleY, mTranslateY);
}
}
- static class TestScaleInfo extends ScaleInfo {
+ static class TestCanvasTransform extends CanvasTransform {
float mScale;
float mTranslate;
- public TestScaleInfo(ScrollBar scrollBar, float scale, float translate) {
+ public TestCanvasTransform(ScrollBar scrollBar, float scale, float translate) {
super(null, scrollBar);
this.mScale = scale;
this.mTranslate = translate;