Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package de.inception.gui.drawitems;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.geom.RoundRectangle2D;
  6.  
  7. import de.inception.gui.json.Settings;
  8.  
  9. public class CheckBoxItem {
  10.  
  11. private int x, y, size;
  12. private boolean checked = false;
  13. private String settingname;
  14.  
  15. public CheckBoxItem(int x, int y, int size, String settingname, boolean defaultvalue) {
  16. this.x = x;
  17. this.y = y;
  18. this.size = size;
  19. this.settingname = settingname;
  20. this.checked = (boolean) Settings.get(settingname, defaultvalue);
  21. }
  22.  
  23. public void draw(Graphics2D g) {
  24. // # Outline
  25. RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, size, size, 5, 5);
  26. g.setColor(new Color(0x404040));
  27. g.fill(rect);
  28.  
  29. // # Inner Box
  30. g.setColor(new Color(0xF4F8F9));
  31. g.fillRect(x + 4, y + 4, size - 8, size - 8);
  32.  
  33. // # Check
  34. if(isChecked()) {
  35. RoundRectangle2D check = new RoundRectangle2D.Float(x + 6, y + 6, size - 12, size - 12, 3, 3);
  36. g.setColor(new Color(0x404040));
  37. g.fill(check);
  38. }
  39. }
  40.  
  41. public boolean isOnBox(int x, int y) {
  42. int leftEdge = getX();
  43. int rightEdge = getX() + getSize();
  44. int topEdge = getY();
  45. int bottomEdge = getY() + getSize();
  46.  
  47. return (x >= leftEdge && x <= rightEdge && y >= topEdge && y <= bottomEdge);
  48. }
  49.  
  50. public void setLocation(int x, int y) {
  51. this.x = x;
  52. this.y = y;
  53. }
  54.  
  55. public int getX() {
  56. return x;
  57. }
  58.  
  59. public int getY() {
  60. return y;
  61. }
  62.  
  63. public int getSize() {
  64. return size;
  65. }
  66.  
  67. public void setChecked(boolean checked) {
  68. this.checked = checked;
  69. Settings.put(settingname, checked);
  70. }
  71.  
  72. public boolean isChecked() {
  73. return checked;
  74. }
  75.  
  76. public void toggle() {
  77. checked = !checked;
  78. Settings.put(settingname, checked);
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement