Changeset 44

Show
Ignore:
Timestamp:
08/16/07 00:11:03 (5 years ago)
Author:
ciro
Message:

added wait dialog when data is parsed,
cleaned up sources and comments.
added missing source files to the repository (whoops)

Location:
mymrc/trunk/Java-client/src/org/myMRC
Files:
3 added
11 modified

Legend:

Unmodified
Added
Removed
  • mymrc/trunk/Java-client/src/org/myMRC/control/Controller.java

    r33 r44  
    1010import org.myMRC.*; 
    1111import org.myMRC.events.*; 
    12 import org.myMRC.net.BluetoothController; 
    13 import org.myMRC.net.InetController; 
    14 import org.myMRC.net.NetworkController; 
     12import org.myMRC.net.*; 
    1513import org.myMRC.parser.*; 
    1614import org.myMRC.screen.*; 
     
    7068     
    7169     
    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     */ 
    8477    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); 
    8982         
    9083        try { 
    91             config = Configuration.createInstance(); 
     84            this.config = Configuration.createInstance(); 
    9285        } catch (Exception e) { 
    9386            e.printStackTrace(); 
     
    9588            alert.setTimeout(alert.FOREVER); 
    9689            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; 
    104116    } 
    105117     
     
    147159    /** 
    148160     * Handles a received opcode. 
    149      * By now, we only get opcode for getting new form data, or for new list 
    150      * data. 
    151161     * 
    152162     * @param opcode opcode of the received event 
     
    179189                break; 
    180190                 
    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); 
    183194                break; 
    184195             
     
    240251                         * InetController. 
    241252                         */ 
    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(); 
    250254                         
    251255                        if (!communicator.isAlive()) { 
     
    279283                break; 
    280284                 
     285            /* FIXME: there should be a better solution than this */ 
    281286            case Opcode.IOP_BT_GET_DEVICES: 
    282287            case Opcode.IOP_BT_GET_DEV_CANCEL: 
     
    285290            case Opcode.IOP_BT_SERVICES_DETAILS: 
    286291            case Opcode.IOP_BT_CONNECT: 
    287                 /* distribute to BluetoothController */ 
     292                /* delegate to BluetoothController */ 
    288293                BluetoothController.getInstance().handleBTopcode(opcode, data); 
    289294                break; 
     
    319324                if (communicator != null && communicator.isAlive()) { 
    320325                    try { 
    321                     communicator.close(); 
     326                        communicator.close(); 
    322327                    } catch (IOException ioe) { 
    323328                        ioe.printStackTrace(); 
     
    340345    private Display display; 
    341346     
     347    /** 
     348     * Creates a new ConnectionStarter object. 
     349     * @param mainDisplay Reference to the MIDlet's main display 
     350     */ 
    342351    public ConnectionStarter(Display mainDisplay) { 
    343352        this.display = mainDisplay; 
     
    352361            InetController.getInstance().open(url); 
    353362        } 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()); 
    355365            alert.setString("Unable to connect to remote server:\n" + e.getMessage()); 
    356366            display.setCurrent(alert); 
  • mymrc/trunk/Java-client/src/org/myMRC/events/Content.java

    r33 r44  
    1010 
    1111/** 
    12  * Static content constants - used for fixed content stored on the mobile 
     12 * Static content constants - used for static content stored on the mobile 
    1313 * device, and not received from the server. 
    1414 * 
     
    5252            "   <textfield setting=\"" + Settings.INET_SERVER_HOST + "\" label=\"Inet Server Host\" size=\"20\"/>" + 
    5353            "   <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\"/>" + 
    5754            "   <command type=\"back\" label=\"Cancel\" opcode=\"0" + Opcode.IOP_START + "\"/>" + 
    5855            "   <command label=\"Save\" opcode=\"0" + Opcode.IOP_SETTINGS_SAVE + "\"/>" + 
  • mymrc/trunk/Java-client/src/org/myMRC/events/Opcode.java

    r32 r44  
    3535    public static final int   IOP_START             =   900; 
    3636    public static final int   IOP_ABOUT_DIALOG      =   901; 
     37    public static final int   IOP_PARSE             =   909; // general parse command (-> AlertScreen) 
    3738    public static final String OP_PARSELIST         = "0910"; 
    3839    public static final int   IOP_PARSELIST         =   910; 
  • mymrc/trunk/Java-client/src/org/myMRC/myMRC.java

    r33 r44  
    66 */ 
    77 
    8 import java.io.IOException; 
    98import javax.microedition.lcdui.Display; 
    10 import javax.microedition.midlet.*; 
     9import javax.microedition.midlet.MIDlet; 
     10import org.myMRC.control.Controller; 
    1111import org.myMRC.events.Content; 
    1212import 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; 
    1713 
    1814 
     
    2117 * 
    2218 * @author  Sven Gregori 
    23  * @version 
     19 * @version 1.0 
    2420 */ 
    2521public class myMRC extends MIDlet { 
    26     private final String id = "myMRC 0.1j"; 
    2722     
    2823    /** 
    2924     * Creates a new instance of myMRC. 
    30      * Loads the configuration for myMRC itself, starts the screen 
    31      * controller and creates the settings menu. 
     25     * The Controller instance is created and the start screen is parsed 
     26     * and displayed. 
    3227     */ 
    3328    public myMRC() { 
  • mymrc/trunk/Java-client/src/org/myMRC/net/BluetoothController.java

    r33 r44  
    66 */ 
    77import java.io.IOException; 
    8 import java.io.InputStream; 
    9 import java.io.OutputStream; 
    108import java.util.Vector; 
    119import javax.bluetooth.*; 
     
    3028{ 
    3129    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     */ 
    4144    public static synchronized BluetoothController getInstance() { 
    4245        if (instance == null) { 
     
    4649    } 
    4750     
     51     
    4852    /** 
    4953     * Creates a new instance of BluetoothController. 
     
    5155    private BluetoothController() { 
    5256        this.controller = Controller.getInstance(); 
    53         //this.getDevices(); 
    54     } 
     57    } 
     58     
    5559     
    5660    /** 
     
    112116            bse.printStackTrace(); 
    113117        } 
    114         this.agent = local.getDiscoveryAgent(); 
     118         
     119        this.agent        = local.getDiscoveryAgent(); 
    115120        this.devicesFound = new Vector(); 
     121         
    116122        try { 
    117123            if(!this.agent.startInquiry(DiscoveryAgent.GIAC, this)) { 
     
    166172                 
    167173            case DiscoveryListener.INQUIRY_ERROR: 
    168                 //Error during inquiry, add appropriate code here 
     174                // Error during inquiry 
    169175                System.out.println("inquiry error"); 
    170176                break; 
    171177            case DiscoveryListener.INQUIRY_TERMINATED: 
    172                 /* 
    173                  * Inquiry terminated by agent.cancelInquiry() 
    174                  * Add appropriate code here 
    175                  */ 
     178                // Inquiry terminated by agent.cancelInquiry() 
    176179                System.out.println("inquiry terminated"); 
    177180                break; 
     
    270273            this.agent.searchServices(attrSet, uuidSet, device, this); 
    271274        } catch (BluetoothStateException e) { 
    272             // FIXME add error message 
     275            // FIXME: add error message 
    273276        } 
    274277    } 
     
    406409     */ 
    407410    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()); 
    411414         
    412415        try { 
     
    430433     
    431434     
     435    /** 
     436     * Closes the network connection. 
     437     * @throws IOException if a Java API close() function throws an Exception 
     438     */ 
    432439    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; 
    455456    } 
    456457} 
  • mymrc/trunk/Java-client/src/org/myMRC/net/InetController.java

    r32 r44  
    2727    /** 
    2828     * Returns the singleton instance of this class. 
    29      *  
    3029     * @return Singleton InetController instance 
    3130     */ 
     
    7776     */ 
    7877    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 and 
    82          *          handle the Exception that will occur in the Recever.read() 
    83          *          method then. 
    84          */ 
    8578        if (receiver != null) { 
    8679            receiver.close(); 
  • mymrc/trunk/Java-client/src/org/myMRC/net/NetworkController.java

    r37 r44  
    1717 */ 
    1818public abstract class NetworkController { 
    19     private int counter; 
    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; 
    2323     
     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     */ 
    2429    final int MAX_UNRESPONDED_SENDS = 5; 
    2530     
     
    4348     
    4449    /** 
    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. 
    5553     * 
    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 
    6156     */ 
    6257    public void send(String opcode, String data) { 
     
    7570         
    7671        /* 
    77          * put the 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, 
    7873         * only the first 4 bytes are taken 
    7974         */ 
     
    8479        String dataLen; 
    8580        if (data == null) { 
    86             System.out.println("DATA IS NULL"); 
    8781            dataLen = null; 
    88             len = 0; 
     82            len     = 0; 
    8983        } else { 
    9084            dataLen = String.valueOf(data.length()); 
    91             len = dataLen.length(); 
     85            len     = dataLen.length(); 
    9286        } 
    9387         
     
    116110            } 
    117111             
    118             /* finally! we can send it ;) */ 
     112            /* finally! we can send it */ 
    119113            System.out.println("send: '" + sendBuf + "'"); 
    120114            ostream.write(sendBuf.toString().getBytes()); 
     
    123117             
    124118        } catch (IOException ioe) { 
    125             //ioe.printStackTrace(); 
    126119            Controller.getInstance().processInternalEvent( 
    127120                    Opcode.IOP_DISCONNECT_FORCED, ioe.getMessage()); 
     
    130123     
    131124     
    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() { 
    133130        this.counter = 0; 
    134131    } 
    135132     
     133    /** 
     134     * Closes the network connection. 
     135     * Each subclass is responsible for its own way of closing the connection. 
     136     */ 
    136137    public abstract void close() throws IOException; 
    137138} 
  • mymrc/trunk/Java-client/src/org/myMRC/net/Receiver.java

    r32 r44  
    4949            org.myMRC.screen.AlertScreen alert = new org.myMRC.screen.AlertScreen(null, 0, c.getCurrentScreen()); 
    5050            if (istream == null) { 
    51                 alert.setString("fuck, istream is null"); 
     51                alert.setString("[DBG] oh oh, istream is null"); 
    5252                c.setScreen(alert); 
    5353                break; 
     
    5757            String eventId = "-"; 
    5858            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); 
    6361                if (eventId != null) { 
    6462                    controller.resetCounter(); 
     
    6866            } catch (InterruptedIOException iioe) { 
    6967                break; 
    70             } catch (IOException ioe) { 
    71                 ioe.printStackTrace(); 
    7268            } catch (Exception e) { 
    7369                alert.setTimeout(javax.microedition.lcdui.Alert.FOREVER); 
     
    10298            return null; 
    10399        } 
    104         /* 
    105          *java.io.IOException: error 104 during TCP read  
    106         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          
    114100         
    115101        /* 
     
    141127                return null; 
    142128            } 
    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 
    157130            buf.append(new String(readBuf, 0, readSize)); 
    158131            total += readSize; 
     
    169142     */ 
    170143    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         */ 
    172155    } 
    173156} 
  • mymrc/trunk/Java-client/src/org/myMRC/parser/XmlParser.java

    r10 r44  
    77import java.io.ByteArrayInputStream; 
    88import java.io.IOException; 
     9import javax.microedition.lcdui.Displayable; 
    910import org.kxml2.io.KXmlParser; 
     11import org.myMRC.control.Controller; 
     12import org.myMRC.events.Opcode; 
     13import org.myMRC.screen.AlertScreen; 
    1014import org.xmlpull.v1.*; 
    1115 
     
    2428     */ 
    2529    public XmlParser() { 
    26         parser   = new KXmlParser(); 
     30        parser = new KXmlParser(); 
    2731    } 
     32     
    2833     
    2934    /** 
     
    4752     */ 
    4853    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); 
    4964        try { 
    5065            while (parser.next() != XmlPullParser.END_DOCUMENT) { 
     
    5570        } catch (IOException ioe) { 
    5671            ioe.printStackTrace(); 
     72        } finally { 
     73            Controller.getInstance().setScreen(last); 
    5774        } 
    5875    } 
     76     
    5977     
    6078    /** 
  • mymrc/trunk/Java-client/src/org/myMRC/settings/Configuration.java

    r32 r44  
    1212 
    1313/** 
     14 * Deals with the myMRC configuration. 
     15 * The Configuration is stored in a RecordStore object. 
    1416 * 
    1517 * @author Sven Gregori 
     
    1921    RecordStore storage; 
    2022     
     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     */ 
    2130    public static synchronized Configuration createInstance() throws Exception { 
    2231        if (instance == null) { 
    2332            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              
    3433             
    3534            if (instance.storage.getNumRecords() == 0) { 
     
    4039    } 
    4140     
     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     */ 
    4250    public static synchronized Configuration getInstance() { 
    4351        return instance; 
    4452    } 
    4553     
    46     /** Creates a new instance of Configuration */ 
     54     
     55    /** 
     56     * Creates a new instance of Configuration 
     57     */ 
    4758    private Configuration() throws Exception { 
    4859        storage = RecordStore.openRecordStore("myMRCconf", true,  
     
    5061    } 
    5162     
     63     
     64    /** 
     65     * Initializes the RecordStore with default values. This method is called 
     66     * the very first time myMRC is started. 
     67     */ 
    5268    private void loadDefaults() throws Exception { 
    53         this.add("0");          /* 1: CONNECTION_TYPE */ 
     69        this.add("0");          /* 1: CONNECTION_TYPE (0 == CONN_BLUETOOTH) */ 
    5470        this.add("0.0.0.0");    /* 2: INET_SERVER_HOST */ 
    5571        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 */ 
    5872    } 
    5973     
     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     */ 
    6079    private void add(String value) throws Exception { 
    6180        int ret = storage.addRecord(value.getBytes(), 0, value.length()); 
     
    6483     
    6584     
     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     */ 
    6694    public String get(int setting) { 
    6795        byte[] value; 
     
    73101            /* 
    74102             * Again, no matter which exception is thrown, we're screwed 
    75              * anyway - no we can just return null. (maybe signalise it to 
     103             * anyway - so we can just return null. (maybe signalise it to 
    76104             * the user as well? well - TODO) 
    77105             */ 
     
    83111    } 
    84112     
     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     */ 
    85121    public String get(String settingString) { 
    86122        if (settingString.equals("Connection Type")) { 
     
    90126        } else if (settingString.equals("Inet Server Port")) { 
    91127            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); 
    96128        } else { 
    97129            return null; 
     
    100132     
    101133     
     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     */ 
    102139    public void set(int setting, String value) throws Exception { 
    103140        System.out.println("setting #" + setting + " -- " + value); 
     
    110147    } 
    111148     
     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     */ 
    112157    public void set(String settingString, String value) throws Exception { 
    113158        if (settingString.equals("Connection Type")) { 
     
    117162        } else if (settingString.equals("Inet Server Port")) { 
    118163            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); 
    123164        } else { 
    124165            // ignore it 
     
    126167    } 
    127168     
     169     
     170    /** 
     171     * Sets configuration values by examining a given FormScreen element. 
     172     * 
     173     * @param form FormScreen element holding all the settings. 
     174     */ 
    128175    public void setFromForm(FormScreen form) throws Exception { 
    129176        String value = ""; 
     
    135182            } else if (item instanceof ChoiceGroup) { 
    136183                int index = ((ChoiceGroup) item).getSelectedIndex(); 
    137                 //value = ((ChoiceGroup) item).getString(index); 
    138184                this.set(item.getLabel(), Integer.toString(index)); 
    139185            } 
  • mymrc/trunk/Java-client/src/org/myMRC/settings/Settings.java

    r32 r44  
    88 
    99/** 
     10 * Static class that holds constants for the configuration. 
    1011 * 
    1112 * @author Sven Gregori 
     
    2021     * inidces for the RecordStore object in Configuration.java 
    2122     */ 
     23    /** RecordStore's index for the connection type (1) */ 
    2224    public static final int CONNECTION_TYPE  = 1; 
     25    /** RecordStore's index for the inet server host (2) */ 
    2326    public static final int INET_SERVER_HOST = 2; 
     27    /** RecordStore's index for the inet server port (3) */ 
    2428    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; 
    2729     
    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; 
    2935     
    30      
     36    /** CONNECTION_TYPE value to use Bluetooth communication (0) */ 
    3137    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; 
    3340}