« prev next »
Java Docking Home> Developer Guide> How to Use Dragging

How to Use Dragging

:: Dragging dockables ::

A DraggerFactory creates the draggers for dragging the dockables of your application. You have to give your dragger factory to the DockingManager.

By default the StaticDraggerFactory is used. You can use a DynamicDraggerFactory like this:

		DockingManager.setDraggerFactory(new DynamicDraggerFactory());

:: Static dragging ::

By default this way of dragging is used. When a Dockable is dragged, a representation of the dockable, is painted. This is done by a DockableDragPainter.

Usually this representation is a rectangle. It shows where the dockable will be docked in a Dock, if the mouse would be released at the current mouse position. This rectangle can be painted:

Some dockable drag painters:
		DockableDragPainter swDockableDragPainterWithoutLabel = new SwDockableDragPainter(new DefaultRectanglePainter(), false);
		DockableDragPainter swDockableDragPainterWithLabel = new SwDockableDragPainter(new RectangleDragComponentFactory(new DefaultRectanglePainter(), true), false);
		DockableDragPainter swDockableDragPainterWithoutLabelNoFloat = new SwDockableDragPainter(new DefaultRectanglePainter());
		DockableDragPainter swDockableDragPainterWithLabelNoFloat = new SwDockableDragPainter(new RectangleDragComponentFactory(new DefaultRectanglePainter(), true));
		DockableDragPainter labelDockableDragPainter = new LabelDockableDragPainter();
		DockableDragPainter imageDockableDragPainter = new ImageDockableDragPainter();
		DockableDragPainter windowDockableDragPainterWithoutLabel = new WindowDockableDragPainter(new DefaultRectanglePainter());
		DockableDragPainter windowDockableDragPainterWithLabel = new WindowDockableDragPainter(new DefaultRectanglePainter(), true);
		DockableDragPainter transparentWindowDockableDragPainterWithoutLabel = new TransparentWindowDockableDragPainter(new DefaultRectanglePainter());
		DockableDragPainter transparentWindowDockableDragPainterWithLabel = new TransparentWindowDockableDragPainter(new DefaultRectanglePainter(), true);

Different drag painters can be combined with the CompositeDockableDragPainter:

			// Create the dockable drag painter and dragger factory.
			CompositeDockableDragPainter compositeDockableDragPainter = new CompositeDockableDragPainter();
			if (additionalDockableDragPainter != null)
			DraggerFactory draggerFactory 	= new StaticDraggerFactory(compositeDockableDragPainter);

A rectangle to represent the dockable is painted with a RectanglePainter. By default a DefaultRectanglePainter is used. You can change the layout of this drag rectangle by changing the properties of this painter:

		// The drag rectangles have to be rubberbands.
		float[] pattern = {1.0f, 1.0f};
		Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, pattern, 0.0f);
		DefaultRectanglePainter borderPainter = new DefaultRectanglePainter();
		SwDockableDragPainter dockableDragPainter = new SwDockableDragPainter(borderPainter);
		StaticDraggerFactory draggerFactory = new StaticDraggerFactory(dockableDragPainter);

:: Dynamic dragging ::

When a dockable is dragged, and the mouse is above a dock where the dockable can be docked, then the dockable is immediately docked in that dock, but the dragging can still be continued.

You can use dynamic dragging like this:

		DockingManager.setDraggerFactory(new DynamicDraggerFactory());
IMPORTANT: Sometimes dynamic dragging can be confusing for the users of your application, especially when a dockable has a lot of possibilities to dock itself.

:: Dragging cursors ::

By default the docking library uses the folowing cursors:

You can change these cursors like this:

The source code of the samples can be found in:

DynamicDraggingShows dynamic dragging of dockables.
DragRectangleShows other drag rectangles.
DragPainterShows combinations of dockable drag painters.

« prev next »