view src/samer/core_/util/swing/VPanel.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	Tools.java
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY;
 *	without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.core.util.swing;
import  samer.core.util.*;
import  samer.core.*;
import  java.awt.*;
import  javax.swing.*;
import  javax.swing.border.*;

/**
 *		This is a panel with an optional bevel border,
 *		and a name label. It can also draw bevels
 *		round its children
 */


public class VPanel extends JPanel implements Viewer
{
	private	Border			cborder=null; // border for children
	private 	Viewer			vwr;

	/** Constructors can specify bevel type, inset and name */

	public VPanel() { this(null); }
	public VPanel(Viewer vwr)
	{
		super( new FlowLayout(FlowLayout.LEFT,0,0));

		this.vwr=vwr;
		// border=Border.createDefault(); // ??
		// addMouseListener(MouseRetarget.listener);
		setBorder(BorderFactory.createEmptyBorder(3,6,3,6));
	}

	public void setName(String txt) {
		if (txt==null) {
			setBorder(BorderFactory.createEmptyBorder(2,6,2,6));
			return;
		}
		super.setName(txt);
		setBorder(
			BorderFactory.createCompoundBorder(
				BorderFactory.createTitledBorder(
					BorderFactory.createEmptyBorder(4,0,8,0),  // space top and bottom
					txt, TitledBorder.LEADING, TitledBorder.BELOW_TOP),
				BorderFactory.createEmptyBorder(0,12,0,0) // small indent
			)
		);
	}

	public void setChildBorder( Border b) { cborder=b; }

	/*
	public void paintChildren(Graphics g) {
		if (cborder!=null) {
			Component []	c=getComponents();
			Insets	insets=cborder.getBorderInsets(this);
			int		dx=insets.left, dy=insets.top;
			int		dw=insets.left+insets.right;
			int		dh=insets.top+insets.bottom;

			for (int i=c.length-1; i>=0; i--) {
				Rectangle r=c[i].getBounds();
				if (!r.isEmpty()) {
					cborder.paintBorder(
						c[i], g,
						r.x-dx, r.y-dy,
						r.width+dw, r.height+dh
					);
				}
			}
		}
		super.paintChildren();
	}
	*/


	public Component getComponent() { return this; }
	public void	attach() {}
	public void	detach() {}

	// private 	JPopupMenu		thing=null;
	private	DynamicPopupHandler thing=null;
	
	public void	exposeCommands(Agent agent) {
		thing=MenuBuilder.showCommands(agent,this,thing);
	}

	public void addNotify() { if (vwr!=null) vwr.attach(); super.addNotify(); }
	public void removeNotify() { if (vwr!=null) vwr.detach(); super.removeNotify(); }

//	public void add(Viewer v) { super.add(v.getComponent()); }
	public void add(Viewable v) { add(v.getViewer().getComponent()); }
}