/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.guillc.dialog;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.guillc.event.GfrEvtValidityChanged;
import org.geoforge.guillc.handler.IGfrHandlerListenerPanelDialog;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.panel.GfrPnlGrpTxfFullEditableYes;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
/**
*
* @author bill
*/
abstract public class GfrDlgCmdCancelOkEdtUrlAbs extends GfrDlgCmdCancelOkEdtAbs
{
final private static int INT_SIZE_LABEL = 160;
final private static int INT_SIZE_CONTENT = 370;
final private static int INT_SIZE_BUTTON = 30;
final private static Logger _LOGGER_ = Logger.getLogger(GfrDlgCmdCancelOkEdtUrlAbs.class.getName());
static
{
GfrDlgCmdCancelOkEdtUrlAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// ---
private GfrPnlGrpTxfFullEditableYes _pnlUrl_;
private String[] _strsFileExtension_ = null;
protected GfrDlgCmdCancelOkEdtUrlAbs(
String strTitle,
String strLabel,
String[] strsFileExtension)
{
super(
(JFrame) null, //frmOwner,
strTitle);
this._strsFileExtension_ = strsFileExtension;
this._pnlUrl_ = new GfrPnlGrpTxfFullEditableYes(strLabel);
this._pnlUrl_.addPanelListener((IGfrHandlerListenerPanelDialog)this);
super.addToListResizable(this._pnlUrl_);
super.setLengths(
INT_SIZE_LABEL, INT_SIZE_CONTENT, INT_SIZE_BUTTON);
}
@Override
public void destroy()
{
super.destroy();
if (this._pnlUrl_ != null)
{
this._pnlUrl_.removePanelListener((IGfrHandlerListenerPanelDialog)this);
this._pnlUrl_.destroy();
this._pnlUrl_ = null;
}
}
@Override
public boolean init()
{
if (! super.init())
return false;
if (! this._pnlUrl_.init())
return false;
this._pnlUrl_.setMandatoryIcon(true);
super._pnlContent.add(this._pnlUrl_);
return true;
}
public String getValue()
{
return this._pnlUrl_.getValue();
}
@Override
protected boolean _noErrorToDisplay()
{
return this._pnlUrlHasNoError_();
}
@Override
protected void _updateModifiedFieldStatus(GfrEvtPanelChange e)
{
Object obj = e.getSource();
if (obj instanceof GfrPnlGrpTxfFullEditableYes)
{
boolean bln = _pnlUrlEnablesOk_();
this._pnlUrl_.setValueIsOk(bln);
return;
}
// dev coding error, should show an error dialog
String strError = "Uncaught instanceof obj, obj.getClass().toString()=" + obj.getClass().toString();
GfrDlgCmdCancelOkEdtUrlAbs._LOGGER_.severe(strError);
GfrOptionPaneAbs.s_showDialogError(rootPane, strError);
}
@Override
protected boolean _okEnableable()
{
return this._pnlUrlEnablesOk_();
}
private boolean _pnlUrlEnablesOk_()
{
String strUrl = this._pnlUrl_.getValue();
if (strUrl == null || strUrl.length() < 1)
return false;
strUrl = strUrl.trim();
try
{
new URI(strUrl);
new URL(strUrl);
}
catch (URISyntaxException excURISyntax)
{
validityChanged(new GfrEvtValidityChanged(false, "Wrong Syntax URL."));
return false;
}
catch (MalformedURLException excMalformedURL)
{
validityChanged(new GfrEvtValidityChanged(false, "Malformed URL."));
return false;
}
catch (Exception exc)
{
validityChanged(new GfrEvtValidityChanged(false, "Please enter a valid URL."));
return false;
}
for (int i=0; i<this._strsFileExtension_.length; i++)
{
if (strUrl.toLowerCase().endsWith(this._strsFileExtension_[i]))
return true;
}
String strAllowedExtension = "";
for (int i=0; i<this._strsFileExtension_.length; i++)
strAllowedExtension += this._strsFileExtension_[i] + " ";
validityChanged(new GfrEvtValidityChanged(false, "Wrong file extension, supported extensions:" + strAllowedExtension));
return false;
}
private boolean _pnlUrlHasNoError_()
{
String strUrl = this._pnlUrl_.getValue();
if (strUrl == null || strUrl.length() < 1)
return true;
return this._pnlUrlEnablesOk_();
}
}