- Timestamp:
- 07/22/07 02:54:29 (5 years ago)
- Location:
- mymrc/trunk/Java-client
- Files:
-
- 8 added
- 4 removed
- 8 modified
-
dist (added)
-
dist/myMRC.jad (added)
-
dist/myMRC.jar (added)
-
src/images/icon.png (added)
-
src/images/mymrc.png (modified) (previous)
-
src/org/myMRC/control/Controller.java (modified) (11 diffs)
-
src/org/myMRC/events/Content.java (modified) (6 diffs)
-
src/org/myMRC/events/Opcode.java (modified) (1 diff)
-
src/org/myMRC/myMRC.java (modified) (4 diffs)
-
src/org/myMRC/net/BluetoothController.java (added)
-
src/org/myMRC/net/CommunicationController.java (deleted)
-
src/org/myMRC/net/InetController.java (added)
-
src/org/myMRC/net/NetworkController.java (added)
-
src/org/myMRC/net/Receiver.java (modified) (6 diffs)
-
src/org/myMRC/net/RequestTable.java (deleted)
-
src/org/myMRC/parser/FormParser.java (modified) (4 diffs)
-
src/org/myMRC/settings/ConfigParserException.java (deleted)
-
src/org/myMRC/settings/Configuration.java (modified) (2 diffs)
-
src/org/myMRC/settings/ConfigurationConnection.java (deleted)
-
src/org/myMRC/settings/Settings.java (added)
Legend:
- Unmodified
- Added
- Removed
-
mymrc/trunk/Java-client/src/org/myMRC/control/Controller.java
r20 r32 10 10 import org.myMRC.*; 11 11 import org.myMRC.events.*; 12 import org.myMRC.net.CommunicationController; 12 import org.myMRC.net.BluetoothController; 13 import org.myMRC.net.InetController; 14 import org.myMRC.net.NetworkController; 13 15 import org.myMRC.parser.*; 14 16 import org.myMRC.screen.*; … … 31 33 private PlaybackCanvas canvas; 32 34 private Display display; 33 private CommunicationController communicator; 34 private ConfigurationConnection confcon; 35 private NetworkController communicator; 35 36 private Configuration config; 36 37 private ListParser listParser; … … 78 79 } 79 80 80 81 public MIDlet getMidlet() { return this.myMRC; } 81 82 82 83 /** Creates a new instance of Controller */ … … 86 87 canvas = new PlaybackCanvas(); 87 88 display = Display.getDisplay(myMRC); 88 communicator = CommunicationController.getInstance(); 89 confcon = ConfigurationConnection.getInstance(); 90 config = Configuration.getInstance(); 89 90 try { 91 config = Configuration.createInstance(); 92 } catch (Exception e) { 93 e.printStackTrace(); 94 AlertScreen alert = new AlertScreen(null, Opcode.IOP_START, display.getCurrent()); 95 alert.setTimeout(alert.FOREVER); 96 alert.setString("Error while loading settings:\n" + e.getMessage()); 97 display.setCurrent(alert); 98 } 99 91 100 listParser = new ListParser(list); 92 101 formParser = new FormParser(form); 93 102 canvasParser = new CanvasParser(canvas); 103 94 104 } 95 105 … … 125 135 public void setScreen(Displayable screen) { 126 136 display.setCurrent(screen); 137 } 138 139 /** 140 * Returns the currently displayed screen element. 141 * @return Currently displayed screen element. 142 */ 143 public Displayable getCurrentScreen() { 144 return display.getCurrent(); 127 145 } 128 146 … … 212 230 this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START_CONNECTED); 213 231 } 232 214 233 break; 215 234 216 235 case Opcode.IOP_CONNECT: 217 /* 218 * We have to use a separate thread to start the 219 * CommunicationController. 220 */ 221 if (!communicator.isAlive()) { 222 ConnectionStarter comstarter = new ConnectionStarter(this.display); 223 comstarter.start(); 224 } else { 225 communicator.send(Opcode.OP_HELLO, null); 236 switch (Util.atoi(config.get(Settings.CONNECTION_TYPE))) { 237 case Settings.CONN_BLUETOOTH: 238 this.communicator = BluetoothController.getInstance(); 239 break; 240 241 case Settings.CONN_INET: 242 /* 243 * We have to use a separate thread to start the 244 * InetController. 245 */ 246 247 /* 248 * W A R N I N G 249 * FIXME/CHECKME - I changed the whole net.*Controller 250 * stuff, and this here hasn't been tested yet, 251 * so it should be done :) 252 */ 253 this.communicator = InetController.getInstance(); // <-- !! 254 255 if (!communicator.isAlive()) { 256 ConnectionStarter comstarter = new ConnectionStarter(this.display); 257 comstarter.start(); 258 } else { 259 communicator.send(Opcode.OP_HELLO, null); 260 } 261 262 break; 226 263 } 227 264 break; … … 238 275 239 276 case Opcode.IOP_DISCONNECT: 240 communicator.destroy(); 241 this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START_DISCONNECTED); 277 try { 278 communicator.close(); 279 this.handle(Opcode.IOP_PARSEFORM, Content.CONT_START_DISCONNECTED); 280 } catch (IOException ioe) { 281 ioe.printStackTrace(); 282 } 283 break; 284 285 case Opcode.IOP_BT_GET_DEVICES: 286 case Opcode.IOP_BT_GET_DEV_CANCEL: 287 case Opcode.IOP_BT_DEVICE_DETAILS: 288 case Opcode.IOP_BT_GET_SERVICES: 289 case Opcode.IOP_BT_SERVICES_DETAILS: 290 case Opcode.IOP_BT_CONNECT: 291 /* distribute to BluetoothController */ 292 BluetoothController.getInstance().handleBTopcode(opcode, data); 242 293 break; 243 294 … … 251 302 252 303 case Opcode.IOP_SETTINGS_SAVE: 253 config.writeSettings(form);304 //config.writeSettings(form); 254 305 try { 255 conf con.getInstance().save();256 } catch ( IOException ioe) {257 ioe.printStackTrace();306 config.setFromForm(form); 307 } catch (Exception e) { 308 e.printStackTrace(); 258 309 alert.setTimeout(alert.FOREVER); 259 alert.setString("Error while saving settings:\n" + ioe.getMessage());310 alert.setString("Error while saving settings:\n" + e.getMessage()); 260 311 display.setCurrent(alert); 261 312 break; … … 272 323 case Opcode.IOP_INT_EXIT: 273 324 if (communicator.isAlive()) { 274 communicator.destroy(); // FIXME: does it work? 325 try { 326 communicator.close(); // FIXME: does it work? 327 } catch (IOException ioe) { 328 ioe.printStackTrace(); 329 } 275 330 } 276 331 Controller.killEmAll(); … … 296 351 public void run() { 297 352 /* hum, emulator doesn't react here sometimes anymore */ 353 String url = "socket://" + 354 Configuration.getInstance().get(Settings.INET_SERVER_HOST) + ":" + 355 Configuration.getInstance().get(Settings.INET_SERVER_PORT); 298 356 try { 299 CommunicationController.getInstance().open( 300 "socket://" + Configuration.getInstance().getServerString()); 357 InetController.getInstance().open(url); 301 358 } catch (Exception e) { 302 359 AlertScreen alert = new AlertScreen("Connection failed!", 990, display.getCurrent()); … … 305 362 return; 306 363 } 307 CommunicationController.getInstance().send(Opcode.OP_HELLO, null);364 InetController.getInstance().send(Opcode.OP_HELLO, null); 308 365 } 309 366 } -
mymrc/trunk/Java-client/src/org/myMRC/events/Content.java
r20 r32 1 1 package org.myMRC.events; 2 2 3 import org.myMRC.net.CommunicationController;4 3 /* 5 4 * Content.java … … 7 6 * Created on June 29, 2007, 1:08 AM 8 7 */ 9 8 import org.myMRC.net.InetController; 9 import org.myMRC.settings.Settings; 10 10 11 11 /** … … 24 24 "<form label=\"myMRC 0.1\">" + 25 25 " <image file=\"mymrc.png\"/>" + 26 " <string label=\"Not Connected\"/>" +26 " <string text=\"Not Connected\"/>" + 27 27 " <command label=\"Connect\" opcode=\"0" + Opcode.IOP_CONNECT + "\"/>" + 28 28 " <command label=\"Settings\" opcode=\"0" + Opcode.IOP_SETTINGS + "\"/>" + … … 35 35 "<form label=\"myMRC 0.1\">" + 36 36 " <image file=\"mymrc.png\"/>" + 37 " <string label=\"Connection lost!\"/>" +37 " <string text=\"Connection lost!\"/>" + 38 38 " <command label=\"Connect\" opcode=\"0" + Opcode.IOP_CONNECT + "\"/>" + 39 39 " <command label=\"Settings\" opcode=\"0" + Opcode.IOP_SETTINGS + "\"/>" + … … 57 57 public static final String CONT_SETTINGS = 58 58 "<form label=\"Settings\">" + 59 " <textfield setting=\"serverHost\" label=\"Server Host\" size=\"20\"/>" + 60 " <textfield setting=\"serverPort\" label=\"Server Port\" type=\"number\" size=\"5\"/>" + 59 " <select type=\"exclusive\" label=\"Connection Type\" setting=\"" + Settings.CONNECTION_TYPE + "\">" + 60 " <option value=\"" + Settings.CONN_BLUETOOTH + "\" label=\"Bluetooth\"/>" + 61 " <option value=\"" + Settings.CONN_INET + "\" label=\"Internet Socket\"/>" + 62 " </select>" + 63 " <spacer height=\"5\"/>" + 64 " <textfield setting=\"" + Settings.INET_SERVER_HOST + "\" label=\"Inet Server Host\" size=\"20\"/>" + 65 " <textfield setting=\"" + Settings.INET_SERVER_PORT + "\" label=\"Inet Server Port\" type=\"number\" size=\"5\"/>" + 66 " <spacer height=\"5\"/>" + 67 " <textfield setting=\"" + Settings.BT_SERVER_ADDR + "\" label=\"Bluetooth Server Address\" size=\"20\"/>" + 68 " <textfield setting=\"" + Settings.BT_SERVER_PORT + "\" label=\"Bluetooth Server Port\" type=\"number\" size=\"5\"/>" + 61 69 " <command type=\"back\" label=\"Cancel\" opcode=\"0" + Opcode.IOP_START + "\"/>" + 62 70 " <command label=\"Save\" opcode=\"0" + Opcode.IOP_SETTINGS_SAVE + "\"/>" + … … 65 73 public static final String CONT_ABOUT = 66 74 "<form label=\"About\">" + 67 " <string label=\"myMRC 0.1\"/>" + 68 " <string label=\"(c) 2007 Sven Gregori and Damien Lefevre\"/>" + 75 " <string label=\"myMRC 0.1\" text=\"(c) 2007 Sven Gregori and Damien Lefevre\"/>" + 76 " <string label=\"\" text=\"For documentation, updates, source code, etc. please visit http://www.mymrc.org/\"/>" + 77 " <string label=\"\" text=\"myMRC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.\"/>" + 78 " <string label=\"\" text=\"myMRC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\"/>" + 69 79 " <command type=\"back\" label=\"Ok\" opcode=\"0" + Opcode.IOP_START + "\"/>" + 70 80 "</form>"; -
mymrc/trunk/Java-client/src/org/myMRC/events/Opcode.java
r20 r32 43 43 public static final int IOP_SETTINGS = 920; 44 44 public static final int IOP_SETTINGS_SAVE = 921; 45 public static final int IOP_CONNECT = 990; 46 public static final int IOP_DISCONNECT_CONF = 991; 47 public static final int IOP_DISCONNECT_FORCED = 992; 48 public static final int IOP_DISCONNECT = 993; 45 public static final int IOP_CONNECT = 950; 46 public static final int IOP_DISCONNECT_CONF = 951; 47 public static final int IOP_DISCONNECT_FORCED = 952; 48 public static final int IOP_DISCONNECT = 953; 49 public static final int IOP_BT_GET_DEVICES = 960; 50 public static final int IOP_BT_GET_DEV_CANCEL = 961; 51 public static final int IOP_BT_DEVICE_DETAILS = 962; 52 public static final int IOP_BT_GET_SERVICES = 963; 53 public static final int IOP_BT_SERVICES_DETAILS = 964; 54 public static final int IOP_BT_CONNECT = 965; 49 55 public static final int IOP_INT_EXIT_CONF = 998; 50 56 public static final int IOP_INT_EXIT = 999; -
mymrc/trunk/Java-client/src/org/myMRC/myMRC.java
r22 r32 11 11 import org.myMRC.events.Content; 12 12 import org.myMRC.events.Opcode; 13 import org.myMRC.net.CommunicationController; 13 import org.myMRC.net.BluetoothController; 14 import org.myMRC.net.InetController; 14 15 import org.myMRC.settings.*; 15 16 import org.myMRC.control.Controller; … … 31 32 */ 32 33 public myMRC() { 33 34 try {35 ConfigurationConnection ccon = ConfigurationConnection.createInstance();36 ccon.load();37 } catch (IOException ioe) {38 ioe.printStackTrace();39 } catch (ConfigParserException cpe) {40 cpe.printStackTrace();41 }42 43 34 Controller.createInstance(this); 44 35 Controller.getInstance().handle(Opcode.IOP_PARSEFORM, Content.CONT_START); … … 51 42 public void exitMIDlet() { 52 43 try { 53 if (CommunicationController.getInstance().isAlive()) { 54 CommunicationController.getInstance().close(); 44 if (InetController.getInstance().isAlive()) { 45 InetController.getInstance().close(); 46 } 47 if (BluetoothController.getInstance().isAlive()) { 48 BluetoothController.getInstance().close(); 55 49 } 56 50 } catch (IOException ioe) { … … 61 55 } 62 56 63 CommunicationController.destroy();57 //InetController.getInstance().destroy(); 64 58 65 59 Display.getDisplay(this).setCurrent(null); -
mymrc/trunk/Java-client/src/org/myMRC/net/Receiver.java
r15 r32 7 7 import java.io.*; 8 8 import org.myMRC.Util; 9 import org.myMRC.control.Controller; 9 10 10 11 /** 11 12 * Handles all incoming network traffic. Works together with the 12 * CommunicationController.13 * 13 * InetController and BluetoothController. 14 * 14 15 * @author Sven Gregori 15 16 */ 16 17 class Receiver extends Thread { 17 18 private boolean doRun; 18 private CommunicationController controller;19 19 private InputStream istream; 20 private NetworkController controller; 20 21 21 22 private final int READBUF_SIZE = 512; 22 23 static final int EVENTID_SIZE = 4; 24 static final int DATABUF_SIZE = 16; 23 25 24 26 25 27 /** 26 28 * Creates a new instance of Receiver. 27 * 28 * @param controller Reference to the CommunicationController which29 * 30 * @param controller Reference to the InetController which 29 31 * creates this object. 30 32 * @param istream InputStream object from the socket to the server 31 33 */ 32 Receiver( CommunicationController controller, InputStream istream) {34 Receiver(NetworkController controller, InputStream istream) { 33 35 this.doRun = true; 34 36 this.controller = controller; … … 36 38 } 37 39 40 38 41 /** 39 42 * Thread run method. 40 43 * Waits all the time for data from the server. After receiving data it 41 * calls the handleReceived method from the CommunicationController.44 * calls the handleReceived method from the InetController. 42 45 */ 43 46 public void run() { 44 47 while (doRun) { 48 Controller c = Controller.getInstance(); 49 org.myMRC.screen.AlertScreen alert = new org.myMRC.screen.AlertScreen(null, 0, c.getCurrentScreen()); 50 if (istream == null) { 51 alert.setString("fuck, istream is null"); 52 c.setScreen(alert); 53 break; 54 } 55 56 StringBuffer buf = null; 57 String eventId = "-"; 45 58 try { 46 StringBuffer buf = new StringBuffer(); 47 String eventId = read(buf); 59 //StringBuffer buf = new StringBuffer(); 60 buf = new StringBuffer(); 61 //String eventId = read(buf); 62 eventId = read(buf); 48 63 if (eventId != null) { 49 controller.handleReceived(eventId, buf.toString()); 64 controller.resetCounter(); 65 Controller.getInstance().handle(Util.atoi(eventId), buf.toString()); 50 66 } 51 67 … … 54 70 } catch (IOException ioe) { 55 71 ioe.printStackTrace(); 72 } catch (Exception e) { 73 alert.setTimeout(javax.microedition.lcdui.Alert.FOREVER); 74 alert.setString(e.getClass().toString() + " in Receiver: " + e.getMessage() + 75 " istream = " + istream + " buf = " + buf.toString() + 76 " eventId = " + eventId); 77 c.setScreen(alert); 56 78 } 57 79 } … … 67 89 * @return Event ID of the read data 68 90 */ 69 private String read(StringBuffer buf) throws IOException, IndexOutOfBoundsException {70 byte[] eventId = new byte[ controller.EVENTID_SIZE];71 byte[] dSize = new byte[ controller.DATABUF_SIZE];91 private String read(StringBuffer buf) throws IOException, IndexOutOfBoundsException, NullPointerException { 92 byte[] eventId = new byte[EVENTID_SIZE]; 93 byte[] dSize = new byte[DATABUF_SIZE]; 72 94 byte[] readBuf = new byte[READBUF_SIZE]; 73 95 … … 76 98 77 99 /* First read the event ID from the server */ 78 if (istream.read(eventId, 0, controller.EVENTID_SIZE) == -1) {100 if (istream.read(eventId, 0, EVENTID_SIZE) == -1) { 79 101 doRun = false; 80 102 return null; … … 96 118 * larger than 10 petabyte ;p 97 119 */ 98 if ( (readSize = istream.read(dSize, 0, controller.DATABUF_SIZE)) == -1) {120 if ( (readSize = istream.read(dSize, 0, DATABUF_SIZE)) == -1) { 99 121 doRun = false; 100 122 return null; -
mymrc/trunk/Java-client/src/org/myMRC/parser/FormParser.java
r20 r32 95 95 96 96 String label = parser.getAttributeValue(null, "label"); 97 String setting = parser.getAttributeValue(null, "setting");97 int setting = Util.atoi(parser.getAttributeValue(null, "setting")); 98 98 int size = Util.atoi(parser.getAttributeValue(null, "width")); 99 99 if (size == 0) { 100 100 size = DEFAULT_TEXTFIELD_SIZE; 101 101 } 102 String text = config.getSettingString(setting); 102 103 String text = config.get(setting); 103 104 form.append(new TextField(label, text, size, constraints)); 104 105 … … 142 143 ChoiceGroup select = new ChoiceGroup( 143 144 parser.getAttributeValue(null, "label"), selectType); 144 String setting = parser.getAttributeValue(null, "setting");145 int setting = Util.atoi(parser.getAttributeValue(null, "setting")); 145 146 while (!(parser.next() == XmlPullParser.END_TAG && 146 147 parser.getName() != null && … … 179 180 * structure and stores it in the given ChoiceGroup object. Sets also the 180 181 * selected option (if any) as selected. 181 * 182 * 182 183 * @param select ChoiceGroup object to fill 183 184 * @param setting String representation of the variable from the 184 * Co nfiguration class which the ChoiceGroup is handling185 * CoConfigurationXlass which the ChoiceGroup is handling 185 186 * @throws XmlPullParserException if an Exception from the underlying XML 186 187 * parser occurs. 187 188 */ 188 private void createSelectOptions(ChoiceGroup select, Stringsetting)189 private void createSelectOptions(ChoiceGroup select, int setting) 189 190 throws XmlPullParserException 190 191 { … … 192 193 if (parser.getName().equalsIgnoreCase("option")) { 193 194 String value = parser.getAttributeValue(null, "value"); 195 String label = parser.getAttributeValue(null, "label"); 194 196 /* 195 197 * TODO: add pictures in choicegroup (e.g. flags in language 196 198 * choice, could look neat :> 197 199 */ 198 int index = select.append( value, null);199 if (config.get SettingString(setting).equalsIgnoreCase(value)) {200 int index = select.append(label, null); 201 if (config.get(setting).equalsIgnoreCase(value)) { 200 202 select.setSelectedIndex(index, true); 201 203 } -
mymrc/trunk/Java-client/src/org/myMRC/settings/Configuration.java
r15 r32 3 3 * Configuration.java 4 4 * 5 * Created on March 22, 2007, 6:40 PM5 * Created on July 20, 2007, 2:30 AM 6 6 */ 7 import java.util.Vector; 7 8 import javax.microedition.lcdui.*; 9 import javax.microedition.rms.*; 8 10 import org.myMRC.screen.FormScreen; 9 import org.myMRC.Util;10 11 11 12 12 13 /** 13 * Global myMRC configuration class.14 * Holds all information from the myMRC.conf file and handles operations on it.15 * Implemented as Singleton Pattern.16 14 * 17 15 * @author Sven Gregori 18 16 */ 19 17 public class Configuration { 20 /** static instance for Singleton implementation */21 18 private static Configuration instance; 19 RecordStore storage; 22 20 23 /* 24 * myMRC settings itself. 25 */ 26 private String path; 27 private String configFile; 28 private String serverHost; 29 private int serverPort; 30 31 /* 32 * default values 33 */ 34 //final String DEFAULT_PATH = "/myMRC/"; 35 final String DEFAULT_PATH = "/E:/Others/"; 36 final String CONFIG_FILE = "myMRC.conf"; 37 38 /** 39 * Returns the singleton instance of this class. 40 * 41 * @param none 42 * @return Singleton Configuration instance 43 */ 44 public static synchronized Configuration getInstance() { 21 public static synchronized Configuration createInstance() throws Exception { 45 22 if (instance == null) { 46 23 instance = new Configuration(); 24 25 // only during developemnt! 26 /* 27 instance.storage.closeRecordStore(); 28 instance.storage.deleteRecordStore("myMRCconf"); 29 instance.storage = RecordStore.openRecordStore("myMRCconf", true, 30 RecordStore.AUTHMODE_PRIVATE, true); 31 System.out.println("num records = " + instance.storage.getNumRecords()); 32 */ 33 34 35 if (instance.storage.getNumRecords() == 0) { 36 instance.loadDefaults(); 37 } 47 38 } 48 39 return instance; 49 40 } 50 41 51 /** 52 * Creates a new instance of Configuration 53 */ 54 private Configuration() { 55 this.path = DEFAULT_PATH; 56 this.configFile = CONFIG_FILE; 57 this.serverHost = "0.0.0.0"; 58 this.serverPort = 0; 42 public static synchronized Configuration getInstance() { 43 return instance; 44 } 45 46 /** Creates a new instance of Configuration */ 47 private Configuration() throws Exception { 48 storage = RecordStore.openRecordStore("myMRCconf", true, 49 RecordStore.AUTHMODE_PRIVATE, true); 50 } 51 52 private void loadDefaults() throws Exception { 53 this.add("0"); /* 1: CONNECTION_TYPE */ 54 this.add("0.0.0.0"); /* 2: INET_SERVER_HOST */ 55 this.add("0"); /* 3: INET_SERVER_PORT */ 56 this.add("00:00:00:00:00:00"); /* 4: BT_SERVER_ADDR */ 57 this.add("0"); /* 5: BT_SERVER_PORT */ 58 } 59 60 private void add(String value) throws Exception { 61 int ret = storage.addRecord(value.getBytes(), 0, value.length()); 62 System.out.println("added #" + ret); 59 63 } 60 64 61 65 62 /** 63 * Returns the configuration for "path" 64 * @return configuration for "path" 65 */ 66 public String getPath() { 67 return this.path; 66 public String get(int setting) { 67 byte[] value; 68 69 System.out.println("getting #" + setting); 70 try { 71 value = storage.getRecord(setting); 72 } catch (Exception e) { 73 /* 74 * Again, no matter which exception is thrown, we're screwed 75 * anyway - no we can just return null. (maybe signalise it to 76 * the user as well? well - TODO) 77 */ 78 e.printStackTrace(); 79 return null; 80 } 81 82 return new String(value); 68 83 } 69 84 70 /** 71 * Returns the configuration for "configFile". 72 * @return configuration for "configFile" 73 */ 74 public String getConfigFile() { 75 return this.configFile; 76 } 77 78 /** 79 * Returns the configuration for "serverHost". 80 * @return configuration for "serverHost" 81 */ 82 public String getServerHost() { 83 return this.serverHost; 84 } 85 86 /** 87 * Returns the configuration for "serverPort", converted to integer. 88 * @return configuration for "serverPort" 89 */ 90 public int getServerPort() { 91 return this.serverPort; 92 } 93 94 /** 95 * Returns the server host and server port concatenated as a single String 96 * so it can be used for opening sockets. 97 * @return serverHost:serverPort 98 */ 99 public String getServerString() { 100 return this.serverHost + ":" + this.serverPort; 101 } 102 103 /** 104 * Returns the configuration value for a given setting as a String. 105 * 106 * @param setting requested setting to return its value. 107 * @return value as a String, or an empty String if setting is unknown. 108 */ 109 public String getSettingString(String setting) { 110 if (setting == null) { 111 return ""; 112 } else if (setting.equalsIgnoreCase("path")) { 113 return this.path; 114 } else if (setting.equalsIgnoreCase("configFile")) { 115 return this.configFile; 116 } else if (setting.equalsIgnoreCase("Server Host") || setting.equalsIgnoreCase("serverHost")) { 117 return this.serverHost; 118 } else if (setting.equalsIgnoreCase("Server Port") || setting.equalsIgnoreCase("serverPort")) { 119 return String.valueOf(this.serverPort); 85 public String get(String settingString) { 86 if (settingString.equals("Connection Type")) { 87 return get(Settings.CONNECTION_TYPE); 88 } else if (settingString.equals("Inet Server Host")) { 89 return get(Settings.INET_SERVER_HOST); 90 } else if (settingString.equals("Inet Server Port")) { 91 return get(Settings.INET_SERVER_PORT); 92 } else if (settingString.equals("Bluetooth Server Address")) { 93 return get(Settings.BT_SERVER_ADDR); 94 } else if (settingString.equals("Bluetooth Server Port")) { 95 return get(Settings.BT_SERVER_PORT); 120 96 } else { 121 return "";97 return null; 122 98 } 123 99 } 124 100 125 /** 126 * Sets the given value of a given setting. 127 * If the setting doesn't exist, nothing is done. 128 * 129 * @param setting setting whose value is to be set 130 * @param value the actual value 131 */ 132 public void setValue(String setting, String value) { 133 System.out.println(setting + " now " + value); 134 if (setting.equalsIgnoreCase("Server Host") || setting.equalsIgnoreCase("serverHost")) { 135 this.serverHost = value; 136 } else if (setting.equalsIgnoreCase("Server Port") || setting.equalsIgnoreCase("serverPort")) { 137 this.serverPort = Util.atoi(value); 101 102 public void set(int setting, String value) throws Exception { 103 System.out.println("setting #" + setting + " -- " + value); 104 try { 105 storage.setRecord(setting, value.getBytes(), 0, value.length()); 106 } catch (Exception e) { 107 throw new Exception(e.getMessage() + 108 "\nsetting: " + setting + "\nvalue: " + value); 138 109 } 139 110 } 140 111 141 /** 142 * Writes setting values taken from a FormEntry object. 143 * 144 * @param entry FormScreen object holding the values. 145 */ 146 public void writeSettings(FormScreen form) { 112 public void set(String settingString, String value) throws Exception { 113 if (settingString.equals("Connection Type")) { 114 set(Settings.CONNECTION_TYPE, value); 115 } else if (settingString.equals("Inet Server Host")) { 116 set(Settings.INET_SERVER_HOST, value); 117 } else if (settingString.equals("Inet Server Port")) { 118 set(Settings.INET_SERVER_PORT, value); 119 } else if (settingString.equals("Bluetooth Server Address")) { 120 set(Settings.BT_SERVER_ADDR, value); 121 } else if (settingString.equals("Bluetooth Server Port")) { 122 set(Settings.BT_SERVER_PORT, value); 123 } else { 124 // ignore it 125 } 126 } 127 128 public void setFromForm(FormScreen form) throws Exception { 147 129 String value = ""; 148 130 for (int i = 0; i < form.size(); i++) { … … 150 132 if (item instanceof TextField) { 151 133 value = ((TextField) item).getString(); 152 this.set Value(item.getLabel(), value);134 this.set(item.getLabel(), value); 153 135 } else if (item instanceof ChoiceGroup) { 154 136 int index = ((ChoiceGroup) item).getSelectedIndex(); 155 value = ((ChoiceGroup) item).getString(index);156 this.set Value(item.getLabel(), value);137 //value = ((ChoiceGroup) item).getString(index); 138 this.set(item.getLabel(), Integer.toString(index)); 157 139 } 158 140 }
