01: /*
02: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.instance.common.ui;
07:
08: //
09:
10: import java.awt.*;
11:
12: //
13:
14: public class Box extends Panel {
15: //
16: protected String title = null;
17:
18: //
19: //
20: //
21: public Box(String title, Component component) {
22: this .title = title;
23:
24: setLayout(new BorderLayout());
25: add(component, BorderLayout.CENTER);
26: }
27:
28: //
29: //
30: //
31: private static final int DEFAULT_INSETS_TOP = 2;
32: private static final int DEFAULT_INSETS_LEFT = 2;
33: private static final int DEFAULT_INSETS_BOTTOM = 2;
34: private static final int DEFAULT_INSETS_RIGHT = 2;
35:
36: public Insets getInsets() {
37: Graphics g = getGraphics();
38: FontMetrics fm = g.getFontMetrics();
39:
40: g.dispose();
41: return new Insets(fm.getHeight(), DEFAULT_INSETS_LEFT,
42: DEFAULT_INSETS_BOTTOM, DEFAULT_INSETS_RIGHT);
43: }
44:
45: public void paint(Graphics g) {
46: Dimension sz = getSize();
47: FontMetrics fm = g.getFontMetrics();
48: int h = fm.getHeight();
49:
50: g.setColor(SystemColor.controlShadow);
51: g.drawRect(0, h / 2, sz.width - 2, sz.height - 2 - h / 2);
52: g.setColor(SystemColor.controlLtHighlight);
53: g.drawRect(1, h / 2 + 1, sz.width - 2, sz.height - 2 - h / 2);
54:
55: g.setColor(getBackground());
56: g.clearRect(sz.width / 2 - fm.stringWidth(title) / 2 - 2, 0, fm
57: .stringWidth(title) + 4, fm.getHeight());
58:
59: g.setColor(getForeground());
60: g.drawString(title, sz.width / 2 - fm.stringWidth(title) / 2,
61: fm.getAscent());
62: }
63:
64: //
65: //
66: //
67: }
|