--- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/GUIComponent.java 2014-07-31 17:27:47.570615344 +0400 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.Frame; + +public class GUIComponent extends Frame { } --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/GUIMerlinFocus.java 2014-07-31 17:27:48.114615322 +0400 @@ -0,0 +1,811 @@ +/* + * Copyright (c) 2002, 2014, 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. + */ + +import java.awt.*; +import java.awt.event.*; + +/* + * @author Aruna Samji + */ + +public class GUIMerlinFocus extends Frame { + //GUI for KeyboardFocusManagerEvent + Button button; + List list; + + volatile boolean buttonFocusGained, listFocusGained, listFocusLost, + buttonFocusLost, currentkeyboardFocusManager, buttonClicked, + KeyPressed; + + String buttonClickedStr; + + CustomDefaultKeyBoardFocusManager1 cdk; + + //GUI for WindowFocusEvents + Frame frame1; + Dialog dialog1; + + Frame frame2; + Dialog dialog2; + + Frame frame3; + TextField textfield; + Button button1; + TextArea textarea; + Panel rootPanel; + + volatile boolean frame1Activated, frame2Deactivated, + dialog1Activated, dialog2Deactivated, + button1FocusGained, textareaFocusGained, textfieldFocusLost; + + //GUI for OppositeComponentTest + Frame frame4; + Button button2; + List list2; + TextField textfield2; + + Component focusLostComp; + Component focusGainedComp; + + //GUI for FocusTraversalPolicyTest + Frame testFrame; + Button button5; + List list5; + Panel rootPanel1; + Button button6; + Choice choice5; + TextField textfield5; + Checkbox checkbox5; + Component focusLost5; + Component focusGained5; + + Frame testFrame1; + Button button7; + List list6; + Panel rootPanel2; + + FocusTraversalPolicy cp; + + Frame frame5; + Panel firstpanel; + Panel secondpanel; + Button firstbutton; + Button secondbutton; + Choice firstchoice; + Choice secondchoice; + TextField firsttextfield; + TextField secondtextfield; + + Component complost; + Component compgain; + + DefaultKeyboardFocusManager manager; + + //GUI for ProgrammaticTraversalTest + Frame testFrame2; + Button button8; + List list8; + Panel rootPanel8; + Button button9; + Choice choice8; + TextField textfield8; + Checkbox checkbox8; + Component focusLost2; + Component focusGained2; + + KeyboardFocusManager manager2; + + //GUI for RequestFocusOwnerTest + Frame testframe3; + TextField textfield14; + Button button14; + TextArea textarea14; + Checkbox checkbox14; + + //GUI for GlobalFocusOwnerTest + Frame testframe4; + TextField textfield15; + + volatile boolean tempfocus, + keypressed15, keyreleased15, + button1flag, focusgain; + + DefaultKeyboardFocusManager de; + + public void setBooleans() { + + buttonFocusGained = false; + listFocusGained = false; + listFocusLost = false; + buttonFocusLost = false; + currentkeyboardFocusManager = false; + buttonClicked = false; + KeyPressed = false; + + frame1Activated = false; + frame2Deactivated = false; + dialog1Activated = false; + dialog2Deactivated = false; + + button1FocusGained = false; + textareaFocusGained = false; + textfieldFocusLost = false; + + keypressed15 = false; + keyreleased15 = false; + button1flag = false; + focusgain = false ; + } + + public void framesSetLocationAndSize() { + frame1.setSize(500, 100); + frame1.setLocation(100, 100); + frame2.setSize(500, 100); + frame2.setLocation(100, 200); + } + + public void dialogsSetLocationAndSize() { + dialog1.setSize(500, 100); + dialog1.setLocation(100, 300); + dialog2.setSize(500, 100); + dialog2.setLocation(100, 400); + } + + public GUIMerlinFocus() { + setBooleans(); + this.setSize(500, 270); + this.setLayout(new FlowLayout()); + this.setBackground(Color.blue); + cdk = new CustomDefaultKeyBoardFocusManager1(this); + button = new Button("Button"); + + list = new java.awt.List(); + list.add("one"); + list.add("two"); + + button.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent fe) { buttonFocusGained = true; } + public void focusLost(FocusEvent fe) { buttonFocusLost = true; } + }); + + list.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent ke) { KeyPressed = true; } + }); + + list.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent fe) { listFocusGained = true; } + public void focusLost(FocusEvent fe) { listFocusLost = true; } + }); + + button.addActionListener(e -> { + if (e.getSource() == button) { + buttonClickedStr = "AWTEventDispatcher " + + "dispatches the event by itself:" + + "After ButtonClick"; + buttonClicked = true; + } + }); + + this.add(button); + this.add(list); + //End of GUI for KeyboardFocusManagerEvent + + //GUI for WindowFocusEvents + frame1 = new Frame("Frame 1"); + dialog1 = new Dialog(frame1, "Dialog 1"); + + frame2 = new Frame("Frame 2"); + dialog2 = new Dialog(frame2, "Dialog 2"); + + frame1.setBackground(Color.red); + frame1.addWindowListener(new WindowAdapter() { + public void windowActivated(WindowEvent we) { + if (we.getSource() == frame1) frame1Activated = true; + } + }); + + frame2.setBackground(Color.blue); + frame2.addWindowListener(new WindowAdapter() { + public void windowDeactivated(WindowEvent we) { + if (we.getSource() == frame2) frame2Deactivated = true; + } + }); + + dialog1.setBackground(Color.green); + dialog1.addWindowListener(new WindowAdapter() { + public void windowActivated(WindowEvent we) { + if (we.getSource() == dialog1) dialog1Activated = true; + } + }); + + dialog2.setBackground(Color.yellow); + dialog2.addWindowListener(new WindowAdapter() { + public void windowDeactivated(WindowEvent we) { + if (we.getSource() == dialog2) dialog2Deactivated = true; + } + }); + + frame3 = new Frame("WindowFocusEvents"); + frame3.setLayout(new FlowLayout()); + frame3.setBackground(Color.red); + + rootPanel = new Panel(); + rootPanel.setBackground(Color.yellow); + + textfield = new TextField("TextField"); + textfield.addFocusListener(new FocusAdapter() { + public void focusLost(FocusEvent fe) { + textfieldFocusLost = true; + } + }); + + button1 = new Button("Button"); + button1.setEnabled(false); + button1.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent fe) { + button1FocusGained = true; + } + }); + + textarea = new TextArea("TextArea", 3, 10); + textarea.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent fe) { + textareaFocusGained = true; + } + }); + + rootPanel.add(textfield, 0); + rootPanel.add(button1, 1); + rootPanel.add(textarea, 2); + rootPanel.setBounds(20, 20, 350, 200); + + frame3.setBounds(0, 0, 500, 270); + frame3.add(rootPanel); + //End of GUI for WindowFocusEvents + + //GUI for OppositeComponentTest + //Component + frame4 = new Frame("OppositeComponentTest"); + button2 = new Button("Button"); + button2.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusGainedComp = fe.getOppositeComponent(); } + public void focusGained(FocusEvent fe) { focusLostComp = fe.getOppositeComponent(); } + }); + + textfield2 = new TextField("TextField"); + textfield2.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusGainedComp = fe.getOppositeComponent(); } + public void focusGained(FocusEvent fe) { focusLostComp = fe.getOppositeComponent(); } + }); + + list2 = new java.awt.List(2); + list2.add("Item 1"); + list2.add("Item 2"); + list2.add("Item 3"); + list2.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusGainedComp = fe.getOppositeComponent(); } + public void focusGained(FocusEvent fe) { focusLostComp = fe.getOppositeComponent(); } + }); + + frame4.setLayout(new FlowLayout()); + frame4.add(button2); + frame4.add(textfield2); + frame4.add(list2); + frame4.setBackground(Color.green); + frame4.setSize(500, 255); + //End of GUI for OppositeComponentTest + + //GUI for FocusTraversalPolicyTest + testFrame = new Frame("FocusTraversalPolicy"); + testFrame.setLayout(new FlowLayout()); + testFrame.setBackground(Color.blue); + + testFrame1 = new Frame("FocusTraversalPolicy"); + testFrame1.setLayout(new FlowLayout()); + testFrame1.setBackground(Color.blue); + testFrame1.setSize(500, 270); + + rootPanel1 = new Panel(); + rootPanel1.setBackground(Color.yellow); + + rootPanel2 = new Panel(); + rootPanel2.setBackground(Color.yellow); + + button5 = new Button("Button1"); + button5.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + button7 = new Button("Button3"); + button7.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + list5 = new List(2); + list5.add("Item 1"); + list5.add("Item 2"); + list5.add("Item 3"); + list5.add("Item 4"); + list5.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + list6 = new List(2); + list6.add("Item 1"); + list6.add("Item 2"); + list6.add("Item 3"); + list6.add("Item 4"); + list6.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + button6 = new Button("Button2"); + button6.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + choice5 = new Choice(); + choice5.add("item 1"); + choice5.add("item 2"); + choice5.add("item 3"); + choice5.add("item 4"); + choice5.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + textfield5 = new TextField("TextField"); + textfield5.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + checkbox5 = new Checkbox("CheckBox"); + checkbox5.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + focusLost5 = fe.getComponent(); + focusLost5 = fe.getComponent(); + } + + public void focusGained(FocusEvent fe) { + focusGained5 = fe.getComponent(); + focusGained5 = fe.getComponent(); + } + }); + + testFrame.add(button5); + testFrame.add(list5); + testFrame.add(button6); + testFrame.add(choice5); + testFrame.add(checkbox5); + testFrame.add(textfield5, 4); + + rootPanel1.add(button7); + rootPanel1.add(list6); + + cp = new CustomPolicy(button5, list5, button6, choice5, textfield5, checkbox5); + + testFrame.setFocusTraversalPolicy(cp); + + testFrame1.add(rootPanel1); + + testFrame.setSize(500, 270); + //Forward and backward traversal + manager = new DefaultKeyboardFocusManager(); + frame5 = new Frame("FocusTraversalPolicy"); + frame5.setBackground(Color.yellow); + + firstpanel = new Panel(); + firstpanel.setBackground(Color.red); + + secondpanel = new Panel(); + secondpanel.setBackground(Color.green); + + firstbutton = new Button("First"); + firstbutton.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + secondbutton = new Button("Second"); + secondbutton.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + firstchoice = new Choice(); + firstchoice.add("First"); + firstchoice.add("First"); + firstchoice.add("First"); + firstchoice.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + secondchoice = new Choice(); + secondchoice.add("Second"); + secondchoice.add("Second"); + secondchoice.add("Second"); + secondchoice.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + firsttextfield = new TextField("First"); + firsttextfield.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + secondtextfield = new TextField("Second"); + secondtextfield.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + firstpanel.add(firstbutton); + firstpanel.add(firstchoice); + firstpanel.add(firsttextfield); + firstpanel.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + secondpanel.add(secondbutton); + secondpanel.add(secondchoice); + secondpanel.add(secondtextfield); + secondpanel.setFocusCycleRoot(true); + secondpanel.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + + frame5.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + complost = (Component) fe.getSource(); + } + + public void focusGained(FocusEvent fe) { + compgain = null; + compgain = (Component) fe.getSource(); + } + }); + frame5.add(firstpanel, BorderLayout.NORTH); + frame5.add(secondpanel, BorderLayout.SOUTH); + + //End of GUI for FocusTraversalPolicyTest + + //GUI for ProgrammaticTraversalTest + testFrame2 = new Frame("ProgrammaticTraversal"); + testFrame2.setLayout(new FlowLayout()); + + rootPanel8 = new Panel(); + rootPanel8.setLayout(new FlowLayout()); + rootPanel8.setBackground(Color.yellow); + + button8 = new Button("Button1"); + button8.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); } + public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); } + }); + + list8 = new List(2); + list8.add("Item 1"); + list8.add("Item 2"); + list8.add("Item 3"); + list8.add("Item 4"); + list8.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); } + public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); } + }); + + button9 = new Button("Button2"); + button9.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); } + public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); } + }); + + choice8 = new Choice(); + choice8.add("Item 1"); + choice8.add("Item 2"); + choice8.add("Item 3"); + choice8.add("Item 4"); + choice8.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); } + public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); } + }); + + textfield8 = new TextField("Text Field"); + textfield8.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); } + public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); } + }); + + checkbox8 = new Checkbox("Check Box"); + checkbox8.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); } + public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); } + }); + + rootPanel8.add(button8); + rootPanel8.add(list8); + rootPanel8.add(button9); + rootPanel8.add(choice8); + rootPanel8.add(textfield8, 4); + rootPanel8.add(checkbox8); + + testFrame2.add(rootPanel8); + testFrame2.setBackground(Color.red); + testFrame2.pack(); + testFrame2.setSize(500, 270); + + manager2 = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + + //End of GUI for ProgrammaticTraversalTest + + //GUI for RequestFocusOwnerTest + testframe3 = new Frame("RequestFocusOwner"); + testframe3.setLayout(new FlowLayout()); + testframe3.setBackground(Color.yellow); + + textfield14 = new TextField("TextField"); + textarea14 = new TextArea("TextArea", 3, 10); + checkbox14 = new Checkbox("Click Me"); + button14 = new Button("Press me"); + + testframe3.add(button14); + testframe3.add(checkbox14); + testframe3.add(textarea14); + testframe3.add(textfield14); + testframe3.setSize(500, 270); + + //End of GUI for RequestFocusOwnerTest + + //GUI for GlobalFocusOwnerTest + de = new DefaultKeyboardFocusManager(); + testframe4 = new Frame("testFrame"); + testframe4.setLayout(new FlowLayout()); + testframe4.setBackground(Color.green); + + textfield15 = new TextField("TextField"); + textfield15.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent fe) { + tempfocus = fe.isTemporary(); + } + + public void focusGained(FocusEvent fe) { + if (fe.getSource().equals(textfield15)) + focusgain = true; + } + }); + + textfield15.addKeyListener(new KeyListener() { + public void keyPressed(KeyEvent ke) { keypressed15 = true; } + public void keyReleased(KeyEvent ke) { keyreleased15 = true; } + public void keyTyped(KeyEvent ke) { } + }); + + testframe4.add(textfield15); + testframe4.setSize(500, 270); + } + + class CustomPolicy extends FocusTraversalPolicy { + Button button5; + List list5; + Button button6; + Choice choice5; + TextField textfield5; + Checkbox checkbox5; + + public CustomPolicy(Button button5, List list5, Button button6, + Choice choice5, TextField textfield5, Checkbox checkbox5) { + this.button5 = button5; + this.list5 = list5; + this.button6 = button6; + this.choice5 = choice5; + this.textfield5 = textfield5; + this.checkbox5 = checkbox5; + } + + public Component getComponentAfter(Container fr,Component comp) { + if (comp == button5) + return choice5; + else if (comp == list5) + return textfield5; + else if (comp == button6) + return button5; + else if (comp == choice5) + return list5; + else + return button6; + } + + public Component getComponentBefore(Container fr,Component comp) { + if (comp == button5) + return button6; + else if (comp == list5) + return choice5; + else if (comp == button6) + return textfield5; + else if (comp == choice5) + return button5; + else + return list5; + } + + public Component getDefaultComponent(Container fr) { + return choice5; + } + + public Component getFirstComponent(Container fr) { + return choice5; + } + + public Component getLastComponent(Container fr) { + return checkbox5; + } + } + + class CustomDefaultKeyBoardFocusManager1 extends DefaultKeyboardFocusManager { + + public Component comp; + boolean cdkdispatchKeyEvent = false; + boolean cdkprocessKeyEvent = false; + + public CustomDefaultKeyBoardFocusManager1(Component ce) { + this.comp = ce; + } + + public boolean dispatchKeyEvent(KeyEvent e) { + super.dispatchKeyEvent(e); + cdkdispatchKeyEvent=true; + return false; + } + + public boolean dispatchEvent(java.awt.AWTEvent ae) { + super.dispatchEvent(ae); + return false; + } + + public void processKeyEvent(Component comp,KeyEvent ke) { + cdkprocessKeyEvent = true; + super.processKeyEvent(comp,ke); + } + + protected Container getGlobalCurrentFocusCycleRoot() { + return super.getGlobalCurrentFocusCycleRoot(); + } + + protected Component getGlobalFocusOwner() throws SecurityException { + return super.getGlobalFocusOwner(); + } + + protected Window getGlobalFocusedWindow() throws SecurityException { + return super.getGlobalFocusedWindow(); + } + } +} + + --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/GUIXDnDJava.java 2014-07-31 17:27:48.634615302 +0400 @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.datatransfer.*; +import java.awt.dnd.*; + +/* + * @author Girish R (girish.ramachandran@sun.com) + */ + +public class GUIXDnDJava extends Frame implements ClipboardOwner { + + Process process; + volatile boolean framesVisible; + final Clipboard selection = Toolkit.getDefaultToolkit().getSystemSelection(); + + Object dropData = new String(""); + volatile boolean dragDropEnd, dropSuccess; + int dropAction; + DragSource ds; + DragSourceListener dsl; + DragGestureListener dgl; + DropTargetListener dtl; + static String data = "DragDropEnd TEST"; + + + public GUIXDnDJava() throws Exception { + this.setSize(500, 300); + this.setLocation(new Point(6, 200)); + this.setVisible(true); + ds = DragSource.getDefaultDragSource(); + dsl = new DragSourceAdapter() { + public void dragDropEnd(DragSourceDropEvent dsde) { + dragDropEnd = true; + dropSuccess = dsde.getDropSuccess(); + dropAction = dsde.getDropAction(); + + System.out.println("getDropSuccess: " + dsde.getDropSuccess()); + System.out.println("getDropAction: " + dsde.getDropAction()); + } + }; + + dgl = dge -> { + System.out.println("Drag gesture"); + dge.startDrag(null, new StringSelection(data), dsl); + }; + + ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dgl); + dtl = new DropTargetAdapter() { + public void drop(DropTargetDropEvent dtde) { + System.out.println("Drop occured"); + dtde.acceptDrop(DnDConstants.ACTION_COPY); + Transferable t = dtde.getTransferable(); + try { + dropData = t.getTransferData(DataFlavor.stringFlavor); + } catch (Exception e) { + throw new RuntimeException(e); + } + dtde.dropComplete(true); + } + }; + new DropTarget(this, dtl); + + // Only a way to receive notification when the child is ready. + selection.setContents(new StringSelection("Sun"), this); + } + + public void startChild() throws Exception { + String childName = "xdnd-child"; + + Runtime runtime = Runtime.getRuntime(); + Process proc = runtime.exec("/bin/chmod u+x "+childName); + proc.waitFor(); + + //Run the native process and wait for it to get over + process = Runtime.getRuntime().exec("./"+childName); + } + + /** + * This will be notified when the Native window comes up. Test starts here. + */ + public void lostOwnership(Clipboard clipboard, Transferable contents) { + this.framesVisible = true; + } + + public void destroyProcess() { + if (process != null) + process.destroy(); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/GUIXEmbedListeners.java 2014-07-31 17:27:49.158615281 +0400 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import sun.awt.EmbeddedFrame; +import sun.awt.X11.XEmbeddedFrame; + +import java.awt.*; +import java.awt.event.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +/* + * @summary This class creates the SWT shell with AWT Frame embedded in it. + * The embedded AWT Frame has components added to it, listeners are + * added and events are triggered to check if the listeners are + * notified. + * @author Girish R (girish.ramachandran@sun.com) + */ + +public class GUIXEmbedListeners extends Frame { + + EmbeddedFrame frame; + Button button1, button2; + TextField textfield1; + Choice colorchoice; + Scrollbar scrollBar; + Panel panel, panel1; + volatile boolean act_event, adj_list, comp_hidden, comp_moved, + comp_resized, comp_shown, comp_removed, comp_added, focus_gain, + focus_lost, ancestor_moved, ancestor_resized, hierarchy_changed, + item_changed, key_pressed, key_released, key_typed, + mouse_clicked, mouse_entered, mouse_exited, mouse_pressed, + mouse_released, mouse_moved, mouse_dragged, textvalue_changed; + + static String WINDOW_ID_FILE = "window_id"; + String windowID; + Process process; + + public void destroyProcess() { + if (process != null) + process.destroy(); + } + + /** + * Open SWT shell here. + * Add all components and listeners + */ + public GUIXEmbedListeners() throws Exception { + + String osName = System.getProperty("os.name"); + if (!osName.equals("Linux") && !osName.equals("SunOS")) + return; + + //Run the native process and wait for it to get over + process = Runtime.getRuntime().exec("./gtk-embedder"); + + File file = new File(WINDOW_ID_FILE); + int waitCount = 0; + while (!file.exists() && waitCount < 20) { + try { Thread.sleep(100); } catch (Exception e) {} + waitCount++; + } + windowID = new BufferedReader(new FileReader(file)).readLine(); + + frame = new XEmbeddedFrame(Long.decode(windowID).longValue()); + + frame.setLayout(new FlowLayout()); + frame.setSize(500, 270); + + frame.setBackground(Color.red); + + button1 = new Button("TestButton"); + button2 = new Button("TestButton2"); + textfield1 = new TextField("Textfield"); + textfield1.setLocation(50, 50); + textfield1.setSize(80, 80); + + colorchoice = new Choice(); + colorchoice.add("Green"); + colorchoice.add("Blue"); + colorchoice.add("Red"); + colorchoice.add("White"); + + panel = new Panel(); + panel.setSize(100, 100); + panel.setBackground(Color.white); + panel1 = new Panel(); + panel1.setLocation(50, 50); + + panel1.setBackground(Color.blue); + scrollBar = new Scrollbar(); + + button1.addActionListener( e -> act_event = true ); + + scrollBar.addAdjustmentListener( e -> adj_list = true ); + + button1.addComponentListener( new ComponentListener () { + public void componentHidden(ComponentEvent e) { comp_hidden = true; } + public void componentMoved(ComponentEvent e) { comp_moved = true; } + public void componentResized(ComponentEvent e) { comp_resized = true; } + public void componentShown(ComponentEvent e) { comp_shown = true; } + }); + + frame.addContainerListener( new ContainerListener () { + public void componentAdded(ContainerEvent e) { comp_added = true; } + public void componentRemoved(ContainerEvent e) { comp_removed = true; } + }); + + button1.addFocusListener( new FocusListener () { + public void focusGained(FocusEvent e) { focus_gain = true; } + public void focusLost(FocusEvent e) { focus_lost = true; } + }); + + button1.addHierarchyBoundsListener( new HierarchyBoundsListener () { + public void ancestorMoved(HierarchyEvent e) { ancestor_moved = true; } + public void ancestorResized(HierarchyEvent e) { ancestor_resized = true; } + }); + + button1.addHierarchyListener( e -> hierarchy_changed = true ); + + colorchoice.addItemListener( e -> item_changed = true); + + textfield1.addKeyListener( new KeyListener () { + public void keyPressed(KeyEvent e) { key_pressed = true; } + public void keyReleased(KeyEvent e) { key_released = true; } + public void keyTyped(KeyEvent e) { key_typed = true; } + }); + button1.addMouseListener( new MouseListener () { + public void mouseClicked(MouseEvent e) { mouse_clicked = true; } + public void mouseEntered(MouseEvent e) { mouse_entered = true; } + public void mouseExited(MouseEvent e) { mouse_exited = true; } + public void mousePressed(MouseEvent e) { mouse_pressed = true; } + public void mouseReleased(MouseEvent e) { mouse_released = true; } + }); + + button1.addMouseMotionListener( new MouseMotionListener () { + public void mouseDragged(MouseEvent e) { mouse_moved = true; } + public void mouseMoved(MouseEvent e) { mouse_dragged = true; } + }); + + textfield1.addTextListener( e -> textvalue_changed = true); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/GUIXEmbedMemory.java 2014-07-31 17:27:49.678615260 +0400 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import sun.awt.X11.XEmbeddedFrame; + +import java.awt.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +/* + * @summary GUI of XEmbedMemoryTestTask. It creates an SWT shell on which an + * AWT Frame is embedded. Components will be added in the AWT frame + * and checked for any memory leak when they are removed. + * @author Girish R (girish.ramachandran@sun.com), AWT-SQE + */ + +public class GUIXEmbedMemory extends Frame { + + XEmbeddedFrame frame; + String windowID; + Process process; + static String WINDOW_ID_FILE = "window_id"; + + public void destroyProcess() { + if (process != null) + process.destroy(); + } + + public GUIXEmbedMemory() throws Exception { + //Check if the OS is Solaris or Linux and the toolkit is XToolkit + String osName = System.getProperty("os.name"); + if (!osName.equals("Linux") && !osName.equals("SunOS")) { + return; + } + process = Runtime.getRuntime().exec("./gtk-embedder"); + + File file = new File(WINDOW_ID_FILE); + int waitCount = 0; + while (!file.exists() && waitCount < 20) { + try { Thread.sleep(100); } catch (Exception e) {} + waitCount++; + } + + windowID = new BufferedReader(new FileReader(file)).readLine(); + + long window = Long.decode(windowID).longValue(); + frame = new XEmbeddedFrame(window); + + frame.setLayout(new FlowLayout()); + frame.setSize(500, 270); + + frame.setBackground(Color.red); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/GUIZoomFrame.java 2014-07-31 17:27:50.206615239 +0400 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +/* + * @author Aruna Samji + */ + +public class GUIZoomFrame extends Frame { + + Frame frame1, frame2; + Button button; + TextArea textarea; + volatile boolean maxHor, maxVer, maxBoth, normal, iconify; + + public GUIZoomFrame() { + //GUI for ZoomFrameChangeState + frame1 = new Frame("ZoomFrameChangeState"); + frame1.setBackground(Color.red); + frame1.setSize(500,270); + + //GUI for ZoomFrameRepaint + frame2 = new Frame("ZoomFrameRepaint"); + frame2.setBackground(Color.red); + frame2.setSize(500,270); + frame2.setLayout(null); + button = new Button("TestButton"); + textarea = new TextArea("TextArea"); + button.setBounds(20, 100, 80, 60); + textarea.setBounds(120, 100, 80, 60); + + //Listeners for ZoomFrameChangeState + frame1.addWindowStateListener( new WindowAdapter() { + public void windowStateChanged(WindowEvent e) { + if (e.getNewState() == Frame.MAXIMIZED_BOTH) + maxBoth=true; + + if (e.getNewState() == Frame.NORMAL) + normal=true; + + if (e.getNewState() == Frame.ICONIFIED) + iconify=true; + + if (e.getNewState() == Frame.MAXIMIZED_HORIZ) + maxHor=true; + + if (e.getNewState() == Frame.MAXIMIZED_VERT) + maxVer=true; + } + + }); + + //Listeners for ZoomFrameRepaint + frame2.addWindowStateListener( new WindowAdapter() { + public void windowStateChanged(WindowEvent e) { + if (e.getNewState() == Frame.MAXIMIZED_BOTH) + maxBoth = true; + + if (e.getNewState() == Frame.NORMAL) + normal = true; + } + }); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/ImageSelection.java 2014-07-31 17:27:50.726615219 +0400 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.datatransfer.*; +import java.awt.Image; + +/* + * @summary A Transferable which can transfer an image + * @author Girish R (girish.ramachandran@sun.com) + */ + +public class ImageSelection implements Transferable { + + Image image; + + public ImageSelection(Image image) { + this.image = image; + } + + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { + if (flavor.equals(DataFlavor.imageFlavor)) { + return image; + } else { + throw new UnsupportedFlavorException(flavor); + } + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + return flavor.equals(DataFlavor.imageFlavor); + } + + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[] {DataFlavor.imageFlavor}; + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/Task.java 2014-07-31 17:27:51.254615198 +0400 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com) + */ + +public abstract class Task { + + protected T gui; + protected ExtendedRobot robot; + + public Task(Class guiClass, ExtendedRobot robot) throws Exception { + this.robot = robot; + EventQueue.invokeAndWait(() -> { + try { + this.gui = (T) guiClass.getConstructor().newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + + robot.waitForIdle(1000); + } + + public abstract void task() throws Exception; + + public void verifyFailed() {}; + + public void runTask() throws Exception { + task(); + verifyFailed(); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskDialog.java 2014-07-31 17:27:51.778615177 +0400 @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.Label; + +/* + * @test + * @summary Create and dispose the Dialog + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskDialog + */ + +public class TaskDialog extends Task { + + Frame frame; + Dialog dialog; + Panel panel; + Button button; + Canvas canvas; + Checkbox checkbox; + Choice choice; + Container container; + Label label; + List list; + Scrollbar scrollbar; + TextArea textarea; + TextField textfield; + + public static void main (String[] args) throws Exception { + new TaskDialog(GUIComponent.class, new ExtendedRobot()).runTask(); + } + + TaskDialog(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + for (int i = 0; i < 10; i++) { + EventQueue.invokeAndWait(() -> { + frame = new Frame(); + dialog = new Dialog(frame, "DialogTest"); + dialog.setBackground(Color.green); + dialog.setSize(600, 270); + + panel = new Panel(); + + container = new Container(); + container.setLayout(new FlowLayout()); + + button = new Button("Button"); + canvas = new Canvas(); + checkbox = new Checkbox("CheckBox"); + choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice 2"); + choice.add("Choice 3"); + choice.add("Choice 4"); + + label = new Label("Label"); + list = new List(2); + list.add("list 1"); + list.add("list 2"); + list.add("list 3"); + scrollbar = new Scrollbar(); + + textarea = new TextArea("TextArea", 3, 10); + textfield = new TextField("TextField"); + + container.add(button); + container.add(canvas); + container.add(checkbox); + container.add(choice); + container.add(label); + container.add(list); + container.add(scrollbar); + container.add(textarea); + container.add(textfield); + + panel.add(container); + dialog.add(panel); + + dialog.setVisible(true); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(() -> { + dialog.dispose(); + frame.dispose(); + }); + robot.waitForIdle(1000); + } + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskFocusTraversalPolicy.java 2014-07-31 17:27:52.306615156 +0400 @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +/* + * @test + * @summary Set the Focus Traversal Policy and check whether the First, Initial, + * Default & Last Components are returning properly. Try to traverse + * the focus forward and backward within a focus cycle using the traversal + * key explicitly set by the user. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskFocusTraversalPolicy + */ + +public class TaskFocusTraversalPolicy extends Task { + + public static void main (String[] args) throws Exception { + new TaskFocusTraversalPolicy(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskFocusTraversalPolicy(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> gui.testFrame1.setVisible(true)); + robot.waitForIdle(1000); + + if (gui.focusGained5 == null || ! gui.focusGained5.equals(gui.button7)) + throw new RuntimeException("Default Component is not getting focus"); + + + EventQueue.invokeAndWait(gui.testFrame1::dispose); + robot.waitForIdle(1000); + + // 1.checking whether + // i)The InitialComponent is getting focus when the + // new FocusTraversalPolicy is set for a container. + // ii)checking whether the First, Initial, Default, Next and + // Previous Components are returned properly as per the + // traversal policy set for the container. + + //Setting the traversal policy for the frame. + if ( (gui.cp.getInitialComponent(gui.testFrame)) != gui.choice5) + throw new RuntimeException("Initial Component is not returning correctly."); + + if ( (gui.cp.getFirstComponent(gui.testFrame)) != gui.choice5) + throw new RuntimeException("First Component is not returning correctly."); + + if ( (gui.cp.getDefaultComponent(gui.testFrame)) != gui.choice5) + throw new RuntimeException("Default Component is not returning correctly."); + + if ( (gui.cp.getLastComponent(gui.testFrame)) != gui.checkbox5) + throw new RuntimeException("Last Component is not returning correctly."); + + if ( (gui.cp.getComponentAfter(gui.testFrame,gui.button5)) != gui.choice5) + throw new RuntimeException("Next Component is not returned correctly for button."); + + if ( (gui.cp.getComponentAfter(gui.testFrame,gui.list5)) != gui.textfield5) + throw new RuntimeException("Next Component is not returned correctly for list."); + + if ( (gui.cp.getComponentAfter(gui.testFrame,gui.button6)) != gui.button5) + throw new RuntimeException("Next Component is not returned correctly for button2."); + + if ( (gui.cp.getComponentAfter(gui.testFrame,gui.choice5)) != gui.list5) + throw new RuntimeException("Next Component is not returned correctly for choice."); + + if ( (gui.cp.getComponentAfter(gui.testFrame,gui.textfield5)) != gui.button6) + throw new RuntimeException("Next Component is not returned correctly for textfield."); + + if ( (gui.cp.getComponentBefore(gui.testFrame,gui.button5)) != gui.button6) + throw new RuntimeException("Previous Component is not returned correctly for button."); + + if ( (gui.cp.getComponentBefore(gui.testFrame,gui.list5)) != gui.choice5) + throw new RuntimeException("Previous Component is not returned correctly for list."); + + if ( (gui.cp.getComponentBefore(gui.testFrame,gui.button6)) != gui.textfield5) + throw new RuntimeException("Previous Component is not returned correctly for button2."); + + if ( (gui.cp.getComponentBefore(gui.testFrame,gui.choice5)) != gui.button5) + throw new RuntimeException("Previous Component is not returned correctly for choice."); + + if ( (gui.cp.getComponentBefore(gui.testFrame,gui.textfield5)) != gui.list5) + throw new RuntimeException("Previous Component is not returned correctly for textfield."); + + EventQueue.invokeAndWait(() -> gui.testFrame.setVisible(true)); + robot.waitForIdle(1000); + + if (gui.focusGained5 != gui.choice5) + throw new RuntimeException("Initial Component is not getting focus " + + "after setting the traversal policy"); + + EventQueue.invokeAndWait(gui.testFrame::dispose); + + //Forward and backward traversal + EventQueue.invokeAndWait(() -> { + gui.frame5.setSize(500,270); + gui.frame5.setVisible(true); + }); + robot.waitForIdle(1000); + + HashSet hs = new HashSet(); + HashSet hs1 = new HashSet(); + + //Assersion:By default, Containers must not become the + // Focus Cycle Roots without programmatically + // setting it as a Focus Cycle Root. + + if (gui.firstpanel.isFocusCycleRoot()) + throw new RuntimeException("By default, Containers becomes the Focus " + + "Cycle Roots without programmatically setting it as a " + + "Focus Cycle Root."); + + EventQueue.invokeAndWait(() -> { + gui.firstpanel.setFocusCycleRoot(true); + gui.frame5.toFront(); + }); + robot.waitForIdle(1000); + + Point firstButtonCenter = gui.firstbutton.getLocationOnScreen(); + firstButtonCenter.translate(gui.firstbutton.getWidth()/2, gui.firstbutton.getHeight()/2); + robot.mouseMove(gui.firstbutton.getLocationOnScreen()); + robot.glide(gui.firstbutton.getLocationOnScreen(), firstButtonCenter); + robot.click(); + robot.waitForIdle(1000); + + //Assersion:When the focus owner is a Component inside a particular + // cycle, normal forward and backward focus traversal must + // not move the focus owner above the focus cycle root in + // the Component hierarchy + + //TAB key is pressed + robot.type(KeyEvent.VK_TAB); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firstchoice) + throw new RuntimeException("When the focus owner is a Component " + + "inside a particular cycle, normal forward and backward " + + "focus traversal moves the focus owner above the focus " + + "cycle root in the Component hierarchy"); + + //TAB key is pressed + robot.type(KeyEvent.VK_TAB); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firsttextfield) + throw new RuntimeException("When the focus owner is a Component " + + "inside a particular cycle, normal forward and backward " + + "focus traversal moves the focus owner above the focus " + + "cycle root in the Component hierarchy"); + + robot.type(KeyEvent.VK_TAB); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firstbutton) + throw new RuntimeException("When the focus owner is a Component " + + "inside a particular cycle, normal forward and backward " + + "focus traversal moves the focus owner above the focus " + + "cycle root in the Component hierarchy"); + + //Assersion:Most recent Focus Owner must be either of the following + // 1) Focused Component + // 2) A Component which must gain focus when its + // parent Window is focused + + EventQueue.invokeAndWait(() -> gui.manager.downFocusCycle(gui.firstpanel)); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firstbutton) + throw new RuntimeException("Component does not gain focus when its " + + "parent Window is focused "); + + //Assersion:When a Key is set as forward traversal key + // (KeyboardFocusManager.FORWARD_TRAVERSAL_KEY), + // the key must generate a forward focus traversal + // for every each component. + + EventQueue.invokeAndWait(() -> { + gui.firstbutton.requestFocusInWindow(); + + //setting "B" as FORWARD_TRAVERSAL_KEY. + hs.add(java.awt.AWTKeyStroke.getAWTKeyStroke("B")); + + KeyboardFocusManager.getCurrentKeyboardFocusManager() + .setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, hs); + }); + robot.waitForIdle(1000); + + //key press and key release of "B". + robot.type(KeyEvent.VK_B); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firstchoice) + throw new RuntimeException("When a Key is set as forward traversal " + + "key,the key does not generate a forward focus traversal " + + "for every each component."); + + //key press and key release of "B". + robot.type(KeyEvent.VK_B); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firsttextfield) + throw new RuntimeException("Assertion failed: Normal forward focus " + + "traversal is bringing focus out of the focus cycle"); + + //Assersion:When a Key is set as backward traversal key + // (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEY), + // the key must generate a backward focus traversal + // for every each component. + + EventQueue.invokeAndWait(() -> { + //setting "C" as BACKWARD_TRAVERSAL_KEY. + hs1.add(java.awt.AWTKeyStroke.getAWTKeyStroke("C")); + + KeyboardFocusManager.getCurrentKeyboardFocusManager() + .setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, hs1); + }); + robot.waitForIdle(1000); + + //key press and key release of "C". + robot.type(KeyEvent.VK_C); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firstchoice) + throw new RuntimeException("Assertion failed: Normal forward focus " + + "traversal is bringing focus out of the focus cycle"); + + //key press and key release of "C". + robot.type(KeyEvent.VK_C); + robot.waitForIdle(1000); + + if (gui.compgain != gui.firstbutton) + throw new RuntimeException("Assertion failed:Normal forward focus " + + "traversal is bringing focus out of the focus cycle"); + + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(() -> { + KeyboardFocusManager.setCurrentKeyboardFocusManager(null); + gui.frame5.dispose(); + }); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskFrame.java 2014-07-31 17:27:52.826615136 +0400 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.Label; + +/* + * @test + * @summary Create and dispose the Frame + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskFrame + */ + +public class TaskFrame extends Task { + + public static void main (String[] args) throws Exception { + new TaskFrame(GUIComponent.class, new ExtendedRobot()).runTask(); + } + + public TaskFrame(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + Frame[] frame = new Frame[1]; + + for (int i = 0; i < 10; i++) { + EventQueue.invokeAndWait(() -> { + frame[0] = new Frame("FrameTest"); + frame[0].setBackground(Color.blue); + frame[0].setSize(600, 270); + + Panel panel = new Panel(); + + Container container = new Container(); + container.setLayout(new FlowLayout()); + + Button button = new Button("Button"); + Canvas canvas = new Canvas(); + Checkbox checkbox = new Checkbox("CheckBox"); + Choice choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice 2"); + choice.add("Choice 3"); + choice.add("Choice 4"); + + Label label = new Label("Label"); + List list = new List(2); + list.add("list 1"); + list.add("list 2"); + list.add("list 3"); + Scrollbar scrollbar = new Scrollbar(); + + TextArea textarea = new TextArea("TextArea", 3, 10); + TextField textfield = new TextField("TextField"); + + container.add(button); + container.add(canvas); + container.add(checkbox); + container.add(choice); + container.add(label); + container.add(list); + container.add(scrollbar); + container.add(textarea); + container.add(textfield); + + panel.add(container); + frame[0].add(panel); + + frame[0].setVisible(true); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(frame[0]::dispose); + robot.waitForIdle(1000); + } + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskGlobalFocusOwner.java 2014-07-31 17:27:53.350615115 +0400 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Call the method KeyboardFocusManager. clearGlobalFocusOwner() + * and check whether the global focus owner has got cleared + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskGlobalFocusOwner + */ + +public class TaskGlobalFocusOwner extends Task { + + public static void main (String[] args) throws Exception { + new TaskGlobalFocusOwner(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskGlobalFocusOwner(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> gui.testframe4.setVisible(true)); + robot.waitForIdle(1000); + + gui.tempfocus = true; + + Point textfield15Center = gui.textfield15.getLocationOnScreen(); + textfield15Center.translate(gui.textfield15.getWidth()/2, gui.textfield15.getHeight()/2); + robot.glide(gui.textfield15.getLocationOnScreen(), textfield15Center); + robot.click(); + robot.waitForIdle(1000); + + //Clear the GlobalFocusOwner, textfield should receive the permanent focus lost + //and any key events should not be generated. + gui.setBooleans(); + + EventQueue.invokeAndWait(() -> gui.de.clearGlobalFocusOwner()); + robot.waitForIdle(1000); + + if (gui.tempfocus == true) + throw new RuntimeException("The focus lost is temporary when " + + "globalFocusOwner is cleared."); + + robot.type('A'); + robot.waitForIdle(1000); + + if (gui.keypressed15) + throw new RuntimeException("The keyevent is triggered when " + + "globalfocusowner is cleared" ); + + //Get the focus again and check for the key events + gui.setBooleans(); + robot.click(); + robot.waitForIdle(1000); + + if (! gui.focusgain) + throw new RuntimeException("The textfield did not get focus."); + + robot.type('A'); + robot.waitForIdle(1000); + + if (! gui.keypressed15) + throw new RuntimeException("The keyevent is not triggered."); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskKeyboardFocusManagerEvent.java 2014-07-31 17:27:53.878615094 +0400 @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Triggering Focus, Window & Key Events and checking they are + * handled properly by the KeyboardFocusManager and KeyEventDispatcher. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskKeyboardFocusManagerEvent + */ + +public class TaskKeyboardFocusManagerEvent extends Task { + + public static void main (String[] args) throws Exception { + new TaskKeyboardFocusManagerEvent(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskKeyboardFocusManagerEvent(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.button.setEnabled(false); + gui.setVisible(true); + }); + robot.waitForIdle(1000); + + gui.setBooleans(); + EventQueue.invokeAndWait(() -> gui.button.setEnabled(true)); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(gui.button::requestFocusInWindow); + robot.waitForIdle(1000); + + //No two Components must receive the KeyEvents at the same time + if (gui.buttonFocusGained && gui.listFocusGained) + throw new RuntimeException("Two Components receive the KeyEvents " + + "at the same time\n"); + + if (gui.buttonFocusGained == false) + throw new RuntimeException("Button has not Gained the focus even " + + "after requesting\n"); + + //-------------------------------------------------------------------- + + //When any Focus/ Window/ Key Events are triggered, the dispatchEvent() + //of the installed KeyboardFocusManager must be invoked by + //AWTEventDispatcher + EventQueue.invokeAndWait(() -> + KeyboardFocusManager.setCurrentKeyboardFocusManager(gui.cdk) + ); + robot.waitForIdle(1000); + + if (!(KeyboardFocusManager.getCurrentKeyboardFocusManager() + instanceof GUIMerlinFocus.CustomDefaultKeyBoardFocusManager1)) + throw new RuntimeException("CurrentKeyboardFocusManager Is:" + + KeyboardFocusManager.getCurrentKeyboardFocusManager()); + + //Change the focus to the next component. + EventQueue.invokeAndWait(gui.cdk::focusNextComponent); + robot.waitForIdle(100); + + if (gui.listFocusGained == false) + throw new RuntimeException("List has not Gained the focus even " + + "after changing the focus\n"); + + //Check if the old component has lost the focus + if (gui.buttonFocusLost == false) + throw new RuntimeException("Button has not lost the focus\n"); + + //Check for the active window + if (gui.cdk.getActiveWindow() == null) + throw new RuntimeException("Active Window is not the Frame\n"); + + //Check the focus owner + if (gui.cdk.getFocusOwner() == null) + throw new RuntimeException("Focus Owner is not the List\n"); + + //Check for the key event + Point listOrigin = gui.list.getLocationOnScreen(); + Point listCenter = gui.list.getLocationOnScreen(); + listCenter.translate(gui.list.getWidth()/2, gui.list.getHeight()/2); + robot.mouseMove(listOrigin); + robot.glide(listOrigin, listCenter); + robot.waitForIdle(1000); + robot.click(); + robot.type('N'); + + if (gui.KeyPressed == false) + throw new RuntimeException("Key Event is not generated\n"); + + //-------------------------------------------------------------------- + //When KeyboardFocusManager.dispatchEvent() returns false, + //AWTEventDispatcher must dispatch the event by itself + + Point buttonOrigin = gui.button.getLocationOnScreen(); + Point buttonCenter = gui.button.getLocationOnScreen(); + buttonCenter.translate(gui.button.getWidth()/2, gui.button.getHeight()/2); + robot.glide(buttonOrigin, buttonCenter); + robot.click(); + robot.waitForIdle(1000); + + if (gui.buttonClicked == false) + throw new RuntimeException("AWTEventDispatcher does not dispatch the event by itself\n"); + + EventQueue.invokeAndWait(() -> + KeyboardFocusManager.setCurrentKeyboardFocusManager(null) + ); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskOppositeComponent.java 2014-07-31 17:27:54.406615073 +0400 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.event.KeyEvent; + +/* + * @test + * @summary Change the focus between components and check whether the + * FocusEvents has been triggered properly and check whether the + * information about the Opposite Component can be obtained. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskOppositeComponent + */ + +public class TaskOppositeComponent extends Task { + + public static void main (String[] args) throws Exception { + new TaskOppositeComponent(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskOppositeComponent(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> + gui.frame4.setVisible(true) + ); + robot.waitForIdle(1000); + + // Transfer the focus from Button to List & check whether the + // getOppositeComponent is returning the component which lost + // the focus. + Point button2Origin = gui.button2.getLocationOnScreen(); + Point button2Center = gui.button2.getLocationOnScreen(); + button2Center.translate(gui.button2.getWidth()/2, gui.button2.getHeight()/2); + robot.glide(button2Origin, button2Center); + robot.waitForIdle(1000); + robot.click(); + + robot.type(KeyEvent.VK_TAB); + + if (gui.focusLostComp != gui.button2) + throw new RuntimeException("didn't get the information about " + + "opposite Component which lose the focus.\n"); + + // Transfer the focus from List to LwButton & check whether the + // getOppositeComponent is returning the component which gain + // the focus. + robot.type(KeyEvent.VK_TAB); + + if (gui.focusGainedComp!=gui.list2) + throw new RuntimeException("didn't get the information about " + + "opposite Component which gain the focus"); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskProgrammaticTraversal.java 2014-07-31 17:27:54.934615052 +0400 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Try to traverse through all the Focusable Components + * programmatically and check whether the focus has been traversed + * or not + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskProgrammaticTraversal + */ + +public class TaskProgrammaticTraversal extends Task { + + public static void main (String[] args) throws Exception { + new TaskProgrammaticTraversal(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskProgrammaticTraversal(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> + gui.testFrame2.setVisible(true) + ); + robot.waitForIdle(1000); + + Point button9Center = gui.button9.getLocationOnScreen(); + button9Center.translate(gui.button9.getWidth()/2, gui.button9.getHeight()/2); + robot.glide(gui.button9.getLocationOnScreen(), button9Center); + robot.waitForIdle(1000); + robot.click(); + + EventQueue.invokeAndWait(gui.manager2::focusNextComponent); + robot.waitForIdle(1000); + + if (gui.focusGained2 != gui.choice8) + throw new RuntimeException("KeyboardFocusManager.focusNextComponent() " + + "is not changing the focus owner."); + + EventQueue.invokeAndWait(gui.manager2::focusPreviousComponent); + robot.waitForIdle(1000); + + if (gui.focusGained2 != gui.button9) + throw new RuntimeException("KeyboardFocusManager.focusPreviousComponent() " + + "is not changing the focus owner."); + + EventQueue.invokeAndWait(() -> + gui.manager2.focusPreviousComponent(gui.checkbox8) + ); + robot.waitForIdle(1000); + + if (gui.focusGained2 != gui.textfield8) + throw new RuntimeException("KeyboardFocusManager.focusPreviousComponent(component) " + + "is not changing the focus owner."); + + EventQueue.invokeAndWait(() -> + gui.manager2.focusNextComponent(gui.textfield8) + ); + robot.waitForIdle(1000); + + if (gui.focusGained2 != gui.checkbox8) + throw new RuntimeException("KeyboardFocusManager.focusNextComponent(component) " + + "is not changing the focus owner."); + + EventQueue.invokeAndWait(gui.button8::transferFocus); + robot.waitForIdle(1000); + + if (gui.focusGained2 != gui.list8) + throw new RuntimeException("Component.transferFocus() is not changing " + + "the focus owner."); + + EventQueue.invokeAndWait(gui.list8::transferFocusBackward); + robot.waitForIdle(1000); + + if (gui.focusGained2 != gui.button8) + throw new RuntimeException("Component.transferFocusBackward() is not " + + "changing the focus owner."); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskRequestFocusOwner.java 2014-07-31 17:27:55.466615031 +0400 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Try to request focus to a component in a top level window which + * is not focused and check whether the component is becoming the + * focus owner.Check for the FOCUS_GAINED event and the keyevents by + * making the component focusable and non focusable. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskRequestFocusOwner + */ + +public class TaskRequestFocusOwner extends Task { + + public static void main (String[] args) throws Exception { + new TaskRequestFocusOwner(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskRequestFocusOwner(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> + gui.testframe3.setVisible(true) + ); + robot.waitForIdle(1000); + + Point button14Center = gui.button14.getLocationOnScreen(); + button14Center.translate(gui.button14.getWidth()/2, gui.button14.getHeight()/2); + robot.glide(gui.button14.getLocationOnScreen(), button14Center); + robot.click(); + robot.waitForIdle(1000); + + //Make the checkbox Disabled using the setVisible(false) and check + //whether the checkbox is getting the Focus + EventQueue.invokeAndWait(() -> { + gui.checkbox14.setEnabled(false); + gui.checkbox14.setVisible(false); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(gui.checkbox14::requestFocusInWindow); + robot.waitForIdle(1000); + if(gui.checkbox14.isFocusOwner()) + throw new RuntimeException("The checkbox has got the Focus when made " + + "setEnable(false) and setVisible(false)."); + + EventQueue.invokeAndWait(() -> { + gui.checkbox14.setEnabled(true); + gui.checkbox14.setVisible(true); + }); + robot.waitForIdle(1000); + EventQueue.invokeAndWait(gui.checkbox14::requestFocusInWindow); + robot.waitForIdle(1000); + if(!gui.checkbox14.isFocusOwner()) + throw new RuntimeException("The Checkbox did get the focus when made " + + "setEnable(true) and setVisible(true)."); + + //Checking whether the TextArea has gained the Focus after making + //setFocusable as false + EventQueue.invokeAndWait(() -> { + gui.textarea14.setFocusable(false); + gui.textarea14.requestFocusInWindow(); + }); + robot.waitForIdle(1000); + if(gui.textarea14.isFocusOwner()) + throw new RuntimeException("The Focus is transferred to Non-Focusable " + + "TextArea."); + + EventQueue.invokeAndWait(() -> + gui.textarea14.setFocusable(true) + ); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(() -> + gui.textarea14.requestFocusInWindow() + ); + robot.waitForIdle(1000); + if(!gui.textarea14.isFocusOwner()) + throw new RuntimeException("The Focus is not transferred to Focusable " + + "TextArea"); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskWindow.java 2014-07-31 17:27:55.990615010 +0400 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.Label; + +/* + * @test + * @summary Create and dispose the Window + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskWindow + */ + +public class TaskWindow extends Task { + + Frame frame; + Window window; + Panel panel; + Button button; + Canvas canvas; + Checkbox checkbox; + Choice choice; + Container container; + Label label; + List list; + Scrollbar scrollbar; + TextArea textarea; + TextField textfield; + + public static void main (String[] args) throws Exception { + new TaskWindow(GUIComponent.class, new ExtendedRobot()).runTask(); + } + + TaskWindow(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + + for (int i = 0; i < 10; i++) { + EventQueue.invokeAndWait(() -> { + frame = new Frame("WindowTest"); + window = new Window(frame); + window.setBackground(Color.red); + window.setSize(600, 270); + + panel = new Panel(); + + container = new Container(); + container.setLayout(new FlowLayout()); + + button = new Button("Button"); + canvas = new Canvas(); + + checkbox = new Checkbox("CheckBox"); + choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice 2"); + choice.add("Choice 3"); + choice.add("Choice 4"); + + label = new Label("Label"); + list = new List(2); + list.add("list 1"); + list.add("list 2"); + list.add("list 3"); + scrollbar = new Scrollbar(); + + textarea = new TextArea("TextArea", 3, 10); + textfield = new TextField("TextField"); + + container.add(button); + container.add(canvas); + container.add(checkbox); + container.add(choice); + container.add(label); + container.add(list); + container.add(scrollbar); + container.add(textarea); + container.add(textfield); + + panel.add(container); + window.add(panel); + + window.setVisible(true); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(() -> { + container.remove(button); + container.remove(canvas); + container.remove(checkbox); + container.remove(choice); + container.remove(label); + container.remove(list); + container.remove(scrollbar); + container.remove(textarea); + container.remove(textfield); + + panel.remove(container); + window.remove(panel); + window.dispose(); + frame.dispose(); + }); + robot.waitForIdle(1000); + robot.waitForIdle(1000); + } + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskWindowFocusEvents.java 2014-07-31 17:27:56.522614989 +0400 @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.event.*; + +/* + * @test + * @summary Active and check whether the respective WindowEvents are triggered + * properly and traverse the focus through focusable & non focusable + * components in a window and check whether the FocusEvents are + * triggered properly. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskWindowFocusEvents + */ + +public class TaskWindowFocusEvents extends Task { + + public static void main (String[] args) throws Exception { + new TaskWindowFocusEvents(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); + } + + TaskWindowFocusEvents(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.setBooleans(); + gui.frame1.setVisible(true); + gui.frame2.setVisible(true); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(gui::framesSetLocationAndSize); + robot.waitForIdle(1000); + + // WindowEvent.WINDOW_DEACTIVATED must be dispatched to + // the Frame + + // WindowEvent.WINDOW_ACTIVATED must be dispatched to + // Frame when this Frame becomes the active window + + // An Active Window must be either of the following + // Frame which is the Focused Window + // First Frame that is the owner of the focused Window + + Point movePoint = gui.frame2.getLocationOnScreen(); + movePoint.translate(gui.frame2.getWidth()/2, gui.frame2.getHeight()/2); + robot.mouseMove(movePoint); + robot.waitForIdle(1000); + robot.click(); + + gui.setBooleans(); + + movePoint = gui.frame1.getLocationOnScreen(); + movePoint.translate(gui.frame1.getWidth()/2, gui.frame1.getHeight()/2); + robot.mouseMove(movePoint); + robot.waitForIdle(1000); + robot.click(); + + if (!gui.frame1Activated) + throw new RuntimeException("Window activated event is not fired for " + + gui.frame1); + + if (!gui.frame2Deactivated) + throw new RuntimeException("Window deactivated event is not fired for " + + gui.frame2); + + if (!gui.frame1.isActive()) + throw new RuntimeException("Not an active window " + gui.frame1); + + // WindowEvent.WINDOW_DEACTIVATED must be dispatched to + // the Dialog + + // WindowEvent.WINDOW_ACTIVATED must be dispatched to + // Dialog when this Dialog becomes the active window + + // An Active Window must be either of the following + // Dialog which is the Focused Window + // First Dialog that is the owner of the focused Window + + EventQueue.invokeAndWait(() -> { + gui.dialog1.setVisible(true); + gui.dialog2.setVisible(true); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(gui::dialogsSetLocationAndSize); + robot.waitForIdle(1000); + + movePoint = gui.dialog2.getLocationOnScreen(); + movePoint.translate(gui.dialog2.getWidth()/2, gui.dialog2.getHeight()/2); + robot.mouseMove(movePoint); + robot.waitForIdle(1000); + robot.click(); + + gui.setBooleans(); + + movePoint = gui.dialog1.getLocationOnScreen(); + movePoint.translate(gui.dialog1.getWidth()/2, gui.dialog1.getHeight()/2); + robot.mouseMove(movePoint); + robot.waitForIdle(1000); + robot.click(); + + if (!gui.dialog1Activated) + throw new RuntimeException("Window activated event is not fired for " + + gui.dialog1); + + if (!gui.dialog2Deactivated) + throw new RuntimeException("Window deactivated event is not fired for " + + gui.dialog2); + + if (!gui.dialog1.isActive()) + throw new RuntimeException("Not an active window " + gui.dialog1); + + gui.setBooleans(); + EventQueue.invokeAndWait(() -> { + gui.frame1.dispose(); + gui.frame2.dispose(); + gui.dialog1.dispose(); + gui.dialog2.dispose(); + + gui.frame3.setVisible(true); + }); + robot.waitForIdle(1000); + + // Only focus traversable component can receive + // FocusEvent.FOCUS_GAINED event. When client code or user + // try to focus a non focus traversable component, + // this component can not receive FocusEvent.FOCUS_GAINED event + + // Bring mouse pointer on to button + Point buttonCenter = gui.button1.getLocationOnScreen(); + buttonCenter.translate(gui.button1.getWidth()/2, gui.button1.getHeight()/2); + robot.mouseMove(buttonCenter); + robot.waitForIdle(1000); + robot.click(); + + if (gui.textfieldFocusLost) + throw new RuntimeException("Focus lost event has triggered for text " + + "field when clicked on disabled component.\n"); + + if (gui.button1FocusGained) + throw new RuntimeException("Disabled component gained focus " + + gui.button1); + + // FocusEvent.FOCUS_GAINED must be dispatched to a + // focus traversable component when this component + // becomes the Focus Owner + + // FocusEvent.FOCUS_LOST must be dispatched to a component + // when this component is no longer a Focus Owner + + gui.setBooleans(); + + Point textfieldCenter = gui.textfield.getLocationOnScreen(); + textfieldCenter.translate(gui.textfield.getWidth() / 2, gui.textfield.getHeight() / 2); + robot.mouseMove(textfieldCenter); + robot.waitForIdle(); + robot.click(); + robot.type(KeyEvent.VK_TAB); + + if( !gui.textfieldFocusLost ) + throw new RuntimeException("When tab is pressed, Focus lost event " + + "didn't fire for " + gui.textfield); + + if(!gui.textareaFocusGained) + throw new RuntimeException("When tab is pressed, Focus gained event " + + "didn't fire for " + gui.textarea); + + EventQueue.invokeAndWait(gui.frame3::dispose); + robot.waitForIdle(1000); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskXDragDrop.java 2014-07-31 17:27:57.066614968 +0400 @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; +import java.awt.dnd.DnDConstants; + +/* + * @test + * @summary Testcase to test the reliability of XDnD implementation. Opens a + * native window and drags and drops between java and the native + * windows. Checks if the events are properly triggered and the drag + * and drop occurs successfully. Tries to drag large amount of data + * and checks if there is any memory leak issue. This testcase has + * been taken from XDnD Tiger testsuite. + * @author Girish R (girish.ramachandran@sun.com), AWT-SQE + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run shell TaskXDragDrop.sh + */ + +public class TaskXDragDrop extends Task { + + Point javaPoint; + Point nativePoint; + + public static void main (String[] args) throws Exception { + new TaskXDragDrop(GUIXDnDJava.class, new ExtendedRobot()).runTask(); + System.exit(0); + } + + /** + * Initializes the GUI. Adds listeners to the GUI. + */ + public TaskXDragDrop(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + + gui.startChild(); + gui.dragDropEnd = false; + gui.dropSuccess = false; + gui.dropAction = 0; + gui.dropData = new String(""); + } + + /** + * Took the test from XDnD tests. + * Open the native window and wait for the test to complete. + */ + public void task() throws Exception { + //EventQueue.invokeAndWait(gui::requestFocus); + //robot.waitForIdle(1000); + + javaPoint = new Point(6, 200); + Dimension d = gui.getSize(); + javaPoint.translate(d.width / 2, d.height / 2); + + nativePoint = new Point(650, javaPoint.y); + + robot.dragAndDrop(javaPoint, nativePoint); + //robot.waitForIdle(1000); + robot.dragAndDrop(nativePoint, javaPoint); + //robot.waitForIdle(1000); + + if (!(GUIXDnDJava.data + GUIXDnDJava.data).equals(((String) (gui.dropData)).trim())) + throw new RuntimeException("Incorrect drop data: " + gui.dropData); + + if (!gui.dragDropEnd) + throw new RuntimeException("TEST FAIL: dragDropEnd() method is not called"); + + gui.destroyProcess(); + EventQueue.invokeAndWait(gui::dispose); + } + + public void verifyFailed() { + if (gui.dropSuccess == false) + throw new RuntimeException("Drop is NOT successful"); + + if (gui.dropAction != DnDConstants.ACTION_MOVE) + throw new RuntimeException("Drop Action is wrong"); + } +} + --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskXDragDrop.sh 2014-07-31 17:27:57.614614946 +0400 @@ -0,0 +1,61 @@ +# Copyright (c) 2004, 2014, 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. + +SOURCES="${TESTSRC}/TaskXDragDrop.java ${TESTSRC}/GUIXDnDJava.java ${TESTSRC}/Task.java" + +OS=`uname -s` +case "$OS" in + SunOS | Linux ) + # This test compile native code with gcc compiler using X libraries + # So only X-based environment should be tested + ;; + * ) + echo "The test is not need to be run under $OS" + exit 0; + ;; +esac + +echo " Compiling..." +XDND_COMPILE_NATIVE="gcc -s ${TESTSRC}/xdnd-child.c -o xdnd-child `pkg-config --libs xt`" +${XDND_COMPILE_NATIVE} + +if [ $? -ne 0 ]; then + echo " Compiling the c program failed" + echo " Command was: ${XDND_COMPILE_NATIVE}" + exit 1; +fi + +${TESTJAVA}/bin/javac -cp ${TESTCLASSPATH} -d ${TESTCLASSES} ${SOURCES} + +if [ $? -ne 0 ]; then + echo " Compilation Failed" + exit 1 +fi + +echo " Running..." +${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} TaskXDragDrop + +if [ $? -ne 0 ]; then + echo " Execution Failed" + exit 1 +else + exit 0 +fi --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskXEmbedListeners.java 2014-07-31 17:27:58.154614924 +0400 @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Testcase to check if the listeners are notified when events occur + * in the components added on an embedded AWT Frame in an SWT shell. + * @author Girish R (girish.ramachandran@sun.com) + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run shell TaskXEmbedListeners.sh + */ + +public class TaskXEmbedListeners extends Task { + + public static void main (String[] args) throws Exception { + new TaskXEmbedListeners(GUIXEmbedListeners.class, new ExtendedRobot()).runTask(); + System.exit(0); + } + + public TaskXEmbedListeners(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + /** + * Do the test. There's a problem in closing the SWT shell. Its not getting + * closed when the close method is called. Currently using setVisible + * (false). Not sure if it'll be gc'd. + * Took the test from Frame test. + */ + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.textfield1.setText("Textfield"); + gui.frame.removeAll(); + gui.frame.add(gui.button1); + gui.frame.setVisible(true); + }); + robot.waitForIdle(1000); + + robot.glide(new Point(100, 100), new Point(200, 105)); + robot.waitForIdle(1000); + robot.click(); + Point button1Origin; + Point button1Center; + Point scrollBar1Origin; + Point scrollBar1Center; + Point textarea1Origin; + Point textarea1Center; + Point choicePos; + Point choicePoint; + + button1Origin = gui.button1.getLocationOnScreen(); + button1Center = gui.button1.getLocationOnScreen(); + button1Center.translate(gui.button1.getWidth()/2, gui.button1.getHeight()/2); + + //ActionListener + robot.glide(button1Origin, button1Center); + robot.click(); + if (! gui.act_event) + throw new RuntimeException("When Button is clicked, Action Event " + + "is not generated.\n"); + + //AdjustmentListener + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.button1); + gui.frame.setLayout(null); + gui.scrollBar.setSize(30, 150); + gui.scrollBar.setLocation(40, 25); + gui.frame.add(gui.scrollBar); + }); + robot.waitForIdle(1000); + + scrollBar1Origin = gui.scrollBar.getLocationOnScreen(); + scrollBar1Center = gui.scrollBar.getLocationOnScreen(); + scrollBar1Center.translate(gui.scrollBar.getWidth()/2, gui.scrollBar.getHeight()/2); + + robot.glide(scrollBar1Origin, scrollBar1Center); + robot.click(); + if (! gui.adj_list) + throw new RuntimeException("When Scroll bar is moved, Adjustment " + + "Event is not generated.\n"); + + //ComponentListener + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.scrollBar); + gui.frame.repaint(); + gui.frame.add(gui.button1); + gui.button1.setVisible(false); + }); + robot.waitForIdle(1000); + if (! gui.comp_hidden) + throw new RuntimeException("When Button is Hidden, Component " + + "hidden Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> { + gui.frame.setLayout(null); + gui.button1.setLocation(100, 50); + gui.button1.setVisible(true); + }); + robot.waitForIdle(1000); + if (! gui.comp_shown) + throw new RuntimeException("When Button is Shown, Component " + + "shown Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> gui.button1.setLocation(50, 100)); + robot.waitForIdle(1000); + if (! gui.comp_moved) { + throw new RuntimeException("When Button is Moved, Component " + + "Moved Event is not generated.\n"); + } + + EventQueue.invokeAndWait(() -> gui.button1.setSize(100, 60)); + robot.waitForIdle(1000); + if (! gui.comp_resized) + throw new RuntimeException("When Button is Resized, Component " + + "Resized Event is not generated.\n"); + + //ContainerListener + EventQueue.invokeAndWait(() -> gui.frame.remove(gui.button1)); + robot.waitForIdle(1000); + if (! gui.comp_removed) + throw new RuntimeException("When Button is removed, Component " + + "removed Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> { + gui.frame.add(gui.button1); + gui.frame.repaint(); + }); + robot.waitForIdle(1000); + if (! gui.comp_added) + throw new RuntimeException("When Button is added, Component " + + "Added Event is not generated.\n"); + + //FocusListener + EventQueue.invokeAndWait(() -> { + gui.button2.setSize(100, 60); + gui.button2.setLocation(160, 100); + gui.frame.add(gui.button2); + gui.button1.requestFocus(); + }); + robot.waitForIdle(1000); + if (! gui.focus_gain) + throw new RuntimeException("When Focus is requested, Focus " + + "gained Event is not generated.\n"); + + EventQueue.invokeAndWait(gui.button1::transferFocus); + robot.waitForIdle(1000); + if (! gui.focus_lost) + throw new RuntimeException("When Focus is lost, Focus lost Event " + + "is not generated.\n"); + + //HierarchyBoundsListener + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.button1); + gui.frame.remove(gui.button2); + gui.panel.setLocation(10, 10); + gui.panel.add(gui.button1); + gui.frame.add(gui.panel); + gui.panel.setLocation(50, 50); + gui.panel.setSize(200, 200); + }); + robot.waitForIdle(1000); + if (! gui.ancestor_moved) + throw new RuntimeException("When Ancestor is moved, Ancestor " + + "moved Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> gui.panel.setSize(240, 200)); + robot.waitForIdle(1000); + if (! gui.ancestor_resized) + throw new RuntimeException("When Ancestor is resized, Ancestor " + + "resized Event is not generated.\n"); + + //HierarchyListener + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.panel); + gui.panel1.setSize(200, 200); + gui.panel1.add(gui.button1); + gui.frame.add(gui.panel1); + }); + robot.waitForIdle(1000); + if (! gui.hierarchy_changed) + throw new RuntimeException("When Ancestor is Changed, hierarchy " + + "changed Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> gui.frame.remove(gui.panel1)); + robot.waitForIdle(1000); + + //ItemListener + EventQueue.invokeAndWait(() -> { + gui.frame.setLayout(new FlowLayout()); + gui.frame.add(gui.colorchoice); + gui.colorchoice.setLocation(50, 50); + gui.frame.setVisible(true); + }); + robot.waitForIdle(1000); + + Point choiceOrigin = gui.colorchoice.getLocationOnScreen(); + choicePos = gui.colorchoice.getLocationOnScreen(); + choicePoint=new Point(choicePos.x+55, choicePos.y+8); + robot.glide(choiceOrigin, choicePoint); + robot.waitForIdle(1000); + robot.click(); + robot.mouseMove(choicePoint); + robot.waitForIdle(1000); + choicePoint = new Point(choicePos.x+50,choicePos.y+80); + robot.mouseMove(choicePoint); + robot.waitForIdle(1000); + robot.click(); + + if (gui.item_changed == false) + throw new RuntimeException("When Item is changed, Item Method " + + "Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.colorchoice); + + //KeyListener + gui.frame.add(gui.textfield1); + }); + robot.waitForIdle(1000); + + textarea1Origin = gui.textfield1.getLocationOnScreen(); + textarea1Center = gui.textfield1.getLocationOnScreen(); + textarea1Center.translate(gui.textfield1.getWidth()/2, gui.textfield1.getHeight()/2); + robot.glide(textarea1Origin, textarea1Center); + robot.waitForIdle(1000); + robot.click(); + robot.type('N'); + if (gui.key_pressed == false) + throw new RuntimeException("When Key is pressed, Key Pressed " + + "Event is not generated.\n"); + + if (gui.key_released == false) + throw new RuntimeException("When Key is released, Key Released " + + "Event is not generated.\n"); + + if (gui.key_typed == false) + throw new RuntimeException("When Key is typed, Key Typed Event " + + "is not generated.\n"); + + //MouseListener + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.textfield1); + gui.frame.add(gui.button1); + gui.button1.setLocation(100, 50); + }); + robot.waitForIdle(1000); + + button1Origin = gui.button1.getLocationOnScreen(); + button1Center = gui.button1.getLocationOnScreen(); + button1Center.translate(gui.button1.getWidth()/2, gui.button1.getHeight()/2); + robot.glide(button1Origin, button1Center); + robot.waitForIdle(1000); + if (gui.mouse_entered == false) + throw new RuntimeException("When Mouse is entered, mouse entered " + + "Event is not generated.\n"); + + robot.click(); + if (gui.mouse_pressed == false) + throw new RuntimeException("When Mouse is pressed, mouse pressed " + + "Event is not generated.\n"); + + if (gui.mouse_released == false) + throw new RuntimeException("When Mouse is released, mouse released " + + "Event is not generated.\n"); + + if (gui.mouse_clicked == false) + throw new RuntimeException("When Mouse is clicked, mouse clicked " + + "Event is not generated.\n"); + + robot.mouseMove(150, 150); + robot.waitForIdle(1000); + if (gui.mouse_exited == false) + throw new RuntimeException("When Mouse is exited, mouse exited " + + "Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.button1); + + //MouseMotionListener + gui.frame.add(gui.button1); + }); + robot.waitForIdle(1000); + + button1Origin = gui.button1.getLocationOnScreen(); + button1Center = gui.button1.getLocationOnScreen(); + button1Center.translate(gui.button1.getWidth()/2, gui.button1.getHeight()/2); + robot.glide(button1Origin, button1Center); + robot.waitForIdle(1000); + robot.dragAndDrop(button1Center, button1Origin); + if (gui.mouse_dragged == false) + throw new RuntimeException("When Mouse is dragged, mouse dragged " + + "Event is not generated.\n"); + + robot.mouseMove(button1Origin); + robot.waitForIdle(1000); + if (gui.mouse_moved == false) + throw new RuntimeException("When Mouse is moved, mouse moved " + + "Event is not generated.\n"); + + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.button1); + + //TextListener + gui.frame.add(gui.textfield1); + }); + robot.waitForIdle(1000); + + robot.mouseMove(gui.textfield1.getLocationOnScreen()); + robot.waitForIdle(1000); + robot.click(); + robot.type('A'); + if (gui.textvalue_changed == false) + throw new RuntimeException("When Text value is changed, TextEvent " + + "is not generated.\n"); + + EventQueue.invokeAndWait(() -> { + gui.frame.remove(gui.textfield1); + }); + robot.waitForIdle(1000); + + gui.destroyProcess(); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskXEmbedListeners.sh 2014-07-31 17:27:58.682614903 +0400 @@ -0,0 +1,61 @@ +# Copyright (c) 2004, 2014, 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. + +SOURCES="${TESTSRC}/TaskXEmbedListeners.java ${TESTSRC}/GUIXEmbedListeners.java ${TESTSRC}/Task.java" + +OS=`uname -s` +case "$OS" in + SunOS | Linux ) + # This test compile native code with gcc compiler using X libraries + # So only X-based environment should be tested + ;; + * ) + echo "The test is not need to be run under $OS" + exit 0; + ;; +esac + +echo " Compiling..." +XEMBED_COMPILE_NATIVE="gcc ${TESTSRC}/gtk-embedder.c -o gtk-embedder `pkg-config --cflags --libs glib-2.0 cairo gtk+-2.0 atk`" +${XEMBED_COMPILE_NATIVE} + +if [ $? -ne 0 ]; then + echo " Compiling the c program failed" + echo " Command was: ${XEMBED_COMPILE_NATIVE}" + exit 1; +fi + +${TESTJAVA}/bin/javac -cp ${TESTCLASSPATH} -d ${TESTCLASSES} ${SOURCES} + +if [ $? -ne 0 ]; then + echo " Compilation Failed" + exit 1 +fi + +echo "Running..." +${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} TaskXEmbedListeners + +if [ $? -ne 0 ]; then + echo " Execution Failed" + exit 1 +else + exit 0 +fi --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskXEmbedMemory.java 2014-07-31 17:27:59.238614881 +0400 @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Testcase to check if there is any memory leak when components are + * added and then removed from an embedded AWT Frame in an SWT shell. + * @author Girish R (girish.ramachandran@sun.com), AWT-SQE + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run shell TaskXEmbedMemory.sh + */ + +public class TaskXEmbedMemory extends Task { + + Panel panel; + Button button; + Canvas canvas; + Checkbox checkbox; + Choice choice; + Container container; + Label label; + List list; + Scrollbar scrollbar; + TextArea textarea; + TextField textfield; + + public static void main (String[] args) throws Exception { + new TaskXEmbedMemory(GUIXEmbedMemory.class, new ExtendedRobot()).runTask(); + System.exit(0); + } + + public TaskXEmbedMemory(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + /** + * Simple test. All components and remove them. Check if there's memory leak. + * Took the test from Frame test. + */ + public void task() throws Exception { + robot.glide(100, 100, 200, 110); + robot.waitForIdle(); + robot.click(); + + EventQueue.invokeAndWait(() -> { + panel = new Panel(); + + container = new Container(); + container.setLayout(new FlowLayout()); + + button = new Button("Button"); + canvas = new Canvas(); + checkbox = new Checkbox("CheckBox"); + choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice 2"); + choice.add("Choice 3"); + choice.add("Choice 4"); + + label = new Label("Label"); + list = new List(2); + list.add("list 1"); + list.add("list 2"); + list.add("list 3"); + scrollbar = new Scrollbar(); + + textarea = new TextArea("TextArea", 3, 10); + textfield = new TextField("TextField"); + + container.add(button); + container.add(canvas); + container.add(checkbox); + container.add(choice); + container.add(label); + container.add(list); + container.add(scrollbar); + container.add(textarea); + container.add(textfield); + + panel.add(container); + gui.frame.add(panel); + }); + robot.waitForIdle(1000); + + EventQueue.invokeAndWait(gui.frame::removeAll); + robot.waitForIdle(1000); + + gui.destroyProcess(); + EventQueue.invokeAndWait(gui::dispose); + } +} + --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskXEmbedMemory.sh 2014-07-31 17:27:59.770614860 +0400 @@ -0,0 +1,61 @@ +# Copyright (c) 2004, 2014, 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. + +SOURCES="${TESTSRC}/TaskXEmbedMemory.java ${TESTSRC}/GUIXEmbedMemory.java ${TESTSRC}/Task.java" + +OS=`uname -s` +case "$OS" in + SunOS | Linux ) + # This test compile native code with gcc compiler using X libraries. + # So only X-based environment should be tested + ;; + * ) + echo "The test is not need to be run under $OS" + exit 0; + ;; +esac + +echo " Compiling..." +XEMBED_COMPILE_NATIVE="gcc ${TESTSRC}/gtk-embedder.c -o gtk-embedder `pkg-config --cflags --libs glib-2.0 cairo gtk+-2.0 atk`" +${XEMBED_COMPILE_NATIVE} + +if [ $? -ne 0 ]; then + echo " Compiling the c program failed" + echo " Command was: ${XEMBED_COMPILE_NATIVE}" + exit 1; +fi + +${TESTJAVA}/bin/javac -cp ${TESTCLASSPATH} -d ${TESTCLASSES} ${SOURCES} + +if [ $? -ne 0 ]; then + echo " Compilation Failed" + exit 1 +fi + +echo "Running..." +${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} TaskXEmbedMemory + +if [ $? -ne 0 ]; then + echo " Execution Failed" + exit 1 +else + exit 0 +fi --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskZoomFrameChangeState.java 2014-07-31 17:28:00.306614839 +0400 @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Construct a Frame, zoom it from the normal state and back forth + * using Frame.ZOOMED and Frame.NORMAL. Iconofy from the zoomed + * state and back forth using Frame.ICONIFIED and Frame.NORMAL and + * check the zoomed size is same as the screen size. Check the + * location of the frame after restoration from zoom or icon. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskZoomFrameChangeState + */ + +public class TaskZoomFrameChangeState extends Task { + + public static void main (String[] args) throws Exception { + new TaskZoomFrameChangeState(GUIZoomFrame.class, new ExtendedRobot()).runTask(); + } + + TaskZoomFrameChangeState(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.frame1.setLayout(null); + gui.frame1.setVisible(true); + gui.frame1.removeAll(); + if (gui.frame1.getExtendedState() != Frame.NORMAL) + gui.frame1.setExtendedState(Frame.NORMAL); + }); + robot.waitForIdle(1000); + + Point frameOrigin = gui.frame1.getLocationOnScreen(); + Point newposition; + + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.ICONIFIED) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for ICONIFIED state is set... + if (gui.frame1.getExtendedState() != Frame.ICONIFIED) + throw new RuntimeException("The bitwise mask Frame.ICONIFIED is " + + "not set when the frame is in ICONIFIED state"); + + //To check whether the Frame is iconified programmatically.......... + if (! gui.iconify) + throw new RuntimeException("Frame is not Iconified"); + + //Normalising the Frame.... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for NORMAL state is set... + if (gui.frame1.getExtendedState() != Frame.NORMAL) + throw new RuntimeException("The bitwise mask Frame.NORMAL is not " + + "set when the frame is in NORMAL state after Iconofied"); + + //To check whether the Frame is normalised programmatically.......... + if (! gui.normal) + throw new RuntimeException("Frame is not restored to normal after" + + " Iconofied"); + + newposition = gui.frame1.getLocationOnScreen(); + + if((frameOrigin.x != newposition.x)&(frameOrigin.y != newposition.y)) + throw new RuntimeException("The frame is not positioned back " + + "to the original place on the screen after Iconified"); + + robot.waitForIdle(1000); + + //To check whether the state is supported in the platform.... + if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_HORIZ)) { + //System.out.println("Frame.MAXIMIZED_HORIZ is supported"); + //Maximising the Frame horizontally......... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.MAXIMIZED_HORIZ) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for MAXIMIZED_HORIZ state is set... + if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_HORIZ) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_HOR " + + "is not set when the frame is in MAXIMIZED_HOR state"); + + //To check whether the Frame is maximized horizontally.......... + if (! gui.maxHor) + throw new RuntimeException("Frame is not maximized horizontally"); + + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + } + + //To check whether the state is supported in the platform.... + if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_VERT)) { + //System.out.println("Frame.MAXIMIZED_VERT is supported"); + //Maximising the Frame vertically......... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.MAXIMIZED_VERT) + ); + robot.waitForIdle(1000); + //To check whether the bitwise mask for MAXIMIZED_VERT state is set... + if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_VERT) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_VERT " + + "is not set when the frame is in MAXIMIZED_VERT state"); + + //To check whether the Frame is maximized vertically.......... + if (! gui.maxVer) + throw new RuntimeException("Frame is not maximized vertically"); + + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + } + + if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)){ + //Maximising the Frame fully + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.MAXIMIZED_BOTH) + ); + } + robot.waitForIdle(1000); + + //To check whether the state is supported in the platform.... + if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { + //To check whether the bitwise mask for MAXIMIZED_BOTH state is set... + if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_BOTH) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " + + "is not set when the frame is in MAXIMIZED_BOTH state"); + + //To check whether the Frame is maximized fully.......... + if (! gui.maxBoth) + throw new RuntimeException("Frame is not maximized fully"); + } + + //Normalising the Frame.... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(10000); + + //To check whether the bitwise mask for NORMAL state is set... + if (gui.frame1.getExtendedState() != Frame.NORMAL) + throw new RuntimeException("The bitwise mask Frame.NORMAL " + + "is not set when the frame is in NORMAL state after Zoomed"); + + //To check whether the Frame is normalised programmatically.......... + if (! gui.normal) + throw new RuntimeException("Frame is not restored to normal after Zoomed"); + + robot.waitForIdle(1000); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskZoomFrameRepaint.java 2014-07-31 17:28:00.834614818 +0400 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Construct a frame with some components and zoom the frame and bring + * it back to normal state. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskZoomFrameRepaint + */ + +public class TaskZoomFrameRepaint extends Task { + + public static void main (String[] args) throws Exception { + new TaskZoomFrameRepaint(GUIZoomFrame.class, new ExtendedRobot()).runTask(); + } + + TaskZoomFrameRepaint(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.frame2.setVisible(true); + gui.frame2.removeAll(); + gui.frame2.add(gui.button); + gui.frame2.add(gui.textarea); + if (gui.frame2.getExtendedState() != Frame.NORMAL) + gui.frame2.setExtendedState(Frame.NORMAL); + }); + robot.waitForIdle(1000); + + Point buttonOrigin, newbuttonOrigin, newbuttonCenter; + Point textareaOrigin, newtextareaOrigin, newtextareaCenter ; + + //to find the lenght and width of the component originally + buttonOrigin = gui.button.getLocationOnScreen(); + textareaOrigin = gui.textarea.getLocationOnScreen(); + + if (Toolkit.getDefaultToolkit().isFrameStateSupported( + Frame.MAXIMIZED_BOTH)){ + //Maximising the Frame fully......... + EventQueue.invokeAndWait(() -> + gui.frame2.setExtendedState(Frame.MAXIMIZED_BOTH) + ); + robot.waitForIdle(1000); + //To check whether the bitwise mask for MAXIMIZED_BOTH state is set... + if (gui.frame2.getExtendedState() != Frame.MAXIMIZED_BOTH) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " + + "is not set when the frame is in MAXIMIZED_BOTH state"); + + //To check whether the Frame is maximized fully.......... + if (gui.maxBoth == false) + throw new RuntimeException("Frame is not maximized fully"); + } + + //Normalising the Frame.... + EventQueue.invokeAndWait(() -> + gui.frame2.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for NORMAL state is set... + if (gui.frame2.getExtendedState() != Frame.NORMAL) + throw new RuntimeException("The bitwise mask Frame.NORMAL is not " + + "set when the frame is in NORMAL state"); + + //To check whether the Frame is normalised programmatically.......... + if (! gui.normal) + throw new RuntimeException("Frame is not restored to normal"); + + //to find the lenght and width of the component after zommed and back to normal + newbuttonOrigin = gui.button.getLocationOnScreen(); + newtextareaOrigin = gui.textarea.getLocationOnScreen(); + newbuttonCenter = gui.button.getLocationOnScreen(); + newbuttonCenter.translate(gui.button.getWidth()/2, gui.button.getHeight()/2); + newtextareaCenter = gui.textarea.getLocationOnScreen(); + newtextareaCenter.translate(gui.textarea.getWidth()/2, gui.textarea.getHeight()/2); + + if((buttonOrigin.x != newbuttonOrigin.x)&(buttonOrigin.y != newbuttonOrigin.y)) + throw new RuntimeException("The button is not positioned back to the " + + "original place on the screen after iconified"); + + if((textareaOrigin.x != newtextareaOrigin.x)&(textareaOrigin.y != newtextareaOrigin.y)) + throw new RuntimeException("The TextArea is not positioned back to the " + + "original place on the screen after iconified"); + + EventQueue.invokeAndWait(() -> { + gui.frame2.remove(gui.button); + gui.frame2.remove(gui.textarea); + }); + robot.waitForIdle(1000); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskZoomUndFrameChangeState.java 2014-07-31 17:28:01.374614797 +0400 @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Construct a Undecorated Frame, zoom it from the normal state and + * back forth using Frame.ZOOMED and Frame.NORMAL. Iconofy from the + * zoomed state and back forth using Frame.ICONIFIED and Frame.NORMAL + * and check the zoomed size is same as the screen size. Check the + * location of the frame after restoration from zoom or icon. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskZoomUndFrameChangeState + */ + +public class TaskZoomUndFrameChangeState extends Task { + + public static void main (String[] args) throws Exception { + new TaskZoomUndFrameChangeState(GUIZoomFrame.class, new ExtendedRobot()).runTask(); + } + + TaskZoomUndFrameChangeState(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.frame1.setLayout(null); + gui.frame1.setUndecorated(true); + gui.frame1.setVisible(true); + gui.frame1.removeAll(); + if (gui.frame1.getExtendedState() != Frame.NORMAL) + gui.frame1.setExtendedState(Frame.NORMAL); + }); + robot.waitForIdle(1000); + + Point frameOrigin = gui.frame1.getLocationOnScreen(); + + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.ICONIFIED) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for ICONIFIED state is set... + if (gui.frame1.getExtendedState() != Frame.ICONIFIED) + throw new RuntimeException("The bitwise mask Frame.ICONIFIED is " + + "not set when the frame is in ICONIFIED state"); + + //To check whether the Frame is iconified programmatically.......... + if (! gui.iconify) + throw new RuntimeException("Frame is not Iconified"); + + //Normalising the Frame.... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for NORMAL state is set... + if (gui.frame1.getExtendedState() != Frame.NORMAL) + throw new RuntimeException("The bitwise mask Frame.NORMAL is " + + "not set when the frame is in NORMAL state after Iconofied"); + + //To check whether the Frame is normalised programmatically.......... + if (! gui.normal) + throw new RuntimeException("Frame is not restored to normal after Iconofied"); + + Point newposition = gui.frame1.getLocationOnScreen(); + + if((frameOrigin.x != newposition.x)&(frameOrigin.y != newposition.y)) + throw new RuntimeException("The frame is not positioned back to " + + "the original place on the screen after Iconified"); + + robot.waitForIdle(1000); + + //To check whether the state is supported in the platform.... + if (Toolkit.getDefaultToolkit().isFrameStateSupported( + Frame.MAXIMIZED_HORIZ)){ + //System.out.println("Frame.MAXIMIZED_HORIZ is supported"); + //Maximising the Frame horizontally......... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.MAXIMIZED_HORIZ) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for MAXIMIZED_HORIZ state is set... + if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_HORIZ) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_HOR " + + "is not set when the frame is in MAXIMIZED_HOR state"); + + //To check whether the Frame is maximized horizontally.......... + if (! gui.maxHor) + throw new RuntimeException("Frame is not maximized horizontally"); + + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + } + + //To check whether the state is supported in the platform.... + if (Toolkit.getDefaultToolkit().isFrameStateSupported( + Frame.MAXIMIZED_VERT)){ + //System.out.println("Frame.MAXIMIZED_VERT is supported"); + //Maximising the Frame vertically......... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.MAXIMIZED_VERT) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for MAXIMIZED_VERT state is set... + if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_VERT) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_VERT " + + "is not set when the frame is in MAXIMIZED_VERT state"); + + //To check whether the Frame is maximized vertically.......... + if (! gui.maxVer) + throw new RuntimeException("Frame is not maximized vertically"); + + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + } + + robot.waitForIdle(1000); + + if (Toolkit.getDefaultToolkit().isFrameStateSupported + (Frame.MAXIMIZED_BOTH)){ + //Maximising the Frame fully......... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.MAXIMIZED_BOTH) + ); + }; + robot.waitForIdle(1000); + + //To check whether the state is supported in the platform.... + if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)){ + //To check whether the bitwise mask for MAXIMIZED_BOTH state is set... + if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_BOTH) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " + + "is not set when the frame is in MAXIMIZED_BOTH state"); + + //To check whether the Frame is maximized fully.......... + if (! gui.maxBoth) + throw new RuntimeException("Frame is not maximized fully"); + } + + //Normalising the Frame.... + EventQueue.invokeAndWait(() -> + gui.frame1.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for NORMAL state is set... + if (gui.frame1.getExtendedState() != Frame.NORMAL) + throw new RuntimeException("The bitwise mask Frame.NORMAL is not " + + "set when the frame is in NORMAL state after Zoomed"); + + //To check whether the Frame is normalised programmatically.......... + if (! gui.normal) + throw new RuntimeException("Frame is not restored to normal after Zoomed"); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TaskZoomUndFrameRepaint.java 2014-07-31 17:28:01.910614776 +0400 @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +import java.awt.*; + +/* + * @test + * @summary Construct a Undecorated frame with some components and zoom + * the frame and bring it back to normal state. + * @author Aruna Samji + * @library ../../../lib/testlibrary + * @build ExtendedRobot + * @run main TaskZoomUndFrameRepaint + */ + +public class TaskZoomUndFrameRepaint extends Task { + + public static void main (String[] args) throws Exception { + new TaskZoomUndFrameRepaint(GUIZoomFrame.class, new ExtendedRobot()).runTask(); + } + + TaskZoomUndFrameRepaint(Class guiClass, ExtendedRobot robot) throws Exception { + super(guiClass, robot); + } + + public void task() throws Exception { + EventQueue.invokeAndWait(() -> { + gui.frame2.setUndecorated(true); + gui.frame2.setVisible(true); + gui.frame2.removeAll(); + gui.frame2.add(gui.button); + gui.frame2.add(gui.textarea); + if (gui.frame2.getExtendedState() != Frame.NORMAL) + gui.frame2.setExtendedState(Frame.NORMAL); + }); + robot.waitForIdle(1000); + + Point buttonOrigin, newbuttonOrigin, buttonCenter; + Point textareaOrigin, newtextareaOrigin, textareaCenter; + + //to find the lenght and width of the component originally + buttonOrigin = gui.button.getLocationOnScreen(); + textareaOrigin = gui.textarea.getLocationOnScreen(); + buttonCenter = gui.button.getLocationOnScreen(); + buttonCenter.translate(gui.button.getWidth()/2, gui.button.getHeight()/2); + textareaCenter = gui.textarea.getLocationOnScreen(); + textareaCenter.translate(gui.textarea.getWidth()/2, gui.textarea.getHeight()/2); + + if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)){ + //Maximising the Frame fully......... + EventQueue.invokeAndWait(() -> + gui.frame2.setExtendedState(Frame.MAXIMIZED_BOTH) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for MAXIMIZED_BOTH state is set... + if (gui.frame2.getExtendedState() != Frame.MAXIMIZED_BOTH) + throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " + + "is not set when the frame is in MAXIMIZED_BOTH state"); + + //To check whether the Frame is maximized fully.......... + if (gui.maxBoth == false) + throw new RuntimeException("Frame is not maximized fully"); + } + + //Normalising the Frame.... + EventQueue.invokeAndWait(() -> + gui.frame2.setExtendedState(Frame.NORMAL) + ); + robot.waitForIdle(1000); + + //To check whether the bitwise mask for NORMAL state is set... + if (gui.frame2.getExtendedState() != Frame.NORMAL) + throw new RuntimeException("The bitwise mask Frame.NORMAL is not set" + + " when the frame is in NORMAL state"); + + //To check whether the Frame is normalised programmatically.......... + if (! gui.normal) + throw new RuntimeException("Frame is not restored to normal"); + + //to find the lenght and width of the component after zommed and back to normal + newbuttonOrigin = gui.button.getLocationOnScreen(); + newtextareaOrigin = gui.textarea.getLocationOnScreen(); + + if((buttonOrigin.x != newbuttonOrigin.x)&(buttonOrigin.y != newbuttonOrigin.y)) + throw new RuntimeException("The button is not positioned back to " + + "the original place on the screen after iconified"); + + if((textareaOrigin.x != newtextareaOrigin.x)&(textareaOrigin.y != newtextareaOrigin.y)) + throw new RuntimeException("The TextArea is not positioned back to " + + "the original place on the screen after iconified"); + + EventQueue.invokeAndWait(() -> { + gui.frame2.remove(gui.button); + gui.frame2.remove(gui.textarea); + }); + robot.waitForIdle(1000); + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/TempImage.java 2014-07-31 17:28:02.470614753 +0400 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014, 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. + */ + +import java.awt.*; +import java.awt.image.BufferedImage; + +/* + * @summary Temporary buffered image for tests + * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com) + */ + +public class TempImage extends BufferedImage { + + public TempImage(int width, int height, int imageType) { + super(width, width, imageType); + Graphics2D g = (Graphics2D) getGraphics(); + g.setColor(Color.WHITE); + g.fillRect(0, 0, getWidth(), getHeight()); + char direction = 'r'; + int thickness = 10; + int lineLength = getWidth(); + Point currPos = new Point(0,0); + g.setColor(Color.RED); + while (lineLength > 0) { + lineLength -= thickness; + switch (direction) { + case 'r' : + g.fillRect(currPos.x, currPos.y, lineLength, thickness); + currPos.translate(lineLength - thickness, thickness); + direction = 'd'; + break; + case 'd' : + g.fillRect(currPos.x, currPos.y, thickness, lineLength); + currPos.translate(0, lineLength - thickness); + direction = 'l'; + break; + case 'l' : + g.fillRect(currPos.x-lineLength, currPos.y, lineLength, thickness); + currPos.translate(-lineLength, 0); + direction = 'u'; + break; + case 'u' : + g.fillRect(currPos.x, currPos.y-lineLength, thickness, lineLength); + currPos.translate(thickness, -lineLength); + direction = 'r'; + break; + } + } + } +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/gtk-embedder.c 2014-07-31 17:28:03.030614731 +0400 @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +/* + * @summary Native window for TaskXEmbedListeners and TaskXEmbedMemory. + */ + +#include + +#include +#include +#include + +int n_children = 0; + +GSList *sockets = NULL; + +GtkWidget *window; +GtkWidget *vbox; + +typedef struct { + GtkWidget *box; + GtkWidget *frame; + GtkWidget *socket; +} Socket; + +static void quit_cb (gpointer callback_data, guint callback_action, GtkWidget *widget) { + GtkWidget *message_dialog = gtk_message_dialog_new (GTK_WINDOW (window), 0, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "Really Quit?"); + gtk_dialog_add_buttons (GTK_DIALOG (message_dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_QUIT, GTK_RESPONSE_YES, + NULL); + + gtk_dialog_set_default_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_YES); + + if (gtk_dialog_run (GTK_DIALOG (message_dialog)) == GTK_RESPONSE_YES) + gtk_widget_destroy (window); + + gtk_widget_destroy (message_dialog); +} + +static void socket_destroyed (GtkWidget *widget, Socket *socket) { + sockets = g_slist_remove (sockets, socket); + g_free (socket); +} + +static void plug_added (GtkWidget *widget, Socket *socket) { + g_print ("Plug added to socket\n"); + + gtk_widget_show (socket->socket); + gtk_widget_hide (socket->frame); +} + +static gboolean plug_removed (GtkWidget *widget, Socket *socket) { + g_print ("Plug removed from socket\n"); + + gtk_widget_hide (socket->socket); + gtk_widget_show (socket->frame); + + return TRUE; +} + +static Socket * create_socket (void) { + GtkWidget *label; + + Socket *socket = g_new (Socket, 1); + + socket->box = gtk_vbox_new (FALSE, 0); + + socket->socket = gtk_socket_new (); + + gtk_box_pack_start (GTK_BOX (socket->box), socket->socket, TRUE, TRUE, 0); + + socket->frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (socket->frame), GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (socket->box), socket->frame, TRUE, TRUE, 0); + gtk_widget_show (socket->frame); + + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), "Empty"); + gtk_container_add (GTK_CONTAINER (socket->frame), label); + gtk_widget_show (label); + + sockets = g_slist_prepend (sockets, socket); + + + g_signal_connect (G_OBJECT (socket->socket), "destroy", + G_CALLBACK (socket_destroyed), socket); + g_signal_connect (G_OBJECT (socket->socket), "plug_added", + G_CALLBACK (plug_added), socket); + g_signal_connect (G_OBJECT (socket->socket), "plug_removed", + G_CALLBACK (plug_removed), socket); + + return socket; +} + +void remove_child (void) { + if (sockets) { + Socket *socket = sockets->data; + gtk_widget_destroy (socket->box); + } +} + +static gboolean +child_read_watch (GIOChannel *channel, GIOCondition cond, gpointer data) +{ + GIOStatus status; + GError *error = NULL; + char *line; + gsize term; + int xid; + + status = g_io_channel_read_line (channel, &line, NULL, &term, &error); + switch (status) { + case G_IO_STATUS_NORMAL: + line[term] = '\0'; + xid = strtol (line, NULL, 0); + if (xid == 0) { + fprintf (stderr, "Invalid window id '%s'\n", line); + } else { + Socket *socket = create_socket (); + gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0); + gtk_widget_show (socket->box); + + gtk_socket_add_id (GTK_SOCKET (socket->socket), xid); + } + g_free (line); + return TRUE; + case G_IO_STATUS_AGAIN: + return TRUE; + case G_IO_STATUS_EOF: + n_children--; + g_io_channel_shutdown (channel, FALSE, NULL); + return FALSE; + case G_IO_STATUS_ERROR: + fprintf (stderr, "Error reading fd from child: %s\n", error->message); + exit (1); + return FALSE; + default: + g_assert_not_reached (); + return FALSE; + } +} + +int main (int argc, char *argv[]) { + GtkWidget *hbox; + Socket *socket; + char buffer[20]; + FILE *idFile; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_set_size_request (window, 300, 300); + gtk_widget_set_uposition (window, 100, 100); + g_signal_connect (window, "destroy", + G_CALLBACK (gtk_main_quit), NULL); + + gtk_window_set_title (GTK_WINDOW (window), "XEmbed Test"); + + + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + vbox = gtk_vbox_new (FALSE, 0); + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + + gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + socket = create_socket (); + gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0); + sprintf(buffer, "%#lx", (gulong) gtk_socket_get_id (GTK_SOCKET (socket->socket))); + idFile = fopen("window_id", "w"); + if (idFile != NULL) { + fprintf(idFile, "%s", buffer); + fclose(idFile); + } else { + exit(1); + } + + gtk_widget_show_all (window); + gtk_main (); + + if (n_children) { + g_print ("Waiting for children to exit\n"); + while (n_children) + g_main_context_iteration (NULL, TRUE); + } + + return 0; +} --- /dev/null 2014-07-31 16:13:19.122792434 +0400 +++ new/test/java/awt/reliability/xdnd-child.c 2014-07-31 17:28:03.558614710 +0400 @@ -0,0 +1,903 @@ +/* + * Copyright (c) 2004, 2014, 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. + */ + +/* + * @summary Native window for TaskXDragDrop. This is taken from + * XDnD Tiger AWT testsuite. + * @author Aruna Samji (aruna.samji@sun.com) + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +//#define TRACE + +/* XDnD atom names */ +static const char* XAtomName_XdndActionCopy = "XdndActionCopy"; +static const char* XAtomName_XdndAware = "XdndAware"; +static const char* XAtomName_XdndDrop = "XdndDrop"; +static const char* XAtomName_XdndEnter = "XdndEnter"; +static const char* XAtomName_XdndFinished = "XdndFinished"; +static const char* XAtomName_XdndLeave = "XdndLeave"; +static const char* XAtomName_XdndPosition = "XdndPosition"; +static const char* XAtomName_XdndProxy = "XdndProxy"; +static const char* XAtomName_XdndSelection = "XdndSelection"; +static const char* XAtomName_XdndStatus = "XdndStatus"; + +static const char* XAtomName_XdndActionMove = "XdndActionMove"; +static const char* XAtomName_XdndActionLink = "XdndActionLink"; + +static const char* XAtomName_TextPlain = "text/plain"; + +/* XDnD atoms */ +static Atom _XA_XdndActionCopy = None; +static Atom _XA_XdndAware = None; +static Atom _XA_XdndDrop = None; +static Atom _XA_XdndEnter = None; +static Atom _XA_XdndFinished = None; +static Atom _XA_XdndLeave = None; +static Atom _XA_XdndPosition = None; +static Atom _XA_XdndProxy = None; +static Atom _XA_XdndSelection = None; +static Atom _XA_XdndStatus = None; +static Atom _XA_TextPlain = None; + +static Atom _XA_XdndActionMove = None; +static Atom _XA_XdndActionLink = None; + +/* XDnD constants */ +static const Atom XDnDVersion = 4; +static const unsigned int DND_VERSION_SHIFT = 24; +static const unsigned int ACCEPT_DROP_FLAG = 1; + +/* shared constants */ +static const EventMask DRAG_MASK = ButtonMotionMask | PointerMotionMask | + KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask; + +/* shared function prototypes */ +static void init(); +static void remove_dnd_grab(Display* dpy, Time time); +static void cleanup_drag(Display* dpy); +static void register_drag_source(Widget widget); + +/* XDnD support */ +static Boolean intern_xdnd_atoms(Display* dpy); +static void update_dnd_version(int version); +static int get_dnd_version(); +static void set_same_answer(int x, int y, int w, int h); +static Boolean is_same_answer(int x, int y); +static Boolean register_xdnd_drop_target(Widget widget); + +/* shared state variables */ +static Boolean drag_in_progress = False; + +static Window target_win = None; +static Window target_proxy_win = None; + +static char* drop_data = NULL; + +int main(int argc, char **argv) { + XtAppContext app; + Widget widget = XtAppInitialize (&app, "XDnD_main", + NULL, 0, + &argc, argv, + NULL, NULL, 0); + + XtVaSetValues(widget, XtNx, 550, XtNy, 220, + XtNwidth, 200, XtNheight, 150, NULL); + XtRealizeWidget(widget); + + init(); + intern_xdnd_atoms(XtDisplay(widget)); + + register_drag_source(widget); + register_xdnd_drop_target(widget); + + XSetSelectionOwner(XtDisplay(widget), XA_PRIMARY, None, CurrentTime); + +#ifdef DEBUG + fprintf(stderr,"Root=%X\n", XRootWindowOfScreen(XtScreen(widget))); +#endif + for (;;) { + XEvent event; + Window root_win = XRootWindowOfScreen(XtScreen(widget)); + XtAppNextEvent(app, &event); +#ifdef DEBUG + fprintf(stderr,"Event type=%d win=%X\n", event.type, event.xany.window); + if (event.type == MotionNotify) { + fprintf(stderr," subwin=%X\n", event.xmotion.subwindow); + } +#endif + if (drag_in_progress && event.xany.window == root_win) { + switch (event.type) { + case ButtonPress: + case ButtonRelease: + case MotionNotify: + case EnterNotify: + case LeaveNotify: + { + Window child; + XTranslateCoordinates(XtDisplay(widget), root_win, + XtWindow(widget), + event.xbutton.x, event.xbutton.y, + &event.xbutton.x, &event.xbutton.y, + &child); + } + case KeyPress: + case KeyRelease: + event.xany.window = XtWindow(widget); + } + } + XtDispatchEvent(&event); + } + + return 0; +} + +static Boolean bad_window = False; +static int (*original_x_errhandler)(Display* dpy, XErrorEvent*); + +static int x_errhandler(Display *dpy, XErrorEvent *err) { + if (err->error_code == BadWindow) { + bad_window = True; + } + + { + char errstr[256]; + XGetErrorText( dpy, err->error_code, errstr, 256 ); + fprintf(stderr, "Error: %s %d\n Major opcode: %d\n Resource id: 0x%lx\n", + errstr, err->error_code, err->request_code, err->resourceid); + } + return 0; +} + +static void init() { + original_x_errhandler = XSetErrorHandler(x_errhandler); +} + +static Boolean intern_xdnd_atoms(Display* dpy) { + _XA_XdndActionCopy = XInternAtom(dpy, XAtomName_XdndActionCopy, False); + if (_XA_XdndActionCopy == None) { + return False; + } + + _XA_XdndActionMove = XInternAtom(dpy, XAtomName_XdndActionMove, False); + if (_XA_XdndActionMove == None) { + return False; + } + + _XA_XdndActionLink = XInternAtom(dpy, XAtomName_XdndActionLink, False); + if (_XA_XdndActionLink == None) { + return False; + } + + _XA_XdndAware = XInternAtom(dpy, XAtomName_XdndAware, False); + if (_XA_XdndAware == None) { + return False; + } + + _XA_XdndDrop = XInternAtom(dpy, XAtomName_XdndDrop, False); + if (_XA_XdndDrop == None) { + return False; + } + + _XA_XdndEnter = XInternAtom(dpy, XAtomName_XdndEnter, False); + if (_XA_XdndEnter == None) { + return False; + } + + _XA_XdndFinished = XInternAtom(dpy, XAtomName_XdndFinished, False); + if (_XA_XdndFinished == None) { + return False; + } + + _XA_XdndLeave = XInternAtom(dpy, XAtomName_XdndLeave, False); + if (_XA_XdndLeave == None) { + return False; + } + + _XA_XdndPosition = XInternAtom(dpy, XAtomName_XdndPosition, False); + if (_XA_XdndPosition == None) { + return False; + } + + _XA_XdndProxy = XInternAtom(dpy, XAtomName_XdndProxy, False); + if (_XA_XdndProxy == None) { + return False; + } + + _XA_XdndSelection = XInternAtom(dpy, XAtomName_XdndSelection, False); + if (_XA_XdndSelection == None) { + return False; + } + + _XA_XdndStatus = XInternAtom(dpy, XAtomName_XdndStatus, False); + if (_XA_XdndStatus == None) { + return False; + } + + _XA_TextPlain = XInternAtom(dpy, XAtomName_TextPlain, False); + if (_XA_TextPlain == None) { + return False; + } + + return True; +} + +/******************************* Drag source support **************************/ + +static Boolean +xdnd_convert_proc(Widget w, Atom * selection, Atom * target, Atom * type, + XtPointer * value, unsigned long *length, int32_t *format) { + +#ifdef DEBUG + fprintf(stderr,"xdnd_convert_proc\n"); +#endif + if (*target == _XA_TextPlain) { + char* str = drop_data; + int len = strlen(str); + + char* copy = (char*)XtMalloc(len); + strcpy(copy, str); + + *type = *target; + *value = (XtPointer)copy; + *length = len; + *format = 8; + + return True; + } + return False; +} + +static Window find_receiver_window(Widget wid, int x, int y) { + Display* dpy = XtDisplay(wid); + Atom type; + int format; + unsigned long nitems; + unsigned long after; + unsigned char *data; + + Window src_w = XtWindow(wid); + Window dest_w = XRootWindowOfScreen(XtScreen(wid)); + Window ret_w = None; + Window child_w = None; + int src_x = x; + int src_y = y; + + while (dest_w != None) { + XTranslateCoordinates(dpy, src_w, dest_w, + src_x, src_y, &src_x, &src_y, &child_w); + + if (child_w == None) { + break; + } + + src_w = dest_w; + dest_w = child_w; + + type = None; + XGetWindowProperty(dpy, dest_w, _XA_XdndAware, 0, 1, False, + AnyPropertyType, &type, &format, &nitems, + &after, &data); + + if (type == XA_ATOM && data != NULL) { + ret_w = dest_w; + } + + XFree(data); + data = NULL; + } + + return ret_w; +} + +static void update_receiver_window(Display* dpy, Window win) { + Atom type; + int format; + unsigned long nitems; + unsigned long after; + unsigned char *data; + + if (win == None) { + target_win = None; + target_proxy_win = None; + return; + } + + XGetWindowProperty(dpy, win, _XA_XdndAware, 0, 1, False, + AnyPropertyType, &type, &format, &nitems, + &after, &data); + + if (type == XA_ATOM && data != NULL) { + Window proxy_win = None; + int target_version = *((int*)data); + update_dnd_version(target_version); + + XFree(data); + + XGetWindowProperty(dpy, win, _XA_XdndProxy, 0, 1, False, + XA_WINDOW, &type, &format, &nitems, &after, &data); + + if (type == XA_WINDOW && data != None) { + proxy_win = *((Window*)data); + XFree(data); + + XGetWindowProperty(dpy, proxy_win, _XA_XdndProxy, 0, 1, False, + XA_WINDOW, &type, &format, &nitems, &after, &data); + + if (type != XA_WINDOW || data == NULL || + *((Window*)data) != proxy_win) { + proxy_win = None; + } + + XFree(data); + + if (proxy_win == None) { + proxy_win = win; + } + } + + target_win = win; + target_proxy_win = proxy_win; + } else { + XFree(data); + } + + if (target_proxy_win == None) { + target_proxy_win = target_win; + } + + { + XWindowAttributes xwa; + + XGetWindowAttributes(dpy, win, &xwa); + XSelectInput(dpy, win, + xwa.your_event_mask | EnterWindowMask | LeaveWindowMask); + } +} + +static void xdnd_send_enter(Display* dpy, Window source_win, XMotionEvent* event) { + XClientMessageEvent enter; + + enter.type = ClientMessage; + enter.window = target_win; + enter.format = 32; + enter.message_type = _XA_XdndEnter; + enter.data.l[0] = source_win; + enter.data.l[1] = get_dnd_version() << DND_VERSION_SHIFT; + enter.data.l[2] = _XA_TextPlain; + enter.data.l[3] = 0; + enter.data.l[4] = 0; + + set_same_answer(event->x_root - 1, + event->y_root - 1, 3, 3); + +#ifdef DEBUG + fprintf(stderr,"xdnd_send_enter win=%X\n", target_proxy_win); +#endif + XSendEvent(dpy, target_proxy_win, False, NoEventMask, + (XEvent*)&enter); +} + +static void +send_enter(Display* dpy, Window source_win, XMotionEvent* event) { + xdnd_send_enter(dpy, source_win, event); +} + + +static void +xdnd_send_leave(Display* dpy, Window source_win, XMotionEvent* event) { + XClientMessageEvent leave; + + leave.type = ClientMessage; + leave.window = target_win; + leave.format = 32; + leave.message_type = _XA_XdndLeave; + leave.data.l[0] = source_win; + leave.data.l[1] = 0; + leave.data.l[2] = 0; + leave.data.l[3] = 0; + leave.data.l[4] = 0; + +#ifdef DEBUG + fprintf(stderr,"xdnd_send_leave win=%X\n", target_proxy_win); +#endif + XSendEvent(dpy, target_proxy_win, False, NoEventMask, + (XEvent*)&leave); +} + +static void +send_leave(Display* dpy, Window source_win, XMotionEvent* event) { + xdnd_send_leave(dpy, source_win, event); +} + +static void +xdnd_send_move(Display* dpy, Window source_win, XMotionEvent* event) { + XClientMessageEvent move; + + move.type = ClientMessage; + move.window = target_win; + move.format = 32; + move.message_type = _XA_XdndPosition; + move.data.l[0] = source_win; + move.data.l[1] = 0; /* flags */ + move.data.l[2] = event->x_root << 16 | event->y_root; + move.data.l[3] = event->time; + /*move.data.l[4] = _XA_XdndActionCopy;*/ + move.data.l[4] = _XA_XdndActionMove; + + if (event != NULL) { + switch (event->state & (ShiftMask | ControlMask)) { + case 0 : move.data.l[4] = _XA_XdndActionCopy; break; + case ShiftMask : move.data.l[4] = _XA_XdndActionMove; break; + case ControlMask : move.data.l[4] = _XA_XdndActionCopy; break; + case (ShiftMask | ControlMask) : move.data.l[4] = _XA_XdndActionLink; break; + } + } + +#ifdef DEBUG + fprintf(stderr,"xdnd_send_move win=%X\n", target_proxy_win); +#endif + XSendEvent(dpy, target_proxy_win, False, NoEventMask, + (XEvent*)&move); +} + +static void send_move(Display* dpy, Window source_win, XMotionEvent* event) { + xdnd_send_move(dpy, source_win, event); +} + +static void handle_move(Widget w, XMotionEvent* event) { + Display* dpy = XtDisplay(w); + Window source_win = XtWindow(w); + Window receiver_win = None; + int flags = 2 | 3 << 4 | 2 << 8; + + receiver_win = find_receiver_window(w, event->x, event->y); +#ifdef DEBUG + fprintf(stderr,"handle_move receiver=%X\n", receiver_win); + fprintf(stderr," target=%X proxy=%X\n", target_win, target_proxy_win); +#endif + + if (target_win != receiver_win) { + if (target_win != None) { + send_leave(dpy, source_win, event); + } + + update_receiver_window(dpy, receiver_win); + + if (target_win != None) { + send_enter(dpy, source_win, event); + } + } + + if (target_win != None) { + send_move(dpy, source_win, event); + } +} + +static void handle_xdnd_status(Widget w, XClientMessageEvent* event) { +#ifdef TRACE + fprintf(stderr,"[Source] dragOver {XDnD}\n"); +#endif + +#ifdef DEBUG + fprintf(stderr,"handle_xdnd_status\n"); +#endif +} + +static void +handle_xdnd_finished(Widget w, XClientMessageEvent* event) { +#ifdef TRACE + fprintf(stderr,"[Source] dragDropEnd {XDnD}\n"); +#endif + +#ifdef DEBUG + fprintf(stderr,"handle_xdnd_finished\n"); +#endif + cleanup_drag(XtDisplay(w)); + fprintf(stderr,"finished\n"); + //exit(0); +} + +static void +xdnd_handle_client_message(Widget w, XClientMessageEvent* event) { + if (event->message_type == _XA_XdndStatus) { + handle_xdnd_status(w, event); + } else if (event->message_type == _XA_XdndFinished) { + handle_xdnd_finished(w, event); + } +} + +static void +handle_client_message(Widget w, XClientMessageEvent* event) { + xdnd_handle_client_message(w, event); +} + +static void +xdnd_send_drop(Display* dpy, Window source_win, XButtonEvent* event) { + XClientMessageEvent drop; + drop.type = ClientMessage; + drop.window = target_win; + drop.format = 32; + drop.message_type = _XA_XdndDrop; + drop.data.l[0] = source_win; + drop.data.l[1] = 1 << 24; /* flags */ + drop.data.l[2] = 0; /* ### */ + drop.data.l[3] = event->time; + drop.data.l[4] = 0; + + XSendEvent(dpy, target_proxy_win, False, NoEventMask, (XEvent*)&drop); +} + +static void +send_drop(Display* dpy, Window source_win, XButtonEvent* event) { + xdnd_send_drop(dpy, source_win, event); +} + +static void +drag_event_handler(Widget w, XtPointer client_data, + XEvent * event, Boolean * cont) { +#ifdef DEBUG + fprintf(stderr,"drag_event_handler type=%d in_progress=%X\n", event->type, drag_in_progress); +#endif + + if (!drag_in_progress) { + XtRemoveEventHandler(w, DRAG_MASK, False, drag_event_handler, NULL); + return; + } + + switch (event->type) { + case KeyRelease: { + KeySym keysym = XKeycodeToKeysym(XtDisplay(w), event->xkey.keycode, 0); + #ifdef DEBUG + fprintf(stderr,"\tKeyRelease code=%X sym=%X\n", event->xkey.keycode); + #endif + if (keysym == XK_Escape) { + remove_dnd_grab(XtDisplay(w), event->xkey.time); + cleanup_drag(XtDisplay(w)); + } + *cont = False; + break; + } + case KeyPress: + case ButtonPress: + break; + case MotionNotify: { + handle_move(w, (XMotionEvent*)event); + break; + } + case ButtonRelease: + #ifdef DEBUG + fprintf(stderr,"\tButtonRelease button=%d\n", event->xbutton.button); + #endif + if (event->xbutton.button == Button1) { + remove_dnd_grab(XtDisplay(w), event->xbutton.time); + if (target_win != None) { + send_drop(XtDisplay(w), XtWindow(w), &event->xbutton); + #ifdef DEBUG + fprintf(stderr,"DROP_START sent\n"); + #endif + } else { + cleanup_drag(XtDisplay(w)); + } + *cont = True; + } else { + *cont = False; + } + break; + case ClientMessage: + handle_client_message(w, &event->xclient); + break; + } +} + +static void initiate_drag(Widget w, XEvent* event) { + Display* dpy = XtDisplay(w); + int num_targets = 1; + Atom target = XA_STRING; + int index = -1; + unsigned int event_mask = + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask; + unsigned int root_event_mask = + ButtonMotionMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask; + + if (XtOwnSelection(w, _XA_XdndSelection, event->xmotion.time, + xdnd_convert_proc, NULL, NULL) != True) { +#ifdef DEBUG + fprintf(stderr,"initiate_drag: cannot own selection\n"); +#endif + return; + } + + { + Window root_win = RootWindowOfScreen(XtScreen(w)); + XWindowAttributes xwa; + Cursor cursor = XCreateFontCursor(dpy, XC_hand2); + + XGetWindowAttributes(dpy, root_win, &xwa); + XSelectInput(dpy, root_win, xwa.your_event_mask | root_event_mask); + + if (XGrabPointer(dpy, root_win, + True, + event_mask, + GrabModeSync, + GrabModeAsync, + None, + cursor, + event->xmotion.time) != GrabSuccess) { + #ifdef DEBUG + fprintf(stderr,"initiate_drag: XGrabPointer fails\n"); + #endif + return; + } + + if (XGrabKeyboard(dpy, root_win, + False, + GrabModeSync, + GrabModeAsync, + event->xmotion.time) != GrabSuccess) { + #ifdef DEBUG + fprintf(stderr,"initiate_drag: XGrabKeyboard fails\n"); + #endif + return; + } + XAllowEvents(dpy, SyncPointer, event->xmotion.time); + } + XtInsertEventHandler(w, DRAG_MASK, + True, drag_event_handler, NULL, XtListHead); +} + +static void +drag_gesture_recognizer(Widget w, XtPointer client_data, + XEvent * event, Boolean * cont) { +#ifdef DEBUG + fprintf(stderr,"drag_gesture_recognizer: type=%d\n", event->type); +#endif + if (event->type != MotionNotify) { + return; + } + + if (drag_in_progress) { +#ifdef DEBUG + fprintf(stderr,"initiate_drag: in progress\n"); +#endif + return; + } + +#ifdef DEBUG + fprintf(stderr,"drag_gesture_recognizer: start\n"); +#endif + initiate_drag(w, event); + drag_in_progress = True; +} + +static void register_drag_source(Widget w) { +#ifdef DEBUG + fprintf(stderr,"register_drag_source: w=%X\n", w); +#endif + XtAddEventHandler(w, ButtonMotionMask | ButtonPressMask, + False, drag_gesture_recognizer, (XtPointer)NULL); +} + +static void remove_dnd_grab(Display* dpy, Time time) { + XUngrabPointer(dpy, time); + XUngrabKeyboard(dpy, time); +} + +static void cleanup_drag(Display* dpy) { +#ifdef DEBUG + fprintf(stderr,"cleanup_drag\n"); +#endif + + drag_in_progress = False; + target_win = None; + target_proxy_win = None; +} + +/* XDnD state variables */ +static int dnd_version = 0; + +static int same_x = 0; +static int same_y = 0; +static int same_w = 0; +static int same_h = 0; + +static void set_same_answer(int x, int y, int w, int h) { + same_x = x; + same_y = y; + same_w = w; + same_h = h; +} + +static Boolean is_same_answer(int x, int y) { + if (!drag_in_progress) { + return False; + } + + if (x >= same_x && x < same_x + same_w && + y >= same_y && y < same_y + same_h) { + return True; + } + + return False; +} + +static void update_dnd_version(int version) { + dnd_version = XDnDVersion < version ? XDnDVersion : version; +} + +static int get_dnd_version() { + return dnd_version; +} + +/******************************* Drop target support **************************/ + +static void handle_xdnd_enter(Widget w, XEvent* event) { +#ifdef TRACE + fprintf(stderr,"[Target] dragEnter {XDnD}\n"); +#endif + +#ifdef DEBUG + fprintf(stderr,"handle_xdnd_enter\n"); +#endif +} + +static void handle_xdnd_leave(Widget w, XEvent* event) { +#ifdef TRACE + fprintf(stderr,"[Target] dragExit {XDnD}\n"); +#endif +#ifdef DEBUG + fprintf(stderr,"handle_xdnd_leave\n"); +#endif +} + +static void handle_xdnd_position(Widget w, XEvent* event) { + Window drag_source = event->xclient.data.l[0]; + XClientMessageEvent response; + response.type = ClientMessage; + response.window = drag_source; + response.format = 32; + response.message_type = _XA_XdndStatus; + response.data.l[0] = XtWindow(w); + response.data.l[1] = 0; /* flags */ + response.data.l[2] = 0; /* x, y */ + response.data.l[3] = 0; /* w, h */ + response.data.l[4] = 0; /* action */ + + response.data.l[1] |= ACCEPT_DROP_FLAG; + /*response.data.l[4] = _XA_XdndActionCopy;*/ + response.data.l[4] = _XA_XdndActionMove; + +#ifdef TRACE + fprintf(stderr,"[Target] dragOver {XDnD}\n"); +#endif +#ifdef DEBUG + fprintf(stderr,"handle_xdnd_position win=%ld\n", event->xclient.data.l[0]); +#endif + XSendEvent(XtDisplay(w), drag_source, False, + NoEventMask, (XEvent*)&response); +} + +static void +selection_callback_proc(Widget w, XtPointer client_data, Atom* selection, + Atom* type, XtPointer value, unsigned long* length, + int* format) { + + if (*type == _XA_TextPlain) { +#ifdef DEBUG + fprintf(stderr,"selection_callback_proc data=%s\n", (char*)value); +#endif +#ifdef TRACE + fprintf(stderr,"[Target] drop {XDnD} data=%s\n", (char*)value); +#endif + } + + if (value != NULL && *length != 0) { + drop_data = calloc(1, 2*(*length)); + strcpy(drop_data, (char*)value); + strcpy(drop_data + (*length), (char*)value); +#ifdef TRACE + fprintf(stderr,"[Target] drag data=%s\n", drop_data); +#endif + } + + if (value != NULL) { + XtFree((char*)value); + } +} + +static void handle_xdnd_drop(Widget w, XEvent* event) { +#ifdef TRACE + fprintf(stderr,"[Target] drop {XDnD}\n"); +#endif + XtGetSelectionValue(w, _XA_XdndSelection, _XA_TextPlain, + selection_callback_proc, NULL, + XtLastTimestampProcessed(XtDisplay(w))); +#ifdef DEBUG + fprintf(stderr,"handle_xdnd_drop\n"); +#endif + { + Window drag_source = event->xclient.data.l[0]; + XClientMessageEvent finished; + finished.type = ClientMessage; + finished.window = drag_source; + finished.format = 32; + finished.message_type = _XA_XdndFinished; + finished.data.l[0] = XtWindow(w); + finished.data.l[1] = 0; /* flags */ + XSendEvent(XtDisplay(w), drag_source, False, + NoEventMask, (XEvent*)&finished); + } +} + +static void +target_client_message_handler(Widget w, XtPointer client_data, + XEvent* event, Boolean* cont) { +#ifdef DEBUG + fprintf(stderr,"target_client_message_handler\n"); +#endif + + if (event->type != ClientMessage) { + return; + } + + if (event->xclient.message_type == _XA_XdndEnter) { + handle_xdnd_enter(w, event); + } else if (event->xclient.message_type == _XA_XdndPosition) { + handle_xdnd_position(w, event); + } else if (event->xclient.message_type == _XA_XdndLeave) { + handle_xdnd_leave(w, event); + } else if (event->xclient.message_type == _XA_XdndDrop) { + handle_xdnd_drop(w, event); + } +} + +static Boolean register_xdnd_drop_target(Widget widget) { + Widget w = NULL; + + for (w = widget; w != NULL && !XtIsShell(w); w = XtParent(w)); + + if (w == NULL || XtWindow(w) == None) { + return False; + } + +#ifdef DEBUG + fprintf(stderr,"register_xdnd_drop_target win=%X\n", XtWindow(w)); +#endif + XChangeProperty(XtDisplay(w), XtWindow(w), + _XA_XdndAware, XA_ATOM, 32, + PropModeReplace, + (unsigned char*)&XDnDVersion, 1); + + XtAddEventHandler(w, EnterWindowMask | LeaveWindowMask, + True, target_client_message_handler, NULL); +} +/*************************** End drop target support **************************/