/*
* 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 org.geoforge.guillc.handler.IGfrHandlerListenerPanelDialog;
import java.awt.geom.Point2D;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.lang.util.geography.point.GfrPointDms;
import org.geoforge.lang.util.geography.point.GfrPointConical;
import org.geoforge.lang.util.geography.projection.GfrPrjAbs;
import org.geoforge.lang.util.geography.projection.conical.PrjConAbs;
import org.geoforge.lang.util.geography.projection.conical.PrjConLambertIII_Carto;
import org.geoforge.lang.util.geography.projection.conical.PrjConLambertII_Carto;
import org.geoforge.lang.util.geography.projection.conical.PrjConLambertIV_Carto;
import org.geoforge.lang.util.geography.projection.conical.PrjConLambertI_Carto;
import org.geoforge.lang.util.geography.GfrUtilConversionConical;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com ... please remove "_AT_" from the above
* string to get the right email address
*/
public class GfrPnlCrdStmLambert extends GfrPnlPosStmAbs implements IGfrHandlerListenerPanelDialog
{
private static final String _STR_LAMBERT_I_ = "Lambert I";
private static final String _STR_LAMBERT_II_ = "Lambert II";
private static final String _STR_LAMBERT_III_ = "Lambert III";
private static final String _STR_LAMBERT_IV_ = "Lambert IV";
private static final String _STR_LAMBERT_II_EXT_ = "Lambert II extended";
private static final String[] _STRS_COORD_SYSTEMS_ =
{
_STR_LAMBERT_I_,
_STR_LAMBERT_II_,
_STR_LAMBERT_III_,
_STR_LAMBERT_IV_,
_STR_LAMBERT_II_EXT_
};
private GfrPnlGrpSngCmbNotEditableStr _pnlChoice_;
private GfrPnlGrpEditCrdXY _pnlLocation_;
public GfrPnlCrdStmLambert()
{
this._pnlChoice_ = new GfrPnlGrpSngCmbNotEditableStr(
GfrPnlCrdStmLambert._STRS_COORD_SYSTEMS_,
"Coordinate system");
this._pnlLocation_ = new GfrPnlGrpEditCrdXY("X-Y");
super.addToListResizable(this._pnlChoice_);
super.addToListResizable(this._pnlLocation_);
this._pnlLocation_.addPanelListener((IGfrHandlerListenerPanelDialog) this);
}
@Override
public Point2D.Double getGeometry()
{
Double dblX = this._pnlLocation_.getXValue();
Double dblY = this._pnlLocation_.getYValue();
if (dblX == null || dblY == null)
return null;
GfrPrjAbs prj = null;
if (this._pnlChoice_.getContent().equals(_STR_LAMBERT_I_))
prj = PrjConLambertI_Carto.s_getInstance();
if (this._pnlChoice_.getContent().equals(_STR_LAMBERT_II_))
prj = PrjConLambertII_Carto.s_getInstance();
if (this._pnlChoice_.getContent().equals(_STR_LAMBERT_III_))
prj = PrjConLambertIII_Carto.s_getInstance();
if (this._pnlChoice_.getContent().equals(_STR_LAMBERT_IV_))
prj = PrjConLambertIV_Carto.s_getInstance();
if (this._pnlChoice_.getContent().equals(_STR_LAMBERT_II_EXT_))
prj = PrjConLambertII_Carto.s_getInstance();
GfrPointDms dms = GfrUtilConversionConical.s_getDmsCoordinateFromConical(
new GfrPointConical(
dblX,
dblY),
(PrjConAbs) prj);
return new Point2D.Double(dms.getLongitude(), dms.getLatitude());
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlChoice_.init())
return false;
if (!this._pnlLocation_.init())
return false;
this._pnlChoice_.removeElement(0);
this._pnlChoice_.setSelectedIndex(4);
super.addWithSpace(this._pnlChoice_);
super.addWithSpace(this._pnlLocation_);
return true;
}
public void setCorrectInput(boolean bln)
{
this._pnlLocation_.setValueIsOk(bln);
}
public void setMandatory(boolean bln)
{
this._pnlLocation_.setMandatoryIcon(bln);
}
@Override
public void somethingHasHappened(GfrEvtPanelChange e)
{
super.firePanelUpdate();
}
public boolean hasNoError()
{
boolean blnXempty = this._pnlLocation_.isEmptyXCoordinate();
boolean blnYempty = this._pnlLocation_.isEmptyYCoordinate();
boolean blnIsXMalformed = this._pnlLocation_.hasXCoordinateError();
boolean blnIsYMalformed = this._pnlLocation_.hasYCoordinateError();
if ((blnXempty && blnYempty)
||(blnXempty && !blnIsYMalformed)
||(blnYempty && !blnIsXMalformed)
)
return true;
return this.enablesOk();
}
public boolean enablesOk()
{
boolean blnXempty = this._pnlLocation_.isEmptyXCoordinate();
boolean blnYempty = this._pnlLocation_.isEmptyYCoordinate();
if (blnXempty && blnYempty)
return false;
Point2D.Double geom = this.getGeometry();
boolean blnIsXMalformed = this._pnlLocation_.hasXCoordinateError();
boolean blnIsYMalformed = this._pnlLocation_.hasYCoordinateError();
String strMalformedFields = "";
String strWhat = "coordinate";
if (blnIsXMalformed)
strMalformedFields += "X";
if (blnIsXMalformed && blnIsYMalformed)
{
strMalformedFields += ", ";
strWhat += "s";
}
if (blnIsYMalformed)
strMalformedFields += "Y";
if (geom == null && (blnIsXMalformed || blnIsYMalformed))
{
fireValidityUpdate(
false,
"Error in " + strWhat + " : " + strMalformedFields);
return false;
}
if (blnXempty || blnYempty)
return false;
return true;
}
}