Package org.geoforge.io.writer

Source Code of org.geoforge.io.writer.GfrIoBldSheetLatLonObjs

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

import java.awt.Component;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.geoforge.io.header.GfrIoSheetColIdxXlosNamLatLon;
import org.geoforge.io.saver.GfrIoBldSheetTlosNamLatLonAbs;
import org.geoforge.io.saver.GfrObjectNamPnt;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/**
*
* @author bantchao
*
* !!! should be generalized in super-class !!!
*/
public class GfrIoBldSheetLatLonObjs extends GfrIoBldSheetTlosNamLatLonAbs
{

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

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

   private String _strWhat_ = null;

   private ArrayList<GfrObjectNamPnt> _altPntId_ = null;

   private GfrIoSheetColIdxXlosNamLatLon _choicesUser_ = null;

   public ArrayList<GfrObjectNamPnt> getResult()
   {
      return this._altPntId_;
   }

   public GfrIoBldSheetLatLonObjs(
           Component cmpOwner,
           ArrayList<Object[]> alt,
           String strWhat,
           GfrIoSheetColIdxXlosNamLatLon choicesUser)
   {
      super(
              cmpOwner,
              alt);

      this._altPntId_ = new ArrayList<GfrObjectNamPnt>();

      this._strWhat_ = strWhat;
      this._choicesUser_ = choicesUser;
   }

   @Override
   public void doJob() throws Exception
   {
      if (super._alt == null || super._alt.size() < 1)
      {
         System.err.println("No valid data found in file");
         throw new Exception("No valid data found in file");
      }


      if (super._alt.size() < 1)
      {
         System.err.println("super._alt_.size() < 1");
         throw new Exception("Number of records less than 1, found: " + (super._alt.size() - 1));
      }


      int intLineCount = 0;


      for (Object[] objsCur : super._alt)
      {
         intLineCount++;


         if (objsCur.length < 3) // !!!
            continue;

         String strId = null;

         try
         {
            strId = (String) objsCur[_INT_COL_NAME];
            strId = strId.replaceAll("\"", "");
         }
         catch (Exception exc)
         {
            if (_INT_CHOICE_WARNING == 2)
               continue;

            String strWarning = "Failed to read " + this._strWhat_ + "'s name";
            strWarning += "\n row: " + intLineCount;
            strWarning += "\n column: " + (this._choicesUser_.getColName() + 1);
            strWarning += "\n\n";
            strWarning += "Message:";
            strWarning += "\n   " + exc.getMessage();
            GfrIoBldSheetLatLonObjs._LOGGER_.warning(strWarning);

            _INT_CHOICE_WARNING = JOptionPane.showOptionDialog(
                    this._cmpOwner,
                    strWarning,
                    "Warning",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null, _STRS_CHOICE_WARNING,
                    _STRS_CHOICE_WARNING[2]);

            if (_INT_CHOICE_WARNING == 0)
            {
               _manageUserCancelled_();
               return;
            }

            continue;
         }




         double dblLongitude;

         try
         {
            dblLongitude = super._readLongitude(objsCur);
         }
         catch (Exception exc)
         {
            if (_INT_CHOICE_WARNING == 2)
               continue;

            String strWarning = "Failed to read longitude";
            strWarning += "\n row: " + intLineCount;
            strWarning += "\n column: " + (this._choicesUser_.getColLongitude() + 1);
            strWarning += "\n\n";
            strWarning += "Message:";
            strWarning += "\n   " + exc.getMessage();
            GfrIoBldSheetLatLonObjs._LOGGER_.warning(strWarning);

            _INT_CHOICE_WARNING = JOptionPane.showOptionDialog(
                    this._cmpOwner, strWarning, "Warning",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
                    null, _STRS_CHOICE_WARNING, _STRS_CHOICE_WARNING[2]);

            if (_INT_CHOICE_WARNING == 0)
            {
               _manageUserCancelled_();
               return;
            }

            continue;
         }


         // ---

         double dblLatitude;

         try
         {
            dblLatitude = super._readLatitude(objsCur);
         }
         catch (Exception exc)
         {
            if (_INT_CHOICE_WARNING == 2)
               continue;

            String strWarning = "Failed to read latitude";
            strWarning += "\n row: " + intLineCount;
            strWarning += "\n column: " + (this._choicesUser_.getColLatitude() + 1);
            strWarning += "\n\n";
            strWarning += "Message:";
            strWarning += "\n   " + exc.getMessage();
            GfrIoBldSheetLatLonObjs._LOGGER_.warning(strWarning);

            _INT_CHOICE_WARNING = JOptionPane.showOptionDialog(
                    this._cmpOwner, strWarning, "Warning",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
                    null, _STRS_CHOICE_WARNING, _STRS_CHOICE_WARNING[2]);

            if (_INT_CHOICE_WARNING == 0)
            {
               _manageUserCancelled_();
               return;
            }

            continue;
         }

         try
         {
            Point2D.Double dbl = new Point2D.Double(dblLongitude, dblLatitude);

            GfrObjectNamPnt objCur = new GfrObjectNamPnt(strId, dbl);
            this._altPntId_.add(objCur);
         }
         catch (Exception exc)
         {
            if (_INT_CHOICE_WARNING == 2)
               continue;

            String strWarning = "Failed to read line: " + intLineCount;
            strWarning += "\n\n";
            strWarning += "Message:";
            strWarning += "\n   " + exc.getMessage();
            GfrIoBldSheetLatLonObjs._LOGGER_.warning(strWarning);

            _INT_CHOICE_WARNING = JOptionPane.showOptionDialog(
                    this._cmpOwner, strWarning, "Warning",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
                    null, _STRS_CHOICE_WARNING, _STRS_CHOICE_WARNING[2]);

            if (_INT_CHOICE_WARNING == 0)
            {
               _manageUserCancelled_();
               return;
            }

            continue;
         }

      }

   }

   // -- fixed tbrl if user cancel
   private void _manageUserCancelled_()
   {
      if (super._alt != null)
      {
         super._alt.clear();
         super._alt = null; // meaning aborted by user
      }

      // --- in order to cancel
      if (this._altPntId_!=null)
      {
         this._altPntId_.clear();
         this._altPntId_ = null;
      }
   }
}
TOP

Related Classes of org.geoforge.io.writer.GfrIoBldSheetLatLonObjs

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.