diff --git a/resources/icons/check_black.png b/resources/icons/check_black.png
new file mode 100644
index 0000000..ec1a52f
Binary files /dev/null and b/resources/icons/check_black.png differ
diff --git a/resources/icons/check_white.png b/resources/icons/check_white.png
new file mode 100644
index 0000000..5c29230
Binary files /dev/null and b/resources/icons/check_white.png differ
diff --git a/resources/ui.xml b/resources/ui.xml
index 9049239..3cc50e8 100644
--- a/resources/ui.xml
+++ b/resources/ui.xml
@@ -4,35 +4,60 @@
Visible="true"
Size="640, 480"
Title="FANTASTICEST UI THINGY">
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index 135cc89..35549f9 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,4 +1,6 @@
import guiTree.Components.Button;
+import guiTree.Components.CheckBox;
+import guiTree.Components.ToggleButton;
import guiTree.Window;
import guiTree.events.MouseAdapter;
import parser.XAMLParser;
@@ -11,29 +13,31 @@ public class Main {
Window window = XAMLParser.parse("ui.xml");
assert window != null;
- Button button1 = (Button)window.findByName("button1");
- button1.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent mouseEvent) {
- System.out.println("Button x: " + button1.getLocationX() + " y: " + button1.getLocationY());
- }
- });
-
- Button button2 = (Button)window.findByName("button2");
- button2.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent mouseEvent) {
- System.out.println("Button x: " + button2.getLocationX() + " y: " + button2.getLocationY());
- }
- });
-
- Button button4 = (Button)window.findByName("button4");
- button4.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent mouseEvent) {
- System.out.println("Button x: " + button4.getLocationX() + " y: " + button4.getLocationY());
- }
- });
+// Button button1 = (Button)window.findByName("button1");
+// button1.addMouseListener(new MouseAdapter() {
+// @Override
+// public void mouseClicked(MouseEvent mouseEvent) {
+// System.out.println("Button x: " + button1.getLocationX() + " y: " + button1.getLocationY());
+// }
+// });
+//
+// ToggleButton button2 = (ToggleButton)window.findByName("button2");
+// button2.addMouseListener(new MouseAdapter() {
+// @Override
+// public void mouseClicked(MouseEvent mouseEvent) {
+// System.out.println("Button x: " + button2.getLocationX() + " y: " + button2.getLocationY());
+// }
+// });
+//
+// Button button4 = (Button)window.findByName("button4");
+// button4.addMouseListener(new MouseAdapter() {
+// @Override
+// public void mouseClicked(MouseEvent mouseEvent) {
+// System.out.println("Button x: " + button4.getLocationX() + " y: " + button4.getLocationY());
+// }
+// });
+ CheckBox checkBox = (CheckBox)window.findByName("checkbox");
+ window.repaint();
}catch (Exception e){
e.printStackTrace();
}
diff --git a/src/converters/BooleanConverter.java b/src/converters/BooleanConverter.java
index dabd8fe..a770264 100644
--- a/src/converters/BooleanConverter.java
+++ b/src/converters/BooleanConverter.java
@@ -4,6 +4,7 @@ public class BooleanConverter implements ConverterInterface {
@Override
public Boolean convert(String content) {
+ content = content.replaceAll(" ", "");
return Boolean.valueOf(content);
}
}
diff --git a/src/converters/ColorConverter.java b/src/converters/ColorConverter.java
index 71a7f7c..5fef27d 100644
--- a/src/converters/ColorConverter.java
+++ b/src/converters/ColorConverter.java
@@ -5,6 +5,7 @@ import java.awt.*;
public class ColorConverter implements ConverterInterface {
@Override
public Color convert(String content) {
+ content = content.replaceAll(" ", "");
return Color.decode(content);
}
}
diff --git a/src/converters/DoubleConverter.java b/src/converters/DoubleConverter.java
index c91d8dc..dc4185f 100644
--- a/src/converters/DoubleConverter.java
+++ b/src/converters/DoubleConverter.java
@@ -4,6 +4,7 @@ public class DoubleConverter implements ConverterInterface{
@Override
public Double convert(String content) {
+ content = content.replaceAll(" ", "");
return Double.parseDouble(content);
}
}
diff --git a/src/converters/FloatConverter.java b/src/converters/FloatConverter.java
index 0a8b8ea..9bc026e 100644
--- a/src/converters/FloatConverter.java
+++ b/src/converters/FloatConverter.java
@@ -6,6 +6,7 @@ public class FloatConverter implements ConverterInterface {
@Override
public Float convert(String content) throws InvalidTypeException {
+ content = content.replaceAll(" ", "");
float number = Float.parseFloat(content);
if(number > 1 || number < 0) {
throw new InvalidTypeException();
diff --git a/src/converters/IntegerConverter.java b/src/converters/IntegerConverter.java
index fddefbb..e51b5cf 100644
--- a/src/converters/IntegerConverter.java
+++ b/src/converters/IntegerConverter.java
@@ -4,6 +4,7 @@ public class IntegerConverter implements ConverterInterface {
@Override
public Integer convert(String content) {
+ content = content.replaceAll(" ", "");
return Integer.parseInt(content);
}
}
diff --git a/src/guiTree/Components/Button.java b/src/guiTree/Components/Button.java
index c1869a3..d0f69c0 100644
--- a/src/guiTree/Components/Button.java
+++ b/src/guiTree/Components/Button.java
@@ -2,7 +2,6 @@ package guiTree.Components;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
-import guiTree.Helper.Timer;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -111,6 +110,9 @@ public class Button extends Visual {
}
//Draw Label
+ if(getFont() != null) {
+ g.setFont(getFont());
+ }
g.setColor(this.getFontColor());
int textWidth = 0;
int textHeight = 0;
diff --git a/src/guiTree/Components/CheckBox.java b/src/guiTree/Components/CheckBox.java
new file mode 100644
index 0000000..7e56b80
--- /dev/null
+++ b/src/guiTree/Components/CheckBox.java
@@ -0,0 +1,134 @@
+package guiTree.Components;
+
+import guiTree.Helper.Debugger;
+import guiTree.Helper.Tag;
+import guiTree.Visual;
+import guiTree.events.MouseAdapter;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+public class CheckBox extends Visual {
+ private BufferedImage icon;
+ private boolean hovered;
+ private boolean marked;
+ private String text;
+
+ public CheckBox() {
+ this(false, "");
+ }
+
+ public CheckBox(Boolean marked) {
+ this(marked, "");
+ }
+
+ public CheckBox(String text) {
+ this(false, text);
+ }
+
+ public CheckBox(Boolean value, String text) {
+ super();
+ this.marked = value;
+ this.text = text;
+ setAccentColor(new Color(0.6f, 0.6f, 0.6f, 0.5f));
+ this.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent mouseEvent) {
+ marked = !marked;
+ Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ @Override
+ public void mouseEntered(MouseEvent mouseEvent) {
+ hovered = true;
+ Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ @Override
+ public void mouseExited(MouseEvent mouseEvent) {
+ hovered = false;
+ Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ @Override
+ public void mouseMoved(MouseEvent mouseEvent) {
+ Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ });
+ }
+
+ public boolean isMarked() {
+ return marked;
+ }
+
+ public void setMarked(boolean marked) {
+ this.marked = marked;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public void setIcon(BufferedImage icon) {
+ this.icon = icon;
+ }
+
+ public void setIcon(String url) {
+ try{
+ icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void paint(BufferedImage imageBuffer) {
+ Graphics2D g = imageBuffer.createGraphics();
+
+ //Set Transparency
+ g.setComposite(AlphaComposite.Clear);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setComposite(AlphaComposite.Src);
+
+ if(hovered && !marked) {
+ g.setColor(getAccentColor());
+ g.fillRect(0, 0, getHeight() - 1, getHeight() - 1);
+ }
+
+ if(marked) {
+ g.setColor(getForegroundColor());
+ g.fillRect(1, 1, getHeight() - 2, getHeight() - 2);
+
+ if(icon != null) {
+ int iconWidth = icon.getWidth();
+ int iconHeight = icon.getHeight();
+
+ int iconX = (this.getHeight() - iconWidth) / 2;
+ int iconY = (this.getHeight() - iconHeight) / 2;
+ Graphics2D g2 = imageBuffer.createGraphics();
+ g2.drawImage(icon, iconX, iconY, null);
+ g2.dispose();
+ }
+ }
+
+ g.setColor(getFontColor());
+ if(getFont() != null) {
+ g.setFont(getFont());
+ }
+ int textHeight = g.getFontMetrics().getHeight();
+ g.drawString(text, getHeight() + 10, getHeight() / 2 + textHeight / 4);
+
+ g.setColor(getBorderColor());
+ g.drawRect(0, 0, getHeight() - 1, getHeight() - 1);
+ g.dispose();
+ }
+}
diff --git a/src/guiTree/Components/CheckBoxList.java b/src/guiTree/Components/CheckBoxList.java
new file mode 100644
index 0000000..12eba83
--- /dev/null
+++ b/src/guiTree/Components/CheckBoxList.java
@@ -0,0 +1,151 @@
+package guiTree.Components;
+
+import guiTree.Helper.Point2d;
+import guiTree.Visual;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class CheckBoxList extends Visual {
+ private List checkBoxList;
+ int spacing;
+ private BufferedImage icon;
+ private Point2d checkBoxSize;
+
+ public CheckBoxList() {
+ this(20);
+ }
+
+ public CheckBoxList(int spacing) {
+ checkBoxList = new ArrayList<>();
+ this.spacing = spacing;
+ }
+
+ @Override
+ public void addVisual(Visual v) {
+ if(!(v instanceof CheckBox)) {
+ System.out.println("Trying to insert into checkbox list something different from checkbox");
+ return;
+ }
+ CheckBox checkbox = (CheckBox)v;
+ if(checkBoxList.size() == 0) {
+ checkbox.setLocation(0, 0);
+
+ }
+ else {
+ checkbox.setLocation(0, checkBoxList.get(checkBoxList.size() - 1).getLocationY() + spacing);
+ }
+ if(icon != null) {
+ checkbox.setIcon(icon);
+ }
+ if(checkBoxSize != null) {
+ checkbox.setSize(checkBoxSize.x, checkBoxSize.y);
+ }
+ checkbox.setForegroundColor(getForegroundColor());
+ checkbox.setBackgroundColor(getBackgroundColor());
+ checkbox.setAccentColor(getAccentColor());
+ checkbox.setFontColor(getFontColor());
+ checkBoxList.add(checkbox);
+ super.addVisual(checkbox);
+ }
+
+ @Override
+ public void removeVisual(Visual v) {
+ if(v instanceof CheckBox) {
+ checkBoxList.remove(v);
+ super.removeVisual(v);
+ }
+ }
+
+ public void setIcon(BufferedImage icon) {
+ this.icon = icon;
+ for(CheckBox cb: checkBoxList) {
+ cb.setIcon(icon);
+ }
+ }
+
+ public void setIcon(String url) {
+ try {
+ icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ for(CheckBox cb: checkBoxList) {
+ cb.setIcon(icon);
+ }
+ }
+
+ public void setCheckBoxSize(Integer width, Integer height) {
+ for(CheckBox cb: checkBoxList) {
+ cb.setSize(width, height);
+ }
+ checkBoxSize = new Point2d(width, height);
+ }
+
+ @Override
+ public void setFont(Font font) {
+ super.setFont(font);
+ for(CheckBox cb: checkBoxList) {
+ cb.setFont(font);
+ }
+ }
+
+ @Override
+ public void setBackgroundColor(Color backgroundColor) {
+ super.setBackgroundColor(backgroundColor);
+ for(CheckBox cb: checkBoxList) {
+ cb.setBackgroundColor(backgroundColor);
+ }
+ }
+
+ @Override
+ public void setForegroundColor(Color foregroundColor) {
+ super.setForegroundColor(foregroundColor);
+ for(CheckBox cb: checkBoxList) {
+ cb.setForegroundColor(foregroundColor);
+ }
+ }
+
+ @Override
+ public void setFontColor(Color fontColor) {
+ super.setFontColor(fontColor);
+ for(CheckBox cb: checkBoxList) {
+ cb.setFontColor(fontColor);
+ }
+ }
+
+ @Override
+ public void setAccentColor(Color accentColor) {
+ super.setAccentColor(accentColor);
+ for(CheckBox cb: checkBoxList) {
+ cb.setAccentColor(accentColor);
+ }
+ }
+
+ public void setSpacing(Integer spacing) {
+ this.spacing = spacing;
+ if(checkBoxList == null) {
+ return;
+ }
+ int offsetY = 0;
+ for(CheckBox cb: checkBoxList) {
+ cb.setLocationY(offsetY);
+ offsetY += spacing;
+ }
+ }
+
+ public List getActiveBoxes() {
+ List markedBoxes = new ArrayList<>();
+ for(CheckBox cb: checkBoxList) {
+ if(cb.isMarked()) {
+ markedBoxes.add(cb);
+ }
+ }
+ return markedBoxes;
+ }
+}
diff --git a/src/guiTree/Components/TitleBar.java b/src/guiTree/Components/TitleBar.java
index c657173..2bddeeb 100644
--- a/src/guiTree/Components/TitleBar.java
+++ b/src/guiTree/Components/TitleBar.java
@@ -124,6 +124,7 @@ public class TitleBar extends Visual {
public void setTitle(String title) {
this.title = title;
+ update();
}
@Override
@@ -142,6 +143,9 @@ public class TitleBar extends Visual {
iconGraphics.drawImage(icon, 5, (getHeight() - icon.getHeight())/2, null);
iconGraphics.dispose();
+ if(getFont() != null) {
+ g.setFont(getFont());
+ }
int stringOffset = icon.getWidth() + 10;
int textHeight = 0;
if(!title.equals("")) {
diff --git a/src/guiTree/Components/ToggleButton.java b/src/guiTree/Components/ToggleButton.java
new file mode 100644
index 0000000..2097a86
--- /dev/null
+++ b/src/guiTree/Components/ToggleButton.java
@@ -0,0 +1,159 @@
+package guiTree.Components;
+
+import guiTree.Helper.Debugger;
+import guiTree.Helper.Tag;
+import guiTree.Visual;
+import guiTree.events.MouseAdapter;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+public class ToggleButton extends Visual {
+ private String label;
+ private Boolean pressed;
+ private Boolean hovered;
+ private BufferedImage icon;
+
+ public ToggleButton() {
+ this("", null);
+ }
+
+ public ToggleButton(String label) {
+ this(label, null);
+ }
+
+ public ToggleButton(BufferedImage icon) {
+ this(null, icon);
+ }
+
+ public ToggleButton(String label, BufferedImage icon) {
+ super();
+ this.label = label;
+ this.icon = icon;
+ pressed = false;
+ hovered = false;
+ this.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent mouseEvent) {
+ pressed = !pressed;
+ Debugger.log("Pressed: " + getName(), Tag.LISTENER);
+ Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ @Override
+ public void mouseEntered(MouseEvent mouseEvent) {
+ hovered = true;
+ Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ @Override
+ public void mouseExited(MouseEvent mouseEvent) {
+ hovered = false;
+ Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ @Override
+ public void mouseMoved(MouseEvent mouseEvent) {
+ Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
+ repaint();
+ }
+ });
+ }
+
+ @Override
+ public void paint(BufferedImage imageBuffer)
+ {
+ //Get Graphics
+ Graphics2D g = imageBuffer.createGraphics();
+
+ //Set Transparency
+ g.setComposite(AlphaComposite.Clear);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setComposite(AlphaComposite.Src);
+
+ //Choose background
+ if(hovered) {
+ g.setColor(this.getAccentColor());
+ }
+ else {
+ g.setColor(this.getBackgroundColor());
+ }
+ if(pressed) {
+ g.setColor(this.getForegroundColor());
+ }
+
+ //Draw Button
+ if(getHasBorder()) {
+ g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2);
+ g.setColor(getBorderColor());
+ g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
+ }
+ else {
+ g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
+ }
+
+ //Draw Label
+ if(getFont() != null) {
+ g.setFont(getFont());
+ }
+ g.setColor(this.getFontColor());
+ int textWidth = 0;
+ int textHeight = 0;
+ if(!label.equals("")) {
+ textWidth = g.getFontMetrics().stringWidth(label);
+ textHeight = g.getFontMetrics().getHeight();
+ }
+
+ g.drawString(this.label, (this.getWidth() - textWidth)/2, (this.getHeight() + textHeight)/2);
+
+ //Draw Icon
+ if(icon != null) {
+ int iconWidth = icon.getWidth();
+ int iconHeight = icon.getHeight();
+
+ int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
+ int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
+ Graphics2D g2 = imageBuffer.createGraphics();
+ g2.drawImage(icon, iconX, iconY, null);
+ g2.dispose();
+ }
+
+ g.dispose();
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return this.label;
+ }
+
+ public void setIcon(BufferedImage icon) {
+ this.icon = icon;
+ }
+
+ public void setIcon(String url) {
+ try{
+ icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public BufferedImage getIcon() {
+ return icon;
+ }
+
+ public void setPressed(Boolean pressed) {
+ this.pressed = pressed;
+ }
+
+ public Boolean getPressed() {
+ return pressed;
+ }
+}
diff --git a/src/guiTree/Helper/Tag.java b/src/guiTree/Helper/Tag.java
index 4f6e826..684107a 100644
--- a/src/guiTree/Helper/Tag.java
+++ b/src/guiTree/Helper/Tag.java
@@ -1,7 +1,7 @@
package guiTree.Helper;
public enum Tag {
- LISTENER(false),
+ LISTENER(true),
PAINTING(false);
public boolean value;
diff --git a/src/guiTree/Visual.java b/src/guiTree/Visual.java
index 70da9ac..0552884 100644
--- a/src/guiTree/Visual.java
+++ b/src/guiTree/Visual.java
@@ -48,6 +48,8 @@ public class Visual {
private Integer absoluteY;
private Float relativeX;
private Float relativeY;
+ private Boolean hasBorder;
+ private Font font;
private Color backgroundColor;
private Color foregroundColor;
private Color accentColor;
@@ -57,7 +59,6 @@ public class Visual {
public Boolean dirty;
private static Visual entered;
private Boolean focused;
- private Boolean hasBorder;
private Boolean pressed;
@@ -109,7 +110,7 @@ public class Visual {
this.name = name;
}
- private void setSize() {
+ public void setSize() {
if(parent != null) {
if(relativeWidth > 0.0) {
width = Math.round(relativeWidth * parent.width);
@@ -180,6 +181,10 @@ public class Visual {
this.locationY = y;
}
+ public void setFont(Font font) {
+ this.font = font;
+ }
+
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
propagateDirt();
@@ -230,6 +235,10 @@ public class Visual {
return this.locationY;
}
+ public Font getFont() {
+ return font;
+ }
+
public Color getBackgroundColor() {
return backgroundColor;
}
@@ -339,8 +348,11 @@ public class Visual {
window.revalidate();
}
- public void paint(BufferedImage imageBuffer) {
+ public void update() {
+ propagateDirt();
+ }
+ public void paint(BufferedImage imageBuffer) {
}
/*--------------------------------------------------------------------
@@ -508,8 +520,12 @@ public class Visual {
if(imageBuffer == null) {
return;
}
- Graphics g = this.imageBuffer.getGraphics();
- g.setColor(backgroundColor);
+ Graphics2D g = this.imageBuffer.createGraphics();
+
+ g.setComposite(AlphaComposite.Clear);
+ g.fillRect(0, 0, getWidth(), getHeight());
+ g.setComposite(AlphaComposite.Src);
+
g.fillRect(0, 0, width, height);
g.dispose();
}
diff --git a/src/parser/XAMLParser.java b/src/parser/XAMLParser.java
index 596ecd9..e232db4 100644
--- a/src/parser/XAMLParser.java
+++ b/src/parser/XAMLParser.java
@@ -76,7 +76,7 @@ public class XAMLParser {
List