annotate src/samer/core_/util/swing/VCanvas.java @ 8:5e3cbbf173aa tip

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