import {ReportItemBase} from "./ReportItemBase"; import {RectF, RectUnit, PointUnit, SizeUnit, Unit, UnitType} from "../drawing/Unit"; import {transaction} from "mobx/lib/mobx"; import {PROPERTY_KEY} from "./constants"; import {Style} from "../drawing/Style"; import {properties} from "./decorates"; import {CommonProperty, PrintProperty} from "./properties/define"; import {JRElement} from "../jasper/JRElement"; import {PositionTypeEnum, StretchTypeEnum, ModeEnum} from "../jasper/type/Enums"; import {JRElementGroup} from "../jasper/JRElementGroup"; @properties(CommonProperty) @properties(PrintProperty) export abstract class ReportItem extends ReportItemBase implements JRElement{ constructor(){ super(); this.initPrivateProperties(); } private initPrivateProperties(){ } get location():PointUnit { return new PointUnit(this.getPropertyValue(CommonProperty.x) , this.getPropertyValue(CommonProperty.y)); } set location(value:PointUnit) { transaction(() => { this.setPropertyValue(CommonProperty.x, value.x); this.setPropertyValue(CommonProperty.y, value.y); }); } get size():SizeUnit { return new SizeUnit(this.getPropertyValue(CommonProperty.width) , this.getPropertyValue(CommonProperty.height)); } set size(value:SizeUnit) { transaction(() => { this.setPropertyValue(CommonProperty.width, value.width); this.setPropertyValue(CommonProperty.height, value.height); }); } get bounds():RectUnit { return RectUnit.fromLocationAndSize(this.location, this.size); } set bounds(value:RectUnit) { this.location = value.location; this.size = value.size; } get left():Unit { return this.location.x; } set left(value:Unit) { this.location = new PointUnit(value, this.location.y); } get top():Unit { return this.location.y; } set top(value:Unit) { this.location = new PointUnit(this.location.x, value); } get width():Unit { return this.size.width; } set width(value:Unit) { this.size = new SizeUnit(value, this.size.height); } get height():Unit { return this.size.height; } set height(value:Unit) { this.size = new SizeUnit(this.size.width, value); } get backColor():string{ return this.getPropertyValue(CommonProperty.backColor); } set backColor(value:string){ this.setPropertyValue(CommonProperty.backColor, value); } clone(){ const item = new (this.constructor); item.left = this.left.clone(); item.top = this.top.clone(); item.width = this.width.clone(); item.height = this.height.clone(); item.setPropertyValue(CommonProperty.backColor, this.style.backgroundColor); item.setPropertyValue(CommonProperty.foreColor, this.style.color); item.setPropertyValue(CommonProperty.opaque, this.style.opaque); return item; } /** * 组件的首选 Size * @returns {number[]} */ protected preferredSize(): {width:number, height:number} { return {width: 100, height: 30}; } // ------------- JRElement interface implements block begin getPositionType():PositionTypeEnum { return this.getPropertyValue(PrintProperty.positionType); } setPositionType(positionTypeValue:PositionTypeEnum):void { this.setPropertyValue(PrintProperty.positionType, positionTypeValue); } getStretchType():StretchTypeEnum { return this.getPropertyValue(PrintProperty.stretchType); } setStretchType(stretchTypeValue:StretchTypeEnum):void { this.setPropertyValue(PrintProperty.stretchType, stretchTypeValue); } isPrintRepeatedValues():boolean { return this.getPropertyValue(PrintProperty.isPrintRepeatedValues); } setPrintRepeatedValues(isPrintRepeatedValues:boolean):void { this.setPropertyValue(PrintProperty.isPrintRepeatedValues, isPrintRepeatedValues); } isRemoveLineWhenBlank():boolean { return this.getPropertyValue(PrintProperty.isRemoveLineWhenBlank); } setRemoveLineWhenBlank(isRemoveLineWhenBlank:boolean):void { this.setPropertyValue(PrintProperty.isRemoveLineWhenBlank, isRemoveLineWhenBlank); } isPrintInFirstWholeBand():boolean { return this.getPropertyValue(PrintProperty.isPrintInFirstWholeBand); } setPrintInFirstWholeBand(isPrintInFirstWholeBand:boolean):void { this.setPropertyValue(PrintProperty.isPrintInFirstWholeBand, isPrintInFirstWholeBand); } isPrintWhenDetailOverflows():boolean { return this.getPropertyValue(PrintProperty.isPrintWhenDetailOverflows); } setPrintWhenDetailOverflows(isPrintWhenDetailOverflows:boolean):void { this.setPropertyValue(PrintProperty.isPrintWhenDetailOverflows, isPrintWhenDetailOverflows); } getElementGroup():JRElementGroup { return this.parent as any; } getUUID():string { return this.objectId; } getX():number { return this.left.pixels; } setX(value:number):void { this.left = Unit.pixel(value); } getY():number { return this.top.pixels; } setY(value:number):void { this.top = Unit.pixel(value); } getWidth():number { return this.width.pixels; } setWidth(value:number):void { this.width = Unit.pixel(value); } getHeight():number { return this.height.pixels; } setHeight(value:number):void { this.height = Unit.pixel(value); } getOwnForecolor():string { return this.style.color; } setForecolor(color:string):void { this.style.color = color; } getOwnBackcolor():string { return this.style.backgroundColor; } setBackcolor(color:string):void { this.style.backgroundColor = color; } getOwnModeValue():ModeEnum { return this.style.opaque === true ? ModeEnum.Opaque : ModeEnum.Transparent; } setMode(mode:ModeEnum):void { this.style.opaque = mode === ModeEnum.Opaque ? true : false; } // ------------- JRElement interface implements block end }