test/java/awt/dnd/DragSourceListenerSerializationTest/DragSourceListenerSerializationTest.java

Print this page




  57 import java.util.stream.Collectors;
  58 import java.util.stream.Stream;
  59 
  60 import static jdk.testlibrary.Asserts.assertEquals;
  61 
  62 public class DragSourceListenerSerializationTest {
  63     public static void main(String[] args) throws Exception {
  64         DragSource ds = new DragSource();
  65         TestDragSourceAdapter dsa1 = new TestDragSourceAdapter(1);
  66         TestDragSourceAdapter dsa2 = new TestDragSourceAdapter(2);
  67         Component c = new Button();
  68         DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(c,
  69                 DnDConstants.ACTION_COPY,
  70                 e -> e.startDrag(null, null));
  71         MouseEvent me = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, 0,
  72                 InputEvent.CTRL_MASK, 100, 100, 0, false);
  73         DragGestureEvent dge = new DragGestureEvent(dgr, DnDConstants.ACTION_COPY,
  74                 new Point(100, 100),
  75                 Arrays.asList(me));
  76         DragSourceContext dsc = new DragSourceContext(
  77                 Toolkit.getDefaultToolkit().createDragSourceContextPeer(dge),
  78                 dge,
  79                 new Cursor(Cursor.HAND_CURSOR),
  80                 null, null, new StringSelection("TEXT"), null);
  81 
  82         ds.addDragSourceListener(dsa1);
  83         ds.addDragSourceListener(dsa2);
  84         ds.addDragSourceListener(dsa2);
  85         ds.addDragSourceMotionListener(dsa1);
  86         ds.addDragSourceMotionListener(dsa1);
  87         ds.addDragSourceMotionListener(dsa2);
  88         dsc.addDragSourceListener(dsa2);
  89 
  90         byte[] serialized;
  91         try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
  92              ObjectOutputStream oos = new ObjectOutputStream(bos)) {
  93             oos.writeObject(dsc);
  94             serialized = bos.toByteArray();
  95         }
  96 
  97         DragSourceContext dsc_copy;




  57 import java.util.stream.Collectors;
  58 import java.util.stream.Stream;
  59 
  60 import static jdk.testlibrary.Asserts.assertEquals;
  61 
  62 public class DragSourceListenerSerializationTest {
  63     public static void main(String[] args) throws Exception {
  64         DragSource ds = new DragSource();
  65         TestDragSourceAdapter dsa1 = new TestDragSourceAdapter(1);
  66         TestDragSourceAdapter dsa2 = new TestDragSourceAdapter(2);
  67         Component c = new Button();
  68         DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(c,
  69                 DnDConstants.ACTION_COPY,
  70                 e -> e.startDrag(null, null));
  71         MouseEvent me = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, 0,
  72                 InputEvent.CTRL_MASK, 100, 100, 0, false);
  73         DragGestureEvent dge = new DragGestureEvent(dgr, DnDConstants.ACTION_COPY,
  74                 new Point(100, 100),
  75                 Arrays.asList(me));
  76         DragSourceContext dsc = new DragSourceContext(

  77                 dge,
  78                 new Cursor(Cursor.HAND_CURSOR),
  79                 null, null, new StringSelection("TEXT"), null);
  80 
  81         ds.addDragSourceListener(dsa1);
  82         ds.addDragSourceListener(dsa2);
  83         ds.addDragSourceListener(dsa2);
  84         ds.addDragSourceMotionListener(dsa1);
  85         ds.addDragSourceMotionListener(dsa1);
  86         ds.addDragSourceMotionListener(dsa2);
  87         dsc.addDragSourceListener(dsa2);
  88 
  89         byte[] serialized;
  90         try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
  91              ObjectOutputStream oos = new ObjectOutputStream(bos)) {
  92             oos.writeObject(dsc);
  93             serialized = bos.toByteArray();
  94         }
  95 
  96         DragSourceContext dsc_copy;