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

Method paste

ij/src/main/java/ij/ImagePlus.java:3051–3104  ·  view source on GitHub ↗

Inserts the contents of the internal clipboard into this image. If there is a selection the same size as the image on the clipboard, the image is inserted into that selection, otherwise the selection is inserted into the center of the image.

()

Source from the content-addressed store, hash-verified

3049 is a selection the same size as the image on the clipboard, the image is inserted
3050 into that selection, otherwise the selection is inserted into the center of the image.*/
3051 public void paste() {
3052 if (clipboard==null)
3053 return;
3054 int cType = clipboard.getType();
3055 int iType = getType();
3056 int w = clipboard.getWidth();
3057 int h = clipboard.getHeight();
3058 Roi cRoi = clipboard.getRoi();
3059 Rectangle r = null;
3060 Rectangle cr = null;
3061 Roi roi = getRoi();
3062 if (roi!=null)
3063 r = roi.getBounds();
3064 if (cRoi!=null)
3065 cr = cRoi.getBounds();
3066 if (cr==null)
3067 cr = new Rectangle(0, 0, w, h);
3068 if (r==null || (cr.width!=r.width || cr.height!=r.height)) {
3069 // Create a new roi centered on visible part of image, or centered on image if clipboard is >= image
3070 ImageCanvas ic = win!=null?ic = win.getCanvas():null;
3071 Rectangle srcRect = ic!=null?ic.getSrcRect():new Rectangle(0,0,width,height);
3072 int xCenter = w>=width ? width/2 : srcRect.x + srcRect.width/2;
3073 int yCenter = h>=height ? height/2 : srcRect.y + srcRect.height/2;
3074 if (cRoi!=null && cRoi.getType()!=Roi.RECTANGLE) {
3075 cRoi.setImage(this);
3076 cRoi.setLocation(xCenter-w/2, yCenter-h/2);
3077 setRoi(cRoi);
3078 } else
3079 setRoi(xCenter-w/2, yCenter-h/2, w, h);
3080 roi = getRoi();
3081 }
3082 if (IJ.isMacro()) {
3083 //non-interactive paste
3084 int pasteMode = Roi.getCurrentPasteMode();
3085 boolean nonRect = roi.getType()!=Roi.RECTANGLE;
3086 ImageProcessor ip = getProcessor();
3087 if (nonRect) ip.snapshot();
3088 r = roi.getBounds();
3089 int xoffset = cr.x<0?-cr.x:0;
3090 int yoffset = cr.y<0?-cr.y:0;
3091 ip.copyBits(clipboard.getProcessor(), r.x+xoffset, r.y+yoffset, pasteMode);
3092 if (nonRect) {
3093 ImageProcessor mask = roi.getMask();
3094 ip.setMask(mask);
3095 ip.setRoi(roi.getBounds());
3096 ip.reset(ip.getMask());
3097 }
3098 updateAndDraw();
3099 } else if (roi!=null) {
3100 roi.startPaste(clipboard);
3101 Undo.setup(Undo.PASTE, this);
3102 }
3103 changes = true;
3104 }
3105
3106 /** Inserts the contents of the internal clipboard at the
3107 specified location, without updating the display. */

Callers 2

doImageMethod · 0.95
pasteMethod · 0.95

Calls 15

getTypeMethod · 0.95
getRoiMethod · 0.95
getBoundsMethod · 0.95
getSrcRectMethod · 0.95
getTypeMethod · 0.95
setImageMethod · 0.95
setLocationMethod · 0.95
setRoiMethod · 0.95
isMacroMethod · 0.95
getCurrentPasteModeMethod · 0.95
getProcessorMethod · 0.95
snapshotMethod · 0.95

Tested by

no test coverage detected