Beginner questions for specific layout

Hi,

first of all I would like to thank you for this great framework and especially the extensive documentation which helps a lot when starting with such a complex API.
I just started playing around with DockingFrames and I was able to come up with something useful quite fast using the CControl.getContentArea() as you can see in the attached screenshot.

I would like to implement additional things and need some help:

  1. How do I disable the north area which in the screenshot contains the minimized Tool3?
  2. How do I configure DF to always minimize to the nearest border (except the north) when clicking the minimize button?
  3. When multiple dockables are stacked and display tabs for selection the toolbar buttons behave unexpected for me because some of them only are only applied on the currently visible dockable (ie. the close button) while some others are applied on all stacked dockables (for example the minimize button). I would like to configure a behaviour that all buttons are always only applied on the currently active and visible dockable. How can I achieve this?

Here is the code I have so far:

{
    public ClientPro ()
    {
        super ("C 2013.0.0");
        setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        addWindowListener (new WindowAdapter ()
        {
            @Override
            public void windowClosing (WindowEvent e)
            {
                ComponentHelper.storeComponentPosition (ClientPro.this, getPrefsKey ());
            }
        });
        initDocking ();
    }

    private void initDocking ()
    {
        final CControl control = new CControl (this);
        control.setTheme (ThemeMap.KEY_FLAT_THEME);

        this.add (control.getContentArea ());

        final DefaultSingleCDockable dockable = create ("v", "Non-moving Content");
        control.addDockable (dockable);
        dockable.setVisible (true);
        dockable.setExternalizable (false);
        dockable.setMinimizable (false);
        dockable.setCloseable (false);
        dockable.setStackable (false);

        createTool (control, "Tool 1");
        createTool (control, "Tool 2");
        createTool (control, "Tool 3");

        DockController dockController = control.getController ();
        dockController.getRelocator ().addVetoableDockRelocatorListener (new VetoableDockRelocatorAdapter ()
        {
            @Override
            public void grabbing (DockRelocatorEvent event)
            {
                final Dockable dockable = event.getDockable ();
                final DockElement component = dockable.getElement ();
                if (component instanceof DefaultCommonDockable)
                {
                    DefaultCommonDockable defaultCommonDockable = (DefaultCommonDockable) component;
                    final String uniqueId = ((DefaultSingleCDockable) defaultCommonDockable.getDockable ()).getUniqueId ();
                    if (uniqueId.equals ("v"))
                    {
                        event.cancel ();
                    }
                }
            }
        });
    }

    private DefaultSingleCDockable createTool (CControl control, final String title)
    {
        final DefaultSingleCDockable dockableTool = create (UUID.randomUUID ().toString (), title);
        dockableTool.setLocation (CLocation.base ().normalWest (0.2));
        dockableTool.setMaximizable (false);
        dockableTool.setResizeLocked (true);
        dockableTool.setCloseable (true);
        control.addDockable (dockableTool);
        dockableTool.setVisible (true);
        return dockableTool;
    }

    private static DefaultSingleCDockable create (String key, String title)
    {
        DefaultSingleCDockable dockable = new DefaultSingleCDockable (key, title);
        JPanel panel = new JPanel (new GridBagLayout ());
        panel.add (new JButton ("test " + title), new GridBagConstraints (0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets (0, 0, 0, 0), 0, 0));
        dockable.add (panel);
        dockable.setFocusComponent (panel);
        return dockable;
    }

    public static void main (String[] args)
    {
        ClientPro clientPro = new ClientPro ();
        clientPro.showDialogAndKeepMinimumSize (new Dimension (800, 600));
    }
}

Thanks a lot,
Campus

After reading some more documentation I could answer point 3 myself:

control.setGroupBehavior (new TopMostGroupBehavior ());

does what I want.

Cool :smiley:

About 1: you cannot use CContentArea if you only want a subset of stations. In such a case you need to create each station for yourself:

frame.add( control.createMinimizeArea("south"), BorderLayout.SOUTH );
frame.add( control.createMinimizeArea("east"), BorderLayout.EAST );
frame.add( control.createMinimizeArea("west"), BorderLayout.WEST );```

Instead of "CLocation.base().normalWest(0.2)" you will have to write 
```		CGridArea gridArea = ...; // the "center" you created earlier
		CLocation.normalized(gridArea).west(0.2);```


About 2: have to answer later, but since the minimize-button can be replaced it is certainly possible to implement this new behavior.

Thanks a lot for your answer. That looks much better now. Another question just came up: with the code shown above all Tool dockables are stacked to the left of the main pane which is what I want. But the tabs show always the first and the last added tool dockable as being selected which looks like a bug to me. Am I doing something wrong here? I tried adding some .stack() to the location but that didn’t change anything.

Thanks again,
Campus

About 2. Here is an example how to replace the minimize-action. I did not write the code to actually find out which side is closest to a Dockable, but I guess that is a piece of cake for you :wink:


import javax.swing.JFrame;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.action.predefined.CMinimizeAction;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.mode.CMinimizedMode;
import bibliothek.gui.dock.common.mode.KeyedLocationModeActionProvider;

public class NearestMinimization {
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setBounds(20, 20, 400, 400);

		CControl control = new CControl(frame);

		// access to the object that represents everything related to
		// minimization
		CMinimizedMode minimizedMode = control.getLocationManager()
				.getMinimizedMode();

		// we replace the default prodvider of actions with a new provider, that
		// only contains
		// our special CustomCMinimizeAction
		minimizedMode.setActionProvider(new KeyedLocationModeActionProvider(
				CDockable.ACTION_KEY_MINIMIZE, new CustomCMinimizeAction(
						control)));

		// Instead of accessing the CMinimizedMode we could also replace the action of
		// each dockable by calling:
		
		// DefaultSingleCDockable dockable = ...
		// dockable.putAction(CDockable.ACTION_KEY_MINIMIZE, customMinimizeAction);

		frame.add(control.getContentArea());

		CGrid grid = new CGrid(control);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				grid.add(i, j, 1, 1, new DefaultSingleCDockable("id" + i + j,
						"Title " + i + " " + j));
			}
		}
		control.getContentArea().deploy(grid);

		frame.setVisible(true);
	}

	private static class CustomCMinimizeAction extends CMinimizeAction {
		public CustomCMinimizeAction(CControl control) {
			super(control);
		}

		@Override
		public void action(CDockable dockable) {
			// this call ignores any grouping of Dockables, but you said you do not want
			// to use such a feature anyways...
			dockable.setLocation(CLocation.base().minimalEast());
		}
	}
}

Hi Beni,

thanks a lot for your help. I was ale to accomplish what I want with the following code:

        // we replace the default prodvider of actions with a new provider, that only contains our special CustomCMinimizeAction
        minimizedMode.setActionProvider (new KeyedLocationModeActionProvider (CDockable.ACTION_KEY_MINIMIZE, new CMinimizeAction (control)
        {
            @Override
            public void action (CDockable dockable)
            {
                Component component = dockable.getFocusComponent ();
                if (component == null && dockable instanceof DefaultCDockable)
                {
                    DefaultCDockable defaultCDockable = (DefaultCDockable) dockable;
                    component = defaultCDockable.getContentPane ().getComponent (0);
                }
                if (component != null)
                {
                    final int componentX = (int) component.getLocationOnScreen ().getX ();
                    final int windowHorizontalCenter = (int) (getLocationOnScreen ().getX () + getWidth () / 2);
                    if (componentX + component.getWidth () < windowHorizontalCenter)
                    {
                        dockable.setLocation (CLocation.minimized (minimizeAreaWest));
                    }
                    else if (componentX > windowHorizontalCenter)
                    {
                        dockable.setLocation (CLocation.minimized (minimizeAreaEast));
                    }
                    else
                    {
                        dockable.setLocation (CLocation.minimized (minimizeAreaSouth));
                    }
                }
                else
                {
                    super.action (dockable);
                }
            }
        }));

Thanks and all the best,
Campus