001 /*****************************************************************************
002
003 jBudget.
004 Copyright (C) 2006-2008 Dmitri Petrov
005
006 This program 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 This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
018
019 *****************************************************************************/
020
021 package org.jbudget.util;
022
023 import java.awt.Color;
024 import java.awt.event.ActionEvent;
025 import java.awt.event.ActionListener;
026 import javax.swing.JComponent;
027 import javax.swing.Timer;
028
029 /**
030 * General purpose GUI utilities.
031 * @author petrov
032 */
033 public class GuiUtils
034 {
035 /** Changes background color from c1 to c2 several times. Finally
036 * leaves background in c2
037 */
038 public static void blink(JComponent component, Color c1, Color c2)
039 {
040 final JComponent cmp = component;
041 final Color color1 = c1;
042 final Color color2 = c2;
043 cmp.setBackground(color2);
044 Timer timer = new Timer(300, new ActionListener()
045 {
046
047 int counter = 0;
048
049 public void actionPerformed(ActionEvent e)
050 {
051 if (counter % 2 == 0)
052 {
053 cmp.setBackground(color1);
054 }
055 else
056 {
057 cmp.setBackground(color2);
058 }
059 if (counter++ == 5)
060 {
061 Timer t = (Timer) (e.getSource());
062 t.stop();
063 }
064 }
065 });
066 timer.start();
067 }
068 }