annotate src/luan/modules/swing/List.luan @ 1735:4b56eff90040 default tip

add hosting.html
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 02 Oct 2022 17:32:00 -0600
parents 915cb538e2a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1616
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local set_metatable = Luan.set_metatable or error()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 require "java"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local JList = require "java:javax.swing.JList"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local DefaultListModel = require "java:javax.swing.DefaultListModel"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local List = {}
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local mt = {}
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 function mt.__index(list,key)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 if key == "size" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 return list.model.getSize()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 error("'"..key.."' not defined")
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 function mt.__new_index(list,key,value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 if key == "size" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 list.model.setSize(value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 return
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 error("'"..key.."' not defined")
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 function List.new()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 local model = DefaultListModel.new()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 local jlist = JList.new(model)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 local list = { java=jlist, model=model }
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 list.add_element = model.addElement
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 set_metatable(list,mt)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 return list
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 return List