JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
Insets.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.nativewindow.util;
30
31/**
32 * Mutable insets representing rectangular window decoration insets on all four edges
33 * in window units.
34 */
35public class Insets implements Cloneable, InsetsImmutable {
36 static final InsetsImmutable zeroInsets = new Insets();
37 public static final InsetsImmutable getZero() { return zeroInsets; }
38
39 private int l, r, t, b;
40
41 public Insets() {
42 this(0, 0, 0, 0);
43 }
44
45 public Insets(final int left, final int right, final int top, final int bottom) {
46 this.l=left;
47 this.r=right;
48 this.t=top;
49 this.b=bottom;
50 }
51
52 @Override
53 public Object cloneMutable() {
54 return clone();
55 }
56
57 @Override
58 protected Object clone() {
59 try {
60 return super.clone();
61 } catch (final CloneNotSupportedException ex) {
62 throw new InternalError();
63 }
64 }
65
66 @Override
67 public final int getLeftWidth() { return l; }
68 @Override
69 public final int getRightWidth() { return r; }
70 @Override
71 public final int getTotalWidth() { return l + r; }
72 @Override
73 public final int getTopHeight() { return t; }
74 @Override
75 public final int getBottomHeight() { return b; }
76 @Override
77 public final int getTotalHeight() { return t + b; }
78
79 /**
80 * Set the inset values of this instance in window units.
81 * @param left left inset width in window units.
82 * @param right right inset width in window units.
83 * @param top top inset width in window units.
84 * @param bottom bottom inset width in window units.
85 */
86 public final void set(final int left, final int right, final int top, final int bottom) {
87 l = left; r = right; t = top; b = bottom;
88 }
89 /**
90 * Set the left inset value of this instance in window units.
91 * @param left left inset width in window units.
92 */
93 public final void setLeftWidth(final int left) { l = left; }
94 /**
95 * Set the right inset value of this instance in window units.
96 * @param right right inset width in window units.
97 */
98 public final void setRightWidth(final int right) { r = right; }
99 /**
100 * Set the top inset value of this instance in window units.
101 * @param top top inset width in window units.
102 */
103 public final void setTopHeight(final int top) { t = top; }
104 /**
105 * Set the bottom inset value of this instance in window units.
106 * @param bottom bottom inset width in window units.
107 */
108 public final void setBottomHeight(final int bottom) { b = bottom; }
109
110 @Override
111 public boolean equals(final Object obj) {
112 if(this == obj) { return true; }
113 if (obj instanceof Insets) {
114 final Insets insets = (Insets)obj;
115 return (r == insets.r) && (l == insets.l) &&
116 (b == insets.b) && (t == insets.t);
117 }
118 return false;
119 }
120
121 @Override
122 public int hashCode() {
123 final int sum1 = l + b;
124 final int sum2 = t + r;
125 final int val1 = sum1 * (sum1 + 1)/2 + l;
126 final int val2 = sum2 * (sum2 + 1)/2 + r;
127 final int sum3 = val1 + val2;
128 return sum3 * (sum3 + 1)/2 + val2;
129 }
130
131 @Override
132 public String toString() {
133 return "[ l "+l+", r "+r+" - t "+t+", b "+b+" - "+getTotalWidth()+"x"+getTotalHeight()+"]";
134 }
135}
136
Mutable insets representing rectangular window decoration insets on all four edges in window units.
Definition: Insets.java:35
static final InsetsImmutable getZero()
Definition: Insets.java:37
Insets(final int left, final int right, final int top, final int bottom)
Definition: Insets.java:45
final void setBottomHeight(final int bottom)
Set the bottom inset value of this instance in window units.
Definition: Insets.java:108
final void setLeftWidth(final int left)
Set the left inset value of this instance in window units.
Definition: Insets.java:93
boolean equals(final Object obj)
Checks whether two rect objects are equal.
Definition: Insets.java:111
final void setTopHeight(final int top)
Set the top inset value of this instance in window units.
Definition: Insets.java:103
final void setRightWidth(final int right)
Set the right inset value of this instance in window units.
Definition: Insets.java:98
Immutable insets representing rectangular window decoration insets on all four edges in window units.