18fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael/* 28fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Copyright (C) 2009 The Android Open Source Project 38fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * 48fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 58fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * you may not use this file except in compliance with the License. 68fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * You may obtain a copy of the License at 78fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * 88fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * http://www.eclipse.org/org/documents/epl-v10.php 98fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * 108fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Unless required by applicable law or agreed to in writing, software 118fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * distributed under the License is distributed on an "AS IS" BASIS, 128fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * See the License for the specific language governing permissions and 148fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * limitations under the License. 158fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael */ 168fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 178fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphaelpackage com.android.ide.eclipse.adt.internal.editors.layout.gle2; 188fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 198fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphaelimport java.util.List; 208fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 218fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael/** 228fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Information for the current alternate selection, i.e. the possible selected items 238fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * that are located at the same x/y as the original view, either sibling or parents. 248fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael */ 258fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael/* package */ class CanvasAlternateSelection { 268fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael private final CanvasViewInfo mOriginatingView; 278fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael private final List<CanvasViewInfo> mAltViews; 288fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael private int mIndex; 298fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 308fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael /** 318fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Creates a new alternate selection based on the given originating view and the 328fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * given list of alternate views. Both cannot be null. 338fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael */ 348fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael public CanvasAlternateSelection(CanvasViewInfo originatingView, List<CanvasViewInfo> altViews) { 358fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael assert originatingView != null; 368fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael assert altViews != null; 378fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael mOriginatingView = originatingView; 388fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael mAltViews = altViews; 398fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael mIndex = altViews.size() - 1; 408fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } 418fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 428fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael /** Returns the list of alternate views. Cannot be null. */ 438fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael public List<CanvasViewInfo> getAltViews() { 448fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael return mAltViews; 458fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } 468fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 478fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael /** Returns the originating view. Cannot be null. */ 488fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael public CanvasViewInfo getOriginatingView() { 498fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael return mOriginatingView; 508fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } 518fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 528fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael /** 538fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Returns the current alternate view to select. 548fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Initially this is the top-most view. 558fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael */ 568fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael public CanvasViewInfo getCurrent() { 578fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael return mIndex >= 0 ? mAltViews.get(mIndex) : null; 588fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } 598fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 608fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael /** 618fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * Changes the current view to be the next one and then returns it. 628fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael * This loops through the alternate views. 638fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael */ 648fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael public CanvasViewInfo getNext() { 658fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael if (mIndex == 0) { 668fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael mIndex = mAltViews.size() - 1; 678fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } else if (mIndex > 0) { 688fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael mIndex--; 698fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } 708fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael 718fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael return getCurrent(); 728fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael } 738fbb33e21e7b6c0d13c9b368c4a24f6c13809027Raphael} 74