2 * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
4 * This file is part of LEA.
6 * LEA is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option) any
11 * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with LEA. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.BasicStroke;
22 import java.awt.Color;
23 import java.awt.Graphics;
24 import java.awt.Graphics2D;
25 import java.awt.RenderingHints;
26 import java.awt.image.BufferedImage;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import javax.imageio.ImageIO;
30 import javax.swing.JPanel;
36 abstract class InfoPanel extends JPanel {
38 private static final long serialVersionUID = 8311083210432152308L;
40 private String text = "";
41 private BufferedImage image = null;
42 private BufferedImage[] noImageImages = null;
43 private int imageWidth, imageHeight;
44 private int animationTime = 0;
46 private AnimationThread animationThread = null;
48 private class AnimationThread extends Thread {
50 private boolean shutdown = false;
51 private int counter = 0;
53 public AnimationThread() {
57 public void shutdown() {
64 counter = (++counter % noImageImages.length);
65 image = noImageImages[counter];
68 try { Thread.sleep(animationTime); } catch (InterruptedException e) {}
74 public InfoPanel(String text, String[] noImageImageFileNames, int fps, int imageWidth, int imageHeight) {
76 this.imageWidth = imageWidth;
77 this.imageHeight = imageHeight;
78 if (noImageImageFileNames == null || noImageImageFileNames.length == 0) {
79 this.noImageImages = null;
81 this.noImageImages = new BufferedImage[noImageImageFileNames.length];
82 for (int i = 0; i < noImageImageFileNames.length; ++i) {
83 this.noImageImages[i] = loadImage(noImageImageFileNames[i]);
86 this.animationTime = (fps == 0 ? 0 : 1000/fps);
90 protected static BufferedImage loadImage(String fileName) {
91 BufferedImage image = null;
94 FaceInfoPanel.class.getClassLoader().getResourceAsStream(fileName);
96 image = ImageIO.read(in);
99 } catch (IOException ex) {
100 ex.printStackTrace();
108 public void paint(Graphics g) {
109 Graphics2D g2d = (Graphics2D) g;
111 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
112 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
113 RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
115 g2d.setBackground(new Color(0, 0, 0));
116 g2d.clearRect(0, 0, this.getWidth(), this.getHeight());
118 g2d.setColor(new Color(39, 53, 66));
119 g2d.fillRoundRect(2, 2, this.getWidth()-4, this.getHeight()-4, 10, 10);
121 g2d.setColor(new Color(118, 149, 174));
122 g2d.drawString(text, 10, 20);
124 g2d.setColor(new Color(81, 111, 137));
125 g2d.drawRect(this.getWidth()-11-imageWidth, 9, imageWidth+1, imageHeight+1);
129 this.getWidth() - 10 - imageWidth, 10,
130 imageWidth, imageHeight, null);
133 g2d.setStroke(new BasicStroke(2.0f));
134 g2d.setColor(new Color(81, 111, 137));
135 g2d.drawRoundRect(2, 2, this.getWidth()-4, this.getHeight()-4, 10, 10);
138 protected synchronized void setImage(BufferedImage image) {
140 if (this.noImageImages != null && this.noImageImages.length > 0) {
141 image = this.noImageImages[0];
142 if (this.animationTime > 0) {
143 if (this.animationThread == null)
144 this.animationThread = new AnimationThread();
148 if (this.animationThread != null) {
149 this.animationThread.shutdown();
150 this.animationThread = null;