diff --git a/AWT startup.iml b/AWT startup.iml
index c90834f..8433b9d 100644
--- a/AWT startup.iml
+++ b/AWT startup.iml
@@ -4,6 +4,7 @@
+
diff --git a/resources/company.xml b/resources/company.xml
new file mode 100644
index 0000000..db75c38
--- /dev/null
+++ b/resources/company.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index 406768d..09fb9ad 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,38 +1,22 @@
+import guiTree.Window;
+import parser.XAMLParser;
+
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Main {
public static void main(String[] args) {
- Window win = new Window();
- win.setVisible(true);
- win.setSize(640, 480);
- win.setPositionRelativeTo(null);
- win.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- win.dispose();
- }
- });
-
- Button button = new Button();
- win.addVisual(button);
- int x = 20;
- int y = 20;
- while(true){
- if(x > win.getWidth()){
- x = 0;
- y+=20;
- }
- if(y > win.getHeight()){
- y = 0;
- }
- button.setLocation(x, y);
- x+=10;
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ try{
+ Window window = XAMLParser.parse("company.xml");
+ assert window != null;
+ window.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ window.dispose();
+ }
+ });
+ }catch (Exception e){
+ e.printStackTrace();
}
}
}
diff --git a/src/converters/BooleanConverter.java b/src/converters/BooleanConverter.java
new file mode 100644
index 0000000..dabd8fe
--- /dev/null
+++ b/src/converters/BooleanConverter.java
@@ -0,0 +1,9 @@
+package converters;
+
+public class BooleanConverter implements ConverterInterface {
+
+ @Override
+ public Boolean convert(String content) {
+ return Boolean.valueOf(content);
+ }
+}
diff --git a/src/converters/ColorConverter.java b/src/converters/ColorConverter.java
new file mode 100644
index 0000000..71a7f7c
--- /dev/null
+++ b/src/converters/ColorConverter.java
@@ -0,0 +1,10 @@
+package converters;
+
+import java.awt.*;
+
+public class ColorConverter implements ConverterInterface {
+ @Override
+ public Color convert(String content) {
+ return Color.decode(content);
+ }
+}
diff --git a/src/converters/Converter.java b/src/converters/Converter.java
new file mode 100644
index 0000000..9a1fe1b
--- /dev/null
+++ b/src/converters/Converter.java
@@ -0,0 +1,31 @@
+package converters;
+
+import com.sun.jdi.InvalidTypeException;
+
+import java.awt.*;
+import java.util.HashMap;
+
+public class Converter {
+ private HashMap, ConverterInterface>> converterTable;
+
+ public Converter(){
+ this.converterTable = new HashMap<>();
+ this.converterTable.put(Integer.class, new IntegerConverter());
+ this.converterTable.put(Float.class, new FloatConverter());
+ this.converterTable.put(Double.class, new DoubleConverter());
+ this.converterTable.put(String.class, new StringConverter());
+ this.converterTable.put(Boolean.class, new BooleanConverter());
+ this.converterTable.put(Integer.TYPE, new IntegerConverter());
+ this.converterTable.put(Float.TYPE, new FloatConverter());
+ this.converterTable.put(Double.TYPE, new DoubleConverter());
+ this.converterTable.put(Boolean.TYPE, new BooleanConverter());
+ this.converterTable.put(Color.class, new ColorConverter());
+ }
+
+ public Object objectCreatorFactory (Class> type, String content) throws InvalidTypeException {
+ if(this.converterTable.containsKey(type)) {
+ return this.converterTable.get(type).convert(content);
+ }
+ throw new InvalidTypeException();
+ }
+}
diff --git a/src/converters/ConverterInterface.java b/src/converters/ConverterInterface.java
new file mode 100644
index 0000000..6a942d7
--- /dev/null
+++ b/src/converters/ConverterInterface.java
@@ -0,0 +1,5 @@
+package converters;
+
+public interface ConverterInterface {
+ T convert(String content);
+}
diff --git a/src/converters/DoubleConverter.java b/src/converters/DoubleConverter.java
new file mode 100644
index 0000000..c91d8dc
--- /dev/null
+++ b/src/converters/DoubleConverter.java
@@ -0,0 +1,9 @@
+package converters;
+
+public class DoubleConverter implements ConverterInterface{
+
+ @Override
+ public Double convert(String content) {
+ return Double.parseDouble(content);
+ }
+}
diff --git a/src/converters/FloatConverter.java b/src/converters/FloatConverter.java
new file mode 100644
index 0000000..e3fc97d
--- /dev/null
+++ b/src/converters/FloatConverter.java
@@ -0,0 +1,9 @@
+package converters;
+
+public class FloatConverter implements ConverterInterface {
+
+ @Override
+ public Float convert(String content) {
+ return Float.parseFloat(content);
+ }
+}
diff --git a/src/converters/IntegerConverter.java b/src/converters/IntegerConverter.java
new file mode 100644
index 0000000..fddefbb
--- /dev/null
+++ b/src/converters/IntegerConverter.java
@@ -0,0 +1,9 @@
+package converters;
+
+public class IntegerConverter implements ConverterInterface {
+
+ @Override
+ public Integer convert(String content) {
+ return Integer.parseInt(content);
+ }
+}
diff --git a/src/converters/StringConverter.java b/src/converters/StringConverter.java
new file mode 100644
index 0000000..66a259b
--- /dev/null
+++ b/src/converters/StringConverter.java
@@ -0,0 +1,9 @@
+package converters;
+
+public class StringConverter implements ConverterInterface {
+
+ @Override
+ public String convert(String content) {
+ return content;
+ }
+}
diff --git a/src/Button.java b/src/guiTree/Button.java
similarity index 78%
rename from src/Button.java
rename to src/guiTree/Button.java
index 0d9ea49..434d763 100644
--- a/src/Button.java
+++ b/src/guiTree/Button.java
@@ -1,3 +1,7 @@
+package guiTree;
+
+import guiTree.Visual;
+
import java.awt.*;
import java.awt.image.BufferedImage;
@@ -12,7 +16,7 @@ public class Button extends Visual {
public void paint(BufferedImage imageBuffer)
{
Graphics g = imageBuffer.getGraphics();
- g.setColor(Color.BLUE);
+ g.setColor(this.getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
}
}
diff --git a/src/CustomFrame.java b/src/guiTree/CustomFrame.java
similarity index 96%
rename from src/CustomFrame.java
rename to src/guiTree/CustomFrame.java
index 6a6bfb5..15d1a74 100644
--- a/src/CustomFrame.java
+++ b/src/guiTree/CustomFrame.java
@@ -1,3 +1,5 @@
+package guiTree;
+
import java.awt.*;
import java.awt.image.BufferedImage;
diff --git a/src/Visual.java b/src/guiTree/Visual.java
similarity index 85%
rename from src/Visual.java
rename to src/guiTree/Visual.java
index 5fac94b..0a1fa53 100644
--- a/src/Visual.java
+++ b/src/guiTree/Visual.java
@@ -1,3 +1,5 @@
+package guiTree;
+
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
@@ -16,13 +18,14 @@ public class Visual {
/*--------------------------------------------------------------------
Attributes
---------------------------------------------------------------------*/
- private int width;
- private int height;
- private int locationX;
- private int locationY;
+ private String name;
+ private Integer width;
+ private Integer height;
+ private Integer locationX;
+ private Integer locationY;
private Color backgroundColor;
private Color foregroundColor;
- private Boolean valid;
+ private Boolean active;
/*--------------------------------------------------------------------
@@ -33,13 +36,23 @@ public class Visual {
this.parent = null;
this.backgroundColor = Color.WHITE;
this.foregroundColor = Color.BLACK;
- valid = false;
+
+ this.active = this instanceof Window;
}
/*--------------------------------------------------------------------
Attributes Methods
---------------------------------------------------------------------*/
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
public int getWidth()
{
return this.width;
@@ -50,13 +63,12 @@ public class Visual {
return this.height;
}
- public void setSize(int width, int height){
+ public void setSize(Integer width, Integer height){
this.width = width;
this.height = height;
initializeImageBuffer(width, height);
- this.valid = false;
this.revalidate();
}
@@ -68,10 +80,9 @@ public class Visual {
return this.locationY;
}
- public void setLocation(int x, int y){
+ public void setLocation(Integer x, Integer y){
this.locationX = x;
this.locationY = y;
- this.valid = false;
this.revalidate();
}
@@ -81,7 +92,6 @@ public class Visual {
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
- this.valid = false;
this.revalidate();
}
@@ -91,7 +101,6 @@ public class Visual {
public void setForegroundColor(Color foregroundColor) {
this.foregroundColor = foregroundColor;
- this.valid = false;
this.revalidate();
}
@@ -101,8 +110,8 @@ public class Visual {
}
private void calculateInitialLocation(){
- this.locationX = 200;
- this.locationY = 200;
+ this.locationX = 20;
+ this.locationY = 50;
}
@@ -116,9 +125,9 @@ public class Visual {
child.calculateInitialLocation();
child.calculateInitialSize();
child.imageBuffer = new BufferedImage(child.getWidth(), child.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
- child.valid = false;
- this.revalidate();
+ child.active = true;
+ child.revalidate();
}
private void setParent(Visual parent)
@@ -142,16 +151,14 @@ public class Visual {
}
public void revalidate() {
+ if(!this.active){
+ return;
+ }
initializeImageBuffer(width, height);
this.paint(imageBuffer);
for(Visual v:children){
- if(!v.valid){
- v.paint(v.imageBuffer);
- }
this.imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
- v.valid = true;
}
- this.valid = true;
if(!(this instanceof Window)){
this.parent.revalidate();
}
@@ -169,7 +176,7 @@ public class Visual {
Helper Methods
---------------------------------------------------------------------*/
- private void initializeImageBuffer(int width, int height){
+ private void initializeImageBuffer(Integer width, Integer height){
this.imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
this.imageBuffer.getGraphics().setColor(backgroundColor);
this.imageBuffer.getGraphics().fillRect(0, 0, width, height);
diff --git a/src/Window.java b/src/guiTree/Window.java
similarity index 85%
rename from src/Window.java
rename to src/guiTree/Window.java
index fba4f0e..a4e2ddf 100644
--- a/src/Window.java
+++ b/src/guiTree/Window.java
@@ -1,3 +1,7 @@
+package guiTree;
+
+import guiTree.Visual;
+
import java.awt.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
@@ -17,7 +21,7 @@ public class Window extends Visual {
}
@Override
- public void setSize(int width, int height)
+ public void setSize(Integer width, Integer height)
{
this.frame.setSize(width, height);
super.setSize(width, height);
@@ -26,6 +30,7 @@ public class Window extends Visual {
public void setFrameImageBuffer(BufferedImage imageBuffer){
this.frame.setImageBuffer(imageBuffer);
+ this.frame.repaint();
}
public void setSize(Dimension dimension) {
@@ -55,4 +60,8 @@ public class Window extends Visual {
public void setPositionRelativeTo(Component c){
frame.setLocationRelativeTo(c);
}
+
+ public void setPositionRelativeTo(){
+ frame.setLocationRelativeTo(null);
+ }
}
diff --git a/src/parser/XAMLParser.java b/src/parser/XAMLParser.java
new file mode 100644
index 0000000..2b5a9b9
--- /dev/null
+++ b/src/parser/XAMLParser.java
@@ -0,0 +1,141 @@
+package parser;
+
+import com.sun.jdi.InvalidTypeException;
+import converters.Converter;
+import guiTree.Visual;
+import guiTree.Window;
+import org.w3c.dom.*;
+
+import javax.xml.parsers.*;
+import java.io.*;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+public class XAMLParser {
+ private final static String packageName = "guiTree.";
+ private static Converter valueConverter = new Converter();
+
+ private static void setAttributes(Object object, NamedNodeMap attributeList){
+ for(int i = 0; i < attributeList.getLength(); i++){
+ Node attribute = attributeList.item(i);
+ String methodName = "set";
+ methodName = methodName.concat(attribute.getNodeName());
+ List