Sha256: 9771266bcd601630bade62d16d0030017e461463844be981c47188f7a4ea4329

Contents?: true

Size: 934 Bytes

Versions: 13

Compression:

Stored size: 934 Bytes

Contents

require 'swing/menu'
require 'swing/menu_item'
require 'swing/attr_setter'

module Swing

  class MenuBar < javax.swing.JMenuBar
    include AttrSetter

    def initialize opts = {}
      set_attributes(opts) { super() }

      if opts[:structure]
        [opts[:structure]].flatten.each do |element|
          case element
            when Hash # Hash defines menu structure
              element.each do |menu_name, menu_structure|
                menu = Menu.new menu_name.to_s, :parent => self
                menu_structure.each do |item_name, item_action|
                  MenuItem.new item_name.to_s, :parent => menu, &item_action
                end
              end
            else
              self.add element
          end
        end
      end
    end
  end

  # Post-processing (non-setter) options given to initialize
  def self.add_component component, parent
    parent.setJMenuBar component if parent
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
swing-0.1.16 lib/swing/old/menu_bar.rb
swing-0.1.15 lib/swing/old/menu_bar.rb
swing-0.1.14 lib/swing/old/menu_bar.rb
swing-0.1.12 lib/swing/old/menu_bar.rb
swing-0.1.10 lib/swing/old/menu_bar.rb
swing-0.1.8 lib/swing/old/menu_bar.rb
swing-0.1.7 lib/swing/old/menu_bar.rb
swing-0.1.5 lib/swing/old/menu_bar.rb
swing-0.1.4 lib/swing/old/menu_bar.rb
swing-0.1.3 lib/swing/old/menu_bar.rb
swing-0.1.2 lib/swing/old/menu_bar.rb
swing-0.1.1 lib/swing/old/menu_bar.rb
swing-0.1.0 lib/swing/old/menu_bar.rb