* a missing systray.config file is now handled gracefully

* fixed javadoc warnings
This commit is contained in:
hypercubus
2004-08-21 04:03:22 +00:00
committed by zzz
parent 7dc8d0cfec
commit f4754d7481
4 changed files with 28 additions and 17 deletions

View File

@ -39,7 +39,7 @@
<mkdir dir="./build/javadoc" />
<javadoc
sourcepath="./src"
classpath="./src:./src/net/i2p/apps/systray/systray4j.jar"
classpath="./src:./src/net/i2p/apps/systray/lib/systray4j.jar"
destdir="./build/javadoc"
packagenames="*"
use="true"

View File

@ -17,17 +17,24 @@ import java.util.Properties;
* Simple config file handler.
*
* @author hypercubus
*
* TODO Make write operations keep original line comments intact.
*/
public class ConfigFile {
// TODO Make write operations keep original line comments intact.
private String _configFile;
private Properties _properties = new Properties();
public ConfigFile(String configFile) {
/**
* Initializes the {@link ConfigFile} object.
*
* @param configFile The config file to use.
* @return <code>false</code> if the given config file cannot be
* located or accessed, otherwise <code>true</code>.
*/
public boolean init(String configFile) {
_configFile = configFile;
readConfigFile();
return readConfigFile();
}
public String getProperty(String key) {
@ -43,7 +50,7 @@ public class ConfigFile {
writeConfigFile();
}
private void readConfigFile() {
private boolean readConfigFile() {
FileInputStream fileInputStream = null;
@ -51,16 +58,18 @@ public class ConfigFile {
fileInputStream = new FileInputStream(_configFile);
_properties.load(fileInputStream);
} catch (IOException e) {
System.exit(1);
return false;
}
try {
fileInputStream.close();
} catch (IOException e1) {
// No worries.
}
return true;
}
private void writeConfigFile() {
FileOutputStream fileOutputStream = null;
try {

View File

@ -61,7 +61,6 @@ public class ShellCommand {
synchronized(caller) {
caller.notify(); // In case the caller is still in the wait() state.
}
return;
}
}
@ -184,7 +183,7 @@ public class ShellCommand {
* {@link #getErrorStream()}, respectively. Input can be passed to the
* <code>STDIN</code> of the shell process via {@link #getInputStream()}.
*
* @param _shellCommand The command for the shell to execute.
* @param shellCommand The command for the shell to execute.
*/
public void execute(String shellCommand) {
execute(shellCommand, NO_CONSUME_OUTPUT, NO_WAIT_FOR_EXIT_STATUS);
@ -199,7 +198,7 @@ public class ShellCommand {
* Input can be passed to the <code>STDIN</code> of the shell process via
* {@link #getInputStream()}.
*
* @param _shellCommand The command for the shell to execute.
* @param shellCommand The command for the shell to execute.
* @return <code>true</code> if the spawned shell process
* returns an exit status of 0 (indicating success),
* else <code>false</code>.
@ -221,7 +220,7 @@ public class ShellCommand {
* {@link #getErrorStream()}, respectively. Input can be passed to the
* <code>STDIN</code> of the shell process via {@link #getInputStream()}.
*
* @param _shellCommand The command for the shell to execute.
* @param shellCommand The command for the shell to execute.
* @param seconds The method will return <code>true</code> if this
* number of seconds elapses without the process
* returning an exit status. A value of <code>0</code>
@ -256,7 +255,7 @@ public class ShellCommand {
* without waiting for an exit status. Any output produced by the executed
* command will not be displayed.
*
* @param _shellCommand The command for the shell to execute.
* @param shellCommand The command for the shell to execute.
* @throws IOException
*/
public void executeSilent(String shellCommand) throws IOException {
@ -268,7 +267,7 @@ public class ShellCommand {
* all of the command's resulting shell processes have completed. Any output
* produced by the executed command will not be displayed.
*
* @param _shellCommand The command for the shell to execute.
* @param shellCommand The command for the shell to execute.
* @return <code>true</code> if the spawned shell process
* returns an exit status of 0 (indicating success),
* else <code>false</code>.
@ -287,7 +286,7 @@ public class ShellCommand {
* specified number of seconds has elapsed first. Any output produced by the
* executed command will not be displayed.
*
* @param _shellCommand The command for the shell to execute.
* @param shellCommand The command for the shell to execute.
* @param seconds The method will return <code>true</code> if this
* number of seconds elapses without the process
* returning an exit status. A value of <code>0</code>
@ -356,7 +355,6 @@ public class ShellCommand {
processStdoutReader = new StreamReader(_inputStream);
processStdoutReader.start();
}
if (waitForExitStatus) {
try {
_process.waitFor();
@ -374,7 +372,6 @@ public class ShellCommand {
if (_process.exitValue() > 0)
return false;
}
} catch (Exception e) {
return false;
}

View File

@ -25,7 +25,7 @@ public class SysTray implements SysTrayMenuListener {
private BrowserChooser _browserChooser;
private String _browserString;
private ConfigFile _configFile = new ConfigFile("../systray.config");
private ConfigFile _configFile = new ConfigFile();
private Frame _frame;
private SysTrayMenuItem _itemExit = new SysTrayMenuItem("Exit I2P systray", "exit");
private SysTrayMenuItem _itemSelectBrowser = new SysTrayMenuItem("Select preferred browser...", "selectbrowser");
@ -34,7 +34,12 @@ public class SysTray implements SysTrayMenuListener {
private UrlLauncher _urlLauncher = new UrlLauncher();
public SysTray() {
if (!_configFile.init("../systray.config"))
_configFile.setProperty("browser", "default");
_browserString = _configFile.getProperty("browser", "default");
_sysTrayMenuIcon.addSysTrayMenuListener(this);
createSysTrayMenu();
}