Home | History | Annotate | Download | only in gle2
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
     18 
     19 import java.util.List;
     20 
     21 /**
     22  * Information for the current alternate selection, i.e. the possible selected items
     23  * that are located at the same x/y as the original view, either sibling or parents.
     24  */
     25 /* package */ class CanvasAlternateSelection {
     26     private final CanvasViewInfo mOriginatingView;
     27     private final List<CanvasViewInfo> mAltViews;
     28     private int mIndex;
     29 
     30     /**
     31      * Creates a new alternate selection based on the given originating view and the
     32      * given list of alternate views. Both cannot be null.
     33      */
     34     public CanvasAlternateSelection(CanvasViewInfo originatingView, List<CanvasViewInfo> altViews) {
     35         assert originatingView != null;
     36         assert altViews != null;
     37         mOriginatingView = originatingView;
     38         mAltViews = altViews;
     39         mIndex = altViews.size() - 1;
     40     }
     41 
     42     /** Returns the list of alternate views. Cannot be null. */
     43     public List<CanvasViewInfo> getAltViews() {
     44         return mAltViews;
     45     }
     46 
     47     /** Returns the originating view. Cannot be null. */
     48     public CanvasViewInfo getOriginatingView() {
     49         return mOriginatingView;
     50     }
     51 
     52     /**
     53      * Returns the current alternate view to select.
     54      * Initially this is the top-most view.
     55      */
     56     public CanvasViewInfo getCurrent() {
     57         return mIndex >= 0 ? mAltViews.get(mIndex) : null;
     58     }
     59 
     60     /**
     61      * Changes the current view to be the next one and then returns it.
     62      * This loops through the alternate views.
     63      */
     64     public CanvasViewInfo getNext() {
     65         if (mIndex == 0) {
     66             mIndex = mAltViews.size() - 1;
     67         } else if (mIndex > 0) {
     68             mIndex--;
     69         }
     70 
     71         return getCurrent();
     72     }
     73 }
     74