Class: SmarterMeter::Interfaces::Wizard::PachubePage

Inherits:
Object
  • Object
show all
Includes:
WizardPage
Defined in:
lib/smartermeter/interfaces/swing.rb

Instance Method Summary collapse

Methods included from WizardPage

#build, #header

Constructor Details

#initialize(buttons) ⇒ PachubePage

Returns a new instance of PachubePage.



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/smartermeter/interfaces/swing.rb', line 405

def initialize(buttons)
  @buttons = buttons

  title = "<html><b>Connect to Pachube</b></html>"
  message  = "In order to view your power data on Pachube you'll need to create an account."

  header(title, message) do |c|
    layout = "
        [ create ]
        [ api_key_label | <api_key ]
        [ feed_id_label | <feed_id ]
        [ datastream_id_label | <datastream_id ]
    "
    @controls = Profligacy::Swing::LEL.new(JPanel, layout) do |cc,ii|
      cc.create = JButton.new "Create a Pachube Account"
      ii.create = { :action => method(:open_pachube_registration) }
      cc.api_key_label = JLabel.new "Api Key:"
      cc.api_key_field = JTextField.new
      ii.api_key_field = { :key => method(:validate) }
      cc.feed_id_label = JLabel.new "Feed id:"
      cc.feed_id_field = JTextField.new
      ii.feed_id_field = { :key => method(:validate) }
      cc.datastream_id_label = JLabel.new "Datastream Name:"
      cc.datastream_id_field = JTextField.new
      ii.datastream_id_field = { :key => method(:validate) }
    end
    c.controls = @controls.build
  end
end

Instance Method Details

#api_keyObject



435
436
437
# File 'lib/smartermeter/interfaces/swing.rb', line 435

def api_key
  @controls.api_key.text.strip
end

#datastream_idObject



443
444
445
# File 'lib/smartermeter/interfaces/swing.rb', line 443

def datastream_id
  @controls.datastream_id.text.strip
end

#feed_idObject



439
440
441
# File 'lib/smartermeter/interfaces/swing.rb', line 439

def feed_id
  @controls.feed_id.text.strip
end

#open_pachube_registration(*ignored_args) ⇒ Object

Opens the Pachube plans page so that users can register

Returns nothing.



450
451
452
453
454
# File 'lib/smartermeter/interfaces/swing.rb', line 450

def open_pachube_registration(*ignored_args)
    desktop = Desktop.getDesktop()
    uri = Java::JavaNet::URI.new("https://pachube.com/plans")
    desktop.browse(uri)
end

#validate(*ignored_args) ⇒ Object

Determines whether a user has entered authorization information from Google.

Returns nothing.



460
461
462
463
464
# File 'lib/smartermeter/interfaces/swing.rb', line 460

def validate(*ignored_args)
  if api_key.any? && feed_id.any? && datastream_id.any?
    @buttons.next.enabled = true
  end
end