001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
018: */
019:
020: package edu.umd.cs.findbugs.gui2;
021:
022: import java.awt.BorderLayout;
023: import java.awt.Color;
024: import java.awt.Dimension;
025: import java.awt.Frame;
026: import java.awt.Graphics;
027: import java.awt.Image;
028: import java.awt.MediaTracker;
029: import java.awt.Toolkit;
030:
031: import javax.swing.BorderFactory;
032: import javax.swing.ImageIcon;
033: import javax.swing.JLabel;
034: import javax.swing.JPanel;
035: import javax.swing.JWindow;
036:
037: /*
038: * If long load times are getting you down, uncomment this class's instantiation in driver
039: * and add an extra 4 seconds to your load time, but get to watch a dancing bug for the remainder!
040: */
041:
042: public class SplashFrame extends JWindow {
043:
044: private static Thread animator;
045:
046: public SplashFrame() {
047: super (new Frame());
048:
049: Toolkit toolkit = Toolkit.getDefaultToolkit();
050: Image image = toolkit.getImage(MainFrame.class
051: .getResource("SplashBug1.png"));
052: Image image2 = toolkit.getImage(MainFrame.class
053: .getResource("SplashBug2B.png"));
054: Image imageReverse = toolkit.getImage(MainFrame.class
055: .getResource("SplashBug1reverse.png"));
056: Image image2Reverse = toolkit.getImage(MainFrame.class
057: .getResource("SplashBug2reverseB.png"));
058:
059: // JPanel temp = new JPanel(new BorderLayout());
060: // temp.setBorder(BorderFactory.createLineBorder(Color.black, 2));
061: // setContentPane(temp);
062: JLabel l = new JLabel(new ImageIcon(MainFrame.class
063: .getResource("umdFindbugs.png")));
064: JPanel p = new JPanel();
065: Viewer viewer = new Viewer(image, image2, imageReverse,
066: image2Reverse);
067: final JPanel bottom = viewer;
068: p.setBackground(Color.white);
069: bottom.setBackground(Color.white);
070:
071: p.add(l);
072: getContentPane().add(p, BorderLayout.CENTER);
073: getContentPane().add(bottom, BorderLayout.SOUTH);
074: pack();
075: Dimension screenSize = Toolkit.getDefaultToolkit()
076: .getScreenSize();
077: Dimension labelSize = l.getPreferredSize();
078: p.setPreferredSize(new Dimension(labelSize.width + 50,
079: labelSize.height + 20));
080: p.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
081: bottom
082: .setBorder(BorderFactory.createLineBorder(Color.BLACK,
083: 1));
084: Dimension panelSize = p.getPreferredSize();
085: bottom.setPreferredSize(new Dimension(panelSize.width, image
086: .getHeight(null) + 2));
087:
088: setLocation(screenSize.width / 2 - (panelSize.width / 2),
089: screenSize.height / 2 - (panelSize.height / 2));
090:
091: // g.drawImage(new ImageIcon("bugSplash3.png"),0 ,0 ,null);
092:
093: pack();
094: screenSize = null;
095: labelSize = null;
096: viewer.animate();
097:
098: }
099:
100: public static void main(String[] args) {
101: (new SplashFrame()).setVisible(true);
102:
103: }
104:
105: @Override
106: public void setVisible(boolean b) {
107: super .setVisible(b);
108: if (!b)
109: animator.interrupt();
110: }
111:
112: private static class Viewer extends JPanel {
113: private Image image;
114: private Image image2;
115: private Image imageR;
116: private Image image2R;
117: boolean swap = false;
118: boolean reverse = true;
119: int callCount = 0;
120: int xpos = 0;
121: int ypos = 0;
122: int farRight;
123:
124: public Viewer(Image i1, Image i2, Image i1r, Image i2r) {
125: image = i1;
126: image2 = i2;
127: imageR = i1r;
128: image2R = i2r;
129: MediaTracker mediaTracker = new MediaTracker(this );
130: mediaTracker.addImage(image, 0);
131: mediaTracker.addImage(image2, 1);
132: mediaTracker.addImage(imageR, 2);
133: mediaTracker.addImage(image2R, 3);
134: try {
135: mediaTracker.waitForID(0);
136: mediaTracker.waitForID(1);
137: mediaTracker.waitForID(2);
138: mediaTracker.waitForID(3);
139: } catch (InterruptedException ie) {
140: System.err.println(ie);
141: System.exit(1);
142: }
143: animator = new Thread(new Runnable() {
144: public void run() {
145: int deltaX = 1;
146:
147: while (true) {
148: if (Thread.currentThread().isInterrupted())
149: return;
150:
151: callCount++;
152: if (callCount == 10) {
153: swap = !swap;
154: callCount = 0;
155: }
156:
157: xpos += deltaX;
158: try {
159: Thread.sleep(20);
160: } catch (InterruptedException e) {
161: break;
162: }
163:
164: if (xpos > Viewer.this .getSize().width
165: - image.getWidth(null)) {
166: deltaX = -1;
167: reverse = !reverse;
168: }
169: if (xpos < 0) {
170: deltaX = 1;
171: reverse = !reverse;
172: }
173:
174: Viewer.this .repaint();
175: }
176: }
177: });
178: }
179:
180: public void animate() {
181: animator.start();
182: }
183:
184: @Override
185: public void setPreferredSize(Dimension d) {
186: super .setPreferredSize(d);
187: }
188:
189: private Image imageToDraw() {
190: if (swap) {
191: if (!reverse)
192: return image;
193: return imageR;
194: } else {
195: if (!reverse)
196: return image2;
197: return image2R;
198: }
199: }
200:
201: @Override
202: public void paint(Graphics graphics) {
203: super .paint(graphics);
204:
205: // graphics.clearRect(0,0,500,500);
206: graphics.drawImage(imageToDraw(), xpos, ypos, null);
207: }
208: }
209: }
|