added comparison of default and current external tools settings

This commit is contained in:
fros4943 2007-03-22 16:41:50 +00:00
parent 2babc1c0ee
commit 1da6d10730
2 changed files with 35 additions and 3 deletions

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.25 2007/03/22 16:17:01 fros4943 Exp $ * $Id: GUI.java,v 1.26 2007/03/22 16:41:50 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -130,6 +130,7 @@ public class GUI {
private static Logger logger = Logger.getLogger(GUI.class); private static Logger logger = Logger.getLogger(GUI.class);
// External tools setting names // External tools setting names
private static Properties defaultExternalToolsSettings;
private static Properties currentExternalToolsSettings; private static Properties currentExternalToolsSettings;
private static final String externalToolsSettingNames[] = new String[] { private static final String externalToolsSettingNames[] = new String[] {
@ -1990,6 +1991,17 @@ public class GUI {
return currentExternalToolsSettings.getProperty(name, defaultValue); return currentExternalToolsSettings.getProperty(name, defaultValue);
} }
/**
* @param name
* Name of setting
* @param defaultValue
* Default value
* @return Value
*/
public static String getExternalToolsDefaultSetting(String name, String defaultValue) {
return defaultExternalToolsSettings.getProperty(name, defaultValue);
}
/** /**
* @param name * @param name
* Name of setting * Name of setting
@ -2018,12 +2030,14 @@ public class GUI {
in.close(); in.close();
currentExternalToolsSettings = settings; currentExternalToolsSettings = settings;
defaultExternalToolsSettings = (Properties) currentExternalToolsSettings.clone();
} catch (IOException e) { } catch (IOException e) {
// Error while importing default properties // Error while importing default properties
logger.warn( logger.warn(
"Error when reading external tools settings from " + filename, e); "Error when reading external tools settings from " + filename, e);
} finally { } finally {
if (currentExternalToolsSettings == null) { if (currentExternalToolsSettings == null) {
defaultExternalToolsSettings = new Properties();
currentExternalToolsSettings = new Properties(); currentExternalToolsSettings = new Properties();
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ExternalToolsDialog.java,v 1.1 2006/08/21 12:13:01 fros4943 Exp $ * $Id: ExternalToolsDialog.java,v 1.2 2007/03/22 16:41:50 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -133,6 +133,7 @@ public class ExternalToolsDialog extends JDialog {
// Set actual used values into all text fields // Set actual used values into all text fields
updateTextFields(); updateTextFields();
compareWithDefaults();
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
@ -149,6 +150,22 @@ public class ExternalToolsDialog extends JDialog {
} }
} }
private void compareWithDefaults() {
for (int i = 0; i < GUI.getExternalToolsSettingsCount(); i++) {
String currentValue = textFields[i].getText();
// Compare with default value
String defaultValue = GUI.getExternalToolsDefaultSetting(GUI.getExternalToolsSettingName(i), "");
if (currentValue.equals(defaultValue)) {
textFields[i].setBackground(Color.WHITE);
textFields[i].setToolTipText("");
} else {
textFields[i].setBackground(Color.LIGHT_GRAY);
textFields[i].setToolTipText("Default value: " + defaultValue);
}
}
}
private class ExternalToolsEventHandler private class ExternalToolsEventHandler
implements implements
ActionListener, ActionListener,
@ -157,12 +174,13 @@ public class ExternalToolsDialog extends JDialog {
// NOP // NOP
} }
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
// NOP compareWithDefaults();
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("reset")) { if (e.getActionCommand().equals("reset")) {
GUI.loadExternalToolsDefaultSettings(); GUI.loadExternalToolsDefaultSettings();
updateTextFields(); updateTextFields();
compareWithDefaults();
} else if (e.getActionCommand().equals("ok")) { } else if (e.getActionCommand().equals("ok")) {
for (int i = 0; i < GUI.getExternalToolsSettingsCount(); i++) { for (int i = 0; i < GUI.getExternalToolsSettingsCount(); i++) {
GUI.setExternalToolsSetting(GUI.getExternalToolsSettingName(i), textFields[i].getText() GUI.setExternalToolsSetting(GUI.getExternalToolsSettingName(i), textFields[i].getText()