FileDocCategorySizeDatePackage
SVTableCellEditor.javaAPI DocApache Poi 3.0.16327Mon Jan 01 12:39:34 GMT 2007org.apache.poi.hssf.contrib.view

SVTableCellEditor

public class SVTableCellEditor extends AbstractCellEditor implements ActionListener, TableCellEditor
Sheet Viewer Table Cell Editor -- not commented via javadoc as it nearly completely consists of overridden methods.
author
Jason Height
since
16 July 2002

Fields Summary
private static final Color
black
private static final Color
white
private Hashtable
colors
private HSSFWorkbook
wb
private JTextField
editor
private HSSFCell
editorValue
Constructors Summary
public SVTableCellEditor(HSSFWorkbook wb)



     
    this.wb = wb;
    this.editor = new JTextField();
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

    System.out.println("Action performed");
    stopCellEditing();
  
public voidcancelCellEditing()

    System.out.println("Cancel Cell Editing");
    fireEditingCanceled();
  
private final java.awt.ColorgetAWTColor(int index, java.awt.Color deflt)
This method retrieves the AWT Color representation from the colour hash table

      HSSFColor clr = (HSSFColor)colors.get(new Integer(index));
      if (clr == null) return deflt;
      return getAWTColor(clr);
    
private static final java.awt.ColorgetAWTColor(org.apache.poi.hssf.util.HSSFColor clr)

      short[] rgb = clr.getTriplet();
      return new Color(rgb[0],rgb[1],rgb[2]);
    
public java.lang.ObjectgetCellEditorValue()
Gets the cellEditorValue attribute of the SVTableCellEditor object

return
The cellEditorValue value

    System.out.println("GetCellEditorValue");
    //JMH Look at when this method is called. Should it return a HSSFCell?
    return editor.getText();
  
public java.awt.ComponentgetTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
Gets the tableCellEditorComponent attribute of the SVTableCellEditor object

return
The tableCellEditorComponent value

    System.out.println("GetTableCellEditorComponent");
    HSSFCell cell = (HSSFCell) value;
    if (cell != null) {
          HSSFCellStyle style = cell.getCellStyle();
          HSSFFont f = wb.getFontAt(style.getFontIndex());
          boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
          boolean isitalics = f.getItalic();

          int fontstyle = Font.PLAIN;

          if (isbold) fontstyle = Font.BOLD;
          if (isitalics) fontstyle = fontstyle | Font.ITALIC;

          int fontheight = f.getFontHeightInPoints();
          if (fontheight == 9) fontheight = 10; //fix for stupid ol Windows

          Font font = new Font(f.getFontName(),fontstyle,fontheight);
          editor.setFont(font);

          if (style.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
            editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
          } else editor.setBackground(white);

          editor.setForeground(getAWTColor(f.getColor(), black));


      //Set the value that is rendered for the cell
      switch (cell.getCellType()) {
        case HSSFCell.CELL_TYPE_BLANK:
          editor.setText("");
          break;
        case HSSFCell.CELL_TYPE_BOOLEAN:
          if (cell.getBooleanCellValue()) {
            editor.setText("true");
          } else {
            editor.setText("false");
          }
          break;
        case HSSFCell.CELL_TYPE_NUMERIC:
          editor.setText(Double.toString(cell.getNumericCellValue()));
          break;
        case HSSFCell.CELL_TYPE_STRING:
          editor.setText(cell.getRichStringCellValue().getString());
          break;
        case HSSFCell.CELL_TYPE_FORMULA:
        default:
          editor.setText("?");
      }
      switch (style.getAlignment()) {
        case HSSFCellStyle.ALIGN_LEFT:
        case HSSFCellStyle.ALIGN_JUSTIFY:
        case HSSFCellStyle.ALIGN_FILL:
          editor.setHorizontalAlignment(SwingConstants.LEFT);
          break;
        case HSSFCellStyle.ALIGN_CENTER:
        case HSSFCellStyle.ALIGN_CENTER_SELECTION:
          editor.setHorizontalAlignment(SwingConstants.CENTER);
          break;
        case HSSFCellStyle.ALIGN_GENERAL:
        case HSSFCellStyle.ALIGN_RIGHT:
          editor.setHorizontalAlignment(SwingConstants.RIGHT);
          break;
        default:
          editor.setHorizontalAlignment(SwingConstants.LEFT);
          break;
      }

    }
    return editor;
  
public booleanisCellEditable(java.util.EventObject e)
Gets the cellEditable attribute of the SVTableCellEditor object

return
The cellEditable value

    if (e instanceof MouseEvent) {
      return ((MouseEvent) e).getClickCount() >= 2;
    }
    return false;
  
public booleanshouldSelectCell(java.util.EventObject anEvent)

    return true;
  
public booleanstartCellEditing(java.util.EventObject anEvent)

    System.out.println("Start Cell Editing");
    return true;
  
public booleanstopCellEditing()

    System.out.println("Stop Cell Editing");
    fireEditingStopped();
    return true;