import {JRBaseFactory} from "./JRBaseFactory"; import {LineShape} from "../../items/LineShape"; import {SchemaConstants} from "../SchemaConstants"; import {LineDirection, LineStyleEnum} from "../../configs/enums"; import {GraphicItem} from "../../items/GraphicItem"; import EllipseItem from "../../items/EllipseItem"; import RectangleItem from "../../items/RectangleItem"; import {Unit} from "../../drawing/Unit"; export abstract class JRGraphicFactory extends JRBaseFactory { setAttrs(element: GraphicItem, atts: {}) { const lineColor = atts[SchemaConstants.ATTRIBUTE_lineColor]; if (lineColor) { element.lineColor = lineColor; } const lineStyle = atts[SchemaConstants.ATTRIBUTE_lineStyle]; if (lineStyle) { element.lineStyle = (LineStyleEnum[lineStyle]); } const lineWidth = atts[SchemaConstants.ATTRIBUTE_lineWidth]; if (lineWidth) { element.style.strokeWidth = Unit.pixel(lineWidth); } } } export class JRLineFactory extends JRGraphicFactory { createObject(atts: {}): any { const element = new LineShape(); const direction = atts[SchemaConstants.ATTRIBUTE_direction]; if (direction) { element.direction = (LineDirection[direction]); } this.setAttrs(element, atts); return element; } } export class JRRectFactory extends JRGraphicFactory { createObject(atts: {}): any { const element = new RectangleItem(); const fill = atts[SchemaConstants.ATTRIBUTE_fill]; if (fill) { element.fill = fill; } this.setAttrs(element, atts); return element; } } export class JREllipseFactory extends JRGraphicFactory { createObject(atts: {}): any { const element = new EllipseItem(); const fill = atts[SchemaConstants.ATTRIBUTE_fill]; if (fill) { element.fill = fill; } this.setAttrs(element, atts); return element; } }