1 | /* |
2 | * Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.edit.policies; |
5 | |
6 | import org.eclipse.draw2d.ColorConstants; |
7 | import org.eclipse.draw2d.Figure; |
8 | import org.eclipse.draw2d.Graphics; |
9 | import org.eclipse.draw2d.IFigure; |
10 | import org.eclipse.draw2d.Label; |
11 | import org.eclipse.draw2d.RectangleFigure; |
12 | import org.eclipse.draw2d.geometry.Rectangle; |
13 | import org.eclipse.gef.editpolicies.SelectionEditPolicy; |
14 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel; |
15 | |
16 | /** |
17 | * @generated |
18 | */ |
19 | public class PalladioComponentModelTextSelectionEditPolicy extends |
20 | SelectionEditPolicy { |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | private IFigure selectionFeedbackFigure; |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | private IFigure focusFeedbackFigure; |
31 | |
32 | /** |
33 | * @generated |
34 | */ |
35 | protected void showPrimarySelection() { |
36 | if (getHostFigure() instanceof WrapLabel) { |
37 | ((WrapLabel) getHostFigure()).setSelected(true); |
38 | ((WrapLabel) getHostFigure()).setFocus(true); |
39 | } else { |
40 | showSelection(); |
41 | showFocus(); |
42 | } |
43 | } |
44 | |
45 | /** |
46 | * @generated |
47 | */ |
48 | protected void showSelection() { |
49 | if (getHostFigure() instanceof WrapLabel) { |
50 | ((WrapLabel) getHostFigure()).setSelected(true); |
51 | ((WrapLabel) getHostFigure()).setFocus(false); |
52 | } else { |
53 | hideSelection(); |
54 | addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure()); |
55 | refreshSelectionFeedback(); |
56 | hideFocus(); |
57 | } |
58 | } |
59 | |
60 | /** |
61 | * @generated |
62 | */ |
63 | protected void hideSelection() { |
64 | if (getHostFigure() instanceof WrapLabel) { |
65 | ((WrapLabel) getHostFigure()).setSelected(false); |
66 | ((WrapLabel) getHostFigure()).setFocus(false); |
67 | } else { |
68 | if (selectionFeedbackFigure != null) { |
69 | removeFeedback(selectionFeedbackFigure); |
70 | selectionFeedbackFigure = null; |
71 | } |
72 | hideFocus(); |
73 | } |
74 | } |
75 | |
76 | /** |
77 | * @generated |
78 | */ |
79 | protected void showFocus() { |
80 | if (getHostFigure() instanceof WrapLabel) { |
81 | ((WrapLabel) getHostFigure()).setFocus(true); |
82 | } else { |
83 | hideFocus(); |
84 | addFeedback(focusFeedbackFigure = createFocusFeedbackFigure()); |
85 | refreshFocusFeedback(); |
86 | } |
87 | } |
88 | |
89 | /** |
90 | * @generated |
91 | */ |
92 | protected void hideFocus() { |
93 | if (getHostFigure() instanceof WrapLabel) { |
94 | ((WrapLabel) getHostFigure()).setFocus(false); |
95 | } else { |
96 | if (focusFeedbackFigure != null) { |
97 | removeFeedback(focusFeedbackFigure); |
98 | focusFeedbackFigure = null; |
99 | } |
100 | } |
101 | } |
102 | |
103 | /** |
104 | * @generated |
105 | */ |
106 | protected Rectangle getFeedbackBounds() { |
107 | Rectangle bounds; |
108 | if (getHostFigure() instanceof Label) { |
109 | bounds = ((Label) getHostFigure()).getTextBounds(); |
110 | bounds.intersect(getHostFigure().getBounds()); |
111 | } else { |
112 | bounds = getHostFigure().getBounds().getCopy(); |
113 | } |
114 | getHostFigure().getParent().translateToAbsolute(bounds); |
115 | getFeedbackLayer().translateToRelative(bounds); |
116 | return bounds; |
117 | } |
118 | |
119 | /** |
120 | * @generated |
121 | */ |
122 | protected IFigure createSelectionFeedbackFigure() { |
123 | if (getHostFigure() instanceof Label) { |
124 | Label feedbackFigure = new Label(); |
125 | feedbackFigure.setOpaque(true); |
126 | feedbackFigure |
127 | .setBackgroundColor(ColorConstants.menuBackgroundSelected); |
128 | feedbackFigure |
129 | .setForegroundColor(ColorConstants.menuForegroundSelected); |
130 | return feedbackFigure; |
131 | } else { |
132 | RectangleFigure feedbackFigure = new RectangleFigure(); |
133 | feedbackFigure.setFill(false); |
134 | return feedbackFigure; |
135 | } |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected IFigure createFocusFeedbackFigure() { |
142 | return new Figure() { |
143 | |
144 | protected void paintFigure(Graphics graphics) { |
145 | graphics.drawFocus(getBounds().getResized(-1, -1)); |
146 | } |
147 | }; |
148 | } |
149 | |
150 | /** |
151 | * @generated |
152 | */ |
153 | protected void updateLabel(Label target) { |
154 | Label source = (Label) getHostFigure(); |
155 | target.setText(source.getText()); |
156 | target.setTextAlignment(source.getTextAlignment()); |
157 | target.setFont(source.getFont()); |
158 | } |
159 | |
160 | /** |
161 | * @generated |
162 | */ |
163 | protected void refreshSelectionFeedback() { |
164 | if (selectionFeedbackFigure != null) { |
165 | if (selectionFeedbackFigure instanceof Label) { |
166 | updateLabel((Label) selectionFeedbackFigure); |
167 | selectionFeedbackFigure.setBounds(getFeedbackBounds()); |
168 | } else { |
169 | selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, |
170 | 5)); |
171 | } |
172 | } |
173 | } |
174 | |
175 | /** |
176 | * @generated |
177 | */ |
178 | protected void refreshFocusFeedback() { |
179 | if (focusFeedbackFigure != null) { |
180 | focusFeedbackFigure.setBounds(getFeedbackBounds()); |
181 | } |
182 | } |
183 | |
184 | /** |
185 | * @generated |
186 | */ |
187 | public void refreshFeedback() { |
188 | refreshSelectionFeedback(); |
189 | refreshFocusFeedback(); |
190 | } |
191 | } |