/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package DisplayProject.table;
import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import DisplayProject.RadioList;
import Framework.EventManager;
import Framework.IntegerData;
/**
* Cell Renderer for a {@link DisplayProject.RadioList} in an {@link DisplayProject.controls.ArrayField}.
* We create a new {@link DisplayProject.RadioList} so we don't interfere with the {@link RadioListCellEditor}.
* @deprecated This class should not be used, use the inner class inside RadioListUI instead.
*/
@SuppressWarnings("serial")
public class RadioListCellRenderer extends DefaultTableCellRenderer implements ArrayFieldEmptyCellRenderer {
private RadioList radioList = null;
private RadioList radioListOriginal = null;
private RadioList radioListPainter = null;
public RadioListCellRenderer(RadioList radioList)
{
super();
this.radioListOriginal = radioList;
this.radioList = new RadioList(radioList.getOrientation(), radioList.getCaption().toString());
ArrayFieldCellHelper.setUpCellRenderer(radioList, this.radioList); // CraigM: 28/03/2008
this.radioList.setOrientation(radioList.getOrientation());
this.radioList.setWrapSize(radioList.getWrapSize());
this.radioList.setElementList(this.radioList.getElementList());
this.radioList.setModel(radioList.getModel());
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
{
// When we modify the value for the renderer, we don't want to tell the world we are doing it as
// it is just for display purposes. CraigM: 02/04/2008
EventManager.disableEventPosting();
try {
if (isSelected) {
this.radioList.setForeground(table.getSelectionForeground());
this.radioList.setBackground(table.getSelectionBackground());
}
else {
this.radioList.setBackground(table.getBackground()); //PM:27/9/07
this.radioList.setForeground(table.getForeground()); //PM:27/9/07
}
if (value != null) {
if (value instanceof Number || value instanceof IntegerData) {
// Scan through the list to find a match for this number
int num;
if (value instanceof Number) {
num = ((Number)value).intValue();
}
else {
IntegerData anInt = (IntegerData)value;
if (anInt.isNull()) {
// If it is null, then clear out the radio list. CraigM: 08/08/2007
this.radioList.clearSelection();
return this.radioList;
}
else {
num = anInt.intValue();
}
}
this.radioList.setSelectedIndex(num-1);
}
// must be s string or textdata
else {
this.radioList.setTextValue(value.toString());
}
}
}
// Make sure we turn events on again. CraigM: 02/04/2008
finally {
EventManager.enableEventPosting();
}
// TF:14/12/2009:DET-143:Allowed the tool tip information to show
this.radioList.setToolTipText(this.radioListOriginal.getToolTipText());
return this.radioList;
}
/**
* CraigM:20/01/2009 - Create a buffered image of the RadioList.
*/
public BufferedImage getImage(int width) {
int height = this.radioListOriginal.getMinimumSize().height;
// TF:27/11/2009:Changed this to use the passed width
// int width = this.radioListOriginal.getMinimumSize().width;
if (this.radioListPainter == null) {
this.radioListPainter = new RadioList(this.radioListOriginal.getOrientation(), this.radioListOriginal.getCaption().toString());
this.radioListPainter.setWrapSize(this.radioListOriginal.getWrapSize());
this.radioListPainter.setElementList(this.radioListOriginal.getElementList());
this.radioListPainter.setModel(this.radioListOriginal.getModel());
}
this.radioListPainter.setForeground(this.radioListOriginal.getForeground());
this.radioListPainter.setBackground(this.radioListOriginal.getBackground());
return ArrayFieldCellHelper.createBufferedImage(this.radioListPainter, width, height);
}
}