Class: AddEdgeMouseListener
- Inherits:
-
Object
- Object
- AddEdgeMouseListener
- Includes:
- AppMouseListener
- Defined in:
- lib/app/simple_controller.rb
Instance Method Summary collapse
-
#initialize(controller) ⇒ AddEdgeMouseListener
constructor
A new instance of AddEdgeMouseListener.
- #mousePressed(event) ⇒ Object
- #mouseReleased(event) ⇒ Object
Methods included from AppMouseListener
#mouseClicked, #mouseEntered, #mouseExited
Constructor Details
#initialize(controller) ⇒ AddEdgeMouseListener
Returns a new instance of AddEdgeMouseListener.
337 338 339 |
# File 'lib/app/simple_controller.rb', line 337 def initialize(controller) @controller = controller end |
Instance Method Details
#mousePressed(event) ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/app/simple_controller.rb', line 341 def mousePressed(event) if (!@first) @first = @controller.model.get_nearest_node(event.x, event.y) @controller.model.click(@first) else @second = @controller.model.get_nearest_node(event.x, event.y) @controller.model.click(@second) @edge = @controller.model.add_edge(@first, @second) @controller.model.click_edge(@edge) end end |
#mouseReleased(event) ⇒ Object
353 354 355 356 357 358 359 360 |
# File 'lib/app/simple_controller.rb', line 353 def mouseReleased(event) @controller.model.unclick(@first) if @first @controller.model.unclick_edge(@edge) if @edge if @second @controller.view.remove_mouse_listener(self) @controller.model.unclick(@second) if @second end end |