/** * To implement {@link * org.w3c.dom.svg.SVGTextContentElement#getStartPositionOfChar(int charnum)}. */ public static SVGPoint getStartPositionOfChar (Element elt, final int charnum) throws DOMException { final SVGOMElement svgelt = (SVGOMElement)elt; if ( (charnum < 0) || (charnum >= getNumberOfChars(elt)) ){ throw svgelt.createDOMException (DOMException.INDEX_SIZE_ERR, "",null); } final SVGTextContent context = (SVGTextContent)svgelt.getSVGContext(); return new SVGTextPoint(svgelt){ public float getX(){ return (float)SVGTextContentSupport.getStartPos (this.svgelt, context, charnum).getX(); } public float getY(){ return (float)SVGTextContentSupport.getStartPos (this.svgelt, context, charnum).getY(); } }; }
/** * To implement {@link * org.w3c.dom.svg.SVGTextContentElement#getEndPositionOfChar(int charnum)}. */ public static SVGPoint getEndPositionOfChar (Element elt,final int charnum) throws DOMException { final SVGOMElement svgelt = (SVGOMElement)elt; if ( (charnum < 0) || (charnum >= getNumberOfChars(elt)) ){ throw svgelt.createDOMException (DOMException.INDEX_SIZE_ERR, "",null); } final SVGTextContent context = (SVGTextContent)svgelt.getSVGContext(); return new SVGTextPoint(svgelt){ public float getX(){ return (float)SVGTextContentSupport.getEndPos (this.svgelt, context, charnum).getX(); } public float getY(){ return (float)SVGTextContentSupport.getEndPos (this.svgelt, context, charnum).getY(); } }; }
/** * Get the relative coordinates of a point within the coordinate system of a * particular SVG Element. * * @param evt Event, needs to be a DOMMouseEvent * @param reference SVG Element the coordinate system is used of * @return Array containing the X and Y values */ public static double[] getRelativeCoordinates(Event evt, Element reference) { if(evt instanceof DOMMouseEvent && reference instanceof SVGLocatable && reference instanceof SVGElement) { // Get the screen (pixel!) coordinates DOMMouseEvent gnme = (DOMMouseEvent) evt; SVGMatrix mat = ((SVGLocatable) reference).getScreenCTM(); SVGMatrix imat = mat.inverse(); SVGPoint cPt = ((SVGElement) reference).getOwnerSVGElement().createSVGPoint(); cPt.setX(gnme.getClientX()); cPt.setY(gnme.getClientY()); // Have Batik transform the screen (pixel!) coordinates into SVG element // coordinates cPt = cPt.matrixTransform(imat); return new double[] { cPt.getX(), cPt.getY() }; } return null; }
/** * Convert the coordinates of an DOM Event from screen into element * coordinates. * * @param doc Document context * @param tag Element containing the coordinate system * @param evt Event to interpret * @return coordinates */ public static SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt) { try { DOMMouseEvent gnme = (DOMMouseEvent) evt; SVGMatrix mat = ((SVGLocatable) tag).getScreenCTM(); SVGMatrix imat = mat.inverse(); SVGPoint cPt = ((SVGDocument) doc).getRootElement().createSVGPoint(); cPt.setX(gnme.getClientX()); cPt.setY(gnme.getClientY()); return cPt.matrixTransform(imat); } catch(Exception e) { LoggingUtil.warning("Error getting coordinates from SVG event.", e); return null; } }
@Override public boolean duringDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { ClusterOrder order = getClusterOrder(); int mouseDownIndex = getSelectedIndex(order, startPoint); int mouseActIndex = getSelectedIndex(order, dragPoint); final int begin = Math.max(Math.min(mouseDownIndex, mouseActIndex), 0); final int end = Math.min(Math.max(mouseDownIndex, mouseActIndex), order.size()); double width = plotwidth / order.size(); double x1 = begin * width; double x2 = (end * width) + width; mtag.removeChild(mtag.getLastChild()); Element marker = addMarkerRect(x1, x2 - x1); SVGUtil.setCSSClass(marker, CSS_RANGEMARKER); mtag.appendChild(marker); return true; }
@Override public boolean startEdgeCreation(GraphElement graphElement, Point point) { boolean alreadyStarted = edgeCreationFromSource || edgeCreationFromSink; boolean started = super.startEdgeCreation(graphElement, point); if (!alreadyStarted && started) { if (edgeMoveElement instanceof SVGGraphEdge) { SVGGraphEdge svgGraphEdge = (SVGGraphEdge) edgeMoveElement; SVGPoint sourcePoint = svgGraphEdge.getPathElement() .getPointAtLength(0f); edgeLine.setSourcePoint(new Point((int) sourcePoint.getX(), (int) sourcePoint.getY())); } else edgeLine.setSourcePoint(point); edgeLine.setTargetPoint(point); edgeLine.setColour(Color.BLACK); // edgeLine.setVisible(true); } return started; }
public Rectangle2D.Float getBorderScreenPosition() { Rectangle2D.Float rect = getBorder(); SVGElement eleBorder = getElement(SvgElementType.Border); SVGMatrix matrix = ((SVGLocatable) eleBorder).getScreenCTM(); SVGPoint leftTopCoordinatePoint = new SVGOMPoint(rect.x, rect.y); SVGPoint leftTopScreenPoint = leftTopCoordinatePoint .matrixTransform(matrix); SVGPoint rightBottomCoordinatePoint = new SVGOMPoint(rect.x + rect.width, rect.y + rect.height); SVGPoint rightBottomScreenPoint = rightBottomCoordinatePoint .matrixTransform(matrix); Rectangle2D.Float result = new Rectangle2D.Float( leftTopScreenPoint.getX(), leftTopScreenPoint.getY(), rightBottomScreenPoint.getX() - leftTopScreenPoint.getX(), rightBottomScreenPoint.getY() - leftTopScreenPoint.getY()); return result; }
public void setScreenRect(Rectangle2D.Float rect) { this.screenRect = rect; SVGMatrix matrix = objectElement.getScreenCTM(); SVGPoint leftTopScreenPoint = new SVGOMPoint(rect.x, rect.y); SVGPoint leftTopCoorindatePoint = leftTopScreenPoint .matrixTransform(matrix.inverse()); SVGPoint rightBottomScreenPoint = new SVGOMPoint(rect.x + rect.width, rect.y + rect.height); SVGPoint rightBottomCoorindatePoint = rightBottomScreenPoint .matrixTransform(matrix.inverse()); Rectangle2D.Float coordinateRect = new Rectangle2D.Float( leftTopCoorindatePoint.getX(), leftTopCoorindatePoint.getY(), rightBottomCoorindatePoint.getX() - leftTopCoorindatePoint.getX(), rightBottomCoorindatePoint.getY() - leftTopCoorindatePoint.getY()); setCoordinateRectangle("", coordinateRect); }
/** * Constructs a polygon according to the specified parameters. * * @param ctx the bridge context to use * @param e the element that describes a rect element * @param shapeNode the shape node to initialize */ protected void buildShape(BridgeContext ctx, Element e, ShapeNode shapeNode) { SVGOMPolygonElement pe = (SVGOMPolygonElement) e; try { SVGOMAnimatedPoints _points = pe.getSVGOMAnimatedPoints(); _points.check(); SVGPointList pl = _points.getAnimatedPoints(); int size = pl.getNumberOfItems(); if (size == 0) { shapeNode.setShape(DEFAULT_SHAPE); } else { AWTPolygonProducer app = new AWTPolygonProducer(); app.setWindingRule(CSSUtilities.convertFillRule(e)); app.startPoints(); for (int i = 0; i < size; i++) { SVGPoint p = pl.getItem(i); app.point(p.getX(), p.getY()); } app.endPoints(); shapeNode.setShape(app.getShape()); } } catch (LiveAttributeException ex) { throw new BridgeException(ctx, ex); } }
/** * Constructs a polyline according to the specified parameters. * * @param ctx the bridge context to use * @param e the element that describes a rect element * @param shapeNode the shape node to initialize */ protected void buildShape(BridgeContext ctx, Element e, ShapeNode shapeNode) { SVGOMPolylineElement pe = (SVGOMPolylineElement) e; try { SVGOMAnimatedPoints _points = pe.getSVGOMAnimatedPoints(); _points.check(); SVGPointList pl = _points.getAnimatedPoints(); int size = pl.getNumberOfItems(); if (size == 0) { shapeNode.setShape(DEFAULT_SHAPE); } else { AWTPolylineProducer app = new AWTPolylineProducer(); app.setWindingRule(CSSUtilities.convertFillRule(e)); app.startPoints(); for (int i = 0; i < size; i++) { SVGPoint p = pl.getItem(i); app.point(p.getX(), p.getY()); } app.endPoints(); shapeNode.setShape(app.getShape()); } } catch (LiveAttributeException ex) { throw new BridgeException(ctx, ex); } }
/** * Transforms an {@link SVGPoint} by an {@link SVGMatrix} and returns * the new point. */ public static SVGPoint matrixTransform(SVGPoint point, SVGMatrix matrix) { float newX = matrix.getA() * point.getX() + matrix.getC() * point.getY() + matrix.getE(); float newY = matrix.getB() * point.getX() + matrix.getD() * point.getY() + matrix.getF(); return new SVGOMPoint(newX, newY); }
/** * Asserts that the given item is an {@link SVGPoint}. */ protected void checkItemType(Object newItem) throws SVGException { if (!(newItem instanceof SVGPoint)) { createSVGException(SVGException.SVG_WRONG_TYPE_ERR, "expected.point", null); } }
/** * Returns the base value of the attribute as an {@link AnimatableValue}. */ public AnimatableValue getUnderlyingValue(AnimationTarget target) { SVGPointList pl = getPoints(); int n = pl.getNumberOfItems(); float[] points = new float[n * 2]; for (int i = 0; i < n; i++) { SVGPoint p = pl.getItem(i); points[i * 2] = p.getX(); points[i * 2 + 1] = p.getY(); } return new AnimatablePointListValue(target, points); }
/** * <b>DOM</b>: Implements {@link SVGPointList#getItem(int)}. */ public SVGPoint getItem(int index) throws DOMException { if (hasAnimVal) { return super.getItem(index); } return getPoints().getItem(index); }
/** * <b>DOM</b>: Implements {@link SVGPointList#initialize(SVGPoint)}. */ public SVGPoint initialize(SVGPoint newItem) throws DOMException, SVGException { throw element.createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.point.list", null); }
/** * <b>DOM</b>: Implements {@link * SVGPointList#insertItemBefore(SVGPoint, int)}. */ public SVGPoint insertItemBefore(SVGPoint newItem, int index) throws DOMException, SVGException { throw element.createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.point.list", null); }
/** * <b>DOM</b>: Implements {@link * SVGPointList#replaceItem(SVGPoint, int)}. */ public SVGPoint replaceItem(SVGPoint newItem, int index) throws DOMException, SVGException { throw element.createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.point.list", null); }
@Override public boolean duringDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { deleteChildren(rtag); double x = Math.min(startPoint.getX(), dragPoint.getX()); double y = Math.min(startPoint.getY(), dragPoint.getY()); double width = Math.abs(startPoint.getX() - dragPoint.getX()); double height = Math.abs(startPoint.getY() - dragPoint.getY()); rtag.appendChild(svgp.svgRect(x, y, width, height)); return true; }
@Override public boolean endDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { Mode mode = getInputMode(evt); deleteChildren(rtag); if(startPoint.getX() != dragPoint.getX() || startPoint.getY() != dragPoint.getY()) { updateSelection(mode, startPoint, dragPoint); } return true; }
/** * Updates the selection in the context.<br> * * @param mode Input mode * @param p1 first point of the selected rectangle * @param p2 second point of the selected rectangle */ private void updateSelection(Mode mode, SVGPoint p1, SVGPoint p2) { DBIDSelection selContext = context.getSelection(); // Note: we rely on SET semantics below! final HashSetModifiableDBIDs selection; if(selContext == null || mode == Mode.REPLACE) { selection = DBIDUtil.newHashSet(); } else { selection = DBIDUtil.newHashSet(selContext.getSelectedIds()); } int[] axisrange = getAxisRange(Math.min(p1.getX(), p2.getX()), Math.max(p1.getX(), p2.getX())); DBIDs ids = SamplingResult.getSamplingResult(relation).getSample(); for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) { double[] yPos = proj.fastProjectDataToRenderSpace(relation.get(iter)); if(checkSelected(axisrange, yPos, Math.max(p1.getX(), p2.getX()), Math.min(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()), Math.min(p1.getY(), p2.getY()))) { if(mode == Mode.INVERT) { if(!selection.contains(iter)) { selection.add(iter); } else { selection.remove(iter); } } else { // In REPLACE and ADD, add objects. // The difference was done before by not re-using the selection. // Since we are using a set, we can just add in any case. selection.add(iter); } } } context.setSelection(new DBIDSelection(selection)); }
@Override public boolean endDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { deleteChildren(rtag); if(startPoint.getX() != dragPoint.getX() || startPoint.getY() != dragPoint.getY()) { updateSelection(proj, startPoint, dragPoint); } return true; }
@Override public boolean startDrag(SVGPoint startPoint, Event evt) { ClusterOrder order = getClusterOrder(); int mouseActIndex = getSelectedIndex(order, startPoint); if(mouseActIndex >= 0 && mouseActIndex < order.size()) { double width = plotwidth / order.size(); double x1 = mouseActIndex * width; Element marker = addMarkerRect(x1, width); SVGUtil.setCSSClass(marker, CSS_RANGEMARKER); mtag.appendChild(marker); return true; } return false; }
@Override public boolean endDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { ClusterOrder order = getClusterOrder(); int mouseDownIndex = getSelectedIndex(order, startPoint); int mouseActIndex = getSelectedIndex(order, dragPoint); Mode mode = getInputMode(evt); final int begin = Math.max(Math.min(mouseDownIndex, mouseActIndex), 0); final int end = Math.min(Math.max(mouseDownIndex, mouseActIndex), order.size()); updateSelection(mode, begin, end); return true; }
@Override public boolean startDrag(SVGPoint start, Event evt) { epsilon = getEpsilonFromY(plotheight - start.getY()); // opvis.unsetEpsilonExcept(this); svgp.requestRedraw(this.task, this); return true; }
@Override public boolean duringDrag(SVGPoint start, SVGPoint end, Event evt, boolean inside) { if(inside) { epsilon = getEpsilonFromY(plotheight - end.getY()); } // opvis.unsetEpsilonExcept(this); svgp.requestRedraw(this.task, this); return true; }
@Override public boolean endDrag(SVGPoint start, SVGPoint end, Event evt, boolean inside) { if(inside) { epsilon = getEpsilonFromY(plotheight - end.getY()); // opvis.unsetEpsilonExcept(this); // FIXME: replace an existing optics cut result! final ClusterOrder order = optics.getResult(); Clustering<Model> cl = OPTICSCut.makeOPTICSCut(order, epsilon); order.addChildResult(cl); } svgp.requestRedraw(this.task, this); return true; }
@Override public boolean endDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { deleteChildren(rtag); if(startPoint.getX() != dragPoint.getX() || startPoint.getY() != dragPoint.getY()) { updateSelection(startPoint, dragPoint); } return true; }
@Override public boolean endDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { double[] movingVector = new double[] { // dragPoint.getX() - startPoint.getX(), // dragPoint.getY() - startPoint.getY() }; if(context.getSelection() != null) { updateDB(context.getSelection().getSelectedIds(), movingVector); } deleteChildren(rtag); return true; }
@Override public boolean endDrag(SVGPoint startPoint, SVGPoint dragPoint, Event evt, boolean inside) { Mode mode = getInputMode(evt); deleteChildren(rtag); if(startPoint.getX() != dragPoint.getX() || startPoint.getY() != dragPoint.getY()) { updateSelection(mode, proj, startPoint, dragPoint); } return true; }
/** * Updates the selection in the context.<br> * * @param mode Input mode * @param proj * @param p1 first point of the selected rectangle * @param p2 second point of the selected rectangle */ private void updateSelection(Mode mode, Projection2D proj, SVGPoint p1, SVGPoint p2) { DBIDSelection selContext = context.getSelection(); // Note: we rely on SET semantics below! HashSetModifiableDBIDs selection; if(selContext == null || mode == Mode.REPLACE) { selection = DBIDUtil.newHashSet(); } else { selection = DBIDUtil.newHashSet(selContext.getSelectedIds()); } for(DBIDIter iditer = rel.iterDBIDs(); iditer.valid(); iditer.advance()) { double[] vec = proj.fastProjectDataToRenderSpace(rel.get(iditer)); if(vec[0] >= Math.min(p1.getX(), p2.getX()) && vec[0] <= Math.max(p1.getX(), p2.getX()) && vec[1] >= Math.min(p1.getY(), p2.getY()) && vec[1] <= Math.max(p1.getY(), p2.getY())) { if(mode == Mode.INVERT) { if(!selection.contains(iditer)) { selection.add(iditer); } else { selection.remove(iditer); } } else { // In REPLACE and ADD, add objects. // The difference was done before by not re-using the selection. // Since we are using a set, we can just add in any case. selection.add(iditer); } } } context.setSelection(new DBIDSelection(selection)); }