annotate src/luan/modules/swing/Text_area.luan @ 1745:f8950d99f47d default tip

add Lucene.type.float
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 11:53:18 -0700
parents 915cb538e2a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1616
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local set_metatable = Luan.set_metatable or error()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local type = Luan.type or error()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Font = require "luan:swing/Font.luan"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 require "java"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local JTextArea = require "java:javax.swing.JTextArea"
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Text_area = {}
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local mt = {}
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 function mt.__index(text_area,key)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 if key == "line_wrap" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 return text_area.java.getLineWrap()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 if key == "wrap_style_word" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 return text_area.java.getWrapStyleWord()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 if key == "tab_size" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 return text_area.java.getTabSize()
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 error("'"..key.."' not defined")
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 function mt.__new_index(text_area,key,value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 if key == "line_wrap" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 text_area.java.setLineWrap(value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 return
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 if key == "wrap_style_word" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 text_area.java.setWrapStyleWord(value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 return
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 if key == "tab_size" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 text_area.java.setTabSize(value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 return
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 if key == "font" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 if type(value) == "table" then
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 value = Font.get(value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 text_area.java.setFont(value)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 return
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 error("'"..key.."' not defined")
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 function Text_area.new(rows,columns)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 local jtext_area = JTextArea.new(rows,columns)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 local text_area = { java = jtext_area }
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 set_metatable(text_area,mt)
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 return text_area
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 end
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56
915cb538e2a3 start swing
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 return Text_area