~ubuntu-branches/ubuntu/karmic/pilot-link/karmic

« back to all changes in this revision

Viewing changes to bindings/Java/org/gnu/pilotlink/AppInfo.java

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2006-09-22 11:51:36 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20060922115136-qqmy17bx8j5x0y72
Tags: 0.12.1-5
* urgency medium since libpisock-dev was not usable to build any package
* libpisock-dev now depends on libusb-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
public abstract class AppInfo {
4
4
    protected byte buffer[];
5
 
    
 
5
    protected String categories[]=new String[16];
 
6
    protected boolean isCatRenamed[]=new boolean[16];
 
7
    protected int catCount=0;
 
8
    protected int dataOffset=0;
 
9
    protected int bits;
 
10
    protected long id[];
 
11
    protected int lastUniqueID;
6
12
    
7
13
    public AppInfo() {
8
14
        buffer=new byte[65535];
14
20
 
15
21
    public abstract void setBuffer(byte[] b);
16
22
    
17
 
    public byte[] getBuffer() {
18
 
        return buffer;
 
23
    public void parseCategories(){
 
24
        bits=buffer[0]*256+buffer[1];
 
25
        id=new long[4];
 
26
        catCount=0;
 
27
        for (int i=0; i<16; i++) {
 
28
                if (buffer[2+i*16]!=0) {
 
29
                        categories[i]=getStringAt(buffer,2+i*16);
 
30
                                 //=new String(buffer,2+i*16,16);
 
31
                        
 
32
                        //System.out.println("Got Category: \""+categories[i]+"\"");
 
33
                        catCount++;
 
34
                } else {
 
35
                        categories[i]=null;
 
36
                }
 
37
                if ( (bits&(1<<i))!=0) {
 
38
                        isCatRenamed[i]=true;
 
39
                } else {
 
40
                        isCatRenamed[i]=false;
 
41
                }
 
42
        }       
 
43
        dataOffset=2+16*16;
 
44
        for (int i=0; i<4; i++) {
 
45
                id[i]=Record.getLongAt(buffer,dataOffset);
 
46
                dataOffset+=4;
 
47
        }
 
48
        lastUniqueID=buffer[dataOffset];
 
49
        dataOffset+=4;
 
50
        
 
51
        
 
52
    }
 
53
    
 
54
    public void createDefaultBuffer() {
 
55
        for (int i=0; i<buffer.length; i++) {
 
56
                buffer[i]=0;
 
57
        }
 
58
    
 
59
        bits=0;
 
60
        for (int i=0; i<16; i++) {
 
61
                if (isCatRenamed[i]) {
 
62
                        bits|=(1<<i);
 
63
                }
 
64
                if (categories[i]!=null) {
 
65
                        for (int ch=0;ch<16 && ch<categories[i].length();ch++) {
 
66
                                char z=categories[i].charAt(ch);
 
67
                                buffer[2+i*16+ch]=(byte)z;
 
68
                        }
 
69
                }                       
 
70
        }
 
71
        buffer[0]=(byte) (bits>>256);
 
72
        buffer[1]=(byte) (bits&256);
 
73
    }
 
74
    
 
75
    
 
76
    public abstract byte[] getBuffer() ;
 
77
    public boolean isCatRenamed(int idx) {
 
78
        return isCatRenamed[idx];
 
79
    }
 
80
    public void setCatRenamed(int idx,boolean b) {
 
81
        isCatRenamed[idx]=b;
 
82
    }
 
83
    
 
84
    public String getCatName(int idx) {
 
85
        return categories[idx];
 
86
    }
 
87
    public void setCatName(int idx,String n){
 
88
        if (n.length()>16) {
 
89
                n=n.substring(0,16);
 
90
        }
 
91
        categories[idx]=n;
 
92
    }
 
93
    
 
94
    public static String getStringAt(byte buffer[], int idx) {
 
95
        String str="";
 
96
        while (idx<buffer.length && str.length()<16&&buffer[idx]!=0) {
 
97
                
 
98
                str+=(char)buffer[idx];
 
99
                
 
100
                idx++;
 
101
        }
 
102
        return str;
 
103
    }
 
104
    public int getCatCount() {
 
105
        return catCount;
 
106
    }
 
107
    
 
108
    public String toString() {
 
109
        String out="Kategories";
 
110
        for (int i=0; i<16; i++) {
 
111
                out+=" "+categories[i];
 
112
                if (isCatRenamed(i)) {
 
113
                        out+="(ren)";
 
114
                }
 
115
        }
 
116
        return out;
19
117
    }
20
118
}