changeset 1886:03a8924fe9bc

swing
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 09 Apr 2025 08:56:54 -0600
parents d1708f8d4923
children bea843af3422
files src/luan/modules/swing/Component.luan src/luan/modules/swing/Dialog.luan
diffstat 2 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/swing/Component.luan	Tue Apr 08 23:02:14 2025 -0600
+++ b/src/luan/modules/swing/Component.luan	Wed Apr 09 08:56:54 2025 -0600
@@ -47,7 +47,12 @@
 	local jcomponent = component.java
 	jcomponent.putClientProperty("luan",component)  -- don't gc
 	local layout = delete(props,"layout")
-	if layout~=nil then jcomponent.setLayout(layout) end
+	if layout~=nil then
+		if type(layout) == "function" then
+			layout = layout(component)
+		end
+		jcomponent.setLayout(layout)
+	end
 	local border = delete(props,"border")
 	if border~=nil then jcomponent.setBorder(border) end
 	local children = delete(props,"children")
--- a/src/luan/modules/swing/Dialog.luan	Tue Apr 08 23:02:14 2025 -0600
+++ b/src/luan/modules/swing/Dialog.luan	Wed Apr 09 08:56:54 2025 -0600
@@ -4,6 +4,9 @@
 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 new_component = require("luan:swing/Component.luan").new_component or error()
 require "java"
 local JDialog = require "java:javax.swing.JDialog"
@@ -40,14 +43,17 @@
 
 local mt = make_metatable(Dialog)
 
-function Dialog.new(frame)
-	local jframe = frame.java
-	local jdialog = JDialog.new(jframe)
---logger.info(jdialog.getContentPane())
+function Dialog.new(props)
+	check_not_nil(props)
+	local owner_frame = delete(props,"owner_frame")
+	local jdialog = owner_frame and JDialog.new(owner_frame.java)
 	local dialog = { java = jdialog }
+	local content_pane = delete(props,"content_pane")
+	if content_pane~=nil then jdialog.setContentPane(content_pane.java) end
+	check_empty(props)
 	dialog.pack = jdialog.pack
 	function dialog.move_into_owner()
-		jdialog.setLocationRelativeTo(jframe)
+		jdialog.setLocationRelativeTo(jdialog.getOwner())
 	end
 	set_metatable(dialog,mt)
 	return dialog