Class: Skatolo

Inherits:
Java::TechLityReaSkatolo::Skatolo
  • Object
show all
Defined in:
lib/skatolo.rb

Instance Method Summary collapse

Constructor Details

#initialize(applet, events_object = nil) ⇒ Skatolo

Returns a new instance of Skatolo.



22
23
24
25
26
27
28
29
# File 'lib/skatolo.rb', line 22

def initialize (applet, events_object = nil)
  @event_handler = EventHandler.new self
  @events_object = events_object if events_object != nil
  @events_object = applet if events_object == nil

  super(applet, @event_handler)
#    @applet = applet
end

Instance Method Details

#create_getter_for(name) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/skatolo.rb', line 81

def create_getter_for name
  controller = get(name)
  return if is_event_class controller.class

  value = get_controller_value(controller)

  @events_object.create_method(name + "_value") do
    controller = @skatolo.get(name)
    @skatolo.get_controller_value controller
  end

end

#create_setter_for(name) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/skatolo.rb', line 94

def create_setter_for name

  controller = get(name)
  return if is_event_class controller.class

  value = get_controller_value controller
#    puts "Creating a setter for " + name

  @events_object.create_method(name + "_value=") do |value|
    controller = @skatolo.get(name)
    @skatolo.set_controller_value controller, value
  end

end

#get_controller_value(controller) ⇒ Object



110
111
112
113
114
# File 'lib/skatolo.rb', line 110

def get_controller_value controller
  return 1 if is_event_class controller.class
  return controller.getValue if is_value_class controller.class
  return controller.getStringValue  if is_string_value_class controller.class
end

#is_event_class(object_class) ⇒ Object



123
124
125
126
127
# File 'lib/skatolo.rb', line 123

def is_event_class object_class
  object_class == Java::TechLityReaSkatoloGuiControllers::Button or
    object_class == Java::TechLityReaSkatoloGuiControllers::HoverButton or
    object_class == Java::TechLityReaSkatoloGuiControllers::Bang
end

#is_string_value_class(object_class) ⇒ Object



135
136
137
# File 'lib/skatolo.rb', line 135

def is_string_value_class object_class
  object_class == Java::TechLityReaSkatoloGuiControllers::Textfield
end

#is_value_class(object_class) ⇒ Object



129
130
131
132
133
# File 'lib/skatolo.rb', line 129

def is_value_class object_class
  object_class == Java::TechLityReaSkatoloGuiControllers::Slider or
    object_class == Java::TechLityReaSkatoloGuiControllers::HoverToggle or
    object_class == Java::TechLityReaSkatoloGuiControllers::Numberbox
end

#send_event_to_sketch(controlEvent) ⇒ Object

Event function…



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/skatolo.rb', line 45

def send_event_to_sketch(controlEvent)
  controller = get(controlEvent.getName)
  name = controlEvent.getName
  value = controlEvent.getValue
  string_value = controlEvent.getStringValue

#    puts controller.object_id.to_s

  ## There is a method with this name...
  if @events_object.respond_to? name

    ## Buttons usually, not arguments.
    if is_event_class controller.class
      @events_object.send(name)
      return
    end

    ## Sliders, check arity
    if is_value_class controller.class

      ## try to send the value
      @events_object.send(name, value)
      return
    end

    ## Text
    ## Sliders, check arity
    if is_string_value_class controller.class
      ## try to send the value
      @events_object.send(name, string_value)
      return
    end
  end
end

#set_controller_value(controller, value) ⇒ Object



116
117
118
119
120
# File 'lib/skatolo.rb', line 116

def set_controller_value controller, value
  return if is_event_class controller.class
  return controller.setValue value  if is_value_class controller.class
  return controller.setStringValue value  if is_string_value_class controller.class
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/skatolo.rb', line 31

def update
  getAll.to_a.each do |controller|
    name = controller.name
    ## There is a method with this name...

    if not (@events_object.respond_to? name + "_value")
      #        puts "please declare a method for " + name
      create_getter_for name
      create_setter_for name
    end
  end
end