samer@0
|
1 /*
|
samer@0
|
2 * Tools.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.swing;
|
samer@0
|
13 import samer.core.util.*;
|
samer@0
|
14 import samer.core.*;
|
samer@0
|
15 import java.awt.*;
|
samer@0
|
16 import javax.swing.*;
|
samer@0
|
17 import javax.swing.border.*;
|
samer@0
|
18
|
samer@0
|
19 /**
|
samer@0
|
20 * This is a panel with an optional bevel border,
|
samer@0
|
21 * and a name label. It can also draw bevels
|
samer@0
|
22 * round its children
|
samer@0
|
23 */
|
samer@0
|
24
|
samer@0
|
25
|
samer@0
|
26 public class VPanel extends JPanel implements Viewer
|
samer@0
|
27 {
|
samer@0
|
28 private Border cborder=null; // border for children
|
samer@0
|
29 private Viewer vwr;
|
samer@0
|
30
|
samer@0
|
31 /** Constructors can specify bevel type, inset and name */
|
samer@0
|
32
|
samer@0
|
33 public VPanel() { this(null); }
|
samer@0
|
34 public VPanel(Viewer vwr)
|
samer@0
|
35 {
|
samer@0
|
36 super( new FlowLayout(FlowLayout.LEFT,0,0));
|
samer@0
|
37
|
samer@0
|
38 this.vwr=vwr;
|
samer@0
|
39 // border=Border.createDefault(); // ??
|
samer@0
|
40 // addMouseListener(MouseRetarget.listener);
|
samer@0
|
41 setBorder(BorderFactory.createEmptyBorder(3,6,3,6));
|
samer@0
|
42 }
|
samer@0
|
43
|
samer@0
|
44 public void setName(String txt) {
|
samer@0
|
45 if (txt==null) {
|
samer@0
|
46 setBorder(BorderFactory.createEmptyBorder(2,6,2,6));
|
samer@0
|
47 return;
|
samer@0
|
48 }
|
samer@0
|
49 super.setName(txt);
|
samer@0
|
50 setBorder(
|
samer@0
|
51 BorderFactory.createCompoundBorder(
|
samer@0
|
52 BorderFactory.createTitledBorder(
|
samer@0
|
53 BorderFactory.createEmptyBorder(4,0,8,0), // space top and bottom
|
samer@0
|
54 txt, TitledBorder.LEADING, TitledBorder.BELOW_TOP),
|
samer@0
|
55 BorderFactory.createEmptyBorder(0,12,0,0) // small indent
|
samer@0
|
56 )
|
samer@0
|
57 );
|
samer@0
|
58 }
|
samer@0
|
59
|
samer@0
|
60 public void setChildBorder( Border b) { cborder=b; }
|
samer@0
|
61
|
samer@0
|
62 /*
|
samer@0
|
63 public void paintChildren(Graphics g) {
|
samer@0
|
64 if (cborder!=null) {
|
samer@0
|
65 Component [] c=getComponents();
|
samer@0
|
66 Insets insets=cborder.getBorderInsets(this);
|
samer@0
|
67 int dx=insets.left, dy=insets.top;
|
samer@0
|
68 int dw=insets.left+insets.right;
|
samer@0
|
69 int dh=insets.top+insets.bottom;
|
samer@0
|
70
|
samer@0
|
71 for (int i=c.length-1; i>=0; i--) {
|
samer@0
|
72 Rectangle r=c[i].getBounds();
|
samer@0
|
73 if (!r.isEmpty()) {
|
samer@0
|
74 cborder.paintBorder(
|
samer@0
|
75 c[i], g,
|
samer@0
|
76 r.x-dx, r.y-dy,
|
samer@0
|
77 r.width+dw, r.height+dh
|
samer@0
|
78 );
|
samer@0
|
79 }
|
samer@0
|
80 }
|
samer@0
|
81 }
|
samer@0
|
82 super.paintChildren();
|
samer@0
|
83 }
|
samer@0
|
84 */
|
samer@0
|
85
|
samer@0
|
86
|
samer@0
|
87 public Component getComponent() { return this; }
|
samer@0
|
88 public void attach() {}
|
samer@0
|
89 public void detach() {}
|
samer@0
|
90
|
samer@0
|
91 // private JPopupMenu thing=null;
|
samer@0
|
92 private DynamicPopupHandler thing=null;
|
samer@0
|
93
|
samer@0
|
94 public void exposeCommands(Agent agent) {
|
samer@0
|
95 thing=MenuBuilder.showCommands(agent,this,thing);
|
samer@0
|
96 }
|
samer@0
|
97
|
samer@0
|
98 public void addNotify() { if (vwr!=null) vwr.attach(); super.addNotify(); }
|
samer@0
|
99 public void removeNotify() { if (vwr!=null) vwr.detach(); super.removeNotify(); }
|
samer@0
|
100
|
samer@0
|
101 // public void add(Viewer v) { super.add(v.getComponent()); }
|
samer@0
|
102 public void add(Viewable v) { add(v.getViewer().getComponent()); }
|
samer@0
|
103 }
|