/*
* 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.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import org.geoforge.guillc.label.GfrLbl;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.awt.image.GfrFactoryIconAbs;
import org.geoforge.io.awt.image.GfrFactoryIconAppGfr;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
abstract public class GfrPnlGrpAbs extends GfrPnl implements ActionListener
{
//--
//--beg static fields
private static ImageIcon IIN_MANDATORY_OK =
GfrFactoryIconAppGfr.s_getTickGreen(GfrFactoryIconAbs.INT_SIZE_XXSMALL);
//--
private static ImageIcon IIN_MANDATORY_NOT_OK =
GfrFactoryIconAppGfr.s_getUnsetMandatoryNotOk(GfrFactoryIconAbs.INT_SIZE_XXSMALL);
//--
private static ImageIcon IIN_NOT_MANDATORY =
GfrFactoryIconAppGfr.s_getTransparent(GfrFactoryIconAbs.INT_SIZE_XXSMALL);
//--end static fields
//--
//
//--
//--beg private fields
private GfrPnl _pnlLabelWhat_;
private GfrPnl _pnlStatus_;
//--
private boolean _blnMandatory_ = false;
private boolean _blnIsOk_ = false;
//--
private int _widthLabelLeft_ = 0;
private int _widthContentCenter_ = 0;
private int _widthRight_ = 0;
private int _heightComponent_ = 0;
//--end private fields
//--
//
//--
//--beg protected fields
protected GfrPnl _pnlButton;
protected GfrPnl _pnlContent;
protected GfrLbl _lblWhat;
//--end protected fields
//--
//--
//--beg public methods
public void setWidthLabel(int width)
{
this._widthLabelLeft_ = width;
this._pnlLabelWhat_.setPreferredSize(
new Dimension(this._widthLabelLeft_, this._heightComponent_));
_updateDimension();
}
public int getWidthLabel()
{
return this._widthLabelLeft_;
}
public int getHeightComponent()
{
return this._heightComponent_;
}
public void setWidthContent(int width)
{
this._widthContentCenter_ = width;
this._updateDimension();
}
public int getWidthContent()
{
return this._widthContentCenter_;
}
public void setWidthButton(int width)
{
this._widthRight_ = width;
this._pnlButton.setPreferredSize(
new Dimension(this._widthRight_, this._heightComponent_));
_updateDimension();
}
public int getWidthButton()
{
return this._widthRight_;
}
public void setMandatoryIcon(boolean bln)
{
this._blnMandatory_ = bln;
if (bln)
{
if (this._blnIsOk_)
{
this._lblWhat.setIcon(IIN_MANDATORY_OK);
return;
}
this._lblWhat.setIcon(IIN_MANDATORY_NOT_OK);
return;
}
this._lblWhat.setIcon(IIN_NOT_MANDATORY);
}
public boolean isMandatory()
{
return this._blnMandatory_;
}
public void setValueIsOk(boolean bln)
{
this._blnIsOk_ = bln;
if (bln && this._blnMandatory_)
{
this._lblWhat.setIcon(IIN_MANDATORY_OK);
return;
}
if (bln && !this._blnMandatory_)
{
this._lblWhat.setIcon(IIN_NOT_MANDATORY);
return;
}
this._lblWhat.setIcon(IIN_MANDATORY_NOT_OK);
}
public void setWhat(String str)
{
this._lblWhat.setText(str);
}
@Override
public void destroy()
{
if (this._pnlContent != null)
{
this._pnlContent.destroy();
this._pnlContent = null;
}
if (this._pnlLabelWhat_ != null)
{
this._pnlLabelWhat_.destroy();
this._pnlLabelWhat_ = null;
}
if (this._pnlButton != null)
{
this._pnlButton.destroy();
this._pnlButton = null;
}
if (this._pnlStatus_ != null)
{
this._pnlStatus_.destroy();
this._pnlStatus_ = null;
}
super.destroy();
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlContent.init())
return false;
if (!this._pnlLabelWhat_.init())
return false;
if (!this._pnlButton.init())
return false;
if (!this._pnlStatus_.init())
return false;
this.setLayout(new BorderLayout(8, 0));
GfrPnl pnl = new GfrPnl();
pnl.setLayout(new BorderLayout());
this._blnMandatory_ = false;
this._pnlLabelWhat_.setLayout(new BorderLayout());
this._pnlLabelWhat_.add(_lblWhat, BorderLayout.WEST);
this._lblWhat.setIcon(IIN_MANDATORY_NOT_OK);
this._pnlContent.setLayout(new BoxLayout(this._pnlContent, BoxLayout.LINE_AXIS));
this._pnlButton.setLayout(new BorderLayout());
this.add(this._pnlLabelWhat_, BorderLayout.WEST);
this.add(this._pnlContent, BorderLayout.CENTER);
this.add(this._pnlButton, BorderLayout.EAST);
return true;
}
@Override
public void actionPerformed(ActionEvent e)
{
firePanelUpdate();
}
public void addPanelListener(IGfrHandlerListenerPanelDialog plr)
{
listenerList.add(IGfrHandlerListenerPanelDialog.class, plr);
}
public void removePanelListener(IGfrHandlerListenerPanelDialog clr)
{
listenerList.remove(IGfrHandlerListenerPanelDialog.class, clr);
}
public IGfrHandlerListenerPanelDialog[] getPanelListeners()
{
return (IGfrHandlerListenerPanelDialog[]) listenerList.getListeners(IGfrHandlerListenerPanelDialog.class);
}
//--end public methods
//--
//--
//--beg protected methods
protected void _updateDimension()
{
this.setMaximumSize(new Dimension(
this.getWidthButton() + this._widthContentCenter_ + this.getWidthLabel(),
this.getHeightComponent()));
this.setPreferredSize(new Dimension(
this.getWidthButton() + this._widthContentCenter_ + this.getWidthLabel(),
this.getHeightComponent()));
}
public void setHeigth(int intHeigth)
{
this._heightComponent_ = intHeigth;
}
protected GfrPnlGrpAbs(
String strLabelWhat,
int heightComponent)
{
this._lblWhat = new GfrLbl(strLabelWhat);//memo do not append ":" coz internationalisation
this._pnlLabelWhat_ = new GfrPnl();
this._pnlContent = new GfrPnl();
this._pnlButton = new GfrPnl();
this._pnlStatus_ = new GfrPnl();
this._heightComponent_ = heightComponent;
}
protected void firePanelUpdate()
{
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
GfrEvtPanelChange e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = 0; i < listeners.length; i++)
{
if (listeners[i] instanceof IGfrHandlerListenerPanelDialog)
{
e = new GfrEvtPanelChange(GfrPnlGrpAbs.this);
((IGfrHandlerListenerPanelDialog) listeners[i]).somethingHasHappened(e);
}
}
}
//--end protected methods
//--
}