Skip to content

Commit

Permalink
BaseModuleLauncher.getStartupParam becomes getNoSplash since it is th…
Browse files Browse the repository at this point in the history
…e only usage
  • Loading branch information
lolo101 committed Aug 29, 2022
1 parent f99cb98 commit de3d082
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.function.Consumer;

public class AutoLogger<R> {

Expand Down Expand Up @@ -32,11 +32,12 @@ public R resultOrElse(R defaultValue) {
}
}

public void onSuccess(Consumer<R> consumer) {
public Optional<R> result() {
try {
consumer.accept(callable.call());
return Optional.ofNullable(callable.call());
} catch (Exception ex) {
logger.error("Exception: " + ex, ex);
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,57 @@
import javax.swing.*;
import java.io.File;
import java.util.Properties;
import java.util.stream.Stream;

public abstract class BaseModuleLauncher {
public StartupWindow splash = null;
public StartupWindow splash;
public static final Logger logger = LogManager.getRootLogger();
public Root root;
public String[] args;
Properties jnlp_properties;
public final String[] args;

public BaseModuleLauncher(String[] args) {

this.args = args;
BaseConfigureLogging();
}

public String getStartupParam(String name) {
return getStartupParam(name, name, name, null);
private String getNoSplash() {
return Stream.of(args)
.filter("-nosplash"::equalsIgnoreCase)
.findFirst()
.orElseGet(this::getNoSplashProperty);
}

public String getStartupParam(String shortname, String longname, String envname) {
return getStartupParam(shortname, longname, envname, null);
}

public String getStartupParam(String shortname, String longname, String envname, String default_value) {

shortname = "-" + shortname;
longname = "-" + longname;
private String getNoSplashProperty() {

if (args != null) {
boolean next = false;

for (String arg : args) {
if (next) {
return arg;
} else if (arg.equalsIgnoreCase(shortname)
|| arg.equalsIgnoreCase(longname)) {
next = true;
}
}
String envValue = System.getProperty("NOSPLASH");
if (envValue != null) {
System.out.println("env NOSPLASH=" + envValue);
return envValue;
}

parseJNLP();

String url = System.getProperty(envname.toUpperCase());

if (url == null && jnlp_properties != null)
url = jnlp_properties.getProperty(envname.toUpperCase());

if (url == null || url.trim().isEmpty()) {
String sdev = default_value;
if (sdev == null)
sdev = "(null)";

if (logger.isTraceEnabled())
logger.trace(envname + "=" + sdev + " (default)");
return default_value;
Properties jnlp_properties = findJnlpProperties();
String jnlpValue = jnlp_properties.getProperty("NOSPLASH");
if (jnlpValue != null) {
System.out.println("JNLP NOSPLASH" + "=" + jnlpValue);
return jnlpValue;
}

System.out.println(envname + "=" + url);
return url;
if (logger.isTraceEnabled())
logger.trace("NOSPLASH undefined");
return null;
}

private void parseJNLP() {
if (jnlp_properties != null)
return;

for (String arg : args) {
if (arg.endsWith(".jnlp")) {
final File jnlp_file = new File(arg);

if (jnlp_file.exists()) {
new AutoLogger<>(BaseModuleLauncher.class.getName(),
() -> new ParseJNLP(jnlp_file).getProperties()
).onSuccess(result -> jnlp_properties = result);
}
}
}
private Properties findJnlpProperties() {
return Stream.of(args)
.filter(arg -> arg.endsWith(".jnlp"))
.map(File::new)
.filter(File::exists)
.findFirst()
.flatMap(jnlp_file -> new AutoLogger<>(BaseModuleLauncher.class.getName(),
() -> new ParseJNLP(jnlp_file).getProperties()
).result())
.orElseGet(Properties::new);
}

/**
Expand Down Expand Up @@ -167,7 +142,7 @@ public final void configureLogging() {
public abstract String getVersion();

public boolean splashEnabled() {
return !StringUtils.isYes(getStartupParam(null, "nosplash", "NOSPLASH"));
return !StringUtils.isYes(getNoSplash());
}

public void closeSplash() {
Expand All @@ -194,16 +169,11 @@ public void setLookAndFeel() {
}
}

public static String getLookAndFeelStrByName(String name) {
private static String getLookAndFeelStrByName(String name) {

if (name.equalsIgnoreCase("motif")) {
return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
} else if (name.equalsIgnoreCase("metal")) {
return "javax.swing.plaf.metal.MetalLookAndFeel";
} else if (name.equalsIgnoreCase("nimbus")) {
return "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
} else {
return UIManager.getSystemLookAndFeelClassName();
}
if (name.equalsIgnoreCase("motif")) return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
if (name.equalsIgnoreCase("metal")) return "javax.swing.plaf.metal.MetalLookAndFeel";
if (name.equalsIgnoreCase("nimbus")) return "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
return UIManager.getSystemLookAndFeelClassName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class CLIHelpMSGViewer extends CLIHelp
{
public static final String CLI_MAINWIN = "-mainwin";
public static final String CLI_HIDEMENUBAR = "-hidemenubar";
public static final String CLI_NOSPLASH = "-nosplash";
public static final String CLI_HELP = "-h";
public static final String CLI_VERSION = "-v";
public static final String CLI_CONVERT_TEMP = "-t";
Expand All @@ -33,16 +34,19 @@ public CLIHelpMSGViewer( BaseModuleLauncher module_launcher )

add(new CLIOption(
CLI_CONVERT_OPEN,
"Opens the converted message with the associated standard application." ) );
"Opens the converted message with the associated standard application."));

add( new CLIGroupHeader("GUI OPTIONS"));
add(new CLIGroupHeader("GUI OPTIONS"));

add( new CLIOption( CLI_MAINWIN, "Show main window.",
"" ));
add(new CLIOption(CLI_MAINWIN, "Show main window.",
""));

add( new CLIOption( CLI_HIDEMENUBAR, "Hide menubar.",
"In this mode MSGViewer can only show messages. There is no file save as," +
" or something like this avaliable. This mode is use by internet kiosks." ));
add(new CLIOption(CLI_HIDEMENUBAR, "Hide menubar.",
"In this mode MSGViewer can only show messages. There is no file save as," +
" or something like this avaliable. This mode is use by internet kiosks."));

add(new CLIOption(CLI_NOSPLASH, "Do not show Splash screen.",
""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void run() throws Exception {
String htmlContent = parser.getHTML();
System.out.print(htmlContent);

String file_name = getStartupParam("writehtml");
String file_name = "writehtml";

if (file_name != null) {
try (FileWriter fout = new FileWriter(file_name)) {
Expand Down

0 comments on commit de3d082

Please # to comment.