Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.inception.gui.drawitems;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.geom.RoundRectangle2D;
- import de.inception.gui.json.Settings;
- public class CheckBoxItem {
- private int x, y, size;
- private boolean checked = false;
- private String settingname;
- public CheckBoxItem(int x, int y, int size, String settingname, boolean defaultvalue) {
- this.x = x;
- this.y = y;
- this.size = size;
- this.settingname = settingname;
- this.checked = (boolean) Settings.get(settingname, defaultvalue);
- }
- public void draw(Graphics2D g) {
- // # Outline
- RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, size, size, 5, 5);
- g.setColor(new Color(0x404040));
- g.fill(rect);
- // # Inner Box
- g.setColor(new Color(0xF4F8F9));
- g.fillRect(x + 4, y + 4, size - 8, size - 8);
- // # Check
- if(isChecked()) {
- RoundRectangle2D check = new RoundRectangle2D.Float(x + 6, y + 6, size - 12, size - 12, 3, 3);
- g.setColor(new Color(0x404040));
- g.fill(check);
- }
- }
- public boolean isOnBox(int x, int y) {
- int leftEdge = getX();
- int rightEdge = getX() + getSize();
- int topEdge = getY();
- int bottomEdge = getY() + getSize();
- return (x >= leftEdge && x <= rightEdge && y >= topEdge && y <= bottomEdge);
- }
- public void setLocation(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- public int getSize() {
- return size;
- }
- public void setChecked(boolean checked) {
- this.checked = checked;
- Settings.put(settingname, checked);
- }
- public boolean isChecked() {
- return checked;
- }
- public void toggle() {
- checked = !checked;
- Settings.put(settingname, checked);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement