Package org.geoforge.jfreechart.data.xy

Source Code of org.geoforge.jfreechart.data.xy.GfrXYSeriesCollectionDstLogsTloVarAbs

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU Lesser General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.jfreechart.data.xy;

import java.beans.PropertyChangeListener;
import java.util.HashSet;
import org.geoforge.jfreechart.handler.IHandlerContainerVariableLog;
import org.geoforge.jfreechart.handler.IHandlerContainerVariableMarkersTlo;
import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYSeries;

/**
*
* @author bantchao
*/
abstract public class GfrXYSeriesCollectionDstLogsTloVarAbs extends GfrXYSeriesCollectionDstLogsTloAbs implements
        IHandlerContainerVariableLog,
        IHandlerContainerVariableMarkersTlo
{
   final static protected double _DBL_MIN_X_MARKER = -2.;
   final static protected double _DBL_MAX_X_MARKER = GfrXYSeriesCollectionDstLogsTloVarAbs._DBL_MIN_X_MARKER * -1.;
  

  
    // beg trick underscore used as protected candidate to interface
   abstract public XYSeries _fillInVariableLog(String strId) throws Exception;
   abstract public XYSeries _fillInVariableMarker(String strId) throws Exception;
   // end trick underscore used as protected
  
  
  
   protected GfrXYSeriesCollectionDstLogsTloVarAbs(
           PropertyChangeListener lstPropertyChange,
           boolean blnUnitDepthMeter,
           String strIdTlo,
           String[] strsIdLlos) throws Exception
   {
      super(lstPropertyChange, blnUnitDepthMeter);
     
     
      if (strsIdLlos != null && strsIdLlos.length > 0)
      {
         for (int i = 0; i < strsIdLlos.length; i++)
         {
            XYSeries serCur = _fillInVariableLog(strsIdLlos[i]);
            super.addSeries(serCur);
         }
      }
   }
  
   public void updateValuesAbscissaHorizontalSegments() throws Exception
   {
      if (super.getSeriesCount() < 1)
         return;

      double dblMin = 999999999.0; // !!!!!!!
      double dblMax = dblMin;
      dblMax *= -1.;


      // parsing log values
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarLogAbs))
            continue;

         // --
         double dblMinAbscissaCur = serCur.getMinY();
         double dblMaxAbscissaCur = serCur.getMaxY();

         if (dblMin > dblMinAbscissaCur)
            dblMin = dblMinAbscissaCur;

         if (dblMax < dblMaxAbscissaCur)
            dblMax = dblMaxAbscissaCur;
      }

      // ---
      if (dblMin >= dblMax) // no logs
      {
         dblMin = GfrXYSeriesCollectionDstLogsTloVarAbs._DBL_MIN_X_MARKER;
         dblMax = GfrXYSeriesCollectionDstLogsTloVarAbs._DBL_MAX_X_MARKER;
      }

      // ----
      // assigning markers abscissa values
      _updateAbscissaMarkers(dblMin, dblMax);
     
   }
  
   @Override
   public boolean removeAllLogsTlo() throws Exception
   {
      HashSet<GfrXYSeriesDepAbs> hstToRemove = new HashSet<GfrXYSeriesDepAbs>();
     
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarLogAbs))
            continue;

         hstToRemove.add(serCur);
      }
     
      if (hstToRemove.isEmpty())
      {
         hstToRemove = null;
         return false;
      }
     
      for (GfrXYSeriesDepAbs serCur: hstToRemove)
      {
         super.removeSeries(serCur);
      }

      // ---
      hstToRemove.clear();
      hstToRemove = null;
      return true;
   }
  
   @Override
   public boolean removeVariableLog(String strId) throws Exception
   {
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarLogAbs))
            continue;

         GfrXYSeriesDepVarAbs serLogCur = (GfrXYSeriesDepVarAbs) serCur;
         String strIdCur = serLogCur.getUniqueId();

         if (strIdCur.compareTo(strId) != 0)
            continue;

         super.removeSeries(serLogCur);
         return true;
      }

      return false;
   }
  
   @Override
   public boolean addVariableLog(String strId) throws Exception
   {
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarLogAbs))
            continue;

         GfrXYSeriesDepAbs serLogCur = (GfrXYSeriesDepAbs) serCur;
         String strIdCur = serLogCur.getUniqueId();

         if (strIdCur.compareTo(strId) != 0)
            continue;

         return false;
      }

      XYSeries serCur = _fillInVariableLog(strId);
      super.addSeries(serCur);
      return true;
   }
  
   protected void _updateAbscissaMarkers(
            double dblMin,
            double dblMax) throws Exception
   {
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarHrzMrkAbs))
            continue;

         // --

         if (serCur.getItemCount() != 2)
         {
            // TBRL
            System.out.println("serCur.getItemCount() != 2, serCur.getItemCount()=" + serCur.getItemCount());
            System.exit(1);
         }

         XYDataItem datCur0 = serCur.getDataItem(0);
         datCur0.setY(dblMin);
         XYDataItem datCur1 = serCur.getDataItem(1);
         datCur1.setY(dblMax);

         serCur.clear();
         serCur.add(datCur0);
         serCur.add(datCur1);
      }
   }
  
   /*
    * ATTN: logs and markers could share same name!!!!!!!!!!!!!!!!!!!!!!!!!!!
    *
    */
   @Override
   public boolean removeVariableMarkerTlo(String strId)
         throws Exception
   {
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarHrzMrkAbs))
            continue;

         GfrXYSeriesDepAbs serLogCur = (GfrXYSeriesDepAbs) serCur;
         String strIdCur = serLogCur.getUniqueId();

         if (strIdCur.compareTo(strId) != 0)
            continue;

         super.removeSeries(serLogCur);
         return true;
      }

      return false;
   }

   @Override
   public boolean addVariableMarkerTlo(String strId) throws Exception
   {
      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarHrzMrkAbs))
            continue;

         GfrXYSeriesDepAbs serLogCur = (GfrXYSeriesDepAbs) serCur;
         String strIdCur = serLogCur.getUniqueId();

         if (strIdCur.compareTo(strId) != 0)
            continue;

         return false;
      }

      XYSeries serCur = _fillInVariableMarker(strId);
      super.addSeries(serCur);
      return true;
   }

   @Override
   public boolean removeAllMarkersTlo() throws Exception
   {
      HashSet<GfrXYSeriesDepAbs> hstToRemove = new HashSet<GfrXYSeriesDepAbs>();

      for (int i = 0; i < super.getSeriesCount(); i++)
      {
         GfrXYSeriesDepAbs serCur = (GfrXYSeriesDepAbs) super.getSeries(i);

         if (!(serCur instanceof GfrXYSeriesDepVarHrzMrkAbs))
            continue;

         hstToRemove.add(serCur);
      }

      if (hstToRemove.isEmpty())
      {
         hstToRemove = null;
         return false;
      }

      for (GfrXYSeriesDepAbs serCur : hstToRemove)
      {
         super.removeSeries(serCur);
      }

      // ---
      hstToRemove.clear();
      hstToRemove = null;
      return true;
   }
  
}
TOP

Related Classes of org.geoforge.jfreechart.data.xy.GfrXYSeriesCollectionDstLogsTloVarAbs

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.