use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.
the class ChartComponentMapper method tagToComponent.
@Override
public Component tagToComponent(String tagName, Design.ComponentFactory componentFactory, DesignContext context) {
boolean isChartTag = Pattern.matches("^vaadin-.*-chart$", tagName);
if (isChartTag) {
String[] split = tagName.split("-");
if (split.length != 3) {
throw new DesignException("Unknown tag: " + tagName);
}
String typeName = split[1];
ChartType chartType = resolveChartTypeFor(typeName);
if (chartType == null) {
throw new DesignException("Unknown tag: " + tagName);
}
return new Chart(chartType);
}
return super.tagToComponent(tagName, componentFactory, context);
}
use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.
the class ColorFactory method createGradientColor.
private static GradientColor createGradientColor(Element element) {
Elements linearGradients = element.getElementsByTag("linear-gradient");
Elements radialGradients = element.getElementsByTag("radial-gradient");
if (!linearGradients.isEmpty() && radialGradients.isEmpty()) {
Element linearGradient = linearGradients.first();
double x1 = parseDoubleAttribute(linearGradient, "x1");
double y1 = parseDoubleAttribute(linearGradient, "y1");
double x2 = parseDoubleAttribute(linearGradient, "x2");
double y2 = parseDoubleAttribute(linearGradient, "y2");
return GradientColor.createLinear(x1, y1, x2, y2);
}
if (!radialGradients.isEmpty() && linearGradients.isEmpty()) {
Element radialGradient = radialGradients.first();
double cx = parseDoubleAttribute(radialGradient, "cx");
double cy = parseDoubleAttribute(radialGradient, "cy");
double r = parseDoubleAttribute(radialGradient, "r");
return GradientColor.createRadial(cx, cy, r);
}
throw new DesignException("Cannot create color for element: " + element.nodeName());
}
use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.
the class ColorFactory method addStops.
private static void addStops(GradientColor gradientColor, Element element) {
Elements stops = element.getElementsByTag("stops");
for (Element stop : stops) {
double position = parseDoubleAttribute(stop, "position");
String color = stop.attr("color");
if (color == null || "".equals(color)) {
throw new DesignException("No color defined in stops: " + stop);
}
gradientColor.addColorStop(position, new SolidColor(color));
}
}
use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.
the class ChartDesignReader method setValueToParent.
private static void setValueToParent(AbstractConfigurationObject parent, Element element, Object value) {
String propertyName = resolvePropertyName(element);
Method setter = cache.get(parent.getClass()).getSetter(propertyName);
if (setter == null) {
throw new DesignException("Could not find setter for " + propertyName + " in class " + parent.getClass());
}
try {
setter.invoke(parent, value);
} catch (Exception e) {
throw new DesignException("Could not set value type " + value.getClass() + " to class " + parent.getClass(), e);
}
}
use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.
the class ChartDesignReader method createPlotOptionsFor.
private static AbstractPlotOptions createPlotOptionsFor(String type) {
String plotOptionsClassName = "com.vaadin.addon.charts.model.PlotOptions" + toClassName(type);
try {
Class<?> plotOptionsClass = Class.forName(plotOptionsClassName);
Object plotOptions = plotOptionsClass.newInstance();
return (AbstractPlotOptions) plotOptions;
} catch (ClassNotFoundException e) {
throw new DesignException("Cannot find plot options class: " + plotOptionsClassName);
} catch (InstantiationException e) {
throw new DesignException("Cannot create options class: " + plotOptionsClassName);
} catch (IllegalAccessException e) {
throw new DesignException("Cannot create options class: " + plotOptionsClassName);
}
}
Aggregations