Source code: jpl2/common/gui/GroupPanel.java
1 /***********************************************************************
2 * JavaPsionLink 2.0, a java implementation of the psion link protocol
3 * Copyright (C) 2002, 2003 John S Montgomery (john.montgomery@lineone.net)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ************************************************************************/
19 package jpl2.common.gui;
20
21 import java.awt.*;
22
23 /** A panel that draws a line around its edge, to show groupings
24 * of components.
25 **/
26
27 public class GroupPanel extends Panel {
28
29 private String label = null;
30
31 public GroupPanel( String label ) {
32 this.label = label;
33 }
34
35 public Insets getInsets() {
36 FontMetrics metrics = getFontMetrics( getFont() );
37 int height = metrics.getHeight();
38
39 return new Insets( height, height, height, height );
40 }
41
42 public void paint( Graphics g ) {
43 FontMetrics metrics = g.getFontMetrics();
44 int width = metrics.stringWidth( label );
45 int height = metrics.getHeight();
46 int ascent = metrics.getMaxAscent();
47
48 Dimension size = getSize();
49
50 Rectangle textArea = new Rectangle( height, 0, width + 10, height );
51 Rectangle mainArea = new Rectangle( height/2, height/2, size.width - height, size.height - height );
52
53
54 g.setColor( getBackground() );
55 g.fillRect( 0, 0, size.width, size.height );
56 //g.setColor( getForeground() );
57 g.draw3DRect( mainArea.x, mainArea.y, mainArea.width, mainArea.height, false );
58 g.draw3DRect( mainArea.x+1, mainArea.y+1, mainArea.width-2, mainArea.height-2, true );
59
60 if ( !label.equals( "" ) ) {
61 g.setColor( getBackground() );
62 g.fillRect( textArea.x, textArea.y, textArea.width, textArea.height );
63 g.setColor( getForeground() );
64 g.drawString( label, textArea.x+5, ascent );
65 }
66 }
67
68 }