Class: SmarterMeter::Interfaces::Wizard

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

Defined Under Namespace

Modules: WizardPage Classes: CompletePage, PGEPage, PachubePage

Instance Method Summary collapse

Constructor Details

#initializeWizard

Returns a new instance of Wizard.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/smartermeter/interfaces/swing.rb', line 156

def initialize
  UIManager.set_look_and_feel(UIManager.get_system_look_and_feel_class_name)

  layout = "
      [ panel ]
      [ rule ]
      [ >buttons ]
  "

  @page_index = 0

  @wizard = Profligacy::Swing::LEL.new(JFrame, layout) do |c,i|
    c.rule = JSeparator.new

    @buttons = Profligacy::Swing::LEL.new(JPanel, "[back|next|>gap|cancel]") do |cc,ii|
      cc.back = JButton.new "Back"
      cc.back.minimum_size = Dimension.new(50,14)
      cc.back.visible = false
      ii.back = { :action => method(:show_previous_page) }

      cc.next = JButton.new "Next"
      cc.next.minimum_size = Dimension.new(50,14)
      cc.next.enabled = false
      ii.next = { :action => method(:show_next_page) }

      cc.gap = Box.create_horizontal_strut(10)

      cc.cancel = JButton.new "Cancel"
      cc.cancel.minimum_size = Dimension.new(50,14)
      ii.cancel =  { :action => proc do |t, e|
          if cc.cancel.text == "Complete"
            config = {
              :username => @pages[0].username,
              :password => @pages[0].password,
              :transport => :pachube,
              :pachube => {
                :api_key => @pages[1].api_key,
                :feed_id => @pages[1].feed_id,
                :datastream_id => @pages[1].datastream_id
              }
            }
          else
            config = {}
          end

          @frame.dispose
          yield config
        end
      }
    end
    c.buttons = @buttons.build

    @panel = JPanel.new(CardLayout.new)
    @pages = [PGEPage, PachubePage, CompletePage].map do |klass|
      page = klass.new(@buttons)
      @panel.add(page.build, klass.to_s)
      page
    end
    c.panel = @panel
  end

  @frame = @wizard.build(:args => "SmarterMeter Setup", :auto_create_container_gaps => false) do |frame|
    frame.default_close_operation = JFrame::DISPOSE_ON_CLOSE
    frame.set_size(560, 400)
    frame.set_location_relative_to(nil) # Centers on screen
  end
end

Instance Method Details

#show_next_page(type, event) ⇒ Object

Public: Presents the next page of the wizard.

type - The symbol representing the name of the event called event - The Java::Awt::Event that was triggered.

Returns nothing.



230
231
232
233
234
235
# File 'lib/smartermeter/interfaces/swing.rb', line 230

def show_next_page(type, event)
  @page_index += 1
  configure_buttons

  @panel.get_layout.next(@panel)
end

#show_previous_page(type, event) ⇒ Object

Public: Presents the previous page of the wizard.

type - The symbol representing the name of the event called event - The Java::Awt::Event that was triggered.

Returns nothing.



243
244
245
246
247
248
# File 'lib/smartermeter/interfaces/swing.rb', line 243

def show_previous_page(type, event)
  @page_index -= 1
  configure_buttons

  @panel.get_layout.previous(@panel)
end