Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. package net.thumbtack.school.windows.v1;
  2.  
  3. import java.util.Objects;
  4.  
  5. public class RoundButton {
  6.  
  7. private Point center;
  8. private int radius;
  9. private boolean active;
  10.  
  11. public RoundButton(Point center, int radius, boolean active) {
  12. setCenter(center.getX(), center.getY());
  13. setRadius(radius);
  14. setActive(active);
  15. }
  16.  
  17. public RoundButton(int xCenter, int yCenter, int radius, boolean active) {
  18. setCenter(xCenter, yCenter);
  19. setRadius(radius);
  20. setActive(active);
  21. }
  22.  
  23. public RoundButton(Point center, int radius) {
  24. setCenter(center.getX(), center.getY());
  25. setRadius(radius);
  26. setActive(true);
  27. }
  28.  
  29. public RoundButton(int xCenter, int yCenter, int radius) {
  30. setCenter(xCenter, yCenter);
  31. setRadius(radius);
  32. setActive(true);
  33. }
  34.  
  35. public Point getCenter() {
  36. return center;
  37. }
  38.  
  39. public int getRadius() {
  40. return radius;
  41. }
  42.  
  43. public boolean isActive() {
  44. return active;
  45. }
  46.  
  47. public void moveTo(int x, int y) {
  48. setCenter(x, y);
  49. }
  50.  
  51. public void moveTo(Point point) {
  52. setCenter(point.getX(), point.getY());
  53. }
  54.  
  55. public void setCenter(int x, int y) {
  56. this.center = new Point(x, y);
  57. }
  58.  
  59. public void setRadius(int radius) {
  60. this.radius = radius;
  61. }
  62.  
  63. public void setActive(boolean active) {
  64. this.active = active;
  65. }
  66.  
  67. public void moveRel(int dx, int dy) {
  68. setCenter(center.getX() + dx, center.getY() + dy);
  69. }
  70.  
  71. public void resize(double ratio) {
  72. double ResizeRadius = this.radius * ratio;
  73. if (ResizeRadius < 1) {
  74. ResizeRadius = 1;
  75. }
  76. int ResizeRadius1 = (int) ResizeRadius;
  77. setRadius(ResizeRadius1);
  78. }
  79.  
  80. public boolean isInside(int x, int y) {
  81. double Distance = Math.sqrt((x - this.getCenter().getX()) * (x - this.getCenter().getX()) +
  82. (y - this.getCenter().getY()) * (y - this.getCenter().getY()));
  83. return (Distance <= radius);
  84. }
  85.  
  86. public boolean isInside(Point point) {
  87. return isInside(point.getX(), point.getY());
  88. }
  89.  
  90. public boolean isFullyVisibleOnDesktop(Desktop desktop){
  91. return ( center.getY() >= 0 && center.getX() >= 0 &&
  92. center.getY() < desktop.getHeight() &&
  93. center.getX() < desktop.getWidth() &&
  94. center.getX() >= radius && center.getY() >= radius &&
  95. desktop.getWidth() - center.getX() > radius &&
  96. desktop.getHeight() - center.getY() > radius);
  97. }
  98.  
  99. @Override
  100. public boolean equals(Object o) {
  101. if (this == o) return true;
  102. if (o == null || getClass() != o.getClass()) return false;
  103. RoundButton that = (RoundButton) o;
  104. return radius == that.radius &&
  105. active == that.active &&
  106. Objects.equals(center, that.center);
  107. }
  108.  
  109. @Override
  110. public int hashCode() {
  111. return Objects.hash(center, radius, active);
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement