private void begin(WebPlotView pv, ScreenPt spt) { WebPlot plot = pv.getPrimaryPlot(); pv.fixScrollPosition(); _mouseInfo.setEnableAllPersistent(true); _mouseInfo.setEnableAllExclusive(false); switch (_mode) { case SELECT: _firstPt = plot.getImageWorkSpaceCoords(spt); _currentPt = _firstPt; break; case EDIT: LineSelection sel = (LineSelection) pv.getAttribute(WebPlot.ACTIVE_DISTANCE); if (sel == null) { WebAssert.tst(false, "no RecSelection found in plot"); } ImageWorkSpacePt ptAry[] = new ImageWorkSpacePt[] {sel.getPt1(), sel.getPt2()}; int idx = findClosestPtIdx(plot, ptAry, spt); if (idx < 0) return; ScreenPt testPt = plot.getScreenCoords(ptAry[idx]); double dist = distance(testPt, spt); if (dist < EDIT_DISTANCE && dist > -1) { int oppoIdx = idx == 0 ? 1 : 0; _firstPt = ptAry[oppoIdx]; _currentPt = ptAry[idx]; } else { _firstPt = plot.getImageWorkSpaceCoords(spt); _currentPt = _firstPt; } break; case OFF: releaseMouse(); break; default: WebAssert.argTst(false, "only support for SelectType of SELECT EDIT, OFF"); break; } }
private int findClosestPtIdx(WebPlot plot, Pt inPtAry[], ScreenPt spt) { int idx = -1; ScreenPt ptAry[] = new ScreenPt[inPtAry.length]; for (int i = 0; (i < ptAry.length); i++) { ptAry[i] = plot.getScreenCoords(inPtAry[i]); } double dist = Double.MAX_VALUE; double testDist; for (int i = 0; (i < ptAry.length); i++) { if (ptAry[i] != null) { testDist = distance(ptAry[i], spt); if (testDist < dist && testDist > -1) { dist = testDist; idx = i; } } } return idx; }