001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui;
034:
035: import java.awt.BorderLayout;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038: import java.util.ArrayList;
039:
040: import javax.swing.ImageIcon;
041: import javax.swing.JFrame;
042: import javax.swing.JLabel;
043: import javax.swing.JPanel;
044: import javax.swing.Timer;
045:
046: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
047:
048: /**
049: * Implements an animated clock.
050: */
051:
052: public class AnimatedClockPanel extends JPanel {
053: private ArrayList queue = new ArrayList();
054: private Timer timer = new Timer(250, new ActionListener() {
055: public void actionPerformed(ActionEvent e) {
056: nextImage();
057: }
058: });
059: private JLabel label = new JLabel();
060: private BorderLayout borderLayout1 = new BorderLayout();
061:
062: public AnimatedClockPanel() {
063: add("ClockN.gif");
064: add("ClockNE.gif");
065: add("ClockE.gif");
066: add("ClockSE.gif");
067: add("ClockS.gif");
068: add("ClockSW.gif");
069: add("ClockW.gif");
070: add("ClockNW.gif");
071:
072: try {
073: jbInit();
074: } catch (Exception e) {
075: e.printStackTrace();
076: }
077: }
078:
079: private void add(String icon) {
080: queue.add(IconLoader.icon(icon));
081: }
082:
083: public void start() {
084: timer.start();
085: }
086:
087: public void stop() {
088: timer.stop();
089: }
090:
091: private void nextImage() {
092: ImageIcon icon = (ImageIcon) queue.remove(0);
093: queue.add(icon);
094: label.setIcon(icon);
095: }
096:
097: private void jbInit() throws Exception {
098: this .setLayout(borderLayout1);
099: this .add(label, BorderLayout.CENTER);
100: label.setIcon(IconLoader.icon("ClockN.gif"));
101: }
102:
103: public static void main(String[] args) {
104: AnimatedClockPanel p = new AnimatedClockPanel();
105: p.start();
106:
107: JFrame f = new JFrame();
108: f.getContentPane().add(p);
109: f.setVisible(true);
110: }
111: }
|