--- /dev/null 2016-01-25 16:27:43.923614000 +0530 +++ new/test/java/awt/LightweightComponent/LightweightEventTest/LightweightEventTest.java 2016-01-25 17:16:04.347559999 +0530 @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * test of mouse move messages to lightweight components + * @bug 4059999 8005918 + * @author Jeff.Dunn + * @run applet/manual=yesno LightweightEventTest.html + */ + + +import java.applet.*; +import java.awt.*; +import java.awt.event.*; +import java.lang.Exception; +import java.io.PrintStream; + + +//Manual tests should run as applet tests if possible because they +// get the pass and fail buttons handled for us, and no worries about +// dealing with the main thread returning before the test is complete. + +public class LightweightEventTest extends Applet + { + static Font desiredFont = null; + + public void init() + { + //here, create the items that will be tested for correct + // behavior + EventBug e = new EventBug(); + Button b = (Button)e.add("Center", new Button("Heavy")); + + EventBug e1 = new EventBug(); + BorderedLabel b1 = (BorderedLabel)e1.add("Center", new BorderedLabel("Lite")); + + e.addListeners(b); + e1.addListeners(b1); + + e1.setLocation(200,0); + e.setVisible(true); + e1.setVisible(true); + + }//End init() + + }// class LightweightEventTest + + +/** + * Lightweight component + */ +class BorderedLabel extends Component { + + boolean superIsButton = false; + String labelString; + + BorderedLabel(String labelString) { + this.labelString = labelString; + + Component thisComponent = this; + superIsButton = (thisComponent instanceof Button); + if(superIsButton) { + ((Button)thisComponent).setLabel(labelString); + } + } + + public Dimension getMinimumSize() { + Dimension minSize = new Dimension(); + + if (superIsButton) { + minSize = super.getMinimumSize(); + } else { + + Graphics g = getGraphics(); + FontMetrics metrics = g.getFontMetrics(); + + minSize.width = metrics.stringWidth(labelString) + 14; + minSize.height = metrics.getMaxAscent() + metrics.getMaxDescent() + 9; + + g.dispose(); g = null; + } + //System.out.println("minimumSize = "+minSize); + return minSize; + } + + public Dimension getPreferredSize() { + Dimension prefSize = new Dimension(); + if (superIsButton) { + prefSize = super.getPreferredSize(); + } else { + prefSize = getMinimumSize(); + } + //System.out.println("preferredSize = "+prefSize); + return prefSize; + } + + public void paint(Graphics g){ + + super.paint(g); + Rectangle bounds = getBounds(); + if (superIsButton) { + return; + } + Dimension size = getSize(); + Color oldColor = g.getColor(); + + // draw border + g.setColor(getBackground()); + g.fill3DRect(0,0, size.width, size.height, false); + g.fill3DRect(3,3, size.width-6, size.height-6, true); + + // draw text + FontMetrics metrics = g.getFontMetrics(); + int centerX = size.width/2; + int centerY = size.height/2; + int textX = centerX - (metrics.stringWidth(labelString)/2); + int textY = centerY + ((metrics.getMaxAscent()+metrics.getMaxDescent())/2); + g.setColor(getForeground()); + g.drawString(labelString, textX, textY); + + + g.setColor(oldColor); + } +} // class BorderedLabel + +class EventBug extends Container { + Frame w; + int frameEnters = 0; + int frameExits = 0; + int buttonEnters = 0; + int buttonExits = 0; + + public EventBug() { + super(); + this.w = new Frame(); + w.setLayout(new BorderLayout()); + this.setLayout(new BorderLayout()); + w.add("Center", this); + w.pack(); + w.show(); + } + + public Dimension getPreferredSize() { + return new Dimension(100,100); + } + + public Insets getInsets() + { + return new Insets(20,20,20,20); + } + + // Forward to the Window + public void setLocation(int x, int y) { w.setLocation(x,y); } + public void setVisible(boolean b) { w.setVisible(b); } + + // Add listeners to Frame and button + public void addListeners(Component b) { + b.setName("Button"); + b.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent e) { + SysOut.println("Button Enter"); + buttonEnters++; + } + public void mouseExited(MouseEvent e) { + SysOut.println("Button Exit"); + buttonExits++; + } + public void mouseClicked(MouseEvent e) { + SysOut.println("Button enter = " + + buttonEnters + + " Button Exit = " + + buttonExits + + " Frame enter = " + + frameEnters + + " Frame Exit = " + + frameExits); + } + }); + w.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent e) { + SysOut.println("Frame Enter"); + frameEnters++; + } + public void mouseExited(MouseEvent e) { + SysOut.println("Frame Exit"); + frameExits++; + } + }); + } + +} // class EventBug + + +class TestDialog extends Dialog + { + + TextArea output; + TextField display; + + public TestDialog(Frame frame, String name, String[] message) + { + super(frame, name); + int maxStringLength = 0; + for (int i=0; i