glimmer-dsl-swt 4.17.3.0 → 4.17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +126 -454
- data/VERSION +1 -1
- data/glimmer-dsl-swt.gemspec +9 -6
- data/lib/glimmer-dsl-swt.rb +1 -0
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +1 -0
- data/lib/glimmer/dsl/swt/widget_expression.rb +1 -0
- data/lib/glimmer/rake_task.rb +4 -21
- data/lib/glimmer/swt/custom/code_text.rb +88 -0
- data/lib/glimmer/swt/message_box_proxy.rb +1 -1
- data/lib/glimmer/swt/sash_form_proxy.rb +53 -0
- data/lib/glimmer/swt/widget_proxy.rb +1 -1
- data/samples/elaborate/meta_sample.rb +166 -0
- data/samples/hello/hello_sash_form.rb +137 -0
- metadata +11 -8
- data/lib/glimmer/rake_task/sample.rb +0 -115
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.17.
|
1
|
+
4.17.4.0
|
data/glimmer-dsl-swt.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: glimmer-dsl-swt 4.17.
|
5
|
+
# stub: glimmer-dsl-swt 4.17.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "glimmer-dsl-swt".freeze
|
9
|
-
s.version = "4.17.
|
9
|
+
s.version = "4.17.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["AndyMaleh".freeze]
|
14
|
-
s.date = "2020-10-
|
14
|
+
s.date = "2020-10-21"
|
15
15
|
s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Library)".freeze
|
16
16
|
s.email = "andy.am@gmail.com".freeze
|
17
17
|
s.executables = ["glimmer".freeze, "girb".freeze]
|
@@ -81,10 +81,10 @@ Gem::Specification.new do |s|
|
|
81
81
|
"lib/glimmer/rake_task.rb",
|
82
82
|
"lib/glimmer/rake_task/list.rb",
|
83
83
|
"lib/glimmer/rake_task/package.rb",
|
84
|
-
"lib/glimmer/rake_task/sample.rb",
|
85
84
|
"lib/glimmer/rake_task/scaffold.rb",
|
86
85
|
"lib/glimmer/swt/color_proxy.rb",
|
87
86
|
"lib/glimmer/swt/cursor_proxy.rb",
|
87
|
+
"lib/glimmer/swt/custom/code_text.rb",
|
88
88
|
"lib/glimmer/swt/display_proxy.rb",
|
89
89
|
"lib/glimmer/swt/dnd_proxy.rb",
|
90
90
|
"lib/glimmer/swt/font_proxy.rb",
|
@@ -94,6 +94,7 @@ Gem::Specification.new do |s|
|
|
94
94
|
"lib/glimmer/swt/menu_proxy.rb",
|
95
95
|
"lib/glimmer/swt/message_box_proxy.rb",
|
96
96
|
"lib/glimmer/swt/packages.rb",
|
97
|
+
"lib/glimmer/swt/sash_form_proxy.rb",
|
97
98
|
"lib/glimmer/swt/scrolled_composite_proxy.rb",
|
98
99
|
"lib/glimmer/swt/shell_proxy.rb",
|
99
100
|
"lib/glimmer/swt/style_constantizable.rb",
|
@@ -112,6 +113,7 @@ Gem::Specification.new do |s|
|
|
112
113
|
"samples/elaborate/contact_manager/contact_manager_presenter.rb",
|
113
114
|
"samples/elaborate/contact_manager/contact_repository.rb",
|
114
115
|
"samples/elaborate/login.rb",
|
116
|
+
"samples/elaborate/meta_sample.rb",
|
115
117
|
"samples/elaborate/tic_tac_toe.rb",
|
116
118
|
"samples/elaborate/tic_tac_toe/board.rb",
|
117
119
|
"samples/elaborate/tic_tac_toe/cell.rb",
|
@@ -128,6 +130,7 @@ Gem::Specification.new do |s|
|
|
128
130
|
"samples/hello/hello_menu_bar.rb",
|
129
131
|
"samples/hello/hello_message_box.rb",
|
130
132
|
"samples/hello/hello_pop_up_context_menu.rb",
|
133
|
+
"samples/hello/hello_sash_form.rb",
|
131
134
|
"samples/hello/hello_tab.rb",
|
132
135
|
"samples/hello/hello_world.rb",
|
133
136
|
"vendor/swt/linux/swt.jar",
|
@@ -155,7 +158,7 @@ Gem::Specification.new do |s|
|
|
155
158
|
s.add_runtime_dependency(%q<os>.freeze, [">= 1.0.0", "< 2.0.0"])
|
156
159
|
s.add_runtime_dependency(%q<rake>.freeze, [">= 10.1.0", "< 14.0.0"])
|
157
160
|
s.add_runtime_dependency(%q<text-table>.freeze, [">= 1.2.4", "< 2.0.0"])
|
158
|
-
s.add_runtime_dependency(%q<
|
161
|
+
s.add_runtime_dependency(%q<rouge>.freeze, [">= 3.23.0", "< 4.0.0"])
|
159
162
|
s.add_development_dependency(%q<juwelier>.freeze, [">= 2.4.9", "< 3.0.0"])
|
160
163
|
s.add_development_dependency(%q<warbler>.freeze, [">= 2.0.5", "< 3.0.0"])
|
161
164
|
s.add_development_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
|
@@ -174,7 +177,7 @@ Gem::Specification.new do |s|
|
|
174
177
|
s.add_dependency(%q<os>.freeze, [">= 1.0.0", "< 2.0.0"])
|
175
178
|
s.add_dependency(%q<rake>.freeze, [">= 10.1.0", "< 14.0.0"])
|
176
179
|
s.add_dependency(%q<text-table>.freeze, [">= 1.2.4", "< 2.0.0"])
|
177
|
-
s.add_dependency(%q<
|
180
|
+
s.add_dependency(%q<rouge>.freeze, [">= 3.23.0", "< 4.0.0"])
|
178
181
|
s.add_dependency(%q<juwelier>.freeze, [">= 2.4.9", "< 3.0.0"])
|
179
182
|
s.add_dependency(%q<warbler>.freeze, [">= 2.0.5", "< 3.0.0"])
|
180
183
|
s.add_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
|
data/lib/glimmer-dsl-swt.rb
CHANGED
data/lib/glimmer/rake_task.rb
CHANGED
@@ -62,26 +62,9 @@ namespace :glimmer do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
desc 'Runs a Glimmer internal sample [included in gem]. If no name is supplied, it runs all samples.'
|
71
|
-
task :run, [:name] => [:requires] do |t, args|
|
72
|
-
Glimmer::RakeTask::Sample.run(args[:name])
|
73
|
-
end
|
74
|
-
|
75
|
-
desc 'Lists Glimmer internal samples [included in gem]. Filters by query if specified (query is optional)'
|
76
|
-
task :list, [:query] => [:requires] do |t, args|
|
77
|
-
Glimmer::RakeTask::Sample.list(args[:query])
|
78
|
-
end
|
79
|
-
|
80
|
-
desc 'Outputs code for a Glimmer internal sample [included in gem] (name is required)'
|
81
|
-
task :code, [:name] => [:requires] do |t, args|
|
82
|
-
Glimmer::RakeTask::Sample.code(args[:name])
|
83
|
-
end
|
84
|
-
|
65
|
+
desc 'Brings up the Glimmer Meta-Sample app to allow browsing, running, and viewing code of Glimmer samples'
|
66
|
+
task :samples do
|
67
|
+
Glimmer::Launcher.new([File.expand_path('../../../samples/elaborate/meta_sample.rb', __FILE__)]).launch
|
85
68
|
end
|
86
69
|
|
87
70
|
namespace :package do
|
@@ -95,7 +78,7 @@ namespace :glimmer do
|
|
95
78
|
Glimmer::RakeTask::Package.gemspec
|
96
79
|
end
|
97
80
|
|
98
|
-
desc 'Generate gem'
|
81
|
+
desc 'Generate gem under pkg directory'
|
99
82
|
task :gem do
|
100
83
|
Glimmer::RakeTask::Package.gem
|
101
84
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'glimmer/ui/custom_widget'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
module Custom
|
6
|
+
# CodeText is a customization of StyledText with support for Ruby Syntax Highlighting
|
7
|
+
class CodeText
|
8
|
+
include Glimmer::UI::CustomWidget
|
9
|
+
|
10
|
+
SYNTAX_COLOR_MAP = {
|
11
|
+
Builtin: [215,58,73],
|
12
|
+
Class: [3,47,98],
|
13
|
+
Constant: [0,92,197],
|
14
|
+
Double: [0,92,197],
|
15
|
+
Escape: [:red],
|
16
|
+
Function: [:blue],
|
17
|
+
Instance: [227,98,9],
|
18
|
+
Integer: [:blue],
|
19
|
+
Interpol: [:blue],
|
20
|
+
Keyword: [:blue],
|
21
|
+
Name: [111,66,193], #purple
|
22
|
+
Operator: [:red],
|
23
|
+
Pseudo: [:dark_red],
|
24
|
+
Punctuation: [:blue],
|
25
|
+
Single: [106,115,125], # Also, Comments
|
26
|
+
Symbol: [:dark_green],
|
27
|
+
Text: [75, 75, 75],
|
28
|
+
}
|
29
|
+
|
30
|
+
# TODO support `option :language`
|
31
|
+
# TODO support auto language detection
|
32
|
+
|
33
|
+
def text=(value)
|
34
|
+
swt_widget&.text = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def text
|
38
|
+
swt_widget&.text
|
39
|
+
end
|
40
|
+
|
41
|
+
def syntax_highlighting
|
42
|
+
return [] if text.to_s.strip.empty?
|
43
|
+
code = text
|
44
|
+
lexer = Rouge::Lexer.find_fancy('ruby', code)
|
45
|
+
lex = lexer.lex(code).to_a
|
46
|
+
code_size = 0
|
47
|
+
lex_hashes = lex.map do |pair|
|
48
|
+
{token_type: pair.first, token_text: pair.last}
|
49
|
+
end.each do |hash|
|
50
|
+
hash[:token_index] = code_size
|
51
|
+
code_size += hash[:token_text].size
|
52
|
+
end
|
53
|
+
# TODO consider grouping by line to optimize performance for line get style listener
|
54
|
+
end
|
55
|
+
|
56
|
+
before_body {
|
57
|
+
@swt_style = swt_style == 0 ? [:border, :multi, :v_scroll, :h_scroll] : swt_style
|
58
|
+
}
|
59
|
+
|
60
|
+
body {
|
61
|
+
styled_text(swt_style) {
|
62
|
+
font name: 'Consolas', height: 15
|
63
|
+
foreground rgb(75, 75, 75)
|
64
|
+
left_margin 5
|
65
|
+
top_margin 5
|
66
|
+
right_margin 5
|
67
|
+
bottom_margin 5
|
68
|
+
|
69
|
+
on_line_get_style { |line_style_event|
|
70
|
+
styles = []
|
71
|
+
line_style_event.lineOffset
|
72
|
+
syntax_highlighting.each do |token_hash|
|
73
|
+
if token_hash[:token_index] >= line_style_event.lineOffset && token_hash[:token_index] < (line_style_event.lineOffset + line_style_event.lineText.size)
|
74
|
+
start_index = token_hash[:token_index]
|
75
|
+
size = token_hash[:token_text].size
|
76
|
+
token_color = SYNTAX_COLOR_MAP[token_hash[:token_type].name] || [:black]
|
77
|
+
token_color = color(*token_color).swt_color
|
78
|
+
styles << StyleRange.new(start_index, size, token_color, nil)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
line_style_event.styles = styles.to_java(StyleRange) unless styles.empty?
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/swt/widget_proxy'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module SWT
|
26
|
+
# Proxy for org.eclipse.swt.custom.SashForm
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class SashFormProxy < WidgetProxy
|
30
|
+
def post_add_content
|
31
|
+
swt_widget.setWeights(@weights) unless @weights.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_attribute(attribute_name, *args)
|
35
|
+
if attribute_name.to_s == "weights"
|
36
|
+
@weights = args
|
37
|
+
@weights = @weights.first if @weights.first.is_a?(Array)
|
38
|
+
else
|
39
|
+
super(attribute_name, *args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_attribute(attribute_name)
|
44
|
+
if attribute_name.to_s == "weights"
|
45
|
+
swt_widget.getWeights.to_a
|
46
|
+
else
|
47
|
+
super(attribute_name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -55,7 +55,7 @@ module Glimmer
|
|
55
55
|
"radio" => [:radio],
|
56
56
|
"scrolled_composite" => [:border, :h_scroll, :v_scroll],
|
57
57
|
"spinner" => [:border],
|
58
|
-
"styled_text" => [:border],
|
58
|
+
"styled_text" => [:border, :multi, :v_scroll, :h_scroll],
|
59
59
|
"table" => [:virtual, :border, :full_selection],
|
60
60
|
"text" => [:border],
|
61
61
|
"toggle" => [:toggle],
|
@@ -0,0 +1,166 @@
|
|
1
|
+
class Sample
|
2
|
+
attr_accessor :sample_directory, :file, :selected
|
3
|
+
|
4
|
+
def initialize(file, sample_directory: )
|
5
|
+
self.file = file
|
6
|
+
self.sample_directory = sample_directory
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
if @name.nil?
|
11
|
+
@name = File.basename(file, '.rb').split('_').map(&:capitalize).join(' ')
|
12
|
+
if @name.start_with?('Hello')
|
13
|
+
name_parts = @name.split
|
14
|
+
name_parts[0] = name_parts.first + ','
|
15
|
+
name_parts[-1] = name_parts.last + '!'
|
16
|
+
@name = name_parts.join(' ')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
@name
|
20
|
+
end
|
21
|
+
|
22
|
+
def content
|
23
|
+
@content ||= File.read(file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def launch
|
27
|
+
load file
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class SampleDirectory
|
32
|
+
class << self
|
33
|
+
attr_accessor :selected_sample
|
34
|
+
|
35
|
+
def sample_directories
|
36
|
+
if @sample_directories.nil?
|
37
|
+
@sample_directories = Dir.glob(File.join(File.expand_path('..', __FILE__), '*')).
|
38
|
+
select { |file| File.directory?(file) }.
|
39
|
+
map { |file| SampleDirectory.new(file) }
|
40
|
+
glimmer_gems = Gem.find_latest_files("glimmer-*-*")
|
41
|
+
sample_directories = glimmer_gems.map do |lib|
|
42
|
+
File.dirname(File.dirname(lib))
|
43
|
+
end.select do |gem|
|
44
|
+
Dir.exist?(File.join(gem, 'samples'))
|
45
|
+
end.map do |gem|
|
46
|
+
Dir.glob(File.join(gem, 'samples', '*')).select {|file_or_dir| Dir.exist?(file_or_dir)}
|
47
|
+
end.flatten.uniq.reverse
|
48
|
+
if Dir.exist?('samples')
|
49
|
+
Dir.glob(File.join('samples', '*')).to_a.reverse.each do |dir|
|
50
|
+
sample_directories << dir if Dir.exist?(dir)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
sample_directories = sample_directories.uniq {|dir| File.basename(dir)}
|
54
|
+
@sample_directories = sample_directories.map { |file| SampleDirectory.new(file) }
|
55
|
+
end
|
56
|
+
@sample_directories
|
57
|
+
end
|
58
|
+
|
59
|
+
def all_samples
|
60
|
+
@all_samples ||= sample_directories.map(&:samples).reduce(:+)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
include Glimmer # used for observe syntax
|
65
|
+
|
66
|
+
attr_accessor :file
|
67
|
+
|
68
|
+
def initialize(file)
|
69
|
+
self.file = file
|
70
|
+
end
|
71
|
+
|
72
|
+
def name
|
73
|
+
File.basename(file).split('_').map(&:capitalize).join(' ')
|
74
|
+
end
|
75
|
+
|
76
|
+
def samples
|
77
|
+
if @samples.nil?
|
78
|
+
@samples = Dir.glob(File.join(file, '*')).
|
79
|
+
select { |file| File.file?(file) }.
|
80
|
+
map { |sample_file| Sample.new(sample_file, sample_directory: self) }.
|
81
|
+
sort_by(&:name)
|
82
|
+
|
83
|
+
@samples.each do |sample|
|
84
|
+
observe(sample, :selected) do |new_selected_value|
|
85
|
+
if new_selected_value
|
86
|
+
self.class.all_samples.reject {|a_sample| a_sample.name == sample.name}.each do |other_sample|
|
87
|
+
other_sample.selected = false
|
88
|
+
end
|
89
|
+
self.class.selected_sample = sample
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
@samples
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class MetaSampleApplication
|
99
|
+
include Glimmer
|
100
|
+
|
101
|
+
def launch
|
102
|
+
shell {
|
103
|
+
text 'Glimmer Meta-Sample (The Sample of Samples)'
|
104
|
+
|
105
|
+
on_swt_show {
|
106
|
+
SampleDirectory.selected_sample = SampleDirectory.all_samples.first
|
107
|
+
}
|
108
|
+
|
109
|
+
sash_form {
|
110
|
+
composite {
|
111
|
+
grid_layout 1, false
|
112
|
+
|
113
|
+
scrolled_composite {
|
114
|
+
layout_data(:fill, :fill, true, true)
|
115
|
+
|
116
|
+
composite {
|
117
|
+
SampleDirectory.sample_directories.each { |sample_directory|
|
118
|
+
group {
|
119
|
+
layout_data(:fill, :fill, true, true)
|
120
|
+
grid_layout 2, false
|
121
|
+
text sample_directory.name
|
122
|
+
font height: 30
|
123
|
+
|
124
|
+
sample_directory.samples.each { |sample|
|
125
|
+
label_radio = radio {
|
126
|
+
selection bind(sample, :selected)
|
127
|
+
}
|
128
|
+
label {
|
129
|
+
text sample.name
|
130
|
+
font height: 30
|
131
|
+
|
132
|
+
on_mouse_up {
|
133
|
+
sample.selected = true
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
button {
|
143
|
+
layout_data(:center, :center, false, false) {
|
144
|
+
height_hint 150
|
145
|
+
}
|
146
|
+
text 'Launch Sample'
|
147
|
+
font height: 45
|
148
|
+
on_widget_selected {
|
149
|
+
SampleDirectory.selected_sample.launch
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
code_text {
|
155
|
+
text bind(SampleDirectory, 'selected_sample.content')
|
156
|
+
editable false
|
157
|
+
caret nil
|
158
|
+
}
|
159
|
+
|
160
|
+
weights 1, 2
|
161
|
+
}
|
162
|
+
}.open
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
MetaSampleApplication.new.launch
|