You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CapsContainer.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // CapsContainer.java - A container of capabilities as used in the RFB
  21. // protocol 3.130
  22. //
  23. import java.util.Vector;
  24. import java.util.Hashtable;
  25. class CapsContainer {
  26. // Public methods
  27. public CapsContainer() {
  28. infoMap = new Hashtable(64, (float)0.25);
  29. orderedList = new Vector(32, 8);
  30. }
  31. public void add(CapabilityInfo capinfo) {
  32. Integer key = new Integer(capinfo.getCode());
  33. infoMap.put(key, capinfo);
  34. }
  35. public void add(int code, String vendor, String name, String desc) {
  36. Integer key = new Integer(code);
  37. infoMap.put(key, new CapabilityInfo(code, vendor, name, desc));
  38. }
  39. public boolean isKnown(int code) {
  40. return infoMap.containsKey(new Integer(code));
  41. }
  42. public CapabilityInfo getInfo(int code) {
  43. return (CapabilityInfo)infoMap.get(new Integer(code));
  44. }
  45. public String getDescription(int code) {
  46. CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(new Integer(code));
  47. if (capinfo == null)
  48. return null;
  49. return capinfo.getDescription();
  50. }
  51. public boolean enable(CapabilityInfo other) {
  52. Integer key = new Integer(other.getCode());
  53. CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(key);
  54. if (capinfo == null)
  55. return false;
  56. boolean enabled = capinfo.enableIfEquals(other);
  57. if (enabled)
  58. orderedList.addElement(key);
  59. return enabled;
  60. }
  61. public boolean isEnabled(int code) {
  62. CapabilityInfo capinfo = (CapabilityInfo)infoMap.get(new Integer(code));
  63. if (capinfo == null)
  64. return false;
  65. return capinfo.isEnabled();
  66. }
  67. public int numEnabled() {
  68. return orderedList.size();
  69. }
  70. public int getByOrder(int idx) {
  71. int code;
  72. try {
  73. code = ((Integer)orderedList.elementAt(idx)).intValue();
  74. } catch (ArrayIndexOutOfBoundsException e) {
  75. code = 0;
  76. }
  77. return code;
  78. }
  79. // Protected data
  80. protected Hashtable infoMap;
  81. protected Vector orderedList;
  82. }