/*
* 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.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import org.geoforge.guillc.combobox.GfrCmb;
import org.geoforge.guillc.handler.IGfrHandlerSelectedIndex;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
public class GfrPnlGrpCmbAbs extends GfrPnlGrpAbs implements
ActionListener, IGfrHandlerSelectedIndex
{
protected GfrCmb _cmb;
protected GfrPnlGrpCmbAbs(
Object[] objss,
String strLabelWhat,
final int intWidthCombo,
int intH)
{
this(strLabelWhat, intH);
this._cmb = new GfrCmb(objss)
{
@Override
public Dimension getMaximumSize()
{
Dimension dim = super.getMaximumSize();
dim = new Dimension(intWidthCombo, dim.height);
return dim;
}
@Override
public Dimension getPreferredSize()
{
Dimension dim = super.getPreferredSize();
dim = new Dimension(intWidthCombo, dim.height);
return dim;
}
@Override
public Dimension getMinimumSize()
{
Dimension dim = super.getMinimumSize();
dim = new Dimension(intWidthCombo, dim.height);
return dim;
}
};
this._addActionListenerToCmb_((ActionListener) this);
}
private GfrPnlGrpCmbAbs(
String strLabelWhat,
int intH)
{
super(
strLabelWhat,
intH);
}
protected GfrPnlGrpCmbAbs(
Object[] objss,
String strLabelWhat,
int intH)
{
this(strLabelWhat, intH);
this._cmb = new GfrCmb(objss);
this._addActionListenerToCmb_((ActionListener) this);
}
public void setComboChoices(Object[] objss)
{
DefaultComboBoxModel model = new DefaultComboBoxModel(objss);
this._cmb.setModel(model);
this._cmb.setEnabled(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
super.actionPerformed(e);
}
public void setContent(Object obj)
{
this._cmb.setSelectedItem(obj);
}
public Object getContent()
{
return this._cmb.getSelectedItem();
}
public void setContent(int index)
{
this._cmb.setSelectedIndex(index);
}
public void removeElement(int index)
{
this._cmb.removeItemAt(index);
}
public void setEditable(boolean bln)
{
this._cmb.setEditable(bln);
}
@Override
public void setEnabled(boolean bln)
{
this._cmb.setEnabled(bln);
}
@Override
public boolean init()
{
if (!super.init())
return false;
if(!this._cmb.init())
return false;
super.setMandatoryIcon(false);
this._pnlContent.add(_cmb, BorderLayout.CENTER);
return true;
}
@Override
public void destroy()
{
if (this._cmb != null)
{
this._cmb.destroy();
this._cmb = null;
}
super.destroy();
}
@Override
public int getSelectedIndex()
{
return this._cmb.getSelectedIndex();
}
@Override
public void setSelectedIndex(int index)
{
this._cmb.setSelectedIndex(index);
}
private void _addActionListenerToCmb_(ActionListener alr)
{
this._cmb.addActionListener(alr);
}
public void insertItemAt(Object obj, int index)
{
this._cmb.insertItemAt(obj, index);
this._cmb.setSelectedIndex(0);
}
}