/*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.geoforge.worldwind.builder;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.layers.LayerList;
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.editor.GfrEditorObjShpSegWiseTool;
import org.geoforge.worldwind.builder.entry.GfrEntryBltObjPikAbs;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com ... please remove "_AT_" from the above
* string to get the right email address
*/
/*
* Nothing done, just copy of Pln
*/
abstract public class GfrBldObjPikShpSegWiseAbs extends GfrBldObjPikShpAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrBldObjPikShpSegWiseAbs.class.getName());
static
{
GfrBldObjPikShpSegWiseAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
// BEG PLINE
protected GfrEntryBltObjPikAbs _peyEntrySelected_ = null;
protected boolean _blnResizeNewShapes;
public boolean isResizeNewShapesToViewport()
{
return this._blnResizeNewShapes;
}
// 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 GfrBldObjPikShpSegWiseAbs(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();
super._glcWwd.redraw();
}
@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(GfrEntryBltObjPikAbs 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(GfrEntryBltObjPikAbs 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);
//!!!! TODO => no polyline but vector
((GfrEditorObjShpSegWiseAbs)this._epe).setPolyline((Polyline) this._peyEntrySelected_.getRenderable());
((GfrEditorObjShpSegWiseAbs)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.
((GfrEditorObjShpSegWiseTool)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 false;//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";
GfrBldObjPikShpSegWiseAbs._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()";
GfrBldObjPikShpSegWiseAbs._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((GfrEntryBltObjPikAbs) 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;
}
}