Package org.geoforge.io.writer

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

/*
*  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.GfrIoSheetColIdxXlosNamGeometry;
import org.geoforge.io.saver.GfrIoBldSheetTlosNamGeometryAbs;
import org.geoforge.io.saver.GfrObjectNamGeometry;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrIoBldSheetGeometryObjs extends GfrIoBldSheetTlosNamGeometryAbs
{

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

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

   private String _strWhat_ = null;

   private ArrayList<GfrObjectNamGeometry> _altPntId_ = null;

   private GfrIoSheetColIdxXlosNamGeometry _choicesUser_ = null;

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

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

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

      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 < 2) // !!!
            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();
            GfrIoBldSheetGeometryObjs._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;
         }



         // ---

         ArrayList<Point2D.Double> altP2ds;

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

            String strWarning = "Failed to read geometry";
            strWarning += "\n row: " + intLineCount;
            strWarning += "\n column: " + (this._choicesUser_.getColGeometry() + 1);
            strWarning += "\n\n";
            strWarning += "Message:";
            strWarning += "\n   " + exc.getMessage();
            GfrIoBldSheetGeometryObjs._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
         {
            GfrObjectNamGeometry objCur = new GfrObjectNamGeometry(strId, altP2ds);
            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();
            GfrIoBldSheetGeometryObjs._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.GfrIoBldSheetGeometryObjs

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.