glimmer-dsl-swt 4.17.8.2 → 4.17.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -1
  3. data/README.md +228 -7
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-swt.gemspec +11 -7
  6. data/lib/glimmer-dsl-swt.rb +4 -3
  7. data/lib/glimmer/data_binding/table_items_binding.rb +5 -5
  8. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +3 -3
  9. data/lib/glimmer/dsl/swt/widget_expression.rb +1 -0
  10. data/lib/glimmer/launcher.rb +9 -9
  11. data/lib/glimmer/swt/custom/code_text.rb +36 -34
  12. data/lib/glimmer/swt/date_time_proxy.rb +87 -0
  13. data/lib/glimmer/swt/display_proxy.rb +6 -6
  14. data/lib/glimmer/swt/dnd_proxy.rb +6 -10
  15. data/lib/glimmer/swt/message_box_proxy.rb +7 -7
  16. data/lib/glimmer/swt/sash_form_proxy.rb +3 -3
  17. data/lib/glimmer/swt/shell_proxy.rb +18 -3
  18. data/lib/glimmer/swt/style_constantizable.rb +5 -5
  19. data/lib/glimmer/swt/styled_text_proxy.rb +8 -13
  20. data/lib/glimmer/swt/swt_proxy.rb +7 -8
  21. data/lib/glimmer/swt/tab_item_proxy.rb +6 -1
  22. data/lib/glimmer/swt/table_column_proxy.rb +13 -5
  23. data/lib/glimmer/swt/table_proxy.rb +187 -66
  24. data/lib/glimmer/swt/widget_listener_proxy.rb +4 -4
  25. data/lib/glimmer/swt/widget_proxy.rb +70 -24
  26. data/samples/elaborate/contact_manager.rb +3 -3
  27. data/samples/elaborate/meta_sample.rb +9 -9
  28. data/samples/hello/hello_browser.rb +3 -3
  29. data/samples/hello/hello_checkbox_group.rb +3 -0
  30. data/samples/hello/hello_combo.rb +5 -5
  31. data/samples/hello/hello_date_time.rb +63 -0
  32. data/samples/hello/hello_group.rb +1 -1
  33. data/samples/hello/hello_menu_bar.rb +3 -3
  34. data/samples/hello/hello_pop_up_context_menu.rb +3 -3
  35. data/samples/hello/hello_radio_group.rb +3 -0
  36. data/samples/hello/hello_sash_form.rb +3 -3
  37. data/samples/hello/hello_spinner.rb +69 -0
  38. data/samples/hello/hello_tab.rb +3 -3
  39. data/samples/hello/hello_table.rb +287 -0
  40. metadata +10 -6
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -35,6 +35,7 @@ require 'logging'
35
35
  require 'nested_inherited_jruby_include_package'
36
36
  require 'super_module'
37
37
  require 'rouge'
38
+ require 'date'
38
39
 
39
40
  # Internal requires
40
41
  require 'ext/glimmer/config'
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -61,7 +61,7 @@ module Glimmer
61
61
  add_dependent(@table_observer_registration => @table_items_observer_registration)
62
62
  @model_collection = new_model_collection
63
63
  end
64
- populate_table(@model_collection, @table, @column_properties)
64
+ populate_table(@model_collection, @table, @column_properties)
65
65
  end
66
66
 
67
67
  def populate_table(model_collection, parent, column_properties)
@@ -79,7 +79,7 @@ module Glimmer
79
79
  selected_table_items = parent.search {|item| selected_table_item_models.include?(item.getData) }
80
80
  selected_table_items = [parent.swt_widget.getItems.first].to_java(TableItem) if selected_table_items.empty? && !parent.swt_widget.getItems.empty?
81
81
  parent.swt_widget.setSelection(selected_table_items) unless selected_table_items.empty?
82
- parent.sort
82
+ parent.sort!
83
83
  parent.swt_widget.redraw if parent&.swt_widget&.respond_to?(:redraw)
84
84
  end
85
85
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -58,3 +58,4 @@ require 'glimmer/swt/table_proxy'
58
58
  require 'glimmer/swt/table_column_proxy'
59
59
  require 'glimmer/swt/sash_form_proxy'
60
60
  require 'glimmer/swt/styled_text_proxy'
61
+ require 'glimmer/swt/date_time_proxy'
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -31,12 +31,12 @@ module Glimmer
31
31
  OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
32
32
 
33
33
  TEXT_USAGE = <<~MULTI_LINE_STRING
34
- Glimmer (Ruby Desktop Development GUI Library) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
34
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
35
35
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
36
36
 
37
- Runs Glimmer applications and tasks.
37
+ Runs Glimmer applications and tasks.
38
38
 
39
- When applications are specified, they are run using JRuby,
39
+ When applications are specified, they are run using JRuby,
40
40
  automatically preloading the glimmer Ruby gem and SWT jar dependency.
41
41
 
42
42
  Optionally, extra Glimmer options, JRuby options, and/or environment variables may be passed in.
@@ -112,7 +112,7 @@ module Glimmer
112
112
  def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
113
113
  jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
114
114
  env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
115
- env_vars_string = env_vars.map do |k,v|
115
+ env_vars_string = env_vars.map do |k,v|
116
116
  if OS.windows? && ENV['PROMPT'] # detect command prompt (or powershell)
117
117
  "set #{k}=#{v} && "
118
118
  else
@@ -224,8 +224,8 @@ module Glimmer
224
224
  task_name = task.name_with_args.sub('glimmer:', '')
225
225
  line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
226
226
  bound = TTY::Screen.width - 6
227
- line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
228
- end
227
+ line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
228
+ end
229
229
  end
230
230
  end
231
231
 
@@ -38,32 +38,25 @@ module Glimmer
38
38
  swt_widget&.text
39
39
  end
40
40
 
41
- def syntax_highlighting
41
+ def syntax_highlighting(text)
42
42
  return [] if text.to_s.strip.empty?
43
- return @syntax_highlighting if already_syntax_highlighted?
44
- @last_text = text
45
- @lexer ||= Rouge::Lexer.find_fancy('ruby', text)
46
- lex = @lexer.lex(text).to_a
47
- text_size = 0
48
- lex_hashes = lex.map do |pair|
49
- {token_type: pair.first, token_text: pair.last}
50
- end.each do |hash|
51
- hash[:token_index] = text_size
52
- text_size += hash[:token_text].size
53
- end
54
- text_lines = text.split("\n")
55
- line_index = 0
56
- @syntax_highlighting = text_lines_map = text_lines.reduce({}) do |hash, line|
57
- line_hashes = []
58
- line_hashes << lex_hashes.shift while lex_hashes.any? && lex_hashes.first[:token_index].between?(line_index, line_index + line.size)
59
- hash.merge(line_index => line_hashes).tap do
60
- line_index += line.size + 1
43
+ @syntax_highlighting ||= {}
44
+ unless @syntax_highlighting.keys.include?(text)
45
+ lex = lexer.lex(text).to_a
46
+ text_size = 0
47
+ @syntax_highlighting[text] = lex.map do |pair|
48
+ {token_type: pair.first, token_text: pair.last}
49
+ end.each do |hash|
50
+ hash[:token_index] = text_size
51
+ text_size += hash[:token_text].size
61
52
  end
62
53
  end
54
+ @syntax_highlighting[text]
63
55
  end
64
56
 
65
- def already_syntax_highlighted?
66
- @last_text == text
57
+ def lexer
58
+ # TODO Try to use Rouge::Lexer.find_fancy('guess', code) in the future to guess the language or otherwise detect it from file extension
59
+ @lexer ||= Rouge::Lexer.find_fancy('ruby')
67
60
  end
68
61
 
69
62
  before_body {
@@ -78,22 +71,31 @@ module Glimmer
78
71
  top_margin 5
79
72
  right_margin 5
80
73
  bottom_margin 5
74
+
75
+ on_modify_text { |event|
76
+ # clear unnecessary syntax highlighting cache on text updates, and do it async to avoid affecting performance
77
+ new_text = event.data
78
+ async_exec {
79
+ unless @syntax_highlighting.nil?
80
+ lines = new_text.to_s.split("\n")
81
+ line_diff = @syntax_highlighting.keys - lines
82
+ line_diff.each do |line|
83
+ @syntax_highlighting.delete(line)
84
+ end
85
+ end
86
+ }
87
+ }
81
88
 
82
89
  on_line_get_style { |line_style_event|
83
- @styles ||= {}
84
- @styles = {} unless already_syntax_highlighted?
85
- if @styles[line_style_event.lineOffset].nil?
86
- styles = []
87
- syntax_highlighting[line_style_event.lineOffset].to_a.each do |token_hash|
88
- start_index = token_hash[:token_index]
89
- size = token_hash[:token_text].size
90
- token_color = SYNTAX_COLOR_MAP[token_hash[:token_type].name] || [:black]
91
- token_color = color(*token_color).swt_color
92
- styles << StyleRange.new(start_index, size, token_color, nil)
93
- end
94
- @styles[line_style_event.lineOffset] = styles.to_java(StyleRange)
90
+ styles = []
91
+ syntax_highlighting(line_style_event.lineText).to_a.each do |token_hash|
92
+ start_index = token_hash[:token_index]
93
+ size = token_hash[:token_text].size
94
+ token_color = SYNTAX_COLOR_MAP[token_hash[:token_type].name] || [:black]
95
+ token_color = color(*token_color).swt_color
96
+ styles << StyleRange.new(line_style_event.lineOffset + start_index, size, token_color, nil)
95
97
  end
96
- line_style_event.styles = @styles[line_style_event.lineOffset] unless @styles[line_style_event.lineOffset].empty?
98
+ line_style_event.styles = styles.to_java(StyleRange) unless styles.empty?
97
99
  }
98
100
  }
99
101
  }
@@ -0,0 +1,87 @@
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 'date'
23
+ require 'glimmer/swt/widget_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ # Proxy for org.eclipse.swt.widgets.DateTime
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class DateTimeProxy < WidgetProxy
31
+ CUSTOM_ATTRIBUTES = %w[date_time date time month]
32
+
33
+ def date_time
34
+ DateTime.new(year, month, day, hours, minutes, seconds)
35
+ end
36
+
37
+ def date_time=(date_time_value)
38
+ self.time = date_time_value.to_time
39
+ end
40
+
41
+ def date
42
+ date_time.to_date
43
+ end
44
+
45
+ def date=(date_value)
46
+ self.year = date_value.year
47
+ self.month = date_value.month
48
+ self.day = date_value.day
49
+ end
50
+
51
+ def time
52
+ date_time.to_time
53
+ end
54
+
55
+ def time=(time_value)
56
+ self.date = time_value.to_date
57
+ self.hours = time_value.hour
58
+ self.minutes = time_value.min
59
+ self.seconds = time_value.sec
60
+ end
61
+
62
+ def month
63
+ swt_widget.month + 1
64
+ end
65
+
66
+ def month=(new_value)
67
+ swt_widget.month = new_value - 1
68
+ end
69
+
70
+ def set_attribute(attribute_name, *args)
71
+ if CUSTOM_ATTRIBUTES.include?(attribute_name.to_s)
72
+ send(ruby_attribute_setter(attribute_name), args.first)
73
+ else
74
+ super(attribute_name, *args)
75
+ end
76
+ end
77
+
78
+ def get_attribute(attribute_name)
79
+ if CUSTOM_ATTRIBUTES.include?(attribute_name.to_s)
80
+ send(attribute_name)
81
+ else
82
+ super(attribute_name)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -59,7 +59,7 @@ module Glimmer
59
59
 
60
60
  def content(&block)
61
61
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::DisplayExpression.new, &block)
62
- end
62
+ end
63
63
 
64
64
  def method_missing(method, *args, &block)
65
65
  if can_handle_observation_request?(method)
@@ -73,8 +73,8 @@ module Glimmer
73
73
  end
74
74
 
75
75
  def respond_to?(method, *args, &block)
76
- super ||
77
- can_handle_observation_request?(method) ||
76
+ super ||
77
+ can_handle_observation_request?(method) ||
78
78
  swt_display.respond_to?(method, *args, &block)
79
79
  end
80
80
 
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -26,15 +26,15 @@ module Glimmer
26
26
  # Proxy for org.eclipse.swt.dnd.DND
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
- class DNDProxy
30
- include StyleConstantizable
29
+ class DNDProxy
30
+ include StyleConstantizable
31
31
 
32
32
  class << self
33
33
  JAVA_IMPORT = 'org.eclipse.swt.dnd.DND'
34
34
 
35
35
  java_import JAVA_IMPORT
36
36
 
37
- def constant_java_import
37
+ def constant_java_import
38
38
  JAVA_IMPORT
39
39
  end
40
40
 
@@ -45,10 +45,6 @@ module Glimmer
45
45
  def constant_value_none
46
46
  DND::DROP_NONE
47
47
  end
48
-
49
- def extra_styles
50
- {}
51
- end
52
48
  end
53
49
  end
54
50
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -38,7 +38,7 @@ module Glimmer
38
38
  if parent.nil?
39
39
  @temporary_parent = parent = Glimmer::SWT::ShellProxy.new.swt_widget
40
40
  end
41
- @swt_widget = MessageBox.new(parent, style)
41
+ @swt_widget = MessageBox.new(parent, style)
42
42
  end
43
43
 
44
44
  def open
@@ -49,7 +49,7 @@ module Glimmer
49
49
 
50
50
  def content(&block)
51
51
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::MessageBoxExpression.new, &block)
52
- end
52
+ end
53
53
 
54
54
  # TODO refactor the following methods to put in a JavaBean mixin or somethin (perhaps contribute to OSS project too)
55
55
 
@@ -81,9 +81,9 @@ module Glimmer
81
81
  end
82
82
 
83
83
  def respond_to?(method, *args, &block)
84
- super ||
84
+ super ||
85
85
  swt_widget.respond_to?(method, *args, &block)
86
- end
86
+ end
87
87
  end
88
88
  end
89
89
  end