/** * Binds this manipulator to the specified SVG rect. * * @param element The SVG rect this manipulator is applied to. * @return The root element of the manipulator */ @Override public OMSVGElement bind(Record record) { this.record = record; SVGViewBoxElementModel model = (SVGViewBoxElementModel) record.getModel(); mode = Mode.PASSIVE; // Create the graphical representations for the manipulator // The manipulator has the following SVG structure // <g> // <rect/> position // <g> // <rect/> top-left corner // <rect/> bottom-right corner // </g> // </g> OMSVGRectElement rect = (OMSVGRectElement) model.getElementWrapper(); svg = rect.getOwnerSVGElement(); OMSVGDocument document = (OMSVGDocument) svg.getOwnerDocument(); g = document.createSVGGElement(); g.setClassNameBaseVal(AppBundle.INSTANCE.css().rectGeometryManipulator()); posHandle = document.createSVGRectElement(); OMSVGGElement handleGroup = document.createSVGGElement(); topLeftHandle = document.createSVGRectElement(); bottomRightHandle = document.createSVGRectElement(); g.appendChild(posHandle); g.appendChild(handleGroup); handleGroup.appendChild(topLeftHandle); handleGroup.appendChild(bottomRightHandle); monitorModel = true; model.addChangeListener(this); scheduleInit(); return g; }
/** Detaches this manipulator from the DOM tree */ @Override public void unbind() { if (g != null) { Element parent = g.getElement().getParentElement(); if (parent != null) { parent.removeChild(g.getElement()); } SVGViewBoxElementModel model = (SVGViewBoxElementModel) record.getModel(); model.removeChangeListener(this); record = null; g = null; posHandle = null; topLeftHandle = null; bottomRightHandle = null; mode = Mode.PASSIVE; } }
@Override public void modelChanged(ChangeEvent event) { if (monitorModel) { SVGViewBoxElementModel model = (SVGViewBoxElementModel) record.getModel(); if (model.getElement().hasAttribute(SVGConstants.SVG_TRANSFORM_ATTRIBUTE)) { g.setAttribute( SVGConstants.SVG_TRANSFORM_ATTRIBUTE, model.getElement().getAttribute(SVGConstants.SVG_TRANSFORM_ATTRIBUTE)); } float x = model.get(SVGConstants.SVG_X_ATTRIBUTE); float y = model.get(SVGConstants.SVG_Y_ATTRIBUTE); float width = model.get(SVGConstants.SVG_WIDTH_ATTRIBUTE); float height = model.get(SVGConstants.SVG_HEIGHT_ATTRIBUTE); posHandle.getX().getBaseVal().newValueSpecifiedUnits(Unit.PX, x); posHandle.getY().getBaseVal().newValueSpecifiedUnits(Unit.PX, y); posHandle.getWidth().getBaseVal().newValueSpecifiedUnits(Unit.PX, width); posHandle.getHeight().getBaseVal().newValueSpecifiedUnits(Unit.PX, height); update(); } }