Skip to content

Commit

Permalink
Fix Issue #377: Workaround the "mix console disappeared even after re…
Browse files Browse the repository at this point in the history
…start" problem
  • Loading branch information
jjazzboss committed Dec 10, 2023
1 parent 8cb7a09 commit 1d1e2eb
Showing 1 changed file with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.jjazz.mixconsole.api;

import java.util.MissingResourceException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jjazz.utilities.api.ResUtil;
Expand All @@ -48,7 +49,7 @@
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "explorer", openAtStartup = true, position = 1)
@TopComponent.Registration(mode = "explorer", openAtStartup = true, position = 0)
@ActionID(category = "Window", id = "org.jjazz.mixconsole.api.MixConsoleTopComponent")
// @ActionReference(path = "Menu/Window", position = 120) Useless if not closable
@TopComponent.OpenActionRegistration(
Expand All @@ -64,8 +65,6 @@ public final class MixConsoleTopComponent extends TopComponent

public MixConsoleTopComponent()
{
setName(ResUtil.getString(getClass(), "CTL_MixConsoleTopComponent"));
setToolTipText(ResUtil.getString(getClass(), "CTL_MixConsoleTopComponentDesc"));
putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, Boolean.TRUE);
putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
putClientProperty(TopComponent.PROP_KEEP_PREFERRED_SIZE_WHEN_SLIDED_IN, Boolean.TRUE);
Expand All @@ -74,31 +73,52 @@ public MixConsoleTopComponent()
putClientProperty(TopComponent.PROP_UNDOCKING_DISABLED, Boolean.FALSE);
putClientProperty(TopComponent.PROP_SLIDING_DISABLED, Boolean.FALSE);

initComponents();

// For Issue #377 be extra careful to make sure there is no exception at this stage
String name = "MixConsole bug, please report";
String tooltip = name;
try
{
name = ResUtil.getString(getClass(), "CTL_MixConsoleTopComponent");
tooltip = ResUtil.getString(getClass(), "CTL_MixConsoleTopComponentDesc");
} catch (MissingResourceException ex)
{
exceptionOccuredInConstructor(ex);
}
setName(name);
setToolTipText(tooltip);


initComponents(); // only one basic line, can't fail


try
{
// Catch exception & assertion errors to make sure user is notified, and that MixConsoleTopComponent is opened.
// Catch exception & assertion errors to make sure user is notified, and that MixConsoleTopComponent is still created.
// Fix Issue #261: If there is a bug in MixConsole(), MixConsoleTopComponent will not be displayed, user will exit JJazzLab and Netbeans
// will save the window configuration (WindowManager.wswmgr) without MixConsoleTopComponent. When user restarts JJazzLab, MixConsoleTopComponent will not appear
// anymore, even if the bug has gone!
editor = new MixConsole(MixConsoleSettings.getDefault());
// anymore, even if the bug has gone!
editor = new MixConsole(MixConsoleSettings.getDefault()); // If bug here then editor is null
add(editor);
} catch (Throwable t)
{
// Log & notify user, this is serious
String msg = "ERROR can't create the MixConsole, please report this bug with the Log file content. err='" + t.getMessage() + "'";
LOGGER.log(Level.SEVERE, "MixConsoleTopComponent() {0}", msg);
Exceptions.printStackTrace(t);
NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notifyLater(nd);
// Log & notify user, this is serious, but let MixConsole be created
exceptionOccuredInConstructor(t);
}


INSTANCE = this;
}

static private void exceptionOccuredInConstructor(Throwable t)
{
String msg = "ERROR can't create the MixConsole, please report this bug with the Log file content. err='" + t.getMessage() + "'";
LOGGER.log(Level.SEVERE, "MixConsoleTopComponent() {0}", msg);
Exceptions.printStackTrace(t);
NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notifyLater(nd);
}

/**
* Get the unique instance of this MixConsoleTopComponent.
*
Expand All @@ -122,18 +142,20 @@ public MixConsole getEditor()
@Override
public UndoRedo getUndoRedo()
{
return editor.getUndoManager();
// Fix Issue #377: editor might be null if exception was catched in constructor
return editor != null ? editor.getUndoManager() : super.getUndoRedo();
}

@Override
public Lookup getLookup()
{
return editor.getLookup();
// Fix Issue #377: editor might be null if exception was catched in constructor
return editor != null ? editor.getLookup() : super.getLookup();
}

/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of
* this method is always regenerated by the Form Editor.
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this
* method is always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
Expand Down

0 comments on commit 1d1e2eb

Please # to comment.