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 android.graphics.RectF;
     20 
     21 /**
     22  * Convenience implementation of {@link BoxModelable}.
     23  */
     24 public class BoxModel implements BoxModelable{
     25 
     26     private float marginLeft;
     27     private float marginTop;
     28     private float marginRight;
     29     private float marginBottom;
     30 
     31 
     32     private float paddingLeft;
     33     private float paddingTop;
     34     private float paddingRight;
     35     private float paddingBottom;
     36     //private RectF marginRect;
     37     //private RectF paddingRect;
     38 
     39     public BoxModel() {
     40 
     41     }
     42 
     43     @SuppressWarnings("SameParameterValue")
     44     public BoxModel(float marginLeft, float marginTop, float marginRight, float marginBottom,
     45                     float paddingLeft, float paddingTop, float paddingRight, float paddingBottom) {
     46         this.marginLeft = marginLeft;
     47         this.marginTop = marginTop;
     48         this.marginRight = marginRight;
     49         this.marginBottom = marginBottom;
     50 
     51         this.paddingLeft = paddingLeft;
     52         this.paddingTop = paddingTop;
     53         this.paddingRight = paddingRight;
     54         this.paddingBottom = paddingBottom;
     55     }
     56 
     57     /**
     58      * Returns a RectF instance describing the inner edge of the margin layer.
     59      * @param boundsRect
     60      * @return
     61      */
     62     public RectF getMarginatedRect(RectF boundsRect) {
     63         return new RectF( boundsRect.left + getMarginLeft(),
     64                 boundsRect.top + getMarginTop(),
     65                 boundsRect.right - getMarginRight(),
     66                 boundsRect.bottom - getMarginBottom());
     67     }
     68 
     69     /**
     70      * Returns a RectF instance describing the inner edge of the padding layer.
     71      * @param marginRect
     72      * @return
     73      */
     74     public RectF getPaddedRect(RectF marginRect) {
     75         return new RectF(marginRect.left + getPaddingLeft(),
     76                 marginRect.top+getPaddingTop(),
     77                 marginRect.right - getPaddingRight(),
     78                 marginRect.bottom - getPaddingBottom());
     79     }
     80 
     81     @Override
     82     public void setMargins(float left, float top, float right, float bottom) {
     83         setMarginLeft(left);
     84         setMarginTop(top);
     85         setMarginRight(right);
     86         setMarginBottom(bottom);
     87     }
     88 
     89     @Override
     90     public void setPadding(float left, float top, float right, float bottom) {
     91         setPaddingLeft(left);
     92         setPaddingTop(top);
     93         setPaddingRight(right);
     94         setPaddingBottom(bottom);
     95     }
     96 
     97 
     98     public float getMarginLeft() {
     99         return marginLeft;
    100     }
    101 
    102     public void setMarginLeft(float marginLeft) {
    103         this.marginLeft = marginLeft;
    104     }
    105 
    106     public float getMarginTop() {
    107         return marginTop;
    108     }
    109 
    110     public void setMarginTop(float marginTop) {
    111         this.marginTop = marginTop;
    112     }
    113 
    114     public float getMarginRight() {
    115         return marginRight;
    116     }
    117 
    118     public void setMarginRight(float marginRight) {
    119         this.marginRight = marginRight;
    120     }
    121 
    122     public float getMarginBottom() {
    123         return marginBottom;
    124     }
    125 
    126     public void setMarginBottom(float marginBottom) {
    127         this.marginBottom = marginBottom;
    128     }
    129 
    130     public float getPaddingLeft() {
    131         return paddingLeft;
    132     }
    133 
    134     public void setPaddingLeft(float paddingLeft) {
    135         this.paddingLeft = paddingLeft;
    136     }
    137 
    138     public float getPaddingTop() {
    139         return paddingTop;
    140     }
    141 
    142     public void setPaddingTop(float paddingTop) {
    143         this.paddingTop = paddingTop;
    144     }
    145 
    146     public float getPaddingRight() {
    147         return paddingRight;
    148     }
    149 
    150     public void setPaddingRight(float paddingRight) {
    151         this.paddingRight = paddingRight;
    152     }
    153 
    154     public float getPaddingBottom() {
    155         return paddingBottom;
    156     }
    157 
    158     public void setPaddingBottom(float paddingBottom) {
    159         this.paddingBottom = paddingBottom;
    160     }
    161 }
    162