1 /****************************************************************************/ 2 // Eclipse SUMO, LisumSimulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2016-2018 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file Constants.java 11 /// @author Maximiliano Bottazzi 12 /// @date 2016 13 /// @version $Id$ 14 /// 15 // 16 /****************************************************************************/ 17 package de.dlr.ts.lisum.gui; 18 19 import de.dlr.ts.commons.tools.FileTools; 20 import de.dlr.ts.lisum.simulation.LisumSimulation; 21 import de.dlr.ts.utils.xmladmin2.XMLAdmin2; 22 import de.dlr.ts.utils.xmladmin2.MalformedKeyOrNameException; 23 import de.dlr.ts.utils.xmladmin2.XMLNodeNotFoundException; 24 import java.io.File; 25 import java.io.IOException; 26 import java.io.InputStream; 27 import java.util.logging.Level; 28 import java.util.logging.Logger; 29 import javafx.beans.property.BooleanProperty; 30 import javafx.beans.property.SimpleBooleanProperty; 31 import javafx.scene.image.Image; 32 import org.apache.commons.io.IOUtils; 33 import org.xml.sax.SAXException; 34 35 36 /** 37 * 38 * @author @author <a href="mailto:maximiliano.bottazzi@dlr.de">Maximiliano Bottazzi</a> 39 */ 40 public class SystemProperties 41 { 42 private static final SystemProperties INSTANCE = new SystemProperties(); 43 44 private LisumSimulation currentSimulation = null; 45 private final BooleanProperty simulationOpened = new SimpleBooleanProperty(false); 46 private final BooleanProperty simulationStarted = new SimpleBooleanProperty(false); 47 48 private final int width = 1200; 49 private final int height = 900; 50 51 private final String systemName = "LiSuM"; 52 private String systemVersion = "1.0"; 53 private final Image mainIcon = new Image(getClass().getResourceAsStream("/images/icons/LisaSumoIcon.png")); 54 55 56 57 58 /** 59 * 60 * @return 61 */ getInstance()62 public static SystemProperties getInstance() 63 { 64 return INSTANCE; 65 } 66 67 /** 68 * 69 */ SystemProperties()70 private SystemProperties() 71 { 72 loadSystemVersion(); 73 } 74 75 /** 76 * 77 * @return 78 */ simulationOpenedProperty()79 public BooleanProperty simulationOpenedProperty() 80 { 81 return simulationOpened; 82 } 83 getSystemVersion()84 public String getSystemVersion() { 85 return systemVersion; 86 } 87 88 /** 89 * 90 * @return 91 */ simulationStartedProperty()92 public BooleanProperty simulationStartedProperty() 93 { 94 return simulationStarted; 95 } 96 97 /** 98 * 99 * @return 100 */ getMainIcon()101 public Image getMainIcon() 102 { 103 return mainIcon; 104 } 105 106 /** 107 * 108 * @param project 109 */ setCurrentSimulation(LisumSimulation project)110 public void setCurrentSimulation(LisumSimulation project) 111 { 112 this.currentSimulation = project; 113 114 if(project != null) 115 { 116 this.simulationOpened.set(true); 117 } 118 else 119 { 120 this.simulationOpened.set(false); 121 this.simulationStarted.set(false); 122 } 123 } 124 125 /** 126 * 127 * @return 128 */ getSystemName()129 public String getSystemName() 130 { 131 return systemName + " " + systemVersion; 132 } 133 134 /** 135 * 136 * @return 137 */ getCurrentSimulation()138 public LisumSimulation getCurrentSimulation() 139 { 140 return currentSimulation; 141 } 142 143 /** 144 * 145 * @return 146 */ getWidth()147 public int getWidth() 148 { 149 return width; 150 } 151 152 /** 153 * 154 * @return 155 */ getHeight()156 public int getHeight() 157 { 158 return height; 159 } 160 loadSystemVersion()161 private void loadSystemVersion() 162 { 163 File pom = new File("pom.xml"); 164 if(pom.exists()) 165 { 166 try { 167 XMLAdmin2 x = new XMLAdmin2().load(pom); 168 String version = x.getNode("version").getValue(); 169 FileTools.writeSmallTextFile("src/main/resources/version/version", version); 170 } 171 catch (SAXException | IOException | MalformedKeyOrNameException | XMLNodeNotFoundException ex) { 172 Logger.getLogger(GlobalConfig.class.getName()).log(Level.SEVERE, null, ex); 173 } 174 } 175 176 ClassLoader classLoader = getClass().getClassLoader(); 177 InputStream res = classLoader.getResourceAsStream("version/version"); 178 179 if(res != null) 180 { 181 try { 182 byte[] array = IOUtils.toByteArray(res); 183 this.systemVersion = new String(array).trim(); 184 } catch (IOException ex) { 185 Logger.getLogger(GlobalConfig.class.getName()).log(Level.SEVERE, null, ex); 186 } 187 } 188 } 189 } 190