public enum JSensors {

	get;

	private static final Logger LOGGER = LoggerFactory.getLogger(JSensors.class);

	final Map<String, String> baseConfig;

	private Map<String, String> usedConfig = null;

	static {
		checkRights();
	}

	private static void checkRights() {
		if (OSDetector.isWindows() && !PowerShellOperations.isAdministrator()) {
			LOGGER.warn("You have not executed jSensors in Administrator mode, so CPU temperature sensors will not be detected.");
		}
	}

	JSensors() {
		// Load config from file
		baseConfig = SensorsConfig.getConfigMap();
	}

	/**
	 * Updates default config (configurationon jsensors.properties) with a new one
	 * 
	 * @param config
	 *            maps that contains the new config values
	 * @return {@link JSensors} instance
	 */
	public JSensors config(Map<String, String> config) {
		// Initialise config if necessary
		if (this.usedConfig == null) {
			this.usedConfig = this.baseConfig;
		}

		// Override values
		for (final Map.Entry<String, String> entry : config.entrySet()) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug(String.format("Overriding config entry %s, %s by %s", entry.getKey(),
						this.usedConfig.get(entry.getKey()), entry.getValue()));
			}
			this.usedConfig.put(entry.getKey(), entry.getValue());
		}

		return this;
	}

	/**
	 * Retrieve all sensors components values. The supported sensors types are:
	 * <ul>
	 * <li>Fan: fan speed</li>
	 * <li>Load: component load %</li>
	 * <li>Temperature: temperature of sensor in C(Centigrader) or F(Farenheit)
	 * depending on system settings</li>
	 * </ul>
	 * <p>
	 * 
	 * @return {@link Components} object that containt the lists of components
	 */
	public Components components() {
		if (this.usedConfig == null) {
			this.usedConfig = new HashMap<String, String>();
		}

		Components components = SensorsLocator.get.getComponents(this.usedConfig);

		// Reset config
		this.usedConfig = this.baseConfig;

		return components;
	}

	/**
	 * Standalone entry point
	 * 
	 * @param args program arguments
	 */
	public static void main(String[] args) {
		boolean guiMode = false;
		Map<String, String> overriddenConfig = new HashMap<String, String>();
		for (final String arg : args) {
			if ("--debug".equals(arg)) {
				overriddenConfig.put("debugMode", "true");
			}
			if ("--gui".equals(arg)) {
				guiMode = true;
			}
		}

		if (guiMode) {
			GuiOutput.showOutput(overriddenConfig);
		} else {
			ConsoleOutput.showOutput(overriddenConfig);
		}
	}
}
 public enum PowerShellOperations {
	GET;

	private static final Logger LOGGER = LoggerFactory.getLogger(PowerShellOperations.class);

	private PowerShell powerShell = null;

	PowerShellOperations() {
		this.powerShell = PowerShell.openSession();
	}

	public static boolean isAdministrator() {
		String command = "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] \"Administrator\")";

		return "true".equalsIgnoreCase(PowerShell.executeSingleCommand(command).getCommandOutput());
	}

	public String getRawSensorsData() {
		return this.powerShell.executeScript(PowerShellScriptHelper.generateScript()).getCommandOutput();
	}
} public abstract class Component {
	public final String name;
	public final Sensors sensors;

	public Component(String name, Sensors sensors) {
		this.name = name;
		this.sensors = sensors;
	}
} public class Components {
	public final List<Cpu> cpus;
	public final List<Gpu> gpus;
	public final List<Disk> disks;
	public final List<Mobo> mobos;

	public Components(List<Cpu> cpus, List<Gpu> gpus, List<Disk> disks, List<Mobo> mobos) {
		this.cpus = cpus;
		this.gpus = gpus;
		this.disks = disks;
		this.mobos = mobos;
	}
} public class Cpu extends Component {

	public Cpu(String name, Sensors sensors) {
		super(name, sensors);
	}

} public class Disk extends Component {

	public Disk(String name, Sensors sensors) {
		super(name, sensors);
	}

} public class Gpu extends Component {

	public Gpu(String name, Sensors sensors) {
		super(name, sensors);
	}

} public class Fan {
	public final String name;
	public final Double value;

	public Fan(String name, Double value) {
		this.name = name;
		this.value = value;
	}
} public class Load {
	public final String name;
	public final Double value;

	public Load(String name, Double value) {
		this.name = name;
		this.value = value;
	}
} public class Temperature {
	public final String name;
	public final Double value;

	public Temperature(String name, Double value) {
		this.name = name;
		this.value = value;
	}
} public class OSDetector {
	private static final String OS = System.getProperty("os.name").toLowerCase();

	/**
	 * Hide constructor
	 */
	private OSDetector() {
	}

	public static boolean isWindows() {
		return OS.startsWith("win");
	}

	public static boolean isUnix() {
		return OS.contains("nix") || OS.contains("nux") || OS.contains("aix");
	}

}
import com.profesorfalken.jsensors.model.sensors.Load;
import com.profesorfalken.jsensors.model.sensors.Temperature;
import com.profesorfalken.jsensors.util.OSDetector;
import java.awt.EventQueue;
import java.util.List;
import java.util.Map;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import com.profesorfalken.jsensors.JSensors;
import com.profesorfalken.jsensors.manager.windows.powershell.PowerShellOperations;
import com.profesorfalken.jsensors.model.components.Component;
import com.profesorfalken.jsensors.model.components.Components;
import com.profesorfalken.jsensors.model.components.Cpu;
import com.profesorfalken.jsensors.model.components.Disk;
import com.profesorfalken.jsensors.model.components.Gpu;
import com.profesorfalken.jsensors.model.sensors.Fan;
/*
 * Copyright 2016-2018 Javier Garcia Alonso.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.profesorfalken.jsensors.standalone;




/**
 * Provides an output using a Swing based GUI
 * 
 * @author Javier Garcia Alonso
 *
 */
public class GuiOutput {

	public static void showOutput(final Map<String, String> config) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				JSensorsGUI gui = new GuiOutput().new JSensorsGUI(config);
				gui.setVisible(true);
			}
		});
	}

	@SuppressWarnings("serial")
	class JSensorsGUI extends JFrame {
		private Map<String, String> config;
		private JTable table = new JTable();

		public JSensorsGUI(Map<String, String> config) {
			this.config = config;
			initUI();
		}

		private void initUI() {
			setTitle("JSensors");
			setSize(600, 400);
			setLocationRelativeTo(null);
			setDefaultCloseOperation(EXIT_ON_CLOSE);

			if (OSDetector.isWindows() && !PowerShellOperations.isAdministrator()) {