src/solaris/classes/sun/awt/X11/WindowDimensions.java

Print this page

        

@@ -71,11 +71,11 @@
     }
 
     public WindowDimensions(final WindowDimensions dims) {
         this.loc = new Point(dims.loc);
         this.size = new Dimension(dims.size);
-        this.insets = (dims.insets != null)?((Insets)dims.insets.clone()):new Insets(0, 0, 0, 0);
+        this.insets = cloneOrZero(dims.insets);
         this.isClientSizeSet = dims.isClientSizeSet;
     }
 
     public Rectangle getClientRect() {
         if (isClientSizeSet) {

@@ -114,11 +114,11 @@
     public Dimension getSize() {
         return getBounds().getSize();
     }
 
     public Insets getInsets() {
-        return (Insets)insets.clone();
+        return cloneOrZero(insets);
     }
     public Rectangle getBounds() {
         if (isClientSizeSet) {
             Rectangle res = new Rectangle(loc, size);
             res.width += (insets.left + insets.right);

@@ -143,11 +143,11 @@
         location.y += insets.top;
         return new Rectangle(location, size);
     }
 
     public void setInsets(Insets in) {
-        insets = (in != null)?((Insets)in.clone()):new Insets(0, 0, 0, 0);
+        insets = cloneOrZero(in);
         if (!isClientSizeSet) {
             if (size.width < (insets.left+insets.right)) {
                 size.width = (insets.left+insets.right);
             }
             if (size.height < (insets.top+insets.bottom)) {

@@ -175,6 +175,11 @@
     }
 
     public int hashCode() {
         return ((insets == null)? (0):(insets.hashCode())) ^ getClientRect().hashCode() ^ getBounds().hashCode();
     }
+
+    private static Insets cloneOrZero(Insets insets) {
+        return insets == null ? new Insets(0, 0, 0, 0) :
+            (Insets)insets.clone();
+    }
 }