Mercurial Hosting > luan
changeset 1892:3990486911d9 default tip
swing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Apr 2025 21:40:51 -0600 |
parents | 6a95ec46404a |
children | |
files | src/luan/modules/swing/Abstract_button.luan src/luan/modules/swing/Button.luan src/luan/modules/swing/Component.luan src/luan/modules/swing/Label.luan src/luan/modules/swing/Menu_item.luan src/luan/modules/swing/Scroll_pane.luan src/luan/modules/swing/SwingLuan.java src/luan/modules/swing/Text_field.luan |
diffstat | 8 files changed, 47 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/swing/Abstract_button.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Abstract_button.luan Fri Apr 11 21:40:51 2025 -0600 @@ -9,6 +9,8 @@ local super__new_index = Component.__new_index or error() local super_construct = Component.construct or error() require "java" +local SwingLuan = require "java:luan.modules.swing.SwingLuan" +local newActionListener = SwingLuan.newActionListener local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "swing/Abstract_button" @@ -45,6 +47,13 @@ if enabled~=nil then jbutton.setEnabled(enabled) end local margin = delete(props,"margin") if margin~=nil then jbutton.setMargin(margin) end + local action = delete(props,"action") + if action~=nil then jbutton.setActionCommand(action) end + local action_listener = delete(props,"action_listener") + if action_listener~=nil then jbutton.addActionListener(newActionListener(action_listener)) end + function button.add_action_listener(action_listener) + jbutton.addActionListener(newActionListener(action_listener)) + end button.set_enabled = jbutton.setEnabled return button end
--- a/src/luan/modules/swing/Button.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Button.luan Fri Apr 11 21:40:51 2025 -0600 @@ -1,6 +1,8 @@ local Luan = require "luan:Luan.luan" local error = Luan.error local set_metatable = Luan.set_metatable or error() +local Utils = require "luan:swing/Utils.luan" +local check_empty = Utils.check_empty or error() local Abstract_button = require "luan:swing/Abstract_button.luan" local super__index = Abstract_button.__index or error() local super__new_index = Abstract_button.__new_index or error() @@ -22,6 +24,7 @@ jbutton.setMargin(no_insets) local button = { java = jbutton } super_construct(button,props) + check_empty(props) set_metatable(button,super_mt) return button end
--- a/src/luan/modules/swing/Component.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Component.luan Fri Apr 11 21:40:51 2025 -0600 @@ -49,6 +49,7 @@ end local mt = make_metatable(Component) +Component.mt = mt local function construct(component,props) check_not_nil(props)
--- a/src/luan/modules/swing/Label.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Label.luan Fri Apr 11 21:40:51 2025 -0600 @@ -2,10 +2,13 @@ local error = Luan.error local set_metatable = Luan.set_metatable 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 Component = require "luan:swing/Component.luan" +local super__index = Component.__index or error() +local super__new_index = Component.__new_index or error() local super_construct = Component.construct or error() require "java" local JLabel = require "java:javax.swing.JLabel" @@ -13,7 +16,26 @@ local Label = {} -local mt = make_metatable(Component) +function Label.__index(label,key) + local rtn = super__index(label,key) + if rtn ~= fail then return rtn end + if key == "text" then + return label.java.getText() + end + return fail +end + +function Label.__new_index(label,key,value) + local rtn = super__new_index(label,key,value) + if rtn ~= fail then return end + if key == "text" then + label.java.setText(value) + return + end + return fail +end + +local mt = make_metatable(Label) function Label.new(props) local jlabel = JLabel.new()
--- a/src/luan/modules/swing/Menu_item.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Menu_item.luan Fri Apr 11 21:40:51 2025 -0600 @@ -15,8 +15,6 @@ local KeyStroke = require "java:javax.swing.KeyStroke" local KeyEvent = require "java:java.awt.event.KeyEvent" local InputEvent = require "java:java.awt.event.InputEvent" -local SwingLuan = require "java:luan.modules.swing.SwingLuan" -local newActionListener = SwingLuan.newActionListener local Menu_item = {} @@ -48,11 +46,6 @@ local jmenu_item = menu_item.java local accelerator = delete(props,"accelerator") if accelerator~=nil then jmenu_item.setAccelerator(KeyStroke.getKeyStroke(accelerator)) end - local action_listener = delete(props,"action_listener") - if action_listener~=nil then jmenu_item.addActionListener(newActionListener(action_listener)) end - function menu_item.add_action_listener(action_listener) - jmenu_item.addActionListener(newActionListener(action_listener)) - end return menu_item end Menu_item.construct = construct
--- a/src/luan/modules/swing/Scroll_pane.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Scroll_pane.luan Fri Apr 11 21:40:51 2025 -0600 @@ -7,14 +7,13 @@ local check_empty = Utils.check_empty or error() local Component = require "luan:swing/Component.luan" local super_construct = Component.construct or error() +local super_mt = Component.mt or error() require "java" local JScrollPane = require "java:javax.swing.JScrollPane" local Scroll_pane = {} -local mt = make_metatable(Component) - function Scroll_pane.new(props) local view = delete(props,"view") or error "view property requied" local jscroll_pane = JScrollPane.new(view.java) @@ -26,7 +25,7 @@ function scroll_pane.set_row_header_view(view) jscroll_pane.setRowHeaderView(view.java) end - set_metatable(scroll_pane,mt) + set_metatable(scroll_pane,super_mt) return scroll_pane end
--- a/src/luan/modules/swing/SwingLuan.java Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/SwingLuan.java Fri Apr 11 21:40:51 2025 -0600 @@ -67,6 +67,9 @@ if( component != null ) t.rawPut("source",component); } + String action = event.getActionCommand(); + if( action != null ) + t.rawPut("action",action); fn.call(luan,t); } catch(LuanException e) { //throw new LuanRuntimeException(e);
--- a/src/luan/modules/swing/Text_field.luan Fri Apr 11 13:26:53 2025 -0600 +++ b/src/luan/modules/swing/Text_field.luan Fri Apr 11 21:40:51 2025 -0600 @@ -9,6 +9,8 @@ local super_construct = Text_component.construct or error() require "java" local JTextField = require "java:javax.swing.JTextField" +local SwingLuan = require "java:luan.modules.swing.SwingLuan" +local newActionListener = SwingLuan.newActionListener local Text_field = {} @@ -21,6 +23,10 @@ super_construct(text_field,props) local columns = delete(props,"columns") if columns~=nil then jtext_field.setColumns(columns) end + local action = delete(props,"action") + if action~=nil then jtext_field.setActionCommand(action) end + local action_listener = delete(props,"action_listener") + if action_listener~=nil then jtext_field.addActionListener(newActionListener(action_listener)) end check_empty(props) set_metatable(text_field,mt) return text_field