Here you can find the source of mergeClip(Graphics g, Shape clip)
Parameter | Description |
---|---|
g | the graphics object to update |
clip | a new clipping region to add to the graphics clip. This may return null if the current clip is null . |
Parameter | Description |
---|---|
NullPointerException | if any parameter is null |
public static Shape mergeClip(Graphics g, Shape clip)
//package com.java2s; /*//from w ww. j a va 2 s.com * Copyright (c) 2009 Albert Kurucz. * * This file, GraphicsUtilities.java is part of JTStand. * * JTStand is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JTStand is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with JTStand. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.geom.Area; import java.awt.Shape; import java.awt.Graphics; public class Main { /** * Sets the clip on a graphics object by merging a supplied clip with the * existing one. The new clip will be an intersection of the old clip and * the supplied clip. The old clip shape will be returned. This is useful * for resetting the old clip after an operation is performed. * * @param g * the graphics object to update * @param clip * a new clipping region to add to the graphics clip. This may * return {@code null} if the current clip is {@code null}. * @return the current clipping region of the supplied graphics object * @throws NullPointerException * if any parameter is {@code null} */ public static Shape mergeClip(Graphics g, Shape clip) { Shape oldClip = g.getClip(); if (oldClip == null) { g.setClip(clip); return null; } Area area = new Area(oldClip); area.intersect(new Area(clip));//new Rectangle(0,0,width,height))); g.setClip(area); return oldClip; } }