Mercurial Hosting > luan
changeset 1885:d1708f8d4923 default tip
swing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 08 Apr 2025 23:02:14 -0600 |
parents | 55ad3e7cd01a |
children | |
files | src/luan/modules/swing/Abstract_button.luan src/luan/modules/swing/Button.luan src/luan/modules/swing/Check_box_menu_item.luan src/luan/modules/swing/Component.luan src/luan/modules/swing/Menu.luan src/luan/modules/swing/Menu_bar.luan src/luan/modules/swing/Menu_item.luan src/luan/modules/swing/Scroll_pane.luan src/luan/modules/swing/Text_area.luan src/luan/modules/swing/Text_area_line_numbers.luan src/luan/modules/swing/Text_component.luan |
diffstat | 11 files changed, 45 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/swing/Abstract_button.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Abstract_button.luan Tue Apr 08 23:02:14 2025 -0600 @@ -35,7 +35,7 @@ Abstract_button.mt = make_metatable(Abstract_button) local function construct(button,props) - super_construct(button) + super_construct(button,props) local jbutton = button.java local text = delete(props,"text") if text~=nil then jbutton.setText(text) end
--- a/src/luan/modules/swing/Button.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Button.luan Tue Apr 08 23:02:14 2025 -0600 @@ -13,7 +13,6 @@ local Button = {} function Button.new(props) - props = props or {} local button = { java = JButton.new() } super_construct(button,props) set_metatable(button,super_mt)
--- a/src/luan/modules/swing/Check_box_menu_item.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Check_box_menu_item.luan Tue Apr 08 23:02:14 2025 -0600 @@ -38,12 +38,11 @@ local mt = make_metatable(Check_box_menu_item) function Check_box_menu_item.new(props) - props = props or {} local jcbmi = JCheckBoxMenuItem.new() local cbmi = { java = jcbmi } + super_construct(cbmi,props) local state = delete(props,"state") if state~=nil then jcbmi.setState(state) end - super_construct(cbmi,props) check_empty(props) set_metatable(cbmi,mt) return cbmi
--- a/src/luan/modules/swing/Component.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Component.luan Tue Apr 08 23:02:14 2025 -0600 @@ -2,11 +2,13 @@ local error = Luan.error local type = Luan.type or error() local set_metatable = Luan.set_metatable or error() +local ipairs = Luan.ipairs or error() local Utils = require "luan:swing/Utils.luan" local fail = Utils.fail or error() local make_metatable = Utils.make_metatable or error() local delete = Utils.delete or error() local check_empty = Utils.check_empty or error() +local check_not_nil = Utils.check_not_nil or error() local get_font = require("luan:swing/Font.luan").get or error() require "java" local JPanel = require "java:javax.swing.JPanel" @@ -41,8 +43,19 @@ local mt = make_metatable(Component) local function construct(component,props) + check_not_nil(props) local jcomponent = component.java jcomponent.putClientProperty("luan",component) -- don't gc + local layout = delete(props,"layout") + if layout~=nil then jcomponent.setLayout(layout) end + local border = delete(props,"border") + if border~=nil then jcomponent.setBorder(border) end + local children = delete(props,"children") + if children~=nil then + for _, child in ipairs(children) do + jcomponent.add(child.java) + end + end component.request_focus_in_window = jcomponent.requestFocusInWindow function component.set_font(font) if type(font) == "table" then @@ -58,6 +71,11 @@ function component.add(el) jcomponent.add(el.java) end + function component.add_all(list) + for _, child in ipairs(list) do + jcomponent.add(child.java) + end + end return component end Component.construct = construct @@ -72,6 +90,7 @@ function Component.new_panel(props) local panel = { java = JPanel.new() } construct(panel,props) + check_empty(props) set_metatable(panel,mt) return panel end
--- a/src/luan/modules/swing/Menu.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Menu.luan Tue Apr 08 23:02:14 2025 -0600 @@ -24,7 +24,6 @@ Menu.separator = separator function Menu.new(props) - props = props or {} local jmenu = JMenu.new() local menu = { java = jmenu } super_construct(menu,props)
--- a/src/luan/modules/swing/Menu_bar.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Menu_bar.luan Tue Apr 08 23:02:14 2025 -0600 @@ -5,7 +5,6 @@ local Utils = require "luan:swing/Utils.luan" local make_metatable = Utils.make_metatable or error() local check_empty = Utils.check_empty or error() -local check_not_nil = Utils.check_not_nil or error() local delete = Utils.delete or error() local Component = require "luan:swing/Component.luan" local super_construct = Component.construct or error() @@ -18,10 +17,9 @@ local mt = make_metatable(Component) function Menu_bar.new(props) - check_not_nil(props) local jmenu_bar = JMenuBar.new() local menu_bar = { java = jmenu_bar } - super_construct(menu_bar) + super_construct(menu_bar,props) local menus = delete(props,"menus") if menus~=nil then for _, menu in ipairs(menus) do
--- a/src/luan/modules/swing/Menu_item.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Menu_item.luan Tue Apr 08 23:02:14 2025 -0600 @@ -58,7 +58,6 @@ Menu_item.construct = construct function Menu_item.new(props) - props = props or {} local jmenu_item = JMenuItem.new() local menu_item = { java = jmenu_item } menu_item = construct(menu_item,props)
--- a/src/luan/modules/swing/Scroll_pane.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Scroll_pane.luan Tue Apr 08 23:02:14 2025 -0600 @@ -3,6 +3,8 @@ local set_metatable = Luan.set_metatable or error() local Utils = require "luan:swing/Utils.luan" local make_metatable = Utils.make_metatable or error() +local delete = Utils.delete or error() +local check_empty = Utils.check_empty or error() local Component = require "luan:swing/Component.luan" local super_construct = Component.construct or error() require "java" @@ -13,10 +15,12 @@ local mt = make_metatable(Component) -function Scroll_pane.new(view) +function Scroll_pane.new(props) + local view = delete(props,"view") or error "view property requied" local jscroll_pane = JScrollPane.new(view.java) local scroll_pane = { java = jscroll_pane } - super_construct(scroll_pane) + super_construct(scroll_pane,props) + check_empty(props) function scroll_pane.set_row_header_view(view) jscroll_pane.setRowHeaderView(view.java) end
--- a/src/luan/modules/swing/Text_area.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Text_area.luan Tue Apr 08 23:02:14 2025 -0600 @@ -4,10 +4,11 @@ local Utils = require "luan:swing/Utils.luan" local fail = Utils.fail or error() local make_metatable = Utils.make_metatable or error() +local check_empty = Utils.check_empty or error() local Text_component = require("luan:swing/Text_component.luan") local super__index = Text_component.__index or error() local super__new_index = Text_component.__new_index or error() -local new_text_component = Text_component.new or error() +local super_construct = Text_component.construct or error() require "java" local TextAreaLuan = require "java:luan.modules.swing.TextAreaLuan" @@ -66,10 +67,11 @@ local mt = make_metatable(Text_area) -function Text_area.new() - local text_area = { java = TextAreaLuan.new() } - new_text_component(text_area) - local jtext_area = text_area.java +function Text_area.new(props) + local jtext_area = TextAreaLuan.new() + local text_area = { java = jtext_area } + super_construct(text_area,props) + check_empty(props) text_area.show_whitespace = jtext_area.showWhitespace function text_area.get_line_from_position(pos) return jtext_area.getLineOfOffset(pos-1) + 1
--- a/src/luan/modules/swing/Text_area_line_numbers.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Text_area_line_numbers.luan Tue Apr 08 23:02:14 2025 -0600 @@ -3,8 +3,10 @@ local set_metatable = Luan.set_metatable or error() local Utils = require "luan:swing/Utils.luan" local make_metatable = Utils.make_metatable or error() +local delete = Utils.delete or error() +local check_empty = Utils.check_empty or error() local Component = require "luan:swing/Component.luan" -local super = Component.construct or error() +local super_construct = Component.construct or error() require "java" local TextAreaLineNumbersLuan = require "java:luan.modules.swing.TextAreaLineNumbersLuan" @@ -13,10 +15,12 @@ local mt = make_metatable(Component) -function TextAreaLineNumbers.new(text_area) +function TextAreaLineNumbers.new(props) + local text_area = delete(props,"text_area") or error "text_area property requied" local jtaln = TextAreaLineNumbersLuan.new(text_area.java) local taln = { java = jtaln } - super(taln) + super_construct(taln,props) + check_empty(props) set_metatable(taln,mt) return taln end
--- a/src/luan/modules/swing/Text_component.luan Tue Apr 08 19:43:00 2025 -0600 +++ b/src/luan/modules/swing/Text_component.luan Tue Apr 08 23:02:14 2025 -0600 @@ -7,7 +7,7 @@ local Component = require "luan:swing/Component.luan" local super__index = Component.__index or error() local super__new_index = Component.__new_index or error() -local super = Component.construct or error() +local super_construct = Component.construct or error() local new_document = require("luan:swing/Document.luan").new or error() require "java" local SwingLuan = require "java:luan.modules.swing.SwingLuan" @@ -47,8 +47,8 @@ return fail end -function Text_component.new(component) - super(component) +function Text_component.construct(component,props) + super_construct(component,props) local jcomponent = component.java fixTextComponent(jcomponent) component.cut = jcomponent.cut