Browse Source

Toggle command for logging

pull/1/head
weisj 5 years ago
parent
commit
89a6248dba
  1. 15
      src/main/java/com/weis/darklaf/DarkLaf.java
  2. 24
      src/main/java/com/weis/darklaf/LafManager.java

15
src/main/java/com/weis/darklaf/DarkLaf.java

@ -16,8 +16,6 @@ import javax.swing.text.html.StyleSheet;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Method;
@ -25,7 +23,6 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
/**
@ -33,18 +30,6 @@ import java.util.logging.Logger;
*/
public class DarkLaf extends BasicLookAndFeel {
static {
try (InputStream inputStream = DarkLaf.class.getClassLoader()
.getResourceAsStream("logging.properties")) {
if (inputStream != null) {
LogManager.getLogManager().readConfiguration(inputStream);
}
} catch (IOException e) {
Logger.getGlobal().log(Level.SEVERE, "init logging system", e);
}
}
private static final Logger LOGGER = Logger.getLogger(DarkLaf.class.getName());
private static final String NAME = "Darklaf";
private BasicLookAndFeel base;

24
src/main/java/com/weis/darklaf/LafManager.java

@ -7,6 +7,11 @@ import javax.swing.*;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
/**
* Manager for the Look and Feel.
@ -16,6 +21,10 @@ import java.awt.*;
*/
public final class LafManager {
static {
setLogEnabled(true);
}
private static Theme currentLaf = Theme.Dark;
static void setCurrentLaf(final Theme currentLaf) {
@ -27,6 +36,21 @@ public final class LafManager {
return currentLaf;
}
public static void setLogEnabled(boolean logEnabled) {
if (!logEnabled) {
LogManager.getLogManager().reset();
} else {
try (InputStream inputStream = DarkLaf.class.getClassLoader()
.getResourceAsStream("logging.properties")) {
if (inputStream != null) {
LogManager.getLogManager().readConfiguration(inputStream);
}
} catch (IOException e) {
Logger.getGlobal().log(Level.SEVERE, "init logging system", e);
}
}
}
/**
* Set the LaF to one of the two defaults.
*

Loading…
Cancel
Save