added sliders

reworked painting
added animations
reworked point2
added point3 point4
made tag inner class in Debugger
added fps animation parsing debuggers
made new thread for painting at 60fps
This commit is contained in:
Macocian Adrian Radu
2020-03-31 01:01:25 +03:00
parent c4b18404a8
commit 62f3d8d46c
35 changed files with 763 additions and 379 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

View File

@@ -9,55 +9,58 @@
<!-- Size="1.0, 1.0"-->
<!-- Location="0.0, 0.0"-->
<!-- BackgroundColor="#333333">-->
<!-- <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">-->
<!-- <ToggleButton-->
<!-- Name="button2"-->
<!-- BackgroundColor="#000099"-->
<!-- AccentColor="#000066"-->
<!-- ForegroundColor="#000033"-->
<!-- Size="0.5, 0.5"-->
<!-- Location="0.25, 0.25"-->
<!-- Label="button2"/>-->
<!-- </Button>-->
<!-- </Button>-->
<Button
Name="button1"
BackgroundColor="#999999"
AccentColor="#666666"
ForegroundColor="#333333"
Size="320, 240"
Location="0.0, 0.5"
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">
<ToggleButton
Name="button2"
BackgroundColor="#000099"
AccentColor="#000066"
ForegroundColor="#000033"
Size="0.5, 0.5"
Location="0.25, 0.25"
Label="button2"/>
</Button>
</Button>
<!-- <Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/>-->
<CheckBoxList
Name="checkboxlist"
CheckBoxSize="300, 20"
BackgroundColor="#666666"
AccentColor="#444444"
ForegroundColor="#005599"
Size="0.5, 0.5"
Icon="check_white"
Spacing="30"
Location="0.0, 0.0">
<CheckBox
Name="checkbox1"
Text="HAHA FRAR"/>
<CheckBox
Name="checkbox2"
Text="HAHA FRAR2"/>
<CheckBox
Name="checkbox3"
Text="HAHA FRAR3"/>
</CheckBoxList>
<!-- <CheckBoxList-->
<!-- Name="checkboxlist"-->
<!-- CheckBoxSize="300, 20"-->
<!-- BackgroundColor="#666666"-->
<!-- AccentColor="#444444"-->
<!-- ForegroundColor="#005599"-->
<!-- Size="0.5, 0.3"-->
<!-- Icon="check_white"-->
<!-- Spacing="30"-->
<!-- Location="0.0, 0.0">-->
<!-- <CheckBox-->
<!-- Name="checkbox1"-->
<!-- Text="HAHA FRAR"/>-->
<!-- <CheckBox-->
<!-- Name="checkbox2"-->
<!-- Text="HAHA FRAR2"/>-->
<!-- <CheckBox-->
<!-- Name="checkbox3"-->
<!-- Text="HAHA FRAR3"/>-->
<!-- </CheckBoxList>-->
<ToggleButton Name="button3" BackgroundColor="#123456" AccentColor="654321" Size="100, 100" Location="0.5, 0.5" Icon="minimize_white"/>
<Slider Name="slider" Location="-20, 0" Size="20, 100" HasBorder="false"/>
<Slider Name="hslider" Location="400, 0" Size="80, 20" Direction="horizontal"/>
<Button Location="350, 20" Size="20, 70"/>
<!-- </Panel>-->
</Window>

View File

@@ -1,43 +1,53 @@
import guiTree.Components.Button;
import guiTree.Components.CheckBox;
import guiTree.Components.ToggleButton;
import guiTree.Animations.ColorAnimation;
import guiTree.Animations.LocationAnimation;
import guiTree.Components.Slider;
import guiTree.Helper.Point2;
import guiTree.Visual;
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;
// 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");
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);
}catch (Exception e){
e.printStackTrace();
}

View File

@@ -1,6 +1,7 @@
package converters;
import com.sun.jdi.InvalidTypeException;
import guiTree.Components.Slider;
import java.awt.*;
import java.util.HashMap;
@@ -20,6 +21,7 @@ public class Converter {
this.converterTable.put(Double.TYPE, new DoubleConverter());
this.converterTable.put(Boolean.TYPE, new BooleanConverter());
this.converterTable.put(Color.class, new ColorConverter());
this.converterTable.put(Slider.Direction.class, new DirectionConverter());
}
public Object objectCreatorFactory (Class<?> type, String content) throws InvalidTypeException {

View File

@@ -0,0 +1,18 @@
package converters;
import com.sun.jdi.InvalidTypeException;
import guiTree.Components.Slider;
public class DirectionConverter implements ConverterInterface<Slider.Direction> {
@Override
public Slider.Direction convert(String content) throws InvalidTypeException {
content = content.toLowerCase();
if(content.equals("horizontal")) {
return Slider.Direction.Horizontal;
}
if(content.equals("vertical")) {
return Slider.Direction.Vertical;
}
throw new InvalidTypeException();
}
}

View File

@@ -0,0 +1,6 @@
package guiTree.Animations;
public interface AnimationInterface {
int FPS = 60;
boolean step();
}

View File

@@ -0,0 +1,51 @@
package guiTree.Animations;
import guiTree.Helper.*;
import guiTree.Visual;
import java.awt.*;
public class ColorAnimation implements AnimationInterface {
private Point4<Float> from;
private Point4<Integer> to;
private Point4<Float> offset;
private Visual element;
public ColorAnimation(Visual v, Color from, Color to, int ms) {
this.from = new Point4<>((float)from.getRed(), (float)from.getGreen(), (float)from.getBlue(), (float)from.getAlpha());
this.to = new Point4<>(to.getRed(), to.getGreen(), to.getBlue(), to.getAlpha());
this.offset = new Point4<>((this.to.a - this.from.a) * 1000 / FPS / ms,
(this.to.b - this.from.b) * 1000 / FPS / ms,
(this.to.c - this.from.c) * 1000 / FPS / ms,
(this.to.d - this.from.d) * 1000 / FPS / ms);
this.element = v;
Debugger.log("Created color animation for " + v.getName() +
" from r: " + this.from.a +
" g: " + this.from.b +
" b: " + this.from.c +
" a: " + this.from.d +
" to r: " + this.to.a +
" g: " + this.to.b +
" b: " + this.to.c +
" a: " + this.to.d, Debugger.Tag.ANIMATIONS);
}
@Override
public boolean step() {
if(from.a > to.a - 1 && from.a < to.a + 1 &&
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));
Debugger.log("Animation for " + element.getName() + " finished", Debugger.Tag.ANIMATIONS);
return true;
}
from.a += offset.a;
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.update();
return false;
}
}

View File

@@ -0,0 +1,34 @@
package guiTree.Animations;
import guiTree.Helper.Debugger;
import guiTree.Helper.Point2;
import guiTree.Visual;
public class LocationAnimation implements AnimationInterface {
private Point2<Float> from;
private Point2<Integer> to;
private Point2<Float> offset;
private Visual element;
public LocationAnimation(Visual v, Point2<Integer> from, Point2<Integer> to, int ms) {
this.from = new Point2<>(from.x.floatValue(), from.y.floatValue());
this.to = to;
this.offset = new Point2<>((float)(to.x - from.x) * 1000 / FPS / ms, (float)(to.y - from.y) * 1000 / FPS / ms);
this.element = v;
Debugger.log("Created animation for " + v.getName() + " from x: " + from.x + " y: " + from.y + " to x: " + to.x + " y: " + to.y, Debugger.Tag.ANIMATIONS);
}
@Override
public boolean step() {
if(from.x > to.x - 1 && from.x < to.x + 1 && from.y > to.y - 1 && from.y < to.y + 1) {
element.setLocation(to.x, to.y);
Debugger.log("Animation for " + element.getName() + " finished", Debugger.Tag.ANIMATIONS);
return true;
}
from.x += offset.x;
from.y += offset.y;
element.setLocation(Math.round(from.x), Math.round(from.y));
element.update();
return false;
}
}

View File

@@ -1,7 +1,6 @@
package guiTree.Components;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -17,6 +16,7 @@ public class Button extends Visual {
private Boolean pressed;
private Boolean hovered;
private BufferedImage icon;
private int round = -1;
public Button() {
this("", null);
@@ -40,39 +40,39 @@ public class Button extends Visual {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
pressed = false;
update();
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
pressed = true;
Debugger.log("Pressed: " + getName(), Tag.LISTENER);
Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
repaint();
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;
Debugger.log("Calling repaint from released: " + getName(), Tag.PAINTING);
repaint();
update();
Debugger.log("Calling repaint from released: " + getName(), Debugger.Tag.PAINTING);
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
hovered = true;
Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
repaint();
update();
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
hovered = false;
Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
repaint();
update();
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
}
@Override
public void mouseDragged(MouseEvent mouseEvent) {
}
@Override
public void mouseMoved(MouseEvent mouseEvent) {
Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from moved: " + getName(), Debugger.Tag.PAINTING);
}
});
}
@@ -82,11 +82,7 @@ public class Button extends Visual {
{
//Get Graphics
Graphics2D g = imageBuffer.createGraphics();
//Set Transparency
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, getWidth(), getHeight());
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//Choose background
if(hovered) {
@@ -101,12 +97,12 @@ public class Button extends Visual {
//Draw Button
if(getHasBorder()) {
g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2);
g.fillRoundRect(1, 1, getWidth() - 1, getHeight() - 1, round, round);
g.setColor(getBorderColor());
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, round, round);
}
else {
g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
g.fillRoundRect(0, 0, getWidth(), getHeight(), round, round);
}
//Draw Label
@@ -138,6 +134,10 @@ public class Button extends Visual {
g.dispose();
}
public void setRound(int round) {
this.round = round;
}
public void setLabel(String label) {
this.label = label;
}

View File

@@ -1,7 +1,6 @@
package guiTree.Components;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -39,25 +38,24 @@ public class CheckBox extends Visual {
@Override
public void mousePressed(MouseEvent mouseEvent) {
marked = !marked;
Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
hovered = true;
Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
hovered = false;
Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseMoved(MouseEvent mouseEvent) {
Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from moved: " + getName(), Debugger.Tag.PAINTING);
}
});
}

View File

@@ -1,6 +1,6 @@
package guiTree.Components;
import guiTree.Helper.Point2d;
import guiTree.Helper.Point2;
import guiTree.Visual;
import javax.imageio.ImageIO;
@@ -15,7 +15,7 @@ public class CheckBoxList extends Visual {
private List<CheckBox> checkBoxList;
int spacing;
private BufferedImage icon;
private Point2d checkBoxSize;
private Point2<Integer> checkBoxSize;
public CheckBoxList() {
this(20);
@@ -84,7 +84,7 @@ public class CheckBoxList extends Visual {
for(CheckBox cb: checkBoxList) {
cb.setSize(width, height);
}
checkBoxSize = new Point2d(width, height);
checkBoxSize = new Point2<>(width, height);
}
@Override

View File

@@ -2,6 +2,8 @@ package guiTree.Components;
import guiTree.Visual;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
@@ -105,4 +107,14 @@ public class Panel extends Visual {
// reposition();
// }
}
@Override
public void paint(BufferedImage imageBuffer) {
Graphics2D g = imageBuffer.createGraphics();
g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
g.dispose();
}
}

View File

@@ -0,0 +1,66 @@
package guiTree.Components;
import guiTree.Helper.Debugger;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
import java.awt.*;
import java.awt.image.BufferedImage;
public class ScrollPanel extends Visual {
private float positionX;
private float positionY;
private float ratioX;
private float ratioY;
private Slider verticalScrollBar;
private Slider horizontalScrollBar;
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");
}
@Override
public void setSize() {
super.setSize();
if(verticalScrollBar != null && horizontalScrollBar != null) {
verticalScrollBar.setSize(20, getHeight() - 20);
horizontalScrollBar.setSize(getWidth() - 20, 20);
return;
}
if(horizontalScrollBar != null) {
horizontalScrollBar.setSize(getWidth(), 20);
}
if(verticalScrollBar != null) {
verticalScrollBar.setSize(20, getHeight());
}
}
@Override
public void paint(BufferedImage imageBuffer) {
Graphics2D g = imageBuffer.createGraphics();
if(getHasBorder()) {
g.setColor(getBackgroundColor());
g.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
g.setColor(getBorderColor());
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
else {
g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
}
g.dispose();
}
}

View File

@@ -0,0 +1,264 @@
package guiTree.Components;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
public class Slider extends Visual {
public enum Direction {
Vertical,
Horizontal
}
private Direction direction;
private Button slider;
private Button button2;
private Button button1;
private SliderListener sliderListener;
public Slider() {
this(Direction.Vertical);
}
public Slider(Direction direction) {
super();
this.direction = direction;
button1 = new Button();
button2 = new Button();
slider = new Button();
setBackgroundColor(new Color(175, 175, 175));
setForegroundColor(new Color(112, 112, 112));
setAccentColor(new Color(50, 50, 50));
button1.setHasBorder(false);
button2.setHasBorder(false);
if(direction == Direction.Horizontal) {
button1.setIcon("arrow_left_black");
button2.setIcon("arrow_right_black");
button1.setLocation(0.0f, 0.15f);
button2.setLocation(-1.0f, 0.15f);
slider.setLocation(-1.0f, 0.25f);
slider.setSize(-1.0f, 0.5f);
slider.setLocation(20, 0);
}
else {
button1.setIcon("arrow_up_black");
button2.setIcon("arrow_down_black");
button1.setLocation(0.15f, 0.0f);
button2.setLocation(0.15f, -1.0f);
slider.setLocation(0.25f, -1.0f);
slider.setSize(0.5f, -1.0f);
slider.setLocation(0, 20);
}
addVisual(button1);
addVisual(button2);
addVisual(slider);
button1.setLocation(0, 0);
slider.setRound(10);
button1.setRound(10);
button2.setRound(10);
button1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
moveSlider(-0.05f);
button1.update();
}
});
button2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
moveSlider(0.05f);
button2.update();
}
});
sliderListener = new SliderListener();
slider.addMouseListener(sliderListener);
}
public float getSliderLocation() {
if(direction == Direction.Vertical) {
return (float)slider.getLocationY() / getHeight();
}
else {
return (float)slider.getLocationX() / getWidth();
}
}
public void setSliderSize(int width, int height) {
slider.setSize(width, height);
}
private void moveSlider(int offset) {
if(direction == Direction.Vertical) {
if(slider.getLocationY() + slider.getHeight() + offset > getHeight() - button2.getHeight()) {
slider.setLocationY(getHeight() - slider.getHeight() - button2.getHeight());
}
else if (slider.getLocationY() + offset < button1.getHeight()) {
slider.setLocationY(button1.getHeight());
}
else {
slider.setLocationY(Math.round(slider.getLocationY() + offset));
}
}
else {
if(slider.getLocationX() + slider.getWidth() + offset > getWidth() - button2.getWidth()) {
slider.setLocationX(getWidth() - slider.getWidth() - button2.getWidth());
}
else if (slider.getLocationX() + offset < button1.getWidth()) {
slider.setLocationX(button1.getWidth());
}
else {
slider.setLocationX(Math.round(slider.getLocationX() + offset));
}
}
}
public void setDirection(Direction direction) {
this.direction = direction;
if(direction == Direction.Horizontal) {
button1.setIcon("arrow_left_black");
button2.setIcon("arrow_right_black");
button1.setLocation(0.0f, 0.15f);
button2.setLocation(-1.0f, 0.15f);
slider.setLocation(-1.0f, 0.25f);
slider.setSize(-1.0f, 0.5f);
slider.setLocation(20, 0);
}
else {
button1.setIcon("arrow_up_black");
button2.setIcon("arrow_down_black");
button1.setLocation(0.15f, 0.0f);
button2.setLocation(0.15f, -1.0f);
slider.setLocation(0.25f, -1.0f);
slider.setSize(0.5f, -1.0f);
slider.setLocation(0, 20);
}
}
private void moveSlider(float offset) {
if(direction == Direction.Vertical) {
moveSlider(Math.round(offset * getHeight()));
return;
}
moveSlider(Math.round(offset * getWidth()));
}
@Override
public void setBackgroundColor(Color color) {
super.setBackgroundColor(color);
button1.setBackgroundColor(new Color(0, 0, 0, 0.0f));
button2.setBackgroundColor(new Color(0, 0, 0, 0.0f));
}
@Override
public void setForegroundColor(Color color) {
super.setForegroundColor(color);
slider.setBackgroundColor(color);
slider.setAccentColor(color);
button1.setAccentColor(color);
button2.setAccentColor(color);
}
@Override
public void setAccentColor(Color color) {
super.setAccentColor(color);
button1.setForegroundColor(color);
button2.setForegroundColor(color);
slider.setForegroundColor(color);
}
@Override
public void setBorderColor(Color color) {
super.setBorderColor(color);
button1.setBorderColor(color);
button2.setBorderColor(color);
slider.setBorderColor(color);
}
@Override
public void setName(String name) {
super.setName(name);
slider.setName(name + " slider");
button1.setName(name + " button 1");
button2.setName(name + " button 2");
}
@Override
public void setSize() {
super.setSize();
if(direction == Direction.Vertical) {
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);
}
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);
}
}
@Override
public void paint(BufferedImage imageBuffer) {
Graphics2D g = imageBuffer.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if(getHasBorder()) {
g.setColor(getBorderColor());
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();
int x2 = Math.round(0.85f * getWidth()) - x1;
int y2 = getHeight() - button2.getHeight() - y1;
g.fillRoundRect(x1, y1, x2, y2, 10, 10);
}
else {
int x1 = button1.getWidth();
int y1 = Math.round(0.15f * getHeight());
int x2 = getWidth() - button2.getWidth() - x1;
int y2 = Math.round(0.85f * getHeight()) - y1;
g.fillRoundRect(x1, y1, x2, y2, 10, 10);
}
g.dispose();
}
private class SliderListener extends MouseAdapter {
private int start;
@Override
public void mousePressed(MouseEvent mouseEvent) {
if(direction == Direction.Vertical) {
start = mouseEvent.getY();
}
else {
start = mouseEvent.getX();
}
}
@Override
public void mouseDragged(MouseEvent mouseEvent) {
if(direction == Direction.Vertical) {
moveSlider(mouseEvent.getY() - start);
start = mouseEvent.getY();
}
else {
moveSlider(mouseEvent.getX() - start);
start = mouseEvent.getX();
}
slider.update();
}
}
}

View File

@@ -1,7 +1,6 @@
package guiTree.Components;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Visual;
import guiTree.events.MouseAdapter;
@@ -40,26 +39,25 @@ public class ToggleButton extends Visual {
@Override
public void mousePressed(MouseEvent mouseEvent) {
pressed = !pressed;
Debugger.log("Pressed: " + getName(), Tag.LISTENER);
Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
repaint();
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;
Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
hovered = false;
Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
update();
}
@Override
public void mouseMoved(MouseEvent mouseEvent) {
Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
repaint();
Debugger.log("Calling repaint from moved: " + getName(), Debugger.Tag.PAINTING);
}
});
}

View File

@@ -1,12 +1,11 @@
package guiTree;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Helper.Timer;
import guiTree.events.KeyEventGetter;
import guiTree.events.MouseWheelGetter;
import javax.swing.*;
import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
@@ -40,7 +39,10 @@ public class CustomFrame extends JFrame {
@Override
public void paint(Graphics g) {
Timer timer = new Timer();
timer.startTiming();
g.drawImage(imageBuffer, 0, 0, this.getWidth(), this.getHeight(), null);
Debugger.log("AWT time: " + timer.stopTiming(), Debugger.Tag.PAINTING);
}
private class MouseResizeListener implements MouseMotionListener, MouseListener {

View File

@@ -1,6 +1,20 @@
package guiTree.Helper;
public class Debugger {
public enum Tag {
LISTENER(false),
PAINTING(false),
FPS(false),
ANIMATIONS(true),
PARSING(false);
public boolean value;
Tag(boolean value) {
this.value = value;
}
}
private static Timer timer = new Timer();
public static void log(String message, Tag tag) {

View File

@@ -0,0 +1,15 @@
package guiTree.Helper;
public class Point2<T> {
public T x;
public T y;
public Point2(T x, T y) {
this.x = x;
this.y = y;
}
public boolean equals(Point2<T> point2) {
return x == point2.y && y == point2.y;
}
}

View File

@@ -1,11 +0,0 @@
package guiTree.Helper;
public class Point2d {
public int x;
public int y;
public Point2d(int x,int y) {
this.x = x;
this.y = y;
}
}

View File

@@ -0,0 +1,17 @@
package guiTree.Helper;
public class Point3<T> {
public T x;
public T y;
public T z;
public Point3(T x, T y, T z) {
this.x = x;
this.y = y;
this.z = z;
}
public boolean equals(Point3<T> point3) {
return x == point3.x && y == point3.y && z == point3.z;
}
}

View File

@@ -0,0 +1,19 @@
package guiTree.Helper;
public class Point4<T> {
public T a;
public T b;
public T c;
public T d;
public Point4(T a, T b, T c, T d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public boolean equals(Point4<T> point4) {
return a == point4.a && b == point4.b && c == point4.c && d == point4.d;
}
}

View File

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

View File

@@ -12,4 +12,8 @@ public class Timer {
now = System.currentTimeMillis();
return now - prev;
}
public long getTime() {
return System.currentTimeMillis() - prev;
}
}

View File

@@ -1,9 +0,0 @@
package guiTree.Listeners;
public enum Direction {
NORTH,
SOUTH,
WEST,
EAST,
ALL
}

View File

@@ -1,186 +0,0 @@
package guiTree.Listeners;
import guiTree.Helper.Point2d;
import guiTree.events.MouseAdapter;
import java.awt.*;
import java.awt.event.MouseEvent;
public class ResizeListener extends MouseAdapter {
public Point2d location;
public Point2d size;
public Cursor cursor;
private Boolean moving = false;
private Boolean resizing = false;
private Point2d initialLocation;
private int resizeDelta = 5;
private Boolean NORTH;
private Boolean SOUTH;
private Boolean WEST;
private Boolean EAST;
public ResizeListener(Direction[] directions, Point2d size, Point2d location) {
this.cursor = new Cursor(Cursor.DEFAULT_CURSOR);
this.size = size;
this.location = location;
NORTH = false;
SOUTH = false;
WEST = false;
EAST = false;
for(Direction dir:directions) {
if(dir == Direction.NORTH) {
NORTH = true;
}
if(dir == Direction.SOUTH) {
SOUTH = true;
}
if(dir == Direction.WEST) {
WEST = true;
}
if(dir == Direction.EAST) {
EAST = true;
}
if(dir == Direction.ALL) {
NORTH = true;
SOUTH = true;
WEST = true;
EAST = true;
}
}
}
public void setLocation(int x, int y) {
location.x = x;
location.y = y;
}
public void setSize(int x, int y) {
size.x = x;
size.y = y;
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
this.cursor = new Cursor(Cursor.DEFAULT_CURSOR);
}
@Override
public void mouseDragged(MouseEvent mouseEvent) {
if(moving) {
setLocation(mouseEvent.getXOnScreen() - initialLocation.x, mouseEvent.getYOnScreen() - initialLocation.y);
}
else if(!resizing){
this.resizing = true;
this.resize(mouseEvent);
}
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
if(cursor.getType() != Cursor.DEFAULT_CURSOR){
this.moving = false;
}
else {
this.moving = true;
this.resizing = false;
}
initialLocation = new Point2d(mouseEvent.getX(), mouseEvent.getY());
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
moving = false;
}
@Override
public void mouseMoved(MouseEvent mouseEvent) {
if(mouseEvent.getX() < resizeDelta || mouseEvent.getX() > size.x - resizeDelta ||
mouseEvent.getY() < resizeDelta || mouseEvent.getY() > size.y - resizeDelta) {
this.setResizeCursor(mouseEvent);
}
else {
cursor = new Cursor(Cursor.DEFAULT_CURSOR);
}
}
private void setResizeCursor(MouseEvent e){
if(e.getX() <= resizeDelta) {
if(e.getY() <= resizeDelta && (NORTH && WEST)) {
cursor = new Cursor(Cursor.NW_RESIZE_CURSOR);
}
else if(e.getY() >= size.y - resizeDelta && (SOUTH && WEST)){
cursor = new Cursor(Cursor.SW_RESIZE_CURSOR);
}
else if(WEST){
cursor = new Cursor(Cursor.W_RESIZE_CURSOR);
}
}
else if(e.getX() >= size.x - resizeDelta){
if(e.getY() <= resizeDelta && (NORTH && EAST)){
cursor = new Cursor(Cursor.NE_RESIZE_CURSOR);
}
else if(e.getY() >= size.y - resizeDelta && (SOUTH && EAST)){
cursor = new Cursor(Cursor.SE_RESIZE_CURSOR);
}
else if(EAST){
cursor = new Cursor(Cursor.E_RESIZE_CURSOR);
}
}
else{
if(e.getY() <= resizeDelta && (NORTH)){
cursor = new Cursor(Cursor.N_RESIZE_CURSOR);
}
else if(e.getY() >= size.y - resizeDelta && (SOUTH)){
cursor = new Cursor(Cursor.S_RESIZE_CURSOR);
}
}
}
private void resize(MouseEvent e) {
switch (cursor.getType()) {
case Cursor.N_RESIZE_CURSOR:
setSize(size.x, size.y + initialLocation.y - e.getYOnScreen());
setLocation(location.x, e.getYOnScreen());
initialLocation.y = e.getYOnScreen();
break;
case Cursor.NE_RESIZE_CURSOR:
setSize(size.x + e.getXOnScreen() - initialLocation.x, size.y + initialLocation.y - e.getYOnScreen());
setLocation(location.x, e.getYOnScreen());
initialLocation.x = e.getXOnScreen();
initialLocation.y = e.getYOnScreen();
break;
case Cursor.NW_RESIZE_CURSOR:
setSize(size.x + initialLocation.x - e.getXOnScreen(), size.y + initialLocation.y - e.getYOnScreen());
setLocation(e.getXOnScreen(), e.getYOnScreen());
initialLocation.x = e.getXOnScreen();
initialLocation.y = e.getYOnScreen();
break;
case Cursor.E_RESIZE_CURSOR:
setSize(size.x + e.getXOnScreen() - initialLocation.x, size.y);
initialLocation.x = e.getXOnScreen();
break;
case Cursor.W_RESIZE_CURSOR:
setSize(size.x + initialLocation.x - e.getXOnScreen(), size.y);
setLocation(e.getXOnScreen(), location.y);
initialLocation.x = e.getXOnScreen();
break;
case Cursor.SE_RESIZE_CURSOR:
setSize(size.x + e.getXOnScreen() - initialLocation.x, size.y + e.getYOnScreen() - initialLocation.y);
initialLocation.x = e.getXOnScreen();
initialLocation.y = e.getYOnScreen();
break;
case Cursor.S_RESIZE_CURSOR:
setSize(size.x, size.y + e.getYOnScreen() - initialLocation.y);
initialLocation.y = e.getYOnScreen();
break;
case Cursor.SW_RESIZE_CURSOR:
setSize(size.x + initialLocation.x - e.getXOnScreen(), size.y + e.getYOnScreen() - initialLocation.y);
setLocation(e.getXOnScreen(), location.y);
initialLocation.x = e.getXOnScreen();
initialLocation.y = e.getYOnScreen();
break;
}
this.resizing = false;
}
}

View File

@@ -1,7 +1,8 @@
package guiTree;
import guiTree.Animations.AnimationInterface;
import guiTree.Helper.Debugger;
import guiTree.Helper.Tag;
import guiTree.Helper.Point2;
import guiTree.Helper.Timer;
import guiTree.events.KeyListener;
import guiTree.events.MouseListener;
@@ -21,6 +22,7 @@ public class Visual {
public static final int SIZE_CHANGED = 1;
public static final int LOCATION_CHANGED = 2;
private static List<AnimationInterface> animations = new ArrayList<>();
/*--------------------------------------------------------------------
Tree Elements
@@ -56,12 +58,11 @@ public class Visual {
private Color fontColor;
private Color borderColor;
private Boolean active;
public Boolean dirty;
private Boolean dirty;
private static Visual entered;
private Boolean focused;
private Boolean pressed;
/*--------------------------------------------------------------------
Constructors
---------------------------------------------------------------------*/
@@ -174,11 +175,11 @@ public class Visual {
}
public void setLocationX(Integer x) {
this.locationX = x;
setLocation(x, getLocationY());
}
public void setLocationY(Integer y) {
this.locationY = y;
setLocation(getLocationX(), y);
}
public void setFont(Font font) {
@@ -209,6 +210,7 @@ public class Visual {
public void setHasBorder(Boolean hasBorder) {
this.hasBorder = hasBorder;
propagateDirt();
}
/*--------------------------------------------------------------------
@@ -235,6 +237,10 @@ public class Visual {
return this.locationY;
}
public Point2<Integer> getLocation() {
return new Point2<>(locationX, locationY);
}
public Font getFont() {
return font;
}
@@ -316,35 +322,52 @@ public class Visual {
}
}
public void addAnimation(AnimationInterface animation) {
animations.add(animation);
}
public void removeAnimation(AnimationInterface animation) {
animations.remove(animation);
}
public void repaint() {
Debugger.log("Called repaint from " + name, Debugger.Tag.PAINTING);
for(int i = 0; i < animations.size(); i++) {
if(animations.get(i).step()) {
animations.remove(animations.get(i));
i--;
}
}
if(dirty && active) {
this.revalidate();
revalidate();
}
}
private void revalidate() {
Timer timer = new Timer();
Debugger.log("Revalidating " + name, Tag.PAINTING);
Debugger.log("Revalidating " + name, Debugger.Tag.PAINTING);
timer.startTiming();
clearImageBuffer();
this.paint(imageBuffer);
for (Visual v : children) {
v.repaint();
this.imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
if(v.dirty && v.active) {
v.revalidate();
}
imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
}
this.dirty = false;
dirty = false;
if(!(this instanceof Window)){
this.parent.revalidate();
long time = timer.stopTiming();
Debugger.log("Finished Revalidating " + name + ": " + time, Tag.PAINTING);
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
parent.revalidate();
return;
}
Window window = (Window)this;
window.setFrameImageBuffer(imageBuffer);
long time = timer.stopTiming();
Debugger.log("Finished Revalidating " + name + ": " + time, Tag.PAINTING);
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
window.revalidate();
}
@@ -387,17 +410,15 @@ public class Visual {
for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mouseClicked(mouseEvent);
}
entered.propagateDirt();
entered.focused = true;
Debugger.log("Clicked " + entered.name, Tag.LISTENER);
Debugger.log("Clicked " + entered.name, Debugger.Tag.LISTENER);
}
void mouseReleased(MouseEvent mouseEvent) {
for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mouseReleased(mouseEvent);
}
Debugger.log("Released " + entered.name, Tag.LISTENER);
propagateDirt();
Debugger.log("Released " + entered.name, Debugger.Tag.LISTENER);
entered.pressed = false;
}
@@ -405,9 +426,8 @@ public class Visual {
for(MouseListener mouseListener: entered.mouseListeners) {
mouseListener.mousePressed(mouseEvent);
}
entered.propagateDirt();
entered.pressed = true;
Debugger.log("Pressed " + entered.name, Tag.LISTENER);
Debugger.log("Pressed " + entered.name, Debugger.Tag.LISTENER);
}
void mouseEntered(MouseEvent mouseEvent) {
@@ -429,8 +449,7 @@ public class Visual {
for(MouseListener mouseListener: mouseListeners) {
mouseListener.mouseEntered(mouseEvent);
}
Debugger.log("Entered " + entered.name, Tag.LISTENER);
propagateDirt();
Debugger.log("Entered " + entered.name, Debugger.Tag.LISTENER);
}
void mouseExited(MouseEvent mouseEvent) {
@@ -443,8 +462,7 @@ public class Visual {
for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseExited(mouseEvent);
}
Debugger.log("Exited " + entered.name, Tag.LISTENER);
entered.propagateDirt();
Debugger.log("Exited " + entered.name, Debugger.Tag.LISTENER);
entered = null;
}
@@ -452,8 +470,7 @@ public class Visual {
for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseDragged(mouseEvent);
}
entered.propagateDirt();
Debugger.log("Dragged " + entered.name, Tag.LISTENER);
Debugger.log("Dragged " + entered.name, Debugger.Tag.LISTENER);
}
void mouseMoved(MouseEvent mouseEvent) {
@@ -467,7 +484,7 @@ public class Visual {
for (MouseListener mouseListener : entered.mouseListeners) {
mouseListener.mouseExited(mouseEvent);
}
Debugger.log("Exited " + entered.name, Tag.LISTENER);
Debugger.log("Exited " + entered.name, Debugger.Tag.LISTENER);
entered = this;
}
}
@@ -491,8 +508,7 @@ public class Visual {
mouseListener.mouseMoved(mouseEvent);
}
}
Debugger.log("Moved " + this.name, Tag.LISTENER);
propagateDirt();
Debugger.log("Moved " + this.name, Debugger.Tag.LISTENER);
}
void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
@@ -501,7 +517,7 @@ public class Visual {
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
}
}
Debugger.log("Wheel Moved " + this.name, Tag.LISTENER);
Debugger.log("Wheel Moved " + this.name, Debugger.Tag.LISTENER);
}
/*--------------------------------------------------------------------
@@ -524,9 +540,7 @@ public class Visual {
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, getWidth(), getHeight());
g.setComposite(AlphaComposite.Src);
g.fillRect(0, 0, width, height);
g.dispose();
}

View File

@@ -2,10 +2,13 @@ package guiTree;
import guiTree.Components.TitleBar;
import guiTree.Helper.Debugger;
import guiTree.Helper.Point2d;
import guiTree.Helper.Tag;
import guiTree.Helper.Point2;
import guiTree.Helper.Timer;
import guiTree.events.KeyListener;
import guiTree.events.MouseAdapter;
import guiTree.Components.Panel;
import guiTree.events.MouseListener;
import guiTree.events.MouseWheelListener;
import javax.imageio.ImageIO;
import java.awt.*;
@@ -16,13 +19,14 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Window extends Visual {
public class Window extends Visual implements Runnable{
public CustomFrame frame;
private TitleBar titleBar;
private Panel mainPanel;
private Panel contentPanel;
private Point2d oldSize;
private Point2d oldLocation;
private Point2<Integer> oldSize;
private Boolean close;
private Point2<Integer> oldLocation;
public Window() {
this("");
@@ -50,6 +54,7 @@ public class Window extends Visual {
bar.setName("TitleBar");
bar.setBackgroundColor(Color.GRAY);
this.setTitleBar(bar);
close = false;
}
@Override
@@ -64,7 +69,7 @@ public class Window extends Visual {
else {
contentPanel.setSize(width, height);
}
Debugger.log("Calling repaint from window set size: ", Tag.PAINTING);
Debugger.log("Calling repaint from window set size: ", Debugger.Tag.PAINTING);
repaint();
}
@@ -74,7 +79,7 @@ public class Window extends Visual {
}
public void revalidate() {
Debugger.log("Finished painting", Tag.PAINTING);
Debugger.log("Finished painting", Debugger.Tag.PAINTING);
this.frame.repaint();
}
@@ -192,6 +197,7 @@ public class Window extends Visual {
switch(notify) {
case TitleBar.CLOSE: {
dispose();
close = true;
break;
}
case TitleBar.MINIMIZE: {
@@ -200,8 +206,8 @@ public class Window extends Visual {
}
case TitleBar.MAXIMIZE: {
Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
oldSize = new Point2d(getWidth(), getHeight());
oldLocation = new Point2d(frame.getX(), frame.getY());
oldSize = new Point2<>(getWidth(), getHeight());
oldLocation = new Point2<>(frame.getX(), frame.getY());
this.setSize(screenBounds.width, screenBounds.height);
this.setLocation(screenBounds.x, screenBounds.y);
setState(Frame.MAXIMIZED_BOTH);
@@ -216,8 +222,44 @@ public class Window extends Visual {
}
}
@Override
public void addMouseListener(MouseListener mouseListener) {
contentPanel.addMouseListener(mouseListener);
}
@Override
public void addKeyListener(KeyListener keyListener) {
contentPanel.addKeyListener(keyListener);
}
@Override
public void addMouseWheelListener(MouseWheelListener mouseWheelListener) {
contentPanel.addMouseWheelListener(mouseWheelListener);
}
@Override
public void addVisual(Visual v) {
contentPanel.addVisual(v);
}
@Override
public void run() {
Timer frameTimer = new Timer();
Timer secondTimer = new Timer();
int frames = 0;
frameTimer.startTiming();
secondTimer.startTiming();
while(!close) {
if(frameTimer.getTime() >= 1000/60) {
repaint();
frameTimer.startTiming();
frames ++;
}
if(secondTimer.getTime() >= 1000) {
Debugger.log("Frames per second: " + frames, Debugger.Tag.FPS);
frames = 0;
secondTimer.startTiming();
}
}
}
}

View File

@@ -2,6 +2,7 @@ package parser;
import com.sun.jdi.InvalidTypeException;
import converters.Converter;
import guiTree.Helper.Debugger;
import guiTree.Visual;
import guiTree.Window;
import org.w3c.dom.*;
@@ -24,6 +25,7 @@ public class XAMLParser {
String methodName = "set";
methodName = methodName.concat(attribute.getNodeName());
List<Object> parameterList = convertStringToPrimitives(object, attribute.getNodeValue(), methodName);
Debugger.log("Calling " + methodName + " " + attribute.getNodeValue(), Debugger.Tag.PARSING);
if(parameterList == null) {
break;
}
@@ -54,6 +56,7 @@ public class XAMLParser {
public static Window parse(String filepath) throws Exception {
Object rootObject;
Debugger.log("Started", Debugger.Tag.PARSING);
FileInputStream fileIS = new FileInputStream(new File("resources/" + filepath));
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
@@ -62,11 +65,15 @@ public class XAMLParser {
xmlDocument.normalize();
Element rootNode = xmlDocument.getDocumentElement();
Debugger.log("Root element:" + rootNode.toString(), Debugger.Tag.PARSING);
rootObject = parseNode(rootNode);
if(rootObject instanceof Window) {
((Window) rootObject).repaint();
Thread windowThread = new Thread((Window) rootObject);
windowThread.setName("Painting Thread");
windowThread.start();
return (Window) rootObject;
}
return null;
@@ -76,13 +83,15 @@ public class XAMLParser {
List<Object> primitiveAttributes = new ArrayList<>();
List<String> values = new ArrayList<>();
// value = value.replaceAll(" ", "");
while (value.contains(",")) {
values.add(value.substring(0, value.indexOf(',')));
value = value.substring(value.indexOf(',') + 1);
}
values.add(value);
List<Method> methods = getMethodsFromName(object, methodName);
if(methods.size() == 0) {
System.out.println("Could not find method " + methodName);
}
for(Method method: methods){
Class<?>[] types = method.getParameterTypes();
for(int i = 0; i < types.length; i++){
@@ -97,6 +106,7 @@ public class XAMLParser {
return primitiveAttributes;
}
}
System.err.println("Could not find method " + methodName + " with parameters " + values);
return null;
}
@@ -108,7 +118,9 @@ public class XAMLParser {
catch (ClassNotFoundException e) {
parentClass = Class.forName(packageGuiTree.concat(parentNode.getNodeName()));
}
Debugger.log("Parsing " + parentClass, Debugger.Tag.PARSING);
Object parentObject = parentClass.getDeclaredConstructor().newInstance();
Debugger.log("Constructor called succesfuly for " + parentObject, Debugger.Tag.PARSING);
setAttributes(parentObject, parentNode.getAttributes());
@@ -122,6 +134,7 @@ public class XAMLParser {
Object childObject = parseNode(childNode);
if(parentObject instanceof Visual && childObject instanceof Visual) {
Debugger.log("Adding " + childObject + " to " + parentObject, Debugger.Tag.PARSING);
addVisual((Visual) parentObject, (Visual) childObject);
}
}