From a00add33c470c1343ea80f2b2fcbdc4cc259b5f4 Mon Sep 17 00:00:00 2001 From: BobHanson Date: Mon, 15 Jun 2020 22:07:02 -0500 Subject: [PATCH] JAL-3446 CommandLineOperation test - headless check must be before Desktop.getInstance(), as you can't make an instance of JFrame() when headless. --- src/jalview/gui/Desktop.java | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index a13a38b..d4f479a 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -841,7 +841,13 @@ public class Desktop extends GDesktop final JInternalFrame frame, String title, int w, int h) { // 58 classes - getInstance().addFrame(frame, title, Desktop.FRAME_MAKE_VISIBLE, w, h, + + setFrame(frame, title, w, h); + + // Headless operation has no Desktop instance, only the static class. + + if (getInstance() != null) + getInstance().addFrame(frame, Desktop.FRAME_MAKE_VISIBLE, FRAME_ALLOW_RESIZE, FRAME_SET_MIN_SIZE_300); } @@ -870,7 +876,10 @@ public class Desktop extends GDesktop int w, int h, boolean resizable, boolean ignoreMinSize) { // 15 classes - getInstance().addFrame(frame, title, makeVisible, w, h, resizable, + setFrame(frame, title, w, h); + + if (getInstance() != null) + getInstance().addFrame(frame, makeVisible, resizable, ignoreMinSize); } @@ -888,9 +897,8 @@ public class Desktop extends GDesktop public final static boolean FRAME_SET_MIN_SIZE_300 = false; - private void addFrame(JInternalFrame frame, String title, - boolean makeVisible, int w, int h, boolean resizable, - boolean ignoreMinSize) + private static void setFrame(JInternalFrame frame, String title, + int w, int h) { // TODO: allow callers to determine X and Y position of frame (eg. via // bounds object). @@ -902,14 +910,12 @@ public class Desktop extends GDesktop { frame.setSize(w, h); } - // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN - // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN - // IF JALVIEW IS RUNNING HEADLESS - // /////////////////////////////////////////////// - if (Jalview.isHeadlessMode()) - { - return; - } + } + + private void addFrame(JInternalFrame frame, + boolean makeVisible, boolean resizable, + boolean ignoreMinSize) + { openFrameCount++; @@ -951,7 +957,7 @@ public class Desktop extends GDesktop * add an entry for the new frame in the Window menu * (and remove it when the frame is closed) */ - final JMenuItem menuItem = new JMenuItem(title); + final JMenuItem menuItem = new JMenuItem(frame.getTitle()); frame.addInternalFrameListener(new InternalFrameAdapter() { @Override -- 1.7.10.2