Java Code Examples for java.awt.Graphics.copyArea()

The following are Jave code examples for showing how to use copyArea() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GIFKR   File: ShiftFilter.java   View Source Code Vote up 6 votes
@Override
public BufferedImage apply(BufferedImage img) {
	
	int size = (int) (squareSize * Math.min(img.getWidth(), img.getHeight()));
	int shift = (int) (distance * Math.min(img.getWidth(), img.getHeight()));
	
	for(int i = 0; i < passes; i++) {
		
		int x = (int) (rand.nextDouble() * (img.getWidth()-size));
		int y = (int) (rand.nextDouble() * (img.getHeight()-size));
		
		Graphics g = img.getGraphics();
		g.copyArea(x, y, size, size, (int) ((rand.nextDouble()-.5) * shift), (int) ((rand.nextDouble()-.5) * shift));	
	}
	
	return img;
}
 
Example 2
Project: OpenJSharp   File: MiscTests.java   View Source Code Vote up 6 votes
public void runTest(Object ctx, int numReps) {
    GraphicsTests.Context gctx = (GraphicsTests.Context)ctx;
    int size = gctx.size;
    int x = gctx.initX;
    int y = gctx.initY;
    Graphics g = gctx.graphics;
    g.translate(gctx.orgX, gctx.orgY);
    if (gctx.animate) {
        do {
            g.copyArea(x, y, size, size, dx, dy);
            if ((x -= 3) < 0) x += gctx.maxX;
            if ((y -= 1) < 0) y += gctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            g.copyArea(x, y, size, size, dx, dy);
        } while (--numReps > 0);
    }
    g.translate(-gctx.orgX, -gctx.orgY);
}
 
Example 3
Project: jdk8u-jdk   File: MiscTests.java   View Source Code Vote up 6 votes
public void runTest(Object ctx, int numReps) {
    GraphicsTests.Context gctx = (GraphicsTests.Context)ctx;
    int size = gctx.size;
    int x = gctx.initX;
    int y = gctx.initY;
    Graphics g = gctx.graphics;
    g.translate(gctx.orgX, gctx.orgY);
    if (gctx.animate) {
        do {
            g.copyArea(x, y, size, size, dx, dy);
            if ((x -= 3) < 0) x += gctx.maxX;
            if ((y -= 1) < 0) y += gctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            g.copyArea(x, y, size, size, dx, dy);
        } while (--numReps > 0);
    }
    g.translate(-gctx.orgX, -gctx.orgY);
}
 
Example 4
Project: openjdk-jdk10   File: MiscTests.java   View Source Code Vote up 6 votes
public void runTest(Object ctx, int numReps) {
    GraphicsTests.Context gctx = (GraphicsTests.Context)ctx;
    int size = gctx.size;
    int x = gctx.initX;
    int y = gctx.initY;
    Graphics g = gctx.graphics;
    g.translate(gctx.orgX, gctx.orgY);
    if (gctx.animate) {
        do {
            g.copyArea(x, y, size, size, dx, dy);
            if ((x -= 3) < 0) x += gctx.maxX;
            if ((y -= 1) < 0) y += gctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            g.copyArea(x, y, size, size, dx, dy);
        } while (--numReps > 0);
    }
    g.translate(-gctx.orgX, -gctx.orgY);
}
 
Example 5
Project: lemon-framework   File: VerifyCodeUtils.java   View Source Code Vote up 6 votes
private static void shearX(Graphics g, int w1, int h1, Color color) {  

      int period = random.nextInt(2);  

      boolean borderGap = true;  
      int frames = 1;  
      int phase = random.nextInt(2);  

      for (int i = 0; i < h1; i++) {  
          double d = (double) (period >> 1)  
                  * Math.sin((double) i / (double) period  
                          + (6.2831853071795862D * (double) phase)  
                          / (double) frames);  
          g.copyArea(0, i, w1, 1, (int) d, 0);  
          if (borderGap) {  
              g.setColor(color);  
              g.drawLine((int) d, i, 0, i);  
              g.drawLine((int) d + w1, i, w1, i);  
          }  
      }  

  }
 
Example 6
Project: lemon-framework   File: VerifyCodeUtils.java   View Source Code Vote up 6 votes
private static void shearY(Graphics g, int w1, int h1, Color color) {  

      int period = random.nextInt(40) + 10; // 50;  

      boolean borderGap = true;  
      int frames = 20;  
      int phase = 7;  
      for (int i = 0; i < w1; i++) {  
          double d = (double) (period >> 1)  
                  * Math.sin((double) i / (double) period  
                          + (6.2831853071795862D * (double) phase)  
                          / (double) frames);  
          g.copyArea(i, 0, 1, h1, 0, (int) d);  
          if (borderGap) {  
              g.setColor(color);  
              g.drawLine(i, (int) d, i, 0);  
              g.drawLine(i, (int) d + h1, i, h1);  
          }  

      }  

  }
 
Example 7
Project: school-website   File: VerifyCodeUtils.java   View Source Code Vote up 6 votes
private static void shearX(Graphics g, int w1, int h1, Color color) {

        int period = random.nextInt(2);

        boolean borderGap = true;
        int frames = 1;
        int phase = random.nextInt(2);

        for (int i = 0; i < h1; i++) {
            double d = (double) (period >> 1)
                    * Math.sin((double) i / (double) period
                    + (6.2831853071795862D * (double) phase)
                    / (double) frames);
            g.copyArea(0, i, w1, 1, (int) d, 0);
            if (borderGap) {
                g.setColor(color);
                g.drawLine((int) d, i, 0, i);
                g.drawLine((int) d + w1, i, w1, i);
            }
        }

    }
 
Example 8
Project: school-website   File: VerifyCodeUtils.java   View Source Code Vote up 6 votes
private static void shearY(Graphics g, int w1, int h1, Color color) {

        int period = random.nextInt(40) + 10; // 50;

        boolean borderGap = true;
        int frames = 20;
        int phase = 7;
        for (int i = 0; i < w1; i++) {
            double d = (double) (period >> 1)
                    * Math.sin((double) i / (double) period
                    + (6.2831853071795862D * (double) phase)
                    / (double) frames);
            g.copyArea(i, 0, 1, h1, 0, (int) d);
            if (borderGap) {
                g.setColor(color);
                g.drawLine(i, (int) d, i, 0);
                g.drawLine(i, (int) d + h1, i, h1);
            }

        }

    }
 
Example 9
Project: incubator-netbeans   File: TransformableCanvasComponent.java   View Source Code Vote up 4 votes
private void shift(Graphics g, int idx, int idy, int width, int height) {
    Rectangle areaToRepaint = new Rectangle();

    if (idx == 0) {
        // Vertical shift
        if (idy > 0) {
            // --- Shift down --------------------------------------
            g.copyArea(0, 0, width, height - idy, 0, idy);
            areaToRepaint.setBounds(0, 0, width, idy);
        } else {
            // --- Shift up ----------------------------------------
            g.copyArea(0, -idy, width, height + idy, 0, idy);
            areaToRepaint.setBounds(0, height + idy, width, -idy);
        }
    } else if (idy == 0) {
        // Horizontal shift
        if (idx > 0) {
            // --- Shift right -------------------------------------
            g.copyArea(0, 0, width - idx, height, idx, 0);
            areaToRepaint.setBounds(0, 0, idx, height);
        } else {
            // --- Shift left --------------------------------------
            g.copyArea(-idx, 0, width + idx, height, idx, 0);
            areaToRepaint.setBounds(width + idx, 0, -idx, height);
        }
    } else {
        // Diagonal shift
        if (idx > 0) {
            // Shift right
            if (idy > 0) {
                // --- Shift right down ------------------------
                g.copyArea(0, 0, width - idx, height - idy, idx, idy);
                areaToRepaint.setBounds(0, 0, width, idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(0, idy, idx, height - idy);
            } else {
                // --- Shift right up --------------------------
                g.copyArea(0, -idy, width - idx, height + idy, idx, idy);
                areaToRepaint.setBounds(0, height + idy, width, -idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(0, 0, idx, height + idy);
            }
        } else {
            // Shift left
            if (idy > 0) {
                // --- Shift left down -------------------------
                g.copyArea(-idx, 0, width + idx, height - idy, idx, idy);
                areaToRepaint.setBounds(0, 0, width, idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(width + idx, idy, -idx, height - idy);
            } else {
                // --- Shift left up ---------------------------
                g.copyArea(-idx, -idy, width + idx, height + idy, idx, idy);
                areaToRepaint.setBounds(0, height + idy, width, -idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(width + idx, 0, -idx, height + idy);
            }
        }
    }

    paintContents(g, areaToRepaint);
}
 
Example 10
Project: etomica   File: DisplayBoxCanvas1D.java   View Source Code Vote up 4 votes
/**
    * doPaint is the method that handles the drawing of the box to the screen.
    * Several variables and conditions affect how the image is drawn.  First,
    * the Unit.Length.Sim class variable <code>TO_PIXELS</code> performs the conversion between simulation
    * length units (Angstroms) and pixels.  The default value is 10 pixels/Angstrom
    * reflecting the default size of the box (300 pixels by 300 pixels) and the
    * default box size (30 by 30 A).  
    * The field <code>scale</code> is a multiplicative factor that directly
    * scales up or down the size of the image; this value is adjusted automatically
    * whenever shells of periodic images are drawn, to permit the central image and all 
    * of the specified periodic images to fit in the drawing of the box.  
    *
    * @param g The graphic object to which the image of the box is drawn
    */
    public void doPaint(Graphics g) {
        if(!isVisible() || displayBox.getBox() == null) {return;}
        int w = getSize().width;
        int h = getSize().height;
            
        g.setColor(getBackground());
        g.fillRect(0,0,w,h);
        displayBox.computeImageParameters2(w, h);

        //Draw other features if indicated
//        if(drawBoundary>DRAW_BOUNDARY_NONE) {displayBox.getBox().boundary().draw(g, displayBox.getOrigin(), displayBox.getScale());}
//        if(displayBox.getDrawBoundary()) {displayBox.getBox().boundary().draw(g, displayBox.getOrigin(), displayBox.getScale());}

        //do drawing of all drawing objects that have been added to the display
        for(Iterator iter=displayBox.getDrawables().iterator(); iter.hasNext(); ) {
            Drawable obj = (Drawable)iter.next();
            obj.draw(g, displayBox.getOrigin(), displayBox.getToPixels());
        }
           
        int [] origin = displayBox.getOrigin();
        atomOrigin[0] =origin[0] + (int)(0.5*displayBox.getToPixels()*displayBox.getBox().getBoundary().getBoxSize().getX(0));
        atomOrigin[1] =origin[1];
        
        //Draw all atoms
        if(displayBox.getColorScheme() instanceof ColorSchemeCollective) {
            ((ColorSchemeCollective)displayBox.getColorScheme()).colorAllAtoms();
        }
        IAtomList leafList = displayBox.getBox().getLeafList();
        int nLeaf = leafList.getAtomCount();
        AtomFilter atomFilter = displayBox.getAtomFilter();
        if (atomFilter instanceof AtomFilterCollective) {
            ((AtomFilterCollective)atomFilter).resetFilter();
        }
        for (int iLeaf=0; iLeaf<nLeaf; iLeaf++) {
            IAtom a = leafList.getAtom(iLeaf);
            if(atomFilter != null && atomFilter.test(a)) continue;
            drawAtom(g, atomOrigin, a);
        }
            
        //Draw overflow images if so indicated
        //This needs some work to make more general
///        for(Atom a=displayBox.getBox().firstAtom(); a!=null; a=a.nextAtom()) {
///            if(computeShiftOrigin(a, boundary)) {
///                drawAtom(g, shiftOrigin, a);
///            }
///        }

        //Draw periodic images if indicated ONLY for an etomica Boundary
        if(displayBox.getBox().getBoundary() instanceof Boundary) {
	        if(displayBox.getImageShells() > 0) {
	            double[][] origins = ((Boundary)displayBox.getBox().getBoundary()).imageOrigins(displayBox.getImageShells());  //more efficient to save rather than recompute each time
	            for(int i=0; i<origins.length; i++) {
	                g.copyArea(displayBox.getOrigin()[0],displayBox.getOrigin()[1],displayBox.getDrawSize()[0],displayBox.getDrawSize()[1],(int)(displayBox.getToPixels()*origins[i][0]),(int)(displayBox.getToPixels()*origins[i][1]));
	            }
	        }
        }
        //Draw bar showing scale if indicated
        if(writeScale) {
            g.setColor(Color.lightGray);
            g.fillRect(0,getSize().height-annotationHeight,getSize().width,annotationHeight);
            g.setColor(Color.black);
            g.setFont(font);
            g.drawString("Scale: "+Integer.toString((int)(100*displayBox.getScale()))+"%", 0, getSize().height-3);
        }
    }