Class: Clevic::SelectionModel

Inherits:
Object
  • Object
show all
Defined in:
lib/clevic/swing/selection_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_view) ⇒ SelectionModel

Returns a new instance of SelectionModel.



36
37
38
# File 'lib/clevic/swing/selection_model.rb', line 36

def initialize( table_view )
  @table_view = table_view 
end

Instance Attribute Details

#table_viewObject (readonly)

Returns the value of attribute table_view.



40
41
42
# File 'lib/clevic/swing/selection_model.rb', line 40

def table_view
  @table_view
end

Instance Method Details

#clearObject



73
74
75
# File 'lib/clevic/swing/selection_model.rb', line 73

def clear
  jtable.clear_selection
end

#jtableObject



42
43
44
# File 'lib/clevic/swing/selection_model.rb', line 42

def jtable
  @table_view.jtable
end

#rangesObject

return a collection of selection ranges



47
48
49
50
51
52
53
54
55
# File 'lib/clevic/swing/selection_model.rb', line 47

def ranges
  rv = []
  jtable.selected_rows.to_a.group.each do |row_group|
    jtable.selected_columns.to_a.group.each do |column_group|
      rv << SelectionRange.new( row_group.range, column_group.range )
    end
  end
  rv
end

#row_indexesObject

return an array of integer indexes for currently selected rows



69
70
71
# File 'lib/clevic/swing/selection_model.rb', line 69

def row_indexes
  jtable.selected_rows.to_a
end

#selected?(row, column) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/clevic/swing/selection_model.rb', line 61

def selected?( row, column )
  selected_indexes.first.with do |index|
    index.row == row &&
    index.column == column
  end
end

#selected_indexesObject

return the full set of selected indexes, ordered by row then column



79
80
81
82
83
84
85
86
87
# File 'lib/clevic/swing/selection_model.rb', line 79

def selected_indexes
  indexes = []
  jtable.selected_rows.each do |row_index|
    jtable.selected_columns.each do |column_index|
      indexes << table_view.model.create_index( row_index, column_index )
    end
  end
  indexes
end

#single_cell?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/clevic/swing/selection_model.rb', line 57

def single_cell?
  jtable.selected_row_count == 1 && jtable.selected_column_count == 1
end