With the current version: no chance to accomplish that. I would like such a feature myself, but it would require a lot work.
You could probably add a listener to all Dockables: if one gets maximized you minimize all the others. The “CDockableStateListener” could be used for that (and the method CControl.addStateListener adds it to all Dockables). I don’t know if that would look good.
I’ve just realized that there was a bug and the CDockableStateListener was never called. Well, the following code snippet will work with the code from the repository (username=anonymous, pw=anon) and with the next release.
There is a new listener on line 27, if a Dockable is maximized (line 55) all other Dockables are minimized. If the Dockable is normalized again (line 35) all the other Dockables are normalized too.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import bibliothek.gui.dock.common.CContentArea;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.event.CDockableStateListener;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.mode.ExtendedMode;
public class Dock17 {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(1, 1));
final CControl control = new CControl(frame);
control.addStateListener(new CDockableStateListener(){
private boolean onChange = false;
private List<CDockable> minimized = new ArrayList<CDockable>();
public void visibilityChanged( CDockable dockable ){
// ignore
}
public void normalized( CDockable dockable ){
if( !onChange ){
try{
onChange = true;
CDockable[] array = minimized.toArray(new CDockable[minimized.size()]);
minimized.clear();
for( CDockable mini : array ){
mini.setExtendedMode(ExtendedMode.NORMALIZED);
}
}
finally{
onChange = false;
}
}
}
public void minimized( CDockable dockable ){
}
public void maximized( CDockable dockable ){
if( !onChange ){
try{
onChange = true;
int changes = 0;
for( int i = 0, n = control.getCDockableCount(); i < n; i++ ){
CDockable next = control.getCDockable( i );
if( next != dockable ){
if( next.getExtendedMode() == ExtendedMode.NORMALIZED ){
minimized.add( next );
next.setExtendedMode( ExtendedMode.MINIMIZED );
changes++;
}
}
}
if(changes > 0){
dockable.setExtendedMode(ExtendedMode.MAXIMIZED);
}
}
finally{
onChange = false;
}
}
}
public void externalized( CDockable dockable ){
// ignore
}
});
CContentArea contentArea = control.getContentArea();
frame.add(contentArea);
DefaultSingleCDockable red = create("red", Color.RED);
DefaultSingleCDockable green = create("green", Color.GREEN);
control.add(red);
control.add(green);
green.setLocation(CLocation.base().normal());
red.setLocation(CLocation.base().normal().east(0.5));
green.setVisible(true);
red.setVisible(true);
frame.setSize(new Dimension(700, 700));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static DefaultSingleCDockable create(String title, Color color) {
JPanel panel = new JPanel();
panel.setOpaque(true);
panel.setBackground(color);
DefaultSingleCDockable dockable = new DefaultSingleCDockable(title, title, panel);
return dockable;
}
}```
The bug “the CDockableStateListener was never called” is correct in the version 5g?
I’ve tried this version but it’s never call.
Can I find the correction in the repository or must wait the new version?