Changeset 44
- Timestamp:
- 08/16/07 00:11:03 (5 years ago)
- Location:
- mymrc/trunk/Java-client/src/org/myMRC
- Files:
-
- 3 added
- 11 modified
-
control/Controller.java (modified) (11 diffs)
-
events/Content.java (modified) (2 diffs)
-
events/Opcode.java (modified) (1 diff)
-
myMRC.java (modified) (2 diffs)
-
net/BluetoothController.java (modified) (9 diffs)
-
net/InetController.java (modified) (2 diffs)
-
net/NetworkController.java (modified) (7 diffs)
-
net/Receiver.java (modified) (6 diffs)
-
parser/CanvasParser.java (added)
-
parser/XmlParser.java (modified) (4 diffs)
-
screen/AlertScreen.java (added)
-
screen/PlaybackCanvas.java (added)
-
settings/Configuration.java (modified) (13 diffs)
-
settings/Settings.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mymrc/trunk/Java-client/src/org/myMRC/control/Controller.java
r33 r44 10 10 import org.myMRC.*; 11 11 import org.myMRC.events.*; 12 import org.myMRC.net.BluetoothController; 13 import org.myMRC.net.InetController; 14 import org.myMRC.net.NetworkController; 12 import org.myMRC.net.*; 15 13 import org.myMRC.parser.*; 16 14 import org.myMRC.screen.*; … … 70 68 71 69 72 73 /** 74 * Kills the MIDlet. It invokes the MIDlet's exitMIDlet() method. 75 */ 76 public static void killEmAll() { 77 instance = null; 78 myMRC.exitMIDlet(); 79 } 80 81 public MIDlet getMidlet() { return this.myMRC; } 82 83 /** Creates a new instance of Controller */ 70 /** 71 * Creates a new instance of the Controller. 72 * Creates the Configuration object (which is loaded with default values 73 * the very first time), the screen element objects and the parser objects. 74 * 75 * @param myMRC Reference to the MIDlet. 76 */ 84 77 private Controller(MIDlet myMRC) { 85 form= new FormScreen();86 list= new ListScreen();87 canvas= new PlaybackCanvas();88 display= Display.getDisplay(myMRC);78 this.form = new FormScreen(); 79 this.list = new ListScreen(); 80 this.canvas = new PlaybackCanvas(); 81 this.display = Display.getDisplay(myMRC); 89 82 90 83 try { 91 config = Configuration.createInstance();84 this.config = Configuration.createInstance(); 92 85 } catch (Exception e) { 93 86 e.printStackTrace(); … … 95 88 alert.setTimeout(alert.FOREVER); 96 89 alert.setString("Error while loading settings:\n" + e.getMessage()); 97 display.setCurrent(alert); 98 } 99 100 listParser = new ListParser(list); 101 formParser = new FormParser(form); 102 canvasParser = new CanvasParser(canvas); 103 90 this.display.setCurrent(alert); 91 } 92 93 this.listParser = new ListParser(list); 94 this.formParser = new FormParser(form); 95 this.canvasParser = new CanvasParser(canvas); 96 97 } 98 99 100 101 /** 102 * Kills the MIDlet. It invokes the MIDlet's exitMIDlet() method. 103 */ 104 public static void killEmAll() { 105 instance = null; 106 myMRC.exitMIDlet(); 107 } 108 109 110 /** 111 * Returns the internally stored reference to the MIDlet object. 112 * @return Reference to the MIDlet object. 113 */ 114 public MIDlet getMidlet() { 115 return this.myMRC; 104 116 } 105 117 … … 147 159 /** 148 160 * Handles a received opcode. 149 * By now, we only get opcode for getting new form data, or for new list150 * data.151 161 * 152 162 * @param opcode opcode of the received event … … 179 189 break; 180 190 181 case Opcode.IOP_EXIT: // XXX needed at all anymore? 182 Controller.killEmAll(); 191 case Opcode.IOP_EXIT: 192 case Opcode.IOP_INT_EXIT: 193 this.processInternalEvent(opcode, data); 183 194 break; 184 195 … … 240 251 * InetController. 241 252 */ 242 243 /* 244 * W A R N I N G 245 * FIXME/CHECKME - I changed the whole net.*Controller 246 * stuff, and this here hasn't been tested yet, 247 * so it should be done :) 248 */ 249 this.communicator = InetController.getInstance(); // <-- !! 253 this.communicator = InetController.getInstance(); 250 254 251 255 if (!communicator.isAlive()) { … … 279 283 break; 280 284 285 /* FIXME: there should be a better solution than this */ 281 286 case Opcode.IOP_BT_GET_DEVICES: 282 287 case Opcode.IOP_BT_GET_DEV_CANCEL: … … 285 290 case Opcode.IOP_BT_SERVICES_DETAILS: 286 291 case Opcode.IOP_BT_CONNECT: 287 /* d istribute to BluetoothController */292 /* delegate to BluetoothController */ 288 293 BluetoothController.getInstance().handleBTopcode(opcode, data); 289 294 break; … … 319 324 if (communicator != null && communicator.isAlive()) { 320 325 try { 321 communicator.close();326 communicator.close(); 322 327 } catch (IOException ioe) { 323 328 ioe.printStackTrace(); … … 340 345 private Display display; 341 346 347 /** 348 * Creates a new ConnectionStarter object. 349 * @param mainDisplay Reference to the MIDlet's main display 350 */ 342 351 public ConnectionStarter(Display mainDisplay) { 343 352 this.display = mainDisplay; … … 352 361 InetController.getInstance().open(url); 353 362 } catch (Exception e) { 354 AlertScreen alert = new AlertScreen("Connection failed!", 990, display.getCurrent()); 363 AlertScreen alert = new AlertScreen("Connection failed!", 364 Opcode.IOP_CONNECT, display.getCurrent()); 355 365 alert.setString("Unable to connect to remote server:\n" + e.getMessage()); 356 366 display.setCurrent(alert); -
mymrc/trunk/Java-client/src/org/myMRC/events/Content.java
r33 r44 10 10 11 11 /** 12 * Static content constants - used for fixedcontent stored on the mobile12 * Static content constants - used for static content stored on the mobile 13 13 * device, and not received from the server. 14 14 * … … 52 52 " <textfield setting=\"" + Settings.INET_SERVER_HOST + "\" label=\"Inet Server Host\" size=\"20\"/>" + 53 53 " <textfield setting=\"" + Settings.INET_SERVER_PORT + "\" label=\"Inet Server Port\" type=\"number\" size=\"5\"/>" + 54 " <spacer height=\"5\"/>" +55 " <textfield setting=\"" + Settings.BT_SERVER_ADDR + "\" label=\"Bluetooth Server Address\" size=\"20\"/>" +56 " <textfield setting=\"" + Settings.BT_SERVER_PORT + "\" label=\"Bluetooth Server Port\" type=\"number\" size=\"5\"/>" +57 54 " <command type=\"back\" label=\"Cancel\" opcode=\"0" + Opcode.IOP_START + "\"/>" + 58 55 " <command label=\"Save\" opcode=\"0" + Opcode.IOP_SETTINGS_SAVE + "\"/>" + -
mymrc/trunk/Java-client/src/org/myMRC/events/Opcode.java
r32 r44 35 35 public static final int IOP_START = 900; 36 36 public static final int IOP_ABOUT_DIALOG = 901; 37 public static final int IOP_PARSE = 909; // general parse command (-> AlertScreen) 37 38 public static final String OP_PARSELIST = "0910"; 38 39 public static final int IOP_PARSELIST = 910; -
mymrc/trunk/Java-client/src/org/myMRC/myMRC.java
r33 r44 6 6 */ 7 7 8 import java.io.IOException;9 8 import javax.microedition.lcdui.Display; 10 import javax.microedition.midlet.*; 9 import javax.microedition.midlet.MIDlet; 10 import org.myMRC.control.Controller; 11 11 import org.myMRC.events.Content; 12 12 import org.myMRC.events.Opcode; 13 import org.myMRC.net.BluetoothController;14 import org.myMRC.net.InetController;15 import org.myMRC.settings.*;16 import org.myMRC.control.Controller;17 13 18 14 … … 21 17 * 22 18 * @author Sven Gregori 23 * @version 19 * @version 1.0 24 20 */ 25 21 public class myMRC extends MIDlet { 26 private final String id = "myMRC 0.1j";27 22 28 23 /** 29 24 * Creates a new instance of myMRC. 30 * Loads the configuration for myMRC itself, starts the screen31 * controller and creates the settings menu.25 * The Controller instance is created and the start screen is parsed 26 * and displayed. 32 27 */ 33 28 public myMRC() { -
mymrc/trunk/Java-client/src/org/myMRC/net/BluetoothController.java
r33 r44 6 6 */ 7 7 import java.io.IOException; 8 import java.io.InputStream;9 import java.io.OutputStream;10 8 import java.util.Vector; 11 9 import javax.bluetooth.*; … … 30 28 { 31 29 private static BluetoothController instance = null; 32 private Controller controller; 33 private LocalDevice local = null; 34 private DiscoveryAgent agent = null; 35 private Vector devicesFound = null; 36 private ServiceRecord[] servicesFound = null; 37 private String xmlData; 38 private StreamConnection conn = null; 39 40 30 31 private Controller controller = null; 32 private LocalDevice local = null; 33 private DiscoveryAgent agent = null; 34 private Vector devicesFound = null; 35 private ServiceRecord[] servicesFound = null; 36 private String xmlData = null; 37 private StreamConnection conn = null; 38 39 40 /** 41 * Returns the singleton instance of this class. 42 * @return Singleton InetController instance 43 */ 41 44 public static synchronized BluetoothController getInstance() { 42 45 if (instance == null) { … … 46 49 } 47 50 51 48 52 /** 49 53 * Creates a new instance of BluetoothController. … … 51 55 private BluetoothController() { 52 56 this.controller = Controller.getInstance(); 53 //this.getDevices();54 }57 } 58 55 59 56 60 /** … … 112 116 bse.printStackTrace(); 113 117 } 114 this.agent = local.getDiscoveryAgent(); 118 119 this.agent = local.getDiscoveryAgent(); 115 120 this.devicesFound = new Vector(); 121 116 122 try { 117 123 if(!this.agent.startInquiry(DiscoveryAgent.GIAC, this)) { … … 166 172 167 173 case DiscoveryListener.INQUIRY_ERROR: 168 // Error during inquiry, add appropriate code here174 // Error during inquiry 169 175 System.out.println("inquiry error"); 170 176 break; 171 177 case DiscoveryListener.INQUIRY_TERMINATED: 172 /* 173 * Inquiry terminated by agent.cancelInquiry() 174 * Add appropriate code here 175 */ 178 // Inquiry terminated by agent.cancelInquiry() 176 179 System.out.println("inquiry terminated"); 177 180 break; … … 270 273 this.agent.searchServices(attrSet, uuidSet, device, this); 271 274 } catch (BluetoothStateException e) { 272 // FIXME add error message275 // FIXME: add error message 273 276 } 274 277 } … … 406 409 */ 407 410 private void connect(int index) { 408 ServiceRecord service = this.servicesFound[index];409 String url = service.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);410 AlertScreen alert = new AlertScreen(null, 0, controller.getCurrentScreen());411 ServiceRecord service = this.servicesFound[index]; 412 String url = service.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false); 413 AlertScreen alert = new AlertScreen(null, 0, controller.getCurrentScreen()); 411 414 412 415 try { … … 430 433 431 434 435 /** 436 * Closes the network connection. 437 * @throws IOException if a Java API close() function throws an Exception 438 */ 432 439 public void close() throws IOException { 433 try { 434 if (receiver != null) { 435 receiver.close(); 436 receiver = null; 437 } 438 439 if (ostream != null) { 440 ostream.close(); 441 ostream = null; 442 } 443 444 if (conn != null) { 445 conn.close(); 446 conn = null; 447 } 448 449 isAlive = false; 450 451 } catch (IOException ioe) { 452 453 } 454 440 if (receiver != null) { 441 receiver.close(); 442 receiver = null; 443 } 444 445 if (ostream != null) { 446 ostream.close(); 447 ostream = null; 448 } 449 450 if (conn != null) { 451 conn.close(); 452 conn = null; 453 } 454 455 isAlive = false; 455 456 } 456 457 } -
mymrc/trunk/Java-client/src/org/myMRC/net/InetController.java
r32 r44 27 27 /** 28 28 * Returns the singleton instance of this class. 29 *30 29 * @return Singleton InetController instance 31 30 */ … … 77 76 */ 78 77 public void close() throws IOException { 79 /*80 * TODO: close the input stream from the Receiver thread.81 * maybe store ostream here and close it - BUT! catch and82 * handle the Exception that will occur in the Recever.read()83 * method then.84 */85 78 if (receiver != null) { 86 79 receiver.close(); -
mymrc/trunk/Java-client/src/org/myMRC/net/NetworkController.java
r37 r44 17 17 */ 18 18 public abstract class NetworkController { 19 private intcounter;20 protected boolean isAlive;21 protected Receiver receiver = null;22 protected OutputStream ostream = null;19 private int counter; 20 protected boolean isAlive; 21 protected Receiver receiver = null; 22 protected OutputStream ostream = null; 23 23 24 /** 25 * Maximal number of sent data without a response from the server. 26 * If this amount is exceeded, the connection got most likely interrupted, 27 * so the connection is closed and the user is notified. 28 */ 24 29 final int MAX_UNRESPONDED_SENDS = 5; 25 30 … … 43 48 44 49 /** 45 * Sends a message to the server and involves the reply management 46 * mechanism. This method has to be used if for example data is requested 47 * from the server in order to get the response assigned to the calling 48 * object. When this method is called, the calling method must synchronize 49 * its object with a wait() call. When the requested data arrived, a 50 * notify() is send to the object that is passed here as "requester" 51 * parameter (probably the caller itself). It also must be specified for 52 * which event the data is supposed to be. This event ID and the requester 53 * Object is placed in the internal lookup table where the handleReceived() 54 * method will check for waiting Objects when data is received. 50 * Sends a message to the server. The message's opcode and data is 51 * given, the size is taken from the data and the appropriate message 52 * string is created. 55 53 * 56 * @param requestId ID of the event requested from the server 57 * @param data Message sent to the server 58 * @param replyId ID of the event we wait for a result from the server 59 * @param requester calling Object that is used for synchronization 60 * via wait/notify 54 * @param opcode Message's opcode 55 * @param data Message's data 61 56 */ 62 57 public void send(String opcode, String data) { … … 75 70 76 71 /* 77 * putthe event ID - if it's longer than 4 bytes, well, bad luck,72 * add the event ID - if it's longer than 4 bytes, well, bad luck, 78 73 * only the first 4 bytes are taken 79 74 */ … … 84 79 String dataLen; 85 80 if (data == null) { 86 System.out.println("DATA IS NULL");87 81 dataLen = null; 88 len = 0;82 len = 0; 89 83 } else { 90 84 dataLen = String.valueOf(data.length()); 91 len = dataLen.length();85 len = dataLen.length(); 92 86 } 93 87 … … 116 110 } 117 111 118 /* finally! we can send it ;)*/112 /* finally! we can send it */ 119 113 System.out.println("send: '" + sendBuf + "'"); 120 114 ostream.write(sendBuf.toString().getBytes()); … … 123 117 124 118 } catch (IOException ioe) { 125 //ioe.printStackTrace();126 119 Controller.getInstance().processInternalEvent( 127 120 Opcode.IOP_DISCONNECT_FORCED, ioe.getMessage()); … … 130 123 131 124 132 public void resetCounter() { 125 /** 126 * Resets the counter for the unresponded sent data. 127 * The Receiver thread calls this method whenever data is received. 128 */ 129 void resetCounter() { 133 130 this.counter = 0; 134 131 } 135 132 133 /** 134 * Closes the network connection. 135 * Each subclass is responsible for its own way of closing the connection. 136 */ 136 137 public abstract void close() throws IOException; 137 138 } -
mymrc/trunk/Java-client/src/org/myMRC/net/Receiver.java
r32 r44 49 49 org.myMRC.screen.AlertScreen alert = new org.myMRC.screen.AlertScreen(null, 0, c.getCurrentScreen()); 50 50 if (istream == null) { 51 alert.setString(" fuck, istream is null");51 alert.setString("[DBG] oh oh, istream is null"); 52 52 c.setScreen(alert); 53 53 break; … … 57 57 String eventId = "-"; 58 58 try { 59 //StringBuffer buf = new StringBuffer(); 60 buf = new StringBuffer(); 61 //String eventId = read(buf); 62 eventId = read(buf); 59 buf = new StringBuffer(); 60 eventId = read(buf); 63 61 if (eventId != null) { 64 62 controller.resetCounter(); … … 68 66 } catch (InterruptedIOException iioe) { 69 67 break; 70 } catch (IOException ioe) {71 ioe.printStackTrace();72 68 } catch (Exception e) { 73 69 alert.setTimeout(javax.microedition.lcdui.Alert.FOREVER); … … 102 98 return null; 103 99 } 104 /*105 *java.io.IOException: error 104 during TCP read106 at com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead(Protocol.java:299)107 at com.sun.midp.io.BufferedConnectionAdapter.readBytes(BufferedConnectionAdapter.java:99)108 at com.sun.midp.io.BaseInputStream.read(ConnectionBaseAdapter.java:582)109 at org.myMRC.net.Receiver.read(Receiver.java:78)110 at org.myMRC.net.Receiver.run(Receiver.java:47)111 112 */113 114 100 115 101 /* … … 141 127 return null; 142 128 } 143 /* 144 * Note: append() crashs when the connection is closed (and 145 * therefore read() keeps the buffer empty) and throws an 146 * IndexOutOfBoundException that will end the run() loop. 147 * 148 * FIXME: DAMN! that's not true anymore, after introducing the left 149 * and count variable, read() gets a len of 0, so there's 150 * just some crap in the buffer and it's ending up in an 151 * endless loop - the problem with checking for 0 is: is it 152 * 100% impossible to have count == 0 and not breaking with 153 * data in the stream?? and it might be cleaner to close the 154 * stream in a real way, not by suggestin and error as "ouh, 155 * this could mean connection is closed" 156 */ 129 157 130 buf.append(new String(readBuf, 0, readSize)); 158 131 total += readSize; … … 169 142 */ 170 143 public void close() throws IOException { 171 this.istream.close(); 144 /* 145 * TODO FIXME: since this Receiver is a separated thread and it most 146 * likely is blocked at the read() method, we need a good 147 * way to close the whole thread. We cannot use 148 * this.istream.close(), it only results in a crash but not 149 * in a clean shutdown. 150 * 151 * current workaround is to ignore it :( so no explicit Receiver 152 * shutdown, since the whole midlet is killed there, too - but still, 153 * not a satisfying solution. 154 */ 172 155 } 173 156 } -
mymrc/trunk/Java-client/src/org/myMRC/parser/XmlParser.java
r10 r44 7 7 import java.io.ByteArrayInputStream; 8 8 import java.io.IOException; 9 import javax.microedition.lcdui.Displayable; 9 10 import org.kxml2.io.KXmlParser; 11 import org.myMRC.control.Controller; 12 import org.myMRC.events.Opcode; 13 import org.myMRC.screen.AlertScreen; 10 14 import org.xmlpull.v1.*; 11 15 … … 24 28 */ 25 29 public XmlParser() { 26 parser = new KXmlParser();30 parser = new KXmlParser(); 27 31 } 32 28 33 29 34 /** … … 47 52 */ 48 53 public void parse() { 54 Displayable last = Controller.getInstance().getCurrentScreen(); 55 AlertScreen alert; 56 if (last instanceof AlertScreen) { 57 alert = (AlertScreen) last; 58 alert.reset(null, Opcode.IOP_PARSE, last); 59 } else { 60 alert = new AlertScreen(null, Opcode.IOP_PARSE, last); 61 } 62 alert.setString("Parsing data, please wait.."); 63 Controller.getInstance().setScreen(alert); 49 64 try { 50 65 while (parser.next() != XmlPullParser.END_DOCUMENT) { … … 55 70 } catch (IOException ioe) { 56 71 ioe.printStackTrace(); 72 } finally { 73 Controller.getInstance().setScreen(last); 57 74 } 58 75 } 76 59 77 60 78 /** -
mymrc/trunk/Java-client/src/org/myMRC/settings/Configuration.java
r32 r44 12 12 13 13 /** 14 * Deals with the myMRC configuration. 15 * The Configuration is stored in a RecordStore object. 14 16 * 15 17 * @author Sven Gregori … … 19 21 RecordStore storage; 20 22 23 /** 24 * Creates the Configuration instance. 25 * This has to be called the very first time. In myMRC's initialization, 26 * it's called from the org.myMRC.control.Controller's constructor. 27 * 28 * @return Singleton Configuration instance. 29 */ 21 30 public static synchronized Configuration createInstance() throws Exception { 22 31 if (instance == null) { 23 32 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 33 35 34 if (instance.storage.getNumRecords() == 0) { … … 40 39 } 41 40 41 42 /** 43 * Returns the Configuration instance. 44 * The instance has to be created by using the createInstance() method, 45 * this method just returns it (and should be used once the instance 46 * exists). 47 * 48 * @return Singleton Configuration instance 49 */ 42 50 public static synchronized Configuration getInstance() { 43 51 return instance; 44 52 } 45 53 46 /** Creates a new instance of Configuration */ 54 55 /** 56 * Creates a new instance of Configuration 57 */ 47 58 private Configuration() throws Exception { 48 59 storage = RecordStore.openRecordStore("myMRCconf", true, … … 50 61 } 51 62 63 64 /** 65 * Initializes the RecordStore with default values. This method is called 66 * the very first time myMRC is started. 67 */ 52 68 private void loadDefaults() throws Exception { 53 this.add("0"); /* 1: CONNECTION_TYPE */69 this.add("0"); /* 1: CONNECTION_TYPE (0 == CONN_BLUETOOTH) */ 54 70 this.add("0.0.0.0"); /* 2: INET_SERVER_HOST */ 55 71 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 72 } 59 73 74 75 /** 76 * Adds a configuration value into the internal RecordStore. 77 * Note: you have to keep track of the indices inside the RecordStore! 78 */ 60 79 private void add(String value) throws Exception { 61 80 int ret = storage.addRecord(value.getBytes(), 0, value.length()); … … 64 83 65 84 85 /** 86 * Returns the configuration value for the given setting index. 87 * The setting parameter is best taken from the org.myMRC.settings.Settings 88 * constants. Again, keep track of those indices, there's no automatic 89 * way to assign them. 90 * 91 * @param setting Index of the wished setting inside the RecordStore. 92 * @return Value of the given setting. 93 */ 66 94 public String get(int setting) { 67 95 byte[] value; … … 73 101 /* 74 102 * Again, no matter which exception is thrown, we're screwed 75 * anyway - no we can just return null. (maybe signalise it to103 * anyway - so we can just return null. (maybe signalise it to 76 104 * the user as well? well - TODO) 77 105 */ … … 83 111 } 84 112 113 114 /** 115 * Returns the value for a given String representation of a setting. 116 * The settingString parameter is taken from the Form element's label. 117 * 118 * @param settingString String representation of the wished setting. 119 * @return Value of the given setting, or <code>null</code> if unknown. 120 */ 85 121 public String get(String settingString) { 86 122 if (settingString.equals("Connection Type")) { … … 90 126 } else if (settingString.equals("Inet Server Port")) { 91 127 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);96 128 } else { 97 129 return null; … … 100 132 101 133 134 /** 135 * Sets the setting given by the index to the given value. 136 * @param setting Index of the wished setting inside the RecordStore. 137 * @param value Value for that setting. 138 */ 102 139 public void set(int setting, String value) throws Exception { 103 140 System.out.println("setting #" + setting + " -- " + value); … … 110 147 } 111 148 149 150 /** 151 * Sets the setting given by a string representation to the given value. 152 * The settingString parameter is taken from the Form element's label. 153 * 154 * @param settingString String representation of the wished setting. 155 * @param value Value for that setting. 156 */ 112 157 public void set(String settingString, String value) throws Exception { 113 158 if (settingString.equals("Connection Type")) { … … 117 162 } else if (settingString.equals("Inet Server Port")) { 118 163 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 164 } else { 124 165 // ignore it … … 126 167 } 127 168 169 170 /** 171 * Sets configuration values by examining a given FormScreen element. 172 * 173 * @param form FormScreen element holding all the settings. 174 */ 128 175 public void setFromForm(FormScreen form) throws Exception { 129 176 String value = ""; … … 135 182 } else if (item instanceof ChoiceGroup) { 136 183 int index = ((ChoiceGroup) item).getSelectedIndex(); 137 //value = ((ChoiceGroup) item).getString(index);138 184 this.set(item.getLabel(), Integer.toString(index)); 139 185 } -
mymrc/trunk/Java-client/src/org/myMRC/settings/Settings.java
r32 r44 8 8 9 9 /** 10 * Static class that holds constants for the configuration. 10 11 * 11 12 * @author Sven Gregori … … 20 21 * inidces for the RecordStore object in Configuration.java 21 22 */ 23 /** RecordStore's index for the connection type (1) */ 22 24 public static final int CONNECTION_TYPE = 1; 25 /** RecordStore's index for the inet server host (2) */ 23 26 public static final int INET_SERVER_HOST = 2; 27 /** RecordStore's index for the inet server port (3) */ 24 28 public static final int INET_SERVER_PORT = 3; 25 public static final int BT_SERVER_ADDR = 4;26 public static final int BT_SERVER_PORT = 5;27 29 28 public static final int SETTINGS_COUNT = 5; // adjust me whenever a setting is added! 30 /** 31 * number of configuration elements in the RecordStore. 32 * Note that whenever a setting is added, this value has to be adjusted. 33 */ 34 public static final int SETTINGS_COUNT = 3; 29 35 30 36 /** CONNECTION_TYPE value to use Bluetooth communication (0) */ 31 37 public static final int CONN_BLUETOOTH = 0; 32 public static final int CONN_INET = 1; 38 /** CONNECTION_TYPE value to use Inet Socket communication (1) */ 39 public static final int CONN_INET = 1; 33 40 }
