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()
|
1887
|
8 local delete = Utils.delete or error()
|
|
9 local check_empty = Utils.check_empty or error()
|
1937
|
10 local to_dimension = Utils.to_dimension or error()
|
1914
|
11 local Awt_container = require "luan:swing/Awt_container.luan"
|
|
12 local super__index = Awt_container.__index or error()
|
|
13 local super__new_index = Awt_container.__new_index or error()
|
|
14 local super_construct = Awt_container.construct or error()
|
1616
|
15 require "java"
|
|
16 local JFrame = require "java:javax.swing.JFrame"
|
1862
|
17 local SwingLuan = require "java:luan.modules.swing.SwingLuan"
|
|
18 local newCloseListener = SwingLuan.newCloseListener
|
1937
|
19 local newWindowFocusListener = SwingLuan.newWindowFocusListener
|
1863
|
20 local Logging = require "luan:logging/Logging.luan"
|
|
21 local logger = Logging.logger "swing/Frame"
|
|
22
|
1616
|
23
|
|
24
|
|
25 local Frame = {}
|
|
26
|
1863
|
27 function Frame.__index(frame,key)
|
1914
|
28 local rtn = super__index(frame,key)
|
|
29 if rtn ~= fail then return rtn end
|
1937
|
30 local jframe = frame.java
|
1862
|
31 if key == "title" then
|
1937
|
32 return jframe.getTitle()
|
1862
|
33 end
|
1863
|
34 return fail
|
1616
|
35 end
|
|
36
|
1863
|
37 function Frame.__new_index(frame,key,value)
|
1914
|
38 local rtn = super__new_index(frame,key,value)
|
|
39 if rtn ~= fail then return end
|
1937
|
40 local jframe = frame.java
|
1616
|
41 if key == "visible" then
|
1937
|
42 jframe.setVisible(value)
|
1616
|
43 return
|
|
44 end
|
1862
|
45 if key == "title" then
|
1937
|
46 jframe.setTitle(value)
|
|
47 return
|
|
48 end
|
|
49 if key == "size" then
|
|
50 jframe.setSize(to_dimension(value))
|
1862
|
51 return
|
|
52 end
|
1863
|
53 return fail
|
|
54 end
|
|
55
|
|
56 local mt = make_metatable(Frame)
|
|
57
|
1937
|
58 local function new2(frame,props)
|
1914
|
59 super_construct(frame,props)
|
1937
|
60 local jframe = frame.java
|
1887
|
61 local content_pane = delete(props,"content_pane")
|
|
62 if content_pane~=nil then jframe.setContentPane(content_pane.java) end
|
|
63 check_empty(props)
|
1862
|
64 function frame.add_close_listener(close_listener)
|
|
65 jframe.addWindowListener(newCloseListener(close_listener))
|
1616
|
66 end
|
1937
|
67 function frame.add_window_focus_listener(window_focus_listener)
|
|
68 jframe.addWindowFocusListener(newWindowFocusListener(window_focus_listener))
|
|
69 end
|
1862
|
70 function frame.set_menu_bar(menu_bar)
|
|
71 jframe.setJMenuBar(menu_bar.java)
|
|
72 end
|
1616
|
73 frame.pack = jframe.pack
|
|
74 set_metatable(frame,mt)
|
|
75 return frame
|
|
76 end
|
|
77
|
1937
|
78 function Frame.new(props)
|
|
79 local jframe = JFrame.new()
|
|
80 jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
81 return new2( {java=jframe}, props )
|
|
82 end
|
|
83
|
|
84 function Frame.get_all_frames()
|
|
85 local all = {}
|
|
86 local no_props = {}
|
|
87 for _, jframe in ipairs{JFrame.getFrames()} do
|
|
88 all[#all+1] = new2( {java=jframe}, no_props )
|
|
89 end
|
|
90 return all
|
|
91 end
|
|
92
|
1616
|
93 return Frame
|