org.nuiton.widget.WidgetUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nuiton-widgets Show documentation
Show all versions of nuiton-widgets Show documentation
Widgets graphiques utiles pour tous les développements.
/* *##% Graphical Widget
* Copyright (C) 2004 - 2008 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* . ##%*/
/* *
* WidgetUtil.java
*
* Created: Jul 26, 2004
*
* @author Benjamin Poussin
* Copyright Code Lutin
* @version $Revision: 254 $
*
* Mise a jour: $Date: 2010-04-10 01:13:11 +0200 (sam., 10 avril 2010) $
* par : $Author: tchemit $
*/
package org.nuiton.widget;
import java.awt.Component;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class WidgetUtil { // WidgetUtil
public static Component makeDeepCopy(Component clone) throws Exception {
XMLEncoder e = null;
XMLDecoder d = null;
try {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
e = new XMLEncoder(byteOut);
e.writeObject(clone);
e.flush();
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut
.toByteArray());
d = new XMLDecoder(byteIn);
return (Component) d.readObject();
} catch (Exception eee) {
eee.printStackTrace();
throw (eee);
} finally {
if (e != null) {
e.close();
}
if (d != null) {
d.close();
}
}
}
} // WidgetUtil