Could you please post the xml-file itself? It may contain valuable information. I would also need to know the id (key) of some of the Dockables whose location does not get cached.
You can try calling “m_dockControl.setMissingStrategy( MissingCDockableStrategy.STORE );” directly after you created your “CControl”. This will tell “m_dockControl” not to throw away any layout information. If this does not help, then the layout information never got stored in the first place.
I wrote some small application to check and make absolutely sure that location-caching works - yes it does.
Would you please copy the following lines (line 66 to 82 in my test application) to your application and:
[ul]
[li]Replace the keys “red”, “green”, etc… in the array by keys used by your application.
[/li][li]Call the code directly before “m_dockControl.load(“current”);” and again directly after. What is the output?
[/li][/ul]
Lines to copy:
* Print out the position of a few selected Dockables. Only invisible Dockables
* will print out something else than "null null"
*/
DockFrontend frontend = control.intern();
String[] keys = new String[]{ "red", "green", "blue", "yellow" };
for( String key : keys ){
DefaultCControlRegister register = (DefaultCControlRegister) control.getRegister();
key = register.toSingleId( key );
FrontendEntry entry = frontend.getFrontendEntry( key );
if( entry == null ){
System.out.println( key + ": missing" );
}
else{
System.out.println( key + ": " + entry.getRoot() + " " + entry.getLocation() );
}
}
/*
* End printing
*/```
Entire application
```package test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import bibliothek.gui.DockFrontend;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.intern.DefaultCControlRegister;
import bibliothek.gui.dock.common.menu.SingleCDockableListMenuPiece;
import bibliothek.gui.dock.facile.menu.RootMenuPiece;
import bibliothek.gui.dock.frontend.FrontendEntry;
import bibliothek.util.xml.XElement;
public class Dock12 extends JFrame{
public static void main(String[] args) {
JFrame frame = new Dock12( null );
frame.setVisible( true );
}
private CControl control;
public Dock12(XElement xml){
JButton reload = new JButton( "Reload" );
reload.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ){
reload();
}
});
add(reload, BorderLayout.SOUTH);
load( xml );
JMenuBar bar = new JMenuBar();
RootMenuPiece menu = new RootMenuPiece( "Layout", true );
menu.add( new SingleCDockableListMenuPiece( control ) );
bar.add( menu.getMenu() );
setJMenuBar( bar );
setSize( 600, 500 );
setDefaultCloseOperation( EXIT_ON_CLOSE );
}
private void load(XElement xml){
control = new CControl( this );
getContentPane().add( control.getContentArea() );
loadInitialLayout();
if( xml != null ){
control.readXML( xml );
}
/*
* Print out the position of a few selected Dockables. Only invisible Dockables
* will print out something else than "null null"
*/
DockFrontend frontend = control.intern();
String[] keys = new String[]{ "red", "green", "blue", "yellow" };
for( String key : keys ){
DefaultCControlRegister register = (DefaultCControlRegister) control.getRegister();
key = register.toSingleId( key );
FrontendEntry entry = frontend.getFrontendEntry( key );
if( entry == null ){
System.out.println( key + ": missing" );
}
else{
System.out.println( key + ": " + entry.getRoot() + " " + entry.getLocation() );
}
}
/*
* End printing
*/
}
private void reload(){
XElement xml = null;
if( control != null ){
xml = new XElement( "settings" );
control.writeXML( xml );
getContentPane().remove( control.getContentArea() );
control.destroy();
setVisible( false );
}
Dock12 dock = new Dock12( xml );
dock.setVisible( true );
}
private void loadInitialLayout(){
CGrid grid = new CGrid( control );
grid.add( 0, 0, 10, 10, get( "red", Color.RED ) );
grid.add( 0, 10, 10, 10, get( "green", Color.GREEN ) );
grid.add( 10, 0, 10, 10, get( "blue", Color.BLUE ) );
grid.add( 10, 10, 10, 10, get( "yellow", Color.YELLOW ) );
control.getContentArea().deploy( grid );
}
private DefaultSingleCDockable get(String id, Color color){
JPanel panel = new JPanel();
panel.setBackground( color );
panel.setOpaque( true );
DefaultSingleCDockable result = new DefaultSingleCDockable( id, id, panel );
result.setCloseable( true );
return result;
}
}