view src/luan/modules/swing/List.luan @ 1722:7d2ab44f7a59 default tip

remove String regex fns
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 29 Jul 2022 14:12:01 -0600
parents 915cb538e2a3
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local set_metatable = Luan.set_metatable or error()
require "java"
local JList = require "java:javax.swing.JList"
local DefaultListModel = require "java:javax.swing.DefaultListModel"


local List = {}

local mt = {}

function mt.__index(list,key)
	if key == "size" then
		return list.model.getSize()
	end
	error("'"..key.."' not defined")
end

function mt.__new_index(list,key,value)
	if key == "size" then
		list.model.setSize(value)
		return
	end
	error("'"..key.."' not defined")
end

function List.new()
	local model = DefaultListModel.new()
	local jlist = JList.new(model)
	local list = { java=jlist, model=model }
	list.add_element = model.addElement
	set_metatable(list,mt)
	return list
end

return List