added debugger and timer

improved paint efficiency
debugged relative position
removed bug in parser for empty attribute methods
This commit is contained in:
rmaco
2020-03-23 18:00:45 +02:00
parent bce51befc2
commit 53265227f7
13 changed files with 253 additions and 129 deletions

View File

@@ -1,13 +1,38 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<Window Name="window" Visible="true" Size="640, 480"> <Window
<Panel Name="MainPanel" BackgroundColor="#999999" Size="1.0, 1.0" Overlapping="true"> Name="window"
<Button Name="button1" BackgroundColor="#990000" Size="0.5, 0.5" Location="0.0, 0.0" Label="button1"> Visible="true"
<Button Name="button4" BackgroundColor="#009999" Size="0.3, 0.3" Icon="square_white"> Size="640, 480"
<Button Name="button2" BackgroundColor="#000099" Size="50, 50" Label="button2"/> Title="FANTASTICEST UI THINGY">
<Button
Name="button1"
BackgroundColor="#999999"
AccentColor="#666666"
ForegroundColor="#333333"
Size="0.5, 0.5"
Location="0.0, 0.0"
HasBorder="true"
Label="button1">
<Button
Name="button4"
BackgroundColor="#009999"
AccentColor="#006666"
ForegroundColor="#003333"
Size="0.5, 0.5"
Location="0.25, 0.25"
Icon="square_white"
HasBorder="true">
<Button
Name="button2"
BackgroundColor="#000099"
AccentColor="#000066"
ForegroundColor="#000033"
Size="0.5, 0.5"
Location="0.25, 0.25"
Label="button2"/>
</Button>
</Button> </Button>
</Button>
<Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/> <Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/>
<Button Name="button3" BackgroundColor="#009900" Size="0.5, 0.5" Location="0.5, 0.0" Icon="close_black"/> <Button Name="button3" BackgroundColor="#009900" Size="0.5, 0.5" Location="0.0, 0.5" Icon="close_black"/>
<!-- <Button Name="button3" BackgroundColor="#123456" Size="0.5, 0.5" Location="0.5, 0.0" Icon="minimize_white"/>--> <Button Name="button3" BackgroundColor="#123456" Size="0.5, 0.5" Location="0.5, 0.0" Icon="minimize_white"/>
</Panel>
</Window> </Window>

View File

@@ -1,59 +1,39 @@
import guiTree.Components.Button; import guiTree.Components.Button;
import guiTree.Components.Panel;
import guiTree.Window; import guiTree.Window;
import guiTree.events.MouseAdapter; import guiTree.events.MouseAdapter;
import parser.XAMLParser; import parser.XAMLParser;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
try{ try{
Window window = XAMLParser.parse("ui.xml"); Window window = XAMLParser.parse("ui.xml");
assert window != null; assert window != null;
window.repaint();
Button button = (Button)window.findByName("button3"); Button button1 = (Button)window.findByName("button1");
button.addMouseListener(new MouseAdapter() { button1.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent mouseEvent) { public void mouseClicked(MouseEvent mouseEvent) {
Panel panel = window.getMainPanel(); System.out.println("Button x: " + button1.getLocationX() + " y: " + button1.getLocationY());
if(panel.getOverlapping()) {
panel.setOverlapping(false);
}
else {
panel.setOverlapping(true);
}
window.repaint();
} }
}); });
window.repaint(); Button button2 = (Button)window.findByName("button2");
System.out.println(Float.parseFloat("3")); button2.addMouseListener(new MouseAdapter() {
long now; @Override
long prev = 0; public void mouseClicked(MouseEvent mouseEvent) {
// while(true) { System.out.println("Button x: " + button2.getLocationX() + " y: " + button2.getLocationY());
// now = System.currentTimeMillis(); }
// if(now - prev >= 1000) { });
// int x = button.getLocationX();
// int y = button.getLocationY(); Button button4 = (Button)window.findByName("button4");
// if(x + button.getWidth() >= window.getWidth()) { button4.addMouseListener(new MouseAdapter() {
// x = 0; @Override
// if(y + button.getHeight() >= window.getHeight()) { public void mouseClicked(MouseEvent mouseEvent) {
// y = 0; System.out.println("Button x: " + button4.getLocationX() + " y: " + button4.getLocationY());
// } }
// else { });
// y += 30;
// }
// }
// else {
// x += 30;
// }
// button.setLocation(x, y);
// prev = now;
// window.revalidate();
// }
// }
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -1,5 +1,8 @@
package guiTree.Components; package guiTree.Components;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Helper.Timer;
import guiTree.Visual; import guiTree.Visual;
import guiTree.events.MouseAdapter; import guiTree.events.MouseAdapter;
@@ -35,32 +38,41 @@ public class Button extends Visual {
pressed = false; pressed = false;
hovered = false; hovered = false;
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
pressed = false;
}
@Override @Override
public void mousePressed(MouseEvent mouseEvent) { public void mousePressed(MouseEvent mouseEvent) {
pressed = true; pressed = true;
Debugger.log("Pressed: " + getName(), Tag.LISTENER);
Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
repaint(); repaint();
} }
@Override @Override
public void mouseReleased(MouseEvent mouseEvent) { public void mouseReleased(MouseEvent mouseEvent) {
pressed = false; pressed = false;
Debugger.log("Calling repaint from released: " + getName(), Tag.PAINTING);
repaint(); repaint();
} }
@Override @Override
public void mouseEntered(MouseEvent mouseEvent) { public void mouseEntered(MouseEvent mouseEvent) {
hovered = true; hovered = true;
Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
repaint(); repaint();
} }
@Override @Override
public void mouseExited(MouseEvent mouseEvent) { public void mouseExited(MouseEvent mouseEvent) {
hovered = false; hovered = false;
Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
repaint(); repaint();
} }
@Override @Override
public void mouseDragged(MouseEvent mouseEvent) { public void mouseDragged(MouseEvent mouseEvent) {
repaint();
} }
@Override @Override
public void mouseMoved(MouseEvent mouseEvent) { public void mouseMoved(MouseEvent mouseEvent) {
Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
repaint(); repaint();
} }
}); });
@@ -78,18 +90,28 @@ public class Button extends Visual {
g.setComposite(AlphaComposite.Src); g.setComposite(AlphaComposite.Src);
//Choose background //Choose background
if(hovered || pressed) { if(hovered) {
g.setColor(this.getForegroundColor()); g.setColor(this.getAccentColor());
} }
else { else {
g.setColor(this.getBackgroundColor()); g.setColor(this.getBackgroundColor());
} }
if(pressed) {
g.setColor(this.getForegroundColor());
}
//Draw Button //Draw Button
g.fillRect(0, 0, this.getWidth(), this.getHeight()); if(getHasBorder()) {
g.setColor(this.getFontColor()); 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 //Draw Label
g.setColor(this.getFontColor());
int textWidth = 0; int textWidth = 0;
int textHeight = 0; int textHeight = 0;
if(!label.equals("")) { if(!label.equals("")) {

View File

@@ -72,8 +72,8 @@ public class Panel extends Visual {
@Override @Override
public void addVisual(Visual v) { public void addVisual(Visual v) {
calculatePosition(v);
super.addVisual(v); super.addVisual(v);
calculatePosition(v);
visuals.add(v); visuals.add(v);
} }

View File

@@ -52,9 +52,13 @@ public class TitleBar extends Visual {
close.setBackgroundColor(Color.GRAY); close.setBackgroundColor(Color.GRAY);
maximize.setBackgroundColor(Color.GRAY); maximize.setBackgroundColor(Color.GRAY);
minimize.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); close.setForegroundColor(Color.RED);
maximize.setForegroundColor(Color.LIGHT_GRAY); maximize.setForegroundColor(Color.DARK_GRAY);
minimize.setForegroundColor(Color.LIGHT_GRAY); minimize.setForegroundColor(Color.DARK_GRAY);
this.setSize(0, 30); this.setSize(0, 30);
this.setLocation(0, 0); this.setLocation(0, 0);

View File

@@ -1,5 +1,7 @@
package guiTree; package guiTree;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.events.KeyEventGetter; import guiTree.events.KeyEventGetter;
import guiTree.events.MouseWheelGetter; import guiTree.events.MouseWheelGetter;
@@ -37,8 +39,7 @@ public class CustomFrame extends JFrame {
} }
@Override @Override
public void paint(Graphics g) public void paint(Graphics g) {
{
g.drawImage(imageBuffer, 0, 0, this.getWidth(), this.getHeight(), null); g.drawImage(imageBuffer, 0, 0, this.getWidth(), this.getHeight(), null);
} }

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,12 @@
package guiTree.Helper;
public enum Tag {
LISTENER(false),
PAINTING(false);
public boolean value;
Tag(boolean value) {
this.value = value;
}
}

View File

@@ -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;
}
}

View File

@@ -19,7 +19,7 @@ public class MouseEventGetter implements MouseInputListener {
@Override @Override
public void mouseMoved(MouseEvent mouseEvent) { public void mouseMoved(MouseEvent mouseEvent) {
callingWindow.mouseMoved(mouseEvent, 0, 0); callingWindow.mouseMoved(mouseEvent);
} }
@Override @Override
@@ -39,7 +39,7 @@ public class MouseEventGetter implements MouseInputListener {
@Override @Override
public void mouseEntered(MouseEvent mouseEvent) { public void mouseEntered(MouseEvent mouseEvent) {
callingWindow.mouseEntered(mouseEvent, 0, 0); callingWindow.mouseEntered(mouseEvent);
} }
@Override @Override

View File

@@ -1,5 +1,8 @@
package guiTree; package guiTree;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Helper.Timer;
import guiTree.events.KeyListener; import guiTree.events.KeyListener;
import guiTree.events.MouseListener; import guiTree.events.MouseListener;
import guiTree.events.MouseWheelListener; import guiTree.events.MouseWheelListener;
@@ -15,6 +18,7 @@ public class Visual {
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Constant Values Constant Values
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
public static final int SIZE_CHANGED = 1; public static final int SIZE_CHANGED = 1;
public static final int LOCATION_CHANGED = 2; public static final int LOCATION_CHANGED = 2;
@@ -40,15 +44,20 @@ public class Visual {
private Float relativeHeight; private Float relativeHeight;
private Integer locationX; private Integer locationX;
private Integer locationY; private Integer locationY;
private Integer absoluteX;
private Integer absoluteY;
private Float relativeX; private Float relativeX;
private Float relativeY; private Float relativeY;
private Color backgroundColor; private Color backgroundColor;
private Color foregroundColor; private Color foregroundColor;
private Color accentColor;
private Color fontColor; private Color fontColor;
private Color borderColor;
private Boolean active; private Boolean active;
private Boolean dirty; public Boolean dirty;
private static Visual entered; private static Visual entered;
private Boolean focused; private Boolean focused;
private Boolean hasBorder;
private Boolean pressed; private Boolean pressed;
@@ -70,8 +79,11 @@ public class Visual {
this.backgroundColor = Color.WHITE; this.backgroundColor = Color.WHITE;
this.foregroundColor = Color.BLUE; this.foregroundColor = Color.BLUE;
this.fontColor = Color.BLACK; this.fontColor = Color.BLACK;
this.borderColor = Color.BLACK;
this.accentColor = Color.BLUE;
this.dirty = true; this.dirty = true;
this.hasBorder = false;
this.active = this instanceof Window; this.active = this instanceof Window;
this.focused = false; this.focused = false;
this.pressed = false; this.pressed = false;
@@ -85,6 +97,8 @@ public class Visual {
this.locationX = 0; this.locationX = 0;
this.locationY = 0; this.locationY = 0;
this.absoluteX = 0;
this.absoluteY = 0;
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@@ -115,8 +129,8 @@ public class Visual {
v.setLocation(); v.setLocation();
} }
} }
this.dirty = true; propagateDirt();
this.notifyParent(SIZE_CHANGED); notifyParent(SIZE_CHANGED);
} }
public void setSize(Integer width, Integer height) { public void setSize(Integer width, Integer height) {
@@ -141,7 +155,8 @@ public class Visual {
} }
} }
this.dirty = true; calculateAbsoluteLocation();
propagateDirt();
notifyParent(LOCATION_CHANGED); notifyParent(LOCATION_CHANGED);
} }
@@ -167,25 +182,28 @@ public class Visual {
public void setBackgroundColor(Color backgroundColor) { public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor; this.backgroundColor = backgroundColor;
this.dirty = true; propagateDirt();
} }
public void setForegroundColor(Color foregroundColor) { public void setForegroundColor(Color foregroundColor) {
this.foregroundColor = foregroundColor; this.foregroundColor = foregroundColor;
this.dirty = true; propagateDirt();
} }
public void setFontColor(Color fontColor) { public void setFontColor(Color fontColor) {
this.fontColor = fontColor; this.fontColor = fontColor;
} }
private void calculateInitialLocation() { public void setAccentColor(Color accentColor) {
if(this.locationX <= 0) { this.accentColor = accentColor;
this.locationX = 0; }
}
if(this.locationY <= 0){ public void setBorderColor(Color borderColor) {
this.locationY = 0; this.borderColor = borderColor;
} }
public void setHasBorder(Boolean hasBorder) {
this.hasBorder = hasBorder;
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@@ -224,6 +242,18 @@ public class Visual {
return fontColor; return fontColor;
} }
public Color getAccentColor() {
return accentColor;
}
public Color getBorderColor() {
return borderColor;
}
public Boolean getHasBorder() {
return hasBorder;
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Tree Methods Tree Methods
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
@@ -247,7 +277,7 @@ public class Visual {
public void addVisual(Visual child) { public void addVisual(Visual child) {
this.children.add(child); this.children.add(child);
child.setParent(this); child.setParent(this);
child.calculateInitialLocation(); child.setLocation();
child.setSize(); child.setSize();
if(this.active) { if(this.active) {
@@ -260,7 +290,7 @@ public class Visual {
child.setParent(null); child.setParent(null);
child.imageBuffer = null; child.imageBuffer = null;
child.deactivate(); child.deactivate();
this.dirty = true; propagateDirt();
} }
private void setParent(Visual parent) { private void setParent(Visual parent) {
@@ -273,24 +303,21 @@ public class Visual {
public void notifyParent(int notify) { public void notifyParent(int notify) {
if(parent != null) { if(parent != null) {
this.parent.handleNotification(notify); parent.handleNotification(notify);
} }
} }
public void repaint() { public void repaint() {
if(!this.active){ if(dirty && active) {
return;
}
if(this.dirty) {
this.revalidate(); this.revalidate();
return;
}
for(Visual v: children) {
v.repaint();
} }
} }
private void revalidate() { private void revalidate() {
Timer timer = new Timer();
Debugger.log("Revalidating " + name, Tag.PAINTING);
timer.startTiming();
clearImageBuffer(); clearImageBuffer();
this.paint(imageBuffer); this.paint(imageBuffer);
for (Visual v : children) { for (Visual v : children) {
@@ -300,10 +327,15 @@ public class Visual {
this.dirty = false; this.dirty = false;
if(!(this instanceof Window)){ if(!(this instanceof Window)){
this.parent.revalidate(); this.parent.revalidate();
long time = timer.stopTiming();
Debugger.log("Finished Revalidating " + name + ": " + time, Tag.PAINTING);
return; return;
} }
Window window = (Window)this; Window window = (Window)this;
window.setFrameImageBuffer(imageBuffer); window.setFrameImageBuffer(imageBuffer);
long time = timer.stopTiming();
Debugger.log("Finished Revalidating " + name + ": " + time, Tag.PAINTING);
window.revalidate(); window.revalidate();
} }
@@ -314,6 +346,7 @@ public class Visual {
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Listener Methods Listener Methods
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
public void addMouseListener(MouseListener mouseListener) { public void addMouseListener(MouseListener mouseListener) {
this.mouseListeners.add(mouseListener); this.mouseListeners.add(mouseListener);
} }
@@ -342,15 +375,17 @@ public class Visual {
for(MouseListener mouseListener: entered.mouseListeners) { for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mouseClicked(mouseEvent); mouseListener.mouseClicked(mouseEvent);
} }
dirty = true; entered.propagateDirt();
entered.focused = true; entered.focused = true;
Debugger.log("Clicked " + entered.name, Tag.LISTENER);
} }
void mouseReleased(MouseEvent mouseEvent) { void mouseReleased(MouseEvent mouseEvent) {
for(MouseListener mouseListener: entered.mouseListeners) { for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mouseReleased(mouseEvent); mouseListener.mouseReleased(mouseEvent);
} }
dirty = true; Debugger.log("Released " + entered.name, Tag.LISTENER);
propagateDirt();
entered.pressed = false; entered.pressed = false;
} }
@@ -358,22 +393,23 @@ public class Visual {
for(MouseListener mouseListener: entered.mouseListeners) { for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mousePressed(mouseEvent); mouseListener.mousePressed(mouseEvent);
} }
dirty = true; entered.propagateDirt();
entered.pressed = true; 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){ if(entered != null && entered.pressed){
return; return;
} }
int mouseX = mouseEvent.getX() - offsetX; int mouseX = mouseEvent.getX();
int mouseY = mouseEvent.getY() - offsetY; int mouseY = mouseEvent.getY();
for(Visual v: children) { for(Visual v: children) {
if(mouseX > v.getLocationX() && if(mouseX > v.getLocationX() &&
mouseY > v.getLocationY() && mouseY > v.getLocationY() &&
mouseX < v.getWidth() + v.getLocationX() && mouseX < v.getWidth() + v.getLocationX() &&
mouseY < v.getHeight() + v.getLocationY()){ mouseY < v.getHeight() + v.getLocationY()){
v.mouseEntered(mouseEvent, offsetX + v.locationX, offsetY + v.locationY); v.mouseEntered(mouseEvent);
return; return;
} }
} }
@@ -381,7 +417,8 @@ public class Visual {
for(MouseListener mouseListener: mouseListeners) { for(MouseListener mouseListener: mouseListeners) {
mouseListener.mouseEntered(mouseEvent); mouseListener.mouseEntered(mouseEvent);
} }
dirty = true; Debugger.log("Entered " + entered.name, Tag.LISTENER);
propagateDirt();
} }
void mouseExited(MouseEvent mouseEvent) { void mouseExited(MouseEvent mouseEvent) {
@@ -394,34 +431,37 @@ public class Visual {
for (MouseListener mouseListener : entered.mouseListeners) { for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseExited(mouseEvent); mouseListener.mouseExited(mouseEvent);
} }
Debugger.log("Exited " + entered.name, Tag.LISTENER);
entered.propagateDirt();
entered = null; entered = null;
dirty = true;
} }
void mouseDragged(MouseEvent mouseEvent) { void mouseDragged(MouseEvent mouseEvent) {
for (MouseListener mouseListener : entered.mouseListeners) { for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseDragged(mouseEvent); 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){ if(entered != null && entered.pressed){
return; return;
} }
int mouseX = mouseEvent.getX() - offsetX; int mouseX = mouseEvent.getX();
int mouseY = mouseEvent.getY() - offsetY; int mouseY = mouseEvent.getY();
if(entered != null) { if(entered != null) {
if (!entered.isInside(mouseEvent.getX(), mouseEvent.getY())) { if (!entered.isInside(mouseX, mouseY)) {
for (MouseListener mouseListener : entered.mouseListeners) { for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseExited(mouseEvent); mouseListener.mouseExited(mouseEvent);
} }
Debugger.log("Exited " + entered.name, Tag.LISTENER);
entered = this; entered = this;
} }
} }
for(Visual v: children) { for(Visual v: children) {
if(v.isInside(mouseX, mouseY)) { if(v.isInside(mouseX, mouseY)) {
v.mouseMoved(mouseEvent, offsetX + v.locationX, offsetY + v.locationY); v.mouseMoved(mouseEvent);
return; return;
} }
} }
@@ -439,20 +479,23 @@ public class Visual {
mouseListener.mouseMoved(mouseEvent); 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) { if(focused) {
for(MouseWheelListener mouseWheelListener: mouseWheelListeners) { for(MouseWheelListener mouseWheelListener: mouseWheelListeners) {
mouseWheelListener.mouseWheelMoved(mouseWheelEvent); mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
} }
} }
Debugger.log("Wheel Moved " + this.name, Tag.LISTENER);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Helper Methods Helper Methods
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
private void initializeImageBuffer(){ private void initializeImageBuffer(){
if(this.width <= 0 || this.height <= 0) { if(this.width <= 0 || this.height <= 0) {
return; return;
@@ -476,7 +519,6 @@ public class Visual {
for(Visual child: children) { for(Visual child: children) {
child.activate(); child.activate();
} }
this.dirty = true;
} }
private void deactivate() { private void deactivate() {
@@ -488,6 +530,27 @@ public class Visual {
} }
private boolean isInside(int x, int y) { 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();
}
} }
} }

View File

@@ -1,9 +1,9 @@
package guiTree; package guiTree;
import guiTree.Components.TitleBar; import guiTree.Components.TitleBar;
import guiTree.Helper.Debugger;
import guiTree.Helper.Point2d; import guiTree.Helper.Point2d;
import guiTree.Listeners.Direction; import guiTree.Helper.Tag;
import guiTree.Listeners.ResizeListener;
import guiTree.events.MouseAdapter; import guiTree.events.MouseAdapter;
import guiTree.Components.Panel; import guiTree.Components.Panel;
@@ -25,6 +25,10 @@ public class Window extends Visual {
private Point2d oldLocation; private Point2d oldLocation;
public Window() { public Window() {
this("");
}
public Window(String title) {
super(); super();
this.frame = new CustomFrame(this); this.frame = new CustomFrame(this);
this.setUndecorated(true); this.setUndecorated(true);
@@ -42,7 +46,8 @@ public class Window extends Visual {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
TitleBar bar = new TitleBar("Working Title", icon); TitleBar bar = new TitleBar(title, icon);
bar.setName("TitleBar");
bar.setBackgroundColor(Color.GRAY); bar.setBackgroundColor(Color.GRAY);
this.setTitleBar(bar); this.setTitleBar(bar);
} }
@@ -51,6 +56,7 @@ public class Window extends Visual {
public void setSize(Integer width, Integer height) { public void setSize(Integer width, Integer height) {
this.frame.setSize(width, height); this.frame.setSize(width, height);
super.setSize(width, height); super.setSize(width, height);
mainPanel.setSize(width, height);
if(titleBar != null) { if(titleBar != null) {
titleBar.setSize(this.getWidth(), titleBar.getHeight()); titleBar.setSize(this.getWidth(), titleBar.getHeight());
contentPanel.setSize(width, height - titleBar.getHeight()); contentPanel.setSize(width, height - titleBar.getHeight());
@@ -58,7 +64,7 @@ public class Window extends Visual {
else { else {
contentPanel.setSize(width, height); contentPanel.setSize(width, height);
} }
mainPanel.setSize(width, height); Debugger.log("Calling repaint from window set size: ", Tag.PAINTING);
repaint(); repaint();
} }
@@ -68,6 +74,7 @@ public class Window extends Visual {
} }
public void revalidate() { public void revalidate() {
Debugger.log("Finished painting", Tag.PAINTING);
this.frame.repaint(); this.frame.repaint();
} }
@@ -127,6 +134,10 @@ public class Window extends Visual {
}); });
} }
public void setTitle(String title) {
titleBar.setTitle(title);
}
public TitleBar getTitleBar() { public TitleBar getTitleBar() {
return this.titleBar; return this.titleBar;
} }
@@ -197,7 +208,6 @@ public class Window extends Visual {
break; break;
} }
case TitleBar.NORMALIZE: { case TitleBar.NORMALIZE: {
Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
this.setSize(oldSize.x, oldSize.y); this.setSize(oldSize.x, oldSize.y);
this.setLocation(oldLocation.x, oldLocation.y); this.setLocation(oldLocation.x, oldLocation.y);
setState(Frame.NORMAL); setState(Frame.NORMAL);

View File

@@ -41,26 +41,6 @@ public class XAMLParser {
} }
} }
private static Method getMethod(Object object, String methodName, List<Object> parameterList){
Method method;
Class<?>[] args = new Class[parameterList.size()];
for(Object o: parameterList){
try {
args[parameterList.indexOf(o)] = o.getClass();
} catch (NullPointerException e) {
System.err.println("Null Pointer Exception: " + methodName + " with parameters + " + parameterList.toString());
}
}
try {
method = object.getClass().getMethod(methodName, args);
return method;
} catch (NoSuchMethodException e) {
System.err.println("Method does not exist: " + methodName + " with parameters + " + parameterList.toString());
e.printStackTrace();
}
return null;
}
private static List<Method> getMethodsFromName(Object object, String methodName){ private static List<Method> getMethodsFromName(Object object, String methodName){
Method[] methods = object.getClass().getMethods(); Method[] methods = object.getClass().getMethods();
List<Method> returnMethods = new ArrayList<>(); List<Method> returnMethods = new ArrayList<>();
@@ -86,6 +66,7 @@ public class XAMLParser {
rootObject = parseNode(rootNode); rootObject = parseNode(rootNode);
if(rootObject instanceof Window) { if(rootObject instanceof Window) {
((Window) rootObject).repaint();
return (Window) rootObject; return (Window) rootObject;
} }
return null; return null;
@@ -112,7 +93,7 @@ public class XAMLParser {
break; break;
} }
} }
if(primitiveAttributes.size() == types.length){ if(primitiveAttributes.size() == types.length && types.length == values.size()){
return primitiveAttributes; return primitiveAttributes;
} }
} }