Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ public static String findRegion(Component comp) {
}

DockingPort port = DockingManager.getDockingPort(comp);
if (port == null) {
return null;
}

Component docked = port.getDockedComponent();

if (!(docked instanceof JSplitPane)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class DockPathHandler implements RestorationHandler {

@Override
public boolean restore(Dockable dockable, DockingState dockingState, Map context) {
if (dockingState == null) {
return false;
}

DockingPath dockingPath = dockingState.getPath();
if (dockingPath == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PointHandler implements RestorationHandler, DockingConstants {

@Override
public boolean restore(Dockable dockable, DockingState dockingState, Map context) {
if(DockingManager.isDocked(dockable)) {
if(dockingState == null || DockingManager.isDocked(dockable)) {
return false;
}

Expand All @@ -54,6 +54,10 @@ public boolean restore(Dockable dockable, DockingState dockingState, Map context

private boolean restoreDockable(Dockable dockable, Component win, DockingState dockingState) {
RootWindow window = RootWindow.getRootContainer(win);
if(window == null) {
return false;
}

Container contentPane = window.getContentPane();

Point dropPoint = getDropPoint(dockable, contentPane, dockingState);
Expand Down
3 changes: 3 additions & 0 deletions flexdock-view/src/main/java/org/flexdock/view/Titlebar.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public void setText(String text) {
protected void setActions(Action[] actions) {
if (actions == null) {
actions = new Action[0];
}

if (actionList == null) {
actionList = new ArrayList(3);
actionButtons = new HashMap(3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.flexdock.docking.state.DockingState;
import org.flexdock.perspective.PerspectiveManager;
import org.flexdock.perspective.restore.handlers.AlreadyRestoredHandler;
import org.flexdock.perspective.restore.handlers.DockPathHandler;
import org.flexdock.perspective.restore.handlers.PointHandler;
import org.flexdock.perspective.restore.handlers.RelativeHandler;
import org.flexdock.view.View;
import org.flexdock.view.Viewport;
Expand Down Expand Up @@ -103,4 +105,21 @@ void testAlreadyRestoredHandlerOnlyAcceptsDockedDockables() {
new HashMap()));
}

@Test
void testDockPathHandlerDeclinesWithoutStateOrPath() {
View view = new View("restore.nopath", "No path");

assertFalse(new DockPathHandler().restore(view, null, new HashMap()));
assertFalse(new DockPathHandler().restore(view, new DockingState("restore.nopath"), new HashMap()));
}

@Test
void testPointHandlerDeclinesWithoutStateOrWindow() {
View view = new View("restore.nopoint", "No point");

assertFalse(new PointHandler().restore(view, null, new HashMap()));
// Headless, so there is no docking window to restore into
assertFalse(new PointHandler().restore(view, new DockingState("restore.nopoint"), new HashMap()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.flexdock.docking.Dockable;
import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.defaults.DefaultDockingStrategy;
import org.flexdock.view.View;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -41,6 +42,15 @@ void testNoSiblingOutsideLayout() {
assertSibling(null, bottom, DockingConstants.SOUTH_REGION);
}

@Test
void testNoSiblingForUndockedDockable() {
View undocked = new View(getClass().getSimpleName() + ".undocked", "Undocked");

assertNull(DefaultDockingStrategy.findRegion(undocked));
assertNull(DefaultDockingStrategy.getSibling(undocked));
assertNull(DefaultDockingStrategy.getSibling(undocked, DockingConstants.WEST_REGION));
}

@Test
void testNoSiblingForCenterInvalidRegionOrNullDockable() {
assertSibling(null, centre, DockingConstants.CENTER_REGION);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.flexdock.test.view;

import org.flexdock.view.Titlebar;
import org.junit.jupiter.api.Test;

import javax.swing.AbstractAction;
import javax.swing.Action;
import java.awt.event.ActionEvent;

import static org.junit.jupiter.api.Assertions.*;

class TitlebarTest {

private static Action createAction(String name) {
return new AbstractAction(name) {
@Override
public void actionPerformed(ActionEvent e) {
}
};
}

@Test
void testTitlebarWithActions() {
Titlebar titlebar = new Titlebar(new Action[] {createAction("first"), createAction("second")});

assertEquals(2, titlebar.getActions().length);
assertNotNull(titlebar.getActionButton("first"));
assertNotNull(titlebar.getActionButton("second"));
}

@Test
void testActionAddedAfterEmptyActions() {
Titlebar titlebar = new Titlebar(new Action[0]);

titlebar.addAction(createAction("added"));

assertEquals(1, titlebar.getActions().length);
assertNotNull(titlebar.getActionButton("added"));
}

}
Loading