changeset 1941:fb9563144b34

swing
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 18 May 2025 18:47:06 -0600
parents 5a79d8b92f74
children a25b7963a792
files src/luan/modules/swing/Abstract_button.luan src/luan/modules/swing/Awt_container.luan src/luan/modules/swing/Awt_window.luan src/luan/modules/swing/Component.luan src/luan/modules/swing/SwingLuan.java
diffstat 5 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/swing/Abstract_button.luan	Sun May 18 14:36:52 2025 -0600
+++ b/src/luan/modules/swing/Abstract_button.luan	Sun May 18 18:47:06 2025 -0600
@@ -14,6 +14,7 @@
 local KeyEvent = require "java:java.awt.event.KeyEvent"
 local SwingLuan = require "java:luan.modules.swing.SwingLuan"
 local newActionListener = SwingLuan.newActionListener
+local newChangeListener = SwingLuan.newChangeListener
 local SwingConstants = require "java:javax.swing.SwingConstants"
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "swing/Abstract_button"
@@ -71,6 +72,8 @@
 	if mnemonic~=nil then jbutton.setMnemonic(KeyEvent.getExtendedKeyCodeForChar(char_to_int(mnemonic))) end
 	local action_listener = delete(props,"action_listener")
 	if action_listener~=nil then jbutton.addActionListener(newActionListener(action_listener)) end
+	local change_listener = delete(props,"change_listener")
+	if change_listener~=nil then jbutton.addChangeListener(newChangeListener(change_listener)) end
 	local horizontal_alignment = delete(props,"horizontal_alignment")
 	if horizontal_alignment~=nil then
 		local align = alignments[horizontal_alignment] or error "invalid horizontal_alignment"
@@ -84,6 +87,9 @@
 	function button.add_action_listener(action_listener)
 		jbutton.addActionListener(newActionListener(action_listener))
 	end
+	function button.add_change_listener(change_listener)
+		jbutton.addChangeListener(newChangeListener(change_listener))
+	end
 	button.set_enabled = jbutton.setEnabled
 	return button
 end
--- a/src/luan/modules/swing/Awt_container.luan	Sun May 18 14:36:52 2025 -0600
+++ b/src/luan/modules/swing/Awt_container.luan	Sun May 18 18:47:06 2025 -0600
@@ -77,6 +77,8 @@
 	function component.add_move_stopped_listener( time_after_stopped, fn )
 		notifyAfterMoveStops( jcomponent, newMoveListener(fn), time_after_stopped )
 	end
+	component.request_focus_in_window = jcomponent.requestFocusInWindow
+	component.request_focus = jcomponent.requestFocus
 	return component
 end
 
--- a/src/luan/modules/swing/Awt_window.luan	Sun May 18 14:36:52 2025 -0600
+++ b/src/luan/modules/swing/Awt_window.luan	Sun May 18 18:47:06 2025 -0600
@@ -2,6 +2,7 @@
 local error = Luan.error
 local Utils = require "luan:swing/Utils.luan"
 local fail = Utils.fail or error()
+local delete = Utils.delete or error()
 local to_dimension = Utils.to_dimension or error()
 local Awt_container = require "luan:swing/Awt_container.luan"
 local super__index = Awt_container.__index or error()
@@ -40,6 +41,8 @@
 function Awt_window.construct(window,props)
 	super_construct(window,props)
 	local jwindow = window.java
+	local focusable_window_state = delete(props,"focusable_window_state")
+	if focusable_window_state~=nil then jwindow.setFocusableWindowState(focusable_window_state) end
 	function window.add_close_listener(close_listener)
 		jwindow.addWindowListener(newCloseListener(close_listener))
 	end
--- a/src/luan/modules/swing/Component.luan	Sun May 18 14:36:52 2025 -0600
+++ b/src/luan/modules/swing/Component.luan	Sun May 18 18:47:06 2025 -0600
@@ -100,7 +100,6 @@
 			jcomponent.add(child.java,child.constraints)
 		end
 	end
-	component.request_focus_in_window = jcomponent.requestFocusInWindow
 	component.set_font = set_font
 	component._dont_gc = {}
 	function component.dont_gc(obj)
--- a/src/luan/modules/swing/SwingLuan.java	Sun May 18 14:36:52 2025 -0600
+++ b/src/luan/modules/swing/SwingLuan.java	Sun May 18 18:47:06 2025 -0600
@@ -7,6 +7,8 @@
 import javax.swing.AbstractAction;
 import javax.swing.JComponent;
 import javax.swing.Timer;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ChangeEvent;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.Document;
 import javax.swing.undo.UndoManager;
@@ -156,6 +158,18 @@
 		};
 	}
 
+	public static ChangeListener newChangeListener(final Luan luan,LuanFunction fn) {
+		return new ChangeListener() {
+			@Override public void stateChanged(ChangeEvent event) {
+				try {
+					fn.call(luan);
+				} catch(LuanException e) {
+					exception(e);
+				}
+			}
+		};
+	}
+
 	public static void notifyAfterMoveStops(Component comp,final ComponentListener cl,int timeAfterStopped) {
 		comp.addComponentListener( new ComponentAdapter() {
 			ComponentEvent event;