view src/luan/modules/swing/Component.luan @ 1873:cf38353d77bd default tip

swing
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Apr 2025 16:17:56 -0600
parents 29a1e9bde185
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local type = Luan.type or error()
local Utils = require "luan:swing/Utils.luan"
local fail = Utils.fail or error()
local get_font = require("luan:swing/Font.luan").get or error()
require "java"


local Component = {}

function Component.__index(component,key)
	if key == "foreground_color" then
		return component.java.getForeground()
	end
	return fail
end

function Component.__new_index(component,key,value)
	if key == "foreground_color" then
		component.java.setForeground(value)
		return
	end
	return fail
end

function Component.new(component)
	local jcomponent = component.java
	jcomponent.putClientProperty("luan",component)  -- don't gc
	component.request_focus_in_window = jcomponent.requestFocusInWindow
	function component.set_font(font)
		if type(font) == "table" then
			font = get_font(font)
		end
		jcomponent.setFont(font)
	end
	component._dont_gc = {}
	function component.dont_gc(obj)
		component._dont_gc[obj] = true
	end
	return component
end

return Component