samer@0: /* samer@0: * VPanel.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.heavy; samer@0: import samer.core.util.*; samer@0: import samer.core.*; samer@0: import java.awt.*; samer@0: samer@0: public class VPanel extends JPanel implements Viewer samer@0: { samer@0: private Menu menu=null; samer@0: private Viewer vwr; samer@0: private Label label; samer@0: samer@0: public VPanel() { this(null); } samer@0: public VPanel(Viewer vwr) { super(); this.vwr=vwr; } samer@0: samer@0: public void setName(String txt) { samer@0: if (txt==null) { if (label!=null) remove(label); return; } samer@0: super.setName(txt); samer@0: if (label!=null) label.setText(txt); samer@0: else { samer@0: label=new Label(txt); samer@0: label.addMouseListener(MouseRetarget.listener); samer@0: add(label,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: public void exposeCommands(Agent agent) { samer@0: menu=MenuBuilder.showCommands(agent,this,menu); samer@0: } samer@0: samer@0: public void addNotify() { super.addNotify(); if (vwr!=null) vwr.attach(); } samer@0: public void removeNotify() { if (vwr!=null) vwr.detach(); super.removeNotify(); } samer@0: samer@0: // public void add(Component c) { super.add(c); } samer@0: public void add(Viewer v) { add(v.getComponent()); } samer@0: public void add(Viewable v) { add(v.getViewer()); } samer@0: } samer@0: