001: /*
002: * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.X11;
027:
028: import java.util.HashMap;
029: import java.util.Iterator;
030: import java.util.Map;
031:
032: public class XCreateWindowParams extends HashMap {
033: public XCreateWindowParams() {
034: }
035:
036: public XCreateWindowParams(Object[] map) {
037: init(map);
038: }
039:
040: private void init(Object[] map) {
041: if (map.length % 2 != 0) {
042: throw new IllegalArgumentException(
043: "Map size should be devisible by two");
044: }
045: for (int i = 0; i < map.length; i += 2) {
046: put(map[i], map[i + 1]);
047: }
048: }
049:
050: public XCreateWindowParams putIfNull(Object key, Object value) {
051: if (!containsKey(key)) {
052: put(key, value);
053: }
054: return this ;
055: }
056:
057: public XCreateWindowParams putIfNull(Object key, int value) {
058: if (!containsKey(key)) {
059: put(key, Integer.valueOf(value));
060: }
061: return this ;
062: }
063:
064: public XCreateWindowParams putIfNull(Object key, long value) {
065: if (!containsKey(key)) {
066: put(key, Long.valueOf(value));
067: }
068: return this ;
069: }
070:
071: public XCreateWindowParams add(Object key, Object value) {
072: put(key, value);
073: return this ;
074: }
075:
076: public XCreateWindowParams add(Object key, int value) {
077: put(key, Integer.valueOf(value));
078: return this ;
079: }
080:
081: public XCreateWindowParams add(Object key, long value) {
082: put(key, Long.valueOf(value));
083: return this ;
084: }
085:
086: public XCreateWindowParams delete(Object key) {
087: remove(key);
088: return this ;
089: }
090:
091: public String toString() {
092: StringBuffer buf = new StringBuffer();
093: Iterator eIter = entrySet().iterator();
094: while (eIter.hasNext()) {
095: Map.Entry entry = (Map.Entry) eIter.next();
096: buf.append(entry.getKey() + ": " + entry.getValue() + "\n");
097: }
098: return buf.toString();
099: }
100:
101: }
|