/** * Looks for all beans (if any) located within the supplied bounding box. Also adjusts the * bounding box to be a tight fit around all contained beans * * @param boundingBox the bounding rectangle * @return a Vector of BeanInstances */ public static Vector<Object> findInstances(Rectangle boundingBox, Integer... tab) { int index = 0; if (tab.length > 0) { index = tab[0].intValue(); } Vector<Object> components = null; if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) { components = TABBED_COMPONENTS.get(index); } Graphics gx = null; FontMetrics fm = null; int centerX, centerY; int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; int maxX = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE; Vector<Object> result = new Vector<Object>(); for (int i = 0; i < components.size(); i++) { BeanInstance t = (BeanInstance) components.elementAt(i); centerX = t.getX() + (t.getWidth() / 2); centerY = t.getY() + (t.getHeight() / 2); if (boundingBox.contains(centerX, centerY)) { result.addElement(t); // adjust bounding box stuff // int hf = 0; if (gx == null) { gx = ((JComponent) t.getBean()).getGraphics(); gx.setFont(new Font(null, Font.PLAIN, 9)); fm = gx.getFontMetrics(); // hf = fm.getAscent(); } String label = ""; if (t.getBean() instanceof Visible) { label = ((Visible) t.getBean()).getVisual().getText(); } int labelwidth = fm.stringWidth(label); /* * if (label.length() == 0) { heightMultiplier = 0; } */ int brx = 0; int blx = 0; if (centerX - (labelwidth / 2) - 2 < t.getX()) { blx = (centerX - (labelwidth / 2) - 2); brx = centerX + (labelwidth / 2) + 2; } else { blx = t.getX() - 2; brx = t.getX() + t.getWidth() + 2; } if (blx < minX) { minX = blx; } if (brx > maxX) { maxX = brx; } if (t.getY() - 2 < minY) { minY = t.getY() - 2; } if (t.getY() + t.getHeight() + 2 > maxY) { maxY = t.getY() + t.getHeight() + 2; } } } boundingBox.setBounds(minX, minY, maxX - minX, maxY - minY); return result; }