0N/A/*
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing;
0N/A
0N/Aimport java.util.Enumeration;
1173N/Aimport java.util.HashSet;
2140N/Aimport java.util.Iterator;
0N/Aimport java.util.Locale;
1173N/Aimport java.util.Map.Entry;
1173N/Aimport java.util.Set;
0N/A
0N/A
0N/A
0N/A/**
0N/A *
0N/A * @author Hans Muller
0N/A */
0N/Aclass MultiUIDefaults extends UIDefaults
0N/A{
0N/A private UIDefaults[] tables;
0N/A
0N/A public MultiUIDefaults(UIDefaults[] defaults) {
0N/A super();
0N/A tables = defaults;
0N/A }
0N/A
0N/A public MultiUIDefaults() {
0N/A super();
0N/A tables = new UIDefaults[0];
0N/A }
0N/A
1173N/A @Override
0N/A public Object get(Object key)
0N/A {
0N/A Object value = super.get(key);
0N/A if (value != null) {
0N/A return value;
0N/A }
0N/A
625N/A for (UIDefaults table : tables) {
0N/A value = (table != null) ? table.get(key) : null;
0N/A if (value != null) {
0N/A return value;
0N/A }
0N/A }
0N/A
0N/A return null;
0N/A }
0N/A
1173N/A @Override
0N/A public Object get(Object key, Locale l)
0N/A {
0N/A Object value = super.get(key,l);
0N/A if (value != null) {
0N/A return value;
0N/A }
0N/A
625N/A for (UIDefaults table : tables) {
0N/A value = (table != null) ? table.get(key,l) : null;
0N/A if (value != null) {
0N/A return value;
0N/A }
0N/A }
0N/A
0N/A return null;
0N/A }
0N/A
1173N/A @Override
0N/A public int size() {
2140N/A return entrySet().size();
0N/A }
0N/A
1173N/A @Override
0N/A public boolean isEmpty() {
0N/A return size() == 0;
0N/A }
0N/A
1173N/A @Override
625N/A public Enumeration<Object> keys()
0N/A {
2140N/A return new MultiUIDefaultsEnumerator(
2140N/A MultiUIDefaultsEnumerator.Type.KEYS, entrySet());
0N/A }
0N/A
1173N/A @Override
625N/A public Enumeration<Object> elements()
0N/A {
2140N/A return new MultiUIDefaultsEnumerator(
2140N/A MultiUIDefaultsEnumerator.Type.ELEMENTS, entrySet());
0N/A }
0N/A
1173N/A @Override
1173N/A public Set<Entry<Object, Object>> entrySet() {
1173N/A Set<Entry<Object, Object>> set = new HashSet<Entry<Object, Object>>();
2140N/A for (int i = tables.length - 1; i >= 0; i--) {
2140N/A if (tables[i] != null) {
2140N/A set.addAll(tables[i].entrySet());
1173N/A }
1173N/A }
2140N/A set.addAll(super.entrySet());
1173N/A return set;
1173N/A }
1173N/A
1173N/A @Override
0N/A protected void getUIError(String msg) {
0N/A if (tables.length > 0) {
0N/A tables[0].getUIError(msg);
0N/A } else {
0N/A super.getUIError(msg);
0N/A }
0N/A }
0N/A
625N/A private static class MultiUIDefaultsEnumerator implements Enumeration<Object>
0N/A {
2140N/A public static enum Type { KEYS, ELEMENTS };
2140N/A private Iterator<Entry<Object, Object>> iterator;
2140N/A private Type type;
0N/A
2140N/A MultiUIDefaultsEnumerator(Type type, Set<Entry<Object, Object>> entries) {
2140N/A this.type = type;
2140N/A this.iterator = entries.iterator();
0N/A }
0N/A
0N/A public boolean hasMoreElements() {
2140N/A return iterator.hasNext();
0N/A }
0N/A
0N/A public Object nextElement() {
2140N/A switch (type) {
2140N/A case KEYS: return iterator.next().getKey();
2140N/A case ELEMENTS: return iterator.next().getValue();
2140N/A default: return null;
0N/A }
0N/A }
0N/A }
0N/A
1173N/A @Override
0N/A public Object remove(Object key)
0N/A {
2140N/A Object value = null;
2140N/A for (int i = tables.length - 1; i >= 0; i--) {
2140N/A if (tables[i] != null) {
2140N/A Object v = tables[i].remove(key);
2140N/A if (v != null) {
2140N/A value = v;
2140N/A }
2140N/A }
2140N/A }
2140N/A Object v = super.remove(key);
2140N/A if (v != null) {
2140N/A value = v;
0N/A }
0N/A
2140N/A return value;
0N/A }
0N/A
1173N/A @Override
0N/A public void clear() {
0N/A super.clear();
625N/A for (UIDefaults table : tables) {
0N/A if (table != null) {
0N/A table.clear();
0N/A }
0N/A }
0N/A }
0N/A
1173N/A @Override
0N/A public synchronized String toString() {
0N/A StringBuffer buf = new StringBuffer();
0N/A buf.append("{");
0N/A Enumeration keys = keys();
0N/A while (keys.hasMoreElements()) {
0N/A Object key = keys.nextElement();
0N/A buf.append(key + "=" + get(key) + ", ");
0N/A }
0N/A int length = buf.length();
0N/A if (length > 1) {
0N/A buf.delete(length-2, length);
0N/A }
0N/A buf.append("}");
0N/A return buf.toString();
0N/A }
0N/A}