comparison org.eclipse.jface.text/src/org/eclipse/jface/internal/text/InformationControlReplacer.d @ 12:bc29606a740c

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