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

introduce static helper method GC#drawOn #1063

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tobiasmelcher
Copy link
Contributor

which takes care of creation and disposal of the GC object

Fixes: #955

@tobiasmelcher
Copy link
Contributor Author

@HannesWell : could you please take a look at this change? I had to introduce a new Runnable interface which passes the GC as argument. Is there already an existing interface I could re-use? Do we have to introduce the static method GC#drawOn in all platform specific GC implementations?

Copy link
Contributor

github-actions bot commented Feb 26, 2024

Test Results

   299 files  ±0     299 suites  ±0   6m 58s ⏱️ -21s
 4 100 tests ±0   4 092 ✅ ±0   8 💤 ±0  0 ❌ ±0 
12 212 runs  ±0  12 137 ✅ ±0  75 💤 ±0  0 ❌ ±0 

Results for commit 573159d. ± Comparison against base commit e703afe.

♻️ This comment has been updated with latest results.

@HannesWell
Copy link
Member

Hello @tobiasmelcher, thank you for this PR. Sorry for my late reply but I just started my almost three week of vacation when you created this PR and when I came back a full TODO list was ready to be worked off.

Do we have to introduce the static method GC#drawOn in all platform specific GC implementations?

Yes we do, but you can just import/open the fragments for the other platforms and they will compile in your workspace. For you it is probably sufficient to only have one arch per OS since they only differ in the embedded native binaries, but the code is the same for all archs on one OS.

I had to introduce a new Runnable interface which passes the GC as argument. Is there already an existing interface I could re-use?

Yes there is already SWTRunnable. But as I have just written in #955 (comment), I think this is not the optimal solution, which I only noticed when reviewing your changes to apply the new method (applying it immediately can therefore be very helpful 👍🏽 )

Copy link
Member

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. In general it looks good, but I added some remarks below.

But the most important missing part is the implementation for the linux- and mac-platform as written in my previous comment.

@tobiasmelcher
Copy link
Contributor Author

Thanks a lot @HannesWell for all the feedback. Could you please take a look and review my latest change eb1dc57 ? As already mentioned, I had some troubles with the formatting; I executed then the format action only on the changed coding parts. Is that ok?

Copy link
Member

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already mentioned, I had some troubles with the formatting; I executed then the format action only on the changed coding parts. Is that ok?

Yes, that's IMO the perfect decision.

Could you please also update the doc of the GC class to mention the new GC.create() factory (for all platforms).

With that I think this change is complete (I'll mark it as ready for review), but I would like give others some time to review.

@@ -59,7 +59,22 @@
* @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/
public final class GC extends Resource {
public sealed class GC extends Resource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to also update the doc of this class (where it mentions GC.dispose()) and recommend to use the new factory, ideally with the little example also used in the Image class.
And I think Windows95 and Windows98 are not the most relevant target OS anymore. Maybe that just should be generalized.

Comment on lines +167 to +169
* try (var gc = GC.create(i)) {
* gc.drawRectangle(0, 0, 50, 50));
* }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply this doc update also to the Image implementations for Linux and Mac.

@HannesWell HannesWell marked this pull request as ready for review March 29, 2024 13:38
which takes care of creation and disposal of the GC object

Fixes: eclipse-platform#955
- format the changed coding parts
- remove the GC.create calls at locations where the diff gets too large
}
}

public static GC.Closeable create(Drawable drawable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new method needs some java-doc on all platforms. The existing single argument constructor of GC is probably a good source of inspiration.
The existing GC constructor could also be adjusted to recommend this method for safety.

What's important is to add the tag @since 3.126 in the Java-doc in order to make the API-tools aware this method was just added.

Copy link
Contributor Author

@tobiasmelcher tobiasmelcher Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. I hope it is fine with 6443eca

public final class GC extends Resource {
public sealed class GC extends Resource {

public static final class Closeable extends GC implements AutoCloseable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new class needs some java-doc on all platforms. I think a short text that mentions that this is an auto-closable extension of the GC class is sufficient. The create method could be linked with @see.
What's important is to add the tag @since 3.126 in the Java-doc in order to make the API-tools aware this method was just added.

@tobiasmelcher tobiasmelcher force-pushed the GC.drawOn branch 2 times, most recently from eb1dc57 to 6443eca Compare April 2, 2024 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement java.lang.AutoCloseable in class org.eclipse.swt.graphics.GC
3 participants