List of usage examples for javax.swing SwingUtilities computeDifference
public static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB)
rectA
that do not overlap with rectB
. From source file:org.eclipse.jubula.rc.swing.tester.adapter.JComboBoxAdapter.java
/** * @return a rectangle, where the arrow icon is expected. *///from w w w . ja va2 s.c om private Rectangle findArrowIconArea() { JComboBox comboBox = m_comboBox; Component editor = getComboBoxEditorComponent(comboBox); Rectangle r = null; if (editor == null) { throw new StepExecutionException("could not find editor", //$NON-NLS-1$ EventFactory.createActionError(TestErrorEvent.COMP_NOT_FOUND)); } Rectangle ra[] = SwingUtilities.computeDifference(comboBox.getBounds(), editor.getBounds()); if ((ra == null) || (ra.length < 1)) { throw new StepExecutionException("could not arrow icon", //$NON-NLS-1$ EventFactory.createActionError(TestErrorEvent.COMP_NOT_FOUND)); } r = ra[0]; // find the largest area of the returned rectangles. double bestAreaIndex = Double.MAX_VALUE; for (int i = 0; i < ra.length; i++) { if ((ra[i].height > 0) && (ra[i].width > 0)) { double areaIndex = ((double) ra[i].width) / ra[i].height - 1.0; if (areaIndex < 0) { areaIndex *= (-1); } if (areaIndex < bestAreaIndex) { bestAreaIndex = areaIndex; r = ra[i]; } } } return r; }