Hi,
here is my modest code :
frontend = new DockFrontend(frame);
frame.destroyOnClose(frontend);
frontend.getController().setTheme(new NoStackTheme(new SmoothTheme()));
station = new SplitDockStation();
frame.add(station);
frame.addWindowListener(new WindowAdapter() {
// Invoked when a window is in the process of being closed.
// The close operation can be overridden at this point.
@Override
public void windowClosing(WindowEvent e) {
Logger.getLogger(PersistentLayoutExample.class.getSimpleName()).log(Level.WARNING, "Window Closing Event", "Window Closing Event");
/** saving the flagged (AnnSave) properties **/
PreferenceMgr.getPersistenceMgr().save();
}
});
frontend.addRoot("layout", station);
/* Prepare the Dockables we are going to put onto "station" */
Dockable magenta = new ColorDockable("Magenta", Color.MAGENTA, 2.5f);
/* Never forget to register all Dockables at the DockFrontend */
frontend.addDockable("magenta", magenta);
/* Now we tell the framework that our Dockables can be closed */
frontend.setHideable(magenta, true);
/* Adding the Dockables to "station" */
grid = new SplitDockGrid();
grid.addDockable(60, 30, 40, 70, magenta);
station.dropTree(grid.toTree());
/* We build a menu that allows us to call the different methods easily */
JMenu menu = new JMenu("Layout");
/* The ReadAction calls DockFrontend.readXML */
ReadAction read = new ReadAction(frontend, frame);
menu.add(read);
/* The WriteAction calls DockFrontend.writeXML */
menu.add(new WriteAction(frontend, frame, station));
/* We build a menu that allows us to call the different methods easily */
JMenu window = new JMenu("Window");
window.add(new AddAction(frontend, grid, station));
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
menuBar.add(window);
frame.setJMenuBar(menuBar);
frame.setVisible(true);```
then the actions :
add
```/* Let's create one Dockables */
//Dockable red = new MyColorDockable("My Window " + (i++), Color.RED);
Dockable red = new ColorDockable("Red", Color.RED, 2.5f);
/* We need to register our Dockable. Each Dockable gets associated with a
* unique identifier. */
frontend.addDockable("Red"+System.currentTimeMillis(), red);
/* Now we tell the framework that our Dockables can be closed */
frontend.setHideable(red, true);
grid.addDockable(60, 30, 40, 70, red);
station.addDockable(red); ```
read
…
/* And now we can safely apply the old layouts */
if (inputStream != null) {
XElement xroot = XIO.read(parseISToString(inputStream));
frontend.readXML(xroot);
}
inputStream.close();```
write
output = new FileOutputStream(file.getAbsolutePath());
frontend.writeXML(xroot);
String st = xroot.toString();
output.write(st.getBytes());
output.flush();
output.close();```
When the Dockables are built from the main it works fine save/load but those built from the "Add" action are never loaded back to the frame :-(
what am i doing wrong .