Mercurial > projects > dwt-addons
annotate dwtx/jface/internal/text/InformationControlReplacer.d @ 138:b6bad70d540a
Regex instanceof changes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 02:26:23 +0200 |
parents | 51e6e63f930e |
children | 26688fec6d23 |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.internal.text.InformationControlReplacer; | |
14 | |
131 | 15 import dwtx.jface.internal.text.NonDeletingPositionUpdater; // packageimport |
16 import dwtx.jface.internal.text.InternalAccessor; // packageimport | |
17 import dwtx.jface.internal.text.StickyHoverManager; // packageimport | |
18 import dwtx.jface.internal.text.TableOwnerDrawSupport; // packageimport | |
19 import dwtx.jface.internal.text.DelayedInputChangeListener; // packageimport | |
20 | |
21 | |
129 | 22 import dwt.dwthelper.utils; |
23 | |
24 | |
25 | |
26 import dwt.graphics.Point; | |
27 import dwt.graphics.Rectangle; | |
28 import dwt.widgets.Shell; | |
29 import dwtx.jface.text.AbstractInformationControlManager; | |
30 import dwtx.jface.text.AbstractReusableInformationControlCreator; | |
31 import dwtx.jface.text.DefaultInformationControl; | |
32 import dwtx.jface.text.IInformationControl; | |
33 import dwtx.jface.text.IInformationControlCreator; | |
34 import dwtx.jface.text.IInformationControlExtension2; | |
35 import dwtx.jface.text.IInformationControlExtension3; | |
36 import dwtx.jface.util.Geometry; | |
37 | |
38 | |
39 /** | |
40 * An information control replacer can replace an | |
41 * {@link AbstractInformationControlManager}'s control. | |
42 * | |
43 * @see AbstractInformationControlManager#setInformationControlReplacer(InformationControlReplacer) | |
44 * @since 3.4 | |
45 */ | |
46 public class InformationControlReplacer : AbstractInformationControlManager { | |
47 | |
48 /** | |
49 * Minimal width in pixels. | |
50 */ | |
51 private static final int MIN_WIDTH= 80; | |
52 /** | |
53 * Minimal height in pixels. | |
54 */ | |
55 private static final int MIN_HEIGHT= 50; | |
56 | |
57 /** | |
58 * Default control creator. | |
59 */ | |
60 protected static class DefaultInformationControlCreator : AbstractReusableInformationControlCreator { | |
61 public IInformationControl doCreateInformationControl(Shell shell) { | |
62 return new DefaultInformationControl(shell, true); | |
63 } | |
64 } | |
65 | |
66 private bool fIsReplacing; | |
67 private Object fReplacableInformation; | |
68 private bool fDelayedInformationSet; | |
69 private Rectangle fReplaceableArea; | |
70 private Rectangle fContentBounds; | |
71 | |
72 | |
73 /** | |
74 * Creates a new information control replacer. | |
75 * | |
76 * @param creator the default information control creator | |
77 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
78 public this(IInformationControlCreator creator) { |
129 | 79 super(creator); |
80 takesFocusWhenVisible(false); | |
81 } | |
82 | |
83 /** | |
84 * Replace the information control. | |
85 * | |
86 * @param informationPresenterControlCreator the information presenter control creator | |
87 * @param contentBounds the bounds of the content area of the information control | |
88 * @param information the information to show | |
89 * @param subjectArea the subject area | |
90 * @param takeFocus <code>true</code> iff the replacing information control should take focus | |
91 */ | |
92 public void replaceInformationControl(IInformationControlCreator informationPresenterControlCreator, Rectangle contentBounds, Object information, final Rectangle subjectArea, bool takeFocus) { | |
93 | |
94 try { | |
95 fIsReplacing= true; | |
96 if (! fDelayedInformationSet) | |
97 fReplacableInformation= information; | |
98 else | |
99 takeFocus= true; // delayed input has been set, so the original info control must have been focused | |
100 fContentBounds= contentBounds; | |
101 fReplaceableArea= subjectArea; | |
102 | |
103 setCustomInformationControlCreator(informationPresenterControlCreator); | |
104 | |
105 takesFocusWhenVisible(takeFocus); | |
106 | |
107 showInformation(); | |
108 } finally { | |
109 fIsReplacing= false; | |
110 fReplacableInformation= null; | |
111 fDelayedInformationSet= false; | |
112 fReplaceableArea= null; | |
113 setCustomInformationControlCreator(null); | |
114 } | |
115 } | |
116 | |
117 /* | |
118 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() | |
119 */ | |
120 protected void computeInformation() { | |
121 if (fIsReplacing && fReplacableInformation !is null) { | |
122 setInformation(fReplacableInformation, fReplaceableArea); | |
123 return; | |
124 } | |
125 | |
134 | 126 if cast(DEBUG) |
129 | 127 System.out.println("InformationControlReplacer: no active replaceable"); //$NON-NLS-1$ |
128 } | |
129 | |
130 /** | |
131 * Opens the information control with the given information and the specified | |
132 * subject area. It also activates the information control closer. | |
133 * | |
134 * @param subjectArea the information area | |
135 * @param information the information | |
136 */ | |
137 public void showInformationControl(Rectangle subjectArea, Object information) { | |
138 IInformationControl informationControl= getInformationControl(); | |
139 | |
140 Rectangle controlBounds= fContentBounds; | |
138 | 141 if ( cast(IInformationControlExtension3)informationControl ) { |
134 | 142 IInformationControlExtension3 iControl3= cast(IInformationControlExtension3) informationControl; |
129 | 143 Rectangle trim= iControl3.computeTrim(); |
144 controlBounds= Geometry.add(controlBounds, trim); | |
145 | |
146 /* | |
147 * Ensure minimal size. Interacting with a tiny information control | |
148 * (resizing, selecting text) would be a pain. | |
149 */ | |
150 controlBounds.width= Math.max(controlBounds.width, MIN_WIDTH); | |
151 controlBounds.height= Math.max(controlBounds.height, MIN_HEIGHT); | |
152 | |
153 getInternalAccessor().cropToClosestMonitor(controlBounds); | |
154 } | |
155 | |
156 Point location= Geometry.getLocation(controlBounds); | |
157 Point size= Geometry.getSize(controlBounds); | |
158 | |
159 // Caveat: some IInformationControls fail unless setSizeConstraints(..) is called with concrete values | |
160 informationControl.setSizeConstraints(size.x, size.y); | |
161 | |
138 | 162 if ( cast(IInformationControlExtension2)informationControl ) |
134 | 163 (cast(IInformationControlExtension2) informationControl).setInput(information); |
129 | 164 else |
165 informationControl.setInformation(information.toString()); | |
166 | |
167 informationControl.setLocation(location); | |
168 informationControl.setSize(size.x, size.y); | |
169 | |
170 showInformationControl(subjectArea); | |
171 } | |
172 | |
173 /* | |
174 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() | |
175 */ | |
176 public void hideInformationControl() { | |
177 super.hideInformationControl(); | |
178 } | |
179 | |
180 /** | |
181 * @param input the delayed input, or <code>null</code> to request cancellation | |
182 */ | |
183 public void setDelayedInput(Object input) { | |
184 fReplacableInformation= input; | |
185 if (! isReplacing()) { | |
186 fDelayedInformationSet= true; | |
187 } else if (getCurrentInformationControl2() instanceof IInformationControlExtension2) { | |
134 | 188 (cast(IInformationControlExtension2) getCurrentInformationControl2()).setInput(input); |
129 | 189 } else if (getCurrentInformationControl2() !is null) { |
190 getCurrentInformationControl2().setInformation(input.toString()); | |
191 } | |
192 } | |
193 | |
194 /** | |
195 * Tells whether the replacer is currently replacing another information control. | |
196 * | |
197 * @return <code>true</code> while code from {@link #replaceInformationControl(IInformationControlCreator, Rectangle, Object, Rectangle, bool)} is run | |
198 */ | |
199 public bool isReplacing() { | |
200 return fIsReplacing; | |
201 } | |
202 | |
203 /** | |
204 * @return the current information control, or <code>null</code> if none available | |
205 */ | |
206 public IInformationControl getCurrentInformationControl2() { | |
207 return getInternalAccessor().getCurrentInformationControl(); | |
208 } | |
209 | |
210 /** | |
211 * The number of pixels to blow up the keep-up zone. | |
212 * | |
213 * @return the margin in pixels | |
214 */ | |
215 public int getKeepUpMargin() { | |
216 return 15; | |
217 } | |
218 } |