1625N/A/*
3261N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
1625N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1625N/A *
1625N/A * This code is free software; you can redistribute it and/or modify it
1625N/A * under the terms of the GNU General Public License version 2 only, as
1625N/A * published by the Free Software Foundation.
1625N/A *
1625N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1625N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1625N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1625N/A * version 2 for more details (a copy is included in the LICENSE file that
1625N/A * accompanied this code).
1625N/A *
1625N/A * You should have received a copy of the GNU General Public License version
1625N/A * 2 along with this work; if not, write to the Free Software Foundation,
1625N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1625N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1625N/A */
1625N/A
1561N/A/*
1561N/A * @test
1561N/A * @summary Makes sure that JLayer is synchronizable
1561N/A * @author Alexander Potochkin
1561N/A * @run main SerializationTest
1561N/A */
1561N/A
1561N/Aimport javax.swing.*;
1561N/Aimport javax.swing.plaf.LayerUI;
1561N/Aimport java.io.ByteArrayInputStream;
1561N/Aimport java.io.ObjectOutputStream;
1561N/Aimport java.io.ObjectInputStream;
1561N/Aimport java.io.ByteArrayOutputStream;
1561N/A
1561N/Apublic class SerializationTest {
1561N/A
1561N/A public static void main(String[] args) throws Exception {
1561N/A ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
1561N/A ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream);
1561N/A
1561N/A JLayer<JButton> layer = new JLayer<JButton>(new JButton("Hello"));
1561N/A
1561N/A layer.setUI(new TestLayerUI<JButton>());
1561N/A
1561N/A outputStream.writeObject(layer);
1561N/A outputStream.flush();
1561N/A
1561N/A ByteArrayInputStream byteArrayInputStream =
1561N/A new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
1561N/A ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream);
1561N/A
1561N/A JLayer newLayer = (JLayer) inputStream.readObject();
1561N/A
1561N/A if (newLayer.getGlassPane() == null) {
1561N/A throw new RuntimeException("JLayer's glassPane is null");
1561N/A }
1561N/A if (newLayer.getUI().getClass() != layer.getUI().getClass()) {
1561N/A throw new RuntimeException("Different UIs");
1561N/A }
1561N/A if (newLayer.getView().getClass() != layer.getView().getClass()) {
1561N/A throw new RuntimeException("Different Views");
1561N/A }
1561N/A }
1561N/A
1561N/A static class TestLayerUI<V extends JComponent> extends LayerUI<V> {
1561N/A public String toString() {
1561N/A return "TestLayerUI";
1561N/A }
1561N/A }
1625N/A}