/*
* 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.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.geoforge.guillc.panel.GfrPnlCmdCancelOk;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.guillc.panel.GfrPnlGrpTxfFullEditableNo;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrDlgOpenSpaceFromListWork extends GfrDlgCmdCancelOkExtItmLstSelectableAbs implements
MouseListener,
ListSelectionListener
{
//--
//--beg static
final private static int _INT_SIZE_LABEL_ = 186;
final private static int _INT_SIZE_CONTENT_ = 370;
final private static int _INT_SIZE_BUTTON_ = 20;
//-- end static
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrDlgOpenSpaceFromListWork.class.getName());
static
{
GfrDlgOpenSpaceFromListWork._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
//--
public String getValue()
{
return this._pnlPathWorkSpace_.getValue();
}
private GfrPnlGrpTxfFullEditableNo _pnlPathWorkSpace_;
public GfrDlgOpenSpaceFromListWork(
JFrame frmOwner,
String[] strsExistingItems)
{
super(
frmOwner,
strsExistingItems,
GfrResBundleLang.s_getInstance().getValue("sentence.openWorkspaceFromList"));
this._pnlPathWorkSpace_ = new GfrPnlGrpTxfFullEditableNo(
GfrResBundleLang.s_getInstance().getValue("word.path"));
super.setMouseListener((MouseListener) this);
super.setListSelectListener((ListSelectionListener) this);
super.addToListResizable(this._pnlPathWorkSpace_);
super.setLengths(
_INT_SIZE_LABEL_, _INT_SIZE_CONTENT_, _INT_SIZE_BUTTON_);
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlPathWorkSpace_.init())
return false;
this._pnlPathWorkSpace_.setMandatoryIcon(true);
super._pnlContent.add(this._pnlPathWorkSpace_);
this.pack();
return true;
}
@Override
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() != 2)
return;
String strValue = this._pnlPathWorkSpace_.getValue();
if (strValue == null)
return;
if (!((GfrPnlCmdCancelOk) super._pnlCommand).isEnabledOkCommandDialog())
return;
if (!(e.getSource() instanceof JList)) // should never happen
return;
super.setCancelled(false);
super.setVisible(false);
}
private void _somethingHasChanged_()
{
this._pnlPathWorkSpace_.setValueIsOk(true);
super.setEnabledOkCommandDialog(true);
}
@Override
public void mousePressed(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e)
{
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseExited(MouseEvent e)
{
}
@Override
public void valueChanged(ListSelectionEvent evt)
{
if (evt.getValueIsAdjusting())
return;
if (!(evt.getSource() instanceof JList))
{
String str = "! (evt.getSource() instanceof JList)";
GfrDlgOpenSpaceFromListWork._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
System.exit(1);
}
JList lst = (JList) evt.getSource();
int intRow = lst.getMinSelectionIndex();
if (intRow == -1)
{
this._pnlPathWorkSpace_.setContent("");
super.setEnabledOkCommandDialog(false);
return;
}
String str = (String) lst.getSelectedValue();
this._pnlPathWorkSpace_.setContent(str);
_somethingHasChanged_();
}
@Override
protected boolean _okEnableable()
{
return true;
}
@Override
protected boolean _noErrorToDisplay()
{
return true;
}
@Override
protected void _updateModifiedFieldStatus(GfrEvtPanelChange e)
{
}
}