Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package ui.panel; | |
21 | ||
22 | import java.awt.Color; | |
23 | import java.awt.Dimension; | |
24 | import java.awt.Graphics; | |
25 | import java.awt.Rectangle; | |
26 | import java.util.Vector; | |
27 | ||
28 | import javax.swing.JPanel; | |
29 | ||
30 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
31 | public class MessagePanel extends JPanel { | |
32 | ||
33 | 0 | private int messageId = 0; |
34 | ||
35 | 0 | private int xGap = 10; |
36 | ||
37 | 0 | private int yGap = 20; |
38 | ||
39 | 0 | private int lineSpace = 20; |
40 | ||
41 | 0 | private int maxMessageLength = 0; |
42 | ||
43 | 0 | private Vector<Message> message = new Vector<Message>(); |
44 | ||
45 | 0 | public MessagePanel() { |
46 | ||
47 | 0 | } |
48 | ||
49 | public static void drawLevelLabel(String text, Rectangle levelBounds, | |
50 | Graphics graphic) { | |
51 | 0 | graphic.setColor(Color.WHITE); |
52 | 0 | graphic.drawString(text, (int) (levelBounds.x + 10), |
53 | 0 | (int) (levelBounds.y + 20)); |
54 | 0 | } |
55 | ||
56 | @Override | |
57 | public void paintComponent(Graphics graphics) { | |
58 | 0 | super.paintComponent(graphics); |
59 | 0 | Rectangle bounds = this.getBounds(); |
60 | 0 | for (int i = 0; i < message.size(); i++) { |
61 | 0 | Message m = message.get(i); |
62 | 0 | if (maxMessageLength < m.text.length()) |
63 | 0 | maxMessageLength = m.text.length(); |
64 | 0 | graphics.setColor(m.color); |
65 | 0 | graphics.drawString(i + " " + m.text, bounds.x + xGap, bounds.y //$NON-NLS-1$ |
66 | 0 | + yGap + i * (lineSpace)); |
67 | } | |
68 | 0 | } |
69 | ||
70 | @Override | |
71 | public Dimension getPreferredSize() { | |
72 | 0 | return new Dimension(this.getBounds().x + maxMessageLength * 10, this |
73 | 0 | .getBounds().y |
74 | 0 | + lineSpace * message.size()); |
75 | } | |
76 | ||
77 | public void addMessage(String text, Color color) { | |
78 | 0 | Message m = new Message(messageId, text, color); |
79 | 0 | this.message.add(messageId, m); |
80 | 0 | messageId++; |
81 | 0 | updateUI(); |
82 | 0 | } |
83 | ||
84 | public class Message { | |
85 | int id = 0; | |
86 | ||
87 | String text; | |
88 | ||
89 | Color color; | |
90 | ||
91 | public Message(int id, String text, Color color) { | |
92 | this.id = id; | |
93 | this.text = text; | |
94 | this.color = color; | |
95 | } | |
96 | } | |
97 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |