Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockLocationToScrollDown/Up use of constant for adjustment to track point results in un-usable values #126

Open
croesch opened this issue Feb 8, 2014 · 0 comments

Comments

@croesch
Copy link
Collaborator

croesch commented Feb 8, 2014

Issue by David Bradley from Sat, 16 Apr 2011 07:46:08 -0500
Originally opened as http://jira.codehaus.org/browse/FEST-438


Using class JScrollBarLocation to get a point in a scrollbar track provides un-usable point value. Looking at the code a constant (BLOCK_OFFSET = 4) is used in blockLocationToScrollDown/Up and is an adjustment to the unitLocationToScrollDown/Up. The latter providing a mid-point in the arrow button.

However, in Swing the default size of an arrow button is 16x16, so unitLocation..... gives 8x8 but blockLocation results in only 4 being adjusted from the mid-point, which still resides in the arrow button.

If the scrollbar is not of the default size, the use of BLOCK_OFFSET would likely be more out of whack.

current code looks like:

class JScrollBarLocation
-------------------------

private static final int BLOCK_OFFSET = 4;


@RunsInCurrentThread
  public Point blockLocationToScrollUp(JScrollBar scrollBar)
{
    Point p = unitLocationToScrollUp(scrollBar);
    int offset = BLOCK_OFFSET;
    return blockLocation(scrollBar, p, offset);
  }

Something like below is needed

@RunsInCurrentThread
  public Point blockLocationToScrollUp(JScrollBar scrollBar) {
    // provide a point just off the edge of the arrow button (unit location)
    Point p = unitLocationToScrollUp(scrollBar);

    // offset from the arrow to the track is a factor of
    // scrollBar's orientation width/height
    int offset = 0;

    if( scrollBar.getOrientation() == VERTICAL)
{
         offset = scrollBar.getWidth();
    }
else
{
         offset = scrollBar.getHeight();
    }

    // assume offset represents the arrow's button square size as
    // drawn, the track offset is at the edge of the button (offset/2) and a
    // little further (+2) for inset/border consideration in the most simple
    // form (hardcoded value is a bad design but best guess)
    offset = (offset / 2 ) +2;

    return blockLocation(scrollBar, p, offset);
  }

The above does not deal with border or insets of the arrow button which I've been unable to determine if these will impact the edge calculation or not. (hardcoded +2 value is a bad design but best guess for demostration)

There is other code in class that I've noticed to be abstract, which I've not been able to debug through. So maybe the code is not as above but else where.......

Once the correct value is provided, adding point to the screen location of the scrollBar in my tests provides the exact point to click. This deals with accessibility adjustments provided in an application for different scrollBar sizes.


votes (original issue): 0
watches (original issue): 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant