samer@0
|
1 /*
|
samer@0
|
2 * JPanel.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.core.util.heavy;
|
samer@0
|
13 import samer.core.*;
|
samer@0
|
14 import samer.core.util.*;
|
samer@0
|
15 import java.awt.*;
|
samer@0
|
16 import java.awt.event.*;
|
samer@0
|
17
|
samer@0
|
18 /**
|
samer@0
|
19 * This is a panel with an optional bevel border,
|
samer@0
|
20 * and a name label. It can also draw bevels
|
samer@0
|
21 * round its children
|
samer@0
|
22 */
|
samer@0
|
23
|
samer@0
|
24
|
samer@0
|
25 public class JPanel extends Panel
|
samer@0
|
26 {
|
samer@0
|
27 private Border.Interface cborder=null;
|
samer@0
|
28 private Border.Interface border=null;
|
samer@0
|
29
|
samer@0
|
30 /** Constructors can specify bevel type, inset and name */
|
samer@0
|
31
|
samer@0
|
32 public JPanel() { this(Border.createDefault()); }
|
samer@0
|
33 public JPanel(Border.Interface border)
|
samer@0
|
34 {
|
samer@0
|
35 setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
|
samer@0
|
36 addMouseListener(MouseRetarget.listener);
|
samer@0
|
37 this.border = border;
|
samer@0
|
38 }
|
samer@0
|
39
|
samer@0
|
40 public Insets getInsets() { return border.getBorderInsets(this); }
|
samer@0
|
41
|
samer@0
|
42 public void setBorder( Border.Interface b) { border=b; }
|
samer@0
|
43 public void setChildBorder( Border.Interface b) { cborder=b; }
|
samer@0
|
44
|
samer@0
|
45 public void paint(Graphics g)
|
samer@0
|
46 {
|
samer@0
|
47 super.paint(g);
|
samer@0
|
48
|
samer@0
|
49 if (border!=null) {
|
samer@0
|
50 Dimension d=getSize();
|
samer@0
|
51 border.paintBorder(this,g,0,0,d.width,d.height);
|
samer@0
|
52 }
|
samer@0
|
53
|
samer@0
|
54 if (cborder!=null) {
|
samer@0
|
55 Component [] c=getComponents();
|
samer@0
|
56 Insets insets=cborder.getBorderInsets(this);
|
samer@0
|
57 int dx=insets.left, dy=insets.top;
|
samer@0
|
58 int dw=insets.left+insets.right;
|
samer@0
|
59 int dh=insets.top+insets.bottom;
|
samer@0
|
60
|
samer@0
|
61 for (int i=c.length-1; i>=0; i--) {
|
samer@0
|
62 Rectangle r=c[i].getBounds();
|
samer@0
|
63 if (!r.isEmpty()) {
|
samer@0
|
64 cborder.paintBorder(
|
samer@0
|
65 c[i], g,
|
samer@0
|
66 r.x-dx, r.y-dy,
|
samer@0
|
67 r.width+dw, r.height+dh
|
samer@0
|
68 );
|
samer@0
|
69 }
|
samer@0
|
70 }
|
samer@0
|
71 }
|
samer@0
|
72 }
|
samer@0
|
73 }
|
samer@0
|
74
|