Package org.geoforge.guillc.panel

Source Code of org.geoforge.guillc.panel.GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs

/*
*  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.panel;

import java.awt.BorderLayout;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Observable;
import java.util.logging.Logger;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.jfreechart.chartpanel.GfrChartPanelDstAbs;
import org.geoforge.jfreechart.handler.IHandlerContainerVariableLog;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.lang.util.number.GfrDouble;
import org.geoforge.mdl.event.GfrEvtMdlIdAbs;
import org.geoforge.mdldat.event.*;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;

/**
*
* @author bantchao
*/
abstract public class GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs extends GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloAbs implements
      IHandlerContainerVariableLog
{
   // ----
   // begin: instantiate logger for this class

   final private static Logger _LOGGER_ = Logger.getLogger(GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs.class.getName());

   static
   {
      GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }

   // end: instantiate logger for this class
   // ----
   abstract protected boolean _toggleCheckboxObjectLog(String strIdObject, boolean blnValue) throws Exception;

   protected GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs(
         GfrPnlStatusBarAbs pnlStatusBar,
         String strIdTlo,
         String strIdViewer)
   {
      super(pnlStatusBar, strIdTlo, strIdViewer,
            BorderLayout.NORTH // strLocationToolbar
            );
   }

   @Override
   public void chartMouseMoved(ChartMouseEvent evt)
   {

      //--!!! tempo
      if (true)
         return;

      XYPlot plt = (XYPlot) ((GfrChartPanelDstAbs) super._tot).getPlot();

      int x = evt.getTrigger().getX();
      int y = evt.getTrigger().getY();

      Point2D p = ((GfrChartPanelDstAbs) super._tot).translateScreenToJava2D(new java.awt.Point(x, y));
      ChartRenderingInfo info = ((GfrChartPanelDstAbs) super._tot).getChartRenderingInfo();
      Rectangle2D dataArea = info.getPlotInfo().getDataArea();


      //-- Min max
      ValueAxis axisDomain = plt.getDomainAxis();

      ValueAxis axisRange = plt.getRangeAxis();


      double dblValueMax = GfrDouble.DBL_NDV;
      double dblValueMin = GfrDouble.DBL_NDV;
      double dblDepthMax = GfrDouble.DBL_NDV;
      double dblDepthMin = GfrDouble.DBL_NDV;

      if (axisRange != null)
      {
         dblValueMax = axisRange.java2DToValue(dataArea.getMaxX(), dataArea,
               plt.getRangeAxisEdge());

         dblValueMin = axisRange.java2DToValue(dataArea.getMinX(), dataArea,
               plt.getRangeAxisEdge());
      }

      if (axisDomain != null)
      {
         dblDepthMax = axisDomain.java2DToValue(dataArea.getMaxY(), dataArea,
               plt.getDomainAxisEdge());

         dblDepthMin = axisDomain.java2DToValue(dataArea.getMinY(), dataArea,
               plt.getDomainAxisEdge());
      }

      //!!!! Warning with inverted axis
      if (dblDepthMax < dblDepthMin)
      {
         double dbl = dblDepthMin;
         dblDepthMin = dblDepthMax;
         dblDepthMax = dbl;
      }

      //--
      double dblValue = plt.getRangeAxis().java2DToValue(p.getX(), dataArea,
            plt.getRangeAxisEdge());

      double dblDepth = plt.getDomainAxis().java2DToValue(p.getY(), dataArea,
            plt.getDomainAxisEdge());

      if (dblValue > dblValueMax || dblValue < dblValueMin || dblDepth > dblDepthMax || dblDepth < dblDepthMin)
      {
         super._pnlStatusBar.setMessage("");
         return;
      }


      String strMessage = "Depth="
            + GfrDouble.truncateTwoDecimal(dblDepth);

      if (axisRange != null)
      {
         strMessage += ", Value="
               + GfrDouble.truncateTwoDecimal(dblValue);
      }


      super._pnlStatusBar.setMessage(strMessage);

   }

   @Override
   public void update(Observable obs, Object objEvt)
   {

      try
      {
         if (objEvt instanceof GfrEvtMdlIdDatRemovedLloVarLog)
         {
            GfrEvtMdlIdDatRemovedLloVarLog evt = (GfrEvtMdlIdDatRemovedLloVarLog) objEvt;

            // TODO
            String strIdTlo = evt.getIdParent();

            if (strIdTlo.compareTo(super._strIdTlo) != 0)
               return;

            _removeObjectLog(objEvt);

            // ending
            return;
         }

         //

         if (objEvt instanceof GfrEvtMdlIdDatAddedLloVarLog)
         {
            GfrEvtMdlIdDatAddedLloVarLog evt = (GfrEvtMdlIdDatAddedLloVarLog) objEvt;

            // TODO
            String strIdTlo = evt.getIdParent();

            if (strIdTlo.compareTo(super._strIdTlo) != 0)
               return;

            _addObjectLog(objEvt);

            // ending
            return;
         }
      }
      catch (Exception exc)
      {
         exc.printStackTrace();
         String str = exc.getMessage();
         GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;

      }

      // ---



      // ---

      super.update(obs, objEvt);
   }

   @Override
   protected boolean _toggleCheckboxObject(String strIdObject, boolean blnValue) throws Exception
   {
      if (_toggleCheckboxObjectLog(strIdObject, blnValue))
         return true;

      return super._toggleCheckboxObject(strIdObject, blnValue);
   }

   protected boolean _addObjectLog(Object objEvt) throws Exception
   {
      String strIdObject = ((GfrEvtMdlIdAbs) objEvt).getId();

      _toggleCheckboxObjectLog(strIdObject, true);

      return true;
   }

   protected boolean _removeObjectLog(Object objEvt) throws Exception
   {
      String strIdObject = ((GfrEvtMdlIdAbs) objEvt).getId();

      // !!! if not contained !!!
      return removeVariableLog(strIdObject);
   }

   @Override
   public boolean removeVariableLog(String strId) throws Exception
   {
      return ((IHandlerContainerVariableLog) super._tot).removeVariableLog(strId);
   }

   @Override
   public boolean addVariableLog(String strId) throws Exception
   {
      return ((IHandlerContainerVariableLog) super._tot).addVariableLog(strId);
   }
}
TOP

Related Classes of org.geoforge.guillc.panel.GfrPnlPrintableSctAwtDspSecTloJfcChartLgrStepLogsTloVarAbs

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.