/[eiffelstudio]/branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_change_color_command.e
ViewVC logotype

Contents of /branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_change_color_command.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62171 - (show annotations)
Tue Aug 1 01:27:17 2006 UTC (13 years, 4 months ago) by larryl
File size: 8759 byte(s)
First commit docking tabbed Eiffel Studio.
1 indexing
2 description : "Command to change color of something."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date : "$Date$"
6 revision : "$Revision$"
7
8 class
9 EB_CHANGE_COLOR_COMMAND
10
11 inherit
12 EB_CONTEXT_DIAGRAM_COMMAND
13 redefine
14 new_toolbar_item
15 end
16
17 BON_CONSTANTS
18
19 create
20 make
21
22 feature -- Basic operations
23
24 execute is
25 -- Perform on every class on the diagram.
26 local
27 class_list: ARRAYED_LIST [BON_CLASS_FIGURE]
28 old_color_table, new_color_table: HASH_TABLE [EV_COLOR, STRING]
29 l_nodes: LIST [EG_LINKABLE_FIGURE]
30 bcf: BON_CLASS_FIGURE
31 do
32 create change_color_dialog
33 change_color_dialog.set_color (bon_class_fill_color)
34 change_color_dialog.show_modal_to_window (tool.develop_window.window)
35
36 create class_list.make (20)
37 create old_color_table.make (20)
38 create new_color_table.make (20)
39 from
40 l_nodes := tool.world.flat_classes
41 l_nodes.start
42 until
43 l_nodes.after
44 loop
45 bcf ?= l_nodes.item
46 if bcf /= Void then
47 new_color_table.put (change_color_dialog.color, bcf.model.name)
48 old_color_table.put (bcf.background_color, bcf.model.name)
49 class_list.extend (bcf)
50 end
51 l_nodes.forth
52 end
53 history.do_named_undoable (
54 Interface_names.t_Diagram_change_color_cmd,
55 agent change_color_all (class_list, new_color_table),
56 agent change_color_all (class_list, old_color_table))
57 end
58
59 feature -- Access
60
61 new_toolbar_item (display_text: BOOLEAN): EB_COMMAND_TOOL_BAR_BUTTON is
62 -- Create a new toolbar button for this command.
63 do
64 Result := Precursor (display_text)
65 Result.select_actions.wipe_out
66 Result.select_actions.extend (agent execute)
67 Result.drop_actions.extend (agent execute_with_stone)
68 Result.drop_actions.extend (agent execute_with_list)
69 Result.drop_actions.extend (agent execute_with_cluster_stone)
70 end
71
72 feature {NONE} -- Implementation
73
74 execute_with_cluster_stone (a_stone: CLUSTER_FIGURE_STONE) is
75 -- Colorize all classes in `a_stone'.
76 local
77 cf: BON_CLASS_FIGURE
78 class_list: ARRAYED_LIST [BON_CLASS_FIGURE]
79 old_color_table, new_color_table: HASH_TABLE [EV_COLOR, STRING]
80 es_class: ES_CLASS
81 l_nodes: ARRAYED_LIST [ES_CLASS]
82 do
83 create change_color_dialog
84 change_color_dialog.set_color (bon_class_fill_color)
85 change_color_dialog.show_modal_to_window (tool.develop_window.window)
86
87 create class_list.make (1)
88 create old_color_table.make (1)
89 create new_color_table.make (1)
90
91 l_nodes := a_stone.source.model.sub_nodes_recursive
92
93 from
94 l_nodes.start
95 until
96 l_nodes.after
97 loop
98 es_class := l_nodes.item
99 cf ?= tool.world.figure_from_model (es_class)
100 if cf /= Void then
101 new_color_table.put (change_color_dialog.color, cf.model.name)
102 old_color_table.put (cf.background_color, cf.model.name)
103 class_list.extend (cf)
104 end
105 l_nodes.forth
106 end
107
108 history.do_named_undoable (
109 Interface_names.t_Diagram_change_color_cmd,
110 agent change_color_all (class_list, new_color_table),
111 agent change_color_all (class_list, old_color_table))
112 end
113
114
115 execute_with_stone (a_stone: CLASSI_FIGURE_STONE) is
116 -- Create a development window and process `a_stone'.
117 require
118 a_stone_not_void: a_stone /= Void
119 local
120 cf: BON_CLASS_FIGURE
121 do
122 cf ?= a_stone.source
123 if cf /= Void then
124 create change_color_dialog
125 change_color_dialog.set_color (cf.background_color)
126 change_color_dialog.show_modal_to_window (tool.develop_window.window)
127 if not change_color_dialog.color.is_equal (cf.background_color) then
128 history.do_named_undoable (
129 Interface_names.t_Diagram_change_color_cmd,
130 agent change_color (cf, change_color_dialog.color),
131 agent change_color (cf, cf.background_color))
132 end
133 end
134 end
135
136 execute_with_list (a_list: CLASS_FIGURE_LIST_STONE) is
137 -- Colorize all classes in `a_list'.
138 local
139 cf: BON_CLASS_FIGURE
140 class_list: ARRAYED_LIST [BON_CLASS_FIGURE]
141 l_classes: LIST [EIFFEL_CLASS_FIGURE]
142 old_color_table, new_color_table: HASH_TABLE [EV_COLOR, STRING]
143 do
144 create change_color_dialog
145 change_color_dialog.set_color (bon_class_fill_color)
146 change_color_dialog.show_modal_to_window (tool.develop_window.window)
147
148 l_classes := a_list.classes
149 create old_color_table.make (l_classes.count)
150 create new_color_table.make (l_classes.count)
151 create class_list.make (l_classes.count)
152 from
153 l_classes.start
154 until
155 l_classes.after
156 loop
157 cf ?= l_classes.item
158 if cf /= Void then
159 new_color_table.put (change_color_dialog.color, cf.model.name)
160 old_color_table.put (cf.background_color, cf.model.name)
161 class_list.extend (cf)
162 end
163 l_classes.forth
164 end
165 history.do_named_undoable (
166 Interface_names.t_Diagram_change_color_cmd,
167 agent change_color_all (class_list, new_color_table),
168 agent change_color_all (class_list, old_color_table))
169 end
170
171 change_font (cf: BON_CLASS_FIGURE; a_color: EV_COLOR) is
172 -- Change color of class figure names in order to
173 -- keep them readable.
174 local
175 diff: DOUBLE
176 do
177 diff := a_color.lightness - bon_class_name_color.lightness
178 if diff.abs > 0.3 then
179 cf.set_class_name_color (bon_class_name_color)
180 elseif (a_color.blue > 0.8 and (a_color.green + a_color.red) < 0.5) or a_color.lightness < 0.4 then
181 cf.set_class_name_color (default_colors.white)
182 else
183 cf.set_class_name_color (default_colors.black)
184 end
185 diff := a_color.lightness - bon_generics_color.lightness
186 if diff.abs > 0.3 then
187 cf.set_generics_color (bon_generics_color)
188 elseif (a_color.blue > 0.8 and (a_color.green + a_color.red) < 0.5) or a_color.lightness < 0.4 then
189 cf.set_generics_color (default_colors.white)
190 else
191 cf.set_generics_color (default_colors.black)
192 end
193 end
194
195 change_color (a_class: BON_CLASS_FIGURE; new_color: EV_COLOR) is
196 -- Change color of `a_class' to `new_color'.
197 do
198 change_font (a_class, new_color)
199 a_class.set_background_color (new_color)
200 tool.world.update_cluster_legend
201 tool.projector.project
202 end
203
204 change_color_all (classes: LIST [BON_CLASS_FIGURE]; color_table: HASH_TABLE [EV_COLOR, STRING]) is
205 -- Change color of `classes' according to `color_table'.
206 require
207 classes_exist: classes /= Void
208 color_table_exist: color_table /= Void
209 local
210 cf: BON_CLASS_FIGURE
211 c: EV_COLOR
212 do
213 from
214 classes.start
215 until
216 classes.after
217 loop
218 cf := classes.item
219 c := color_table.item (classes.item.model.name)
220 if c /= Void then
221 -- change_color (cf, c)
222 change_font (classes.item, c)
223 cf.set_background_color (c)
224 end
225 classes.forth
226 end
227
228 tool.world.update_cluster_legend
229 tool.projector.project
230 end
231
232 pixmap: EV_PIXMAP is
233 -- Pixmaps representing the command.
234 do
235 Result := pixmaps.icon_pixmaps.diagram_choose_color_icon
236 end
237
238 pixel_buffer: EV_PIXEL_BUFFER is
239 -- Pixel buffer representing the command.
240 do
241 -- Currently there is no pixel buffer for this command.
242 end
243
244 tooltip: STRING is
245 -- Tooltip for the toolbar button.
246 do
247 Result := Interface_names.f_diagram_change_color
248 end
249
250 name: STRING is "Color"
251 -- Name of the command. Used to store the command in the
252 -- preferences.
253
254 change_color_dialog: EV_COLOR_DIALOG
255 -- Dialog that allows to choose a color.
256
257 default_colors: EV_STOCK_COLORS is
258 -- Eiffel Vision colors.
259 once
260 create Result
261 end
262
263 indexing
264 copyright: "Copyright (c) 1984-2006, Eiffel Software"
265 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
266 licensing_options: "http://www.eiffel.com/licensing"
267 copying: "[
268 This file is part of Eiffel Software's Eiffel Development Environment.
269
270 Eiffel Software's Eiffel Development Environment is free
271 software; you can redistribute it and/or modify it under
272 the terms of the GNU General Public License as published
273 by the Free Software Foundation, version 2 of the License
274 (available at the URL listed under "license" above).
275
276 Eiffel Software's Eiffel Development Environment is
277 distributed in the hope that it will be useful, but
278 WITHOUT ANY WARRANTY; without even the implied warranty
279 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
280 See the GNU General Public License for more details.
281
282 You should have received a copy of the GNU General Public
283 License along with Eiffel Software's Eiffel Development
284 Environment; if not, write to the Free Software Foundation,
285 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
286 ]"
287 source: "[
288 Eiffel Software
289 356 Storke Road, Goleta, CA 93117 USA
290 Telephone 805-685-1006, Fax 805-685-6869
291 Website http://www.eiffel.com
292 Customer support http://support.eiffel.com
293 ]"
294
295 end -- class EB_CHANGE_COLOR_COMMAND
296

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23