From eb4ce47a5c20e5fcfa0dfe2fefbc46ee4ba0c55b Mon Sep 17 00:00:00 2001
From: Macocian Adrian Radu <34056556+macocianradu@users.noreply.github.com>
Date: Tue, 31 Mar 2020 20:36:08 +0300
Subject: [PATCH] removed recursive call in paint added scroll panes without
relative position
---
resources/ui.xml | 66 +-----
src/Main.java | 45 +----
src/converters/FloatConverter.java | 2 +-
src/guiTree/Animations/ColorAnimation.java | 4 +-
src/guiTree/Components/Button.java | 26 +--
src/guiTree/Components/CheckBox.java | 27 +--
src/guiTree/Components/ScrollPanel.java | 188 ++++++++++++++++--
src/guiTree/Components/Slider.java | 38 +++-
src/guiTree/Components/ToggleButton.java | 33 ++-
src/guiTree/CustomFrame.java | 1 -
src/guiTree/Helper/Debugger.java | 4 +-
src/guiTree/Helper/Point2.java | 5 +
src/guiTree/Helper/Point3.java | 5 +
src/guiTree/Helper/Point4.java | 5 +
.../{events => }/MouseWheelGetter.java | 6 +-
src/guiTree/Visual.java | 35 +++-
src/parser/XAMLParser.java | 20 +-
17 files changed, 306 insertions(+), 204 deletions(-)
rename src/guiTree/{events => }/MouseWheelGetter.java (83%)
diff --git a/resources/ui.xml b/resources/ui.xml
index 8af6e27..1850d09 100644
--- a/resources/ui.xml
+++ b/resources/ui.xml
@@ -4,63 +4,11 @@
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 8e33176..0c34ada 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,53 +1,14 @@
-import guiTree.Animations.ColorAnimation;
-import guiTree.Animations.LocationAnimation;
-import guiTree.Components.Slider;
-import guiTree.Helper.Point2;
-import guiTree.Visual;
+import guiTree.Components.ScrollPanel;
import guiTree.Window;
-import guiTree.events.MouseAdapter;
import parser.XAMLParser;
-import java.awt.*;
-import java.awt.event.MouseEvent;
-
-
public class Main {
public static void main(String[] args) {
try{
Window window = XAMLParser.parse("ui.xml");
assert window != null;
- Slider hslider = (Slider)window.findByName("hslider");
- Slider slider = (Slider)window.findByName("slider");
- window.repaint();
- ColorAnimation sliderColor = new ColorAnimation(hslider, slider.getBackgroundColor(), Color.RED, 1000);
- window.addMouseListener(new MouseAdapter() {
- private boolean out = false;
- private LocationAnimation outAnimation;
- private LocationAnimation inAnimation;
- @Override
- public void mouseMoved(MouseEvent mouseEvent) {
- if(mouseEvent.getX() < 20 && mouseEvent.getY() > 0 && mouseEvent.getY() < 100) {
- if(!out) {
- outAnimation = new LocationAnimation(slider, slider.getLocation(), new Point2<>(0, slider.getLocationY()), 500);
- window.removeAnimation(inAnimation);
- window.addAnimation(outAnimation);
- out = true;
- }
- }
- else {
- if(out) {
- inAnimation = new LocationAnimation(slider, slider.getLocation(), new Point2<>(- 20, slider.getLocationY()), 500);
- window.removeAnimation(outAnimation);
- window.addAnimation(inAnimation);
- out = false;
- }
- }
- }
- });
- Thread.sleep(5000);
- System.out.println("Started moving");
- hslider.addAnimation(new LocationAnimation(hslider, hslider.getLocation(), new Point2<>(hslider.getLocationX(), hslider.getLocationY() + 100), 1000));
- hslider.addAnimation(sliderColor);
+ ScrollPanel scrollPanel = (ScrollPanel)window.findByName("ScrollPane");
+ System.out.println();
}catch (Exception e){
e.printStackTrace();
}
diff --git a/src/converters/FloatConverter.java b/src/converters/FloatConverter.java
index 9bc026e..5a0d825 100644
--- a/src/converters/FloatConverter.java
+++ b/src/converters/FloatConverter.java
@@ -8,7 +8,7 @@ public class FloatConverter implements ConverterInterface {
public Float convert(String content) throws InvalidTypeException {
content = content.replaceAll(" ", "");
float number = Float.parseFloat(content);
- if(number > 1 || number < 0) {
+ if(number > 1 || number < 0 || !content.contains(".")) {
throw new InvalidTypeException();
}
return Float.parseFloat(content);
diff --git a/src/guiTree/Animations/ColorAnimation.java b/src/guiTree/Animations/ColorAnimation.java
index 9b2a75e..9ee740b 100644
--- a/src/guiTree/Animations/ColorAnimation.java
+++ b/src/guiTree/Animations/ColorAnimation.java
@@ -36,7 +36,7 @@ public class ColorAnimation implements AnimationInterface {
from.b > to.b - 1 && from.b < to.b + 1 &&
from.c > to.c - 1 && from.c < to.c + 1 &&
from.d > to.d - 1 && from.d < to.d + 1) {
- element.setBackgroundColor(new Color(to.a, to.b, to.c, to.d));
+ element.setPaintColor(new Color(to.a, to.b, to.c, to.d));
Debugger.log("Animation for " + element.getName() + " finished", Debugger.Tag.ANIMATIONS);
return true;
}
@@ -44,7 +44,7 @@ public class ColorAnimation implements AnimationInterface {
from.b += offset.b;
from.c += offset.c;
from.d += offset.d;
- element.setBackgroundColor(new Color(Math.round(from.a), Math.round(from.b), Math.round(from.c), Math.round(from.d)));
+ element.setPaintColor(new Color(Math.round(from.a), Math.round(from.b), Math.round(from.c), Math.round(from.d)));
element.update();
return false;
}
diff --git a/src/guiTree/Components/Button.java b/src/guiTree/Components/Button.java
index a1daf48..adf679b 100644
--- a/src/guiTree/Components/Button.java
+++ b/src/guiTree/Components/Button.java
@@ -1,5 +1,6 @@
package guiTree.Components;
+import guiTree.Animations.ColorAnimation;
import guiTree.Helper.Debugger;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -13,8 +14,6 @@ import java.io.IOException;
public class Button extends Visual {
private String label;
- private Boolean pressed;
- private Boolean hovered;
private BufferedImage icon;
private int round = -1;
@@ -34,36 +33,33 @@ public class Button extends Visual {
super();
this.label = label;
this.icon = icon;
- pressed = false;
- hovered = false;
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
- pressed = false;
update();
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
- pressed = true;
+ addAnimation(new ColorAnimation(Button.this, getAccentColor(), getForegroundColor(), 100));
update();
Debugger.log("Pressed: " + getName(), Debugger.Tag.LISTENER);
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
- pressed = false;
+ addAnimation(new ColorAnimation(Button.this, getForegroundColor(), getAccentColor(), 100));
update();
Debugger.log("Calling repaint from released: " + getName(), Debugger.Tag.PAINTING);
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
- hovered = true;
+ addAnimation(new ColorAnimation(Button.this, getBackgroundColor(), getAccentColor(), 100));
update();
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
- hovered = false;
+ addAnimation(new ColorAnimation(Button.this, getAccentColor(), getBackgroundColor(), 100));
update();
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
}
@@ -83,17 +79,7 @@ public class Button extends Visual {
//Get Graphics
Graphics2D g = imageBuffer.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
- //Choose background
- if(hovered) {
- g.setColor(this.getAccentColor());
- }
- else {
- g.setColor(this.getBackgroundColor());
- }
- if(pressed) {
- g.setColor(this.getForegroundColor());
- }
+ g.setColor(getPaintColor());
//Draw Button
if(getHasBorder()) {
diff --git a/src/guiTree/Components/CheckBox.java b/src/guiTree/Components/CheckBox.java
index 4e7965a..772cac8 100644
--- a/src/guiTree/Components/CheckBox.java
+++ b/src/guiTree/Components/CheckBox.java
@@ -1,5 +1,6 @@
package guiTree.Components;
+import guiTree.Animations.ColorAnimation;
import guiTree.Helper.Debugger;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -37,19 +38,29 @@ public class CheckBox extends Visual {
this.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
+ if(!marked) {
+ addAnimation(new ColorAnimation(CheckBox.this, getAccentColor(), getForegroundColor(), 100));
+ }
+ else {
+ addAnimation(new ColorAnimation(CheckBox.this, getForegroundColor(), getAccentColor(), 100));
+ }
marked = !marked;
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
- hovered = true;
+ if(!marked) {
+ addAnimation(new ColorAnimation(CheckBox.this, getBackgroundColor(), getAccentColor(), 100));
+ }
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
- hovered = false;
+ if(!marked) {
+ addAnimation(new ColorAnimation(CheckBox.this, getAccentColor(), getBackgroundColor(), 100));
+ }
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
update();
}
@@ -92,19 +103,11 @@ public class CheckBox extends Visual {
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);
+ g.setColor(getPaintColor());
- if(hovered && !marked) {
- g.setColor(getAccentColor());
- g.fillRect(0, 0, getHeight() - 1, getHeight() - 1);
- }
+ g.fillRect(1, 1, getHeight() - 1, getHeight() - 1);
if(marked) {
- g.setColor(getForegroundColor());
- g.fillRect(1, 1, getHeight() - 2, getHeight() - 2);
if(icon != null) {
int iconWidth = icon.getWidth();
diff --git a/src/guiTree/Components/ScrollPanel.java b/src/guiTree/Components/ScrollPanel.java
index 7516a9f..2623e5a 100644
--- a/src/guiTree/Components/ScrollPanel.java
+++ b/src/guiTree/Components/ScrollPanel.java
@@ -1,13 +1,20 @@
package guiTree.Components;
-import guiTree.Helper.Debugger;
+import guiTree.Animations.LocationAnimation;
+import guiTree.Helper.Point2;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
+import java.awt.event.MouseWheelEvent;
+import java.util.ArrayList;
+import java.util.List;
+
import java.awt.*;
+import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class ScrollPanel extends Visual {
+ private List children;
private float positionX;
private float positionY;
@@ -19,48 +26,187 @@ public class ScrollPanel extends Visual {
public ScrollPanel() {
super();
setName("ScrollPanel");
- horizontalScrollBar = new Slider(Slider.Direction.Horizontal);
- verticalScrollBar = new Slider(Slider.Direction.Vertical);
- verticalScrollBar.setHasBorder(true);
- horizontalScrollBar.setHasBorder(true);
- addVisual(verticalScrollBar);
- addVisual(horizontalScrollBar);
- verticalScrollBar.setName("vertical scroll bar");
- horizontalScrollBar.setName("horizontal scroll bar");
+ children = new ArrayList<>();
+ addMouseListener(new BarListener());
+ addMouseWheelListener(new MouseWheelListener());
}
@Override
public void setSize() {
super.setSize();
- if(verticalScrollBar != null && horizontalScrollBar != null) {
- verticalScrollBar.setSize(20, getHeight() - 20);
- horizontalScrollBar.setSize(getWidth() - 20, 20);
- return;
+ if (getFarthestX() > getWidth()) {
+ if (horizontalScrollBar == null) {
+ horizontalScrollBar = new Slider(Slider.Direction.Horizontal);
+ horizontalScrollBar.setName(getName() + " horizontal scroll bar");
+ super.addVisual(horizontalScrollBar);
+ horizontalScrollBar.setWidth(1.0f);
+ horizontalScrollBar.setHeight(20);
+ }
+ horizontalScrollBar.setSliderSize((float)getWidth() / getFarthestX());
+ horizontalScrollBar.setLocation(0, getHeight());
}
- if(horizontalScrollBar != null) {
- horizontalScrollBar.setSize(getWidth(), 20);
+ if (getFarthestY() > getHeight()) {
+ if (verticalScrollBar == null) {
+ verticalScrollBar = new Slider(Slider.Direction.Vertical);
+ verticalScrollBar.setName(getName() + " vertical scroll bar");
+ super.addVisual(verticalScrollBar);
+ verticalScrollBar.setHeight(1.0f);
+ verticalScrollBar.setWidth(20);
+ }
+ verticalScrollBar.setSliderSize((float)getHeight() / getFarthestY());
+ verticalScrollBar.setLocation(getWidth(), 0);
+ }
+ }
+
+ @Override
+ public void addVisual(Visual v) {
+ if(v.getWidth() + v.getLocationX() > getFarthestX()) {
+ if (v.getWidth() + v.getLocationX() > getWidth()) {
+ if (horizontalScrollBar == null) {
+ horizontalScrollBar = new Slider(Slider.Direction.Horizontal);
+ horizontalScrollBar.setName(getName() + " horizontal scroll bar");
+ horizontalScrollBar.setWidth(1.0f);
+ horizontalScrollBar.setHeight(20);
+ super.addVisual(horizontalScrollBar);
+ }
+ horizontalScrollBar.setSliderSize((float)getWidth() / v.getWidth() + v.getLocationX());
+ }
+ }
+ if(v.getHeight() + v.getLocationY() > getFarthestY()) {
+ if (v.getHeight() + v.getLocationY() > getHeight()) {
+ if (verticalScrollBar == null) {
+ verticalScrollBar = new Slider(Slider.Direction.Vertical);
+ verticalScrollBar.setName(getName() + " vertical scroll bar");
+ verticalScrollBar.setHeight(1.0f);
+ verticalScrollBar.setWidth(20);
+ super.addVisual(verticalScrollBar);
+ }
+ verticalScrollBar.setSliderSize((float)getHeight() / v.getHeight() + v.getLocationY());
+ }
}
- if(verticalScrollBar != null) {
- verticalScrollBar.setSize(20, getHeight());
+ super.addVisual(v);
+ children.add(new VisualLocation(v));
+ }
+
+ private int getFarthestX() {
+ int max = 0;
+ for(VisualLocation visualLocation: children) {
+ if(max < visualLocation.v.getWidth() + visualLocation.originalLocation.x) {
+ max = visualLocation.v.getWidth() + visualLocation.originalLocation.x;
+ }
+ }
+ return max;
+ }
+
+ private int getFarthestY() {
+ int max = 0;
+ for(VisualLocation visualLocation: children) {
+ if(max < visualLocation.v.getHeight() + visualLocation.originalLocation.y) {
+ max = visualLocation.v.getHeight() + visualLocation.originalLocation.y;
+ }
+ }
+ return max;
+ }
+
+ private void setLocations() {
+ for(VisualLocation visualLocation:children) {
+ visualLocation.v.setLocation(visualLocation.originalLocation.x - Math.round(horizontalScrollBar.getSliderLocation() * (getFarthestX() - getWidth() + 20)),
+ visualLocation.originalLocation.y - Math.round(verticalScrollBar.getSliderLocation() * (getFarthestY() - getHeight() + 20)));
+ System.out.println("Moved: " + visualLocation.v + " from x: " + visualLocation.originalLocation + " to " + visualLocation.v.getLocation());
+ }
+ }
+
+ @Override
+ public void handleNotification(int notify) {
+ if(notify == Slider.SLIDER_MOVED) {
+ setLocations();
}
}
@Override
public void paint(BufferedImage imageBuffer) {
Graphics2D g = imageBuffer.createGraphics();
+ g.setColor(getPaintColor());
if(getHasBorder()) {
- g.setColor(getBackgroundColor());
- g.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
+ g.fillRect(1, 1, getWidth() - 1, getHeight() - 1);
g.setColor(getBorderColor());
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
else {
- g.setColor(getBackgroundColor());
- g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
+ g.fillRect(0, 0, getWidth(), getHeight());
}
g.dispose();
}
+
+ private class BarListener extends MouseAdapter {
+ private boolean outHorizontal = false;
+ private boolean outVertical = false;
+ private LocationAnimation outAnimationHorizontal;
+ private LocationAnimation outAnimationVertical;
+ private LocationAnimation inAnimationHorizontal;
+ private LocationAnimation inAnimationVertical;
+
+ @Override
+ public void mouseMoved(MouseEvent mouseEvent) {
+ if(verticalScrollBar != null) {
+ if (mouseEvent.getX() > getWidth() - verticalScrollBar.getWidth() && mouseEvent.getY() > verticalScrollBar.getLocationY() && mouseEvent.getY() < verticalScrollBar.getHeight()) {
+ if (!outVertical) {
+ outAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth() - verticalScrollBar.getWidth(), verticalScrollBar.getLocationY()), 300);
+ removeAnimation(inAnimationVertical);
+ addAnimation(outAnimationVertical);
+ outVertical = true;
+ }
+ } else {
+ if (outVertical) {
+ inAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth(), verticalScrollBar.getLocationY()), 300);
+ removeAnimation(outAnimationVertical);
+ addAnimation(inAnimationVertical);
+ outVertical = false;
+ }
+ }
+ }
+
+ if(horizontalScrollBar != null) {
+ if (mouseEvent.getY() > getHeight() - horizontalScrollBar.getHeight() && mouseEvent.getX() > horizontalScrollBar.getLocationX() && mouseEvent.getX() < horizontalScrollBar.getWidth()) {
+ if (!outHorizontal) {
+ outAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight() - horizontalScrollBar.getHeight()), 300);
+ removeAnimation(inAnimationHorizontal);
+ addAnimation(outAnimationHorizontal);
+ outHorizontal = true;
+ }
+ } else {
+ if (outHorizontal) {
+ inAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight()), 300);
+ removeAnimation(outAnimationHorizontal);
+ addAnimation(inAnimationHorizontal);
+ outHorizontal = false;
+ }
+ }
+ }
+ }
+ }
+
+ private class MouseWheelListener extends MouseAdapter {
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
+ if(mouseWheelEvent.isShiftDown()) {
+ horizontalScrollBar.moveSlider(mouseWheelEvent.getWheelRotation() * 10);
+ return;
+ }
+ verticalScrollBar.moveSlider(mouseWheelEvent.getWheelRotation() * 10);
+ }
+ }
+
+ private static class VisualLocation {
+ Visual v;
+ Point2 originalLocation;
+
+ public VisualLocation(Visual v) {
+ this.v = v;
+ originalLocation = v.getLocation();
+ }
+ }
}
diff --git a/src/guiTree/Components/Slider.java b/src/guiTree/Components/Slider.java
index 4698c23..ee5fa1e 100644
--- a/src/guiTree/Components/Slider.java
+++ b/src/guiTree/Components/Slider.java
@@ -8,6 +8,8 @@ import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class Slider extends Visual {
+ public static final int SLIDER_MOVED = 3;
+
public enum Direction {
Vertical,
Horizontal
@@ -84,19 +86,33 @@ public class Slider extends Visual {
}
public float getSliderLocation() {
+ int availableSpace;
if(direction == Direction.Vertical) {
- return (float)slider.getLocationY() / getHeight();
- }
- else {
- return (float)slider.getLocationX() / getWidth();
+ availableSpace = getHeight() - button1.getHeight() - slider.getHeight() - button2.getHeight();
+ int sliderY = slider.getLocationY() - button1.getHeight();
+ return (float)sliderY / availableSpace;
}
+ availableSpace = getWidth() - button1.getWidth() - slider.getWidth() - button2.getWidth();
+ int sliderX = slider.getLocationX() - button1.getWidth();
+ return (float)sliderX / availableSpace;
}
- public void setSliderSize(int width, int height) {
- slider.setSize(width, height);
+ public float getSliderSize() {
+ if(direction == Direction.Vertical) {
+ return (float)slider.getHeight() / getHeight();
+ }
+ return (float)slider.getWidth() / getWidth();
}
- private void moveSlider(int offset) {
+ public void setSliderSize(Float size) {
+ if(direction == Direction.Vertical) {
+ slider.setHeight(Math.round(size * getHeight()));
+ return;
+ }
+ slider.setWidth(Math.round(size * getWidth()));
+ }
+
+ public void moveSlider(Integer offset) {
if(direction == Direction.Vertical) {
if(slider.getLocationY() + slider.getHeight() + offset > getHeight() - button2.getHeight()) {
slider.setLocationY(getHeight() - slider.getHeight() - button2.getHeight());
@@ -119,6 +135,7 @@ public class Slider extends Visual {
slider.setLocationX(Math.round(slider.getLocationX() + offset));
}
}
+ notifyParent(SLIDER_MOVED);
}
public void setDirection(Direction direction) {
@@ -143,7 +160,7 @@ public class Slider extends Visual {
}
}
- private void moveSlider(float offset) {
+ public void moveSlider(Float offset) {
if(direction == Direction.Vertical) {
moveSlider(Math.round(offset * getHeight()));
return;
@@ -198,13 +215,13 @@ public class Slider extends Visual {
button1.setSize(Math.round(0.7f * getWidth()), Math.round(0.7f * getWidth()));
button2.setSize(button1.getWidth(), button1.getHeight());
button2.setLocation(0, getHeight() - button2.getHeight());
- slider.setSize(getWidth() / 2, 40);
+ slider.setWidth(getWidth() / 2);
}
else {
button1.setSize(Math.round(0.7f * getHeight()), Math.round(0.7f * getHeight()));
button2.setSize(button1.getWidth(), button1.getHeight());
button2.setLocation(getWidth() - button2.getWidth(), 0);
- slider.setSize(40, getHeight() / 2);
+ slider.setHeight(getHeight() / 2);
}
}
@@ -218,6 +235,7 @@ public class Slider extends Visual {
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
g.setColor(getBackgroundColor());
+
if(direction == Direction.Vertical) {
int x1 = Math.round(0.15f * getWidth());
int y1 = button1.getHeight();
diff --git a/src/guiTree/Components/ToggleButton.java b/src/guiTree/Components/ToggleButton.java
index e3da673..02c6a29 100644
--- a/src/guiTree/Components/ToggleButton.java
+++ b/src/guiTree/Components/ToggleButton.java
@@ -1,5 +1,6 @@
package guiTree.Components;
+import guiTree.Animations.ColorAnimation;
import guiTree.Helper.Debugger;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -38,20 +39,31 @@ public class ToggleButton extends Visual {
this.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
+ if(pressed) {
+ addAnimation(new ColorAnimation(ToggleButton.this, getForegroundColor(), getAccentColor(), 100));
+ }
+ else {
+ addAnimation(new ColorAnimation(ToggleButton.this, getAccentColor(), getForegroundColor(), 100));
+ }
pressed = !pressed;
+
Debugger.log("Pressed: " + getName(), Debugger.Tag.LISTENER);
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
- hovered = true;
+ if(!pressed) {
+ addAnimation(new ColorAnimation(ToggleButton.this, getBackgroundColor(), getAccentColor(), 100));
+ }
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
- hovered = false;
+ if(!pressed) {
+ addAnimation(new ColorAnimation(ToggleButton.this, getAccentColor(), getBackgroundColor(), 100));
+ }
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
update();
}
@@ -67,22 +79,7 @@ public class ToggleButton extends Visual {
{
//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());
- }
+ g.setColor(getPaintColor());
//Draw Button
if(getHasBorder()) {
diff --git a/src/guiTree/CustomFrame.java b/src/guiTree/CustomFrame.java
index d4c424e..5d4523b 100644
--- a/src/guiTree/CustomFrame.java
+++ b/src/guiTree/CustomFrame.java
@@ -3,7 +3,6 @@ package guiTree;
import guiTree.Helper.Debugger;
import guiTree.Helper.Timer;
import guiTree.events.KeyEventGetter;
-import guiTree.events.MouseWheelGetter;
import javax.swing.*;
import java.awt.*;
diff --git a/src/guiTree/Helper/Debugger.java b/src/guiTree/Helper/Debugger.java
index 08cb758..fd571d7 100644
--- a/src/guiTree/Helper/Debugger.java
+++ b/src/guiTree/Helper/Debugger.java
@@ -4,8 +4,8 @@ public class Debugger {
public enum Tag {
LISTENER(false),
PAINTING(false),
- FPS(false),
- ANIMATIONS(true),
+ FPS(true),
+ ANIMATIONS(false),
PARSING(false);
public boolean value;
diff --git a/src/guiTree/Helper/Point2.java b/src/guiTree/Helper/Point2.java
index 0f255c9..ea45229 100644
--- a/src/guiTree/Helper/Point2.java
+++ b/src/guiTree/Helper/Point2.java
@@ -12,4 +12,9 @@ public class Point2 {
public boolean equals(Point2 point2) {
return x == point2.y && y == point2.y;
}
+
+ @Override
+ public String toString() {
+ return "Point2 x:" + x + " y: " + y;
+ }
}
diff --git a/src/guiTree/Helper/Point3.java b/src/guiTree/Helper/Point3.java
index 84af162..b2ff467 100644
--- a/src/guiTree/Helper/Point3.java
+++ b/src/guiTree/Helper/Point3.java
@@ -14,4 +14,9 @@ public class Point3 {
public boolean equals(Point3 point3) {
return x == point3.x && y == point3.y && z == point3.z;
}
+
+ @Override
+ public String toString() {
+ return "Point2 x:" + x + " y: " + y + " z: " + z;
+ }
}
diff --git a/src/guiTree/Helper/Point4.java b/src/guiTree/Helper/Point4.java
index 3fa2706..b32fff9 100644
--- a/src/guiTree/Helper/Point4.java
+++ b/src/guiTree/Helper/Point4.java
@@ -16,4 +16,9 @@ public class Point4 {
public boolean equals(Point4 point4) {
return a == point4.a && b == point4.b && c == point4.c && d == point4.d;
}
+
+ @Override
+ public String toString() {
+ return "Point2 a:" + a + " b: " + b + " c: " + c + " d: " + d;
+ }
}
diff --git a/src/guiTree/events/MouseWheelGetter.java b/src/guiTree/MouseWheelGetter.java
similarity index 83%
rename from src/guiTree/events/MouseWheelGetter.java
rename to src/guiTree/MouseWheelGetter.java
index fb74dda..52a8976 100644
--- a/src/guiTree/events/MouseWheelGetter.java
+++ b/src/guiTree/MouseWheelGetter.java
@@ -1,6 +1,4 @@
-package guiTree.events;
-
-import guiTree.Window;
+package guiTree;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
@@ -14,6 +12,6 @@ public class MouseWheelGetter implements MouseWheelListener {
@Override
public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
-
+ callingWindow.mouseWheelMoved(mouseWheelEvent);
}
}
diff --git a/src/guiTree/Visual.java b/src/guiTree/Visual.java
index 45f295f..aee4459 100644
--- a/src/guiTree/Visual.java
+++ b/src/guiTree/Visual.java
@@ -57,6 +57,7 @@ public class Visual {
private Color accentColor;
private Color fontColor;
private Color borderColor;
+ private Color paintColor;
private Boolean active;
private Boolean dirty;
private static Visual entered;
@@ -135,6 +136,22 @@ public class Visual {
notifyParent(SIZE_CHANGED);
}
+ public void setHeight(Integer height) {
+ setSize(getWidth(), height);
+ }
+
+ public void setWidth(Integer width) {
+ setSize(width, getHeight());
+ }
+
+ public void setHeight(Float height) {
+ setSize(relativeWidth, height);
+ }
+
+ public void setWidth(Float width) {
+ setSize(width, relativeHeight);
+ }
+
public void setSize(Integer width, Integer height) {
this.width = width;
this.height = height;
@@ -188,6 +205,7 @@ public class Visual {
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
+ this.paintColor = backgroundColor;
propagateDirt();
}
@@ -198,14 +216,22 @@ public class Visual {
public void setFontColor(Color fontColor) {
this.fontColor = fontColor;
+ propagateDirt();
}
public void setAccentColor(Color accentColor) {
this.accentColor = accentColor;
+ propagateDirt();
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
+ propagateDirt();
+ }
+
+ public void setPaintColor(Color paintColor) {
+ this.paintColor = paintColor;
+ propagateDirt();
}
public void setHasBorder(Boolean hasBorder) {
@@ -265,6 +291,10 @@ public class Visual {
return borderColor;
}
+ public Color getPaintColor() {
+ return paintColor;
+ }
+
public Boolean getHasBorder() {
return hasBorder;
}
@@ -360,7 +390,6 @@ public class Visual {
if(!(this instanceof Window)){
long time = timer.stopTiming();
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
- parent.revalidate();
return;
}
Window window = (Window)this;
@@ -512,8 +541,8 @@ public class Visual {
}
void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
- if(focused) {
- for(MouseWheelListener mouseWheelListener: mouseWheelListeners) {
+ if(entered.focused) {
+ for(MouseWheelListener mouseWheelListener: entered.mouseWheelListeners) {
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
}
}
diff --git a/src/parser/XAMLParser.java b/src/parser/XAMLParser.java
index f01529c..3dc4d55 100644
--- a/src/parser/XAMLParser.java
+++ b/src/parser/XAMLParser.java
@@ -94,16 +94,18 @@ public class XAMLParser {
}
for(Method method: methods){
Class>[] types = method.getParameterTypes();
- for(int i = 0; i < types.length; i++){
- try{
- primitiveAttributes.add(valueConverter.objectCreatorFactory(types[i], values.get(i)));
- } catch (InvalidTypeException | NumberFormatException e){
- primitiveAttributes.clear();
- break;
+ if(types.length == values.size()) {
+ for (int i = 0; i < types.length; i++) {
+ try {
+ primitiveAttributes.add(valueConverter.objectCreatorFactory(types[i], values.get(i)));
+ } catch (InvalidTypeException | NumberFormatException e) {
+ primitiveAttributes.clear();
+ break;
+ }
+ }
+ if (primitiveAttributes.size() == types.length && types.length == values.size()) {
+ return primitiveAttributes;
}
- }
- if(primitiveAttributes.size() == types.length && types.length == values.size()){
- return primitiveAttributes;
}
}
System.err.println("Could not find method " + methodName + " with parameters " + values);