Source: util/Insets.js

  1. /*
  2. * Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
  3. * by the Administrator of the National Aeronautics and Space Administration.
  4. * All rights reserved.
  5. *
  6. * The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
  7. * Version 2.0 (the "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License
  9. * at http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. *
  16. * NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
  17. * software:
  18. *
  19. * ES6-Promise – under MIT License
  20. * libtess.js – SGI Free Software License B
  21. * Proj4 – under MIT License
  22. * JSZip – under MIT License
  23. *
  24. * A complete listing of 3rd Party software notices and licenses included in
  25. * WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
  26. * PDF found in code directory.
  27. */
  28. define(['../error/ArgumentError',
  29. '../util/Logger'
  30. ],
  31. function (ArgumentError,
  32. Logger) {
  33. "use strict";
  34. /**
  35. * Constructs an Insets object that is a representation of the borders of a container.
  36. * It specifies the space that a container must leave at each of its edges.
  37. * @alias Insets
  38. * @param {Number} top The inset from the top.
  39. * @param {Number} left The inset from the left.
  40. * @param {Number} bottom The inset from the bottom.
  41. * @param {Number} right The inset from the right.
  42. * @constructor
  43. */
  44. var Insets = function (top, left, bottom, right) {
  45. if (arguments.length !== 4) {
  46. throw new ArgumentError(
  47. Logger.logMessage(Logger.LEVEL_SEVERE, "Insets", "constructor", "invalidArgumentCount"));
  48. }
  49. // These are all documented with their property accessors below.
  50. this._top = top;
  51. this._left = left;
  52. this._bottom = bottom;
  53. this._right = right;
  54. };
  55. /**
  56. * Set top, left, bottom, and right to the specified values.
  57. * @param {Number} top The inset from the top.
  58. * @param {Number} left The inset from the left.
  59. * @param {Number} bottom The inset from the bottom.
  60. * @param {Number} right The inset from the right.
  61. */
  62. Insets.prototype.set = function (top, left, bottom, right) {
  63. this._top = top;
  64. this._left = left;
  65. this._bottom = bottom;
  66. this._right = right;
  67. };
  68. /**
  69. * Creates a new copy of this insets with identical property values.
  70. * @returns {Insets} A new insets instance with its property values the same as this one's.
  71. */
  72. Insets.prototype.clone = function () {
  73. return new Insets(this._top, this._left, this._bottom, this._right);
  74. };
  75. /**
  76. * Returns a string representation of this object.
  77. * @returns {String} A string representation of this object.
  78. */
  79. Insets.prototype.toString = function () {
  80. return this._top + " " + this._left + " " + this._bottom + " " + this._right;
  81. };
  82. Object.defineProperties(Insets.prototype, {
  83. /**
  84. * Indicates the the inset from the top.
  85. * @type {Number}
  86. * @memberof Insets.prototype
  87. */
  88. top: {
  89. get: function () {
  90. return this._top;
  91. },
  92. set: function (value) {
  93. this._top = value;
  94. }
  95. },
  96. /**
  97. * Indicates the the inset from the left.
  98. * @type {Number}
  99. * @memberof Insets.prototype
  100. */
  101. left: {
  102. get: function () {
  103. return this._left;
  104. },
  105. set: function (value) {
  106. this._left = value;
  107. }
  108. },
  109. /**
  110. * Indicates the the inset from the bottom.
  111. * @type {Number}
  112. * @memberof Insets.prototype
  113. */
  114. bottom: {
  115. get: function () {
  116. return this._bottom;
  117. },
  118. set: function (value) {
  119. this._bottom = value;
  120. }
  121. },
  122. /**
  123. * Indicates the the inset from the right.
  124. * @type {Number}
  125. * @memberof Insets.prototype
  126. */
  127. right: {
  128. get: function () {
  129. return this._right;
  130. },
  131. set: function (value) {
  132. this._right = value;
  133. }
  134. }
  135. });
  136. return Insets;
  137. }
  138. );