Skip to content

Commit

Permalink
Handle improvements (#129)
Browse files Browse the repository at this point in the history
* Fixes issue #128

The location of docking handles will now be based on the location of the JScrollPane if the dockable is wrapped in one.

The docking utils frame is now slightly larger than the docking frame so that docking handles can render off the edges.

* Removing the movement of the root handle for now. Realized it can make it impossible to dock to the root.

* Cleanup.
  • Loading branch information
andrewauclair authored Nov 18, 2023
1 parent d2f6f22 commit 945d031
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
54 changes: 20 additions & 34 deletions docking-api/src/ModernDocking/floating/DockingHandles.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,28 @@ private void setDockableHandleLocations() {
Point location = ((Component) targetDockable).getLocation();
Dimension size = ((Component) targetDockable).getSize();

// if this dockable is wrapped in a JScrollPane we need to set the handle to the center of the JScrollPane
// not to the center of the dockable (which will more than likely be at a different location)
if (targetDockable.isWrappableInScrollpane()) {
Component parent = ((Component) targetDockable).getParent();

while (parent != null && !(parent instanceof JScrollPane)) {
parent = parent.getParent();
}

if (parent != null) {
JScrollPane display = (JScrollPane) parent;

location = display.getLocation();
size = display.getSize();
}
}

location.x += size.width / 2;
location.y += size.height / 2;

location.y -= (int) (DockingHandle.HANDLE_ICON_SIZE * (1.75/2));

SwingUtilities.convertPointToScreen(location, ((Component) targetDockable).getParent());
SwingUtilities.convertPointFromScreen(location, utilFrame);

Expand All @@ -289,43 +308,10 @@ private void setDockableHandleLocations() {
* @param screenPos New mouse position
*/
public void update(Point screenPos) {
JComponent component = targetRoot;

Point framePoint = new Point(screenPos);
SwingUtilities.convertPointFromScreen(framePoint, component.getParent());

Point point = (component).getLocation();
Dimension size = component.getSize();

SwingUtilities.convertPointToScreen(point, component.getParent());

utilFrame.setLocation(point);
utilFrame.setSize(size);

setRootHandleLocations();
setDockableHandleLocations();

// check if the root handles happen to be under the dockable handles
if (Math.abs(dockableEast.getX() - rootEast.getX()) < dockableEast.getWidth() &&
Math.abs(dockableEast.getY() - rootEast.getY()) < dockableEast.getHeight()) {
// need to move root east, move it up 1/4 of screen
Point location = targetRoot.getLocation();
Dimension rootSize = targetRoot.getSize();
location.x += rootSize.width / 2;
location.y += (rootSize.height / 2) + (rootSize.height / 4);

SwingUtilities.convertPointToScreen(location, targetRoot.getParent());
SwingUtilities.convertPointFromScreen(location, utilFrame);

// setLocation(rootCenter, location.x, location.y);
// setLocation(rootWest, location.x - (size.width / 2) + rootHandleSpacing(rootWest), location.y);
// setLocation(rootNorth, location.x, location.y - (size.height / 2) + rootHandleSpacing(rootNorth));
setLocation(rootEast, location.x + (rootSize.width / 2) - rootHandleSpacing(rootEast), location.y);
// setLocation(rootSouth, location.x, location.y + (size.height / 2) - rootHandleSpacing(rootSouth));

}

framePoint = new Point(screenPos);
Point framePoint = new Point(screenPos);
SwingUtilities.convertPointFromScreen(framePoint, utilFrame);

rootRegion = null;
Expand Down
28 changes: 22 additions & 6 deletions docking-api/src/ModernDocking/floating/DockingUtilsFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ public DockingUtilsFrame(DockingAPI docking, Window referenceDockingWindow, Root

setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); // always moving a dockable when this frame is visible. use the moving cursor to indicate such

// set location and size based on the reference docking frame
setLocation(referenceDockingWindow.getLocation());
setSize(referenceDockingWindow.getSize());

// remember the reference docking frame and create the handles and over components
this.referenceDockingWindow = referenceDockingWindow;

handles = new DockingHandles(this, root);
overlay = new DockingOverlay(docking, this, root);

SwingUtilities.invokeLater(this::setSizeAndLocation);
}

@Override
Expand Down Expand Up @@ -195,12 +194,12 @@ public boolean isDockingToDockable() {

@Override
public void componentResized(ComponentEvent e) {
setSize(referenceDockingWindow.getSize());
setSizeAndLocation();
}

@Override
public void componentMoved(ComponentEvent e) {
setLocation(referenceDockingWindow.getLocation());
setSizeAndLocation();
}

@Override
Expand All @@ -222,4 +221,21 @@ public void paint(Graphics g) {
}
overlay.paint(g);
}

private void setSizeAndLocation() {
int padding = (int) (DockingHandle.HANDLE_ICON_SIZE * 1.75);

Point location = new Point(referenceDockingWindow.getLocationOnScreen());
Dimension size = new Dimension(referenceDockingWindow.getSize());

location.x -= padding;
location.y -= padding;

size.width += padding * 2;
size.height += padding * 2;

// set location and size based on the reference docking frame
setLocation(location);
setSize(size);
}
}

0 comments on commit 945d031

Please sign in to comment.