Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RAP 2.3.2: GC stringExtent() returns different values for same string(Problem can be re-produced using HelloWorld example on Developer's Guide)
RAP 2.3.2: GC stringExtent() returns different values for same string [message #1711064] Mon, 12 October 2015 15:55 Go to next message
Tass Burrfoot is currently offline Tass BurrfootFriend
Messages: 19
Registered: April 2015
Junior Member
Hello

My project uses RAP 2.3.2. I got a problem which could be re-produced on the HelloWorld example provided by the developer's guide web page
http://www.eclipse.org/rap/developers-guide/devguide.php?topic=hello-world.html&version=3.0

Follow everything described on the web page to create the Hello World example. And change the code of BasicEntryPoint.java to this

 @Override
    protected void createContents(Composite parent) {
        parent.setLayout(new GridLayout(2, false));
        Button checkbox = new Button(parent, SWT.CHECK);
        checkbox.setText("Hello");
        Button button = new Button(parent, SWT.PUSH);
        button.setText("World");
        button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GC gc = new GC(button);
		    	String str = "Some-Test-String";
		    	int unit = gc.stringExtent("x").x;
		    	int test = gc.stringExtent(str).x;
		    	gc.dispose();
		    	System.out.println("Test " + test);
		    	System.out.println("Unit " + unit);
			}
        });
    }


Run the application. After page is loaded, click the button "World". I got the following result
Test 140
Unit 9


Then I click the button for the second time. I got this
Test 128
Unit 9


If I click more times, I got Test 128 and Unit 9. HelloWorld example has no font setting and I didn't do anything else on the page just click the button several times. I am not sure why stringExtent() returns different value when I click the button for the first time for string "Some-Test-String"? And why the result is the same for the string "x"? How to ensure gc stringExtent() returning same result for the same string?

My environment is Eclipse Luna, jdk1.8 on windows vista with firefox. In my project I need to compute text values on Label given a width and I got stuck with this problem. Any help and suggestion would be appreciated. Thanks.

Tass
Re: RAP 2.3.2: GC stringExtent() returns different values for same string [message #1711660 is a reply to message #1711064] Mon, 19 October 2015 07:10 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
the reason is the technique in RAP called text-size-determination. When
you request a text size, and it's not yet measured by the browser (size
of particular text is requested for the first time after server is
started) you get an estimated dimension. Than, this text will be sent to
the client for real measurement and the result will be stored in
text-size storage. If you requests the same text size again, a real size
will be returned as it's already measured.
HTH,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: RAP 2.3.2: GC stringExtent() returns different values for same string [message #1712192 is a reply to message #1711660] Wed, 21 October 2015 20:26 Go to previous message
Tass Burrfoot is currently offline Tass BurrfootFriend
Messages: 19
Registered: April 2015
Junior Member
Thank you for the clear explanation.
Previous Topic:How to debug RAP Client Errors
Next Topic:RAP3.1.0 M2 FileUpload NullException
Goto Forum:
  


Current Time: Tue Mar 19 09:30:30 GMT 2024

Powered by FUDForum. Page generated in 0.02513 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top