Here you can find the source of getLetterIcon(Character letter, Color fgColor, Color bgColor, int size)
Parameter | Description |
---|---|
letter | The letter of this icon |
fgColor | The Color to be used in the letter |
bgColor | The Color to be used in the background circle |
size | The width/height of the icon to be generated |
public static ImageIcon getLetterIcon(Character letter, Color fgColor, Color bgColor, int size)
//package com.java2s; /*/* w w w . j a v a2 s .co m*/ * Copyright (c) 2004-2013 Universidade do Porto - Faculdade de Engenharia * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS) * All rights reserved. * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal * * This file is part of Neptus, Command and Control Framework. * * Commercial Licence Usage * Licencees holding valid commercial Neptus licences may use this file * in accordance with the commercial licence agreement provided with the * Software or, alternatively, in accordance with the terms contained in a * written agreement between you and Universidade do Porto. For licensing * terms, conditions, and further information contact lsts@fe.up.pt. * * European Union Public Licence - EUPL v.1.1 Usage * Alternatively, this file may be used under the terms of the EUPL, * Version 1.1 only (the "Licence"), appearing in the file LICENCE.md * included in the packaging of this file. You may not use this work * except in compliance with the Licence. Unless required by applicable * law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF * ANY KIND, either express or implied. See the Licence for the specific * language governing permissions and limitations at * https://www.lsts.pt/neptus/licence. * * For more information please see <http://lsts.fe.up.pt/neptus>. * * Author: * 24/Fev/2005 */ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; public class Main { /** * This method generates an icon which is a circle (background) with a letter showing on top * * @param letter The letter of this icon * @param fgColor The Color to be used in the letter * @param bgColor The Color to be used in the background circle * @param size The width/height of the icon to be generated * @return The generated icon */ public static ImageIcon getLetterIcon(Character letter, Color fgColor, Color bgColor, int size) { BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) bi.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(bgColor); g2d.fill(new Ellipse2D.Double(1, 1, size - 2, size - 2)); g2d.setStroke(new BasicStroke(0.5f)); g2d.setColor(Color.black); g2d.draw(new Ellipse2D.Double(1, 1, size - 2, size - 2)); g2d.setFont(new Font("Helvetica", Font.BOLD, size)); int width = g2d.getFontMetrics().charWidth(letter); g2d.setColor(new Color(0, 0, 0, 64)); g2d.drawString(new String(new char[] { letter }), (size - width) / 2 + 3, size - 1); g2d.drawString(new String(new char[] { letter }), (size - width) / 2 + 2, size - 2); g2d.setColor(fgColor); g2d.drawString(new String(new char[] { letter }), (size - width) / 2 + 1, size - 3); return new ImageIcon(bi); } }