With 1.0.5, is there any way to specify a CDockable’s default minimization location. That is, I’d like to specify which side (north, south, east, west) a dockable is minimized to when the minimize title action is clicked.
There are some ways to achieve your goal, I would not call any of them a “solution”…
The best way: open the application once, make the settings in the GUI and then store the layout. Afterwards just load the layout when starting up the application.
Another way: open the CDockable in its minimized state and then move it to its final location. That would look like the method “create” and the bottom of this code:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import bibliothek.gui.dock.FlapDockStation;
import bibliothek.gui.dock.common.*;
import bibliothek.gui.dock.common.intern.theme.CFlatTheme;
public class Dock {
public static void main( String[] args ) throws Exception{
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
JFrame frame = new JFrame( "demo" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
CControl control = new CControl( frame );
control.setTheme( new CFlatTheme( control ) );
CMinimizeArea west = control.createMinimizeArea( "west" );
CMinimizeArea east = control.createMinimizeArea( "east" );
CGridArea center = control.createGridArea( "center" );
west.setDirection( FlapDockStation.Direction.EAST );
east.setDirection( FlapDockStation.Direction.WEST );
control.setDefaultLocation( west.getStationLocation() );
frame.add( west, BorderLayout.WEST );
frame.add( east, BorderLayout.EAST );
frame.add( center.getComponent(), BorderLayout.CENTER );
create( control, "east", east.getStationLocation(), null );
create( control, "west", west.getStationLocation(), null );
create( control, "center", center.getStationLocation(), west );
create( control, "center1", center.getStationLocation(), west );
create( control, "center2", center.getStationLocation(), east );
create( control, "center3", center.getStationLocation(), east );
frame.setBounds( 20, 20, 400, 400 );
frame.setVisible( true );
}
private static void create( CControl control, String title, CLocation location, CMinimizeArea area ){
DefaultSingleCDockable dock = new DefaultSingleCDockable( title, title, new JLabel( title ) );
dock.setMaximizable( false );
dock.setExternalizable( false );
dock.setCloseable( false );
// set the initial position
if( area != null ){
dock.setLocation( CLocation.minimized( area ) );
}
// show the CDockable
control.add( dock );
dock.setVisible( true );
// move it to its final destination
dock.setLocation( location );
}
}```
(It's a good idea you have, I think that is a missing feature I must add to 1.0.6)
[Edit: this new feature is now in the repository at JavaForge, therefore it is in v1.0.6. It is a new methode called "setDefaultLocation" located in AbstractCDockable. Look at the source code to see how it works.]
Thanks. What I’ve done is create a custom minimize action that knows the direction to minimize in. The code looks something like:
CFlapIndexLocation loc;
if (minLocation == TOP) loc = CLocation.base().minimalNorth();
else if (minLocation == BOTTOM) loc =CLocation.base().minimalSouth();
else if (minLocation == LEFT) loc = CLocation.base().minimalWest();
else if (minLocation == RIGHT) loc = CLocation.base().minimalEast();
else loc = CLocation.base().minimalSouth();
dockable.setLocation(loc);
This seems to work OK. Can you see any reason why it might not work?
You should note however that the user still can drag a CDockable to another minimize-location, but that other location will not get stored. There are ways to prevent the user dragging a CDockable to the wrong area. Or you might replace your special minimize-action with the original when it was clicked once.
I currently don’t have a version on my PC that would start, but these codes should work:
In 1.0.7:
CDockable dockable = ...
CLocation location = CLocation.base().minimalWest();
CStateManager sm = control.getStateManager();
// only when dockable is registered at control
sm.setLocation( dockable.intern(), CDockable.ExtendedMode.MINIMIZED, location );
And in 1.0.8 it gets easier:
AbstractCDockable dockable = ...
CLocation location = CLocation.base().minimalWest();
// can be called anytime, but will not override a setting that already exists
// (e.g. if the dockable already was minimized this method will not have any effect)
dockable.setDefaultLocation( ExtendedMode.MINIMIZED, location );```