/*
* 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.dialog;
import java.util.ArrayList;
import javax.swing.JFrame;
import org.geoforge.guillc.event.GfrEvtValidityChanged;
import org.geoforge.guillc.panel.GfrPnlGrpSngCmbNotEditableStr;
import org.geoforge.guillc.panel.GfrPnlSelColumn;
import org.geoforge.guillc.handler.IGfrHandlerListenerPanelDialog;
import org.geoforge.io.header.GfrIoSheetColIdxXlosNamLatLon;
import org.geoforge.io.header.GfrIoSheetColNamTlosPointLatLonAbs;
/**
*
* @author bantchao
*
* at this level, should contain at least 3 columns
*/
abstract public class GfrDlgSelImpSheetTlosPointLatLonAbs extends GfrDlgSelImpSheetXlosNamAbs
{
final static private int _INT_NB_COLUMNS_MIN_ = 2;
protected int getIndexLatitude()
{
return this._pnlLatitude.getSelectedIndex() - 1;
}
protected int getIndexLongitude()
{
return this._pnlLongitude.getSelectedIndex() - 1;
}
@Override
public GfrIoSheetColIdxXlosNamLatLon getUserChoices()
{
return new GfrIoSheetColIdxXlosNamLatLon(
super.isSkipFirstLine(),
super._getIndexName(),
this.getIndexLatitude(),
this.getIndexLongitude());
}
protected GfrPnlGrpSngCmbNotEditableStr _pnlLongitude = null;
protected GfrPnlGrpSngCmbNotEditableStr _pnlLatitude = null;
protected GfrDlgSelImpSheetTlosPointLatLonAbs(
JFrame frmOwner,
int intNbColumn,
ArrayList<Object[]> alt,
String strSentence,
String strUniqueName,
int intNbColumnMin)
throws Exception
{
super(
frmOwner,
intNbColumn,
alt,
strSentence,
strUniqueName,
_INT_NB_COLUMNS_MIN_ + intNbColumnMin);
this._pnlLongitude = new GfrPnlSelColumn(super._strsItemList, "Longitude");
this._pnlLatitude = new GfrPnlSelColumn(super._strsItemList, "Latitude");
super.addToListResizable(this._pnlLongitude);
super.addToListResizable(this._pnlLatitude);
this._pnlLongitude.addPanelListener((IGfrHandlerListenerPanelDialog) this);
this._pnlLatitude.addPanelListener((IGfrHandlerListenerPanelDialog) this);
}
@Override
protected boolean _noErrorToDisplay()
{
if (!super._noErrorToDisplay())
return false;
int intLongitude = this._pnlLongitude.getSelectedIndex();
int intLatitude = this._pnlLatitude.getSelectedIndex();
int intUniqueName = this._pnlName.getSelectedIndex();
// ----
if (intLongitude != 0)
{
if (intLongitude == intLatitude)
{
boolean blnResult = false;
String str = "Longitude and latitude are sharing the same column";
validityChanged(new GfrEvtValidityChanged(blnResult, str));
return blnResult;
}
if (intLongitude == intUniqueName)
{
boolean blnResult = false;
String str = "Longitude and " + super.getUniqueName() + " are sharing the same column";
validityChanged(new GfrEvtValidityChanged(blnResult, str));
return blnResult;
}
}
if (intLatitude != 0)
{
if (intLatitude == intUniqueName)
{
boolean blnResult = false;
String str = "Latitude and " + super.getUniqueName() + " are sharing the same column";
validityChanged(new GfrEvtValidityChanged(blnResult, str));
return blnResult;
}
}
return true;
}
@Override
protected boolean _okEnableable()
{
//--
if (!super._okEnableable())
return false;
int intId = this._pnlName.getSelectedIndex();
//--
int intLongitude = this._pnlLongitude.getSelectedIndex();
if (intLongitude == 0)
return false;
//--
int intLatitude = this._pnlLatitude.getSelectedIndex();
if (intLatitude == 0)
return false;
// ---
if (intLongitude == intLatitude)
return false;
if (intLongitude == intId)
return false;
// ----
if (intLatitude == intId)
return false;
return true;
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlLongitude.init())
return false;
if (!this._pnlLatitude.init())
return false;
super._initChoicePanel(this._pnlLongitude, GfrIoSheetColNamTlosPointLatLonAbs.STR_LONGITUDE, true);
super._initChoicePanel(this._pnlLatitude, GfrIoSheetColNamTlosPointLatLonAbs.STR_LATITUDE, true);
super._pnlSelect.addWithSpace(this._pnlLongitude);
super._pnlSelect.addWithSpace(this._pnlLatitude);
return true;
}
@Override
public void destroy()
{
super.destroy();
if (this._pnlLongitude != null)
{
this._pnlLongitude.destroy();
this._pnlLongitude = null;
}
if (this._pnlLatitude != null)
{
this._pnlLatitude.destroy();
this._pnlLatitude = null;
}
}
}