Package org.geoforge.worldwind.builder

Source Code of org.geoforge.worldwind.builder.GfrBldObjPikShpPlnAbs

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package org.geoforge.worldwind.builder;

import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.layers.LayerList;
import gov.nasa.worldwind.render.AbstractShape;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.worldwind.builder.entry.GfrEntryBltObjPikAbs;
import org.geoforge.worldwind.builder.entry.GfrEntryBltObjPikShpAbs;
import org.geoforge.worldwind.builder.editor.GfrEditorObjShpPlnAbs;

/**
*
* @author bantchao@gmail.com
*/
/*
* Change Amadeus 2014/01/06
*
* This class is called "GfrBldObjPikShpAbs"
* Shp for Shape, but has also notion of Polyline.
* Only one class extends this one "GfrBldObjPikShpLinAbs", that seems use-less
* I refactor "GfrBldObjPikShpAbs" in "GfrBldObjPikShpPlnAbs" to introduce the notion of Polyline
*/
abstract public class GfrBldObjPikShpPlnAbs extends GfrBldObjPikShpAbs
{
   // ----
   // begin: instantiate logger for this class

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

   static
   {
      GfrBldObjPikShpPlnAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----

   // BEG PLINE
   protected GfrEntryBltObjPikShpAbs _peyEntrySelected_ = null;

   protected boolean _blnResizeNewShapes;

   public boolean isResizeNewShapesToViewport()
   {
      return this._blnResizeNewShapes;
   }

   //!!! notion of polyine
   //protected GfrEditorObjShpPlnAbs _epe = null;

   // END PLINE
   final static private String _STR_NAME_LAYER_ = "PickedShape";

   protected boolean _blnEnabledEdit = true;

   private boolean _blnEnabled_ = true;

   public boolean isEnabled()
   {
      return this._blnEnabled_;
   }

   public void setEnabled(boolean enabled)
   {
      this._blnEnabled_ = enabled;
   }

   public boolean isEnableEdit()
   {
      return this._blnEnabledEdit;
   }

   protected GfrBldObjPikShpPlnAbs(WorldWindowGLCanvas glcWwd)
   {
      super(glcWwd);


      // ---


      // ---
      super._rlr.setName(_STR_NAME_LAYER_);
      super._glcWwd.getInputHandler().addMouseListener((MouseListener) this);


      LayerList llt = super._glcWwd.getModel().getLayers();
      llt.add(super._rlr);

      // test
      super._glcWwd.redraw();
   }

   @Override
   protected void _clearEntry()
   {
      super._glcWwd.getModel().getLayers().remove(this._epe);

      super._clearEntry();
   }

   @Override
   public void mousePressed(MouseEvent e)
   {
      if (e == null || e.isConsumed())
      {
         return;
      }

      if (!this.isEnabled())
      {
         return;
      }

      //noinspection StringEquality
        /*if (e.getButton() == MouseEvent.BUTTON1)
      {
      this.handleSelect();
      }*/
   }

   public void selectEntry(GfrEntryBltObjPikShpAbs entry, boolean updateView)
   {

      this.setSelectedEntry(entry);

      if (updateView)
      {
         /*if (entry != null)
         {
         int index = this.getModel().getIndexForEntry(entry);
         this.getView().setSelectedIndices(new int[] {index});
         }
         else
         {
         this.getView().setSelectedIndices(new int[0]);
         }*/
      }

      if (this.isEnableEdit())
      {
         if (this._peyEntrySelected_ != null && !this.isSelectionEditing())
         {
            this.setSelectionEditing(true);
         }
      }

      super._glcWwd.redraw();

   }

   protected void setSelectedEntry(GfrEntryBltObjPikShpAbs entry)
   {
      if (this._peyEntrySelected_ != null)
      {
         if (this._peyEntrySelected_ != entry && this._peyEntrySelected_.isEditing())
         {
            this.setSelectionEditing(false);
         }

         this._peyEntrySelected_.setSelected(false);
      }

      this._peyEntrySelected_ = entry;

      if (this._peyEntrySelected_ != null)
      {
         this._peyEntrySelected_.setSelected(true);
      }
   }

   protected void setSelectionEditing(boolean editing)
   {
      if (this._peyEntrySelected_ == null)
      {
         throw new IllegalStateException();
      }

      if (this._peyEntrySelected_.isEditing() == editing)
      {
         throw new IllegalStateException();
      }

      this._peyEntrySelected_.setEditing(editing);

      ((GfrEditorObjShpPlnAbs)this._epe).setPolyline((AbstractShape) this._peyEntrySelected_.getRenderable());
      ((GfrEditorObjShpPlnAbs)this._epe).setArmed(editing);


      if (editing)
      {
         //insertBeforePlacenames(super._wwc, this.editor);
         super._glcWwd.getModel().getLayers().add(this._epe);
      }
      else
      {
         super._glcWwd.getModel().getLayers().remove(this._epe);
      }

      //int index = this.getModel().getIndexForEntry(this.selectedEntry);
      //this.getModel().fireTableRowsUpdated(index, index);

   }

   public void setEnableEdit(boolean enable)
   {
      this._blnEnabledEdit = enable;
      this.handleEnableEdit(enable);
   }

   public void setResizeNewShapesToViewport(boolean resize)
   {
      this._blnResizeNewShapes = resize;
   }

   @Override
   public boolean init()
   {
      // The ordering is important here; we want first pass at mouse events.
     ((GfrEditorObjShpPlnAbs)this._epe).setWorldWindow(super._glcWwd);
      this.setResizeNewShapesToViewport(true);

      if (!((IGfrHandlerLifeCycleObject)this._epe).init())
         return false;

      return true;
   }

   @Override
   public void destroy()
   {
      super.destroy();

      if (this._epe != null)
      {
         ((IGfrHandlerLifeCycleObject)this._epe).destroy();
         this._epe = null;
      }
   }

   @Override
   public void mouseReleased(MouseEvent e)
   {
   }

   // BEG PLINE
   protected void handleEnableEdit(boolean enable)
   {
      if (this._peyEntrySelected_ == null)
         return;

      if (this.isSelectionEditing() != enable)
         this.setSelectionEditing(enable);
   }

   protected boolean isSelectionEditing()
   {
      return this._peyEntrySelected_ != null && this._peyEntrySelected_.isEditing();
   }

   protected void viewSelectionChanged()
   {
      System.out.println("GfrBuilderPicksLinAbs.viewSelectionChanged(): void");
      /*int[] indices = this.getView().getSelectedIndices();
      if (indices != null)
      {
      for (OurPolygonEntry entry : this.getEntriesFor(indices))
      {
      this.selectEntry(entry, false);
      }
      }
     
      this._wwc.redraw();*/
   }
   // END  PLINE

   @Override
   protected void _createNewEntry(GfrEntryBltObjPikAbs pey)
   {
      if (super._pey != null)
      {
         String str = "super._pey != null";
         GfrBldObjPikShpPlnAbs._LOGGER_.severe(str);

         JOptionPane.showMessageDialog(null,
                 str, GfrResBundleLang.s_getInstance().getValue("word.error"),
                 JOptionPane.ERROR_MESSAGE);

         return;
      }

      super._pey = pey;

      if (!this._pey.init())
      {
         String str = "! super._pey.init()";
         GfrBldObjPikShpPlnAbs._LOGGER_.severe(str);
         JOptionPane.showMessageDialog(null,
                 str, GfrResBundleLang.s_getInstance().getValue("word.error"), JOptionPane.ERROR_MESSAGE);
         return;
      }

      super._rlr.addRenderable(super._pey.getRenderable());

      //!!!!!!!!!!!!!!!
      super._glcWwd.redraw();

      this.selectEntry((GfrEntryBltObjPikShpAbs) super._pey, true);
   }

   protected Object _getValue(Iterator<? extends LatLon> itr)
   {
      ArrayList<LatLon> alt = new ArrayList<LatLon>();

      while (itr.hasNext())
      {
         LatLon lln = itr.next();
         alt.add(lln);
      }

      return (Object) alt;
   }

}
TOP

Related Classes of org.geoforge.worldwind.builder.GfrBldObjPikShpPlnAbs

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.