* a missing systray.config file is now handled gracefully
* fixed javadoc warnings
This commit is contained in:
@ -39,7 +39,7 @@
|
|||||||
<mkdir dir="./build/javadoc" />
|
<mkdir dir="./build/javadoc" />
|
||||||
<javadoc
|
<javadoc
|
||||||
sourcepath="./src"
|
sourcepath="./src"
|
||||||
classpath="./src:./src/net/i2p/apps/systray/systray4j.jar"
|
classpath="./src:./src/net/i2p/apps/systray/lib/systray4j.jar"
|
||||||
destdir="./build/javadoc"
|
destdir="./build/javadoc"
|
||||||
packagenames="*"
|
packagenames="*"
|
||||||
use="true"
|
use="true"
|
||||||
|
@ -17,17 +17,24 @@ import java.util.Properties;
|
|||||||
* Simple config file handler.
|
* Simple config file handler.
|
||||||
*
|
*
|
||||||
* @author hypercubus
|
* @author hypercubus
|
||||||
*
|
|
||||||
* TODO Make write operations keep original line comments intact.
|
|
||||||
*/
|
*/
|
||||||
public class ConfigFile {
|
public class ConfigFile {
|
||||||
|
|
||||||
|
// TODO Make write operations keep original line comments intact.
|
||||||
|
|
||||||
private String _configFile;
|
private String _configFile;
|
||||||
private Properties _properties = new Properties();
|
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;
|
_configFile = configFile;
|
||||||
readConfigFile();
|
return readConfigFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProperty(String key) {
|
public String getProperty(String key) {
|
||||||
@ -43,7 +50,7 @@ public class ConfigFile {
|
|||||||
writeConfigFile();
|
writeConfigFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readConfigFile() {
|
private boolean readConfigFile() {
|
||||||
|
|
||||||
FileInputStream fileInputStream = null;
|
FileInputStream fileInputStream = null;
|
||||||
|
|
||||||
@ -51,16 +58,18 @@ public class ConfigFile {
|
|||||||
fileInputStream = new FileInputStream(_configFile);
|
fileInputStream = new FileInputStream(_configFile);
|
||||||
_properties.load(fileInputStream);
|
_properties.load(fileInputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
fileInputStream.close();
|
fileInputStream.close();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
// No worries.
|
// No worries.
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeConfigFile() {
|
private void writeConfigFile() {
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = null;
|
FileOutputStream fileOutputStream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -61,7 +61,6 @@ public class ShellCommand {
|
|||||||
synchronized(caller) {
|
synchronized(caller) {
|
||||||
caller.notify(); // In case the caller is still in the wait() state.
|
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
|
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
||||||
* <code>STDIN</code> of the shell process via {@link #getInputStream()}.
|
* <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) {
|
public void execute(String shellCommand) {
|
||||||
execute(shellCommand, NO_CONSUME_OUTPUT, NO_WAIT_FOR_EXIT_STATUS);
|
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
|
* Input can be passed to the <code>STDIN</code> of the shell process via
|
||||||
* {@link #getInputStream()}.
|
* {@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
|
* @return <code>true</code> if the spawned shell process
|
||||||
* returns an exit status of 0 (indicating success),
|
* returns an exit status of 0 (indicating success),
|
||||||
* else <code>false</code>.
|
* else <code>false</code>.
|
||||||
@ -221,7 +220,7 @@ public class ShellCommand {
|
|||||||
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
||||||
* <code>STDIN</code> of the shell process via {@link #getInputStream()}.
|
* <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
|
* @param seconds The method will return <code>true</code> if this
|
||||||
* number of seconds elapses without the process
|
* number of seconds elapses without the process
|
||||||
* returning an exit status. A value of <code>0</code>
|
* 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
|
* without waiting for an exit status. Any output produced by the executed
|
||||||
* command will not be displayed.
|
* 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
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void executeSilent(String shellCommand) 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
|
* all of the command's resulting shell processes have completed. Any output
|
||||||
* produced by the executed command will not be displayed.
|
* 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
|
* @return <code>true</code> if the spawned shell process
|
||||||
* returns an exit status of 0 (indicating success),
|
* returns an exit status of 0 (indicating success),
|
||||||
* else <code>false</code>.
|
* else <code>false</code>.
|
||||||
@ -287,7 +286,7 @@ public class ShellCommand {
|
|||||||
* specified number of seconds has elapsed first. Any output produced by the
|
* specified number of seconds has elapsed first. Any output produced by the
|
||||||
* executed command will not be displayed.
|
* 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
|
* @param seconds The method will return <code>true</code> if this
|
||||||
* number of seconds elapses without the process
|
* number of seconds elapses without the process
|
||||||
* returning an exit status. A value of <code>0</code>
|
* returning an exit status. A value of <code>0</code>
|
||||||
@ -356,7 +355,6 @@ public class ShellCommand {
|
|||||||
processStdoutReader = new StreamReader(_inputStream);
|
processStdoutReader = new StreamReader(_inputStream);
|
||||||
processStdoutReader.start();
|
processStdoutReader.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waitForExitStatus) {
|
if (waitForExitStatus) {
|
||||||
try {
|
try {
|
||||||
_process.waitFor();
|
_process.waitFor();
|
||||||
@ -374,7 +372,6 @@ public class ShellCommand {
|
|||||||
if (_process.exitValue() > 0)
|
if (_process.exitValue() > 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class SysTray implements SysTrayMenuListener {
|
|||||||
|
|
||||||
private BrowserChooser _browserChooser;
|
private BrowserChooser _browserChooser;
|
||||||
private String _browserString;
|
private String _browserString;
|
||||||
private ConfigFile _configFile = new ConfigFile("../systray.config");
|
private ConfigFile _configFile = new ConfigFile();
|
||||||
private Frame _frame;
|
private Frame _frame;
|
||||||
private SysTrayMenuItem _itemExit = new SysTrayMenuItem("Exit I2P systray", "exit");
|
private SysTrayMenuItem _itemExit = new SysTrayMenuItem("Exit I2P systray", "exit");
|
||||||
private SysTrayMenuItem _itemSelectBrowser = new SysTrayMenuItem("Select preferred browser...", "selectbrowser");
|
private SysTrayMenuItem _itemSelectBrowser = new SysTrayMenuItem("Select preferred browser...", "selectbrowser");
|
||||||
@ -34,7 +34,12 @@ public class SysTray implements SysTrayMenuListener {
|
|||||||
private UrlLauncher _urlLauncher = new UrlLauncher();
|
private UrlLauncher _urlLauncher = new UrlLauncher();
|
||||||
|
|
||||||
public SysTray() {
|
public SysTray() {
|
||||||
|
|
||||||
|
if (!_configFile.init("../systray.config"))
|
||||||
|
_configFile.setProperty("browser", "default");
|
||||||
|
|
||||||
_browserString = _configFile.getProperty("browser", "default");
|
_browserString = _configFile.getProperty("browser", "default");
|
||||||
|
|
||||||
_sysTrayMenuIcon.addSysTrayMenuListener(this);
|
_sysTrayMenuIcon.addSysTrayMenuListener(this);
|
||||||
createSysTrayMenu();
|
createSysTrayMenu();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user