我需要一些有关 draw2d 分层窗格序列化的帮助。我阅读了有关序列化的内容,发现只有实现Serializable
接口的类才能序列化,并且它的所有字段本身都是可序列化的,或者是瞬态的。
我有一个非常复杂的图表需要序列化,但不知道如何进行?我发现 LayeredPane 类只包含一个 List 类型的字段。在任何情况下,任何人都可以帮助如何编写,比如递归方法或其他东西,以使 LayeredPane 对象可序列化?
@mKorbel 我面临的问题的示例场景很难给出,因为它是一个非常大的应用程序的一部分。不过,我已经编造了一个案例,这可能会让您对问题有所了解:
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
}
}