|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Business Objects SA - getThreshold() |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.gef; |
12 |
package org.eclipse.gef; |
| 12 |
|
13 |
|
|
Lines 165-170
Link Here
|
| 165 |
} |
166 |
} |
| 166 |
|
167 |
|
| 167 |
/** |
168 |
/** |
|
|
169 |
* The sensitivity of the snapping. Corrections greater than this value will not occur. |
| 170 |
* Subclasses may override this method to change the sensitivity. |
| 171 |
* |
| 172 |
* @return the snapping threshold |
| 173 |
* @since 3.2 |
| 174 |
*/ |
| 175 |
protected double getThreshold() { |
| 176 |
return THRESHOLD; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 168 |
* Generates a list of parts which should be snapped to. The list is the original |
180 |
* Generates a list of parts which should be snapped to. The list is the original |
| 169 |
* children, minus the given exclusions, minus and children whose figures are not visible. |
181 |
* children, minus the given exclusions, minus and children whose figures are not visible. |
| 170 |
* @since 3.0 |
182 |
* @since 3.0 |
|
Lines 196-202
Link Here
|
| 196 |
* @param vert <code>true</code> if the correction is vertical |
208 |
* @param vert <code>true</code> if the correction is vertical |
| 197 |
* @param near the left/top side of the rectangle |
209 |
* @param near the left/top side of the rectangle |
| 198 |
* @param far the right/bottom side of the rectangle |
210 |
* @param far the right/bottom side of the rectangle |
| 199 |
* @return the correction amount or THRESHOLD if no correction was made |
211 |
* @return the correction amount or getThreshold () if no correction was made |
| 200 |
*/ |
212 |
*/ |
| 201 |
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, |
213 |
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, |
| 202 |
double near, double far) { |
214 |
double near, double far) { |
|
Lines 208-234
Link Here
|
| 208 |
if ((int)(near - far) % 2 != 0) |
220 |
if ((int)(near - far) % 2 != 0) |
| 209 |
total -= 1.0; |
221 |
total -= 1.0; |
| 210 |
double result = getCorrectionFor(entries, extendedData, vert, total / 2, 0); |
222 |
double result = getCorrectionFor(entries, extendedData, vert, total / 2, 0); |
| 211 |
if (result == THRESHOLD) |
223 |
if (result == getThreshold ()) |
| 212 |
result = getCorrectionFor(entries, extendedData, vert, near, -1); |
224 |
result = getCorrectionFor(entries, extendedData, vert, near, -1); |
| 213 |
if (result == THRESHOLD) |
225 |
if (result == getThreshold ()) |
| 214 |
result = getCorrectionFor(entries, extendedData, vert, far, 1); |
226 |
result = getCorrectionFor(entries, extendedData, vert, far, 1); |
| 215 |
return result; |
227 |
return result; |
| 216 |
} |
228 |
} |
| 217 |
|
229 |
|
| 218 |
/** |
230 |
/** |
| 219 |
* Returns the correction value between ± {@link #THRESHOLD}, or the THRESHOLD if no |
231 |
* Returns the correction value between ± {@link #getThreshold ()}, or the getThreshold () |
| 220 |
* corrections were found. |
232 |
* if no corrections were found. |
| 221 |
* @param entries the entries |
233 |
* @param entries the entries |
| 222 |
* @param extendedData the map for setting values |
234 |
* @param extendedData the map for setting values |
| 223 |
* @param vert <code>true</code> if vertical |
235 |
* @param vert <code>true</code> if vertical |
| 224 |
* @param value the value being corrected |
236 |
* @param value the value being corrected |
| 225 |
* @param side which sides should be considered |
237 |
* @param side which sides should be considered |
| 226 |
* @return the correction or THRESHOLD if no correction was made |
238 |
* @return the correction or getThreshold () if no correction was made |
| 227 |
*/ |
239 |
*/ |
| 228 |
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, |
240 |
protected double getCorrectionFor(Entry entries[], Map extendedData, boolean vert, |
| 229 |
double value, int side) { |
241 |
double value, int side) { |
| 230 |
double resultMag = THRESHOLD; |
242 |
double resultMag = getThreshold (); |
| 231 |
double result = THRESHOLD; |
243 |
double result = getThreshold (); |
| 232 |
|
244 |
|
| 233 |
String property; |
245 |
String property; |
| 234 |
if (side == -1) |
246 |
if (side == -1) |
|
Lines 322-341
Link Here
|
| 322 |
} |
334 |
} |
| 323 |
|
335 |
|
| 324 |
if ((snapOrientation & HORIZONTAL) != 0) { |
336 |
if ((snapOrientation & HORIZONTAL) != 0) { |
| 325 |
double xcorrect = THRESHOLD; |
337 |
double xcorrect = getThreshold (); |
| 326 |
xcorrect = getCorrectionFor(cols, request.getExtendedData(), true, |
338 |
xcorrect = getCorrectionFor(cols, request.getExtendedData(), true, |
| 327 |
baseRect.preciseX, baseRect.preciseRight()); |
339 |
baseRect.preciseX, baseRect.preciseRight()); |
| 328 |
if (xcorrect != THRESHOLD) { |
340 |
if (xcorrect != getThreshold ()) { |
| 329 |
snapOrientation &= ~HORIZONTAL; |
341 |
snapOrientation &= ~HORIZONTAL; |
| 330 |
correction.preciseX += xcorrect; |
342 |
correction.preciseX += xcorrect; |
| 331 |
} |
343 |
} |
| 332 |
} |
344 |
} |
| 333 |
|
345 |
|
| 334 |
if ((snapOrientation & VERTICAL) != 0) { |
346 |
if ((snapOrientation & VERTICAL) != 0) { |
| 335 |
double ycorrect = THRESHOLD; |
347 |
double ycorrect = getThreshold (); |
| 336 |
ycorrect = getCorrectionFor(rows, request.getExtendedData(), false, |
348 |
ycorrect = getCorrectionFor(rows, request.getExtendedData(), false, |
| 337 |
baseRect.preciseY, baseRect.preciseBottom()); |
349 |
baseRect.preciseY, baseRect.preciseBottom()); |
| 338 |
if (ycorrect != THRESHOLD) { |
350 |
if (ycorrect != getThreshold ()) { |
| 339 |
snapOrientation &= ~VERTICAL; |
351 |
snapOrientation &= ~VERTICAL; |
| 340 |
correction.preciseY += ycorrect; |
352 |
correction.preciseY += ycorrect; |
| 341 |
} |
353 |
} |
|
Lines 344-350
Link Here
|
| 344 |
if ((snapOrientation & EAST) != 0) { |
356 |
if ((snapOrientation & EAST) != 0) { |
| 345 |
double rightCorrection = getCorrectionFor(cols, request.getExtendedData(), |
357 |
double rightCorrection = getCorrectionFor(cols, request.getExtendedData(), |
| 346 |
true, baseRect.preciseRight() - 1, 1); |
358 |
true, baseRect.preciseRight() - 1, 1); |
| 347 |
if (rightCorrection != THRESHOLD) { |
359 |
if (rightCorrection != getThreshold ()) { |
| 348 |
snapOrientation &= ~EAST; |
360 |
snapOrientation &= ~EAST; |
| 349 |
correction.preciseWidth += rightCorrection; |
361 |
correction.preciseWidth += rightCorrection; |
| 350 |
} |
362 |
} |
|
Lines 353-359
Link Here
|
| 353 |
if ((snapOrientation & WEST) != 0) { |
365 |
if ((snapOrientation & WEST) != 0) { |
| 354 |
double leftCorrection = getCorrectionFor(cols, request.getExtendedData(), |
366 |
double leftCorrection = getCorrectionFor(cols, request.getExtendedData(), |
| 355 |
true, baseRect.preciseX, -1); |
367 |
true, baseRect.preciseX, -1); |
| 356 |
if (leftCorrection != THRESHOLD) { |
368 |
if (leftCorrection != getThreshold ()) { |
| 357 |
snapOrientation &= ~WEST; |
369 |
snapOrientation &= ~WEST; |
| 358 |
correction.preciseWidth -= leftCorrection; |
370 |
correction.preciseWidth -= leftCorrection; |
| 359 |
correction.preciseX += leftCorrection; |
371 |
correction.preciseX += leftCorrection; |
|
Lines 363-369
Link Here
|
| 363 |
if ((snapOrientation & SOUTH) != 0) { |
375 |
if ((snapOrientation & SOUTH) != 0) { |
| 364 |
double bottom = getCorrectionFor(rows, request.getExtendedData(), false, |
376 |
double bottom = getCorrectionFor(rows, request.getExtendedData(), false, |
| 365 |
baseRect.preciseBottom() - 1, 1); |
377 |
baseRect.preciseBottom() - 1, 1); |
| 366 |
if (bottom != THRESHOLD) { |
378 |
if (bottom != getThreshold ()) { |
| 367 |
snapOrientation &= ~SOUTH; |
379 |
snapOrientation &= ~SOUTH; |
| 368 |
correction.preciseHeight += bottom; |
380 |
correction.preciseHeight += bottom; |
| 369 |
} |
381 |
} |
|
Lines 372-378
Link Here
|
| 372 |
if ((snapOrientation & NORTH) != 0) { |
384 |
if ((snapOrientation & NORTH) != 0) { |
| 373 |
double topCorrection = getCorrectionFor(rows, request.getExtendedData(), |
385 |
double topCorrection = getCorrectionFor(rows, request.getExtendedData(), |
| 374 |
false, baseRect.preciseY, -1); |
386 |
false, baseRect.preciseY, -1); |
| 375 |
if (topCorrection != THRESHOLD) { |
387 |
if (topCorrection != getThreshold ()) { |
| 376 |
snapOrientation &= ~NORTH; |
388 |
snapOrientation &= ~NORTH; |
| 377 |
correction.preciseHeight -= topCorrection; |
389 |
correction.preciseHeight -= topCorrection; |
| 378 |
correction.preciseY += topCorrection; |
390 |
correction.preciseY += topCorrection; |