Example usage for javax.swing SwingUtilities computeDifference

List of usage examples for javax.swing SwingUtilities computeDifference

Introduction

In this page you can find the example usage for javax.swing SwingUtilities computeDifference.

Prototype

public static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB) 

Source Link

Document

Convenience returning an array of rect representing the regions within rectA that do not overlap with rectB.

Usage

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;
}