Module: RPV::Swing::EventHandlerMixin::ClassMethods

Defined in:
lib/rpv/swing/event_handler_mixin.rb

Instance Method Summary collapse

Instance Method Details

#publish_defaultsObject



10
11
12
13
# File 'lib/rpv/swing/event_handler_mixin.rb', line 10

def publish_defaults
  @publish_defaults = { :events => :action_performed } if @publish_defaults.nil?
  @publish_defaults
end

#publish_events(options = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rpv/swing/event_handler_mixin.rb', line 15

def publish_events(options = nil)
  @publish_events ||= []
  unless options.nil?
    unless options[:events].is_a? Hash
      events = [options[:events]].flatten
      options[:events] = {}
      events.each do |event|
        options[:events][event] = event
      end
    end
    @publish_events << { :options => options }
    options[:events].each do |event, as|
      fires "#{as}".to_sym
    end
  end
  @publish_events
end

#publish_events_for(components = nil, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rpv/swing/event_handler_mixin.rb', line 33

def publish_events_for(components = nil, options = {})
  @publish_events_for ||= []
  unless components.nil?
    components = [components].flatten
    options = options || {}
    options = publish_defaults.merge(options)
    unless options[:events].is_a? Hash
      events = [options[:events]].flatten
      options[:events] = {}
      events.each do |event|
        options[:events][event] = event
      end
    end
    @publish_events_for << { :components => components, :options => options }
    components.each do |component|
      options[:events].each do |event, as|
        fires "#{component}_#{as}".to_sym
      end
    end
  end
  @publish_events_for
end