001 ///////////////////////////////////////////////// 002 // This file is part of Sears project. 003 // Subtitle Editor And Re-Synch 004 // A tool to easily modify and resynch movies subtitles. 005 ///////////////////////////////////////////////// 006 //This program is free software; 007 //you can redistribute it and/or modify it under the terms 008 //of the GNU General Public License 009 //as published by the Free Software Foundation; 010 //either version 2 of the License, or (at your option) any later version. 011 ///////////////////////////////////////////////// 012 //Sears project is available under sourceforge 013 // at adress: http://sourceforge.net/projects/sears/ 014 //Copyright (C) 2005 Booba Skaya 015 //Mail: booba.skaya@gmail.com 016 //////////////////////////////////////////////// 017 package sears.tools; 018 019 import java.io.File; 020 import java.io.FileInputStream; 021 import java.io.FileNotFoundException; 022 import java.io.FileOutputStream; 023 import java.io.IOException; 024 import java.util.Properties; 025 026 /** 027 * Class SearsProperties. 028 * <br><b>Summary:</b><br> 029 * This class contains the Sears Properties. 030 */ 031 public class SearsProperties { 032 /**The properties*/ 033 private Properties properties; 034 /**The instance of the class.*/ 035 private static SearsProperties instance = new SearsProperties(); 036 037 /**The config file name.*/ 038 private static final String CONFIG_FILE = "config.cfg"; 039 040 /**The config folder name.*/ 041 private static final String CONFIG_FOLDER = ".sears"; 042 043 044 /**The width suffix property.*/ 045 public static final String SUFFIX_WIDTH = "_width"; 046 /**The heigth suffix property.*/ 047 public static final String SUFFIX_HEIGTH = "_heigth"; 048 /**The posX suffix property.*/ 049 public static final String SUFFIX_POSX = "_posX"; 050 /**The posY suffix property.*/ 051 public static final String SUFFIX_POSY = "_posY"; 052 /**The last folder property*/ 053 public static final String LAST_FOLDER = "File_lastFolder"; 054 /**The language property*/ 055 public static final String LANGUAGE = "Sears_lang"; 056 /**The country property*/ 057 public static final String COUNTRY = "Sears_count"; 058 /**The player property*/ 059 public static final String PLAYER_FULL_PATH = "Player_fullPath"; 060 /**The look and feel property.*/ 061 public static final String LOOK_AND_FEEL = "Sears_lookAndFeel"; 062 /**The DOS line separator property.*/ 063 public static final String DOS_LINE_SEPARATOR = "Sears_useDOSLineSeparator"; 064 /**The player selected.*/ 065 public static final String PLAYER_SELECTED = "Sears_selectedPlayer"; 066 /**The update address.*/ 067 public static String UPDATE_ADDRESS = "Sears_update"; 068 /**The key to the other player choice.*/ 069 public final static int KEY_OTHER = 1; 070 /**The key to the VLC player choice.*/ 071 public final static int KEY_VLC = 0; 072 /**The ICON_SET_FILE: The file that contains the icons.*/ 073 public static final String ICON_SET = "Sears_iconSet"; 074 /**The DEFAULT_ICON_SET: The default icon set.*/ 075 public static final String DEFAULT_ICON_SET = "floriaen.jar"; 076 /** (<b>String</b>) RECENT_FILES: The RECENT_FILES */ 077 public static final String RECENT_FILES = "Sears_recentFiles"; 078 079 080 /**The VLC_RESTART: to indicate wether vlc should restart after a subtitle change.*/ 081 public static String VLC_RESTART = "Sears_vlcRestart"; 082 /**The VLC_PORT: the port to connect vlc.*/ 083 public static String VLC_PORT = "Sears_vlcPort"; 084 085 /** 086 * Constructor SearsProperties. 087 * <br><b>Summary:</b><br> 088 * Constructor of the class. 089 */ 090 public SearsProperties(){ 091 properties = loadProperties(); 092 } 093 094 095 /** 096 * Method loadProperties. 097 * <br><b>Summary:</b><br> 098 * Use this method to load the software properties. 099 * @return <b>Properties</b> The loaded properties. 100 */ 101 private Properties loadProperties() { 102 //the result of the method. 103 Properties result = new Properties(); 104 try { 105 //Load the property file. 106 result.load(new FileInputStream(getConfigFile())); 107 } catch (FileNotFoundException e) { 108 e.printStackTrace(); 109 } catch (IOException e) { 110 e.printStackTrace(); 111 } 112 //return the result 113 return result; 114 } 115 116 /** 117 * Method saveProperties. 118 * <br><b>Summary:</b><br> 119 * This method saves the properties of Sears in the property file. 120 */ 121 public static void saveProperties() { 122 try { 123 //save the properties. 124 instance.properties.store(new FileOutputStream(getConfigFile()), ""); 125 } catch (FileNotFoundException e) { 126 e.printStackTrace(); 127 } catch (IOException e) { 128 e.printStackTrace(); 129 } 130 } 131 132 /** 133 * Method getProperty. 134 * <br><b>Summary:</b><br> 135 * Return the sears property that correspond to the key. or "" value if not found. 136 * @param key The key to search. 137 * @return <b>String</b> The sears property that correspond to the key. or "" value if not found. 138 */ 139 public static String getProperty(String key){ 140 return getProperty(key, ""); 141 } 142 143 /** 144 * Method getProperty. 145 * <br><b>Summary:</b><br> 146 * Return the sears property that correspond to the key. or default value if not found. 147 * @param key The key to search. 148 * @param defaultValue The default value to return if not found. 149 * @return <b>String</b> The sears property that correspond to the key. or default value if not found. 150 */ 151 public static String getProperty(String key, String defaultValue){ 152 //The result of the method. 153 String result = ""; 154 //try to get the result from the properties. 155 result = instance.properties.getProperty(key, defaultValue); 156 //return the result. 157 return result; 158 } 159 160 /** 161 * Method setProperty. 162 * <br><b>Summary:</b><br> 163 * Set the Sears property. 164 * @param key The key to set. 165 * @param value The value to associate. 166 */ 167 public static void setProperty(String key, String value){ 168 instance.properties.setProperty(key, value); 169 } 170 171 /** 172 * Method getConfigFile. 173 * <br><b>Summary:</b><br> 174 * This method return the config file to be used with Sears. 175 * It creates it if not found. 176 * It uses the user.home property of the system. 177 * @return (<b>File</b>) The config file to be used to load and save Sears propertiess. 178 * @throws IOException 179 */ 180 private static File getConfigFile() throws IOException{ 181 //The result of the method. 182 File result = new File(System.getProperty("user.home")+File.separator+CONFIG_FOLDER+File.separator+CONFIG_FILE); 183 //check parent folder existence 184 if(!result.getParentFile().exists()){ 185 result.getParentFile().mkdirs(); 186 } 187 //Then create the property file if does not exist. 188 if(!result.exists()){ 189 result.createNewFile(); 190 } 191 //return the result. 192 return result; 193 } 194 }