Skip to content

Commit

Permalink
Protect against NPEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Cooper committed Nov 21, 2016
1 parent dffe5e4 commit 6e3e784
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
16 changes: 9 additions & 7 deletions src/main/java/org/dockfx/DockNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ private static FXMLLoader loadNode(String FXMLPath) {
FXMLLoader loader = new FXMLLoader();
try {
loader.load(DockNode.class.getResourceAsStream(FXMLPath));
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
loader.setRoot(new StackPane(new Label("Could not load FXML file")));
}
Expand Down Expand Up @@ -260,8 +259,10 @@ public void setDockTitleBar(DockNodeTitleBar dockTitleBar) {
}

public void showTitleBar(boolean show) {
dockTitleBar.setVisible(show);
dockTitleBar.setManaged(show);
if (null != dockTitleBar) {
dockTitleBar.setVisible(show);
dockTitleBar.setManaged(show);
}
}

public Stage getStage() {
Expand Down Expand Up @@ -650,7 +651,7 @@ protected void setDockPane(DockPane newDockPane) {
if (null != dockPane) {
dockPane.closedProperty().removeListener(dockPaneCloseListener);
}

this.dockPane = newDockPane;

if (null != newDockPane) {
Expand All @@ -672,15 +673,15 @@ private final void dockImpl(DockPane newDockPane) {
*/
public DockPane undock() {
DockPane oldDockPane = null;

if (dockPane != null) {
oldDockPane = dockPane;
dockPane.undock(this);
setDockPane(null);
}
//this.dockedProperty.set(false);
this.tabbedProperty.set(false);

return oldDockPane;
}

Expand All @@ -707,6 +708,7 @@ public void focus() {
}

private final DockPaneCloseListener dockPaneCloseListener = new DockPaneCloseListener();

private final class DockPaneCloseListener implements ChangeListener<Boolean> {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/dockfx/DockPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,9 @@ public void handle(DockEvent event) {
if (event.getEventType() == DockEvent.DOCK_RELEASED && event.getContents() != null) {
if (dockPosDrag != null && dockIndicatorOverlay.isShowing()) {
DockNode dockNode = ((DockPane) event.getContents()).getOnlyChild();
dockNode.dock(this, dockPosDrag, dockAreaDrag);
if (null != dockNode) {
dockNode.dock(this, dockPosDrag, dockAreaDrag);
}
}
}

Expand All @@ -1137,7 +1139,7 @@ public void handle(DockEvent event) {
public void storeLayout(String filePath) {
storeLayout(filePath, generateLayout());
}

public Map<String, ContentHolder> generateLayout() {
HashMap<String, ContentHolder> contents = new HashMap<>();

Expand Down Expand Up @@ -1170,17 +1172,16 @@ public Map<String, ContentHolder> generateLayout() {
if (null != this.root) {
contents.put("_DockedNodes", checkPane(this.root));
}

return contents;
}

public void storeLayout(String fileName, Map<String, ContentHolder> contents) {
public static void storeLayout(String fileName, Map<String, ContentHolder> contents) {
try (XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(fileName)))) {
e.writeObject(contents);
}
catch (FileNotFoundException e1) {
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
Expand Down Expand Up @@ -1251,15 +1252,14 @@ public void applyLayout(Map<String, ContentHolder> contents, DelayOpenHandler de
}
}

public HashMap<String, ContentHolder> loadLayout(String filePath) throws FileNotFoundException {
public static HashMap<String, ContentHolder> loadLayout(String filePath) throws FileNotFoundException {
return loadLayout(new BufferedInputStream(new FileInputStream(filePath)));
}
public HashMap<String, ContentHolder> loadLayout(InputStream is) {

public static HashMap<String, ContentHolder> loadLayout(InputStream is) {
try (XMLDecoder e = new XMLDecoder(is)) {
return (HashMap<String, ContentHolder>) e.readObject();
}
catch (ArrayIndexOutOfBoundsException ex) {
} catch (ArrayIndexOutOfBoundsException ex) {
// empty file
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/dockfx/demo/DockFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void start(Stage primaryStage) {
tabsDock.dock(dockPane, DockPos.TOP);
DockNode tableDock = new DockNode(tableView);
// let's disable our table from being undocked
tableDock.setDockTitleBar(null);
//tableDock.setDockTitleBar(null);
tableDock.setPrefSize(300, 100);
tableDock.dock(dockPane, DockPos.BOTTOM);

Expand Down

0 comments on commit 6e3e784

Please sign in to comment.