Home | History | Annotate | Download | only in xy
      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.xy;
     18 
     19 import android.content.Context;
     20 import com.androidplot.ui.SeriesRenderer;
     21 import com.androidplot.ui.Formatter;
     22 import com.androidplot.util.ZHash;
     23 import com.androidplot.util.ZIndexable;
     24 
     25 public abstract class XYSeriesFormatter<XYRegionFormatterType extends XYRegionFormatter> extends Formatter<XYPlot> {
     26     ZHash<RectRegion, XYRegionFormatterType>  regions;
     27 
     28     {
     29         regions = new ZHash<RectRegion, XYRegionFormatterType>();
     30     }
     31 
     32     public void addRegion(RectRegion region, XYRegionFormatterType regionFormatter) {
     33         regions.addToBottom(region, regionFormatter);
     34     }
     35 
     36     public void removeRegion(RectRegion region) {
     37         regions.remove(region);
     38     }
     39 
     40     /**
     41      * Can be used to access z-index manipulation methods of ZIndexable.
     42      * @return
     43      */
     44     public ZIndexable<RectRegion> getRegions() {
     45         return regions;
     46     }
     47 
     48     /**
     49      * @param region
     50      * @return
     51      */
     52     public XYRegionFormatterType getRegionFormatter(RectRegion region) {
     53         return regions.get(region);
     54     }
     55 
     56     /**
     57      * Not completely sure why this is necessary, but if it's not here then
     58      * subclasses are forced to take a Plot instead of an XYPlot as a parameter,
     59      * which in turn breaks the pattern.
     60      * @param plot
     61      * @return
     62      */
     63     @Override
     64     public abstract SeriesRenderer getRendererInstance(XYPlot plot);
     65 }
     66