|
1 /* |
|
2 * @test |
|
3 * @summary Makes sure that JLayer is synchronizable |
|
4 * @author Alexander Potochkin |
|
5 * @run main SerializationTest |
|
6 */ |
|
7 |
|
8 import javax.swing.*; |
|
9 import javax.swing.plaf.LayerUI; |
|
10 import java.io.ByteArrayInputStream; |
|
11 import java.io.ObjectOutputStream; |
|
12 import java.io.ObjectInputStream; |
|
13 import java.io.ByteArrayOutputStream; |
|
14 |
|
15 public class SerializationTest { |
|
16 |
|
17 public static void main(String[] args) throws Exception { |
|
18 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|
19 ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream); |
|
20 |
|
21 JLayer<JButton> layer = new JLayer<JButton>(new JButton("Hello")); |
|
22 |
|
23 layer.setUI(new TestLayerUI<JButton>()); |
|
24 |
|
25 outputStream.writeObject(layer); |
|
26 outputStream.flush(); |
|
27 |
|
28 ByteArrayInputStream byteArrayInputStream = |
|
29 new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); |
|
30 ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream); |
|
31 |
|
32 JLayer newLayer = (JLayer) inputStream.readObject(); |
|
33 |
|
34 if (newLayer.getLayout() == null) { |
|
35 throw new RuntimeException("JLayer's layout is null"); |
|
36 } |
|
37 if (newLayer.getGlassPane() == null) { |
|
38 throw new RuntimeException("JLayer's glassPane is null"); |
|
39 } |
|
40 if (newLayer.getUI().getClass() != layer.getUI().getClass()) { |
|
41 throw new RuntimeException("Different UIs"); |
|
42 } |
|
43 if (newLayer.getView().getClass() != layer.getView().getClass()) { |
|
44 throw new RuntimeException("Different Views"); |
|
45 } |
|
46 } |
|
47 |
|
48 static class TestLayerUI<V extends JComponent> extends LayerUI<V> { |
|
49 public String toString() { |
|
50 return "TestLayerUI"; |
|
51 } |
|
52 } |
|
53 } |