jdk/src/solaris/classes/sun/awt/XSettings.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Per-screen XSETTINGS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class XSettings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private long serial = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Update these settings with <code>data</code> obtained from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * XSETTINGS manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param data settings data obtained from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *     <code>_XSETTINGS_SETTINGS</code> window property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *     settings manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @return a <code>Map</code> of changed settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public Map update(byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return (new Update(data)).update();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * TBS ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    class Update {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        /* byte order mark */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        private static final int LITTLE_ENDIAN = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        private static final int BIG_ENDIAN    = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        /* setting type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        private static final int TYPE_INTEGER = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        private static final int TYPE_STRING  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        private static final int TYPE_COLOR   = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        private byte[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        private int dlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        private int idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        private boolean isLittle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        private long serial = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        private int nsettings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        private boolean isValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        private HashMap updatedSettings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         * Construct an Update object for the data read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * <code>_XSETTINGS_SETTINGS</code> property of the XSETTINGS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * selection owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * @param data <code>_XSETTINGS_SETTINGS</code> contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        Update(byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            this.data = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            dlen = data.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            if (dlen < 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                // XXX: debug trace?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            // first byte gives endianness of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            // next 3 bytes are unused (pad to 32 bit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            idx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            isLittle = (getCARD8() == LITTLE_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            idx = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            serial = getCARD32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            // N_SETTINGS is actually CARD32 (i.e. unsigned), but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            // since java doesn't have an unsigned int type, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // N_SETTINGS cannot realistically exceed 2^31 (so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            // gonna use int anyway), just read it as INT32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            idx = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            nsettings = getINT32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            updatedSettings = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            isValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        private void needBytes(int n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throws IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if (idx + n <= dlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new IndexOutOfBoundsException("at " + idx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                                + " need " + n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                                + " length " + dlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        private int getCARD8()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throws IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            needBytes(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            int val = data[idx] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            ++idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        private int getCARD16()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throws IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            needBytes(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            int val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (isLittle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                val = ((data[idx + 0] & 0xff)      )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    | ((data[idx + 1] & 0xff) <<  8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                val = ((data[idx + 0] & 0xff) <<  8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    | ((data[idx + 1] & 0xff)      );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            idx += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        private int getINT32()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throws IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            needBytes(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            int val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (isLittle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                val = ((data[idx + 0] & 0xff)      )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    | ((data[idx + 1] & 0xff) <<  8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    | ((data[idx + 2] & 0xff) << 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    | ((data[idx + 3] & 0xff) << 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                val = ((data[idx + 0] & 0xff) << 24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    | ((data[idx + 1] & 0xff) << 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    | ((data[idx + 2] & 0xff) <<  8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    | ((data[idx + 3] & 0xff) <<  0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            idx += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        private long getCARD32()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throws IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return getINT32() & 0x00000000ffffffffL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        private String getString(int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            throws IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            needBytes(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            String str = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                str = new String(data, idx, len, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                // XXX: cannot happen, "UTF-8" is always supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            idx = (idx + len + 3) & ~0x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * Update settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public Map update() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (!isValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            synchronized (XSettings.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                long currentSerial = XSettings.this.serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if (this.serial <= currentSerial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                for (int i = 0; i < nsettings && idx < dlen; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    updateOne(currentSerial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                XSettings.this.serial = this.serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return updatedSettings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         * Parses a particular x setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         * @exception IndexOutOfBoundsException if there isn't enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         *     data for a setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        private void updateOne(long currentSerial)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            throws IndexOutOfBoundsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                   IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            int type = getCARD8();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            ++idx;              // pad to next CARD16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            // save position of the property name, skip to serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            int nameLen = getCARD16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            int nameIdx = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            // check if we should bother
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            idx = (idx + nameLen + 3) & ~0x3; // pad to 32 bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            long lastChanged = getCARD32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // Avoid constructing garbage for properties that has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // changed, skip the data for this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (lastChanged <= currentSerial) { // skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                if (type == TYPE_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    idx += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                } else if (type == TYPE_STRING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    int len = getINT32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    idx = (idx + len + 3) & ~0x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                } else if (type == TYPE_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    idx += 8;   // 4 CARD16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    throw new IllegalArgumentException("Unknown type: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                                       + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            idx = nameIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            String name = getString(nameLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            idx += 4;           // skip serial, parsed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            Object value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (type == TYPE_INTEGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                value = Integer.valueOf(getINT32());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            else if (type == TYPE_STRING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                value = getString(getINT32());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            else if (type == TYPE_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                int r = getCARD16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                int g = getCARD16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                int b = getCARD16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                int a = getCARD16();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                value = new Color(r / 65535.0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                  g / 65535.0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                  b / 65535.0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                  a / 65535.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                throw new IllegalArgumentException("Unknown type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                // dtrace???
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            updatedSettings.put(name, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    } // class XSettings.Update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}