public void freezeElement(GraphicElement element, boolean frozen) { if (frozen) { element.addAttribute("layout.frozen"); } else { element.removeAttribute("layout.frozen"); } }
/** * Check if a sprite contains the given point (x,y). * * @param elt The sprite. * @param x The point abscissa. * @param y The point ordinate. * @return True if (x,y) is in the given element. */ protected boolean spriteContains(GraphicElement elt, double x, double y) { Values size = elt.getStyle().getSize(); double w2 = metrics.lengthToPx(size, 0) / 2; double h2 = size.size() > 1 ? metrics.lengthToPx(size, 1) / 2 : w2; Point2D.Double dst = spritePositionPx((GraphicSprite) elt); // new // Point2D.Double( // elt.getX(), // elt.getY() // ); // Point2D.Double dst = new Point2D.Double(); // Tx.transform( src, dst ); dst.x -= metrics.viewport[0]; dst.y -= metrics.viewport[1]; double x1 = dst.x - w2; double x2 = dst.x + w2; double y1 = dst.y - h2; double y2 = dst.y + h2; if (x < x1) return false; if (y < y1) return false; if (x > x2) return false; if (y > y2) return false; return true; }
@Override protected void pushDynStyle( StyleGroup group, Graphics2D g, Camera camera, GraphicElement element) { Color color = group.getFillColor(0); if (element != null && group.getFillMode() == FillMode.DYN_PLAIN) color = interpolateColor(group, element); g.setColor(color); if (group.getSizeMode() == SizeMode.DYN_SIZE) { Object s = element.getAttribute("ui.size"); if (s != null) { width = metrics.lengthToGu(StyleConstants.convertValue(s)); height = width; w2 = width / 2; h2 = height / 2; } else { size = group.getSize(); width = metrics.lengthToGu(size, 0); height = size.size() > 1 ? metrics.lengthToGu(size, 1) : width; w2 = width / 2; h2 = height / 2; } } }
/** * True if the element should be visible on screen. The method used is to transform the center of * the element (which is always in graph units) using the camera actual transformation to put it * in pixel units. Then to look in the style sheet the size of the element and to test if its * enclosing rectangle intersects the view port. For edges, its two nodes are used. As a speed-up * by default if the camera is in automatic fitting mode, all element should be visible, and the * test always returns true. * * @param element The element to test. * @return True if the element is visible and therefore must be rendered. */ public boolean isVisible(GraphicElement element) { if (autoFit) { return ((!element.hidden) && (element.style.getVisibilityMode() != StyleConstants.VisibilityMode.HIDDEN)); } else { switch (element.getSelectorType()) { case NODE: return !nodeInvisible.contains(element.getId()); case EDGE: return isEdgeVisible((GraphicEdge) element); case SPRITE: return isSpriteVisible((GraphicSprite) element); default: return false; } } }