mjuhasz / BDSup2Sub

Blu-Ray/DVD subtitle editor
Apache License 2.0
211 stars 47 forks source link

Can't run CLI without window manager #46

Open prat0088 opened 11 years ago

prat0088 commented 11 years ago

When I try to run BDSup2Sub over SSH without X11 tunneling I get an error:

java -jar ../Software/BDSup2Sub_v5.1.1.jar --help
Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.awt.X11GraphicsEnvironment.initDisplay(Z)V
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:110)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:119)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at java.awt.Toolkit$2.run(Toolkit.java:868)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:860)
        at javax.swing.UIManager.getSystemLookAndFeelClassName(UIManager.java:608)
        at javax.swing.UIManager$1.run(UIManager.java:1230)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.swing.UIManager.loadSwingProperties(UIManager.java:1225)
        at javax.swing.UIManager.initialize(UIManager.java:1453)
        at javax.swing.UIManager.maybeInitialize(UIManager.java:1422)
        at javax.swing.UIManager.getDefaults(UIManager.java:656)
        at javax.swing.UIManager.getColor(UIManager.java:698)
        at bdsup2sub.core.Configuration.<clinit>(Configuration.java:32)
        at bdsup2sub.BDSup2Sub.<clinit>(BDSup2Sub.java:35)

The problem is that BDSup2Sub/src/main/java/bdsup2sub/core/Configuration.java initializes "public static final Color OK_BACKGROUND = UIManager.getColor("TextField.background");" in the class and not the constructor.

One way to fix this would be to add a isCLI as a required parameter to the constructor, and OK_BACKGROUND would only be initialized if isCLI is false.

mjuhasz commented 11 years ago

It was never my intention to make this desktop application work in a headless environment but I am willing to look into how much work it would be and time permitting implement it.

Indeed we should not eagerly initialize the GUI related parts if we don't need the GUI at all. Whether we need the GUI or not is not a trivial question. Just because the application is started from command line it does not mean the GUI is not loaded later. One example is when you start the application without the output file name specified:

java -jar BDSup2Sub [options]

This will result in loading the GUI with the specified input file pre-loaded for you and all the options applied.

I will look into what needs to be done to make BDSup2Sub work in a headless environment. Essentially if we don't have a full command line (e.g. no output file name specified) the fallback should be starting the GUI if we have a display (this is the current behavior) and a descriptive error message in a headless environment (this needs some work). If we have a full command line it should work regardless of the presence of a display (this needs some work as well).

prat0088 commented 11 years ago

I see. That makes sense. I'm grateful that BDSup2Sub even has a CLI mode in the first place and can convert my PGS subs. : ) As far as the scenarios you describe, I'm happy to have a basic headless sub conversion work from

mjuhasz commented 11 years ago

I am happy to hear you like the CLI mode ;-) BTW, I reopened this issue because this way it's listed for the next milestone so it remains on my radar. You'll be notified when it has been fixed and I'll close the issue then.