comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.core.util.swing;
11 import samer.core.util.*;
12 import samer.core.*;
13 import javax.swing.*;
14 import java.awt.*;
15 import java.awt.event.*;
16
17 /** Basically a Viewer implemented as a bare JComponent.
18 Calls attach() on addNotify(). Also calls realized();
19 Calls sized() when sized.
20 Keeps track of its own width and height.
21 Can display popup menu.
22 */
23
24 public class VCanvas extends JComponent implements Viewer
25 {
26 public int width, height;
27
28 public VCanvas()
29 {
30 addMouseListener(MouseRetarget.listener);
31 addComponentListener( new ComponentAdapter() {
32 public void componentResized(ComponentEvent e) {
33 width=getWidth(); height=getHeight();
34 sized();
35 }
36 } );
37
38 setBackground(Shell.getColor("background",null));
39 setForeground(Shell.getColor("foreground",null));
40 setOpaque(true);
41 }
42
43 protected void realized() {}
44 protected void sized() {}
45
46 protected void paintComponent(Graphics g) { clear(g); }
47 public void clear(Graphics g) {
48 g.setColor(getBackground());
49 g.fillRect(0,0,width,height);
50 }
51
52 public void removeNotify() { detach(); super.removeNotify(); }
53 public void addNotify() {
54 super.addNotify();
55 width=getWidth(); height=getHeight();
56 attach(); realized(); // ??
57 }
58
59 public Dimension getMinimumSize() { return new Dimension(0,0); }
60
61 // ....... MenuAnchor bits .......................
62
63 public Component getComponent() { return this; }
64 public void attach() {}
65 public void detach() {}
66
67 // private javax.swing.JPopupMenu menu=null;
68 private DynamicPopupHandler popup=null;
69
70 public void exposeCommands(Agent agent) {
71 popup=MenuBuilder.showCommands(agent,this,popup);
72 // menu=MenuBuilder.showCommands(agent,getComponent(),menu);
73 }
74 }
75
76