added merge tu grid Panel

moved borders to external components
added text field for one line with select
This commit is contained in:
Macocian Adrian Radu
2020-04-27 17:32:34 +03:00
parent 2e4d83085a
commit 202610764b
29 changed files with 546 additions and 187 deletions

View File

@@ -1,7 +1,7 @@
package parser;
import com.sun.jdi.InvalidTypeException;
import converters.Converter;
import parser.converters.Converter;
import guiTree.Helper.Debugger;
import guiTree.Visual;
import guiTree.Window;
@@ -24,7 +24,18 @@ public class XAMLParser {
Node attribute = attributeList.item(i);
String methodName = "set";
methodName = methodName.concat(attribute.getNodeName());
List<Object> parameterList = convertStringToPrimitives(object, attribute.getNodeValue(), methodName);
List<Method> methods = getMethodsFromName(object, methodName);
String value = attribute.getNodeValue();
if(methods.size() == 0) {
String firstAttribute = methodName.substring(3).toLowerCase();
methodName = "setAttribute";
methods = getMethodsFromName(object, methodName);
value = firstAttribute.concat(",").concat(value);
}
List<Object> parameterList = convertStringToPrimitives(value, methods);
Debugger.log("Calling " + methodName + " " + attribute.getNodeValue(), Debugger.Tag.PARSING);
if(parameterList == null) {
break;
@@ -75,7 +86,7 @@ public class XAMLParser {
return null;
}
private static List<Object> convertStringToPrimitives(Object object, String value, String methodName){
private static List<Object> convertStringToPrimitives(String value, List<Method> methods){
List<Object> primitiveAttributes = new ArrayList<>();
List<String> values = new ArrayList<>();
@@ -84,10 +95,7 @@ public class XAMLParser {
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();
if(types.length == values.size()) {
@@ -104,7 +112,7 @@ public class XAMLParser {
}
}
}
System.err.println("Could not find method " + methodName + " with parameters " + values);
System.err.println("Could not find method " + methods.get(0).getName() + " with parameters " + values);
return null;
}

View File

@@ -0,0 +1,10 @@
package parser.converters;
public class BooleanConverter implements ConverterInterface<Boolean> {
@Override
public Boolean convert(String content) {
content = content.replaceAll(" ", "");
return Boolean.valueOf(content);
}
}

View File

@@ -0,0 +1,11 @@
package parser.converters;
import java.awt.*;
public class ColorConverter implements ConverterInterface<Color> {
@Override
public Color convert(String content) {
content = content.replaceAll(" ", "");
return Color.decode(content);
}
}

View File

@@ -0,0 +1,33 @@
package parser.converters;
import com.sun.jdi.InvalidTypeException;
import guiTree.Components.Slider;
import java.awt.*;
import java.util.HashMap;
public class Converter {
private HashMap<Class<?>, 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());
this.converterTable.put(Slider.Direction.class, new DirectionConverter());
}
public Object objectCreatorFactory (Class<?> type, String content) throws InvalidTypeException {
if(this.converterTable.containsKey(type)) {
return this.converterTable.get(type).convert(content);
}
throw new InvalidTypeException();
}
}

View File

@@ -0,0 +1,7 @@
package parser.converters;
import com.sun.jdi.InvalidTypeException;
public interface ConverterInterface<T> {
T convert(String content) throws InvalidTypeException;
}

View File

@@ -0,0 +1,18 @@
package parser.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,10 @@
package parser.converters;
public class DoubleConverter implements ConverterInterface<Double>{
@Override
public Double convert(String content) {
content = content.replaceAll(" ", "");
return Double.parseDouble(content);
}
}

View File

@@ -0,0 +1,18 @@
package parser.converters;
import com.sun.jdi.InvalidTypeException;
public class FloatConverter implements ConverterInterface<Float> {
@Override
public Float convert(String content) throws InvalidTypeException {
content = content.replaceAll(" ", "");
if(content.toLowerCase().charAt(content.length() - 1) != 'f') {
throw new InvalidTypeException();
}
content = content.substring(0, content.length() - 1);
return Float.parseFloat(content);
}
}

View File

@@ -0,0 +1,10 @@
package parser.converters;
public class IntegerConverter implements ConverterInterface<Integer> {
@Override
public Integer convert(String content) {
content = content.replaceAll(" ", "");
return Integer.parseInt(content);
}
}

View File

@@ -0,0 +1,9 @@
package parser.converters;
public class StringConverter implements ConverterInterface<String> {
@Override
public String convert(String content) {
return content;
}
}