samer@0: /* samer@0: * Tools.java samer@0: * samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.core.util.swing; samer@0: import samer.core.util.*; samer@0: import samer.core.*; samer@0: import java.awt.*; samer@0: import javax.swing.*; samer@0: import javax.swing.border.*; samer@0: samer@0: /** samer@0: * This is a panel with an optional bevel border, samer@0: * and a name label. It can also draw bevels samer@0: * round its children samer@0: */ samer@0: samer@0: samer@0: public class VPanel extends JPanel implements Viewer samer@0: { samer@0: private Border cborder=null; // border for children samer@0: private Viewer vwr; samer@0: samer@0: /** Constructors can specify bevel type, inset and name */ samer@0: samer@0: public VPanel() { this(null); } samer@0: public VPanel(Viewer vwr) samer@0: { samer@0: super( new FlowLayout(FlowLayout.LEFT,0,0)); samer@0: samer@0: this.vwr=vwr; samer@0: // border=Border.createDefault(); // ?? samer@0: // addMouseListener(MouseRetarget.listener); samer@0: setBorder(BorderFactory.createEmptyBorder(3,6,3,6)); samer@0: } samer@0: samer@0: public void setName(String txt) { samer@0: if (txt==null) { samer@0: setBorder(BorderFactory.createEmptyBorder(2,6,2,6)); samer@0: return; samer@0: } samer@0: super.setName(txt); samer@0: setBorder( samer@0: BorderFactory.createCompoundBorder( samer@0: BorderFactory.createTitledBorder( samer@0: BorderFactory.createEmptyBorder(4,0,8,0), // space top and bottom samer@0: txt, TitledBorder.LEADING, TitledBorder.BELOW_TOP), samer@0: BorderFactory.createEmptyBorder(0,12,0,0) // small indent samer@0: ) samer@0: ); samer@0: } samer@0: samer@0: public void setChildBorder( Border b) { cborder=b; } samer@0: samer@0: /* samer@0: public void paintChildren(Graphics g) { samer@0: if (cborder!=null) { samer@0: Component [] c=getComponents(); samer@0: Insets insets=cborder.getBorderInsets(this); samer@0: int dx=insets.left, dy=insets.top; samer@0: int dw=insets.left+insets.right; samer@0: int dh=insets.top+insets.bottom; samer@0: samer@0: for (int i=c.length-1; i>=0; i--) { samer@0: Rectangle r=c[i].getBounds(); samer@0: if (!r.isEmpty()) { samer@0: cborder.paintBorder( samer@0: c[i], g, samer@0: r.x-dx, r.y-dy, samer@0: r.width+dw, r.height+dh samer@0: ); samer@0: } samer@0: } samer@0: } samer@0: super.paintChildren(); samer@0: } samer@0: */ samer@0: samer@0: samer@0: public Component getComponent() { return this; } samer@0: public void attach() {} samer@0: public void detach() {} samer@0: samer@0: // private JPopupMenu thing=null; samer@0: private DynamicPopupHandler thing=null; samer@0: samer@0: public void exposeCommands(Agent agent) { samer@0: thing=MenuBuilder.showCommands(agent,this,thing); samer@0: } samer@0: samer@0: public void addNotify() { if (vwr!=null) vwr.attach(); super.addNotify(); } samer@0: public void removeNotify() { if (vwr!=null) vwr.detach(); super.removeNotify(); } samer@0: samer@0: // public void add(Viewer v) { super.add(v.getComponent()); } samer@0: public void add(Viewable v) { add(v.getViewer().getComponent()); } samer@0: }