Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright 2012 AndroidPlot.com
      3  *
      4  *    Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
      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.androidplot.ui;
     18 
     19 import com.androidplot.ui.PositionMetric;
     20 import com.androidplot.ui.YLayoutStyle;
     21 
     22 public class YPositionMetric extends PositionMetric<YLayoutStyle> {
     23     /*
     24     public enum YLayoutStyle {
     25         ABSOLUTE_FROM_TOP,
     26         ABSOLUTE_FROM_BOTTOM,
     27         ABSOLUTE_FROM_CENTER,
     28         RELATIVE_TO_TOP,
     29         RELATIVE_TO_BOTTOM,
     30         RELATIVE_TO_CENTER
     31     }
     32     */
     33 
     34     //private YLayoutStyle layoutType;
     35 
     36     public YPositionMetric(float value, YLayoutStyle layoutStyle) {
     37         super(value, layoutStyle);
     38         //this.layoutStyle = layoutStyle;
     39 
     40 
     41     }
     42 
     43     /*
     44     @Override
     45     public void set(float value, YLayoutStyle layoutType) {
     46         validatePair(value, layoutType);
     47         super.set(value, layoutType);
     48     }
     49 
     50     @Override
     51     public void setLayoutType(YLayoutStyle layoutType) {
     52         validatePair(getValue(), layoutType);
     53         super.setLayoutType(layoutType);
     54     }
     55 
     56     @Override
     57     public void setValue(float value) {
     58         validatePair(value, getLayoutType());
     59         super.setValue(value);
     60     }
     61     */
     62 
     63     /**
     64      * Throws IllegalArgumentException if there is a problem.
     65      * @param value
     66      */
     67     protected void validatePair(float value, YLayoutStyle layoutStyle) {
     68         switch(layoutStyle) {
     69             case ABSOLUTE_FROM_TOP:
     70             case ABSOLUTE_FROM_BOTTOM:
     71             case ABSOLUTE_FROM_CENTER:
     72                 validateValue(value, PositionMetric.LayoutMode.ABSOLUTE);
     73                 break;
     74             case RELATIVE_TO_TOP:
     75             case RELATIVE_TO_BOTTOM:
     76             case RELATIVE_TO_CENTER:
     77                 validateValue(value, PositionMetric.LayoutMode.RELATIVE);
     78         }
     79     }
     80 
     81     @Override
     82     public float getPixelValue(float size) {
     83         switch(getLayoutType()) {
     84             case ABSOLUTE_FROM_TOP:
     85                 return this.getAbsolutePosition(size, PositionMetric.Origin.FROM_BEGINING);
     86             case ABSOLUTE_FROM_BOTTOM:
     87                 return this.getAbsolutePosition(size, PositionMetric.Origin.FROM_END);
     88             case ABSOLUTE_FROM_CENTER:
     89                 return this.getAbsolutePosition(size, PositionMetric.Origin.FROM_CENTER);
     90             case RELATIVE_TO_TOP:
     91                 return this.getRelativePosition(size, PositionMetric.Origin.FROM_BEGINING);
     92             case RELATIVE_TO_BOTTOM:
     93                 return this.getRelativePosition(size, PositionMetric.Origin.FROM_END);
     94             case RELATIVE_TO_CENTER:
     95                 return this.getRelativePosition(size, PositionMetric.Origin.FROM_CENTER);
     96             default:
     97                 throw new IllegalArgumentException("Unsupported LayoutType: " + this.getLayoutType());
     98         }
     99     }
    100 }
    101