<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2F2D_Graphics%2FImageIcon</id>
		<title>Java Tutorial/2D Graphics/ImageIcon - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2F2D_Graphics%2FImageIcon"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/2D_Graphics/ImageIcon&amp;action=history"/>
		<updated>2026-04-06T12:30:57Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/2D_Graphics/ImageIcon&amp;diff=3510&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/2D_Graphics/ImageIcon&amp;diff=3510&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/2D_Graphics/ImageIcon&amp;diff=3511&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/2D_Graphics/ImageIcon&amp;diff=3511&amp;oldid=prev"/>
				<updated>2010-05-31T15:25:17Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  A button which paints on it one or more scaled arrows in one of the cardinal directions ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
//Revised from greef ui;&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.ruponent;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import javax.swing.Icon;&lt;br /&gt;
import javax.swing.JLabel;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
import javax.swing.JScrollPane;&lt;br /&gt;
import javax.swing.JTable;&lt;br /&gt;
import javax.swing.SwingConstants;&lt;br /&gt;
import javax.swing.table.DefaultTableCellRenderer;&lt;br /&gt;
import javax.swing.table.DefaultTableModel;&lt;br /&gt;
import javax.swing.table.TableColumnModel;&lt;br /&gt;
/**&lt;br /&gt;
 * A button which paints on it one or more scaled arrows in one of the cardinal directions.&lt;br /&gt;
 * @author Adrian BER&lt;br /&gt;
 */&lt;br /&gt;
public class ArrowIcon implements Icon {&lt;br /&gt;
    /** The cardinal direction of the arrow(s). */&lt;br /&gt;
    private int direction;&lt;br /&gt;
    /** The number of arrows. */&lt;br /&gt;
    private int arrowCount;&lt;br /&gt;
    /** The arrow size. */&lt;br /&gt;
    private int arrowSize;&lt;br /&gt;
    public ArrowIcon(int direction, int arrowCount, int arrowSize) {&lt;br /&gt;
        this.direction = direction;&lt;br /&gt;
        this.arrowCount = arrowCount;&lt;br /&gt;
        this.arrowSize = arrowSize;&lt;br /&gt;
    }&lt;br /&gt;
    /** Returns the cardinal direction of the arrow(s).&lt;br /&gt;
     * @see #setDirection(int)&lt;br /&gt;
     */&lt;br /&gt;
    public int getDirection() {&lt;br /&gt;
        return direction;&lt;br /&gt;
    }&lt;br /&gt;
    /** Sets the cardinal direction of the arrow(s).&lt;br /&gt;
     * @param direction the direction of the arrow(s), can be SwingConstants.NORTH,&lt;br /&gt;
     * SwingConstants.SOUTH, SwingConstants.WEST or SwingConstants.EAST&lt;br /&gt;
     * @see #getDirection()&lt;br /&gt;
     */&lt;br /&gt;
    public void setDirection(int direction) {&lt;br /&gt;
        this.direction = direction;&lt;br /&gt;
    }&lt;br /&gt;
    /** Returns the number of arrows. */&lt;br /&gt;
    public int getArrowCount() {&lt;br /&gt;
        return arrowCount;&lt;br /&gt;
    }&lt;br /&gt;
    /** Sets the number of arrows. */&lt;br /&gt;
    public void setArrowCount(int arrowCount) {&lt;br /&gt;
        this.arrowCount = arrowCount;&lt;br /&gt;
    }&lt;br /&gt;
    /** Returns the arrow size. */&lt;br /&gt;
    public int getArrowSize() {&lt;br /&gt;
        return arrowSize;&lt;br /&gt;
    }&lt;br /&gt;
    /** Sets the arrow size. */&lt;br /&gt;
    public void setArrowSize(int arrowSize) {&lt;br /&gt;
        this.arrowSize = arrowSize;&lt;br /&gt;
    }&lt;br /&gt;
    public void paintIcon(Component c, Graphics g, int x, int y) {&lt;br /&gt;
        // paint the arrows&lt;br /&gt;
        int w = getIconWidth();&lt;br /&gt;
        int h = getIconHeight();&lt;br /&gt;
        for (int i = 0; i &amp;lt; arrowCount; i++) {&lt;br /&gt;
            paintArrow(g,&lt;br /&gt;
                    (x + w - arrowSize * (direction == SwingConstants.EAST&lt;br /&gt;
                            || direction == SwingConstants.WEST ? arrowCount : 1)) / 2&lt;br /&gt;
                            + arrowSize * (direction == SwingConstants.EAST&lt;br /&gt;
                            || direction == SwingConstants.WEST ? i : 0),&lt;br /&gt;
                    (y + h - arrowSize * (direction == SwingConstants.EAST&lt;br /&gt;
                            || direction == SwingConstants.WEST ? 1 : arrowCount)) / 2&lt;br /&gt;
                            + arrowSize * (direction == SwingConstants.EAST&lt;br /&gt;
                            || direction == SwingConstants.WEST ? 0 : i)&lt;br /&gt;
                    );&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public int getIconWidth() {&lt;br /&gt;
        return arrowSize * (direction == SwingConstants.EAST&lt;br /&gt;
                || direction == SwingConstants.WEST ? arrowCount : 3);&lt;br /&gt;
    }&lt;br /&gt;
    public int getIconHeight() {&lt;br /&gt;
        return arrowSize * (direction == SwingConstants.NORTH&lt;br /&gt;
                || direction == SwingConstants.SOUTH ? arrowCount : 3);&lt;br /&gt;
    }&lt;br /&gt;
    private void paintArrow(Graphics g, int x, int y) {&lt;br /&gt;
        int mid, i, j;&lt;br /&gt;
        j = 0;&lt;br /&gt;
        arrowSize = Math.max(arrowSize, 2);&lt;br /&gt;
        mid = (arrowSize / 2) - 1;&lt;br /&gt;
        g.translate(x, y);&lt;br /&gt;
        switch (direction) {&lt;br /&gt;
            case SwingConstants.NORTH:&lt;br /&gt;
                for (i = 0; i &amp;lt; arrowSize; i++) {&lt;br /&gt;
                    g.drawLine(mid - i, i, mid + i, i);&lt;br /&gt;
                }&lt;br /&gt;
                break;&lt;br /&gt;
            case SwingConstants.SOUTH:&lt;br /&gt;
                j = 0;&lt;br /&gt;
                for (i = arrowSize - 1; i &amp;gt;= 0; i--) {&lt;br /&gt;
                    g.drawLine(mid - i, j, mid + i, j);&lt;br /&gt;
                    j++;&lt;br /&gt;
                }&lt;br /&gt;
                break;&lt;br /&gt;
            case SwingConstants.WEST:&lt;br /&gt;
                for (i = 0; i &amp;lt; arrowSize; i++) {&lt;br /&gt;
                    g.drawLine(i, mid - i, i, mid + i);&lt;br /&gt;
                }&lt;br /&gt;
                break;&lt;br /&gt;
            case SwingConstants.EAST:&lt;br /&gt;
                j = 0;&lt;br /&gt;
                for (i = arrowSize - 1; i &amp;gt;= 0; i--) {&lt;br /&gt;
                    g.drawLine(j, mid - i, j, mid + i);&lt;br /&gt;
                    j++;&lt;br /&gt;
                }&lt;br /&gt;
                break;&lt;br /&gt;
        }&lt;br /&gt;
        g.translate(-x, -y);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Change JFrame image icon ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.Dimension;&lt;br /&gt;
import java.awt.image.BufferedImage;&lt;br /&gt;
import javax.imageio.ImageIO;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
public class Main extends JFrame {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    Main frame = new Main();&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.setSize(new Dimension(300, 200));&lt;br /&gt;
    BufferedImage image = ImageIO.read(frame.getClass().getResource(&amp;quot;/colors.jpg&amp;quot;));&lt;br /&gt;
    frame.setIconImage(image);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Convert a non-RGB image to an RGB buffered image: ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import java.awt.Image;&lt;br /&gt;
import java.awt.image.BufferedImage;&lt;br /&gt;
import javax.swing.ImageIcon;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    Image image = new ImageIcon(&amp;quot;image.gif&amp;quot;).getImage();&lt;br /&gt;
    BufferedImage bimage = new BufferedImage(image.getWidth(null), image&lt;br /&gt;
        .getHeight(null), BufferedImage.TYPE_INT_RGB);&lt;br /&gt;
    Graphics2D g = bimage.createGraphics();&lt;br /&gt;
    g.drawImage(image, 0, 0, null);&lt;br /&gt;
    g.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Load an Icon from a jar ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import javax.swing.Icon;&lt;br /&gt;
import javax.swing.UIManager;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
  }&lt;br /&gt;
  public static Icon getIconForType(int iconType) {&lt;br /&gt;
    switch (iconType) {&lt;br /&gt;
    case 0:&lt;br /&gt;
      return UIManager.getIcon(&amp;quot;OptionPane.errorIcon&amp;quot;);&lt;br /&gt;
    case 1:&lt;br /&gt;
      return UIManager.getIcon(&amp;quot;OptionPane.informationIcon&amp;quot;);&lt;br /&gt;
    case 2:&lt;br /&gt;
      return UIManager.getIcon(&amp;quot;OptionPane.warningIcon&amp;quot;);&lt;br /&gt;
    case 3:&lt;br /&gt;
      return UIManager.getIcon(&amp;quot;OptionPane.questionIcon&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Load image to ImageIcon and add it to Panel ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import javax.swing.ImageIcon;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JLabel;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class MainClass extends JFrame {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    new MainClass();&lt;br /&gt;
  }&lt;br /&gt;
  public MainClass() {&lt;br /&gt;
    this.setTitle(&amp;quot;Picture Application&amp;quot;);&lt;br /&gt;
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    JPanel panel1 = new JPanel();&lt;br /&gt;
    ImageIcon pic = new ImageIcon(&amp;quot;your.jpg&amp;quot;);&lt;br /&gt;
    panel1.add(new JLabel(pic));&lt;br /&gt;
    this.add(panel1);&lt;br /&gt;
    this.pack();&lt;br /&gt;
    this.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Return a filled oval as an Icon ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 This file is part of the BlueJ program. &lt;br /&gt;
 Copyright (C) 1999-2009  Michael K�lling and John Rosenberg &lt;br /&gt;
 &lt;br /&gt;
 This program is free software; you can redistribute it and/or &lt;br /&gt;
 modify it under the terms of the GNU General Public License &lt;br /&gt;
 as published by the Free Software Foundation; either version 2 &lt;br /&gt;
 of the License, or (at your option) any later version. &lt;br /&gt;
 &lt;br /&gt;
 This program is distributed in the hope that it will be useful, &lt;br /&gt;
 but WITHOUT ANY WARRANTY; without even the implied warranty of &lt;br /&gt;
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the &lt;br /&gt;
 GNU General Public License for more details. &lt;br /&gt;
 &lt;br /&gt;
 You should have received a copy of the GNU General Public License &lt;br /&gt;
 along with this program; if not, write to the Free Software &lt;br /&gt;
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. &lt;br /&gt;
 &lt;br /&gt;
 This file is subject to the Classpath exception as provided in the  &lt;br /&gt;
 LICENSE.txt file that accompanied this code.&lt;br /&gt;
 */&lt;br /&gt;
import javax.swing.*;&lt;br /&gt;
import java.awt.*;&lt;br /&gt;
/**&lt;br /&gt;
 * Return a filled oval as an Icon&lt;br /&gt;
 *&lt;br /&gt;
 * @author  Andrew Patterson&lt;br /&gt;
 * @cvs     $Id: OvalIcon.java 6164 2009-02-19 18:11:32Z polle $&lt;br /&gt;
 */&lt;br /&gt;
public class OvalIcon implements Icon&lt;br /&gt;
{&lt;br /&gt;
    private static OvalIcon redIcon = new OvalIcon(Color.red);&lt;br /&gt;
    private static OvalIcon blankIcon = new OvalIcon(null);&lt;br /&gt;
    public static OvalIcon getRedOvalIcon()&lt;br /&gt;
    {&lt;br /&gt;
        return redIcon;        &lt;br /&gt;
    }&lt;br /&gt;
    public static OvalIcon getBlankOvalIcon()&lt;br /&gt;
    {&lt;br /&gt;
        return blankIcon;&lt;br /&gt;
    }&lt;br /&gt;
    private Color color;&lt;br /&gt;
    public OvalIcon (Color c) {&lt;br /&gt;
       color = c;&lt;br /&gt;
    }&lt;br /&gt;
    public void paintIcon (Component c, Graphics g, int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
  if(color != null) {&lt;br /&gt;
  int width = getIconWidth();&lt;br /&gt;
  int height = getIconHeight();&lt;br /&gt;
   g.setColor (color);&lt;br /&gt;
  g.fillOval (x, y, width, height);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public int getIconWidth() {&lt;br /&gt;
  return 10;&lt;br /&gt;
}&lt;br /&gt;
public int getIconHeight() { &lt;br /&gt;
  return 10;&lt;br /&gt;
}&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  RGB Gray Filter ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2001-2009 JGoodies Karsten Lentzsch. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions are met:&lt;br /&gt;
 *&lt;br /&gt;
 *  o Redistributions of source code must retain the above copyright notice,&lt;br /&gt;
 *    this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *  o Redistributions in binary form must reproduce the above copyright notice,&lt;br /&gt;
 *    this list of conditions and the following disclaimer in the documentation&lt;br /&gt;
 *    and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *  o Neither the name of JGoodies Karsten Lentzsch nor the names of&lt;br /&gt;
 *    its contributors may be used to endorse or promote products derived&lt;br /&gt;
 *    from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS IS&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;&lt;br /&gt;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,&lt;br /&gt;
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE&lt;br /&gt;
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,&lt;br /&gt;
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.awt.Image;&lt;br /&gt;
import java.awt.image.*;&lt;br /&gt;
import javax.swing.GrayFilter;&lt;br /&gt;
import javax.swing.Icon;&lt;br /&gt;
import javax.swing.ImageIcon;&lt;br /&gt;
import javax.swing.JComponent;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * An image filter that turns an icon into a grayscale icon. Used by&lt;br /&gt;
 * the JGoodies Windows and Plastic L&amp;amp;amp;Fs to create a disabled icon.&amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * The high-resolution gray filter can be disabled globally using&lt;br /&gt;
 * {@link Options#setHiResGrayFilterEnabled(boolean)}; it is enabled by default.&lt;br /&gt;
 * The global setting can be overridden per component by setting&lt;br /&gt;
 * the client property key {@link Options#HI_RES_DISABLED_ICON_CLIENT_KEY}&lt;br /&gt;
 * to &amp;lt;code&amp;gt;Boolean.FALSE&amp;lt;/code&amp;gt;.&amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * Thanks to Andrej Golovnin for suggesting a simpler filter formula.&lt;br /&gt;
 *&lt;br /&gt;
 * @author Karsten Lentzsch&lt;br /&gt;
 * @version $Revision: 1.10 $&lt;br /&gt;
 */&lt;br /&gt;
public final class RGBGrayFilter extends RGBImageFilter {&lt;br /&gt;
    /**&lt;br /&gt;
     * Overrides default constructor; prevents instantiation.&lt;br /&gt;
     */&lt;br /&gt;
    private RGBGrayFilter() {&lt;br /&gt;
        canFilterIndexColorModel = true;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns an icon with a disabled appearance. This method is used&lt;br /&gt;
     * to generate a disabled icon when one has not been specified.&lt;br /&gt;
     *&lt;br /&gt;
     * @param component the component that will display the icon, may be null.&lt;br /&gt;
     * @param icon the icon to generate disabled icon from.&lt;br /&gt;
     * @return disabled icon, or null if a suitable icon can not be generated.&lt;br /&gt;
     */&lt;br /&gt;
    public static Icon getDisabledIcon(JComponent component, Icon icon) {&lt;br /&gt;
        if (   (icon == null)&lt;br /&gt;
            || (component == null)&lt;br /&gt;
            || (icon.getIconWidth() == 0)&lt;br /&gt;
            || (icon.getIconHeight() == 0)) {&lt;br /&gt;
            return null;&lt;br /&gt;
        }&lt;br /&gt;
        Image img;&lt;br /&gt;
        if (icon instanceof ImageIcon) {&lt;br /&gt;
            img = ((ImageIcon) icon).getImage();&lt;br /&gt;
        } else {&lt;br /&gt;
            img = new BufferedImage(&lt;br /&gt;
                    icon.getIconWidth(),&lt;br /&gt;
                    icon.getIconHeight(),&lt;br /&gt;
                    BufferedImage.TYPE_INT_ARGB);&lt;br /&gt;
            icon.paintIcon(component, img.getGraphics(), 0, 0);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        ImageProducer producer =&lt;br /&gt;
            new FilteredImageSource(img.getSource(), new RGBGrayFilter());&lt;br /&gt;
        return new ImageIcon(component.createImage(producer));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Converts a single input pixel in the default RGB ColorModel to a single&lt;br /&gt;
     * gray pixel.&lt;br /&gt;
     *&lt;br /&gt;
     * @param x    the horizontal pixel coordinate&lt;br /&gt;
     * @param y    the vertical pixel coordinate&lt;br /&gt;
     * @param rgb  the integer pixel representation in the default RGB color model&lt;br /&gt;
     * @return a gray pixel in the default RGB color model.&lt;br /&gt;
     *&lt;br /&gt;
     * @see ColorModel#getRGBdefault&lt;br /&gt;
     * @see #filterRGBPixels&lt;br /&gt;
     */&lt;br /&gt;
    public int filterRGB(int x, int y, int rgb) {&lt;br /&gt;
        // Find the average of red, green, and blue.&lt;br /&gt;
        float avg = (((rgb &amp;gt;&amp;gt; 16) &amp;amp; 0xff) / 255f +&lt;br /&gt;
                     ((rgb &amp;gt;&amp;gt;  8) &amp;amp; 0xff) / 255f +&lt;br /&gt;
                      (rgb        &amp;amp; 0xff) / 255f) / 3;&lt;br /&gt;
        // Pull out the alpha channel.&lt;br /&gt;
        float alpha = (((rgb &amp;gt;&amp;gt; 24) &amp;amp; 0xff) / 255f);&lt;br /&gt;
        // Calculate the average.&lt;br /&gt;
        // Sun&amp;quot;s formula: Math.min(1.0f, (1f - avg) / (100.0f / 35.0f) + avg);&lt;br /&gt;
        // The following formula uses less operations and hence is faster.&lt;br /&gt;
        avg = Math.min(1.0f, 0.35f + 0.65f * avg);&lt;br /&gt;
        // Convert back into RGB.&lt;br /&gt;
       return (int) (alpha * 255f) &amp;lt;&amp;lt; 24 |&lt;br /&gt;
              (int) (avg   * 255f) &amp;lt;&amp;lt; 16 |&lt;br /&gt;
              (int) (avg   * 255f) &amp;lt;&amp;lt; 8  |&lt;br /&gt;
              (int) (avg   * 255f);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>