Coverage details for ui.panel.MessagePanel

LineHitsSource
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  
330    private int messageId = 0;
34  
350    private int xGap = 10;
36  
370    private int yGap = 20;
38  
390    private int lineSpace = 20;
40  
410    private int maxMessageLength = 0;
42  
430    private Vector<Message> message = new Vector<Message>();
44  
450    public MessagePanel() {
46  
470    }
48  
49     public static void drawLevelLabel(String text, Rectangle levelBounds,
50             Graphics graphic) {
510        graphic.setColor(Color.WHITE);
520        graphic.drawString(text, (int) (levelBounds.x + 10),
530                (int) (levelBounds.y + 20));
540    }
55  
56     @Override
57     public void paintComponent(Graphics graphics) {
580        super.paintComponent(graphics);
590        Rectangle bounds = this.getBounds();
600        for (int i = 0; i < message.size(); i++) {
610            Message m = message.get(i);
620            if (maxMessageLength < m.text.length())
630                maxMessageLength = m.text.length();
640            graphics.setColor(m.color);
650            graphics.drawString(i + " " + m.text, bounds.x + xGap, bounds.y //$NON-NLS-1$
660                    + yGap + i * (lineSpace));
67         }
680    }
69  
70     @Override
71     public Dimension getPreferredSize() {
720        return new Dimension(this.getBounds().x + maxMessageLength * 10, this
730                .getBounds().y
740                + lineSpace * message.size());
75     }
76  
77     public void addMessage(String text, Color color) {
780        Message m = new Message(messageId, text, color);
790        this.message.add(messageId, m);
800        messageId++;
810        updateUI();
820    }
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.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.