View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // RoundCircle.java
20  // Since: 2007/11/26
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.server.app;
26  
27  import java.awt.Graphics2D;
28  import java.awt.RenderingHints;
29  import java.awt.geom.Ellipse2D;
30  import java.awt.image.BufferedImage;
31  import java.io.IOException;
32  
33  import javax.servlet.ServletException;
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  
37  import org.utgenome.gwt.utgb.server.RequestHandlerBase;
38  import org.utgenome.gwt.utgb.server.util.graphic.GraphicUtil;
39  import org.xerial.util.log.Logger;
40  
41  /**
42   * Generates a circle image
43   * 
44   * @author leo
45   * 
46   */
47  public class RoundCircle extends RequestHandlerBase {
48  	private static final long serialVersionUID = 19443895944286732L;
49  
50  	private static Logger _logger = Logger.getLogger(RoundCircle.class);
51  
52  	public String color = "666666";
53  	public int size = 4; // radius of the circle
54  	public float opacity = 1f;
55  
56  	@Override
57  	public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
58  		if (size <= 0)
59  			size = 1;
60  		int canvasSize = size * 2;
61  
62  		BufferedImage circleImage = GraphicUtil.getTransparentBufferedImage(canvasSize, canvasSize);
63  		Graphics2D g = GraphicUtil.getGraphics(circleImage);
64  
65  		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
66  		Ellipse2D circle = new Ellipse2D.Double(0, 0, canvasSize, canvasSize);
67  
68  		g.setColor(GraphicUtil.parseColor(color, (int) (255 * opacity)));
69  		g.fill(circle);
70  
71  		GraphicUtil.writeImage(circleImage, "png", response);
72  	}
73  }