es.gob.afirma.standalone.configurator.ConsoleManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of afirma-ui-simpleafirma-configurator Show documentation
Show all versions of afirma-ui-simpleafirma-configurator Show documentation
Aplicacion auxiliar de instalacion de AutoFirma
/* Copyright (C) 2011 [Gobierno de Espana]
* This file is part of "Cliente @Firma".
* "Cliente @Firma" is free software; you can redistribute it and/or modify it under the terms of:
* - the GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option) any later version.
* - or The European Software License; either version 1.1 or (at your option) any later version.
* You may contact the copyright holder at: [email protected]
*/
package es.gob.afirma.standalone.configurator;
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import es.gob.afirma.core.misc.Platform;
final class ConsoleManager {
private static final Logger LOGGER = Logger.getLogger("es.gob.afirma"); //$NON-NLS-1$
private static boolean getHeadLess() {
if (GraphicsEnvironment.isHeadless()) {
return true;
}
if (Platform.OS.LINUX.equals(Platform.getOS())) {
return true;
}
return false;
}
private static final boolean headless = getHeadLess();
private static final java.io.Console con = System.console();
/**
* Recupera una consola para la notificación del estado del proceso
* de configuración. La selección se realizará en base
* al entorno de ejecución.
* @param cl Escuchador que reaccionará ante los mensajes de la consola.
* Si se indica {@code null} se usará un consola sin entorno gráfico.
* @return
*/
static Console getConsole(final ConsoleListener cl) {
if (headless || cl == null) {
if (con != null) {
LOGGER.info("Se utilizara la consola de tipo I/O"); //$NON-NLS-1$
return new IoConsole(con);
}
LOGGER.info("Se utilizara la consola del sistema"); //$NON-NLS-1$
return new PrintConsole();
}
LOGGER.info("Se utilizara la consola grafica"); //$NON-NLS-1$
return new GraphicConfiguratorConsole(cl);
}
static void showErrorMessage(final Component parent, final String errorText) {
if (!headless) {
JOptionPane.showMessageDialog(
parent,
errorText,
Messages.getString("AutoFirmaConfigurator.2"), //$NON-NLS-1$
JOptionPane.ERROR_MESSAGE
);
}
else if (con != null) {
con.printf(errorText);
}
else {
System.out.println(errorText);
}
}
}