1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 2000 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 29 /* 30 * Copyright (C) 1996 Active Software, Inc. 31 * All rights reserved. 32 * 33 * @(#) VJCanvas.java 1.5 - last change made 12/10/96 34 */ 35 36 package sunsoft.jws.visual.rt.awt; 37 38 import sunsoft.jws.visual.rt.base.Global; 39 import java.awt.*; 40 41 public class VJCanvas extends Canvas { 42 43 public static final int PAINT_EVENT = 2567; 44 public static final int UPDATE_EVENT = 2568; 45 46 /** 47 * This Canvas doesn't keep growing like the regular Canvas does. 48 **/ 49 50 int minWidth = 100, minHeight = 100; 51 setMinWidth(int minWidth)52 public void setMinWidth(int minWidth) { 53 this.minWidth = minWidth; 54 } 55 setMinHeight(int minHeight)56 public void setMinHeight(int minHeight) { 57 this.minHeight = minHeight; 58 } 59 getMinWidth()60 public int getMinWidth() { 61 return minWidth; 62 } 63 getMinHeight()64 public int getMinHeight() { 65 return minHeight; 66 } 67 minimumSize()68 public Dimension minimumSize() { 69 return new Dimension(minWidth, minHeight); 70 } 71 preferredSize()72 public Dimension preferredSize() { 73 return minimumSize(); 74 } 75 update(Graphics g)76 public void update(Graphics g) { 77 if (Global.isWindows()) 78 g = getGraphics(); 79 postEvent(new Event(this, UPDATE_EVENT, g)); 80 paint(g); 81 } 82 paint(Graphics g)83 public void paint(Graphics g) { 84 if (Global.isWindows()) 85 g = getGraphics(); 86 super.paint(g); 87 postEvent(new Event(this, PAINT_EVENT, g)); 88 } 89 90 // 91 // Workaround for Windows95 AWT bug: If 92 // you call request focus while 93 // the mouse is pressed, you get spurious 94 // mouse down events. Not only 95 // that, but the spurious events have 96 // clickCount set to 2, so you end 97 // up with spurious double clicks. 98 // On Windows95 the component 99 // automatically gets the focus when 100 // you press the mouse inside it. 101 // Therefore, it isn't necessary to 102 // call requestFocus at all if running 103 // on Windows and the mouse is down (and this avoids the bug). 104 // postEvent(Event e)105 public boolean postEvent(Event e) { 106 // Fix the click count 107 VJPanel.fixClickCount(e); 108 109 if (e.id == Event.MOUSE_DOWN) 110 VJPanel.isMouseDown = true; 111 else if (e.id == Event.MOUSE_UP) 112 VJPanel.isMouseDown = false; 113 return super.postEvent(e); 114 } 115 requestFocus()116 public void requestFocus() { 117 if (!Global.isWindows() || !VJPanel.isMouseDown) 118 super.requestFocus(); 119 } 120 } 121