JOGL: src/nativewindow/classes/com/jogamp/nativewindow/util/Insets.java Source File

JOGL v2.6.0-rc-20250721 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 */
35 public 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
com.jogamp.nativewindow.util.Insets
Mutable insets representing rectangular window decoration insets on all four edges in window units.
Definition: Insets.java:35
com.jogamp.nativewindow.util.Insets.getRightWidth
final int getRightWidth()
Definition: Insets.java:69
com.jogamp.nativewindow.util.Insets.getTotalWidth
final int getTotalWidth()
Definition: Insets.java:71
com.jogamp.nativewindow.util.Insets.getZero
static final InsetsImmutable getZero()
Definition: Insets.java:37
com.jogamp.nativewindow.util.Insets.Insets
Insets()
Definition: Insets.java:41
com.jogamp.nativewindow.util.Insets.Insets
Insets(final int left, final int right, final int top, final int bottom)
Definition: Insets.java:45
com.jogamp.nativewindow.util.Insets.getTopHeight
final int getTopHeight()
Definition: Insets.java:73
com.jogamp.nativewindow.util.Insets.getLeftWidth
final int getLeftWidth()
Definition: Insets.java:67
com.jogamp.nativewindow.util.Insets.getTotalHeight
final int getTotalHeight()
Definition: Insets.java:77
com.jogamp.nativewindow.util.Insets.setBottomHeight
final void setBottomHeight(final int bottom)
Set the bottom inset value of this instance in window units.
Definition: Insets.java:108
com.jogamp.nativewindow.util.Insets.setLeftWidth
final void setLeftWidth(final int left)
Set the left inset value of this instance in window units.
Definition: Insets.java:93
com.jogamp.nativewindow.util.Insets.hashCode
int hashCode()
Definition: Insets.java:122
com.jogamp.nativewindow.util.Insets.cloneMutable
Object cloneMutable()
Definition: Insets.java:53
com.jogamp.nativewindow.util.Insets.equals
boolean equals(final Object obj)
Checks whether two rect objects are equal.
Definition: Insets.java:111
com.jogamp.nativewindow.util.Insets.toString
String toString()
Definition: Insets.java:132
com.jogamp.nativewindow.util.Insets.setTopHeight
final void setTopHeight(final int top)
Set the top inset value of this instance in window units.
Definition: Insets.java:103
com.jogamp.nativewindow.util.Insets.setRightWidth
final void setRightWidth(final int right)
Set the right inset value of this instance in window units.
Definition: Insets.java:98
com.jogamp.nativewindow.util.Insets.clone
Object clone()
Definition: Insets.java:58
com.jogamp.nativewindow.util.Insets.getBottomHeight
final int getBottomHeight()
Definition: Insets.java:75
com.jogamp.nativewindow.util.InsetsImmutable
Immutable insets representing rectangular window decoration insets on all four edges in window units.
Definition: InsetsImmutable.java:37