1. /*
  2. * @(#)MultiUIDefaults.java 1.10 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing;
  11. import java.util.Enumeration;
  12. /**
  13. *
  14. * @version 1.10 02/02/00
  15. * @author Hans Muller
  16. */
  17. class MultiUIDefaults extends UIDefaults
  18. {
  19. private UIDefaults[] tables;
  20. public MultiUIDefaults(UIDefaults[] defaults) {
  21. super();
  22. tables = defaults;
  23. }
  24. public MultiUIDefaults() {
  25. super();
  26. tables = new UIDefaults[0];
  27. }
  28. public Object get(Object key)
  29. {
  30. Object value = super.get(key);
  31. if (value != null) {
  32. return value;
  33. }
  34. for(int i = 0; i < tables.length; i++) {
  35. UIDefaults table = tables[i];
  36. value = (table != null) ? table.get(key) : null;
  37. if (value != null) {
  38. return value;
  39. }
  40. }
  41. return null;
  42. }
  43. public int size() {
  44. int n = super.size();
  45. for(int i = 0; i < tables.length; i++) {
  46. UIDefaults table = tables[i];
  47. n += (table != null) ? table.size() : 0;
  48. }
  49. return n;
  50. }
  51. public boolean isEmpty() {
  52. return size() == 0;
  53. }
  54. public Enumeration keys()
  55. {
  56. Enumeration[] enums = new Enumeration[1 + tables.length];
  57. enums[0] = super.keys();
  58. for(int i = 0; i < tables.length; i++) {
  59. UIDefaults table = tables[i];
  60. if (table != null) {
  61. enums[i + 1] = table.keys();
  62. }
  63. }
  64. return new MultiUIDefaultsEnumerator(enums);
  65. }
  66. public Enumeration elements()
  67. {
  68. Enumeration[] enums = new Enumeration[1 + tables.length];
  69. enums[0] = super.elements();
  70. for(int i = 0; i < tables.length; i++) {
  71. UIDefaults table = tables[i];
  72. if (table != null) {
  73. enums[i + 1] = table.elements();
  74. }
  75. }
  76. return new MultiUIDefaultsEnumerator(enums);
  77. }
  78. private static class MultiUIDefaultsEnumerator implements Enumeration
  79. {
  80. Enumeration[] enums;
  81. int n = 0;
  82. MultiUIDefaultsEnumerator(Enumeration[] enums) {
  83. this.enums = enums;
  84. }
  85. public boolean hasMoreElements() {
  86. for(int i = n; i < enums.length; i++) {
  87. Enumeration e = enums[i];
  88. if ((e != null) && (e.hasMoreElements())) {
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. public Object nextElement() {
  95. for(; n < enums.length; n++) {
  96. Enumeration e = enums[n];
  97. if ((e != null) && (e.hasMoreElements())) {
  98. return e.nextElement();
  99. }
  100. }
  101. return null;
  102. }
  103. }
  104. public Object remove(Object key)
  105. {
  106. Object value = super.remove(key);
  107. if (value != null) {
  108. return value;
  109. }
  110. for(int i = 0; i < tables.length; i++) {
  111. UIDefaults table = tables[i];
  112. value = (table != null) ? table.remove(key) : null;
  113. if (value != null) {
  114. return value;
  115. }
  116. }
  117. return null;
  118. }
  119. public void clear() {
  120. super.clear();
  121. for(int i = 0; i < tables.length; i++) {
  122. UIDefaults table = tables[i];
  123. if (table != null) {
  124. table.clear();
  125. }
  126. }
  127. }
  128. }