From 9910a099400d1f4faffb696ac54ffc8a9ef1783f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Bitteur?= Date: Thu, 2 Dec 2021 10:56:44 +0100 Subject: [PATCH] Bugfix for global Book Parameters to be accessible even without any book --- .../omr/score/ui/BookParameters.java | 9 ++++--- .../audiveris/omr/sheet/ui/BookActions.java | 26 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/org/audiveris/omr/score/ui/BookParameters.java b/src/main/org/audiveris/omr/score/ui/BookParameters.java index 5313023b0..76db5af75 100644 --- a/src/main/org/audiveris/omr/score/ui/BookParameters.java +++ b/src/main/org/audiveris/omr/score/ui/BookParameters.java @@ -246,7 +246,7 @@ public BookParameters (SheetStub stub) /** * Commit the user actions. * - * @param book the related book + * @param book the related book if any, perhaps null * @return true if committed, false otherwise */ public boolean commit (Book book) @@ -276,8 +276,11 @@ public boolean commit (Book book) if (tab == 0) { defaultModified = true; } else { - book.setModified(true); - bookModified = true; + // Test on book not really needed (unless tabs order gets changed one day) + if (book != null) { + book.setModified(true); + bookModified = true; + } } } } diff --git a/src/main/org/audiveris/omr/sheet/ui/BookActions.java b/src/main/org/audiveris/omr/sheet/ui/BookActions.java index 15cae16c3..db30ac473 100644 --- a/src/main/org/audiveris/omr/sheet/ui/BookActions.java +++ b/src/main/org/audiveris/omr/sheet/ui/BookActions.java @@ -679,15 +679,17 @@ public Task exportSheetAs (ActionEvent e) */ public static void applyUserSettings (final SheetStub stub) { - final Book book = stub.getBook(); + final Book book = (stub != null) ? stub.getBook() : null; - // Dialog already active? - final JDialog activeDialog = book.getParameterDialog(); + if (book != null) { + // Dialog already active? + final JDialog activeDialog = book.getParameterDialog(); - if (activeDialog != null) { - activeDialog.setVisible(true); + if (activeDialog != null) { + activeDialog.setVisible(true); - return; + return; + } } // Create a brand new dialog @@ -705,12 +707,16 @@ public static void applyUserSettings (final SheetStub stub) @Override public void windowClosing (WindowEvent we) { - book.setParameterDialog(null); + if (book != null) { + book.setParameterDialog(null); + } dialog.dispose(); } }); - book.setParameterDialog(dialog); + if (book != null) { + book.setParameterDialog(dialog); + } // User actions on buttons OK, Apply, Cancel final JOptionPane optionPane = new JOptionPane( @@ -738,7 +744,9 @@ public void windowClosing (WindowEvent we) } if (exit) { - book.setParameterDialog(null); + if (book != null) { + book.setParameterDialog(null); + } dialog.setVisible(false); dialog.dispose(); } else {