diff --git a/resources/ui.xml b/resources/ui.xml
index c647ae1..9049239 100644
--- a/resources/ui.xml
+++ b/resources/ui.xml
@@ -1,13 +1,38 @@
-
-
-
+
+
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index 52d2f00..135cc89 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,59 +1,39 @@
import guiTree.Components.Button;
-import guiTree.Components.Panel;
import guiTree.Window;
import guiTree.events.MouseAdapter;
import parser.XAMLParser;
import java.awt.event.MouseEvent;
-
public class Main {
public static void main(String[] args) {
try{
Window window = XAMLParser.parse("ui.xml");
assert window != null;
- window.repaint();
- Button button = (Button)window.findByName("button3");
- button.addMouseListener(new MouseAdapter() {
+
+ Button button1 = (Button)window.findByName("button1");
+ button1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
- Panel panel = window.getMainPanel();
- if(panel.getOverlapping()) {
- panel.setOverlapping(false);
- }
- else {
- panel.setOverlapping(true);
- }
- window.repaint();
+ System.out.println("Button x: " + button1.getLocationX() + " y: " + button1.getLocationY());
}
});
- window.repaint();
- System.out.println(Float.parseFloat("3"));
- long now;
- long prev = 0;
-// while(true) {
-// now = System.currentTimeMillis();
-// if(now - prev >= 1000) {
-// int x = button.getLocationX();
-// int y = button.getLocationY();
-// if(x + button.getWidth() >= window.getWidth()) {
-// x = 0;
-// if(y + button.getHeight() >= window.getHeight()) {
-// y = 0;
-// }
-// else {
-// y += 30;
-// }
-// }
-// else {
-// x += 30;
-// }
-// button.setLocation(x, y);
-// prev = now;
-// window.revalidate();
-// }
-// }
+ 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());
+ }
+ });
}catch (Exception e){
e.printStackTrace();
}
diff --git a/src/guiTree/Components/Button.java b/src/guiTree/Components/Button.java
index 1f13b9a..c1869a3 100644
--- a/src/guiTree/Components/Button.java
+++ b/src/guiTree/Components/Button.java
@@ -1,5 +1,8 @@
package guiTree.Components;
+import guiTree.Helper.Debugger;
+import guiTree.Helper.Tag;
+import guiTree.Helper.Timer;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -35,32 +38,41 @@ public class Button extends Visual {
pressed = false;
hovered = false;
this.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent mouseEvent) {
+ pressed = false;
+ }
@Override
public void mousePressed(MouseEvent mouseEvent) {
pressed = true;
+ Debugger.log("Pressed: " + getName(), Tag.LISTENER);
+ Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
repaint();
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
pressed = false;
+ Debugger.log("Calling repaint from released: " + 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 mouseDragged(MouseEvent mouseEvent) {
- repaint();
}
@Override
public void mouseMoved(MouseEvent mouseEvent) {
+ Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
repaint();
}
});
@@ -78,18 +90,28 @@ public class Button extends Visual {
g.setComposite(AlphaComposite.Src);
//Choose background
- if(hovered || pressed) {
- g.setColor(this.getForegroundColor());
+ if(hovered) {
+ g.setColor(this.getAccentColor());
}
else {
g.setColor(this.getBackgroundColor());
}
+ if(pressed) {
+ g.setColor(this.getForegroundColor());
+ }
//Draw Button
- g.fillRect(0, 0, this.getWidth(), this.getHeight());
- g.setColor(this.getFontColor());
+ 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
+ g.setColor(this.getFontColor());
int textWidth = 0;
int textHeight = 0;
if(!label.equals("")) {
diff --git a/src/guiTree/Components/Panel.java b/src/guiTree/Components/Panel.java
index 701fa47..16ed607 100644
--- a/src/guiTree/Components/Panel.java
+++ b/src/guiTree/Components/Panel.java
@@ -72,8 +72,8 @@ public class Panel extends Visual {
@Override
public void addVisual(Visual v) {
- calculatePosition(v);
super.addVisual(v);
+ calculatePosition(v);
visuals.add(v);
}
diff --git a/src/guiTree/Components/TitleBar.java b/src/guiTree/Components/TitleBar.java
index 73d9afa..c657173 100644
--- a/src/guiTree/Components/TitleBar.java
+++ b/src/guiTree/Components/TitleBar.java
@@ -52,9 +52,13 @@ public class TitleBar extends Visual {
close.setBackgroundColor(Color.GRAY);
maximize.setBackgroundColor(Color.GRAY);
minimize.setBackgroundColor(Color.GRAY);
+ close.setAccentColor(Color.RED);
+ maximize.setAccentColor(Color.LIGHT_GRAY);
+ minimize.setAccentColor(Color.LIGHT_GRAY);
close.setForegroundColor(Color.RED);
- maximize.setForegroundColor(Color.LIGHT_GRAY);
- minimize.setForegroundColor(Color.LIGHT_GRAY);
+ maximize.setForegroundColor(Color.DARK_GRAY);
+ minimize.setForegroundColor(Color.DARK_GRAY);
+
this.setSize(0, 30);
this.setLocation(0, 0);
diff --git a/src/guiTree/CustomFrame.java b/src/guiTree/CustomFrame.java
index 510224e..60f7fd5 100644
--- a/src/guiTree/CustomFrame.java
+++ b/src/guiTree/CustomFrame.java
@@ -1,5 +1,7 @@
package guiTree;
+import guiTree.Helper.Debugger;
+import guiTree.Helper.Tag;
import guiTree.events.KeyEventGetter;
import guiTree.events.MouseWheelGetter;
@@ -37,8 +39,7 @@ public class CustomFrame extends JFrame {
}
@Override
- public void paint(Graphics g)
- {
+ public void paint(Graphics g) {
g.drawImage(imageBuffer, 0, 0, this.getWidth(), this.getHeight(), null);
}
diff --git a/src/guiTree/Helper/Debugger.java b/src/guiTree/Helper/Debugger.java
new file mode 100644
index 0000000..68d30eb
--- /dev/null
+++ b/src/guiTree/Helper/Debugger.java
@@ -0,0 +1,11 @@
+package guiTree.Helper;
+
+public class Debugger {
+ private static Timer timer = new Timer();
+
+ public static void log(String message, Tag tag) {
+ if(tag.value) {
+ System.out.println("[" + tag.toString() + "] " + message);
+ }
+ }
+}
diff --git a/src/guiTree/Helper/Tag.java b/src/guiTree/Helper/Tag.java
new file mode 100644
index 0000000..4f6e826
--- /dev/null
+++ b/src/guiTree/Helper/Tag.java
@@ -0,0 +1,12 @@
+package guiTree.Helper;
+
+public enum Tag {
+ LISTENER(false),
+ PAINTING(false);
+
+ public boolean value;
+
+ Tag(boolean value) {
+ this.value = value;
+ }
+}
diff --git a/src/guiTree/Helper/Timer.java b/src/guiTree/Helper/Timer.java
new file mode 100644
index 0000000..4cbd91f
--- /dev/null
+++ b/src/guiTree/Helper/Timer.java
@@ -0,0 +1,15 @@
+package guiTree.Helper;
+
+public class Timer {
+ private long now;
+ private long prev;
+
+ public void startTiming() {
+ prev = System.currentTimeMillis();
+ }
+
+ public long stopTiming() {
+ now = System.currentTimeMillis();
+ return now - prev;
+ }
+}
diff --git a/src/guiTree/MouseEventGetter.java b/src/guiTree/MouseEventGetter.java
index 8425c89..1a92617 100644
--- a/src/guiTree/MouseEventGetter.java
+++ b/src/guiTree/MouseEventGetter.java
@@ -19,7 +19,7 @@ public class MouseEventGetter implements MouseInputListener {
@Override
public void mouseMoved(MouseEvent mouseEvent) {
- callingWindow.mouseMoved(mouseEvent, 0, 0);
+ callingWindow.mouseMoved(mouseEvent);
}
@Override
@@ -39,7 +39,7 @@ public class MouseEventGetter implements MouseInputListener {
@Override
public void mouseEntered(MouseEvent mouseEvent) {
- callingWindow.mouseEntered(mouseEvent, 0, 0);
+ callingWindow.mouseEntered(mouseEvent);
}
@Override
diff --git a/src/guiTree/Visual.java b/src/guiTree/Visual.java
index 2812c01..70da9ac 100644
--- a/src/guiTree/Visual.java
+++ b/src/guiTree/Visual.java
@@ -1,5 +1,8 @@
package guiTree;
+import guiTree.Helper.Debugger;
+import guiTree.Helper.Tag;
+import guiTree.Helper.Timer;
import guiTree.events.KeyListener;
import guiTree.events.MouseListener;
import guiTree.events.MouseWheelListener;
@@ -15,6 +18,7 @@ public class Visual {
/*--------------------------------------------------------------------
Constant Values
---------------------------------------------------------------------*/
+
public static final int SIZE_CHANGED = 1;
public static final int LOCATION_CHANGED = 2;
@@ -40,15 +44,20 @@ public class Visual {
private Float relativeHeight;
private Integer locationX;
private Integer locationY;
+ private Integer absoluteX;
+ private Integer absoluteY;
private Float relativeX;
private Float relativeY;
private Color backgroundColor;
private Color foregroundColor;
+ private Color accentColor;
private Color fontColor;
+ private Color borderColor;
private Boolean active;
- private Boolean dirty;
+ public Boolean dirty;
private static Visual entered;
private Boolean focused;
+ private Boolean hasBorder;
private Boolean pressed;
@@ -70,8 +79,11 @@ public class Visual {
this.backgroundColor = Color.WHITE;
this.foregroundColor = Color.BLUE;
this.fontColor = Color.BLACK;
+ this.borderColor = Color.BLACK;
+ this.accentColor = Color.BLUE;
this.dirty = true;
+ this.hasBorder = false;
this.active = this instanceof Window;
this.focused = false;
this.pressed = false;
@@ -85,6 +97,8 @@ public class Visual {
this.locationX = 0;
this.locationY = 0;
+ this.absoluteX = 0;
+ this.absoluteY = 0;
}
/*--------------------------------------------------------------------
@@ -115,8 +129,8 @@ public class Visual {
v.setLocation();
}
}
- this.dirty = true;
- this.notifyParent(SIZE_CHANGED);
+ propagateDirt();
+ notifyParent(SIZE_CHANGED);
}
public void setSize(Integer width, Integer height) {
@@ -141,7 +155,8 @@ public class Visual {
}
}
- this.dirty = true;
+ calculateAbsoluteLocation();
+ propagateDirt();
notifyParent(LOCATION_CHANGED);
}
@@ -167,25 +182,28 @@ public class Visual {
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
- this.dirty = true;
+ propagateDirt();
}
public void setForegroundColor(Color foregroundColor) {
this.foregroundColor = foregroundColor;
- this.dirty = true;
+ propagateDirt();
}
public void setFontColor(Color fontColor) {
this.fontColor = fontColor;
}
- private void calculateInitialLocation() {
- if(this.locationX <= 0) {
- this.locationX = 0;
- }
- if(this.locationY <= 0){
- this.locationY = 0;
- }
+ public void setAccentColor(Color accentColor) {
+ this.accentColor = accentColor;
+ }
+
+ public void setBorderColor(Color borderColor) {
+ this.borderColor = borderColor;
+ }
+
+ public void setHasBorder(Boolean hasBorder) {
+ this.hasBorder = hasBorder;
}
/*--------------------------------------------------------------------
@@ -224,6 +242,18 @@ public class Visual {
return fontColor;
}
+ public Color getAccentColor() {
+ return accentColor;
+ }
+
+ public Color getBorderColor() {
+ return borderColor;
+ }
+
+ public Boolean getHasBorder() {
+ return hasBorder;
+ }
+
/*--------------------------------------------------------------------
Tree Methods
---------------------------------------------------------------------*/
@@ -247,7 +277,7 @@ public class Visual {
public void addVisual(Visual child) {
this.children.add(child);
child.setParent(this);
- child.calculateInitialLocation();
+ child.setLocation();
child.setSize();
if(this.active) {
@@ -260,7 +290,7 @@ public class Visual {
child.setParent(null);
child.imageBuffer = null;
child.deactivate();
- this.dirty = true;
+ propagateDirt();
}
private void setParent(Visual parent) {
@@ -273,24 +303,21 @@ public class Visual {
public void notifyParent(int notify) {
if(parent != null) {
- this.parent.handleNotification(notify);
+ parent.handleNotification(notify);
}
}
public void repaint() {
- if(!this.active){
- return;
- }
- if(this.dirty) {
+ if(dirty && active) {
this.revalidate();
- return;
- }
- for(Visual v: children) {
- v.repaint();
}
}
private void revalidate() {
+ Timer timer = new Timer();
+ Debugger.log("Revalidating " + name, Tag.PAINTING);
+ timer.startTiming();
+
clearImageBuffer();
this.paint(imageBuffer);
for (Visual v : children) {
@@ -300,10 +327,15 @@ public class Visual {
this.dirty = false;
if(!(this instanceof Window)){
this.parent.revalidate();
+ long time = timer.stopTiming();
+ Debugger.log("Finished Revalidating " + name + ": " + time, Tag.PAINTING);
return;
}
Window window = (Window)this;
window.setFrameImageBuffer(imageBuffer);
+
+ long time = timer.stopTiming();
+ Debugger.log("Finished Revalidating " + name + ": " + time, Tag.PAINTING);
window.revalidate();
}
@@ -314,6 +346,7 @@ public class Visual {
/*--------------------------------------------------------------------
Listener Methods
---------------------------------------------------------------------*/
+
public void addMouseListener(MouseListener mouseListener) {
this.mouseListeners.add(mouseListener);
}
@@ -342,15 +375,17 @@ public class Visual {
for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mouseClicked(mouseEvent);
}
- dirty = true;
+ entered.propagateDirt();
entered.focused = true;
+ Debugger.log("Clicked " + entered.name, Tag.LISTENER);
}
void mouseReleased(MouseEvent mouseEvent) {
for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mouseReleased(mouseEvent);
}
- dirty = true;
+ Debugger.log("Released " + entered.name, Tag.LISTENER);
+ propagateDirt();
entered.pressed = false;
}
@@ -358,22 +393,23 @@ public class Visual {
for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mousePressed(mouseEvent);
}
- dirty = true;
+ entered.propagateDirt();
entered.pressed = true;
+ Debugger.log("Pressed " + entered.name, Tag.LISTENER);
}
- void mouseEntered(MouseEvent mouseEvent, int offsetX, int offsetY) {
+ void mouseEntered(MouseEvent mouseEvent) {
if(entered != null && entered.pressed){
return;
}
- int mouseX = mouseEvent.getX() - offsetX;
- int mouseY = mouseEvent.getY() - offsetY;
+ int mouseX = mouseEvent.getX();
+ int mouseY = mouseEvent.getY();
for(Visual v: children) {
if(mouseX > v.getLocationX() &&
mouseY > v.getLocationY() &&
mouseX < v.getWidth() + v.getLocationX() &&
mouseY < v.getHeight() + v.getLocationY()){
- v.mouseEntered(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
+ v.mouseEntered(mouseEvent);
return;
}
}
@@ -381,7 +417,8 @@ public class Visual {
for(MouseListener mouseListener: mouseListeners) {
mouseListener.mouseEntered(mouseEvent);
}
- dirty = true;
+ Debugger.log("Entered " + entered.name, Tag.LISTENER);
+ propagateDirt();
}
void mouseExited(MouseEvent mouseEvent) {
@@ -394,34 +431,37 @@ public class Visual {
for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseExited(mouseEvent);
}
+ Debugger.log("Exited " + entered.name, Tag.LISTENER);
+ entered.propagateDirt();
entered = null;
- dirty = true;
}
void mouseDragged(MouseEvent mouseEvent) {
for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseDragged(mouseEvent);
}
- entered.dirty = true;
+ entered.propagateDirt();
+ Debugger.log("Dragged " + entered.name, Tag.LISTENER);
}
- void mouseMoved(MouseEvent mouseEvent, int offsetX, int offsetY) {
+ void mouseMoved(MouseEvent mouseEvent) {
if(entered != null && entered.pressed){
return;
}
- int mouseX = mouseEvent.getX() - offsetX;
- int mouseY = mouseEvent.getY() - offsetY;
+ int mouseX = mouseEvent.getX();
+ int mouseY = mouseEvent.getY();
if(entered != null) {
- if (!entered.isInside(mouseEvent.getX(), mouseEvent.getY())) {
+ if (!entered.isInside(mouseX, mouseY)) {
for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseExited(mouseEvent);
}
+ Debugger.log("Exited " + entered.name, Tag.LISTENER);
entered = this;
}
}
for(Visual v: children) {
if(v.isInside(mouseX, mouseY)) {
- v.mouseMoved(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
+ v.mouseMoved(mouseEvent);
return;
}
}
@@ -439,20 +479,23 @@ public class Visual {
mouseListener.mouseMoved(mouseEvent);
}
}
- dirty = true;
+ Debugger.log("Moved " + this.name, Tag.LISTENER);
+ propagateDirt();
}
- void mouseWheelMoved(MouseWheelEvent mouseWheelEvent, int offsetX, int offsetY) {
+ void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
if(focused) {
for(MouseWheelListener mouseWheelListener: mouseWheelListeners) {
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
}
}
+ Debugger.log("Wheel Moved " + this.name, Tag.LISTENER);
}
/*--------------------------------------------------------------------
Helper Methods
---------------------------------------------------------------------*/
+
private void initializeImageBuffer(){
if(this.width <= 0 || this.height <= 0) {
return;
@@ -476,7 +519,6 @@ public class Visual {
for(Visual child: children) {
child.activate();
}
- this.dirty = true;
}
private void deactivate() {
@@ -488,6 +530,27 @@ public class Visual {
}
private boolean isInside(int x, int y) {
- return x > locationX && x < locationX + width && y > locationY && y < locationY + height;
+ return x > absoluteX && x < absoluteX + width && y > absoluteY && y < absoluteY + height;
+ }
+
+ private void calculateAbsoluteLocation() {
+ if(parent == null) {
+ absoluteX = locationX;
+ absoluteY = locationY;
+ }
+ else {
+ absoluteX = locationX + parent.absoluteX;
+ absoluteY = locationY + parent.absoluteY;
+ for(Visual v: children) {
+ v.calculateAbsoluteLocation();
+ }
+ }
+ }
+
+ private void propagateDirt() {
+ dirty = true;
+ if(parent != null) {
+ parent.propagateDirt();
+ }
}
}
diff --git a/src/guiTree/Window.java b/src/guiTree/Window.java
index 7a3c02e..fed5a07 100644
--- a/src/guiTree/Window.java
+++ b/src/guiTree/Window.java
@@ -1,9 +1,9 @@
package guiTree;
import guiTree.Components.TitleBar;
+import guiTree.Helper.Debugger;
import guiTree.Helper.Point2d;
-import guiTree.Listeners.Direction;
-import guiTree.Listeners.ResizeListener;
+import guiTree.Helper.Tag;
import guiTree.events.MouseAdapter;
import guiTree.Components.Panel;
@@ -25,6 +25,10 @@ public class Window extends Visual {
private Point2d oldLocation;
public Window() {
+ this("");
+ }
+
+ public Window(String title) {
super();
this.frame = new CustomFrame(this);
this.setUndecorated(true);
@@ -42,7 +46,8 @@ public class Window extends Visual {
} catch (IOException e) {
e.printStackTrace();
}
- TitleBar bar = new TitleBar("Working Title", icon);
+ TitleBar bar = new TitleBar(title, icon);
+ bar.setName("TitleBar");
bar.setBackgroundColor(Color.GRAY);
this.setTitleBar(bar);
}
@@ -51,6 +56,7 @@ public class Window extends Visual {
public void setSize(Integer width, Integer height) {
this.frame.setSize(width, height);
super.setSize(width, height);
+ mainPanel.setSize(width, height);
if(titleBar != null) {
titleBar.setSize(this.getWidth(), titleBar.getHeight());
contentPanel.setSize(width, height - titleBar.getHeight());
@@ -58,7 +64,7 @@ public class Window extends Visual {
else {
contentPanel.setSize(width, height);
}
- mainPanel.setSize(width, height);
+ Debugger.log("Calling repaint from window set size: ", Tag.PAINTING);
repaint();
}
@@ -68,6 +74,7 @@ public class Window extends Visual {
}
public void revalidate() {
+ Debugger.log("Finished painting", Tag.PAINTING);
this.frame.repaint();
}
@@ -127,6 +134,10 @@ public class Window extends Visual {
});
}
+ public void setTitle(String title) {
+ titleBar.setTitle(title);
+ }
+
public TitleBar getTitleBar() {
return this.titleBar;
}
@@ -197,7 +208,6 @@ public class Window extends Visual {
break;
}
case TitleBar.NORMALIZE: {
- Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
this.setSize(oldSize.x, oldSize.y);
this.setLocation(oldLocation.x, oldLocation.y);
setState(Frame.NORMAL);
diff --git a/src/parser/XAMLParser.java b/src/parser/XAMLParser.java
index 9cb8f52..596ecd9 100644
--- a/src/parser/XAMLParser.java
+++ b/src/parser/XAMLParser.java
@@ -41,26 +41,6 @@ public class XAMLParser {
}
}
- private static Method getMethod(Object object, String methodName, List