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