Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.thumbtack.school.windows.v1;
- import java.util.Objects;
- public class RoundButton {
- private Point center;
- private int radius;
- private boolean active;
- public RoundButton(Point center, int radius, boolean active) {
- setCenter(center.getX(), center.getY());
- setRadius(radius);
- setActive(active);
- }
- public RoundButton(int xCenter, int yCenter, int radius, boolean active) {
- setCenter(xCenter, yCenter);
- setRadius(radius);
- setActive(active);
- }
- public RoundButton(Point center, int radius) {
- setCenter(center.getX(), center.getY());
- setRadius(radius);
- setActive(true);
- }
- public RoundButton(int xCenter, int yCenter, int radius) {
- setCenter(xCenter, yCenter);
- setRadius(radius);
- setActive(true);
- }
- public Point getCenter() {
- return center;
- }
- public int getRadius() {
- return radius;
- }
- public boolean isActive() {
- return active;
- }
- public void moveTo(int x, int y) {
- setCenter(x, y);
- }
- public void moveTo(Point point) {
- setCenter(point.getX(), point.getY());
- }
- public void setCenter(int x, int y) {
- this.center = new Point(x, y);
- }
- public void setRadius(int radius) {
- this.radius = radius;
- }
- public void setActive(boolean active) {
- this.active = active;
- }
- public void moveRel(int dx, int dy) {
- setCenter(center.getX() + dx, center.getY() + dy);
- }
- public void resize(double ratio) {
- double ResizeRadius = this.radius * ratio;
- if (ResizeRadius < 1) {
- ResizeRadius = 1;
- }
- int ResizeRadius1 = (int) ResizeRadius;
- setRadius(ResizeRadius1);
- }
- public boolean isInside(int x, int y) {
- double Distance = Math.sqrt((x - this.getCenter().getX()) * (x - this.getCenter().getX()) +
- (y - this.getCenter().getY()) * (y - this.getCenter().getY()));
- return (Distance <= radius);
- }
- public boolean isInside(Point point) {
- return isInside(point.getX(), point.getY());
- }
- public boolean isFullyVisibleOnDesktop(Desktop desktop){
- return ( center.getY() >= 0 && center.getX() >= 0 &&
- center.getY() < desktop.getHeight() &&
- center.getX() < desktop.getWidth() &&
- center.getX() >= radius && center.getY() >= radius &&
- desktop.getWidth() - center.getX() > radius &&
- desktop.getHeight() - center.getY() > radius);
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- RoundButton that = (RoundButton) o;
- return radius == that.radius &&
- active == that.active &&
- Objects.equals(center, that.center);
- }
- @Override
- public int hashCode() {
- return Objects.hash(center, radius, active);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement