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 javax.swing.*; samer@0: import java.awt.*; samer@0: import java.awt.event.*; samer@0: samer@0: /** Basically a Viewer implemented as a bare JComponent. samer@0: Calls attach() on addNotify(). Also calls realized(); samer@0: Calls sized() when sized. samer@0: Keeps track of its own width and height. samer@0: Can display popup menu. samer@0: */ samer@0: samer@0: public class VCanvas extends JComponent implements Viewer samer@0: { samer@0: public int width, height; samer@0: samer@0: public VCanvas() samer@0: { samer@0: addMouseListener(MouseRetarget.listener); samer@0: addComponentListener( new ComponentAdapter() { samer@0: public void componentResized(ComponentEvent e) { samer@0: width=getWidth(); height=getHeight(); samer@0: sized(); samer@0: } samer@0: } ); samer@0: samer@0: setBackground(Shell.getColor("background",null)); samer@0: setForeground(Shell.getColor("foreground",null)); samer@0: setOpaque(true); samer@0: } samer@0: samer@0: protected void realized() {} samer@0: protected void sized() {} samer@0: samer@0: protected void paintComponent(Graphics g) { clear(g); } samer@0: public void clear(Graphics g) { samer@0: g.setColor(getBackground()); samer@0: g.fillRect(0,0,width,height); samer@0: } samer@0: samer@0: public void removeNotify() { detach(); super.removeNotify(); } samer@0: public void addNotify() { samer@0: super.addNotify(); samer@0: width=getWidth(); height=getHeight(); samer@0: attach(); realized(); // ?? samer@0: } samer@0: samer@0: public Dimension getMinimumSize() { return new Dimension(0,0); } samer@0: samer@0: // ....... MenuAnchor bits ....................... samer@0: samer@0: public Component getComponent() { return this; } samer@0: public void attach() {} samer@0: public void detach() {} samer@0: samer@0: // private javax.swing.JPopupMenu menu=null; samer@0: private DynamicPopupHandler popup=null; samer@0: samer@0: public void exposeCommands(Agent agent) { samer@0: popup=MenuBuilder.showCommands(agent,this,popup); samer@0: // menu=MenuBuilder.showCommands(agent,getComponent(),menu); samer@0: } samer@0: } samer@0: samer@0: