001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.component; 020 021import icy.util.GraphicsUtil; 022 023import java.awt.Graphics; 024import java.awt.Graphics2D; 025import java.awt.image.BufferedImage; 026 027import javax.swing.JPanel; 028 029/** 030 * @deprecated Don't use this fancy background panel anymore... 031 */ 032@Deprecated 033public class IcyPanel extends JPanel 034{ 035 private static final long serialVersionUID = -7893535181542546173L; 036 037 /** 038 * background draw cache flag 039 */ 040 protected boolean bgDrawCached; 041 042 // internal 043 private BufferedImage bgImage; 044 045 public IcyPanel() 046 { 047 this(false); 048 } 049 050 public IcyPanel(boolean bgDrawCached) 051 { 052 super(); 053 054 this.bgDrawCached = bgDrawCached; 055 bgImage = null; 056 } 057 058 /** 059 * @return the bgDrawCached 060 */ 061 public boolean isBgDrawCached() 062 { 063 return bgDrawCached; 064 } 065 066 /** 067 * @param bgDrawCached 068 * the bgDrawCached to set 069 */ 070 public void setBgDrawCached(boolean bgDrawCached) 071 { 072 this.bgDrawCached = bgDrawCached; 073 } 074 075 @Override 076 protected void paintComponent(Graphics g) 077 { 078 super.paintComponent(g); 079 080 if (bgDrawCached) 081 { 082 final int w = getWidth(); 083 final int h = getHeight(); 084 085 // cached background 086 if ((bgImage == null) || (bgImage.getWidth() != w) || (bgImage.getHeight() != h)) 087 { 088 bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 089 final Graphics2D cachedGraphics = bgImage.createGraphics(); 090 GraphicsUtil.paintIcyBackGround(this, cachedGraphics); 091 cachedGraphics.dispose(); 092 } 093 094 ((Graphics2D) g).drawImage(bgImage, null, 0, 0); 095 } 096 else 097 GraphicsUtil.paintIcyBackGround(this, g); 098 } 099}