Copyright © 2004 Christopher M Butler This work is licensed under a Creative Commons License.
Eleritec Docking Framework Tutorial
Basic Customization Child Container Creation
Altering the Cursor
CursorDemo.java displays a relatively simple example in which custom cursor icons have been used during docking operations on the NORTH dockable panel. This example is, in fact, a complete replica of the CompoundDemo.java shown earlier with a few small additions. The images have been downloaded from http://www.codeguru.com/java/articles/656.shtml and were creaetd by Jonathan Bingham.

Since our class implements the Dockable interface, it has a public getCursorProvider() method. In CompoundDemo.java, this method returned a null reference, forcing the DockingManager to make use of default cursor icons. In this example, however, getCursorProvider() returns the private instance variable cursorProvider, which may or may not be null. As shown in the buildDockingPort() method, we set the Dockable instance's cursorProvider if it is the NORTH panel. This ensures that a custom set of images will be used for the Dockable in the NORTH panel as it is dragged over various DockingPort regions. All other Dockable instances in the application will continue to use the default set of cursor icons.

Toggle to Hide Example Code
public class CursorDemo extends JPanel implements Dockable {
   .
   .
   private CursorProvider cursorProvider;
   .
   .
   public CursorProvider getCursorProvider() {
      return cursorProvider;
   }
   .
   .
   private void setCursorProvider(CursorProvider prov) {
      cursorProvider = prov;
   }

   private static DefaultDockingPort buildDockingPort(String desc) {
      // create the DockingPort
      DefaultDockingPort port = createDockingPort();

      // create the Dockable panel
      CursorDemo cd = new CursorDemo(desc);
      DockingManager.registerDockable(cd);
      // use a custom cursor provider for the north panel
      if ("North".equals(desc))
         cd.setCursorProvider(new CursorDelegate());

      // dock the panel and return the DockingPort
      port.dock(cd, desc, DockingPort.CENTER_REGION, false);
      return port;
   }
}


The static inner class CursorDelegate is our concrete implementation of the CursorProvider interface. It's a relatively simple class that merely returns a set of images on demand. Because of its simplicity and small size, it fits right into the CursorDemo class and most likely isn't worth creating and entire new top-level class.

Toggle to Hide Example Code
private static class CursorDelegate implements CursorProvider {
   private static final Image NORTH_IMG = createImg("tileHorizontal16.gif");
   private static final Image EAST_IMG = createImg("tileVertical16.gif");
   private static final Image CENTER_IMG = createImg("cascadeWindows16.gif");
   private static final Image BLOCKED_IMG = createImg("closeAllWindows16.gif");

   private static Image createImg(String imgName) {
      return ResourceManager.createImage("resources/images/demo/" + imgName);
   }

   public Image getCenterImage() {
      return CENTER_IMG;
   }

   public Image getDisallowedImage() {
      return BLOCKED_IMG;
   }

   public Image getEastImage() {
      return EAST_IMG;
   }

   public Image getNorthImage() {
      return NORTH_IMG;
   }

   public Image getSouthImage() {
      // same image as north
      return NORTH_IMG;
   }

   public Image getWestImage() {
      // same image as east
      return EAST_IMG;
   }
}


It's worth noting that returning an image from every method in this class isn't strictly necessary. The DockingManager, when detecting a null Image returned from a CursorProvider, will simply resort to using the corresponding default icon for the specified DockingPort region.
Basic Customization Child Container Creation