Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/WindowDimensions.java
32288 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.awt.X11;2526import java.awt.*;2728class WindowDimensions {29private Point loc;30private Dimension size;31private Insets insets;32private boolean isClientSizeSet;3334/**35* If isClient is true, the bounds represent the client window area.36* Otherwise, they represent the entire window area, with the insets included37*/38public WindowDimensions(int x, int y, int width, int height, boolean isClient) {39this(new Rectangle(x, y, width, height), null, isClient);40}4142/**43* If isClient is true, the bounds represent the client window area.44* Otherwise, they represent the entire window area, with the insets included45*/46public WindowDimensions(Rectangle rec, Insets ins, boolean isClient) {47if (rec == null) {48throw new IllegalArgumentException("Client bounds can't be null");49}50isClientSizeSet = isClient;51this.loc = rec.getLocation();52this.size = rec.getSize();53setInsets(ins);54}5556/**57* If isClient is true, the bounds represent the client window area.58* Otherwise, they represent the entire window area, with the insets included59*/60public WindowDimensions(Point loc, Dimension size, Insets in, boolean isClient) {61this(new Rectangle(loc, size), in, isClient);62}6364/**65* If isClient is true, the bounds represent the client window area.66* Otherwise, they represent the entire window area, with the insets included67*/68public WindowDimensions(Rectangle bounds, boolean isClient) {69this(bounds, null, isClient);70}7172public WindowDimensions(final WindowDimensions dims) {73this.loc = new Point(dims.loc);74this.size = new Dimension(dims.size);75this.insets = (dims.insets != null)?((Insets)dims.insets.clone()):new Insets(0, 0, 0, 0);76this.isClientSizeSet = dims.isClientSizeSet;77}7879public Rectangle getClientRect() {80if (isClientSizeSet) {81return new Rectangle(loc, size);82} else {83// Calculate client bounds84if (insets != null) {85return new Rectangle(loc.x, loc.y,86size.width-(insets.left+insets.right),87size.height-(insets.top+insets.bottom));88} else {89return new Rectangle(loc, size);90}91}92}9394public void setClientSize(Dimension size) {95this.size = new Dimension(size);96isClientSizeSet = true;97}9899public void setClientSize(int width, int height) {100size = new Dimension(width, height);101isClientSizeSet = true;102}103104public Dimension getClientSize() {105return getClientRect().getSize();106}107108public void setSize(int width, int height) {109size = new Dimension(width, height);110isClientSizeSet = false;111}112113public Dimension getSize() {114return getBounds().getSize();115}116117public Insets getInsets() {118return (Insets)insets.clone();119}120public Rectangle getBounds() {121if (isClientSizeSet) {122Rectangle res = new Rectangle(loc, size);123res.width += (insets.left + insets.right);124res.height += (insets.top + insets.bottom);125return res;126} else {127return new Rectangle(loc, size);128}129}130131public Point getLocation() {132return new Point(loc);133}134public void setLocation(int x, int y) {135loc = new Point(x, y);136}137138public Rectangle getScreenBounds() {139Dimension size = getClientSize();140Point location = getLocation(); // this is Java location141location.x += insets.left;142location.y += insets.top;143return new Rectangle(location, size);144}145146public void setInsets(Insets in) {147insets = (in != null)?((Insets)in.clone()):new Insets(0, 0, 0, 0);148if (!isClientSizeSet) {149if (size.width < (insets.left+insets.right)) {150size.width = (insets.left+insets.right);151}152if (size.height < (insets.top+insets.bottom)) {153size.height = (insets.top+insets.bottom);154}155}156}157158public boolean isClientSizeSet() {159return isClientSizeSet;160}161162public String toString() {163return "[" + loc + ", " + size + "(" +(isClientSizeSet?"client":"bounds") + ")+" + insets + "]";164}165166public boolean equals(Object o) {167if (!(o instanceof WindowDimensions)) {168return false;169}170WindowDimensions dims = (WindowDimensions)o;171return ((dims.insets.equals(insets)))172&& (getClientRect().equals(dims.getClientRect()))173&& (getBounds().equals(dims.getBounds()));174}175176public int hashCode() {177return ((insets == null)? (0):(insets.hashCode())) ^ getClientRect().hashCode() ^ getBounds().hashCode();178}179}180181182