jdk/src/solaris/classes/sun/awt/X11/WindowDimensions.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 1977 3a9980ccb120
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
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-2005 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 sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
class WindowDimensions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
    private Point loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    private Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    private Insets insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private boolean isClientSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    public WindowDimensions(int x, int y, int width, int height, boolean isClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        this(new Rectangle(x, y, width, height), null, isClient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    public WindowDimensions(Rectangle rec, Insets ins, boolean isClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        if (rec == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
            throw new IllegalArgumentException("Client bounds can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        isClientSizeSet = isClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        this.loc = rec.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        this.size = rec.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        setInsets(ins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public WindowDimensions(Point loc, Dimension size, Insets in, boolean isClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this(new Rectangle(loc, size), in, isClient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public WindowDimensions(Rectangle bounds, boolean isClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this(bounds, null, isClient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public WindowDimensions(final WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.loc = new Point(dims.loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.size = new Dimension(dims.size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this.insets = (dims.insets != null)?((Insets)dims.insets.clone()):new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.isClientSizeSet = dims.isClientSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public Rectangle getClientRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (isClientSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            return new Rectangle(loc, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            // Calculate client bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                return new Rectangle(loc.x, loc.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                     size.width-(insets.left+insets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                     size.height-(insets.top+insets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                return new Rectangle(loc, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void setClientSize(Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.size = new Dimension(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        isClientSizeSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void setClientSize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        size = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        isClientSizeSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public Dimension getClientSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return getClientRect().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void setSize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        size = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        isClientSizeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return getBounds().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return (Insets)insets.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (isClientSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            Rectangle res = new Rectangle(loc, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            res.width += (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            res.height += (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return new Rectangle(loc, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return new Point(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void setLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        loc = new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public Rectangle getScreenBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        Dimension size = getClientSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        Point location = getLocation(); // this is Java location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        location.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        location.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new Rectangle(location, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void setInsets(Insets in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        insets = (in != null)?((Insets)in.clone()):new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (!isClientSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            if (size.width < (insets.left+insets.right)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                size.width = (insets.left+insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (size.height < (insets.top+insets.bottom)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                size.height = (insets.top+insets.bottom);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public boolean isClientSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return isClientSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return "[" + loc + ", " + size + "(" +(isClientSizeSet?"client":"bounds") + ")+" + insets + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (!(o instanceof WindowDimensions)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        WindowDimensions dims = (WindowDimensions)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return ((dims.insets.equals(insets)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            && (getClientRect().equals(dims.getClientRect()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            && (getBounds().equals(dims.getBounds()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return ((insets == null)? (0):(insets.hashCode())) ^ getClientRect().hashCode() ^ getBounds().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
}