MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / createNewRoi

Method createNewRoi

ij/src/main/java/ij/ImagePlus.java:2222–2297  ·  view source on GitHub ↗

Starts the process of creating a new selection, where sx and sy are the starting screen coordinates. The selection type is determined by which tool in the tool bar is active. The user interactively sets the selection size and shape.

(int sx, int sy)

Source from the content-addressed store, hash-verified

2220 starting screen coordinates. The selection type is determined by which tool in
2221 the tool bar is active. The user interactively sets the selection size and shape. */
2222 public void createNewRoi(int sx, int sy) {
2223 Roi previousRoi = roi;
2224 deleteRoi(); //also saves the roi as <code>Roi.previousRoi</code> if non-null
2225 Roi prevRoi = Roi.getPreviousRoi();
2226 if (prevRoi != null)
2227 prevRoi.setImage(previousRoi==null ? null : this); //with 'this' it will be recalled in case of ESC
2228 switch (Toolbar.getToolId()) {
2229 case Toolbar.RECTANGLE:
2230 if (Toolbar.getRectToolType()==Toolbar.ROTATED_RECT_ROI)
2231 roi = new RotatedRectRoi(sx, sy, this);
2232 else
2233 roi = new Roi(sx, sy, this, Toolbar.getRoundRectArcSize());
2234 break;
2235 case Toolbar.OVAL:
2236 if (Toolbar.getOvalToolType()==Toolbar.ELLIPSE_ROI)
2237 roi = new EllipseRoi(sx, sy, this);
2238 else
2239 roi = new OvalRoi(sx, sy, this);
2240 break;
2241 case Toolbar.POLYGON:
2242 case Toolbar.POLYLINE:
2243 case Toolbar.ANGLE:
2244 roi = new PolygonRoi(sx, sy, this);
2245 break;
2246 case Toolbar.FREEROI:
2247 case Toolbar.FREELINE:
2248 roi = new FreehandRoi(sx, sy, this);
2249 break;
2250 case Toolbar.LINE:
2251 if ("arrow".equals(Toolbar.getToolName()))
2252 roi = new Arrow(sx, sy, this);
2253 else
2254 roi = new Line(sx, sy, this);
2255 break;
2256 case Toolbar.TEXT:
2257 roi = new TextRoi(sx, sy, this);
2258 ((TextRoi)roi).setPreviousTextRoi(previousRoi);
2259 break;
2260 case Toolbar.POINT:
2261 roi = new PointRoi(sx, sy, this);
2262 if (Prefs.pointAddToOverlay) {
2263 int measurements = Analyzer.getMeasurements();
2264 if (!(Prefs.pointAutoMeasure && (measurements&Measurements.ADD_TO_OVERLAY)!=0))
2265 IJ.run(this, "Add Selection...", "");
2266 Overlay overlay2 = getOverlay();
2267 if (overlay2!=null)
2268 overlay2.drawLabels(!Prefs.noPointLabels);
2269 Prefs.pointAddToManager = false;
2270 }
2271 if (Prefs.pointAutoMeasure || (Prefs.pointAutoNextSlice&&!Prefs.pointAddToManager))
2272 IJ.run(this, "Measure", "");
2273 if (Prefs.pointAddToManager) {
2274 IJ.run(this, "Add to Manager ", "");
2275 ImageCanvas ic = getCanvas();
2276 if (ic!=null) {
2277 RoiManager rm = RoiManager.getInstance();
2278 if (rm!=null) {
2279 if (Prefs.noPointLabels)

Callers 1

handleRoiMouseDownMethod · 0.80

Calls 15

deleteRoiMethod · 0.95
getPreviousRoiMethod · 0.95
setImageMethod · 0.95
getToolIdMethod · 0.95
getRectToolTypeMethod · 0.95
getRoundRectArcSizeMethod · 0.95
getOvalToolTypeMethod · 0.95
getToolNameMethod · 0.95
getMeasurementsMethod · 0.95
runMethod · 0.95
getOverlayMethod · 0.95
drawLabelsMethod · 0.95

Tested by

no test coverage detected