Mercurial Hosting > luan
changeset 1898:49e2103ebf6a
swing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 14 Apr 2025 14:20:45 -0600 |
parents | 8ed184a0cde2 |
children | ef0438da68ae |
files | src/luan/modules/String.luan src/luan/modules/swing/Component.luan src/luan/modules/swing/Text_component.luan |
diffstat | 3 files changed, 32 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
diff -r 8ed184a0cde2 -r 49e2103ebf6a src/luan/modules/String.luan --- a/src/luan/modules/String.luan Mon Apr 14 12:46:45 2025 -0600 +++ b/src/luan/modules/String.luan Mon Apr 14 14:20:45 2025 -0600 @@ -1,6 +1,7 @@ require "java" local StringLuan = require "java:luan.modules.StringLuan" local Pattern = require "java:java.util.regex.Pattern" +local Matcher = require "java:java.util.regex.Matcher" local Boot = require "luan:Boot.luan" local String = {} @@ -17,6 +18,7 @@ String.lower = StringLuan.lower String.regex = Boot.regex String.regex_quote = Pattern.quote +String.regex_quote_replacement = Matcher.quoteReplacement String.repeated = StringLuan.repeated String.replace = StringLuan.replace String.reverse = StringLuan.reverse
diff -r 8ed184a0cde2 -r 49e2103ebf6a src/luan/modules/swing/Component.luan --- a/src/luan/modules/swing/Component.luan Mon Apr 14 12:46:45 2025 -0600 +++ b/src/luan/modules/swing/Component.luan Mon Apr 14 14:20:45 2025 -0600 @@ -90,6 +90,8 @@ alignment_x = alignments[alignment_x] or error "invalid alignment_x" jcomponent.setAlignmentX(alignment_x) end + local tool_tip_text = delete(props,"tool_tip_text") + if tool_tip_text~=nil then jcomponent.setToolTipText(tool_tip_text) end component.constraints = delete(props,"constraints") local children = delete(props,"children") if children~=nil then
diff -r 8ed184a0cde2 -r 49e2103ebf6a src/luan/modules/swing/Text_component.luan --- a/src/luan/modules/swing/Text_component.luan Mon Apr 14 12:46:45 2025 -0600 +++ b/src/luan/modules/swing/Text_component.luan Mon Apr 14 14:20:45 2025 -0600 @@ -19,30 +19,48 @@ local Text_component = {} -function Text_component.__index(text_component,key) - local rtn = super__index(text_component,key) +function Text_component.__index(component,key) + local rtn = super__index(component,key) if rtn ~= fail then return rtn end + local jcomponent = component.java if key == "text" then - return text_component.java.getText() + return jcomponent.getText() end if key == "document" then - local document = new_document(text_component.java.getDocument()) - raw_set(text_component,"document",document) + local document = new_document(jcomponent.getDocument()) + raw_set(component,"document",document) return document end + if key == "selected_text" then + return jcomponent.getSelectedText() or "" + end return fail end -function Text_component.__new_index(text_component,key,value) - local rtn = super__new_index(text_component,key,value) +function Text_component.__new_index(component,key,value) + local rtn = super__new_index(component,key,value) if rtn ~= fail then return end + local jcomponent = component.java if key == "text" then - text_component.java.setText(value) + jcomponent.setText(value) return end if key == "document" then - text_component.java.setDocument(value.java) - raw_set(text_component,"document",value) + jcomponent.setDocument(value.java) + raw_set(component,"document",value) + return + end + if key == "selected_text" then + local document = jcomponent.getDocument() + local start = jcomponent.getSelectionStart() + local end_ = jcomponent.getSelectionEnd() + if end_ > start then + document.remove( start, end_ - start ) + end + if #value > 0 then + document.insertString( start, value, nil ) + end + jcomponent.select( start, start + #value ) return end return fail