001: /*
002: * Created on 10/02/2005
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2004 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023: package br.com.gfp.windows.config;
024:
025: import java.io.File;
026: import java.io.FileInputStream;
027: import java.io.FileNotFoundException;
028: import java.io.FileOutputStream;
029: import java.io.IOException;
030: import java.util.Properties;
031:
032: /**
033: * Esta classe é responsável por guardar a configuração de localização
034: * no disco local da maquina do usuário.
035: * @author Igor Regis da Silva Simoes
036: * @since 10/02/2005 17:45:21
037: */
038: public class RedeConf {
039: private Properties redeFile = new Properties();
040:
041: private File arquivo = new File(System.getProperty("user.dir")
042: + File.separator + "rede.conf");
043:
044: private boolean empty = true;
045:
046: /**
047: *
048: * @throws FileNotFoundException
049: */
050: public RedeConf() throws IOException {
051: if (!arquivo.exists()) {
052: arquivo.createNewFile();
053: } else {
054: FileInputStream fis = new FileInputStream(arquivo);
055: redeFile.load(fis);
056: empty = false;
057: fis.close();
058: }
059: }
060:
061: /**
062: * Determina o nome/endereço do proxy a ser usado para acessar a rede
063: * @param country
064: */
065: public void setUseProxy(Boolean use) {
066: redeFile.setProperty("proxy", use.toString());
067: empty = false;
068: }
069:
070: /**
071: * Determina o nome/endereço do proxy a ser usado para acessar a rede
072: * @param proxy
073: */
074: public void setProxy(String proxy) {
075: redeFile.setProperty("proxy.name", proxy);
076: empty = false;
077: }
078:
079: /**
080: * Determina a porta em que o proxy atende
081: * @param port
082: */
083: public void setProxyPort(Integer port) {
084: redeFile.setProperty("proxy.port", port.toString());
085: empty = false;
086: }
087:
088: /**
089: * Determina o usário usado para acessar o proxy
090: * @param user
091: */
092: public void setProxyUser(String user) {
093: redeFile.setProperty("proxy.user", user);
094: empty = false;
095: }
096:
097: /**
098: * Determina o usário usado para acessar o proxy
099: * @return user
100: */
101: public String getProxyUser() {
102: return redeFile.getProperty("proxy.user");
103: }
104:
105: /**
106: * Determina o nome/endereço do proxy a ser usado para acessar a rede
107: * @return String
108: */
109: public Boolean getUseProxy() {
110: String value = redeFile.getProperty("proxy");
111: value = value == null ? "false" : value;
112: return Boolean.valueOf(value);
113: }
114:
115: /**
116: * Determina o nome/endereço do proxy a ser usado para acessar a rede
117: * @return String
118: */
119: public String getProxy() {
120: return redeFile.getProperty("proxy.name");
121: }
122:
123: /**
124: * Determina a porta em que o proxy atende
125: * @return String
126: */
127: public Integer getProxyPort() {
128: String value = redeFile.getProperty("proxy.port");
129: value = value == null ? "0" : value;
130: return Integer.valueOf(value);
131: }
132:
133: /**
134: * Determina se é necessário usário para acessar o proxy
135: * @return String
136: */
137: public Boolean getNeedUser() {
138: String value = redeFile.getProperty("need.user");
139: value = value == null ? "false" : value;
140: return Boolean.valueOf(value);
141: }
142:
143: /**
144: * Determina se é necessário usário para acessar o proxy
145: * @param need
146: *
147: */
148: public void setNeedUser(Boolean need) {
149: redeFile.setProperty("need.user", need.toString());
150: empty = false;
151: }
152:
153: /**
154: * Salva os dados em um arquivo de configuração
155: * @throws IOException
156: */
157: public void saveData() throws IOException {
158: FileOutputStream fos = new FileOutputStream(arquivo);
159: redeFile.store(fos, null);
160: fos.flush();
161: fos.close();
162: }
163:
164: /**
165: * Indica que as configurações ainda nao foram setadas
166: * @return
167: */
168: public boolean isEmpty() {
169: return empty;
170: }
171:
172: }
|