Class: NodeView
- Inherits:
-
Object
show all
- Defined in:
- lib/gui/node_view.rb
Constant Summary
collapse
- MIN_MOVE =
5
- NODE_SIZE =
40
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#bg_text ⇒ Object
Returns the value of attribute bg_text.
6
7
8
|
# File 'lib/gui/node_view.rb', line 6
def bg_text
@bg_text
end
|
#group ⇒ Object
Returns the value of attribute group.
6
7
8
|
# File 'lib/gui/node_view.rb', line 6
def group
@group
end
|
#icon ⇒ Object
Returns the value of attribute icon.
6
7
8
|
# File 'lib/gui/node_view.rb', line 6
def icon
@icon
end
|
#image ⇒ Object
Returns the value of attribute image.
6
7
8
|
# File 'lib/gui/node_view.rb', line 6
def image
@image
end
|
#node ⇒ Object
Returns the value of attribute node.
7
8
9
|
# File 'lib/gui/node_view.rb', line 7
def node
@node
end
|
#notification_count ⇒ Object
Returns the value of attribute notification_count.
7
8
9
|
# File 'lib/gui/node_view.rb', line 7
def notification_count
@notification_count
end
|
#notification_sev ⇒ Object
Returns the value of attribute notification_sev.
7
8
9
|
# File 'lib/gui/node_view.rb', line 7
def notification_sev
@notification_sev
end
|
#selected ⇒ Object
Returns the value of attribute selected.
6
7
8
|
# File 'lib/gui/node_view.rb', line 6
def selected
@selected
end
|
#text ⇒ Object
Returns the value of attribute text.
6
7
8
|
# File 'lib/gui/node_view.rb', line 6
def text
@text
end
|
Instance Method Details
#add_notification(sev) ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/gui/node_view.rb', line 9
def add_notification(sev)
@notification_count[$status_value.index(sev)] +=1
if @notification_sev < sev
@notification_sev = sev
end
update_notification_icon()
if $icon.embedded? and !$win.visible? and !$icon.blinking?
$icon.set_blinking(true)
end
end
|
#del_notification(sev) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/gui/node_view.rb', line 20
def del_notification(sev)
@notification_count[$status_value.index(sev)] -=1 if @notification_count[$status_value.index(sev)] > 0
max = @notification_count.max
if max == 0
@notification_sev = UNKNOWN
else
@notification_sev = $status_value[@notification_count.index(max)]
end
update_notification_icon()
end
|
#destroy ⇒ Object
165
166
167
|
# File 'lib/gui/node_view.rb', line 165
def destroy()
@group.parent.remove_child(@group) if !@group.nil?
end
|
#get_node_size ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/gui/node_view.rb', line 63
def get_node_size()
view_size=$config.pixmap_size.to_i()
if @node != nil && @node.map != nil
if $network[@node.map].node_size != nil
view_size=$network[@node.map].node_size
end
end
if view_size <= 0
return NODE_SIZE
else
return view_size
end
end
|
#get_size ⇒ Object
83
84
85
|
# File 'lib/gui/node_view.rb', line 83
def get_size()
return @size
end
|
#get_text ⇒ Object
190
191
192
193
194
|
# File 'lib/gui/node_view.rb', line 190
def get_text()
if @text != nil
@text.text
end
end
|
#hide ⇒ Object
173
174
175
|
# File 'lib/gui/node_view.rb', line 173
def hide()
@group.visibility = Goo::CanvasItem::HIDDEN if !@group.nil?
end
|
#hide_link ⇒ Object
256
257
258
259
260
261
262
|
# File 'lib/gui/node_view.rb', line 256
def hide_link()
if @node.nb_links > 0
@node.get_links().each {|lnk|
lnk.remove_link
}
end
end
|
#hide_selected_node_link ⇒ Object
236
237
238
239
240
241
242
243
244
|
# File 'lib/gui/node_view.rb', line 236
def hide_selected_node_link()
$canvas.get_selected_node.each {|n|
if n.nb_links > 0
n.get_links().each {|lnk|
lnk.hide
}
end
}
end
|
#hide_text ⇒ Object
196
197
198
199
200
201
|
# File 'lib/gui/node_view.rb', line 196
def hide_text()
if @text != nil
@bg_text.visibility = Goo::CanvasItem::HIDDEN
@text.visibility = Goo::CanvasItem::HIDDEN
end
end
|
#icon_color(color) ⇒ Object
228
229
230
231
232
233
234
|
# File 'lib/gui/node_view.rb', line 228
def icon_color(color)
if @icon != nil
Gtk.thread_protect do
@icon.fill_color_rgba = color
end
end
end
|
#move(x_translate, y_translate) ⇒ Object
159
160
161
162
163
|
# File 'lib/gui/node_view.rb', line 159
def move(x_translate, y_translate)
@node.x += x_translate
@node.y += y_translate
@group.translate(x_translate, y_translate)
end
|
#move_down ⇒ Object
45
46
47
48
49
|
# File 'lib/gui/node_view.rb', line 45
def move_down()
hide_link()
move(0, MIN_MOVE)
show_link()
end
|
#move_left ⇒ Object
51
52
53
54
55
|
# File 'lib/gui/node_view.rb', line 51
def move_left()
hide_link()
move(-MIN_MOVE, 0)
show_link()
end
|
#move_right ⇒ Object
57
58
59
60
61
|
# File 'lib/gui/node_view.rb', line 57
def move_right()
hide_link()
move(MIN_MOVE, 0)
show_link()
end
|
#move_up ⇒ Object
39
40
41
42
43
|
# File 'lib/gui/node_view.rb', line 39
def move_up()
hide_link()
move(0, -MIN_MOVE)
show_link()
end
|
#reload_bg_text ⇒ Object
need to reload bg text when text label is changed
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/gui/node_view.rb', line 122
def reload_bg_text()
to_size = get_node_size()
siz = to_size + 3*@text.text.size
xdiff = @text.x2 - @text.x1
if siz > xdiff
@bg_text.width = siz
else
@bg_text.width = xdiff
end
@bg_text.width += 5
@bg_text.x = @text.x - @bg_text.width/2
@bg_text.y = @icon.y + to_size + 5
end
|
#reload_label_colors ⇒ Object
136
137
138
139
140
141
|
# File 'lib/gui/node_view.rb', line 136
def reload_label_colors()
cl = Integer("0x#{rgb_to_hex_color(Gdk::Color.new($config.label_bg[0],$config.label_bg[1],$config.label_bg[2]))}ff")
@bg_text.fill_color_rgba = cl
@bg_text.stroke_color_rgba = cl
@text.fill_color_rgba = Integer("0x#{rgb_to_hex_color(Gdk::Color.new($config.label_text[0],$config.label_text[1],$config.label_text[2]))}ff")
end
|
#reparent(canvas_group) ⇒ Object
79
80
81
|
# File 'lib/gui/node_view.rb', line 79
def reparent(canvas_group)
@group.parent = canvas_group
end
|
#reset_notification ⇒ Object
33
34
35
36
37
|
# File 'lib/gui/node_view.rb', line 33
def reset_notification()
@notification_count = Array.new(4, 0)
@notification_sev = UNKNOWN
end
|
#resize ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/gui/node_view.rb', line 87
def resize()
to_size=get_node_size()
hide_link()
@size=$config.pixmap_size
@image.width=(to_size)*80/100.0
@image.height=(to_size)*80/100.0
@image.x= @icon.x+(to_size/2.0)-@image.width/2.0
@image.y= @icon.y+(to_size/2.0)-@image.height/2.0
old_icon_width = @icon.width
old_icon_height = @icon.height
old_icon_y = @icon.y
@icon.width=to_size
@icon.height=to_size
@text.x = @icon.x + get_node_size()/2
@text.y = @icon.y + get_node_size() + 11
reload_bg_text()
reload_label_colors()
if @node.class == Host
circle_size = to_size/2.0
@notification_group.translate(@icon.width - old_icon_width, @icon.y - old_icon_y)
resize_notification_icon(circle_size)
end
show_link()
end
|
#select ⇒ Object
147
148
149
150
151
|
# File 'lib/gui/node_view.rb', line 147
def select()
@icon.stroke_color = "red"
@icon.line_width = 2.0
@selected=true
end
|
#selected? ⇒ Boolean
143
144
145
|
# File 'lib/gui/node_view.rb', line 143
def selected?()
return @selected==true
end
|
#set_image(img_path) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/gui/node_view.rb', line 210
def set_image(img_path)
if @image != nil
full_img_path="#{PIXMAP_PATH}/"+img_path
if FileTest.exist?(full_img_path)
begin
Gtk.thread_protect do
node_size = get_node_size()
@image.pixbuf = Gdk::Pixbuf.new(full_img_path, node_size, node_size)
@image.width=(node_size)*80/100.0
@image.height=(node_size)*80/100.0
end
rescue Exception => msg
$log.error("Image is corrupted #{msg}")
end
end
end
end
|
#set_text(txt) ⇒ Object
183
184
185
186
187
188
|
# File 'lib/gui/node_view.rb', line 183
def set_text(txt)
if (@text != nil) && (@text.text != txt)
@text.text = txt
reload_bg_text()
end
end
|
#set_text_color(color) ⇒ Object
177
178
179
180
181
|
# File 'lib/gui/node_view.rb', line 177
def set_text_color(color)
if @text != nil
@text.fill_color = color
end
end
|
#show ⇒ Object
169
170
171
|
# File 'lib/gui/node_view.rb', line 169
def show()
@group.visibility = Goo::CanvasItem::VISIBLE if !@group.nil?
end
|
#show_link ⇒ Object
264
265
266
267
268
269
270
|
# File 'lib/gui/node_view.rb', line 264
def show_link()
if @node.nb_links > 0
@node.get_links().each {|lnk|
lnk.display
}
end
end
|
#show_selected_node_link ⇒ Object
246
247
248
249
250
251
252
253
254
|
# File 'lib/gui/node_view.rb', line 246
def show_selected_node_link()
$canvas.get_selected_node.each {|n|
if n.nb_links > 0
n.get_links().each {|lnk|
lnk.show
}
end
}
end
|
#show_text ⇒ Object
203
204
205
206
207
208
|
# File 'lib/gui/node_view.rb', line 203
def show_text()
if @text != nil
@bg_text.visibility = Goo::CanvasItem::VISIBLE
@text.visibility = Goo::CanvasItem::VISIBLE
end
end
|
#unlink_node ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
# File 'lib/gui/node_view.rb', line 272
def unlink_node()
node_t=$canvas.get_selected_node()
node_t_size=node_t.size
if node_t_size == 0
@node.del_all_links()
elsif node_t_size == 1
node_t[0].del_all_links()
else
cpt=0
while cpt < node_t_size do
node_id=node_t.shift
node_t.each { |node2_id|
if node_id.linked(node2_id) == 1
node_id.del_node_link(node2_id)
end
}
cpt+=1
end
end
end
|
#unselect ⇒ Object
153
154
155
156
157
|
# File 'lib/gui/node_view.rb', line 153
def unselect()
@icon.stroke_color = "black"
@icon.line_width = 1.0
@selected=false
end
|