-
Notifications
You must be signed in to change notification settings - Fork 149
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
Replace and deprecate Image creating methods accepting Strings as file-system paths #1767
base: master
Are you sure you want to change the base?
Conversation
Test Results 496 files - 6 496 suites - 6 10m 29s ⏱️ + 1m 46s For more details on these failures and errors, see this check. Results for commit f66a204. ± Comparison against base commit 0071da4. This pull request removes 56 tests.
♻️ This comment has been updated with latest results. |
Furthermore with this the existing But with all the ongoing effort on improving high-DPI support I wonder if this should be part of a greater API rework? Not that I'm aware of one, but I would like to make sure that there aren't concurrent, maybe even conflicting efforts. |
I think this is a bad choice, as So adding any new API should also use new/modern/better types and it would allow to use alternative sources beside local files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we plan to rework the Image class because of the HiDPI improvements. And actually, the proposed change is conflicting to what we need to do for that.
The reason is that we currently have a bunch of constructors that create "static" images. That means, these images are created once for a specific zoom value and can then only be rescaled to other zoom values via scaling the raster graphics (leading to blurry results). We are working on replacing all these "static" image initializations with "dynamic" ones, i.e., those that are able to create/render an image for whatever zoom is required (like already possible with ImageFileNameProvider/ImageDataProvider). That is the reason why we, for example, created a new constructor taking an "image drawer" that is capable of rendering an on-demand image in whatever zoom value is required as a replacement for just creating an image with fixed width/height and drawing into it: #1734
This is necessary as with the enhanced HiDPI support on Windows it must be possible to always retrieve an image according to the zoom of the monitor the containing shell is currently placed on. If you are interested, you find an analysis of static/dynamic image construction in our backlog: vi-eclipse/Eclipse-Platform#171 (comment)
I can have a further look at this PR and the neccessity of it to find a solution that is conforming with the enhanced HiDPI support. I just have to leave now for the rest of the day, so I at least wanted to give you the above comment to make you aware of that "conflict".
So having now taken another look at the proposal, I am not yet completely sure about the reason for these changes. I agree that the existing APIs are outdated and need to be reworked, but is there a specific trigger for doing it now and in this way? In particular, do we need a replacement for the deprecated constructor at all? We would actually propose to deprecate the Image constructor accepting a string (referring to a local file) without adding a new one as a replacement for it. Instead, the deprecation notice should give advise how to create an image in a "dynamic" way, i.e., with the ability to rescale according to requested zoom (if possible) based on the existing providers. Taking a look at current usages of |
Ok, if it's not widely used I'll change it to Path. Personally I cannot remember to have used SWT's path, but I'm also not developing that many UIs.
Yes, the specific trigger is #1638 (comment)
Not having a simple constructor that allows to directly create an image from a file would make the creation of images less simple, but 'forcing' users to use the more capable constructors is probably better on the long run. On the other hand not all images are icons. Maybe one just wants to display an image image because that person has implemented a simple image-viewer. Of course one can always use
Using In general I think it's good we are talking about it. :) |
I see, valid point. From a design perspective, it would of course make sense to separate these two use cases and distinguish between "dynamic" and "static" images already by type. But for the sake of API compatibility, that's of course not that easy. So probably we will need to provide separate constructors that clearly state what they are supposed to be used for, i.e., those being used for scalable graphics like icons need to be "provider-based" while plain images may be created directly via a file.
Just to get this correctly: the PR does currently only require new ImageData constructors, but not necessary Image constructors, does it? So wouldn't it be possible to only extend ImageData and wrap the conversion String -> File inside the existing Image constructor? I am just asking for the sake of understanding, not that I propose to make this the final solution :-) |
Use java.nio.file.Path to model file-system paths instead of Strings. Add the new way to create ImageData as static factory instead of a constructor, because a constructor is not really suitable to create a copy of the first element of an array of ImageData.
0d6c6b0
to
f66a204
Compare
Using Strings to represent file-system paths is usually a bad idea since using String as type lacks context (String is almost like a primitive) and requires that callers handle OS-specific file-separators properly.
This PR proposes to provide alternatives for existing Image creating methods that accept Strings to represent file-system paths and to deprecate the existing methods, but not for removal since they probably have a huge user-base.
The type
File
is used instead of the more modernjava.nio.file.Path
to avoid confusion with the Path class that already exists in the 'o.e.swt.graphics' package.There are multiple callers left that have to be adapted but I want to reach consensus about the new API first.