Mercurial > hg > jslab
diff src/samer/core_/util/swing/VCanvas.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/core_/util/swing/VCanvas.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,76 @@ +/* + * 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 javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +/** Basically a Viewer implemented as a bare JComponent. + Calls attach() on addNotify(). Also calls realized(); + Calls sized() when sized. + Keeps track of its own width and height. + Can display popup menu. + */ + +public class VCanvas extends JComponent implements Viewer +{ + public int width, height; + + public VCanvas() + { + addMouseListener(MouseRetarget.listener); + addComponentListener( new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + width=getWidth(); height=getHeight(); + sized(); + } + } ); + + setBackground(Shell.getColor("background",null)); + setForeground(Shell.getColor("foreground",null)); + setOpaque(true); + } + + protected void realized() {} + protected void sized() {} + + protected void paintComponent(Graphics g) { clear(g); } + public void clear(Graphics g) { + g.setColor(getBackground()); + g.fillRect(0,0,width,height); + } + + public void removeNotify() { detach(); super.removeNotify(); } + public void addNotify() { + super.addNotify(); + width=getWidth(); height=getHeight(); + attach(); realized(); // ?? + } + + public Dimension getMinimumSize() { return new Dimension(0,0); } + + // ....... MenuAnchor bits ....................... + + public Component getComponent() { return this; } + public void attach() {} + public void detach() {} + + // private javax.swing.JPopupMenu menu=null; + private DynamicPopupHandler popup=null; + + public void exposeCommands(Agent agent) { + popup=MenuBuilder.showCommands(agent,this,popup); + // menu=MenuBuilder.showCommands(agent,getComponent(),menu); + } +} + +