1616
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local set_metatable = Luan.set_metatable or error()
|
1937
|
4 local ipairs = Luan.ipairs or error()
|
1863
|
5 local Utils = require "luan:swing/Utils.luan"
|
|
6 local fail = Utils.fail or error()
|
|
7 local make_metatable = Utils.make_metatable or error()
|
1944
|
8 local remove = Utils.remove or error()
|
1887
|
9 local check_empty = Utils.check_empty or error()
|
1939
|
10 local Awt_window = require "luan:swing/Awt_window.luan"
|
|
11 local super__index = Awt_window.__index or error()
|
|
12 local super__new_index = Awt_window.__new_index or error()
|
|
13 local super_construct = Awt_window.construct or error()
|
1616
|
14 require "java"
|
|
15 local JFrame = require "java:javax.swing.JFrame"
|
1863
|
16 local Logging = require "luan:logging/Logging.luan"
|
|
17 local logger = Logging.logger "swing/Frame"
|
|
18
|
1616
|
19
|
|
20
|
|
21 local Frame = {}
|
|
22
|
1863
|
23 function Frame.__index(frame,key)
|
1914
|
24 local rtn = super__index(frame,key)
|
|
25 if rtn ~= fail then return rtn end
|
1937
|
26 local jframe = frame.java
|
1862
|
27 if key == "title" then
|
1937
|
28 return jframe.getTitle()
|
1862
|
29 end
|
1863
|
30 return fail
|
1616
|
31 end
|
|
32
|
1863
|
33 function Frame.__new_index(frame,key,value)
|
1914
|
34 local rtn = super__new_index(frame,key,value)
|
|
35 if rtn ~= fail then return end
|
1937
|
36 local jframe = frame.java
|
1862
|
37 if key == "title" then
|
1937
|
38 jframe.setTitle(value)
|
|
39 return
|
|
40 end
|
1863
|
41 return fail
|
|
42 end
|
|
43
|
|
44 local mt = make_metatable(Frame)
|
|
45
|
1937
|
46 local function new2(frame,props)
|
1914
|
47 super_construct(frame,props)
|
1937
|
48 local jframe = frame.java
|
1944
|
49 local content_pane = remove(props,"content_pane")
|
1887
|
50 if content_pane~=nil then jframe.setContentPane(content_pane.java) end
|
|
51 check_empty(props)
|
1862
|
52 function frame.set_menu_bar(menu_bar)
|
|
53 jframe.setJMenuBar(menu_bar.java)
|
|
54 end
|
1616
|
55 set_metatable(frame,mt)
|
|
56 return frame
|
|
57 end
|
|
58
|
1937
|
59 function Frame.new(props)
|
|
60 local jframe = JFrame.new()
|
|
61 jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
62 return new2( {java=jframe}, props )
|
|
63 end
|
|
64
|
|
65 function Frame.get_all_frames()
|
|
66 local all = {}
|
|
67 local no_props = {}
|
|
68 for _, jframe in ipairs{JFrame.getFrames()} do
|
|
69 all[#all+1] = new2( {java=jframe}, no_props )
|
|
70 end
|
|
71 return all
|
|
72 end
|
|
73
|
1616
|
74 return Frame
|