/** * This implementation calls <code>super.hitTest</code> and returns the result if non-null (this * should be a HitInfo.Point), then returns a HitInfo.Interior if the mouse-click occured inside * the text bound (as defined by text layout) * * @return a HitInfo corresponding to the given mouse-event */ public HitInfo hitTest(PEMouseEvent e) { // from Bitmap: if (image != null) { if (getBounds().contains(e.getPicPoint())) { return new HitInfo.Interior((PicText) element, e); } return null; } // from TextLayout: if (!getBounds().contains(e.getPicPoint())) return null; PicText te = (PicText) element; // recompute textlayout b-box, but store it in a temporary field ! Rectangle2D tb = textLayout.getBounds(); Shape text_bounds = text2ModelTr.createTransformedShape(tb); if (text_bounds.contains(e.getPicPoint())) { // [SR:pending] for the hitInfo to be reliable, getPicPoint() should first be transformed by // inverse text2ModelTr ! (especially when rotationAngle != 0) TextHitInfo thi = textLayout.hitTestChar( (float) (e.getPicPoint().x - strx), (float) (e.getPicPoint().y - stry)); // guaranteed to return a non-null thi return new HitInfo.Text((PicText) element, thi, e); } // test hit on textlayout's bounding rectangle : // else if (bounds.contains(e.getPicPoint())) return new HitInfo.Interior(element,e); return null; }
public boolean contains(int x, int y) { // If the button has changed size, // make a new shape object. if (shape == null || !shape.getBounds().equals(getBounds())) { shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight()); } return shape.contains(x, y); }
/* * Creates a line of width EDGE_SELECT_WIDTH for each edge * and tests if mouse click was in that Shape's boundary. * Returns the edge if one was selected, null otherwise. */ public TreeEdge testEdgeShapes(MouseEvent event) { if (argument == null || argument.getTree() == null) return null; double x = event.getX(); double y = event.getY(); BasicStroke edgeWidth = new BasicStroke(EDGE_SELECT_WIDTH); if (argument.getBreadthFirstTraversal() == null) return null; Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); while (nodeList.hasMoreElements()) { TreeVertex vertex = (TreeVertex) nodeList.nextElement(); if (argument.isMultiRoots() && vertex.getLayer() == 0) continue; Enumeration edges = vertex.getEdgeList().elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); Shape shape = edge.getShape(this); Shape wideEdge = edgeWidth.createStrokedShape(shape); TreeVertex child = edge.getDestVertex(); if (wideEdge.contains(x, y)) { edge.setSelected(!edge.isSelected()); return edge; } } } return null; }