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 20 import com.androidplot.ui.PositionMetric; 21 import com.androidplot.ui.XLayoutStyle; 22 23 public class XPositionMetric extends PositionMetric<XLayoutStyle> { 24 25 //private XLayoutStyle layoutType; 26 27 public XPositionMetric(float value, XLayoutStyle layoutStyle) { 28 super(value, layoutStyle); 29 validatePair(value, layoutStyle); 30 //this.layoutStyle = layoutStyle; 31 } 32 33 /** 34 * Throws IllegalArgumentException if there is a problem. 35 * @param value 36 */ 37 protected void validatePair(float value, XLayoutStyle layoutStyle) { 38 switch(layoutStyle) { 39 case ABSOLUTE_FROM_LEFT: 40 case ABSOLUTE_FROM_RIGHT: 41 case ABSOLUTE_FROM_CENTER: 42 validateValue(value, PositionMetric.LayoutMode.ABSOLUTE); 43 break; 44 case RELATIVE_TO_LEFT: 45 case RELATIVE_TO_RIGHT: 46 case RELATIVE_TO_CENTER: 47 validateValue(value, PositionMetric.LayoutMode.RELATIVE); 48 } 49 } 50 51 @Override 52 public float getPixelValue(float size) { 53 switch(getLayoutType()) { 54 case ABSOLUTE_FROM_LEFT: 55 return this.getAbsolutePosition(size, PositionMetric.Origin.FROM_BEGINING); 56 case ABSOLUTE_FROM_RIGHT: 57 return this.getAbsolutePosition(size, PositionMetric.Origin.FROM_END); 58 case ABSOLUTE_FROM_CENTER: 59 return this.getAbsolutePosition(size, PositionMetric.Origin.FROM_CENTER); 60 case RELATIVE_TO_LEFT: 61 return this.getRelativePosition(size, PositionMetric.Origin.FROM_BEGINING); 62 case RELATIVE_TO_RIGHT: 63 return this.getRelativePosition(size, PositionMetric.Origin.FROM_END); 64 case RELATIVE_TO_CENTER: 65 return this.getRelativePosition(size, PositionMetric.Origin.FROM_CENTER); 66 default: 67 throw new IllegalArgumentException("Unsupported LayoutType: " + this.getLayoutType()); 68 } 69 } 70 } 71