Obtain DefaultSingleCDockable handle from its OrientedLabel

Hi Beni,

Thank you for maintaining Docking Frames over the years.

I have an object reference to bibliothek.gui.dock.util.swing.OrientedLabel. Using this object, is there a way to get a handle on its associated DefaultSingleCDockable? I have several dockables, each has an associated OrientedLabel which when clicked, grabs focus to that OrentedLable (and hence to its associated DefaultSingleCDockable). I would like this ability to force OrientedLabel to gain focus programmatically, such as calling toFront() on DefaultSingleCDockable. I looked through the API, and can trace OrientedLabel’s ancestor’s up to JPanel (ConfiguredBackgroundPanel, BackgroundPanel, and JPanel), but I am unable to get a handle to DefaultSingleCDockable. Is there a way?
Swing’s own requestFocusInWindow() does not work in this case.

Thanks.

Adi

Do I even want to know why you access OrientedLabels? Are they created by your application, or are they created by the framework (for titles)? If you created them yourself then I would suggest to implement the interface DockElementRepresentative and add the new objects to the DockController with DockController.addRepresentative. This way the user would get all the features a Dockable has, e.g. the user could start dragging a Dockable by grabbing your OrientedLabel.

Otherwise:
The framework itself needs a way to find out which Component belongs to which Dockable, and you can access that algorithm. Call…

DockController controller = control.getController();
DockElementRepresentative representative = controller.searchElement( someComponent );
if( representative != null ){
  if( representative.getElement().asDockable() instanceof CommonDockable ){
    CDockable dockable = ((CommonDockable)representative.getElement().asDockable()).getDockable();
  }
}

Focus in Swing is rather funny (to the point where I would call it “buggy like hell”). The best way to set the focus is to go with the methods provided by the framework.

controller.setFocusedDockable( request );```

Hi Beni,

This works perfectly! The focus system in DF works consistently using the approach above as well as dockable’s toFront() method. Just great! Thank you.

To answer your question /comment:
The OrientedLabel objects were created by DF directly via dockables. Since I am currently developing a glass pane that covers the entire application window, the best that SwingUtilities.getDeepestComponentAt(…) method can find under the glass pane when the cursor is over a dockable, is the OrientedLabel component. The components within the dockable’s content will not always identify the dockable. As I need to redispatch the event to one of these components within a dockable directly under the glass pane, I also need to pass focus to its associated dockable. Hence, the topic of my post.

And, regarding Swing’s focus sub-system – agree with you – it delivers inconsistent behavior (for example, grabFocus(), requestFocus(), requestFocusInWindow() methods do not work as per spec on Swing’s own components like JPanels and JTrees, even when enclosed within EDT thread). Hopefully, Oracle will fix this sad situation soon.

Again, Beni, thank you for your help and excellent framework.

/Adi

You may want to have a look at the class “GlassedPane” then. It is used by DockingFrames as a glass pane, and it is very transparent (meaning the Components below the glass pane are not affected by its existence). It forwards all the MouseEvents to the underlying Components, and even understands how to display tooltips that are from the underlying Components. So far I did not get much complaints about the class, so it seems to work.