Class: Glimmer::SWT::Custom::Shape::Line

Inherits:
Glimmer::SWT::Custom::Shape show all
Includes:
PathSegment
Defined in:
lib/glimmer/swt/custom/shape/line.rb

Constant Summary

Constants inherited from Glimmer::SWT::Custom::Shape

String

Instance Attribute Summary

Attributes inherited from Glimmer::SWT::Custom::Shape

#args, #drawable, #extent, #name, #options, #parent, #properties, #shapes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PathSegment

#add_to_geometry, #add_to_swt_path, #dispose, #first_path_segment?, #part_of_path?, #path, #path_segment_geometry_method_name, #previous_path_segment, #root_path

Methods inherited from Glimmer::SWT::Custom::Shape

#absolute_x, #absolute_y, #add_shape, #all_parent_properties, #amend_method_name_options_based_on_properties!, #apply_property_arg_conversions, #apply_shape_arg_conversions!, #apply_shape_arg_defaults!, arg_options, #background_pattern_args, #calculate_args!, #calculate_paint_args!, #calculated_args?, #calculated_args_changed!, #calculated_args_changed_for_defaults!, #calculated_height, #calculated_paint_args_changed!, #calculated_width, #calculated_x, #calculated_y, #can_handle_observation_request?, #center_x, #center_y, #clear_shapes, #composite?, #container?, #content, #convert_properties!, #converted_properties, create, #current_parameter_name?, #default_height, #default_height?, #default_width, #default_width?, #default_x, #default_x?, #default_y, #default_y?, #dispose, #drag_and_move, #drag_and_move=, #drag_source, #drag_source=, #draw?, drop_shapes, #ensure_extent, #expanded_shapes, #fill?, flyweight_method_names, flyweight_patterns, #foreground_pattern_args, gc_instance_methods, #get_attribute, #get_data, #get_parameter_attribute, #gradient?, #handle_observation_request, #has_attribute?, #has_some_background?, #has_some_foreground?, #height_delta, #height_delta=, #include_with_children?, #initialize, #inspect, #inverse_transform_point, keywords, #location, #max_height, #max_height?, #max_width, #max_width?, #method_missing, method_name, #paint, #paint_children, #paint_self, #parameter_index, #parameter_name?, #parent_shape_composites, #parent_shape_containers, #parent_shapes, #pattern, pattern, #pattern_args, #possible_parameter_names, #post_add_content, #respond_to?, #rotate, #rotation_angle, #round?, #set_attribute, #set_data, #set_parameter_attribute, #tolerate_shape_extra_args!, valid?, #width_delta, #width_delta=, #x_delta, #x_delta=, #x_end, #y_delta, #y_delta=, #y_end

Methods included from Properties

attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter

Constructor Details

This class inherits a constructor from Glimmer::SWT::Custom::Shape

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::Custom::Shape

Class Method Details

.include?(x1, y1, x2, y2, x, y) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/glimmer/swt/custom/shape/line.rb', line 41

def include?(x1, y1, x2, y2, x, y)
  distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
  distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2)
  distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
  (distance1 + distance2).to_i == distance.to_i
end

Instance Method Details

#absolute_x1Object



93
94
95
96
97
98
99
# File 'lib/glimmer/swt/custom/shape/line.rb', line 93

def absolute_x1
  if parent.is_a?(Shape) && parent.class != Shape
    parent.absolute_x + x1
  else
    x1
  end
end

#absolute_x2Object



109
110
111
112
113
114
115
# File 'lib/glimmer/swt/custom/shape/line.rb', line 109

def absolute_x2
  if parent.is_a?(Shape) && parent.class != Shape
    parent.absolute_x + x2.to_f
  else
    x2
  end
end

#absolute_y1Object



101
102
103
104
105
106
107
# File 'lib/glimmer/swt/custom/shape/line.rb', line 101

def absolute_y1
  if parent.is_a?(Shape) && parent.class != Shape
    parent.absolute_y + y1
  else
    y1
  end
end

#absolute_y2Object



117
118
119
120
121
122
123
# File 'lib/glimmer/swt/custom/shape/line.rb', line 117

def absolute_y2
  if parent.is_a?(Shape) && parent.class != Shape
    parent.absolute_y + y2.to_f
  else
    y2
  end
end

#boundsObject



57
58
59
60
# File 'lib/glimmer/swt/custom/shape/line.rb', line 57

def bounds
  shape_bounds = geometry.getBounds2D
  org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
end

#default_connected_path_segment_arg_countObject



156
157
158
# File 'lib/glimmer/swt/custom/shape/line.rb', line 156

def default_connected_path_segment_arg_count
  2
end

#default_path_segment_arg_countObject



152
153
154
# File 'lib/glimmer/swt/custom/shape/line.rb', line 152

def default_path_segment_arg_count
  4
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


169
170
171
172
173
174
175
# File 'lib/glimmer/swt/custom/shape/line.rb', line 169

def eql?(other)
  other.is_a?(Line) &&
    x1 == (other && other.respond_to?(:x1) && other.x1) &&
    y1 == (other && other.respond_to?(:y1) && other.y1) &&
    x2 == (other && other.respond_to?(:x2) && other.x2) &&
    y2 == (other && other.respond_to?(:y2) && other.y2)
end

#geometryObject



67
68
69
# File 'lib/glimmer/swt/custom/shape/line.rb', line 67

def geometry
  java.awt.geom.Line2D::Double.new(absolute_x1, absolute_y1, absolute_x2, absolute_y2)
end

#hashObject



178
179
180
# File 'lib/glimmer/swt/custom/shape/line.rb', line 178

def hash
  [x1, y1, x2, y2].hash
end

#heightObject



89
90
91
# File 'lib/glimmer/swt/custom/shape/line.rb', line 89

def height
  size.y
end

#include?(x, y) ⇒ Boolean Also known as: contain?

Returns:

  • (Boolean)


125
126
127
128
129
# File 'lib/glimmer/swt/custom/shape/line.rb', line 125

def include?(x, y)
  x, y = inverse_transform_point(x, y)
  # TODO must account for line width
  Line.include?(absolute_x1, absolute_y1, absolute_x2, absolute_y2, x, y)
end

#irregular?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/glimmer/swt/custom/shape/line.rb', line 139

def irregular?
  true
end

#location_parameter_namesObject



53
54
55
# File 'lib/glimmer/swt/custom/shape/line.rb', line 53

def location_parameter_names
  parameter_names
end

#move_by(x_delta, y_delta) ⇒ Object



132
133
134
135
136
137
# File 'lib/glimmer/swt/custom/shape/line.rb', line 132

def move_by(x_delta, y_delta)
  self.x1 += x_delta
  self.y1 += y_delta
  self.x2 += x_delta
  self.y2 += y_delta
end

#parameter_namesObject



49
50
51
# File 'lib/glimmer/swt/custom/shape/line.rb', line 49

def parameter_names
  [:x1, :y1, :x2, :y2]
end

#path_segment_argsObject



147
148
149
150
# File 'lib/glimmer/swt/custom/shape/line.rb', line 147

def path_segment_args
  # TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point
  @args
end

#path_segment_geometry_argsObject



160
161
162
163
# File 'lib/glimmer/swt/custom/shape/line.rb', line 160

def path_segment_geometry_args
  # TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point
  @args
end

#path_segment_method_nameObject



143
144
145
# File 'lib/glimmer/swt/custom/shape/line.rb', line 143

def path_segment_method_name
  'lineTo'
end

#previous_point_connected?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/glimmer/swt/custom/shape/line.rb', line 165

def previous_point_connected?
  @args.compact.count == 2 && !first_path_segment?
end

#sizeObject



62
63
64
65
# File 'lib/glimmer/swt/custom/shape/line.rb', line 62

def size
  shape_bounds = geometry.getBounds2D
  org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
end

#widthObject



85
86
87
# File 'lib/glimmer/swt/custom/shape/line.rb', line 85

def width
  size.x
end

#xObject

Logical x coordinate relative to parent



72
73
74
75
76
# File 'lib/glimmer/swt/custom/shape/line.rb', line 72

def x
  x_value = bounds.x
  x_value -= parent.absolute_x if parent.is_a?(Shape) && parent.class != Shape
  x_value
end

#yObject

Logical y coordinate relative to parent



79
80
81
82
83
# File 'lib/glimmer/swt/custom/shape/line.rb', line 79

def y
  y_value = bounds.y
  y_value -= parent.absolute_y if parent.is_a?(Shape) && parent.class != Shape
  y_value
end