001    /*
002        Copyright (C) 2003 Adam Olsen
003    
004            This program is free software; you can redistribute it and/or modify
005        it under the terms of the GNU General Public License as published by
006        the Free Software Foundation; either version 1, or (at your option)
007        any later version.
008    
009        This program is distributed in the hope that it will be useful,
010        but WITHOUT ANY WARRANTY; without even the implied warranty of
011        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012        GNU General Public License for more details.
013    
014        You should have received a copy of the GNU General Public License
015        along with this program; if not, write to the Free Software
016        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
017    */
018    
019    package com.valhalla.settings;
020    
021    import java.io.*;
022    import java.util.*;
023    
024    public class SettingsProperties extends Properties
025    {
026            /**
027             * Sets a boolean
028             * @param key the key to set
029             * @param value the value to set the key to
030            **/
031            public void setBoolean( String key, boolean value )
032            {
033                    if( value ) setProperty( key, "true" );
034                    else remove( key );
035            }
036    
037            /**
038             * Gets a boolean value
039             * @param key the key to get a boolean for
040             * @return a boolean based on the key
041            **/
042            public boolean getBoolean( String key )
043            {
044                    return ( getProperty( key  ) != null );
045            }
046    
047            public void loadSettings( String file ) throws FileNotFoundException, IOException
048            {
049                    File f = new File( file );
050                    InputStream stream = new FileInputStream( f );
051                    load( stream );
052                    stream.close();
053            }
054    
055            public void saveSettings( String file, String comments ) throws IOException
056            {
057                    File f = new File( file );
058                    OutputStream stream = new FileOutputStream( f );
059                    store( stream, comments );
060                    stream.close();
061            }
062    }