jdk/src/share/classes/javax/swing/text/html/Map.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1287 a04aca99c77a
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 1998-2006 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
package javax.swing.text.html;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Polygon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.text.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Map is used to represent a map element that is part of an HTML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Once a Map has been created, and any number of areas have been added,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * you can test if a point falls inside the map via the contains method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author  Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class Map implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /** Name of the Map. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private String           name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /** An array of AttributeSets. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Vector           areaAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /** An array of RegionContainments, will slowly grow to match the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * length of areaAttributes as needed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private Vector           areas;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public Map() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public Map(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Returns the name of the Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Defines a region of the Map, based on the passed in AttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public void addArea(AttributeSet as) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (areaAttributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            areaAttributes = new Vector(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        areaAttributes.addElement(as.copyAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Removes the previously created area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void removeArea(AttributeSet as) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (as != null && areaAttributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            int numAreas = (areas != null) ? areas.size() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            for (int counter = areaAttributes.size() - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                 counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                if (((AttributeSet)areaAttributes.elementAt(counter)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    isEqual(as)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    areaAttributes.removeElementAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    if (counter < numAreas) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        areas.removeElementAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Returns the AttributeSets representing the differet areas of the Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public AttributeSet[] getAreas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int numAttributes = (areaAttributes != null) ? areaAttributes.size() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                            0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (numAttributes != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            AttributeSet[]    retValue = new AttributeSet[numAttributes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            areaAttributes.copyInto(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Returns the AttributeSet that contains the passed in location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * <code>x</code>, <code>y</code>. <code>width</code>, <code>height</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * gives the size of the region the map is defined over. If a matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * area is found, the AttribueSet for it is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public AttributeSet getArea(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int      numAttributes = (areaAttributes != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                 areaAttributes.size() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (numAttributes > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            int      numAreas = (areas != null) ? areas.size() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (areas == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                areas = new Vector(numAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            for (int counter = 0; counter < numAttributes; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                if (counter >= numAreas) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    areas.addElement(createRegionContainment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                            ((AttributeSet)areaAttributes.elementAt(counter)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                RegionContainment       rc = (RegionContainment)areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                             elementAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (rc != null && rc.contains(x, y, width, height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    return (AttributeSet)areaAttributes.elementAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Creates and returns an instance of RegionContainment that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * used to test if a particular point lies inside a region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected RegionContainment createRegionContainment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                  (AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        Object     shape = attributes.getAttribute(HTML.Attribute.SHAPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (shape == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            shape = "rect";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (shape instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            String                shapeString = ((String)shape).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            RegionContainment     rc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                if (shapeString.equals("rect")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    rc = new RectangleRegionContainment(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                else if (shapeString.equals("circle")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    rc = new CircleRegionContainment(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                else if (shapeString.equals("poly")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    rc = new PolygonRegionContainment(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                else if (shapeString.equals("default")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    rc = DefaultRegionContainment.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } catch (RuntimeException re) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                // Something wrong with attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                rc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Creates and returns an array of integers from the String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <code>stringCoords</code>. If one of the values represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * % the returned value with be negative. If a parse error results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * from trying to parse one of the numbers null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    static protected int[] extractCoords(Object stringCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (stringCoords == null || !(stringCoords instanceof String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        StringTokenizer    st = new StringTokenizer((String)stringCoords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                                    ", \t\n\r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        int[]              retValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        int                numCoords = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        while(st.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            String         token = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            int            scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (token.endsWith("%")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                scale = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                token = token.substring(0, token.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                scale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                int       intValue = Integer.parseInt(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (retValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    retValue = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                else if(numCoords == retValue.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    int[]    temp = new int[retValue.length * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    System.arraycopy(retValue, 0, temp, 0, retValue.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    retValue = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                retValue[numCoords++] = intValue * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (numCoords > 0 && numCoords != retValue.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            int[]    temp = new int[numCoords];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            System.arraycopy(retValue, 0, temp, 0, numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            retValue = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Defines the interface used for to check if a point is inside a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    interface RegionContainment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * Returns true if the location <code>x</code>, <code>y</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         * falls inside the region defined in the receiver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         * <code>width</code>, <code>height</code> is the size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         * the enclosing region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public boolean contains(int x, int y, int width, int height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Used to test for containment in a rectangular region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    static class RectangleRegionContainment implements RegionContainment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        /** Will be non-null if one of the values is a percent, and any value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * that is non null indicates it is a percent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         * (order is x, y, width, height). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        float[]       percents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        /** Last value of width passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int           lastWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /** Last value of height passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        int           lastHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        /** Top left. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        int           x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        int           y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /** Bottom right. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        int           x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        int           y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        public RectangleRegionContainment(AttributeSet as) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            int[]    coords = Map.extractCoords(as.getAttribute(HTML.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                                           Attribute.COORDS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            percents = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (coords == null || coords.length != 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                throw new RuntimeException("Unable to parse rectangular area");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                x0 = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                y0 = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                x1 = coords[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                y1 = coords[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (x0 < 0 || y0 < 0 || x1 < 0 || y1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    percents = new float[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    lastWidth = lastHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    for (int counter = 0; counter < 4; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                        if (coords[counter] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                            percents[counter] = Math.abs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                        (coords[counter]) / 100.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                            percents[counter] = -1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        public boolean contains(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (percents == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                return contains(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (lastWidth != width || lastHeight != height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                lastWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                lastHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                if (percents[0] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    x0 = (int)(percents[0] * width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                if (percents[1] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    y0 = (int)(percents[1] * height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                if (percents[2] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    x1 = (int)(percents[2] * width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                if (percents[3] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    y1 = (int)(percents[3] * height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return contains(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        public boolean contains(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return ((x >= x0 && x <= x1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    (y >= y0 && y <= y1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Used to test for containment in a polygon region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    static class PolygonRegionContainment extends Polygon implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                 RegionContainment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        /** If any value is a percent there will be an entry here for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * percent value. Use percentIndex to find out the index for it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        float[]           percentValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        int[]             percentIndexs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        /** Last value of width passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        int               lastWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        /** Last value of height passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        int               lastHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        public PolygonRegionContainment(AttributeSet as) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            int[]    coords = Map.extractCoords(as.getAttribute(HTML.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                                                COORDS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            if (coords == null || coords.length == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                coords.length % 2 != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                throw new RuntimeException("Unable to parse polygon area");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                int        numPercents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                lastWidth = lastHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                for (int counter = coords.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                     counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    if (coords[counter] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        numPercents++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                if (numPercents > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    percentIndexs = new int[numPercents];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    percentValues = new float[numPercents];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    for (int counter = coords.length - 1, pCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                         counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        if (coords[counter] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                            percentValues[pCounter] = coords[counter] /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                                      -100.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                            percentIndexs[pCounter] = counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                            pCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    percentIndexs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    percentValues = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                npoints = coords.length / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                xpoints = new int[npoints];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                ypoints = new int[npoints];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                for (int counter = 0; counter < npoints; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    xpoints[counter] = coords[counter + counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    ypoints[counter] = coords[counter + counter + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        public boolean contains(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (percentValues == null || (lastWidth == width &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                          lastHeight == height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                return contains(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // Force the bounding box to be recalced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            bounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            lastWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            lastHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            float fWidth = (float)width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            float fHeight = (float)height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            for (int counter = percentValues.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                 counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                if (percentIndexs[counter] % 2 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    // x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    xpoints[percentIndexs[counter] / 2] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                            (int)(percentValues[counter] * fWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    // y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    ypoints[percentIndexs[counter] / 2] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                            (int)(percentValues[counter] * fHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            return contains(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Used to test for containment in a circular region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    static class CircleRegionContainment implements RegionContainment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        /** X origin of the circle. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        int           x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        /** Y origin of the circle. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        int           y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        /** Radius of the circle. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        int           radiusSquared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        /** Non-null indicates one of the values represents a percent. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        float[]       percentValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        /** Last value of width passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        int           lastWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        /** Last value of height passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int           lastHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        public CircleRegionContainment(AttributeSet as) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            int[]    coords = Map.extractCoords(as.getAttribute(HTML.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                                                COORDS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (coords == null || coords.length != 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                throw new RuntimeException("Unable to parse circular area");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            x = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            y = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            radiusSquared = coords[2] * coords[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (coords[0] < 0 || coords[1] < 0 || coords[2] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                lastWidth = lastHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                percentValues = new float[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    if (coords[counter] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        percentValues[counter] = coords[counter] /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                                 -100.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        percentValues[counter] = -1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                percentValues = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        public boolean contains(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if (percentValues != null && (lastWidth != width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                          lastHeight != height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                int      newRad = Math.min(width, height) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                lastWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                lastHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                if (percentValues[0] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    this.x = (int)(percentValues[0] * width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if (percentValues[1] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    this.y = (int)(percentValues[1] * height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                if (percentValues[2] != -1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    radiusSquared = (int)(percentValues[2] *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                   Math.min(width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    radiusSquared *= radiusSquared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return (((x - this.x) * (x - this.x) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                     (y - this.y) * (y - this.y)) <= radiusSquared);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * An implementation that will return true if the x, y location is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * inside a rectangle defined by origin 0, 0, and width equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * width passed in, and height equal to height passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    static class DefaultRegionContainment implements RegionContainment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        /** A global shared instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        static DefaultRegionContainment  si = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        public static DefaultRegionContainment sharedInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if (si == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                si = new DefaultRegionContainment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            return si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        public boolean contains(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            return (x <= width && x >= 0 && y >= 0 && y <= width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
}