/*
* 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 java.awt.geom.Point2D;
import org.geoforge.guillc.handler.IGfrHandlerListenerPanelDialog;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.lang.util.geography.GfrUtilConversionCylindricalUtm;
import org.geoforge.lang.util.geography.point.GfrPointDms;
import org.geoforge.lang.util.geography.point.GfrPointUtm;
import org.geoforge.lang.util.geography.projection.cylindrical.PrjCylUtm;
import org.geoforge.lang.util.geography.GfrUtilUtm;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrPnlCrdStmUtm extends GfrPnlPosStmAbs
{
//--
//-- beg private fields
private GfrPnlGrpEditCrdXY _pnlLocation_;
private GfrPnlGrpChoiceUtmZoneHemisphere _pnlZoneHemisphere_;
//-- end private fields
//--
//--
//-- beg public methods
@Override
public Point2D.Double getGeometry()
{
Double douEasting = this._pnlLocation_.getXValue();
Double douNorthing = this._pnlLocation_.getYValue();
if (douEasting == null || douNorthing == null)
return null;
int zone = _pnlZoneHemisphere_.getZone();
String strHemisphere = _pnlZoneHemisphere_.getHemisphere();
String strLetter = "";
if (strHemisphere.compareTo(GfrUtilUtm.STRS_HEMISPHERE[0]) == 0)
{
strLetter = "T";
}
else
{
strLetter = "K";
}
GfrPointDms dms = GfrUtilConversionCylindricalUtm.s_getDmsCoordinateFromUtm(
new GfrPointUtm(
douNorthing,
douEasting,
zone,
strLetter),
PrjCylUtm.s_getInstance());
return new Point2D.Double(dms.getLongitude(), dms.getLatitude());
}
public void setCorrectInput(boolean bln)
{
this._pnlLocation_.setValueIsOk(bln);
}
public void setMandatory(boolean bln)
{
this._pnlLocation_.setMandatoryIcon(bln);
}
public GfrPnlCrdStmUtm()
{
super();
this._pnlLocation_ = new GfrPnlGrpEditCrdXY("X-Y");
this._pnlZoneHemisphere_ = new GfrPnlGrpChoiceUtmZoneHemisphere("Zone - Hemisphere");
super.addToListResizable(this._pnlLocation_);
super.addToListResizable(this._pnlZoneHemisphere_);
this._pnlLocation_.addPanelListener((IGfrHandlerListenerPanelDialog) this);
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlLocation_.init())
return false;
if (!this._pnlZoneHemisphere_.init())
return false;
this._pnlZoneHemisphere_.setMandatoryIcon(false);
super.addWithSpace(this._pnlLocation_);
super.addWithSpace(this._pnlZoneHemisphere_);
return true;
}
@Override
public void somethingHasHappened(GfrEvtPanelChange e)
{
super.firePanelUpdate();
}
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;
}
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();
}
//-- end public methods
}