Sha256: f72a96dee58ff95d2c10674ba406c36f6ecac87ebff4d651beee3fc6bcdb9241

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

module Clevic

class CellRenderer < javax.swing.table.DefaultTableCellRenderer
  def initialize( table_view )
    super()
    @table_view = table_view
  end
  
  def getTableCellRendererComponent( table, value, selected, has_focus, row_index, column_index )
    index = table.model.create_index( row_index, column_index )
    component = super( table, index.display_value, selected, has_focus, row_index, column_index )
    
    # set alignment
    component.horizontal_alignment = index.field.swing_alignment
    
    # set text colour
    component.foreground =
    case
    # read-only
    when index.field.read_only? || index.entity.andand.readonly? || @table_view.model.read_only?
      java.awt.Color.lightGray
    
    # errors
    when index.entity.errors.has_key?( index.field.id )
      java.awt.Color.red
    
    # whatever the view says
    else
      index.field.foreground_for( index.entity )
    end
    
    # set tooltip
    component.tool_tip_text = index.tooltip
    
    component
  rescue
    puts $!.backtrace
    puts $!.message
    puts index.entity.inspect
    nil
  end
end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
clevic-0.13.0.b9 lib/clevic/swing/cell_renderer.rb
clevic-0.13.0.b6 lib/clevic/swing/cell_renderer.rb
clevic-0.13.0.b5 lib/clevic/swing/cell_renderer.rb
clevic-0.13.0.b3 lib/clevic/swing/cell_renderer.rb
clevic-0.13.0.b2 lib/clevic/swing/cell_renderer.rb
clevic-0.13.0.b1 lib/clevic/swing/cell_renderer.rb