Package DisplayProject.table

Source Code of DisplayProject.table.PictureFieldTableCellRenderer

/*
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 javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

import DisplayProject.GridCell;
import DisplayProject.PictureField;
import Framework.ImageData;

/**
* Cell renderer for a {@link DisplayProject.PictureField}.
* It does not store the picture, rather, it renders it on every request.
*
* CraigM: 11/06/2008 - Rewritten to store PictureField which is reused as a place holder for the ImageDatas.  Fixes sizing issues.
*/
@SuppressWarnings("serial")
public class PictureFieldTableCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer {
    private PictureField originalPic;
    private PictureField clonedPic;

    public PictureFieldTableCellRenderer(PictureField picture) {
      ArrayFieldCellHelper.setUpCellRenderer(picture, this); // CraigM: 28/03/2008
      originalPic = picture;
      clonedPic = new PictureField();
    }

    public Component getTableCellRendererComponent(JTable table, Object data, boolean arg2, boolean arg3, int arg4, int arg5) {
        if ((data != null)&&(data instanceof ImageData)) {
            // TF:08/03/2009:Added the following code to make the renderer clone all the properties properly.
            GridCell origCell = GridCell.get(originalPic);
            GridCell clonedCell = GridCell.get(clonedPic);
            clonedCell.setBottomMargin(origCell.getBottomMargin());
            clonedCell.setTopMargin(origCell.getTopMargin());
            clonedCell.setLeftMargin(origCell.getLeftMargin());
            clonedCell.setRightMargin(origCell.getRightMargin());
            clonedCell.setCellGravity(origCell.getCellGravity());
            clonedCell.setHeightPolicy(origCell.getHeightPolicy());
            clonedCell.setWidthPolicy(origCell.getWidthPolicy());

//            clonedPic.setSize(originalPic.getSize());
//          clonedPic.setMinimumSize(originalPic.getMinimumSize());
//          clonedPic.setPreferredSize(originalPic.getPreferredSize());
//          clonedPic.setFrameColor(originalPic.getFrameColor());
//          clonedPic.setFrameWeight(originalPic.getFrameWeight());
//          clonedPic.setImageGravity(originalPic.getImageGravity());
//          clonedPic.setImageSizePolicy(originalPic.getImageSizePolicy());
//          clonedPic.setBackground(originalPic.getBackground());
//            clonedPic.setImageValue((ImageData)data);
           
            clonedPic.setProperties( originalPic.getSize(),
                  originalPic.getMinimumSize(),
              originalPic.getPreferredSize(),
              originalPic.getFrameColor(),
              originalPic.getFrameWeight(),
              originalPic.getImageGravity(),
              originalPic.getImageSizePolicy(),
              originalPic.getBackground(),
                (ImageData)data);
               
        }
        else {
          clonedPic.setImageValue(null);
          clonedPic.refreshImage();
        }
       
        // TF:14/12/2009:DET-143:Allowed the tool tip information to show
      this.clonedPic.setToolTipText(this.originalPic.getToolTipText());

        return clonedPic;
    }
}
TOP

Related Classes of DisplayProject.table.PictureFieldTableCellRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.