24
|
1 package myVncProxy;
|
0
|
2 //
|
|
3 // Copyright (C) 2003 Constantin Kaplinsky. All Rights Reserved.
|
|
4 //
|
|
5 // This is free software; you can redistribute it and/or modify
|
|
6 // it under the terms of the GNU General Public License as published by
|
|
7 // the Free Software Foundation; either version 2 of the License, or
|
|
8 // (at your option) any later version.
|
|
9 //
|
|
10 // This software is distributed in the hope that it will be useful,
|
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 // GNU General Public License for more details.
|
|
14 //
|
|
15 // You should have received a copy of the GNU General Public License
|
|
16 // along with this software; if not, write to the Free Software
|
|
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
18 // USA.
|
|
19 //
|
|
20
|
|
21 //
|
|
22 // CapsContainer.java - A container of capabilities as used in the RFB
|
|
23 // protocol 3.130
|
|
24 //
|
|
25
|
|
26 import java.util.Vector;
|
|
27 import java.util.Hashtable;
|
|
28
|
|
29 class CapsContainer {
|
|
30
|
|
31 // Public methods
|
|
32
|
|
33 public CapsContainer() {
|
|
34 infoMap = new Hashtable(64, (float)0.25);
|
|
35 orderedList = new Vector(32, 8);
|
|
36 }
|
|
37
|
|
38 public void add(CapabilityInfo capinfo) {
|
|
39 Integer key = new Integer(capinfo.getCode());
|
|
40 infoMap.put(key, capinfo);
|
|
41 }
|
|
42
|
|
43 public void add(int code, String vendor, String name, String desc) {
|
|
44 Integer key = new Integer(code);
|
|
45 infoMap.put(key, new CapabilityInfo(code, vendor, name, desc));
|
|
46 }
|
|
47
|
|
48 public boolean isKnown(int code) {
|
|
49 return infoMap.containsKey(new Integer(code));
|
|
50 }
|
|
51
|
|
52 public CapabilityInfo getInfo(int code) {
|
|
53 return (CapabilityInfo)infoMap.get(new Integer(code));
|
|
54 }
|
|
55
|
|
56 public String getDescription(int code) {
|
|
57 CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(new Integer(code));
|
|
58 if (capinfo == null)
|
|
59 return null;
|
|
60
|
|
61 return capinfo.getDescription();
|
|
62 }
|
|
63
|
|
64 public boolean enable(CapabilityInfo other) {
|
|
65 Integer key = new Integer(other.getCode());
|
|
66 CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(key);
|
|
67 if (capinfo == null)
|
|
68 return false;
|
|
69
|
|
70 boolean enabled = capinfo.enableIfEquals(other);
|
|
71 if (enabled)
|
|
72 orderedList.addElement(key);
|
|
73
|
|
74 return enabled;
|
|
75 }
|
|
76
|
|
77 public boolean isEnabled(int code) {
|
|
78 CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(new Integer(code));
|
|
79 if (capinfo == null)
|
|
80 return false;
|
|
81
|
|
82 return capinfo.isEnabled();
|
|
83 }
|
|
84
|
|
85 public int numEnabled() {
|
|
86 return orderedList.size();
|
|
87 }
|
|
88
|
|
89 public int getByOrder(int idx) {
|
|
90 int code;
|
|
91 try {
|
|
92 code = ((Integer)orderedList.elementAt(idx)).intValue();
|
|
93 } catch (ArrayIndexOutOfBoundsException e) {
|
|
94 code = 0;
|
|
95 }
|
|
96 return code;
|
|
97 }
|
|
98
|
|
99 // Protected data
|
|
100
|
|
101 protected Hashtable infoMap;
|
|
102 protected Vector orderedList;
|
|
103 }
|
|
104
|