View unanswered posts | View active topics It is currently Tue Feb 21, 2017 5:51 am



Reply to topic  [ 4 posts ] 
 SwingComponentWrapper: auto dpi-scaling broken 
Author Message

Joined: Wed Sep 21, 2011 1:41 pm
Posts: 16
Post SwingComponentWrapper: auto dpi-scaling broken
... at least as I understand the intention of BASE_SCALE_FACTOR and the implementation of the fallback to dpi if no explicit scale factors are set :-)

Here's a failing test case:

Code:
    /**
     * Auto-DPI-scaling not working.
     */
    @Test
    public void testDPIScaling() {
       if (Toolkit.getDefaultToolkit().getScreenResolution() == PlatformDefaults.getDefaultDPI()) {
           LOG.info("dpi == default, nothing to test: " +
                   Toolkit.getDefaultToolkit().getScreenResolution());
           return;
       }
       float factor = (float) Toolkit.getDefaultToolkit().getScreenResolution() / PlatformDefaults.getDefaultDPI();
       
       SwingComponentWrapper wrapper = new SwingComponentWrapper(new JButton());
       assertEquals("dpi scaling factor", factor, wrapper.getPixelUnitFactor(true));
       
    }



Reason is the implementation of its method getHorizontalScreenDPI (same for vertical):

Code:
public final int getHorizontalScreenDPI()
{
   return PlatformDefaults.getDefaultDPI();
}


which is used in the scaling method like:

Code:

   return (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI();



which then always is ... 1.

Fix is to implement the getHorizontalScreenDPI to return the toolkit's screenResolution

Code:
    public final int getHorizontalScreenDPI() {
        try {
            return c.getToolkit().getScreenResolution();
        } catch (HeadlessException ex) {
            return PlatformDefaults.getDefaultDPI();
        }
    }


Cheers
Jeanette


Thu Jun 21, 2012 2:16 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: SwingComponentWrapper: auto dpi-scaling broken
Thanks Jeanette,

That is probably an oversight on my part.. Strange though since I am pretty sure I have tested the functionality..

Unfortunately I am absolutely swamped in pay-for projects atm so I will put this, and your other posts, in the work queue.

I will fix them but I can't say when.

MigLayout is on Google Code nowadays. Would you be interested in commit rights?

Cheers,
Mikael


Sat Jun 23, 2012 11:03 am
Profile WWW

Joined: Wed Sep 21, 2011 1:41 pm
Posts: 16
Post Re: SwingComponentWrapper: auto dpi-scaling broken
fixed and committed


Fri Jul 06, 2012 1:07 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: SwingComponentWrapper: auto dpi-scaling broken
The fix is in the next version due in a week or so.

Thanks!

Cheers,
Mikael


Fri Feb 22, 2013 3:48 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.