Question about minimized CDockable

Hi all.

I have one question about minimized CDockable in a SplitDockStation : the use case is :

  • I have 2 CDockable in a splitdockstation
  • I double clicked on one CDockable : this one maximized in the splitdockstation, the other CDockable is not yet visible

My question : how to maintain the minimized CDockable visible as a button for example in the splitdockastation like a tab ?

Sorry if this question had already been asked. If so, could you please send me the url.

Thx

newbee

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.

What a pity !

Well, could you send me a snippet of such code, that would give me a point of start ?

thx

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;
    }
}```

Hi Beni,

that’s exactly the behaviour that we need on our project.

Thx so much for such a great framework !

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?

Monica

It’s not yet in 5g. I’ll upload 5h with the fix (I’m running out of letters…) this weekend. The fix is also in the repository.