Package org.geoforge.guillc.jfree.chart.annotations

Source Code of org.geoforge.guillc.jfree.chart.annotations.GfrXYPolygonAnnotationDstLyrAbs

/*
* 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.guillc.jfree.chart.annotations;

import java.awt.BasicStroke;
import java.awt.Paint;
import java.util.Observable;
import java.util.Observer;
import org.geoforge.java.awt.color.GfrColor;
import org.geoforge.jfreechart.chart.annotations.GfrXYPolygonAnnotationDst;
import org.geoforge.lang.util.GfrUnits;
import org.geoforge.lang.util.number.GfrDouble;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRenamedLloVar;

/**
*
* @author robert
*
* contains a trick to handle tbrls with renaming layer in more than one sec win
* MEMO: toolTips should be unique!!!!!!!!!
*/
abstract public class GfrXYPolygonAnnotationDstLyrAbs extends GfrXYPolygonAnnotationDst implements
        Observer
{
   final static private BasicStroke _BSE_ = new BasicStroke((float) 0);
   final static private Paint _PNT_OUT_ = GfrColor.TRS;
  
   static protected String _s_getFormattedRowHtmlTip(String strWhat, String strValue)
   {
      String str = "";
     
      str += "<tr>";
      
     str += "<td align=\"center\" valign=\"center\"><font size=\"2\">";  
      str += strWhat;
      str += "</font></td>"

      str += "<td align=\"center\" valign=\"center\"><font size=\"2\">";  
      str += strValue;
      str += "</font></td>";
   
  
      str += "</tr>";
     
      return str;
   }
  
   static protected double[] s_getPolygon(
           double dblDepthTop,
           double dblDepthBot)
   {
      double[] dbls =
      {
         dblDepthTop,
         0d,

         dblDepthBot,
         0d,

         dblDepthBot,
         1d,

         dblDepthTop,
         1d
      };
     
      return dbls;
   }
  
  
   // ---
  
   protected String _strId = null;
  
   private String _strName_ = null;
   protected double _dblDepthTop = GfrDouble.DBL_NDV;
   protected double _dblDepthBot = GfrDouble.DBL_NDV;
  
   abstract protected String _getToolTipAsHtml();
  
   protected GfrXYPolygonAnnotationDstLyrAbs(
           boolean blnUnitMeter,
           Paint fillPaint,
           String strId,
           String strName,
           double dblDepthTop,
           double dblDepthBot)
   {
      super(blnUnitMeter,
              GfrXYPolygonAnnotationDstLyrAbs.s_getPolygon(dblDepthTop, dblDepthBot),
              GfrXYPolygonAnnotationDstLyrAbs._BSE_,
              GfrXYPolygonAnnotationDstLyrAbs._PNT_OUT_,
              fillPaint);
     
      this._strId = strId;
      this._strName_ = strName;
      this._dblDepthTop = dblDepthTop;
      this._dblDepthBot = dblDepthBot;
   }
  
   @Override
   public void update(Observable obs, Object objEvt)
   {
      if (! (objEvt instanceof GfrEvtMdlIdDatRenamedLloVar))
         return;
     
      GfrEvtMdlIdDatRenamedLloVar evt = (GfrEvtMdlIdDatRenamedLloVar) objEvt;
     
      String strId = evt.getId();
     
      if (strId.compareTo(this._strId) != 0)
         return;
     
      this._strName_ = evt.getValueNew();
      String strToolTipNew = _getToolTipAsHtml();
      super.setToolTipText(strToolTipNew);
      super.fireAnnotationChanged();
   }
  
   @Override
   public void setUnitDepthMeter(boolean bln)
   {
      // first get info about need to update
      boolean blnShouldUpdate = false;
     
      if (bln != super._blnUnitDepthMeter)
         blnShouldUpdate = true;
     
      // next redirect to subclass
      super.setUnitDepthMeter(bln);
     
     
      // finally update if needed
      if (! blnShouldUpdate)
         return;
     
     
      if (super._blnUnitDepthMeter)
      {
         this._dblDepthTop *= GfrUnits.DBL_K_METER_FOOT;
         this._dblDepthBot *= GfrUnits.DBL_K_METER_FOOT;
      }
     
      else
      {
         this._dblDepthTop /= GfrUnits.DBL_K_METER_FOOT;
         this._dblDepthBot /= GfrUnits.DBL_K_METER_FOOT;
      }
     
      String strToolTipNew = _getToolTipAsHtml();
      super.setToolTipText(strToolTipNew);
   }
  
   @Override
   public void destroy()
   {
      this._strId = null;
      this._strName_ = null;
      this._dblDepthTop = GfrDouble.DBL_NDV;
      this._dblDepthBot = GfrDouble.DBL_NDV;
     
      super.destroy();
   }
  
   // fixing-up tbrl in renaming layer
   static private int _INT_COUNT_TRICK_ = 1;
  
   protected String _getEndToolTipAsHtml()
   {
      String str = "";
      str += "</table>";
      // end table
     
      // beg trick
      for (int i=0; i<_INT_COUNT_TRICK_; i++)
         str += "&nbsp;";
     
      _INT_COUNT_TRICK_++;
      // end trick
     
     
      str += "<br></br>&nbsp;<br></br>";
     
      str += "</center>";
      str += "</body>";
      str += "</html>";
     
      return str;
   }
  
   protected String _getBeginToolTipAsHtml()
   {
      String str = "<html>";
      str += "<head></head>";
      str += "<body>";
      str += "<center>";
     
      str += "<h2>";
      str += this._strName_;
      str += "</h2>";
     
      // beg table
      str += "<table align=center border=\"1\" width=\"80%\">";
     
      // beg header
      str += "<tr>";
        str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\"><strong>WHAT</strong></font></td>";
        str += "<td bgcolor=\"rgb(123,118,88)\" align=\"center\"><font color=\"#ffffff\"><strong>VALUE</strong></font></td>";
      str += "</tr>";
      // end header
     
      String strWhat = null;
      String strValue = null;
     
      // beg row
      strWhat = "Top&nbsp;depth";
      strWhat += "<br>";
      if (super._blnUnitDepthMeter)
         strWhat += "(meters)";
      else
         strWhat += "(feet)";
      strWhat += "</br>";
     
      strValue = String.format("%.2f", this._dblDepthTop);
      str += GfrXYPolygonAnnotationDstLyrAbs._s_getFormattedRowHtmlTip(strWhat, strValue);
      // end row
     
      // beg row
      strWhat = "Bottom&nbsp;depth";
      strWhat += "<br>";
      if (super._blnUnitDepthMeter)
         strWhat += "(meters)";
      else
         strWhat += "(feet)";
      strWhat += "</br>";
      strValue = String.format("%.2f", this._dblDepthBot);
      str += GfrXYPolygonAnnotationDstLyrAbs._s_getFormattedRowHtmlTip(strWhat, strValue);
      // end row
     
      return str;
   }
}
TOP

Related Classes of org.geoforge.guillc.jfree.chart.annotations.GfrXYPolygonAnnotationDstLyrAbs

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.