swing 0.1.8 → 0.1.10
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.
- data/HISTORY +8 -0
- data/VERSION +1 -1
- data/lib/awt/component.rb +0 -4
- data/lib/swing/j_button.rb +0 -2
- data/lib/swing/j_check_box.rb +0 -1
- data/lib/swing/j_component.rb +61 -0
- data/lib/swing/j_frame.rb +1 -0
- data/lib/swing/j_label.rb +1 -4
- data/lib/swing/j_list.rb +0 -3
- data/lib/swing/j_menu.rb +0 -2
- data/lib/swing/j_menu_bar.rb +3 -6
- data/lib/swing/j_menu_item.rb +0 -2
- data/lib/swing/j_panel.rb +1 -4
- data/lib/swing/j_scroll_pane.rb +0 -1
- data/lib/swing/j_split_pane.rb +0 -1
- data/lib/swing/j_table.rb +12 -10
- data/lib/swing.rb +4 -2
- data/lib/swing_support/extensions/attributes.rb +22 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/swing/j_button_spec.rb +2 -2
- data/spec/swing/j_check_box_spec.rb +2 -2
- data/spec/swing/j_frame_spec.rb +1 -1
- data/spec/swing/j_label_spec.rb +3 -2
- data/spec/swing/j_list_spec.rb +3 -3
- data/spec/swing/j_menu_bar_spec.rb +2 -2
- data/spec/swing/j_menu_item_spec.rb +2 -2
- data/spec/swing/j_menu_spec.rb +2 -2
- data/spec/swing/j_panel_spec.rb +2 -2
- data/spec/swing/j_scroll_pane_spec.rb +11 -3
- data/spec/swing/j_split_pane_spec.rb +2 -2
- data/spec/swing/j_table_spec.rb +69 -3
- data/spec/swing/shared.rb +76 -14
- metadata +2 -1
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/lib/awt/component.rb
CHANGED
data/lib/swing/j_button.rb
CHANGED
data/lib/swing/j_check_box.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'swing'
|
2
|
+
|
3
|
+
class Swing::JComponent
|
4
|
+
|
5
|
+
# actionMap ActionMap � �
|
6
|
+
# alignmentX float � �
|
7
|
+
# alignmentY float � �
|
8
|
+
# autoscrolls boolean � � false
|
9
|
+
# border Border � � null
|
10
|
+
# bounds Rectangle � �
|
11
|
+
# debugGraphicsOptions int � � DebugGraphics.NONE_OPTION
|
12
|
+
# doubleBuffered boolean � � false
|
13
|
+
# enabled boolean � � true - OVERRIDE
|
14
|
+
# location Point � � Point(bounds.x, bounds.y) - OVERRIDE
|
15
|
+
# maximumSize Dimension � �
|
16
|
+
# minimumSize Dimension � �
|
17
|
+
# nextFocusableComponent Component � �
|
18
|
+
# opaque boolean � � false
|
19
|
+
# preferredSize Dimension � �
|
20
|
+
# requestFocusEnabled boolean � � true
|
21
|
+
# size Dimension � � Dimension(bounds.height, bounds.width)
|
22
|
+
# toolTipText String � � null - OVERRIDE
|
23
|
+
# transferHandler TransferHandler � � null
|
24
|
+
# verifyInputWhenFocusTarget boolean � �
|
25
|
+
# visible boolean � � true - OVERRIDE
|
26
|
+
# ----Getters only - NO Setters!
|
27
|
+
# UI ComponentUI �
|
28
|
+
# UIClassID String � "ComponentUI"
|
29
|
+
# accessibleContext AccessibleContext � null
|
30
|
+
# ancestorListeners AncestorListener[] �
|
31
|
+
# focusCycleRoot boolean � false
|
32
|
+
# focusTraversable boolean � true
|
33
|
+
# graphics Graphics �
|
34
|
+
# height int � bounds.height
|
35
|
+
# managingFocus boolean � false
|
36
|
+
# optimizedDrawingEnabled boolean � true
|
37
|
+
# paintingTile boolean �
|
38
|
+
# propertyChangeListeners (also string indexed version) PropertyChangeListener[] �
|
39
|
+
# registeredKeyStrokes KeyStroke[] �
|
40
|
+
# rootPane JRootPane �
|
41
|
+
# topLevelAncestor Container �
|
42
|
+
# validateRoot boolean � false
|
43
|
+
# vetoableChangeListeners VetoableChangeListener[]
|
44
|
+
# visibleRect Rectangle �
|
45
|
+
# width int � bounds.width
|
46
|
+
# x int � bounds.x
|
47
|
+
# y int � bounds.y
|
48
|
+
# ----Wrong - NOT Working Setters!
|
49
|
+
# defaultLocales Locale � � - no setter/getter at all
|
50
|
+
# inputMap (also indexed get)InputMap � � - setter not working properly ?!
|
51
|
+
# inputVerifier InputVerifier � � - setter raises exception
|
52
|
+
# insets Insets � � - insets are reset anyways
|
53
|
+
|
54
|
+
attr_setter :action_map, :alignmentx, :alignmenty, :autoscrolls, :border, :bounds,
|
55
|
+
:debug_graphics_options, :double_buffered, :input_map, # :default_locales,
|
56
|
+
:input_verifier, :insets,
|
57
|
+
:opaque, :next_focusable_component, :request_focus_enabled,
|
58
|
+
:tool_tip_text, :verify_input_when_focus_target,
|
59
|
+
:minimum_size => Awt::Dimension, :maximum_size => Awt::Dimension,
|
60
|
+
:preferred_size => Awt::Dimension, :transfer_handler => Swing::TransferHandler
|
61
|
+
end
|
data/lib/swing/j_frame.rb
CHANGED
data/lib/swing/j_label.rb
CHANGED
data/lib/swing/j_list.rb
CHANGED
data/lib/swing/j_menu.rb
CHANGED
data/lib/swing/j_menu_bar.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
require 'swing'
|
2
|
-
require 'swing/j_menu'
|
3
|
-
require 'swing/j_menu_item'
|
4
2
|
|
5
3
|
class Swing::JMenuBar
|
6
4
|
|
7
|
-
attr_setter :tool_tip_text
|
8
|
-
|
9
5
|
# Override post-processing (non-setter) options given to initialize
|
10
6
|
def post_process opts
|
11
7
|
super
|
12
8
|
# Create menu structure from :structure opt
|
13
|
-
|
14
|
-
|
9
|
+
structure = opts.delete :structure
|
10
|
+
if structure
|
11
|
+
[structure].flatten.each do |element|
|
15
12
|
case element
|
16
13
|
when Hash # Hash defines menu structure
|
17
14
|
element.each do |menu_name, menu_structure|
|
data/lib/swing/j_menu_item.rb
CHANGED
data/lib/swing/j_panel.rb
CHANGED
data/lib/swing/j_scroll_pane.rb
CHANGED
data/lib/swing/j_split_pane.rb
CHANGED
data/lib/swing/j_table.rb
CHANGED
@@ -10,7 +10,7 @@ class Swing::JTable
|
|
10
10
|
# cellSelectionEnabled boolean � � false
|
11
11
|
# columnSelectionAllowed boolean � � false
|
12
12
|
# rowSelectionAllowed boolean � � true
|
13
|
-
# selectionMode int � MULTIPLE_INTERVAL_SELECTION
|
13
|
+
# selectionMode int � MULTIPLE_INTERVAL_SELECTION - Setter ONLY!
|
14
14
|
# selectionModel ListSelectionModel � � DefaultListSelectionModel
|
15
15
|
# cellEditor TableCellEditor � � null
|
16
16
|
# dragEnabled boolean � � false
|
@@ -18,8 +18,8 @@ class Swing::JTable
|
|
18
18
|
# intercellSpacing Dimension � � Dimension(1, 1)
|
19
19
|
# preferredScrollableViewportSize Dimension � � Dimension(450, 400)
|
20
20
|
# rowMargin int � � 1
|
21
|
-
# selectionBackground
|
22
|
-
# selectionForeground
|
21
|
+
# selectionBackground Color � � From L&F
|
22
|
+
# selectionForeground Color � � From L&F
|
23
23
|
# showGrid boolean � true
|
24
24
|
# showHorizontalLines boolean � � true
|
25
25
|
# showVerticalLines boolean � � true
|
@@ -37,14 +37,16 @@ class Swing::JTable
|
|
37
37
|
# scrollableTracksViewportHeighto boolean � false
|
38
38
|
# scrollableTracksViewportWidtho boolean � false
|
39
39
|
|
40
|
-
attr_setter :tool_tip_text
|
41
40
|
attr_setter :auto_create_columns_from_model, :auto_resize_mode, :row_height,
|
42
|
-
:model, :column_model, :selection_model,
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
41
|
+
:model, :column_model, :selection_model, :drag_enabled, :cell_editor,
|
42
|
+
:row_margin, :show_grid, :show_horizontal_lines, :show_vertical_lines,
|
43
|
+
:table_header,
|
44
|
+
:grid_color => Awt::Color,
|
45
|
+
:intercell_spacing => Awt::Dimension,
|
46
|
+
:selection_background => Awt::Color,
|
47
|
+
:selection_foreground => Awt::Color,
|
48
|
+
:preferred_scrollable_viewport_size => Awt::Dimension,
|
49
|
+
:selection_mode => Swing::ListSelectionModel::SINGLE_SELECTION,
|
48
50
|
:cell_selection_enabled => true,
|
49
51
|
:row_selection_allowed => false,
|
50
52
|
:column_selection_allowed => false
|
data/lib/swing.rb
CHANGED
@@ -7,6 +7,7 @@ require 'version'
|
|
7
7
|
require 'swing_support'
|
8
8
|
require 'awt'
|
9
9
|
|
10
|
+
require 'swing/j_component'
|
10
11
|
require 'swing/j_button'
|
11
12
|
require 'swing/j_check_box'
|
12
13
|
require 'swing/j_frame'
|
@@ -20,7 +21,8 @@ require 'swing/j_scroll_pane'
|
|
20
21
|
require 'swing/j_split_pane'
|
21
22
|
require 'swing/j_table'
|
22
23
|
|
23
|
-
|
24
|
+
module Swing
|
25
|
+
Table = table
|
24
26
|
# TODO: Impossible to auto-load, this is Swing package, not a Ruby module :(
|
25
27
|
# autoload :JButton, "swing/j_button"
|
26
28
|
# autoload :JCheckBox, "swing/j_check_box"
|
@@ -32,4 +34,4 @@ require 'swing/j_table'
|
|
32
34
|
# autoload :Jdbc, "rubeus/jdbc"
|
33
35
|
# autoload :Reflection, "rubeus/reflection"
|
34
36
|
# autoload :Util, "rubeus/util"
|
35
|
-
|
37
|
+
end # module Swing
|
@@ -15,8 +15,9 @@ module SwingSupport
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Post-processing (non-setter) options given to initialize
|
18
|
+
# You need to delete processed/consumed options from given Hash
|
18
19
|
def post_process opts
|
19
|
-
attach_to opts
|
20
|
+
attach_to opts.delete(:parent)
|
20
21
|
end
|
21
22
|
|
22
23
|
# Proper way to add generic component to its parent
|
@@ -42,26 +43,42 @@ module SwingSupport
|
|
42
43
|
|
43
44
|
# Sets attributes after calling original new
|
44
45
|
def new_with_attributes(*args, &block)
|
45
|
-
opts = args.last.is_a?(Hash) ? args.pop : {}
|
46
|
+
opts = args.last.is_a?(Hash) ? args.pop.dup : {}
|
46
47
|
component = self.new_without_attributes(*args, &block)
|
47
48
|
|
48
|
-
# Extract known attributes given in opts,
|
49
|
+
# Extract known attributes given in opts,
|
50
|
+
# run default actions on them, or return known defaults
|
49
51
|
attributes = attributes().map do |name, default|
|
50
52
|
value = opts.delete name
|
51
|
-
result = if default.nil? # No default,
|
53
|
+
result = if default.nil? # No default, use value directly
|
52
54
|
value
|
53
55
|
elsif default.respond_to? :call # Default is callable, call it with whatever value
|
54
56
|
default.call *value
|
57
|
+
elsif default.is_a?(Class) && value.class != default # Default class of this attribute, create new
|
58
|
+
default.new *value unless value.nil?
|
55
59
|
else # Return either non-nil value or default
|
56
60
|
value.nil? ? default : value
|
57
61
|
end
|
58
62
|
[name, result] unless result.nil?
|
59
63
|
end.compact
|
64
|
+
|
60
65
|
# yield opts if block_given?
|
61
|
-
|
66
|
+
|
67
|
+
attributes.each do |(name, value)|
|
68
|
+
if component.respond_to? "#{name}="
|
69
|
+
component.send "#{name}=", *value
|
70
|
+
elsif component.respond_to? "set_#{name}"
|
71
|
+
component.send "set_#{name}", *value
|
72
|
+
else
|
73
|
+
raise ArgumentError.new "Setter #{name} does not work for #{component}"
|
74
|
+
end
|
75
|
+
end
|
62
76
|
|
63
77
|
# Post-process non-setter opts (setter opts are already consumed by now)
|
64
78
|
component.post_process opts
|
79
|
+
|
80
|
+
# Raises exception if any of the given options left unprocessed
|
81
|
+
raise "Unrecognized options: #{opts}" unless opts.empty?
|
65
82
|
component
|
66
83
|
end
|
67
84
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ require 'swing'
|
|
8
8
|
BASE_PATH = Pathname.new(__FILE__).dirname + '..'
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|
11
|
-
|
11
|
+
config.exclusion_filter = { :failing => true }
|
12
12
|
# config.filter = { :focus => true }
|
13
13
|
# config.include(UserExampleHelpers)
|
14
14
|
# config.mock_with :mocha
|
data/spec/swing/j_button_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Swing::JButton do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { ['Text'] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
it 'is possible to set :enabled attribute to false' do
|
13
13
|
button = Swing::JButton.new 'Disconnect', :enabled => false
|
@@ -6,8 +6,8 @@ describe Swing::JCheckBox do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { ['Text'] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
it 'is possible to set :selected attribute' do
|
13
13
|
box = Swing::JCheckBox.new 'Disconnect', :selected => true
|
data/spec/swing/j_frame_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Swing::JFrame do
|
|
7
7
|
after(:each) { @frame.dispose if @frame }
|
8
8
|
let(:new_args) { ['Frame'] }
|
9
9
|
|
10
|
-
it_behaves_like 'enhanced
|
10
|
+
it_behaves_like 'enhanced Awt::Component'
|
11
11
|
|
12
12
|
it 'is possible to create Frame with options' do
|
13
13
|
@frame = Swing::JFrame.new "Option frame",
|
data/spec/swing/j_label_spec.rb
CHANGED
@@ -6,7 +6,8 @@ describe Swing::JLabel do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { ['Text'] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
|
+
|
11
12
|
end
|
12
13
|
end
|
data/spec/swing/j_list_spec.rb
CHANGED
@@ -4,9 +4,9 @@ require 'swing/shared'
|
|
4
4
|
describe Swing::JList do
|
5
5
|
|
6
6
|
context 'creation' do
|
7
|
-
let(:new_args) { [] }
|
8
7
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
8
|
+
it_behaves_like 'enhanced Awt::Component'
|
9
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
10
|
+
|
11
11
|
end
|
12
12
|
end
|
@@ -6,8 +6,8 @@ describe Swing::JMenuBar do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { [] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
it 'allows to pass parent in as option' do
|
13
13
|
@frame = Swing::JFrame.new 'Menu Test'
|
@@ -6,8 +6,8 @@ describe Swing::JMenuItem do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { ['Text'] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
end
|
13
13
|
end
|
data/spec/swing/j_menu_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Swing::JMenu do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { ['Text'] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
end
|
13
13
|
end
|
data/spec/swing/j_panel_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Swing::JPanel do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { [] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
end
|
13
13
|
end
|
@@ -5,10 +5,18 @@ describe Swing::JScrollPane do
|
|
5
5
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { [] }
|
8
|
-
let(:layout) { Swing::ScrollPaneLayout.new
|
8
|
+
let(:layout) { Swing::ScrollPaneLayout.new }
|
9
9
|
|
10
|
-
it_behaves_like 'enhanced
|
11
|
-
it_behaves_like '
|
10
|
+
it_behaves_like 'enhanced Awt::Component'
|
11
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
12
|
+
|
13
|
+
it 'can be constructed given an enclosed element' do
|
14
|
+
list = Swing::JList.new
|
15
|
+
|
16
|
+
@pane = Swing::JScrollPane.new list, :preferred_size => [700, 900]
|
17
|
+
@pane.viewport.components[0].should == list
|
18
|
+
@pane.preferred_size.should == Awt::Dimension.new(700, 900)
|
19
|
+
end
|
12
20
|
|
13
21
|
end
|
14
22
|
end
|
@@ -6,8 +6,8 @@ describe Swing::JSplitPane do
|
|
6
6
|
context 'creation' do
|
7
7
|
let(:new_args) { [] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
it 'is possible to use constructor with two children' do
|
13
13
|
b1 = Swing::JButton.new 'First'
|
data/spec/swing/j_table_spec.rb
CHANGED
@@ -4,10 +4,76 @@ require 'swing/shared'
|
|
4
4
|
describe Swing::JTable do
|
5
5
|
|
6
6
|
context 'creation' do
|
7
|
-
let(:new_args) { [2,2] }
|
7
|
+
let(:new_args) { [2, 2] }
|
8
8
|
|
9
|
-
it_behaves_like 'enhanced
|
10
|
-
it_behaves_like '
|
9
|
+
it_behaves_like 'enhanced Awt::Component'
|
10
|
+
it_behaves_like 'enhanced Swing::JComponent'
|
11
|
+
|
12
|
+
it 'allows to set properties via constructor' do
|
13
|
+
model = Class.new(Swing::Table::DefaultTableModel).new
|
14
|
+
column_model = Class.new(Swing::Table::DefaultTableColumnModel).new
|
15
|
+
field = Swing::JTextField.new
|
16
|
+
editor = Class.new(Swing::DefaultCellEditor).new field
|
17
|
+
header = Class.new(Swing::Table::JTableHeader).new
|
18
|
+
selection_model = Class.new(Swing::DefaultListSelectionModel).new
|
19
|
+
properties = {
|
20
|
+
:auto_create_columns_from_model => true,
|
21
|
+
:auto_resize_mode => Swing::JTable::AUTO_RESIZE_ALL_COLUMNS,
|
22
|
+
:row_height => 21,
|
23
|
+
:model => model,
|
24
|
+
:column_model => column_model,
|
25
|
+
:selection_model => selection_model,
|
26
|
+
:drag_enabled => true,
|
27
|
+
:cell_editor => editor,
|
28
|
+
:row_margin => 13,
|
29
|
+
:show_horizontal_lines => false,
|
30
|
+
:show_vertical_lines => false,
|
31
|
+
:table_header => header,
|
32
|
+
:cell_selection_enabled => false,
|
33
|
+
:row_selection_allowed => true,
|
34
|
+
}
|
35
|
+
@table = described_class.new *(new_args.push properties)
|
36
|
+
# p @table.methods.sort.grep /election/
|
37
|
+
properties.each do |name, value|
|
38
|
+
p name, value
|
39
|
+
@table.send(name).should == value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'auto-creates appropriate property classes as needed' do
|
44
|
+
properties = {
|
45
|
+
:grid_color => [1, 2, 3],
|
46
|
+
:intercell_spacing => [1, 1],
|
47
|
+
:preferred_scrollable_viewport_size => [100, 100],
|
48
|
+
:selection_background => [1, 2, 3],
|
49
|
+
:selection_foreground => [3, 2, 1],
|
50
|
+
}
|
51
|
+
@table = described_class.new *(new_args.push properties)
|
52
|
+
properties.each do |name, value|
|
53
|
+
@table.send(name).should == @table.class.attributes[name].new(*value)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'also sets some options without getter equivalent' do
|
58
|
+
properties = {
|
59
|
+
:selection_mode => Swing::ListSelectionModel::SINGLE_INTERVAL_SELECTION,
|
60
|
+
:show_grid => false,
|
61
|
+
}
|
62
|
+
@table = described_class.new *(new_args.push properties)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'unable to set this combination of properties for some reason', :failing => true do
|
66
|
+
properties = {
|
67
|
+
:cell_selection_enabled => false,
|
68
|
+
:row_selection_allowed => true,
|
69
|
+
:column_selection_allowed => true,
|
70
|
+
}
|
71
|
+
@table = described_class.new *(new_args.push properties)
|
72
|
+
properties.each do |name, value|
|
73
|
+
p name, value
|
74
|
+
@table.send(name).should == value
|
75
|
+
end
|
76
|
+
end
|
11
77
|
|
12
78
|
end
|
13
79
|
end
|
data/spec/swing/shared.rb
CHANGED
@@ -1,24 +1,32 @@
|
|
1
|
-
shared_examples_for 'enhanced
|
1
|
+
shared_examples_for 'enhanced Awt::Component' do
|
2
2
|
|
3
3
|
after(:each) { @component.dispose if @component.respond_to? :dispose }
|
4
|
+
let(:args) { defined?(new_args) ? new_args : [] }
|
5
|
+
let(:locale) do
|
6
|
+
locales = java.util.Locale.available_locales
|
7
|
+
locales[rand(locales.size)]
|
8
|
+
end
|
4
9
|
|
5
|
-
context 'new with common options' do
|
6
|
-
it '
|
10
|
+
context 'new with common properties set in options' do
|
11
|
+
it 'sets settable properties via constructor options' do
|
7
12
|
# p described_class.attributes
|
8
|
-
|
13
|
+
# p subject.methods.sort.grep /nput/
|
14
|
+
properties = {
|
9
15
|
:background => Awt::Color.new(1, 2, 3),
|
10
16
|
:foreground => Awt::Color.new(3, 2, 1),
|
11
17
|
:cursor => Awt::Cursor.new(Awt::Cursor::HAND_CURSOR),
|
12
18
|
:enabled => false,
|
13
19
|
:visible => false,
|
14
20
|
:font => Awt::Font.new("Trebuchet", Awt::Font::PLAIN, 11),
|
15
|
-
:
|
16
|
-
:location => Awt::Point.new(
|
21
|
+
:locale => locale,
|
22
|
+
:location => Awt::Point.new(100, 200),
|
17
23
|
:size => Awt::Dimension.new(300, 300),
|
18
24
|
:name => 'Blah',
|
25
|
+
# :layout => (defined?(layout) ? layout : Awt::FlowLayout.new),
|
19
26
|
}
|
20
|
-
@component = described_class.new *(
|
21
|
-
|
27
|
+
@component = described_class.new *(args.push properties)
|
28
|
+
# p properties
|
29
|
+
properties.each do |name, value|
|
22
30
|
@component.send(name).should == value
|
23
31
|
end
|
24
32
|
end
|
@@ -26,18 +34,72 @@ shared_examples_for 'enhanced awt component' do
|
|
26
34
|
|
27
35
|
context 'new with parent' do
|
28
36
|
unless described_class == Swing::JFrame || described_class == Swing::JMenuBar
|
29
|
-
it '
|
37
|
+
it 'sets parent via options' do
|
30
38
|
parent = Swing::JPanel.new
|
31
|
-
@component = described_class.new *(
|
39
|
+
@component = described_class.new *(args.push :parent => parent)
|
32
40
|
@component.parent.should == parent
|
33
41
|
end
|
42
|
+
else
|
34
43
|
end
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
|
-
shared_examples_for '
|
39
|
-
|
40
|
-
|
41
|
-
|
47
|
+
shared_examples_for 'enhanced Swing::JComponent' do
|
48
|
+
after(:each) { @component.dispose if @component.respond_to? :dispose }
|
49
|
+
let(:args) { defined?(new_args) ? new_args : [] }
|
50
|
+
let(:border) { Swing::BorderFactory.createEmptyBorder(8, 8, 8, 8) }
|
51
|
+
|
52
|
+
context 'new with common properties set in options' do
|
53
|
+
it 'sets settable properties via constructor options' do
|
54
|
+
focusable = Swing::JPanel.new
|
55
|
+
properties = {
|
56
|
+
:action_map => Swing::ActionMap.new,
|
57
|
+
:alignmentx => 0.5,
|
58
|
+
:alignmenty => 0.5,
|
59
|
+
:autoscrolls => true,
|
60
|
+
:border => border, #Swing::Border::Border.new, # javax.swing.border.Border.new(3, 2, 1, 1),
|
61
|
+
:bounds => Awt::Rectangle.new(3, 2, 1, 1),
|
62
|
+
:debug_graphics_options => Swing::DebugGraphics::LOG_OPTION,
|
63
|
+
# :default_locales => true,
|
64
|
+
:double_buffered => true,
|
65
|
+
# :input_map => Swing::JComponent::WHEN_FOCUSED,
|
66
|
+
# :input_verifier => Swing::InputVerifier.new,
|
67
|
+
# :insets => Awt::Insets.new(1,1,1,1),
|
68
|
+
:maximum_size => Awt::Dimension.new(30, 30),
|
69
|
+
:minimum_size => Awt::Dimension.new(30, 30),
|
70
|
+
:preferred_size => Awt::Dimension.new(30, 30),
|
71
|
+
:opaque => true,
|
72
|
+
:next_focusable_component => focusable,
|
73
|
+
:request_focus_enabled => false,
|
74
|
+
:tool_tip_text => 'Tip',
|
75
|
+
:transfer_handler => Swing::TransferHandler.new('color'),
|
76
|
+
:verify_input_when_focus_target => false
|
77
|
+
}
|
78
|
+
@component = described_class.new *(args.push properties)
|
79
|
+
properties.each do |name, value|
|
80
|
+
@component.send(name).should == value
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'even auto-creates proper classes for given properties' do
|
85
|
+
properties = {
|
86
|
+
:bounds => [3, 2, 10, 10],
|
87
|
+
:maximum_size => [40, 40],
|
88
|
+
:minimum_size => [20, 20],
|
89
|
+
:preferred_size => [30, 30],
|
90
|
+
:transfer_handler => 'color',
|
91
|
+
# :border => [8, 8, 8, 8],
|
92
|
+
# :debug_graphics_options => Swing::DebugGraphics::LOG_OPTION,
|
93
|
+
# :input_map => Swing::JComponent::WHEN_FOCUSED,
|
94
|
+
# :input_verifier => Swing::InputVerifier.new,
|
95
|
+
# :insets => Awt::Insets.new(1,1,1,1),
|
96
|
+
}
|
97
|
+
@component = described_class.new *(args.push properties)
|
98
|
+
bounds = @component.bounds
|
99
|
+
[bounds.minX, bounds.minY, bounds.width, bounds.height].should == [3, 2, 10, 10]
|
100
|
+
@component.minimum_size.should == Awt::Dimension.new(20, 20)
|
101
|
+
@component.preferred_size.should == Awt::Dimension.new(30, 30)
|
102
|
+
@component.maximum_size.should == Awt::Dimension.new(40, 40)
|
103
|
+
end
|
42
104
|
end
|
43
105
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: swing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- arvicco
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/swing/controls.rb
|
58
58
|
- lib/swing/j_button.rb
|
59
59
|
- lib/swing/j_check_box.rb
|
60
|
+
- lib/swing/j_component.rb
|
60
61
|
- lib/swing/j_frame.rb
|
61
62
|
- lib/swing/j_label.rb
|
62
63
|
- lib/swing/j_list.rb
|