Java 序列化draw2d LayeredPane
我需要一些关于draw2d分层窗格序列化的帮助。我阅读了有关序列化的内容,发现只有当类实现了Java 序列化draw2d LayeredPane,java,serialization,draw2d,Java,Serialization,Draw2d,我需要一些关于draw2d分层窗格序列化的帮助。我阅读了有关序列化的内容,发现只有当类实现了Serializable接口,并且它的所有字段本身都是可序列化的,或者是暂时的时,才可以对其进行序列化 我有一个非常复杂的图表,我需要序列化,但对于如何继续,我没有任何线索?我发现LayeredPane类只包含一个List类型的字段。在任何情况下,有人能帮助我们如何编写,比如递归方法或其他东西,使LayeredPane对象可序列化吗 @姆科贝尔 我面临的问题的一个示例场景很难给出,因为它是一个真正大型应用
Serializable
接口,并且它的所有字段本身都是可序列化的,或者是暂时的时,才可以对其进行序列化
我有一个非常复杂的图表,我需要序列化,但对于如何继续,我没有任何线索?我发现LayeredPane类只包含一个List类型的字段。在任何情况下,有人能帮助我们如何编写,比如递归方法或其他东西,使LayeredPane对象可序列化吗
@姆科贝尔
我面临的问题的一个示例场景很难给出,因为它是一个真正大型应用程序的一部分。尽管如此,我还是编造了一个案例,这可能会让你对这个问题有一个想法:
public class Editor extends org.eclipse.ui.part.EditorPart {
org.eclipse.draw2d.FreeformLayer objectsLayer;
org.eclipse.draw2d.ConnectionLayer connectionLayer;
public void createPartControl(Composite parent) {
org.eclipse.draw2d.FigureCanvas canvas = new org.eclipse.draw2d.FigureCanvas(composite);
org.eclipse.draw2d.LayeredPane pane = new org.eclipse.draw2d.LayeredPane();
objectsLayer = new org.eclipse.draw2d.FreeformLayer();
connectionLayer = org.eclipse.draw2d.ConnectionLayer();
pane.add(objectsLayer);
pane.add(connectionLayer);
canvas.setContents(pane);
addFigures();
addConnections();
}
private void addFigures() {
// Adds Objects, i.e., org.eclipse.draw2d.Figure Objects, to the objectLayer
// which turn contains, 1 or more org.eclipse.draw2d.Panel Objects,
// with variable number of org.eclipse.draw2d.Label objects
}
private void addConnections() {
// Adds org.eclipse.draw2d.PolylineConnection objects to the connectionLayer
// between objects in the objectLayer
}
}
您必须扩展LayeredPane类,通过实现该接口使其可序列化,并提供从模型重建LayeredPane的整个结构和属性的方法
public class SerializableLayeredPanne extends LayeredPanne implements Serializable {
private static final long serialVersionUID = 1L;
/**
* the model you are able to FULLY restore layered pane and all its children from,
* it MUST be serializable
*/
private final Serializable model;
SerializableLayeredPanne(Serializable model) {
this.model = model;
}
public void init() {
// set font, color etc.
// add children
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
init();
}
}
因此,您必须添加一个可序列化的模型,该模型包含从头开始构建图形树所需的所有信息。哪种类型的LayeredPane,为了更好地帮助您,请发布@mKorbel:我编辑了这个问题以添加LayeredPane的一个简单示例,我想序列化。