source: trunk/packages/invirt-vnc-client/CapsContainer.java @ 2137

Last change on this file since 2137 was 1334, checked in by broder, 16 years ago

sipb-xen-vnc-client -> invirt-vnc-client

File size: 2.7 KB
Line 
1//
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
25import java.util.Vector;
26import java.util.Hashtable;
27
28class CapsContainer {
29
30  // Public methods
31
32  public CapsContainer() {
33    infoMap = new Hashtable(64, (float)0.25);
34    orderedList = new Vector(32, 8);
35  }
36
37  public void add(CapabilityInfo capinfo) {
38    Integer key = new Integer(capinfo.getCode());
39    infoMap.put(key, capinfo);
40  }
41
42  public void add(int code, String vendor, String name, String desc) {
43    Integer key = new Integer(code);
44    infoMap.put(key, new CapabilityInfo(code, vendor, name, desc));
45  }
46
47  public boolean isKnown(int code) {
48    return infoMap.containsKey(new Integer(code));
49  }
50
51  public CapabilityInfo getInfo(int code) {
52    return (CapabilityInfo)infoMap.get(new Integer(code));
53  }
54
55  public String getDescription(int code) {
56    CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(new Integer(code));
57    if (capinfo == null)
58      return null;
59
60    return capinfo.getDescription();
61  }
62
63  public boolean enable(CapabilityInfo other) {
64    Integer key = new Integer(other.getCode());
65    CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(key);
66    if (capinfo == null)
67      return false;
68
69    boolean enabled = capinfo.enableIfEquals(other);
70    if (enabled)
71      orderedList.addElement(key);
72
73    return enabled;
74  }
75
76  public boolean isEnabled(int code) {
77    CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(new Integer(code));
78    if (capinfo == null)
79      return false;
80
81    return capinfo.isEnabled();
82  }
83
84  public int numEnabled() {
85    return orderedList.size();
86  }
87
88  public int getByOrder(int idx) {
89    int code;
90    try {
91      code = ((Integer)orderedList.elementAt(idx)).intValue();
92    } catch (ArrayIndexOutOfBoundsException e) {
93      code = 0;
94    }
95    return code;
96  }
97
98  // Protected data
99
100  protected Hashtable infoMap;
101  protected Vector orderedList;
102}
103
Note: See TracBrowser for help on using the repository browser.