comparison src/samer/core_/util/swing/VPanel.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Tools.java
3 *
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
5 * All rights reserved.
6 *
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
8 * without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 */
11
12 package samer.core.util.swing;
13 import samer.core.util.*;
14 import samer.core.*;
15 import java.awt.*;
16 import javax.swing.*;
17 import javax.swing.border.*;
18
19 /**
20 * This is a panel with an optional bevel border,
21 * and a name label. It can also draw bevels
22 * round its children
23 */
24
25
26 public class VPanel extends JPanel implements Viewer
27 {
28 private Border cborder=null; // border for children
29 private Viewer vwr;
30
31 /** Constructors can specify bevel type, inset and name */
32
33 public VPanel() { this(null); }
34 public VPanel(Viewer vwr)
35 {
36 super( new FlowLayout(FlowLayout.LEFT,0,0));
37
38 this.vwr=vwr;
39 // border=Border.createDefault(); // ??
40 // addMouseListener(MouseRetarget.listener);
41 setBorder(BorderFactory.createEmptyBorder(3,6,3,6));
42 }
43
44 public void setName(String txt) {
45 if (txt==null) {
46 setBorder(BorderFactory.createEmptyBorder(2,6,2,6));
47 return;
48 }
49 super.setName(txt);
50 setBorder(
51 BorderFactory.createCompoundBorder(
52 BorderFactory.createTitledBorder(
53 BorderFactory.createEmptyBorder(4,0,8,0), // space top and bottom
54 txt, TitledBorder.LEADING, TitledBorder.BELOW_TOP),
55 BorderFactory.createEmptyBorder(0,12,0,0) // small indent
56 )
57 );
58 }
59
60 public void setChildBorder( Border b) { cborder=b; }
61
62 /*
63 public void paintChildren(Graphics g) {
64 if (cborder!=null) {
65 Component [] c=getComponents();
66 Insets insets=cborder.getBorderInsets(this);
67 int dx=insets.left, dy=insets.top;
68 int dw=insets.left+insets.right;
69 int dh=insets.top+insets.bottom;
70
71 for (int i=c.length-1; i>=0; i--) {
72 Rectangle r=c[i].getBounds();
73 if (!r.isEmpty()) {
74 cborder.paintBorder(
75 c[i], g,
76 r.x-dx, r.y-dy,
77 r.width+dw, r.height+dh
78 );
79 }
80 }
81 }
82 super.paintChildren();
83 }
84 */
85
86
87 public Component getComponent() { return this; }
88 public void attach() {}
89 public void detach() {}
90
91 // private JPopupMenu thing=null;
92 private DynamicPopupHandler thing=null;
93
94 public void exposeCommands(Agent agent) {
95 thing=MenuBuilder.showCommands(agent,this,thing);
96 }
97
98 public void addNotify() { if (vwr!=null) vwr.attach(); super.addNotify(); }
99 public void removeNotify() { if (vwr!=null) vwr.detach(); super.removeNotify(); }
100
101 // public void add(Viewer v) { super.add(v.getComponent()); }
102 public void add(Viewable v) { add(v.getViewer().getComponent()); }
103 }