From david.dehaven at oracle.com Tue Jul 1 15:44:13 2014 From: david.dehaven at oracle.com (David DeHaven) Date: Tue, 1 Jul 2014 08:44:13 -0700 Subject: JavaAppLauncher In-Reply-To: References: <4C17A649-C279-4007-AD6A-53650E30361B@oracle.com> <98B8F706-8A91-4E8F-B6B0-BA70F1DAE26C@gmail.com> Message-ID: >>> I might keep in mind there is still? >>> https://bitbucket.org/infinitekind/appbundler >> >> If it's truly a fork of AppBundler then it doesn't use it. AppBundler has it's own launcher code, the executable it produces is also called JavaAppLauncher (and may have been based on this). The Java class uses a different package, so it doesn't rely on JavaAppLauncher in rt.jar. >> >> I've yet to find any actual uses of JavaAppLauncher... it was part of the initial port but the native portion is not built (except for the native methods in apple.launcher.JavaAppLauncher which is in osxlib.dylib). None of it has been touched since then except to change copyright dates. > > As I remember there was an early port version of JavaAppLauncher that was supported by Mike Swingler. I may have a copy pulled of that somewhere. Then there was the Scott Kovatch and Greg Brown AppBundler project which came out with an Oracle sponsored version of JavaAppLauncher. The infinitekind project was forked off of that. If you are referring to the first pass Mike Swingler supported code I would say there is probably no use of that by anyone at this point, except maybe the copy I pulled which I'm not even using. Mike Swingler could probably tell you more. I asked Mike offline before polling the list, whatever's in the JDK source is unused by anything on the Oracle side. I think it's just carry over from the JarBundler app that Apple had for Java 6 that we never implemented. -DrD- From mik3hall at gmail.com Tue Jul 1 21:24:26 2014 From: mik3hall at gmail.com (Michael Hall) Date: Tue, 1 Jul 2014 16:24:26 -0500 Subject: JavaAppLauncher In-Reply-To: References: <4C17A649-C279-4007-AD6A-53650E30361B@oracle.com> <98B8F706-8A91-4E8F-B6B0-BA70F1DAE26C@gmail.com> Message-ID: On Jul 1, 2014, at 10:44 AM, David DeHaven wrote: > I asked Mike offline before polling the list, whatever's in the JDK source is unused by anything on the Oracle side. I think it's just carry over from the JarBundler app that Apple had for Java 6 that we never implemented. It seems like you should be reasonably safe getting rid of it. Michael Hall trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter From hs at tagtraum.com Sat Jul 5 20:22:16 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Sat, 5 Jul 2014 22:22:16 +0200 Subject: Spawning a process from an app packaged with AppBundler impossible Message-ID: Hi, obviously this is not the AppBundler support list, but I hope you humor me and perhaps are able to help. I'm working on an application using the infinitekind AppBundler port (https://bitbucket.org/infinitekind/appbundler). From within the application I'm trying to spawn another process like this: Runtime.getRuntime().exec("/bin/echo"); This works fine when I launch the application with the regular java command. But when I use the AppBundler launcher, I get this: java.io.IOException: Cannot run program "/bin/echo": error=0, spawn failed at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042) at java.lang.Runtime.exec(Runtime.java:620) at java.lang.Runtime.exec(Runtime.java:450) at java.lang.Runtime.exec(Runtime.java:347) at com.tagtraum.spawn.Main.main(Main.java:21) Caused by: java.io.IOException: error=0, spawn failed at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.(UNIXProcess.java:185) at java.lang.ProcessImpl.start(ProcessImpl.java:134) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023) ... 4 more Do you guys have perhaps any idea what's going wrong here? Thank you! -hendrik From mik3hall at gmail.com Sun Jul 6 00:06:29 2014 From: mik3hall at gmail.com (Michael Hall) Date: Sat, 5 Jul 2014 19:06:29 -0500 Subject: Spawning a process from an app packaged with AppBundler impossible In-Reply-To: References: Message-ID: <7D461FD9-2F49-46A6-BCEE-5DD6BF8433EB@gmail.com> On Jul 5, 2014, at 3:22 PM, Hendrik Schreiber wrote: > Runtime.getRuntime().exec("/bin/echo"); exec /bin/echo foo foo Runtime exec works fine from my (non-infinitekind) AppBundler java shell application. Michael Hall trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter From mik3hall at gmail.com Sun Jul 6 00:42:14 2014 From: mik3hall at gmail.com (Michael Hall) Date: Sat, 5 Jul 2014 19:42:14 -0500 Subject: Spawning a process from an app packaged with AppBundler impossible In-Reply-To: References: Message-ID: <70B92FCF-CD7C-4F37-938A-48686A4659E8@gmail.com> On Jul 5, 2014, at 3:22 PM, Hendrik Schreiber wrote: > Runtime.getRuntime().exec("/bin/echo"); I tried it a little more like you did. I'm not seeing results but I'm not seeing exceptions either. dojava try { java.lang.Runtime.getRuntime().exec("/bin/echo"); } catch (java.io.IOException ioex) { ioex.printStackTrace(); } dojava: done dojava try { java.lang.Runtime.getRuntime().exec(new String[] {"/bin/echo","foo"}); } catch (java.io.IOException ioex) { ioex.printStackTrace(); } dojava: done Michael Hall trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter From hs at tagtraum.com Sun Jul 6 08:13:54 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Sun, 6 Jul 2014 10:13:54 +0200 Subject: Spawning a process from an app packaged with AppBundler impossible In-Reply-To: <70B92FCF-CD7C-4F37-938A-48686A4659E8@gmail.com> References: <70B92FCF-CD7C-4F37-938A-48686A4659E8@gmail.com> Message-ID: <8A03A2B6-1EB2-48EA-910B-43617C698D50@tagtraum.com> On Jul 6, 2014, at 2:42, Michael Hall wrote: > On Jul 5, 2014, at 3:22 PM, Hendrik Schreiber wrote: > >> Runtime.getRuntime().exec("/bin/echo"); > > I tried it a little more like you did. I'm not seeing results but I'm not seeing exceptions either. Thanks for checking, Michael. In my setup I use the regular Ant copy task to copy the JRE into my bundle. As it turns out, in .../Content/Home/jre/lib is a file called "jspawnhelper" and it has to be executable for Runtime.getRuntime().exec(...) to work. In my case it wasn't, because Ant unfortunately swallows permissions :-( Cheers, -hendrik From mik3hall at gmail.com Sun Jul 6 09:35:51 2014 From: mik3hall at gmail.com (Michael Hall) Date: Sun, 6 Jul 2014 04:35:51 -0500 Subject: Spawning a process from an app packaged with AppBundler impossible In-Reply-To: <8A03A2B6-1EB2-48EA-910B-43617C698D50@tagtraum.com> References: <70B92FCF-CD7C-4F37-938A-48686A4659E8@gmail.com> <8A03A2B6-1EB2-48EA-910B-43617C698D50@tagtraum.com> Message-ID: On Jul 6, 2014, at 3:13 AM, Hendrik Schreiber wrote: > Thanks for checking, Michael. > > In my setup I use the regular Ant copy task to copy the JRE into my bundle. > > As it turns out, in .../Content/Home/jre/lib is a file called "jspawnhelper" and it has to be executable for Runtime.getRuntime().exec(...) to work. > In my case it wasn't, because Ant unfortunately swallows permissions :-( I haven't had to worry about it or use it for a while but 'ditto' used to be a reliable OS X file copier. I think I originally got it from Carbon Copy Cloner which was shareware that could back up an entire machine. man ditto shows it's still around. Michael Hall trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter From hs at tagtraum.com Sun Jul 6 09:38:56 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Sun, 6 Jul 2014 11:38:56 +0200 Subject: Spawning a process from an app packaged with AppBundler impossible In-Reply-To: References: <70B92FCF-CD7C-4F37-938A-48686A4659E8@gmail.com> <8A03A2B6-1EB2-48EA-910B-43617C698D50@tagtraum.com> Message-ID: <4265B27E-A550-46F8-B05C-3E6F9F0F3E7F@tagtraum.com> On Jul 6, 2014, at 11:35, Michael Hall wrote: > On Jul 6, 2014, at 3:13 AM, Hendrik Schreiber wrote: > >> In my case it wasn't, because Ant unfortunately swallows permissions :-( > > I haven't had to worry about it or use it for a while but 'ditto' used to be a reliable OS X file copier. > > > > > > > > > I think I originally got it from Carbon Copy Cloner which was shareware that could back up an entire machine. > man ditto > shows it's still around. also does the trick. One only has to figure out that it is necessary... -hendrik From mik3hall at gmail.com Sun Jul 6 09:56:28 2014 From: mik3hall at gmail.com (Michael Hall) Date: Sun, 6 Jul 2014 04:56:28 -0500 Subject: Spawning a process from an app packaged with AppBundler impossible In-Reply-To: <4265B27E-A550-46F8-B05C-3E6F9F0F3E7F@tagtraum.com> References: <70B92FCF-CD7C-4F37-938A-48686A4659E8@gmail.com> <8A03A2B6-1EB2-48EA-910B-43617C698D50@tagtraum.com> <4265B27E-A550-46F8-B05C-3E6F9F0F3E7F@tagtraum.com> Message-ID: <66F20754-CFBF-41D8-AB9F-AE06F5D6A96C@gmail.com> On Jul 6, 2014, at 4:38 AM, Hendrik Schreiber wrote: > also does the trick. One only has to figure out that it is necessary... I had code at one point that would check application bundles for known issues and either report or fix them. But there weren't enough issues or enough interest in the code to maintain it on an ongoing basis. Michael Hall trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter From alexandr.scherbatiy at oracle.com Tue Jul 8 15:02:27 2014 From: alexandr.scherbatiy at oracle.com (Alexander Scherbatiy) Date: Tue, 08 Jul 2014 19:02:27 +0400 Subject: [OpenJDK 2D-Dev] [9] Review request for 8029339 Custom MultiResolution image support on HiDPI displays In-Reply-To: <53987361.5040903@oracle.com> References: <52D51764.8020103@oracle.com> <52DF2F98.3030503@oracle.com> <52F4BCEB.9040702@oracle.com> <52F5782A.9060300@oracle.com> <52FB7E3E.6050000@oracle.com> <52FC14EC.9080503@oracle.com> <53037D3D.80709@oracle.com> <5307E71E.50607@oracle.com> <530F3592.40600@oracle.com> <532B00AD.1000704@oracle.com> <532B7EC5.9000206@oracle.com> <532C4DD7.1080804@oracle.com> <532CD202.5070508@oracle.com> <53302A8E.6090107@oracle.com> <53343914.6090004@oracle.com> <533C8DDB.5000406@oracle.com> <533E9D42.10409@oracle.com> <53598D86.5020607@oracle.com> <535A7509.6050802@oracle.com> <5370DC41.5080608@oracle.com> <537639D5.9000206@oracle.com> <53764700.2060309@oracle.com> <5379E117.6010202@oracle.com> <538F2D56.80609@oracle.com> <5396220E.9030708@oracle.com> <5397180C.5040105@oracle.com> <53987361.5040903@oracle.com> Message-ID: <53BC0803.6090704@oracle.com> Hi Phil, Could you review the fix? Thanks, Alexandr. On 6/11/2014 7:18 PM, Alexander Scherbatiy wrote: > > Hi Phil , > > I just prepared a simple FAQ about the Custom MultiResolution image > API. Hope it will be helpful. > > 1. Scale naming convention for high-resolution images. > > Different OSes use different "scale" naming convention for > high-resolution images: > Mac OS X: image.ext, image at 2x.ext > Windows: image.scale-100.ext, image.scale-140.ext, image.scale-180.ext > > Q: Does "scale" naming convention supported in JDK? > A: Mac OS X "scale" naming convention are supported in JDK 8u20 (see > JDK-8011059) > It is planned to support the Windows "scale" naming convention > as well. > > Q. How does it work in JDK? > A. Bundle image.ext and image at 2x.ext images with your app on Mac OS X > and call Toolkit.getImage(...) method: > Image image = Toolkit.getDefaultToolkit().getImage("image.ext"); > Graphics2D g2d = // get graphics > g2d.drawImage(image, 0, 0, null) > SunGraphics2D automatically queries and draws the provided > high-resolution image. > > Q: There are different "scale" naming conventions on Mac OS X and > Windows. > May be it is better to have unified "scale" naming conventions > for all OSes in Java like image[java-scale-Nx].ext? > A: It seems reasonable and can be filled as a new JDK enhancement. > > Q: Does using "scale" naming conventions solves all problems. > A: There are tasks like image processing/programmatically generated > images/loading images from non-standard sources > that can't be solved with predefined set of images. > Q: Are there any tools that support these tasks? > A: Cocoa API contains NSImage that allows to work with image > representations: addRepresentation/removeRepresentation/representations > JDK uses these methods to get/set multi-resolution images for > the Native system (see sun.lwawt.macosx.CImage class). > > 2. Graphics2D > Q: How SunGraphics2D deals with multi-resolution images? > A: SunGraphics2D queries a resolution variant using DPI scale factors > and transformed base image sizes > // logicalDPIX, logicalDPIY - DPI scale factors > // destImageWidth, destImageHeight - transformed base image > sizes including DPI scale factors > multiResolutionImage.getResolutionVariant(logicalDPIX, > logicalDPIY, destImageWidth, destImageHeight); > > Q: Which algorithm multi-resolution image is used in > getResolutionVariant(...) method? > A: ToolkitImage returned by toolkit.loadImage() method should behave > like the native system. > It means that it should use transformed image sizes on Mac OS X > and only DPI scale factors on Windows. > it looks like: > ----------------- > // logicalDPIX, logicalDPIY - DPI scale factors > // destImageWidth, destImageHeight - transformed base image > sizes including DPI scale factors > public Image getResolutionVariant(float logicalDPIX, float > logicalDPIY, > float destImageWidth, float destImageHeight) { > if (Mac OS X) { > return resolution variant best fitted to the > destImageWidth and destImageHeight > } else if (Windows){ > return resolution variant best fitted to the > logicalDPIX and logicalDPIY scale factors > } > } > ----------------- > > 3. Custom multi-resolution image. > Q: The custom multi-resolution image should be able to return an > image according to the requested > transformed image size and DPI scale factors. Is it enough? > A: There are task like setting custom cursor that require to get all > resolution variants. > So the custom multi-resolution image should also contain the > getResolutionVariants(): > > Q: Should the custom multi-resolution image be class or interface? > A: There is ToolkitImage that should also have resolution variants. > It is not possible to extend it from MultiResolutionImage class. > The current proposal introduces the MultiResolutionImage as an > interface. > > Q: MultiResolutionImage interface sounds strange for me. > A: The better name can be suggested. > > Q: What does the Custom MultiResolution image API suggest? > A: The current proposal provides MultiResolutionImage interface > with the following methods: > --------------------------- > Image getResolutionVariant(float logicalDPIX, float logicalDPIY, > float destImageWidth, float destImageHeight); > > List getResolutionVariants(); > --------------------------- > and AbstractMultiResolutionImage class. See samples below. > > > 4. Memory cost > Q: Can the the implementation be "lazy"? > A: SunGraphics2D does not require full list of resolution variants. > It queries only the image with necessary resolution. > It means that resolution variants can be loaded by demand. > Setting a custom cursor requires all resolution variants. > > 5. Rendering hints. > Q: Why rendering hints are added. > A: Provided rendering hints affects only multi-resolution images and > allows to disable > resolution variants usage in app. It can be useful for > performance reasons. > > 6. Samples. > Q: It is interesting to look at samples. > A: Below are 3 samples: > 1. Draw an image with "Hello World!" text > 2. Set a lightened custom cursor > 3. Draw a multi-resolution image created from the program > > Sample 1. Draw a image with "Hello World!" text. The text is drawn > both on the base image and on high-resolution image. > disk: duke.png, duke at 2x.png > ------------------------------- > public static void main(String[] args) { > > Image image = > Toolkit.getDefaultToolkit().getImage("duke.png"); // duke.png and > duke at 2x.png images are loaded by MR-ToolkitImage > > Image imagewithText = image instanceof MultiResolutionImage > ? new TextMultiresolutionImage(image) : drawText(image); > > Graphics2D g2d = // get graphics 2D > g2d.drawImage(imagewithText, x, y, null); > } > > static Image drawText(Image image) { > // return an image with "Hello World!" text > } > > static class TextMultiresolutionImage extends > AbstractMultiResolutionImage { > > private final Image baseImage; > > public TextMultiresolutionImage(Image baseImage) { > this.baseImage = baseImage; > } > > @Override > public Image getResolutionVariant(float logicalDPIX, float > logicalDPIY, > float destImageWidth, float destImageHeight) { > Image rvImage = ((MultiResolutionImage) baseImage). > getResolutionVariant(logicalDPIX, logicalDPIY, > destImageWidth, destImageHeight); > return drawText(rvImage); > } > > @Override > public List getResolutionVariants() { > // this method is not used by SunGraphics2D to draw the > image. > // we just skip it in this example > } > > @Override > protected Image getBaseImage() { > return drawText(baseImage); > } > } > ------------------------------- > > Sample 2. Using filters to create a lightened custom cursor. > The filter is applied to both the base and high-resolution image. > ------------------------------- > public static void main(String[] args) { > > Image image = > Toolkit.getDefaultToolkit().getImage("cursor.png"); // cursor.png and > cursor at 2x.png files are provided > Image lightenedImage = image instanceof MultiResolutionImage > ? new LigtenedMultiresolutionImage(image) : > applyFilter(image); > > Cursor lightenedCursor = Toolkit.getDefaultToolkit(). > createCustomCursor(lightenedImage, new Point(0, 0), > "Lightened Cursor"); > JFrame frame = new JFrame("Frame with lightened cursor"); > frame.setCursor(lightenedCursor); > } > > static Image applyFilter(Image image) { > GrayFilter filter = new GrayFilter(true, 50); > final ImageProducer prod = new > FilteredImageSource(image.getSource(), filter); > return Toolkit.getDefaultToolkit().createImage(prod); > } > > static class LigtenedMultiresolutionImage extends > AbstractMultiResolutionImage { > > private final Image baseImage; > > public LigtenedMultiresolutionImage(Image baseImage) { > this.baseImage = baseImage; > } > > @Override > public Image getResolutionVariant(float logicalDPIX, float > logicalDPIY, > float destImageWidth, float destImageHeight) { > // this method is not necessary for the custom cursor > creation > // we just skip it > } > > // all resolution variants are created to pass them to NSImage > for the custom cursor on Mac OS X. > @Override > public List getResolutionVariants() { > List resolutionVariants = new LinkedList<>(); > for (Image rvImage : ((MultiResolutionImage) baseImage). > getResolutionVariants()) { > resolutionVariants.add(applyFilter(rvImage)); > } > return resolutionVariants; > } > > @Override > protected Image getBaseImage() { > return applyFilter(baseImage); > } > } > ------------------------------- > > Sample 3. Draw a multi-resolution image created from the program: > ------------------------------- > public static void main(String[] args) { > > Image image = generateImage(1); > Image image2x = generateImage(2); > Image mrImage = new CustomMultiresolutionImage(image, image2x); > > Graphics2D g2d = // get graphics2D > g2d.drawImage(mrImage, 0, 0, null); > } > > static Image generateImage(float scaleFactor) { > // generate image according to the scale factor > } > > static class CustomMultiresolutionImage extends > AbstractMultiResolutionImage { > > private final Image image; > private final Image highResolutionImage; > > public CustomMultiresolutionImage(Image baseImage, Image > highResolutionImage) { > this.image = baseImage; > this.highResolutionImage = highResolutionImage; > } > > @Override > public Image getResolutionVariant(float logicalDPIX, float > logicalDPIY, > float destImageWidth, float destImageHeight) { > // destImageWidth and destImageHeight includes both > transforms > // DPI scale factors from Graphics > if (destImageWidth <= image.getWidth(null) > && destImageHeight <= image.getHeight(null)) { > return image; > } > return highResolutionImage; > } > > @Override > public List getResolutionVariants() { > return Arrays.asList(image, highResolutionImage); > } > > @Override > protected Image getBaseImage() { > return image; > } > } > ------------------------------- > Thanks, > Alexandr. > > > On 6/10/2014 6:37 PM, Alexander Scherbatiy wrote: >> On 6/10/2014 1:07 AM, Phil Race wrote: >>> Why the split ? >>> If you look only at the first part. If you can do that then why is >>> the 2nd part needed ? >> The second part introduces algorithms that can be used to retrieve >> a resolution variant >> from a set of images. It can be DPI based, transform based, OS >> based and so on. >> The first part can be implemented without the second part. >> >>> The name "MultiResolutionImage" implies to me that this is a >>> sub-class of Image. >>> But its not, its a way to get images. AbstractMultiResolutionImage, >>> however is >>> a subclass and it implements the former. >> >> Could you suggest the better name? It really needs to have an >> interface if existed image implementation >> is supposed to have resolution variants. The example which is used >> in JDK is ToolkitImage. >> Toolkit.getImage(filename) method returns ToolkitImage which is >> loaded by demand. >> LWCToolkit should return an image with resolution variants on Mac >> OS X if both image and image at 2x >> are provided. What we need here is the ToolkitImage that contains >> resolution variants. >> It can be done if the MultiResolutionImage is an interface and it >> is not possible to do if MultiResolutionImage is a class. >> Here is the MultiResolutionToolkitImage implementation: >> http://hg.openjdk.java.net/jdk9/client/jdk/file/b7ef5e2d252c/src/share/classes/sun/awt/image/MultiResolutionToolkitImage.java >> >> >>> I am supposing (since you don't explain) that you want an Image >>> sub-class here >>> so that the app can specify it where ever an Image is currently >>> accepted by API >>> and the API that is "aware" can accept it. >> If an image implements the MultiResolutionImage interface, >> SunGraphics2D can use it >> to draw an image with necessary resolution on HiDPI display. >> >>> I worry about the memory cost of all of this. Can the the >>> implementation be "lazy"? >> Yes. See the MultiResolutionCachedImage implementation: >> http://hg.openjdk.java.net/jdk9/client/jdk/file/b7ef5e2d252c/src/share/classes/sun/awt/image/MultiResolutionCachedImage.java >> >>> ie even if I call getResolutionVariants() do those images all have >>> to be fully initialised before >>> they are used? It looks like the app probably has to do so .. >> If it needs to pass resolution variants to the native system like >> setting a custom cursor on Mac OS X >> it really needs to initialize all resolution variants. >> >> If it needs to create one multi-resolution image based on >> another multi-resolution image like >> generating a lightening image using a filter, it possible to do >> this lazy. >> See the map(Function mapper) method in the >> MultiResolutionCachedImage. >> >> SunGraphics2D class uses only getResolutionVariant( ...) method to >> retrieve necessary resolution variant. >> It does not call getResolutionVariants() methods so all resolution >> variants are not created during image drawing. >> >>> >>> Also it precludes being able to return "on demand" an image that is >>> rendered to >>> be exactly the size requested. That could be created, drawn using >>> graphics primitives >>> and created precisely and only if needed. >>> >>> Instead we have an API that requires you to apparentlty eagerly >>> create even the >>> highest res image when you are on a device that has no need for it. >>> >>> Who will actually call getResolutionVariants() ? >> Both. >>> Is it us (the implementation) because we >> We use it to create an NSImage from a custom cursor. See >> Toolkit.createCustomCursor() >> and CImage.createFromImage(final Image image) methods. >> >> Developers can use it to show all resolution variants in some >> image tool. >> >>> don't trust the app to make the right selection based on the >>> parameterised call >>> getResolutionVariant() ? >> As it shown, the getResolutionVariant(...) and >> getResolutionVariants() methods are used >> for different purposes. >> getResolutionVariant(...) method is used by SunGraphics2D class to >> pickup an image >> with necessary resolution variant. >> getResolutionVariants() method is used when an application needs >> to use all resolution variants. >> >>> >>> Which approach do we use to pick the image ? If its the former, the >>> app controls it, >> It is the former. >> We also use it MR-ToolkitImage to get a resolution variant >> according to the current system (for example, transforms >> are included to get resolution variant size on Mac OS X). >> >>> if its the latter its us. But which ? >>> >>> I am still stuck on the parameters to getResolutionVariant >>> >>> * @param baseImageWidth the width of the base image. >>> >>> >>> Isn't the base image always the smallest ? >> No for general case. May be it would be possible to print a >> multi-resolution image >> on a printer that can have low DPI. >> >>> Why are we, the caller, supposed >>> to say what that size to the class that has that image. >> >> This question has already had long discussion. The answer is that >> we do it because it is free for us. >> SunGraphics2D already gets the base image size because it uses it >> for resolution image size calculation. >> If you have objections against this, let's remove the base image >> size parameters. >> Developer always can obtain this information calling >> getWidth()/Height() methods. >> >>> So I'd really like to see the example of that method in >>> CustomMultiResolutionImage >>> filled out so we can see what is imagined here .. >> >> Below are two samples. >> The first one loads a multi-resolution image from disk, and >> writes text "Hello World!" on it. Only getResolutionVariant(...) >> method is used >> by system in SunGraphics2D. The getResolutionVariants() method is >> not used. >> >> The second one creates a lightened custom cursor. The >> getResolutionVariants() method is called by system to create NSImage >> with necessary image representations. >> >> Note that Toolkit.getImage(filename) method is already able to >> load both image and image at 2x images on Mac OS X. >> >> Sample 1. Draw an image with "Hello World!" text: >> disk: duke.png, duke at 2x.png >> ------------------------------- >> public static void main(String[] args) { >> >> Image image = >> Toolkit.getDefaultToolkit().getImage("duke.png"); // duke.png and >> duke at 2x.png images are loaded by MR-ToolkitImage >> >> Image imagewithText = image instanceof MultiResolutionImage >> ? new TextMultiresolutionImage(image) : drawText(image); >> >> Graphics2D g2d = // get graphics 2D >> g2d.drawImage(imagewithText, x, y, null); >> } >> >> static Image drawText(Image image) { >> // return an image with "Hello World!" text >> } >> >> static class TextMultiresolutionImage extends >> AbstractMultiResolutionImage { >> >> private final Image baseImage; >> >> public TextMultiresolutionImage(Image baseImage) { >> this.baseImage = baseImage; >> } >> >> @Override >> public Image getResolutionVariant(float destImageWidth, float >> destImageHeight) { >> Image rvImage = ((MultiResolutionImage) baseImage). >> getResolutionVariant(destImageWidth, >> destImageHeight); >> return drawText(rvImage); >> } >> >> // this method is not used by SunGraphics2D to draw the image >> @Override >> public List getResolutionVariants() { >> List resolutionvariants = new LinkedList<>(); >> for (Image image : ((MultiResolutionImage) baseImage). >> getResolutionVariants()) { >> resolutionvariants.add(drawText(image)); >> } >> return resolutionvariants; >> } >> >> @Override >> protected Image getBaseImage() { >> return drawText(baseImage); >> } >> } >> ------------------------------- >> >> Sample 2. Using filters to create a lightened custom cursor. >> ------------------------------- >> public static void main(String[] args) { >> >> Image image = >> Toolkit.getDefaultToolkit().getImage("cursor.png"); // cursor.png and >> cursor at 2x.png files are provided >> Image lightenedImage = image instanceof MultiResolutionImage >> ? new LigtenedMultiresolutionImage(image) : >> applyFilter(image); >> >> Cursor lightenedCursor = Toolkit.getDefaultToolkit(). >> createCustomCursor(lightenedImage, new Point(0, 0), >> "Lightened Cursor"); >> JFrame frame = new JFrame("Frame with lightened cursor"); >> frame.setCursor(lightenedCursor); >> } >> >> static Image applyFilter(Image image) { >> // apply a filter to create ligtened image >> } >> >> static class LigtenedMultiresolutionImage extends >> AbstractMultiResolutionImage { >> >> private final Image baseImage; >> >> public LigtenedMultiresolutionImage(Image baseImage) { >> this.baseImage = baseImage; >> } >> >> @Override >> public Image getResolutionVariant(float destImageWidth, float >> destImageHeight) { >> Image rvImage = ((MultiResolutionImage) baseImage). >> getResolutionVariant(destImageWidth, >> destImageHeight); >> return applyFilter(rvImage); >> } >> >> // all resolution variants are created to pass them to NSImage >> @Override >> public List getResolutionVariants() { >> List resolutionvariants = new LinkedList<>(); >> for (Image image : ((MultiResolutionImage) baseImage). >> getResolutionVariants()) { >> resolutionvariants.add(applyFilter(image)); >> } >> return resolutionvariants; >> } >> >> @Override >> protected Image getBaseImage() { >> return applyFilter(baseImage); >> } >> } >> ------------------------------- >>> >>> Based solely on the usage I see here, its not clear why >>> MultiResolutionImage needs >>> to separately exist. what would implement MultiResolutionImage >>> except for >>> a class that extends AbstractMultiResolutionImage ? Where would you >>> use >>> a straight implementation of MultiResolutionImage ? >> See sun.awt.image.MultiResolutionToolkitImage in JDK 9. Both >> ToolkitImage and MultiResolutionImage should be used in this case. >> >>> >>> Actually I am not sure you answered Jim's question as to who is >>> requesting these APIs. >>> "The AWT team" doesn't need them as they won't be writing the apps. >> >> There was a long thread about the image with sub-pixel resolution >> drawing on Mac OS X: >> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005559.html >> >> >> It was pointed out that Icon images that can be programmatically >> generated also need to have HiDPI support: >> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005566.html >> >> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005569.html >> >> >> All requests about Mac OS X HiDPI support were included to the >> umbrella issue: >> 7124410 [macosx] Lion HiDPI support >> https://bugs.openjdk.java.net/browse/JDK-7124410 >> >>> >>> If the 99% use case will be to provide a way for apps to provide >>> images at custom sizes >>> then we seem to be making them write new code. SFAIK FX found a way >>> to do something >>> similar to what OS X and Windows do which is to load based on file >>> name convention. >> JDK 8 have already loaded images with @2x name convention on >> Mac OS X. >> See the fix for the issue JDK-8011059 [macosx] Support >> automatic @2x images loading on Mac OS X >> https://bugs.openjdk.java.net/browse/JDK-8011059 >>> If we can do that, we load just the one we need. Is the point >>> of use so far removed from the loading logic that we can't do this ? >> >> Mac OS X has both ways to create images: using @2x name >> convention for files >> and NSImage with methods >> addRepresentation/removeRepresentation/representations. >> >> The current API is proposed to dial with images that can have >> source that is different from files. >> It is also used to process already loaded images. >> See the provided two samples with lightened custom cursor and >> text on image. >> Is it possible to write the same samples on JavaFX? >> >>> And none of this seems to help anyone who calls new BufferedImage(w, >>> h, type) .. >> >> Yes. It needs to create a BufferedImage for each screen resolution >> and put them to a multi-resolution image. >> >>> >>> BTW I am not sold on the need for the RenderingHint. Where did the >>> idea come from ? >>> It would affect all rendering using that graphics instance, not just >>> a specific image and >>> if someone doesn't want a MultiRes image used, then maybe they just >>> don't provide one .. >> >> KEY_RESOLUTION_VARIANT is used to switch on/off resolution >> variants usage. >> VALUE_RESOLUTION_VARIANT_ON - SunGraphics2D queries resolution >> variants from multi-resolution image on HiDPI displays. >> VALUE_RESOLUTION_VARIANT_OFF - SunGraphics2D does not use >> resolution variants. Only base image is used. >> >>> In any case, without a solid demonstrated need I would not add the API. >>> >> See provided 2 samples. >> >> Thanks, >> Alexandr. >>> >>> -phil. >>> >>> On 6/4/2014 7:29 AM, Alexander Scherbatiy wrote: >>>> >>>> Hi Phil, >>>> >>>> Could you review the fix where only new MultiResolutionImage >>>> interface and AbstractMultiResolutionImage class are added: >>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.05/ >>>> >>>> Thanks, >>>> Alexandr. >>>> >>>> >>>> On 5/19/2014 2:46 PM, Alexander Scherbatiy wrote: >>>>> >>>>> Hi Phil, >>>>> >>>>> On 5/16/2014 9:12 PM, Phil Race wrote: >>>>>> I think Jim was looking at this. I am not sure if you yet >>>>>> answered all his questions/concerns. >>>>>> >>>>>> There's a lot of API here and it will take more time than I have >>>>>> right now just to get >>>>>> my head around it so do not expect a quick answer. >>>>>> >>>>>> 1. Why is there no javadoc on the new API on Toolkit ? >>>>> It was decided to split the original issue on two parts: >>>>> - this fix adds only MultiResolutionImage interface and >>>>> AbstractMultiResolutionImage class. >>>>> Here is the webrev for it: >>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.05/ >>>>> - the Toolkit related API is moved to the separate issue >>>>> >>>>> Could you review the current fix: >>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.05/ >>>>> >>>>>> 2. What kinds of classes are expected to implement >>>>>> MultiResolutionImage >>>>>> Application ones or platform ones ? >>>>> Both. >>>>> - Application: A developer can provide a set of images with >>>>> different resolutions to create a multi-resolution image. An image >>>>> with best-fitting resolution >>>>> will be drawn on HiDPI display. >>>>> - Platform: we used it to support Aqua L&F on HiDPI displays. >>>>> >>>>>> 3. can you better explain all these parameters : >>>>>> >>>>>> 49 * @param logicalDPIX the logical horizontal DPI of the >>>>>> desktop. >>>>>> 50 * @param logicalDPIY the logical vertical DPI of the >>>>>> desktop. >>>>>> 51 * @param baseImageWidth the width of the base image. >>>>>> 52 * @param baseImageHeight the height of the base image. >>>>>> 53 * @param destImageWidth the width of the destination >>>>>> image. >>>>>> 54 * @param destImageHeight the height of the destination >>>>>> image. >>>>>> 55 * @return image resolution variant. >>>>> >>>>> Could we postpone it to the CCC request? >>>>> >>>>>> >>>>>> 4. public List getResolutionVariants(); >>>>>> >>>>>> So this implies a fixed, known ahead of time set of images ? >>>>>> Why is it required to have this API ? How will anyone be able to >>>>>> tell which is which and use the list ? >>>>> >>>>> Here are some usages from the JDK code: >>>>> - AquaImagefactory.getAppIconCompositedOn(final Image background) >>>>> The original multi-resolution image is used to create >>>>> another multi-resolution image with the background >>>>> - AquaUtils.generateLightenedImage(Image image, ImageFilter >>>>> filter) >>>>> The original multi-resolution image is used to create >>>>> lightening multi-resolution image >>>>> - CImage.createFromImage(final Image image) >>>>> Resolution variants from a multi-resolution image are used >>>>> to create an NSImage >>>>> - CCustomCursor: it is possible set a custom cursor which >>>>> contains resolution variants to the native system >>>>> >>>>> Usually the getResolutionVariants() method is used to create >>>>> one multi-resolution image based on the another multi-resolution >>>>> image. >>>>> >>>>>> 5. Why is the rendering hint needed ? >>>>> Someone can manually switch off the multi-resolution image >>>>> drawing from graphics so only the base image will be drawn. >>>>> It is useful for the performance reason. There is a choice >>>>> to draw the high-resolution image slowly or the low-resolution >>>>> image faster. >>>>> >>>>> Thanks, >>>>> Alexandr. >>>>>> -phil. >>>>>> >>>>>> >>>>>> On 5/16/2014 9:16 AM, Alexander Scherbatiy wrote: >>>>>>> >>>>>>> Hi Phil, >>>>>>> >>>>>>> I need a reviewer from the 2d group for the fix. Could you >>>>>>> take a look at the fix and review it? >>>>>>> >>>>>>> Thanks, >>>>>>> Alexandr. >>>>>>> >>>>>>> >>>>>>> On 5/12/2014 6:35 PM, Alexander Scherbatiy wrote: >>>>>>>> >>>>>>>> There was a long thread about the image with sub-pixel >>>>>>>> resolution drawing on Mac OS X: >>>>>>>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005559.html >>>>>>>> >>>>>>>> >>>>>>>> It was pointed out that Icon images that can be >>>>>>>> programmatically generated also need to have HiDPI support: >>>>>>>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005566.html >>>>>>>> >>>>>>>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005569.html >>>>>>>> >>>>>>>> >>>>>>>> All requests about Mac OS X HiDPI support were included to the >>>>>>>> umbrella issue: >>>>>>>> 7124410 [macosx] Lion HiDPI support >>>>>>>> https://bugs.openjdk.java.net/browse/JDK-7124410 >>>>>>>> >>>>>>>> Thanks, >>>>>>>> Alexandr. >>>>>>>> >>>>>>>> On 4/25/2014 6:45 PM, Alexander Scherbatiy wrote: >>>>>>>>> On 4/25/2014 2:17 AM, Jim Graham wrote: >>>>>>>>>> Hi Alexandr, >>>>>>>>>> >>>>>>>>>> I asked for who was requesting these facilities and you >>>>>>>>>> responded with the solution you are planning to provide. >>>>>>>>>> >>>>>>>>>> I don't care what the solution looks like if we have nobody >>>>>>>>>> asking for the feature - I am asking who is asking for these >>>>>>>>>> capabilities? >>>>>>>>> >>>>>>>>> This is the request from the AWT team for the HiDPI support. >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Alexandr. >>>>>>>>>> >>>>>>>>>> ...jim >>>>>>>>>> >>>>>>>>>> On 4/4/14 4:53 AM, Alexander Scherbatiy wrote: >>>>>>>>>>> On 4/3/2014 2:23 AM, Jim Graham wrote: >>>>>>>>>>>> Hi Alexandr, >>>>>>>>>>>> >>>>>>>>>>>> The back and forth is getting confusing here, so I thought >>>>>>>>>>>> I'd try to >>>>>>>>>>>> summarize and start fresh(ish): >>>>>>>>>>>> >>>>>>>>>>>> 1. We need to support @2x internally for MacOS >>>>>>>>>>>> compatibility (done). >>>>>>>>>>>> >>>>>>>>>>>> 2. We will need to support _DPI images for Win-DPI >>>>>>>>>>>> compatibility (TBD). >>>>>>>>>>>> >>>>>>>>>>>> 3. Customers may have their own collection of images to bundle >>>>>>>>>>>> together into an MR image (working on that here). What is >>>>>>>>>>>> the push >>>>>>>>>>>> for this? Is this simply parity with Mac interfaces? >>>>>>>>>>> >>>>>>>>>>> ---------- >>>>>>>>>>> Image[] resolutionVariants = // get sorted by sizes >>>>>>>>>>> array of >>>>>>>>>>> resolution variants; >>>>>>>>>>> Image mrImage = >>>>>>>>>>> Toolkit.getDefaultToolkit().createMRImage(baseImageIndex, >>>>>>>>>>> resolutionVariants); >>>>>>>>>>> ---------- >>>>>>>>>>> >>>>>>>>>>> Here is the proposed patch: >>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.04/ >>>>>>>>>>> >>>>>>>>>>>> 4. Customers may want to synthetically generate images at >>>>>>>>>>>> arbitrary >>>>>>>>>>>> resolutions (a variation that is impacting this solution). >>>>>>>>>>>> What is >>>>>>>>>>>> the push for this? >>>>>>>>>>> ---------- >>>>>>>>>>> Image mrImage = >>>>>>>>>>> Toolkit.getDefaultToolkit().createMRImage(baseImageWidth, >>>>>>>>>>> baseImageHeight, >>>>>>>>>>> new float[][]{{100, 100}, {150, 150}, {200, >>>>>>>>>>> 200}}, // >>>>>>>>>>> resolution variants sizes >>>>>>>>>>> (rvWidth, rvHeight) -> { /* generate a >>>>>>>>>>> resolution >>>>>>>>>>> variant */ }); >>>>>>>>>>> ---------- >>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> 5. I'm guessing that customers might want to override the >>>>>>>>>>>> logic to >>>>>>>>>>>> choose from among multiple resolutions. That came from me >>>>>>>>>>>> based on >>>>>>>>>>>> seeing Mac and Win using different selection logic and our >>>>>>>>>>>> history of >>>>>>>>>>>> developers split between those wanting cross-platform >>>>>>>>>>>> consistency and >>>>>>>>>>>> those wanting consistency with native apps on each >>>>>>>>>>>> platform. Also, >>>>>>>>>>>> the needs of an animator may differ from the needs of a >>>>>>>>>>>> resolution-settable-document editor as to how dynamically >>>>>>>>>>>> the images >>>>>>>>>>>> shift between resolution variants. >>>>>>>>>>> ---------- >>>>>>>>>>> Image[] resolutionVariants = // get sorted by sizes >>>>>>>>>>> array of >>>>>>>>>>> resolution variants; >>>>>>>>>>> Image mrImage = ImageResolutionHelper.createMRImage( >>>>>>>>>>> (rvWidth, rvHeight, resolutionVariants) -> >>>>>>>>>>> { /*use a >>>>>>>>>>> custom logic to choose a resolution variant from an array of >>>>>>>>>>> images*/}, >>>>>>>>>>> (logicalDPI, baseImageSize, destImageSize) -> >>>>>>>>>>> destImageSize, // calculate the custom aware resolution >>>>>>>>>>> variant size >>>>>>>>>>> baseImageIndex, resolutionVariants); >>>>>>>>>>> ---------- >>>>>>>>>>> >>>>>>>>>>> or just extend the CustomMultiResolutionImage which has >>>>>>>>>>> Image as the >>>>>>>>>>> parent class: >>>>>>>>>>> >>>>>>>>>>> -------------------- >>>>>>>>>>> public class CustomMultiResolutionImage extends >>>>>>>>>>> AbstractMultiResolutionImage { >>>>>>>>>>> >>>>>>>>>>> @Override >>>>>>>>>>> public Image getResolutionVariant(float logicalDPIX, float >>>>>>>>>>> logicalDPIY, >>>>>>>>>>> float baseImageWidth, float baseImageHeight, >>>>>>>>>>> float destImageWidth, float destImageHeight) { >>>>>>>>>>> // return a resolution variant based on the given >>>>>>>>>>> logical DPI, >>>>>>>>>>> // base image size, or destination image size >>>>>>>>>>> } >>>>>>>>>>> >>>>>>>>>>> @Override >>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>> // return a list of resolution variants >>>>>>>>>>> } >>>>>>>>>>> >>>>>>>>>>> @Override >>>>>>>>>>> protected Image getBaseImage() { >>>>>>>>>>> // return the base image >>>>>>>>>>> } >>>>>>>>>>> } >>>>>>>>>>> -------------------- >>>>>>>>>>>> >>>>>>>>>>>> Is that a fair summary of all of the considerations so far, >>>>>>>>>>>> or did I >>>>>>>>>>>> miss something? >>>>>>>>>>> I think it should cover the main needs. >>>>>>>>>>> >>>>>>>>>>> Thanks, >>>>>>>>>>> Alexandr. >>>>>>>>>>>> >>>>>>>>>>>> ...jim >>>>>>>>>>>> >>>>>>>>>>>> On 3/27/14 7:43 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>> >>>>>>>>>>>>> Below are some thoughts about TK.createMRImage(...) method >>>>>>>>>>>>> >>>>>>>>>>>>> On 3/24/2014 4:52 PM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>> >>>>>>>>>>>>>> Could you review the updated fix: >>>>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.03/ >>>>>>>>>>>>>> >>>>>>>>>>>>>> - baseImageWidth/Height arguments are added to the >>>>>>>>>>>>>> getResolutionVariant(...) method >>>>>>>>>>>>>> - dest image sizes are reverted to included DPI scale >>>>>>>>>>>>>> - AbstractMultiResolutionImage is added. It needs only >>>>>>>>>>>>>> to implement >>>>>>>>>>>>>> only 3 methods from the AbstractMultiResolutionImage class >>>>>>>>>>>>>> to create a custom multi-resolution image. For example: >>>>>>>>>>>>>> >>>>>>>>>>>>>> On 3/22/2014 3:57 AM, Jim Graham wrote: >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Your code example below can be expressed as an >>>>>>>>>>>>>>> implementation of the >>>>>>>>>>>>>>> single-method, lambda-compatible interface that >>>>>>>>>>>>>>> expresses just the >>>>>>>>>>>>>>> getRV() method. They could easily do: >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> final Image baseImage = ...; >>>>>>>>>>>>>>> TK.createMRImage(new RVInterface() { >>>>>>>>>>>>>>> public Image getRV(...) { >>>>>>>>>>>>>>> // calculate rvWidth and rvHeight >>>>>>>>>>>>>>> // look up rvWidth/rvHeight in a database of images >>>>>>>>>>>>>>> // possibly contruct a new image >>>>>>>>>>>>>>> return rvImage; >>>>>>>>>>>>>>> } >>>>>>>>>>>>>>> }, baseImage); >>>>>>>>>>>>>>> >>>>>>>>>>>>> The RVInterface mixes the logic that construct an >>>>>>>>>>>>> image and >>>>>>>>>>>>> chooses the necessary resolution variant. >>>>>>>>>>>>> It is ok if a developer always implements this >>>>>>>>>>>>> interface. If it >>>>>>>>>>>>> needs to have DPI/Transform/Platform aware RVInterface the >>>>>>>>>>>>> image >>>>>>>>>>>>> construction logic should be separated. >>>>>>>>>>>>> >>>>>>>>>>>>> Does TK.createMRImage() method implies that Platform >>>>>>>>>>>>> aware logic >>>>>>>>>>>>> should be used for a resolution-variant choosing? >>>>>>>>>>>>> If so, may be general createMRImage() can be placed >>>>>>>>>>>>> in the >>>>>>>>>>>>> ImageResolutionHelper. >>>>>>>>>>>>>>> The main issue I see is if you might want the newly >>>>>>>>>>>>>>> constructed >>>>>>>>>>>>>>> variants to appear in the List returned from the >>>>>>>>>>>>>>> getVariants() >>>>>>>>>>>>>>> method. I'm not sure what value that would have beyond >>>>>>>>>>>>>>> simply >>>>>>>>>>>>>>> returning the base media that the object uses from which >>>>>>>>>>>>>>> to construct >>>>>>>>>>>>>>> its variants...? >>>>>>>>>>>>> >>>>>>>>>>>>> It can be solved by using something like array of image >>>>>>>>>>>>> sizes or >>>>>>>>>>>>> other seeds and a mapper that can create an image from the >>>>>>>>>>>>> given seed. >>>>>>>>>>>>> >>>>>>>>>>>>> It can look like: >>>>>>>>>>>>> ------------------------- >>>>>>>>>>>>> public class ImageResolutionHelper { >>>>>>>>>>>>> public interface RVChooser { >>>>>>>>>>>>> >>>>>>>>>>>>> public Image getRV( >>>>>>>>>>>>> float logicalDPIX, float logicalDPIY, >>>>>>>>>>>>> float baseImageWidth, float baseImageHeight, >>>>>>>>>>>>> float destImageWidth, float destImageHeight, >>>>>>>>>>>>> final Image... resolutionVariants); >>>>>>>>>>>>> } >>>>>>>>>>>>> >>>>>>>>>>>>> public static final RVChooser DPI_AWARE = ...; >>>>>>>>>>>>> public static final RVChooser TRANSFORM_AWARE = ...; >>>>>>>>>>>>> >>>>>>>>>>>>> // resolutionVariants is an array of sorted by >>>>>>>>>>>>> width/height images >>>>>>>>>>>>> static Image createMRImage(final RVChooser rvChooser, >>>>>>>>>>>>> final int baseImageIndex, final Image... >>>>>>>>>>>>> resolutionVariants) { ... } >>>>>>>>>>>>> >>>>>>>>>>>>> // sorted by width/height images should be generated >>>>>>>>>>>>> from seeds >>>>>>>>>>>>> static Image createMRImage(final RVChooser >>>>>>>>>>>>> rvChooser, >>>>>>>>>>>>> final Type baseImageSeed, final >>>>>>>>>>>>> Function >>>>>>>>>>>>> mapper, final Type... rvSeeds) {...} >>>>>>>>>>>>> } >>>>>>>>>>>>> >>>>>>>>>>>>> public abstract class Toolkit { >>>>>>>>>>>>> public abstract Image createMRImage(int >>>>>>>>>>>>> baseImageIndex, Image... >>>>>>>>>>>>> resolutionVariants); // Platform aware rv chooser is used >>>>>>>>>>>>> public abstract RVChooser getPlatformRVChooser() ; >>>>>>>>>>>>> } >>>>>>>>>>>>> -------------------------- >>>>>>>>>>>>> Thanks, >>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> I think it is better to provide both the >>>>>>>>>>>>>>>> MultiResolutionImage >>>>>>>>>>>>>>>> and >>>>>>>>>>>>>>>> its implementation based on the given resolution >>>>>>>>>>>>>>>> variants array. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> It occurs to me that even if we don't go with a >>>>>>>>>>>>>>> lambda-factory-based >>>>>>>>>>>>>>> approach like what I'm describing, it might make sense >>>>>>>>>>>>>>> to provide a >>>>>>>>>>>>>>> baseMR implementation that they can subclass to keep >>>>>>>>>>>>>>> them from trying >>>>>>>>>>>>>>> to subclass off of BufferedImage instead. I really would >>>>>>>>>>>>>>> like to >>>>>>>>>>>>>>> avoid "custom MR images are subclasses of BufImg" if we >>>>>>>>>>>>>>> can as I >>>>>>>>>>>>>>> think the mix of concepts is a little jarring... >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> The implementation could look like: >>>>>>>>>>>>>>>> --------------------------------- >>>>>>>>>>>>>>>> public class CustomMultiResolutionImage extends Image >>>>>>>>>>>>>>>> implements >>>>>>>>>>>>>>>> MultiResolutionImage { >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> int baseImageIndex; >>>>>>>>>>>>>>>> Image[] resolutionVariants; >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> public CustomMultiResolutionImage(int baseImageIndex, >>>>>>>>>>>>>>>> Image... resolutionVariants) { >>>>>>>>>>>>>>>> this.baseImageIndex = baseImageIndex; >>>>>>>>>>>>>>>> this.resolutionVariants = resolutionVariants; >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public int getWidth(ImageObserver observer) { >>>>>>>>>>>>>>>> return getBaseImage().getWidth(null); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public int getHeight(ImageObserver observer) { >>>>>>>>>>>>>>>> return getBaseImage().getHeight(null); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public ImageProducer getSource() { >>>>>>>>>>>>>>>> return getBaseImage().getSource(); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public Graphics getGraphics() { >>>>>>>>>>>>>>>> return getBaseImage().getGraphics(); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public Object getProperty(String name, >>>>>>>>>>>>>>>> ImageObserver observer) { >>>>>>>>>>>>>>>> return getBaseImage().getProperty(name, >>>>>>>>>>>>>>>> observer); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public Image getResolutionVariant(float >>>>>>>>>>>>>>>> logicalDPIX, float >>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>> float destinationImageWidth, float >>>>>>>>>>>>>>>> destinationImageHeight) { >>>>>>>>>>>>>>>> // calculate resolution variant width/height >>>>>>>>>>>>>>>> return getResolutionVariant(rvWidth, rvHeight); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>>>>>> return Arrays.asList(resolutionVariants); >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> private Image getResolutionVariant(float rvWidth, >>>>>>>>>>>>>>>> float >>>>>>>>>>>>>>>> rvHeight) { >>>>>>>>>>>>>>>> // return a resolution variant based on the >>>>>>>>>>>>>>>> given width and >>>>>>>>>>>>>>>> height >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> private Image getBaseImage() { >>>>>>>>>>>>>>>> return resolutionVariants[baseImageIndex]; >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> --------------------------------- >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Then we provide one of these from TK.get/createImage() >>>>>>>>>>>>>>>>> when the >>>>>>>>>>>>>>>>> platform detects @2x, or Win8-style variants. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> For custom images we provide TK.createMRImage(lambda >>>>>>>>>>>>>>>>> getRV, Image >>>>>>>>>>>>>>>>> variants...) and TK.createMRImage(Image variants...); >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Since the get method is just bookkeeping, I >>>>>>>>>>>>>>>>> don't see them >>>>>>>>>>>>>>>>> needing to override it, so the getRV() method is >>>>>>>>>>>>>>>>> really the only >>>>>>>>>>>>>>>>> thing >>>>>>>>>>>>>>>>> they might want to override, and we can tie into the >>>>>>>>>>>>>>>>> new Lambda >>>>>>>>>>>>>>>>> capabilities by making a single-method interface for >>>>>>>>>>>>>>>>> it that they >>>>>>>>>>>>>>>>> supply in a factory method. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> I realize that the interface you created is more >>>>>>>>>>>>>>>>> fundamentally >>>>>>>>>>>>>>>>> OO, but >>>>>>>>>>>>>>>>> the Image class has always been special in this regard >>>>>>>>>>>>>>>>> in the AWT >>>>>>>>>>>>>>>>> ecosystem (in so far as we do not support someone >>>>>>>>>>>>>>>>> implementing their >>>>>>>>>>>>>>>>> own Image subclass even though it is technically >>>>>>>>>>>>>>>>> possible). >>>>>>>>>>>>>>>>> Because of >>>>>>>>>>>>>>>>> this special nature of Image, we end up with the >>>>>>>>>>>>>>>>> situation that if >>>>>>>>>>>>>>>>> someone were given a need to create a subclass of >>>>>>>>>>>>>>>>> Image, then they >>>>>>>>>>>>>>>>> would turn to BufImg as their superclass even though >>>>>>>>>>>>>>>>> BufImg is >>>>>>>>>>>>>>>>> essentially an implementation-specific leaf node on >>>>>>>>>>>>>>>>> the Image class >>>>>>>>>>>>>>>>> hierarchy. This approach with a factory method to >>>>>>>>>>>>>>>>> create an >>>>>>>>>>>>>>>>> internal >>>>>>>>>>>>>>>>> subclass of the new MRI class mirrors the existing >>>>>>>>>>>>>>>>> cases of Image >>>>>>>>>>>>>>>>> objects that come from factories as well. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Thoughts? >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> On 3/20/14 7:52 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> Could you review the updated version of the fix: >>>>>>>>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.01/ >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> - The "getResolutionVariant(int width, int height)" >>>>>>>>>>>>>>>>>> method from >>>>>>>>>>>>>>>>>> MultiResolutionImage class is changed to >>>>>>>>>>>>>>>>>> Image getResolutionVariant(float logicalDPIX, float >>>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>>> float width, float height, AffineTransform transform); >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> - sun.awt.image.ImageResolutionHelper class is >>>>>>>>>>>>>>>>>> added. The >>>>>>>>>>>>>>>>>> sun.awt.image.MultiResolutionToolkitImage and >>>>>>>>>>>>>>>>>> sun.awt.image.MultiResolutionBufferedImage classes >>>>>>>>>>>>>>>>>> are used >>>>>>>>>>>>>>>>>> PLATFORM ImageResolutionHelper. >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> The MultiResolutionImage interface implementation >>>>>>>>>>>>>>>>>> could look >>>>>>>>>>>>>>>>>> like: >>>>>>>>>>>>>>>>>> ------------------------------ >>>>>>>>>>>>>>>>>> public class CustomMultiResolutionImage extends >>>>>>>>>>>>>>>>>> BufferedImage >>>>>>>>>>>>>>>>>> implements >>>>>>>>>>>>>>>>>> MultiResolutionImage { >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> private final Image[] resolutionVariants; >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> public CustomMultiResolutionImage(int baseIndex, >>>>>>>>>>>>>>>>>> Image... >>>>>>>>>>>>>>>>>> images) { >>>>>>>>>>>>>>>>>> super(images[baseIndex].getWidth(null), >>>>>>>>>>>>>>>>>> images[baseIndex].getHeight(null), >>>>>>>>>>>>>>>>>> BufferedImage.TYPE_INT_RGB); >>>>>>>>>>>>>>>>>> this.resolutionVariants = images; >>>>>>>>>>>>>>>>>> Graphics g = getGraphics(); >>>>>>>>>>>>>>>>>> g.drawImage(images[baseIndex], 0, 0, null); >>>>>>>>>>>>>>>>>> g.dispose(); >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>> public Image getResolutionVariant(float >>>>>>>>>>>>>>>>>> logicalDPIX, float >>>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>>> float width, float height, AffineTransform >>>>>>>>>>>>>>>>>> transform) { >>>>>>>>>>>>>>>>>> return getResolutionVariant(logicalDPIX * >>>>>>>>>>>>>>>>>> width, >>>>>>>>>>>>>>>>>> logicalDPIY * >>>>>>>>>>>>>>>>>> height); >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>>>>>>>> return Arrays.asList(resolutionVariants); >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> public Image getResolutionVariant(double width, >>>>>>>>>>>>>>>>>> double >>>>>>>>>>>>>>>>>> height) { >>>>>>>>>>>>>>>>>> for (Image image : resolutionVariants) { >>>>>>>>>>>>>>>>>> if (width <= image.getWidth(null) && >>>>>>>>>>>>>>>>>> height <= >>>>>>>>>>>>>>>>>> image.getHeight(null)) { >>>>>>>>>>>>>>>>>> return image; >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> return this; >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>> ------------------------------ >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> On 2/27/2014 4:54 PM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>> On 2/22/2014 3:54 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>> Hi Alexandr, >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> On 2/18/14 7:33 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>> Hi Jim, >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> Let's divide the discussion into two part. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> 1. Where it is better to hold resolution variants? >>>>>>>>>>>>>>>>>>>>> Putting resolution variants in Image class >>>>>>>>>>>>>>>>>>>>> brings some >>>>>>>>>>>>>>>>>>>>> questions like: >>>>>>>>>>>>>>>>>>>>> - Some type of images do not need to have >>>>>>>>>>>>>>>>>>>>> resolution variants >>>>>>>>>>>>>>>>>>>>> - Should resolution variants have the same type >>>>>>>>>>>>>>>>>>>>> as the base >>>>>>>>>>>>>>>>>>>>> image? >>>>>>>>>>>>>>>>>>>>> - getResolutionVariants() method can return >>>>>>>>>>>>>>>>>>>>> copy of the >>>>>>>>>>>>>>>>>>>>> original >>>>>>>>>>>>>>>>>>>>> list >>>>>>>>>>>>>>>>>>>>> so add/removeRV methods should be also added. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> There are pros and cons for placing resolution >>>>>>>>>>>>>>>>>>>>> variants to >>>>>>>>>>>>>>>>>>>>> Image >>>>>>>>>>>>>>>>>>>>> class or to a separate intreface. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> I agree that this could be a separate interface. In >>>>>>>>>>>>>>>>>>>> my examples >>>>>>>>>>>>>>>>>>>> below I was just sticking them inside an "Image{}" >>>>>>>>>>>>>>>>>>>> to show where >>>>>>>>>>>>>>>>>>>> they >>>>>>>>>>>>>>>>>>>> lived in the set of involved objects, not a specific >>>>>>>>>>>>>>>>>>>> recommendation >>>>>>>>>>>>>>>>>>>> that they actually be new methods on the base class >>>>>>>>>>>>>>>>>>>> itself. I >>>>>>>>>>>>>>>>>>>> probably should have put a comment there about that. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> With respect to add/remove - that is assuming a >>>>>>>>>>>>>>>>>>>> need for manual >>>>>>>>>>>>>>>>>>>> construction of an image set, right? Forgive me if I'm >>>>>>>>>>>>>>>>>>>> forgetting >>>>>>>>>>>>>>>>>>>> something, but I seem to recall that manual >>>>>>>>>>>>>>>>>>>> Multi-Res images was >>>>>>>>>>>>>>>>>>>> proposed as a way for developers to introduce @2x >>>>>>>>>>>>>>>>>>>> support >>>>>>>>>>>>>>>>>>>> themselves, >>>>>>>>>>>>>>>>>>>> but if we are internally managing @2x and -DPI >>>>>>>>>>>>>>>>>>>> variants for them, >>>>>>>>>>>>>>>>>>>> then I'm not sure if there is actual developer need >>>>>>>>>>>>>>>>>>>> to manually >>>>>>>>>>>>>>>>>>>> construct their own. Am I forgetting something? >>>>>>>>>>>>>>>>>>> The NSImage has >>>>>>>>>>>>>>>>>>> addRepresentation/removeRepresentation >>>>>>>>>>>>>>>>>>> methods to >>>>>>>>>>>>>>>>>>> work with image representations on Mac OS X. >>>>>>>>>>>>>>>>>>> The java.awt.Image class should provide similar >>>>>>>>>>>>>>>>>>> functionality to >>>>>>>>>>>>>>>>>>> have the possibilities as Cocoa on HiDPI displays. >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> 2. Using scale factor/image sizes/scaled image >>>>>>>>>>>>>>>>>>>>> sizes to >>>>>>>>>>>>>>>>>>>>> retreive a >>>>>>>>>>>>>>>>>>>>> resolution variant. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> May be it is better to have a structure that >>>>>>>>>>>>>>>>>>>>> provide all >>>>>>>>>>>>>>>>>>>>> necessary >>>>>>>>>>>>>>>>>>>>> information to query the resolution variant: >>>>>>>>>>>>>>>>>>>>> scale factor, >>>>>>>>>>>>>>>>>>>>> draw area >>>>>>>>>>>>>>>>>>>>> width/height, transformed area width/height? >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> For example: >>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>> public interface MultiResolutionImage { >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> interface DrawAreaInfo { >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> float getScaleFactor(); >>>>>>>>>>>>>>>>>>>>> float getAreaWidth(); >>>>>>>>>>>>>>>>>>>>> float getAreaHeight(); >>>>>>>>>>>>>>>>>>>>> float getTransformedAreaWidth(); >>>>>>>>>>>>>>>>>>>>> float getTransformedAreaHeight(); >>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> public Image >>>>>>>>>>>>>>>>>>>>> getResolutionVariant(DrawAreaInfo >>>>>>>>>>>>>>>>>>>>> drawAreaInfo) ; >>>>>>>>>>>>>>>>>>>>> public List getResolutionVariants(); >>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> The problem with a constructor is that this is >>>>>>>>>>>>>>>>>>>> something that is >>>>>>>>>>>>>>>>>>>> (potentially) done on every drawImage() call, which >>>>>>>>>>>>>>>>>>>> means we are >>>>>>>>>>>>>>>>>>>> inviting GC into the equation. If we can come up >>>>>>>>>>>>>>>>>>>> with a simple >>>>>>>>>>>>>>>>>>>> "just >>>>>>>>>>>>>>>>>>>> a couple/3/4 numbers" way to embed that data into a >>>>>>>>>>>>>>>>>>>> method call >>>>>>>>>>>>>>>>>>>> argument list then we can make this lighter weight. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> What about simply having floating point (double) >>>>>>>>>>>>>>>>>>>> dimensions on >>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>> rendered size >>>>>>>>>>>>>>>>>>> There should be a way to choose a resolution >>>>>>>>>>>>>>>>>>> variant >>>>>>>>>>>>>>>>>>> based on >>>>>>>>>>>>>>>>>>> requested drawing size or transformed drawing size. >>>>>>>>>>>>>>>>>>> At least a current transformation should be >>>>>>>>>>>>>>>>>>> included too. >>>>>>>>>>>>>>>>>>>> plus a single floating point "logical DPI" for the >>>>>>>>>>>>>>>>>>>> screen? >>>>>>>>>>>>>>>>>>> There is the ID2D1Factory::GetDesktopDpi method >>>>>>>>>>>>>>>>>>> which returns >>>>>>>>>>>>>>>>>>> dpiX and dpiY. >>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/windows/apps/dd371316 >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> That means that logicalDPIX/Y can have different >>>>>>>>>>>>>>>>>>> values. >>>>>>>>>>>>>>>>>>> At least it is described in the >>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/windows/apps/ff684173 >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> "To get the DPI setting, call the >>>>>>>>>>>>>>>>>>> ID2D1Factory::GetDesktopDpi >>>>>>>>>>>>>>>>>>> method. The DPI is returned as two floating-point >>>>>>>>>>>>>>>>>>> values, one for >>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>> x-axis and one for the y-axis. In theory, these >>>>>>>>>>>>>>>>>>> values can differ. >>>>>>>>>>>>>>>>>>> Calculate a separate scaling factor for each axis." >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> The getResolutionVariant method could look like: >>>>>>>>>>>>>>>>>>> -------------------------------------- >>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(float >>>>>>>>>>>>>>>>>>> logicalDPIX, float >>>>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>>>> float widthX, float widthY, AffineTransform >>>>>>>>>>>>>>>>>>> transform); >>>>>>>>>>>>>>>>>>> -------------------------------------- >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> If the image is known (either passed as an >>>>>>>>>>>>>>>>>>>> argument or the >>>>>>>>>>>>>>>>>>>> method is >>>>>>>>>>>>>>>>>>>> called on the image), then it can provide the >>>>>>>>>>>>>>>>>>>> original WH. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> The MultiResolutionImage default implementation >>>>>>>>>>>>>>>>>>>>> could allow >>>>>>>>>>>>>>>>>>>>> to use >>>>>>>>>>>>>>>>>>>>> different strategies like scale factor/transfom/OS >>>>>>>>>>>>>>>>>>>>> based >>>>>>>>>>>>>>>>>>>>> to query a resolution variant. The OS based >>>>>>>>>>>>>>>>>>>>> strategy can be >>>>>>>>>>>>>>>>>>>>> used by >>>>>>>>>>>>>>>>>>>>> default. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> For Mac policy, all we need is the transformed >>>>>>>>>>>>>>>>>>>> dimensions, which >>>>>>>>>>>>>>>>>>>> can >>>>>>>>>>>>>>>>>>>> be passed in as FP for generality. For Windows >>>>>>>>>>>>>>>>>>>> policy, all we >>>>>>>>>>>>>>>>>>>> need >>>>>>>>>>>>>>>>>>>> is logical DPI for the screen. What other >>>>>>>>>>>>>>>>>>>> information would we >>>>>>>>>>>>>>>>>>>> need, or would an algorithm like to use, that can't >>>>>>>>>>>>>>>>>>>> be computed >>>>>>>>>>>>>>>>>>>> from >>>>>>>>>>>>>>>>>>>> those 2 pieces? >>>>>>>>>>>>>>>>>>> The aim is to provide a base class that can be >>>>>>>>>>>>>>>>>>> used to >>>>>>>>>>>>>>>>>>> create a >>>>>>>>>>>>>>>>>>> MultiResolutionImage like: >>>>>>>>>>>>>>>>>>> http://hg.openjdk.java.net/jdk9/client/jdk/diff/ae53ebce5fa3/src/share/classes/sun/awt/image/MultiResolutionBufferedImage.java >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> A developer should be able to implement a >>>>>>>>>>>>>>>>>>> custom algorithm to >>>>>>>>>>>>>>>>>>> query a resolution variant. >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> It can be done by overriding the >>>>>>>>>>>>>>>>>>> getResolutionVariant image: >>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>> Image mrImage = new >>>>>>>>>>>>>>>>>>> MultiResolutionBufferedImage(){ >>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(...) { >>>>>>>>>>>>>>>>>>> // Custom logic here >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> }; >>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> Or it can be done by using resolution variant >>>>>>>>>>>>>>>>>>> choosers so a >>>>>>>>>>>>>>>>>>> developer can implement custom resolution variant >>>>>>>>>>>>>>>>>>> query: >>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>> public class MultiResolutionBufferedImage implements >>>>>>>>>>>>>>>>>>> MultiResolutionImage{ >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> interface ResolutionVariantChooser{ >>>>>>>>>>>>>>>>>>> Image getResolutionVariant(dpi, size,..., >>>>>>>>>>>>>>>>>>> List >>>>>>>>>>>>>>>>>>> resolutionVariants); >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> ResolutionVariantChooser TRANSFORM_BASED = null; >>>>>>>>>>>>>>>>>>> ResolutionVariantChooser DPI_BASED = null; >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> ResolutionVariantChooser rvChooser; >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(dpi, size,...,) { >>>>>>>>>>>>>>>>>>> return rvChooser.getResolutionVariant(dpi, >>>>>>>>>>>>>>>>>>> size,..., >>>>>>>>>>>>>>>>>>> getResolutionVariants()); >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> On 2/13/2014 4:42 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>>> On 2/12/14 5:59 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>>> On 2/8/2014 4:19 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>>>>> The primary thing that I was concerned about >>>>>>>>>>>>>>>>>>>>>>>> was the >>>>>>>>>>>>>>>>>>>>>>>> presence of >>>>>>>>>>>>>>>>>>>>>>>> integers in the API when Windows uses >>>>>>>>>>>>>>>>>>>>>>>> non-integer multiples >>>>>>>>>>>>>>>>>>>>>>> It would make sense to pass real numbers >>>>>>>>>>>>>>>>>>>>>>> to the >>>>>>>>>>>>>>>>>>>>>>> getResolutionVariant() method if the difference >>>>>>>>>>>>>>>>>>>>>>> between >>>>>>>>>>>>>>>>>>>>>>> resolution >>>>>>>>>>>>>>>>>>>>>>> variants sizes is 1. >>>>>>>>>>>>>>>>>>>>>>> It seems that it is not a common case. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> I was thinking of other API that is related to >>>>>>>>>>>>>>>>>>>>>> this, such as >>>>>>>>>>>>>>>>>>>>>> the API >>>>>>>>>>>>>>>>>>>>>> that queries the scaling factor from a >>>>>>>>>>>>>>>>>>>>>> SurfaceManager. I >>>>>>>>>>>>>>>>>>>>>> seem to >>>>>>>>>>>>>>>>>>>>>> remember some integer return values in that, but >>>>>>>>>>>>>>>>>>>>>> Windows might >>>>>>>>>>>>>>>>>>>>>> have >>>>>>>>>>>>>>>>>>>>>> the answer 1.4 or 1.8, depending on the screen >>>>>>>>>>>>>>>>>>>>>> scaling factor >>>>>>>>>>>>>>>>>>>>>> that was >>>>>>>>>>>>>>>>>>>>>> determined from the UI. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> In terms of the getResolutionVariant() method >>>>>>>>>>>>>>>>>>>>>> here, those >>>>>>>>>>>>>>>>>>>>>> non-integer >>>>>>>>>>>>>>>>>>>>>> screen scaling factors don't directly impact this >>>>>>>>>>>>>>>>>>>>>> API. But, we >>>>>>>>>>>>>>>>>>>>>> have >>>>>>>>>>>>>>>>>>>>>> some issues with the use of integers there from >>>>>>>>>>>>>>>>>>>>>> other sources: >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - That API assumes that the caller will determine >>>>>>>>>>>>>>>>>>>>>> the pixel >>>>>>>>>>>>>>>>>>>>>> size >>>>>>>>>>>>>>>>>>>>>> needed, but the actual media choice is determined >>>>>>>>>>>>>>>>>>>>>> with >>>>>>>>>>>>>>>>>>>>>> different >>>>>>>>>>>>>>>>>>>>>> techniques on Mac and Windows so this means that >>>>>>>>>>>>>>>>>>>>>> the caller >>>>>>>>>>>>>>>>>>>>>> will >>>>>>>>>>>>>>>>>>>>>> have >>>>>>>>>>>>>>>>>>>>>> to worry about platform conventions. Is that the >>>>>>>>>>>>>>>>>>>>>> right >>>>>>>>>>>>>>>>>>>>>> tradeoff? >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - The technique recommended for Mac involves >>>>>>>>>>>>>>>>>>>>>> computing the >>>>>>>>>>>>>>>>>>>>>> precise >>>>>>>>>>>>>>>>>>>>>> size desired using the current transform, which >>>>>>>>>>>>>>>>>>>>>> may be a >>>>>>>>>>>>>>>>>>>>>> floating >>>>>>>>>>>>>>>>>>>>>> point value, so the integer values used in this >>>>>>>>>>>>>>>>>>>>>> API are already >>>>>>>>>>>>>>>>>>>>>> approximations and there is no documentation on >>>>>>>>>>>>>>>>>>>>>> how to >>>>>>>>>>>>>>>>>>>>>> generate the >>>>>>>>>>>>>>>>>>>>>> proper integer. In particular, the current code >>>>>>>>>>>>>>>>>>>>>> in SG2D >>>>>>>>>>>>>>>>>>>>>> naively >>>>>>>>>>>>>>>>>>>>>> uses >>>>>>>>>>>>>>>>>>>>>> a cast to integer to determine the values to >>>>>>>>>>>>>>>>>>>>>> supply which >>>>>>>>>>>>>>>>>>>>>> means a >>>>>>>>>>>>>>>>>>>>>> transformed size of W+0.5 will be truncated to W >>>>>>>>>>>>>>>>>>>>>> and the lower >>>>>>>>>>>>>>>>>>>>>> resolution image will be used. Does that conform >>>>>>>>>>>>>>>>>>>>>> to Mac >>>>>>>>>>>>>>>>>>>>>> guidelines? Do >>>>>>>>>>>>>>>>>>>>>> they require the truncated size to reach W+1 >>>>>>>>>>>>>>>>>>>>>> before the next >>>>>>>>>>>>>>>>>>>>>> size is >>>>>>>>>>>>>>>>>>>>>> used? Passing in float or double values would >>>>>>>>>>>>>>>>>>>>>> sidestep all of >>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>> since then the comparisons would be done with >>>>>>>>>>>>>>>>>>>>>> full precision, >>>>>>>>>>>>>>>>>>>>>> but as >>>>>>>>>>>>>>>>>>>>>> long as we can determine a "best practices >>>>>>>>>>>>>>>>>>>>>> compatible with all >>>>>>>>>>>>>>>>>>>>>> platforms" rule on how to round to integers, then >>>>>>>>>>>>>>>>>>>>>> integers >>>>>>>>>>>>>>>>>>>>>> are OK >>>>>>>>>>>>>>>>>>>>>> there. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - The Windows document you cite below suggests >>>>>>>>>>>>>>>>>>>>>> that the >>>>>>>>>>>>>>>>>>>>>> determination >>>>>>>>>>>>>>>>>>>>>> should be made by looking at the Screen DPI and >>>>>>>>>>>>>>>>>>>>>> choosing the >>>>>>>>>>>>>>>>>>>>>> next >>>>>>>>>>>>>>>>>>>>>> higher media variant based on that screen DPI. >>>>>>>>>>>>>>>>>>>>>> They do not >>>>>>>>>>>>>>>>>>>>>> specify >>>>>>>>>>>>>>>>>>>>>> choosing media based on the current transform as >>>>>>>>>>>>>>>>>>>>>> is done for >>>>>>>>>>>>>>>>>>>>>> Mac. If >>>>>>>>>>>>>>>>>>>>>> we stick with supplying values that are used to >>>>>>>>>>>>>>>>>>>>>> determine which >>>>>>>>>>>>>>>>>>>>>> media >>>>>>>>>>>>>>>>>>>>>> to use, then on Windows we should not take the >>>>>>>>>>>>>>>>>>>>>> transform into >>>>>>>>>>>>>>>>>>>>>> account, >>>>>>>>>>>>>>>>>>>>>> but instead query the SurfaceManager for the >>>>>>>>>>>>>>>>>>>>>> scale factor and >>>>>>>>>>>>>>>>>>>>>> only >>>>>>>>>>>>>>>>>>>>>> transform by those values (even if the current >>>>>>>>>>>>>>>>>>>>>> transform was >>>>>>>>>>>>>>>>>>>>>> manually >>>>>>>>>>>>>>>>>>>>>> overridden to identity). >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> There are pros and cons to both approaches. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> Mac ensures that you are always using the best >>>>>>>>>>>>>>>>>>>>>> media for any >>>>>>>>>>>>>>>>>>>>>> given >>>>>>>>>>>>>>>>>>>>>> render operation. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> But, Windows ensure more consistency in the face >>>>>>>>>>>>>>>>>>>>>> of other >>>>>>>>>>>>>>>>>>>>>> scaling. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> The thing to consider is that if you have a >>>>>>>>>>>>>>>>>>>>>> 500x500 image >>>>>>>>>>>>>>>>>>>>>> with a >>>>>>>>>>>>>>>>>>>>>> 1000x1000 variant and you rendering it at 500x500 >>>>>>>>>>>>>>>>>>>>>> and then >>>>>>>>>>>>>>>>>>>>>> 501x501, >>>>>>>>>>>>>>>>>>>>>> that first jump will be fairly jarring as the >>>>>>>>>>>>>>>>>>>>>> scaled version >>>>>>>>>>>>>>>>>>>>>> of the >>>>>>>>>>>>>>>>>>>>>> 1000x1000 will not look precisely like the >>>>>>>>>>>>>>>>>>>>>> original 500x500 >>>>>>>>>>>>>>>>>>>>>> did. >>>>>>>>>>>>>>>>>>>>>> With >>>>>>>>>>>>>>>>>>>>>> @2x images only, this effect is minimized so the >>>>>>>>>>>>>>>>>>>>>> advantage of >>>>>>>>>>>>>>>>>>>>>> always >>>>>>>>>>>>>>>>>>>>>> using "the best media for a given render >>>>>>>>>>>>>>>>>>>>>> operation" may >>>>>>>>>>>>>>>>>>>>>> outweigh the >>>>>>>>>>>>>>>>>>>>>> inconsistency issue. But, on Windows where the >>>>>>>>>>>>>>>>>>>>>> media are >>>>>>>>>>>>>>>>>>>>>> 1.4x or >>>>>>>>>>>>>>>>>>>>>> 1.8x >>>>>>>>>>>>>>>>>>>>>> in size, a downscaled image will start to show more >>>>>>>>>>>>>>>>>>>>>> interpolation >>>>>>>>>>>>>>>>>>>>>> noise and so the balance of the two choices may >>>>>>>>>>>>>>>>>>>>>> shift more >>>>>>>>>>>>>>>>>>>>>> towards not >>>>>>>>>>>>>>>>>>>>>> wanting a jarring shift. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> We might want one or more of the following: >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - Developer chooses policy (TX_AWARE, DPI_AWARE, >>>>>>>>>>>>>>>>>>>>>> ALWAYS_LARGEST, >>>>>>>>>>>>>>>>>>>>>> NONE, >>>>>>>>>>>>>>>>>>>>>> PLATFORM) where the last policy would use >>>>>>>>>>>>>>>>>>>>>> TX_AWARE on Mac and >>>>>>>>>>>>>>>>>>>>>> DPI_AWARE on Windows >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - We create our own policy and always use it >>>>>>>>>>>>>>>>>>>>>> (TX_AWARE? or >>>>>>>>>>>>>>>>>>>>>> DPI_AWARE?) >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - We create our own policy that dynamically >>>>>>>>>>>>>>>>>>>>>> chooses one of the >>>>>>>>>>>>>>>>>>>>>> above >>>>>>>>>>>>>>>>>>>>>> strategies depending on platform or available >>>>>>>>>>>>>>>>>>>>>> media or ??? >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> - We could create an optional interface for them >>>>>>>>>>>>>>>>>>>>>> to install >>>>>>>>>>>>>>>>>>>>>> their >>>>>>>>>>>>>>>>>>>>>> own >>>>>>>>>>>>>>>>>>>>>> algorithm as well. I think it would work best as >>>>>>>>>>>>>>>>>>>>>> a delegate >>>>>>>>>>>>>>>>>>>>>> interface >>>>>>>>>>>>>>>>>>>>>> that one installs into Image so that it can be >>>>>>>>>>>>>>>>>>>>>> used with any >>>>>>>>>>>>>>>>>>>>>> image >>>>>>>>>>>>>>>>>>>>>> without having to subclass (it wouldn't really >>>>>>>>>>>>>>>>>>>>>> have much to do >>>>>>>>>>>>>>>>>>>>>> for >>>>>>>>>>>>>>>>>>>>>> BufferedImages or VolatileImages, though): >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> class Image { >>>>>>>>>>>>>>>>>>>>>> void >>>>>>>>>>>>>>>>>>>>>> setResolutionHelper(ImageResolutionHelper foo); >>>>>>>>>>>>>>>>>>>>>> List getResolutionVariants(); >>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> or: >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> class Graphics { >>>>>>>>>>>>>>>>>>>>>> void >>>>>>>>>>>>>>>>>>>>>> setResolutionHelper(ImageResolutionHelper foo); >>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> or - anywhere else it could be installed more >>>>>>>>>>>>>>>>>>>>>> centrally (per >>>>>>>>>>>>>>>>>>>>>> App >>>>>>>>>>>>>>>>>>>>>> context)? >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> and the interface would be something like one of >>>>>>>>>>>>>>>>>>>>>> these >>>>>>>>>>>>>>>>>>>>>> variants: >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> interface ImageResolutionHelper { >>>>>>>>>>>>>>>>>>>>>> // This version would prevent substituting a >>>>>>>>>>>>>>>>>>>>>> random image: >>>>>>>>>>>>>>>>>>>>>> // They have to return an index into the >>>>>>>>>>>>>>>>>>>>>> List for >>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>> image... >>>>>>>>>>>>>>>>>>>>>> public int chooseVariant(Image img, double >>>>>>>>>>>>>>>>>>>>>> dpi, number w, >>>>>>>>>>>>>>>>>>>>>> number h); >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> or: >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> // This version would allow substituting an >>>>>>>>>>>>>>>>>>>>>> arbitrary >>>>>>>>>>>>>>>>>>>>>> image: >>>>>>>>>>>>>>>>>>>>>> public Image getVariant(Image img, double >>>>>>>>>>>>>>>>>>>>>> dpi, number w, >>>>>>>>>>>>>>>>>>>>>> number >>>>>>>>>>>>>>>>>>>>>> h); >>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> Since they would be in full control of the >>>>>>>>>>>>>>>>>>>>>> policy, though, we >>>>>>>>>>>>>>>>>>>>>> would >>>>>>>>>>>>>>>>>>>>>> unfortunately always have to call this, there >>>>>>>>>>>>>>>>>>>>>> would be no more >>>>>>>>>>>>>>>>>>>>>> testing >>>>>>>>>>>>>>>>>>>>>> in SG2D to see "if" we need to deal with DPI, >>>>>>>>>>>>>>>>>>>>>> though perhaps we >>>>>>>>>>>>>>>>>>>>>> could >>>>>>>>>>>>>>>>>>>>>> document some internal conditions in which we do >>>>>>>>>>>>>>>>>>>>>> not call it >>>>>>>>>>>>>>>>>>>>>> for >>>>>>>>>>>>>>>>>>>>>> common cases (but that would have to be well >>>>>>>>>>>>>>>>>>>>>> agreed not to >>>>>>>>>>>>>>>>>>>>>> get in >>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>> way of reasonable uses of the API and well >>>>>>>>>>>>>>>>>>>>>> documented)? >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> Note that we would have to do a security audit to >>>>>>>>>>>>>>>>>>>>>> make sure >>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>> random image substitution couldn't allow any sort >>>>>>>>>>>>>>>>>>>>>> of "screen >>>>>>>>>>>>>>>>>>>>>> phishing" >>>>>>>>>>>>>>>>>>>>>> exploit. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> and also what policy they use for choosing >>>>>>>>>>>>>>>>>>>>>>>> scaled images. >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> I don't see a mention of taking the current >>>>>>>>>>>>>>>>>>>>>>>> transform into >>>>>>>>>>>>>>>>>>>>>>>> account, >>>>>>>>>>>>>>>>>>>>>>>> just physical issues like screen DPI and form >>>>>>>>>>>>>>>>>>>>>>>> factor. They >>>>>>>>>>>>>>>>>>>>>>>> talk >>>>>>>>>>>>>>>>>>>>>>>> about >>>>>>>>>>>>>>>>>>>>>>>> resolution plateaus and in their >>>>>>>>>>>>>>>>>>>>>>>> recommendations section they >>>>>>>>>>>>>>>>>>>>>>>> tell the >>>>>>>>>>>>>>>>>>>>>>>> developer to use a particular property that >>>>>>>>>>>>>>>>>>>>>>>> tells them the >>>>>>>>>>>>>>>>>>>>>>>> screen >>>>>>>>>>>>>>>>>>>>>>>> resolution to figure out which image to load if >>>>>>>>>>>>>>>>>>>>>>>> they are >>>>>>>>>>>>>>>>>>>>>>>> loading >>>>>>>>>>>>>>>>>>>>>>>> manually. There is no discussion about >>>>>>>>>>>>>>>>>>>>>>>> dynamically loading >>>>>>>>>>>>>>>>>>>>>>>> multiple >>>>>>>>>>>>>>>>>>>>>>>> versions of the image based on a dynamic >>>>>>>>>>>>>>>>>>>>>>>> program-applied >>>>>>>>>>>>>>>>>>>>>>>> transform >>>>>>>>>>>>>>>>>>>>>>>> factor as is done on MacOS. >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> Also, they tell developers to draw images to a >>>>>>>>>>>>>>>>>>>>>>>> specific size >>>>>>>>>>>>>>>>>>>>>>>> rather >>>>>>>>>>>>>>>>>>>>>>>> than using auto-sizing. That begs the question >>>>>>>>>>>>>>>>>>>>>>>> as to how >>>>>>>>>>>>>>>>>>>>>>>> they >>>>>>>>>>>>>>>>>>>>>>>> interpret a call to draw an image just using a >>>>>>>>>>>>>>>>>>>>>>>> location in >>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>> presence of various DPI factors. >>>>>>>>>>>>>>>>>>>>>>> There is an interesting doc that describes >>>>>>>>>>>>>>>>>>>>>>> how to write >>>>>>>>>>>>>>>>>>>>>>> DPI-aware >>>>>>>>>>>>>>>>>>>>>>> Win32 applications: >>>>>>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/dd464646%28v=vs.85%29.aspx >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> It is suggested to handle WM_DPICHANGED >>>>>>>>>>>>>>>>>>>>>>> message, load >>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>> graphic >>>>>>>>>>>>>>>>>>>>>>> that has slightly greater resolution to the >>>>>>>>>>>>>>>>>>>>>>> current DPI and >>>>>>>>>>>>>>>>>>>>>>> use >>>>>>>>>>>>>>>>>>>>>>> StretchBlt >>>>>>>>>>>>>>>>>>>>>>> to scale down the image. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> On 2/7/14 3:00 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>>>>> On 1/22/2014 6:40 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>>>>>>> Hi Alexander, >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> Before we get too far down the road on this >>>>>>>>>>>>>>>>>>>>>>>>>> API, I think we >>>>>>>>>>>>>>>>>>>>>>>>>> understand >>>>>>>>>>>>>>>>>>>>>>>>>> the way in which MacOS processes >>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution images >>>>>>>>>>>>>>>>>>>>>>>>>> for >>>>>>>>>>>>>>>>>>>>>>>>>> HiDPI >>>>>>>>>>>>>>>>>>>>>>>>>> screens, but have we investigated the >>>>>>>>>>>>>>>>>>>>>>>>>> processes that >>>>>>>>>>>>>>>>>>>>>>>>>> Windows >>>>>>>>>>>>>>>>>>>>>>>>>> uses >>>>>>>>>>>>>>>>>>>>>>>>>> under Windows 8? My impression is that >>>>>>>>>>>>>>>>>>>>>>>>>> Windows 8 has >>>>>>>>>>>>>>>>>>>>>>>>>> included a >>>>>>>>>>>>>>>>>>>>>>>>>> number of new techniques for dealing with the >>>>>>>>>>>>>>>>>>>>>>>>>> high >>>>>>>>>>>>>>>>>>>>>>>>>> resolution >>>>>>>>>>>>>>>>>>>>>>>>>> displays >>>>>>>>>>>>>>>>>>>>>>>>>> that it will run on in the Windows tablet and >>>>>>>>>>>>>>>>>>>>>>>>>> mobile >>>>>>>>>>>>>>>>>>>>>>>>>> industries >>>>>>>>>>>>>>>>>>>>>>>>>> and >>>>>>>>>>>>>>>>>>>>>>>>>> that these will also come into play as 4K >>>>>>>>>>>>>>>>>>>>>>>>>> displays (already >>>>>>>>>>>>>>>>>>>>>>>>>> available) >>>>>>>>>>>>>>>>>>>>>>>>>> become more common on the desktop. We should >>>>>>>>>>>>>>>>>>>>>>>>>> make sure >>>>>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>>>>> what we >>>>>>>>>>>>>>>>>>>>>>>>>> come up with here can provide native >>>>>>>>>>>>>>>>>>>>>>>>>> compatibility with >>>>>>>>>>>>>>>>>>>>>>>>>> either >>>>>>>>>>>>>>>>>>>>>>>>>> platform's policies and standard practices. >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> If you've investigated the MS policies I'd >>>>>>>>>>>>>>>>>>>>>>>>>> like to see a >>>>>>>>>>>>>>>>>>>>>>>>>> summary so >>>>>>>>>>>>>>>>>>>>>>>>>> that we can consider them as we review this >>>>>>>>>>>>>>>>>>>>>>>>>> API... >>>>>>>>>>>>>>>>>>>>>>>>> There is the Windows Guidelines for >>>>>>>>>>>>>>>>>>>>>>>>> scaling to pixel >>>>>>>>>>>>>>>>>>>>>>>>> density: >>>>>>>>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/windows/apps/hh465362.aspx >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> which says that Windows has automatic >>>>>>>>>>>>>>>>>>>>>>>>> resource loading >>>>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>>>> supports >>>>>>>>>>>>>>>>>>>>>>>>> three version of images scaling (100%, 140%, >>>>>>>>>>>>>>>>>>>>>>>>> and 180%) >>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>> Without scaling, as the pixel density of a >>>>>>>>>>>>>>>>>>>>>>>>> display device >>>>>>>>>>>>>>>>>>>>>>>>> increases, the >>>>>>>>>>>>>>>>>>>>>>>>> physical sizes of objects on screen get smaller. >>>>>>>>>>>>>>>>>>>>>>>>> When UI would otherwise be too small to touch >>>>>>>>>>>>>>>>>>>>>>>>> and when text >>>>>>>>>>>>>>>>>>>>>>>>> gets >>>>>>>>>>>>>>>>>>>>>>>>> too >>>>>>>>>>>>>>>>>>>>>>>>> small to read, >>>>>>>>>>>>>>>>>>>>>>>>> Windows scales the system and app UI to one of >>>>>>>>>>>>>>>>>>>>>>>>> the following >>>>>>>>>>>>>>>>>>>>>>>>> scaling >>>>>>>>>>>>>>>>>>>>>>>>> plateaus: >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> 1.0 (100%, no scaling is applied) >>>>>>>>>>>>>>>>>>>>>>>>> 1.4 (140% scaling) >>>>>>>>>>>>>>>>>>>>>>>>> 1.8 (180% scaling) >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> Windows determines which scaling plateau to >>>>>>>>>>>>>>>>>>>>>>>>> use based on the >>>>>>>>>>>>>>>>>>>>>>>>> physical >>>>>>>>>>>>>>>>>>>>>>>>> screen size, the screen resolution, the DPI of >>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>> screen, and >>>>>>>>>>>>>>>>>>>>>>>>> form >>>>>>>>>>>>>>>>>>>>>>>>> factor. >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> Use resource loading for bitmap images in the >>>>>>>>>>>>>>>>>>>>>>>>> app package >>>>>>>>>>>>>>>>>>>>>>>>> For >>>>>>>>>>>>>>>>>>>>>>>>> bitmap >>>>>>>>>>>>>>>>>>>>>>>>> images stored >>>>>>>>>>>>>>>>>>>>>>>>> in the app package, provide a separate image >>>>>>>>>>>>>>>>>>>>>>>>> for each >>>>>>>>>>>>>>>>>>>>>>>>> scaling >>>>>>>>>>>>>>>>>>>>>>>>> factor(100%, 140%, and 180%), >>>>>>>>>>>>>>>>>>>>>>>>> and name your image files using the "scale" >>>>>>>>>>>>>>>>>>>>>>>>> naming >>>>>>>>>>>>>>>>>>>>>>>>> convention >>>>>>>>>>>>>>>>>>>>>>>>> described >>>>>>>>>>>>>>>>>>>>>>>>> below. >>>>>>>>>>>>>>>>>>>>>>>>> Windows loads the right image for the current >>>>>>>>>>>>>>>>>>>>>>>>> scale >>>>>>>>>>>>>>>>>>>>>>>>> automatically. >>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> The image name convention for the various >>>>>>>>>>>>>>>>>>>>>>>>> scales is: >>>>>>>>>>>>>>>>>>>>>>>>> images/logo.scale-100.png >>>>>>>>>>>>>>>>>>>>>>>>> images/logo.scale-140.png >>>>>>>>>>>>>>>>>>>>>>>>> images/logo.scale-180.png >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> The 'ms-appx:///images/logo.png' uri is >>>>>>>>>>>>>>>>>>>>>>>>> used to load the >>>>>>>>>>>>>>>>>>>>>>>>> image >>>>>>>>>>>>>>>>>>>>>>>>> in an >>>>>>>>>>>>>>>>>>>>>>>>> application. >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> If we want to support this in the same way >>>>>>>>>>>>>>>>>>>>>>>>> as it is done >>>>>>>>>>>>>>>>>>>>>>>>> for Mac >>>>>>>>>>>>>>>>>>>>>>>>> OS X >>>>>>>>>>>>>>>>>>>>>>>>> the WToolkit should return MultiResolution >>>>>>>>>>>>>>>>>>>>>>>>> image in >>>>>>>>>>>>>>>>>>>>>>>>> case if >>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>> loaded image has .scale-* qualifiers. >>>>>>>>>>>>>>>>>>>>>>>>> The Graphics class can request an image >>>>>>>>>>>>>>>>>>>>>>>>> with necessary >>>>>>>>>>>>>>>>>>>>>>>>> resolution >>>>>>>>>>>>>>>>>>>>>>>>> from the MultiResolution image. >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> It seems that nothing should be changed in the >>>>>>>>>>>>>>>>>>>>>>>>> MultiResolution >>>>>>>>>>>>>>>>>>>>>>>>> interface in this case. >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> On 1/14/14 2:54 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Could you review the fix: >>>>>>>>>>>>>>>>>>>>>>>>>>> bug: >>>>>>>>>>>>>>>>>>>>>>>>>>> https://bugs.openjdk.java.net/browse/JDK-8029339 >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> webrev: >>>>>>>>>>>>>>>>>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.00 >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> This is a proposal to introduce an API >>>>>>>>>>>>>>>>>>>>>>>>>>> that allows to >>>>>>>>>>>>>>>>>>>>>>>>>>> create a >>>>>>>>>>>>>>>>>>>>>>>>>>> custom >>>>>>>>>>>>>>>>>>>>>>>>>>> multi resolution image. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> I. It seems reasonable that the API should >>>>>>>>>>>>>>>>>>>>>>>>>>> provide two >>>>>>>>>>>>>>>>>>>>>>>>>>> basic >>>>>>>>>>>>>>>>>>>>>>>>>>> operations: >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Get the resolution variant based on the >>>>>>>>>>>>>>>>>>>>>>>>>>> requested >>>>>>>>>>>>>>>>>>>>>>>>>>> image >>>>>>>>>>>>>>>>>>>>>>>>>>> width and >>>>>>>>>>>>>>>>>>>>>>>>>>> height: >>>>>>>>>>>>>>>>>>>>>>>>>>> - Image getResolutionVariant(int width, >>>>>>>>>>>>>>>>>>>>>>>>>>> int height) >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Usually the system provides the scale >>>>>>>>>>>>>>>>>>>>>>>>>>> factor which >>>>>>>>>>>>>>>>>>>>>>>>>>> represents >>>>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>>>> number of pixels corresponding to each >>>>>>>>>>>>>>>>>>>>>>>>>>> linear unit on the >>>>>>>>>>>>>>>>>>>>>>>>>>> display. >>>>>>>>>>>>>>>>>>>>>>>>>>> However, it has sense to combine the >>>>>>>>>>>>>>>>>>>>>>>>>>> scale factor and >>>>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>>>> current >>>>>>>>>>>>>>>>>>>>>>>>>>> transformations to get the actual image size >>>>>>>>>>>>>>>>>>>>>>>>>>> to be >>>>>>>>>>>>>>>>>>>>>>>>>>> displayed. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Get all provided resolution variants: >>>>>>>>>>>>>>>>>>>>>>>>>>> - List getResolutionVariants() >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> There are several uses cases: >>>>>>>>>>>>>>>>>>>>>>>>>>> - Create a new multi-resolution image >>>>>>>>>>>>>>>>>>>>>>>>>>> based on the >>>>>>>>>>>>>>>>>>>>>>>>>>> given >>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution image. >>>>>>>>>>>>>>>>>>>>>>>>>>> - Pass to the native system the >>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution >>>>>>>>>>>>>>>>>>>>>>>>>>> image. For >>>>>>>>>>>>>>>>>>>>>>>>>>> example, >>>>>>>>>>>>>>>>>>>>>>>>>>> a use can set to the system the custom >>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution >>>>>>>>>>>>>>>>>>>>>>>>>>> cursor. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> II. There are some possible ways where the >>>>>>>>>>>>>>>>>>>>>>>>>>> new API can be >>>>>>>>>>>>>>>>>>>>>>>>>>> added >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> 1. java.awt.Image. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> The 2 new methods can be added to the >>>>>>>>>>>>>>>>>>>>>>>>>>> Image class. A >>>>>>>>>>>>>>>>>>>>>>>>>>> user >>>>>>>>>>>>>>>>>>>>>>>>>>> can >>>>>>>>>>>>>>>>>>>>>>>>>>> override >>>>>>>>>>>>>>>>>>>>>>>>>>> the getResolutionVariant() and >>>>>>>>>>>>>>>>>>>>>>>>>>> getResolutionVariants() >>>>>>>>>>>>>>>>>>>>>>>>>>> methods to >>>>>>>>>>>>>>>>>>>>>>>>>>> provide the resolution variants >>>>>>>>>>>>>>>>>>>>>>>>>>> or there can be default implementations >>>>>>>>>>>>>>>>>>>>>>>>>>> of these >>>>>>>>>>>>>>>>>>>>>>>>>>> methods >>>>>>>>>>>>>>>>>>>>>>>>>>> if a >>>>>>>>>>>>>>>>>>>>>>>>>>> user >>>>>>>>>>>>>>>>>>>>>>>>>>> puts resolution variants >>>>>>>>>>>>>>>>>>>>>>>>>>> to the list in the sorted order. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> To check that the image has resolution >>>>>>>>>>>>>>>>>>>>>>>>>>> variants the >>>>>>>>>>>>>>>>>>>>>>>>>>> following >>>>>>>>>>>>>>>>>>>>>>>>>>> statement can be used: >>>>>>>>>>>>>>>>>>>>>>>>>>> image.getResolutionVariants().size() >>>>>>>>>>>>>>>>>>>>>>>>>>> != 1 >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> The disadvantage is that there is an >>>>>>>>>>>>>>>>>>>>>>>>>>> overhead that the >>>>>>>>>>>>>>>>>>>>>>>>>>> Image >>>>>>>>>>>>>>>>>>>>>>>>>>> class >>>>>>>>>>>>>>>>>>>>>>>>>>> should contain the List object and not all >>>>>>>>>>>>>>>>>>>>>>>>>>> images can have resolution variants. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Introduce new MultiResolutionImage >>>>>>>>>>>>>>>>>>>>>>>>>>> interface. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> A user should extend Image class and >>>>>>>>>>>>>>>>>>>>>>>>>>> implement the >>>>>>>>>>>>>>>>>>>>>>>>>>> MultiResolutionImage interface. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> For example: >>>>>>>>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>> public class CustomMultiResolutionImage >>>>>>>>>>>>>>>>>>>>>>>>>>> extends >>>>>>>>>>>>>>>>>>>>>>>>>>> BufferedImage >>>>>>>>>>>>>>>>>>>>>>>>>>> implements MultiResolutionImage { >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Image highResolutionImage; >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> public CustomMultiResolutionImage(BufferedImage >>>>>>>>>>>>>>>>>>>>>>>>>>> baseImage, >>>>>>>>>>>>>>>>>>>>>>>>>>> BufferedImage highResolutionImage) { >>>>>>>>>>>>>>>>>>>>>>>>>>> super(baseImage.getWidth(), >>>>>>>>>>>>>>>>>>>>>>>>>>> baseImage.getHeight(), >>>>>>>>>>>>>>>>>>>>>>>>>>> baseImage.getType()); >>>>>>>>>>>>>>>>>>>>>>>>>>> this.highResolutionImage = highResolutionImage; >>>>>>>>>>>>>>>>>>>>>>>>>>> Graphics g = getGraphics(); >>>>>>>>>>>>>>>>>>>>>>>>>>> g.drawImage(baseImage, 0, 0, null); >>>>>>>>>>>>>>>>>>>>>>>>>>> g.dispose(); >>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(int width, >>>>>>>>>>>>>>>>>>>>>>>>>>> int >>>>>>>>>>>>>>>>>>>>>>>>>>> height) { >>>>>>>>>>>>>>>>>>>>>>>>>>> return ((width <= getWidth() && height <= >>>>>>>>>>>>>>>>>>>>>>>>>>> getHeight())) >>>>>>>>>>>>>>>>>>>>>>>>>>> ? this : highResolutionImage; >>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>>>>>>>>>>>>>>>>> return Arrays.asList(this, >>>>>>>>>>>>>>>>>>>>>>>>>>> highResolutionImage); >>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> The current fix adds the >>>>>>>>>>>>>>>>>>>>>>>>>>> MultiResolutionImage interface >>>>>>>>>>>>>>>>>>>>>>>>>>> and >>>>>>>>>>>>>>>>>>>>>>>>>>> public >>>>>>>>>>>>>>>>>>>>>>>>>>> resolution variant rendering hints. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > From ebakke at MIT.EDU Fri Jul 11 15:12:28 2014 From: ebakke at MIT.EDU (Eirik Bakke) Date: Fri, 11 Jul 2014 15:12:28 +0000 Subject: FW: A small Aqua Swing bug report--how/where to file? In-Reply-To: References: Message-ID: (Resending without image attachment--I don't think my first message got through.) I have a small bug to file against the Aqua L&F in OpenJDK. What's the place/procedure for filing such bugs? (It seems that https://bugs.openjdk.java.net/browse/JDK does not permit the general public to create new bugs, and I'm not sure if it's the place for Aqua-related bugs either.) The bug is a variation of bug #5046173 mentioned in [1], "JTextFields had clipped focus rings". The aforementioned bug was partially resolved, but is still present in cases where the JTextField has the "JTextField.variant" client property set to "search". A minimal example is provided in [2]; when run on MacOS and the text field is in focus, text field is clipped by one or two pixels on all four sides (though you have to look closely to see it). -- Eirik [1] http://www.filibeto.org/unix/macos/lib/dev/releasenotes/Java/JavaLeopardRN/ JavaLeopardRN.pdf [2] https://gist.github.com/anonymous/662976ce8f6a942a3b9b From anthony.petrov at oracle.com Mon Jul 14 09:46:20 2014 From: anthony.petrov at oracle.com (Anthony Petrov) Date: Mon, 14 Jul 2014 13:46:20 +0400 Subject: FW: A small Aqua Swing bug report--how/where to file? In-Reply-To: References: Message-ID: <53C3A6EC.8050402@oracle.com> You can file a new bug at: http://bugreport.java.com/bugreport/ -- best regards, Anthony On 7/11/2014 7:12 PM, Eirik Bakke wrote: > (Resending without image attachment--I don't think my first message got > through.) > > I have a small bug to file against the Aqua L&F in OpenJDK. What's the > place/procedure for filing such bugs? (It seems that > https://bugs.openjdk.java.net/browse/JDK does not permit the general > public to create new bugs, and I'm not sure if it's the place for > Aqua-related bugs either.) > > The bug is a variation of bug #5046173 mentioned in [1], "JTextFields had > clipped focus rings". The aforementioned bug was partially resolved, but > is still present in cases where the JTextField has the > "JTextField.variant" client property set to "search". A minimal example is > provided in [2]; when run on MacOS and the text field is in focus, text > field is clipped by one or two pixels on all four sides (though you have > to look closely to see it). > > -- Eirik > > [1] > http://www.filibeto.org/unix/macos/lib/dev/releasenotes/Java/JavaLeopardRN/ > JavaLeopardRN.pdf > [2] https://gist.github.com/anonymous/662976ce8f6a942a3b9b > From florian.bruckner at 3kraft.com Mon Jul 14 16:38:27 2014 From: florian.bruckner at 3kraft.com (Florian Bruckner (3kraft)) Date: Mon, 14 Jul 2014 18:38:27 +0200 Subject: apple.security.KeychainStore does not load private key (when called from javaws) Message-ID: <53C40783.4060204@3kraft.com> Hi, I've been working on getting client certificates to run on OSX with Apple KeyChain in Java Webstart. KeychainStore works fine if it is passed a keystore password. It does not use it, at least not when trying to create a KeyStore with a private key entry. Java Webstart tries to load private keys from KeyChain if the browser keystore is activated. Unfortunately it tries to load the private key with an empty password (a char[0]), and KeychainStore rejects to load the private key then. It works fine for the trust store, as there are no private keys involved. A simple "fix" for this is to set a dummy password in KeychainStore if no password is passed in engineGetKey, e.g. like this: if (password == null || password.length ==0) { password = "DUMMY".toCharArray(); } Well, not really a fix, but rather a POC that the empty password is in fact the problem. I've not found out what exactly it is that the private key is not loaded, I just verified that the empty password passed by javaws causes it. Before I try to dig into KeychainStore - any idea why the private keys are not loaded if the password is empty? regards, Florian -- 3kraft IT GmbH & Co KG | Wasagasse 26/2 | 1090 Wien | ?sterreich | FN 333787 p (HG Wien) Komplement?r: 3kraft IT GmbH | Wasagasse 26/2 | 1090 Wien | ?sterreich | FN 333558 b (HG Wien) From florian.bruckner at 3kraft.com Tue Jul 15 08:56:40 2014 From: florian.bruckner at 3kraft.com (Florian Bruckner (3kraft)) Date: Tue, 15 Jul 2014 10:56:40 +0200 Subject: apple.security.KeychainStore does not load private key (when called from javaws) In-Reply-To: <53C40783.4060204@3kraft.com> References: <53C40783.4060204@3kraft.com> Message-ID: <53C4ECC8.3020909@3kraft.com> To answer my own question: KeychainStore loads the private key through native code in KeystoreImpl.m. KeystoreImpl.m uses this osx API to retrieve a PKCS#12 bag: https://developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#jumpTo_63 The API documentation says the PKCS#12 keystore requires a password. This is either supplied by the caller or the user is prompted (if a flag is set, which is not the case). KeychainStore then goes on to extract the private key from the returned PKCS#12 store and decrypts it with the password. Therefore, the password passed into engineGetKey is actually used to encrypt and decrypt only in the scope of this method. Therefore, the approach to create a dummy password for this use case is not as weird as I initially thought. Please consider these patches to fix this issue: For jdk7u-dev: diff -r 35aabd00a534 src/macosx/classes/apple/security/KeychainStore.java --- a/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 02:26:55 2014 +0400 +++ b/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 10:52:44 2014 +0200 @@ -134,7 +134,7 @@ * password to recover it. * * @param alias the alias name - * @param password the password for recovering the key + * @param password the password for recovering the key. This password is not used to access the private key in KeyChain, it is used internally only. * * @return the requested key, or null if the given alias does not exist * or does not identify a key entry. @@ -148,6 +148,16 @@ throws NoSuchAlgorithmException, UnrecoverableKeyException { permissionCheck(); + // An empty password is rejected by MacOS API, no private key data + // is exported. If no password is passed (as is the case when + // this implementation is used as browser keystore in various + // deployment scenarios like webstart, JFX and applets), create + // a dummy password to MacOS API is happy. + if (password == null || password.length ==0) { + // Must not be a char array with only a 0, as this is an empty + // string. Therefore use a single character. + password = new char[]{'A'} + } Object entry = entries.get(alias.toLowerCase()); For jdk8u-dev: diff -r baec3649f6c0 src/macosx/classes/apple/security/KeychainStore.java --- a/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 02:00:52 2014 +0400 +++ b/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 10:54:45 2014 +0200 @@ -140,7 +140,7 @@ * password to recover it. * * @param alias the alias name - * @param password the password for recovering the key + * @param password the password for recovering the key. This password is not used to access the private key in KeyChain, it is used internally only. * * @return the requested key, or null if the given alias does not exist * or does not identify a key entry. @@ -154,7 +154,16 @@ throws NoSuchAlgorithmException, UnrecoverableKeyException { permissionCheck(); - + // An empty password is rejected by MacOS API, no private key data + // is exported. If no password is passed (as is the case when + // this implementation is used as browser keystore in various + // deployment scenarios like webstart, JFX and applets), create + // a dummy password to MacOS API is happy. + if (password == null || password.length ==0) { + // Must not be a char array with only a 0, as this is an empty + // string. Therefore use a single character. + password = new char[]{'A'} + } Object entry = entries.get(alias.toLowerCase()); if (entry == null || !(entry instanceof KeyEntry)) { With best regards, Florian -- 3kraft IT GmbH & Co KG | Wasagasse 26/2 | 1090 Wien | ?sterreich | FN 333787 p (HG Wien) Komplement?r: 3kraft IT GmbH | Wasagasse 26/2 | 1090 Wien | ?sterreich | FN 333558 b (HG Wien) On 14.07.14 18:38, Florian Bruckner (3kraft) wrote: > Hi, > > I've been working on getting client certificates to run on OSX with Apple KeyChain in Java > Webstart. KeychainStore works fine if it is passed a keystore password. It does not use it, at > least not when trying to create a KeyStore with a private key entry. > > Java Webstart tries to load private keys from KeyChain if the browser keystore is activated. > Unfortunately it tries to load the private key with an empty password (a char[0]), and > KeychainStore rejects to load the private key then. It works fine for the trust store, as there > are no private keys involved. > > A simple "fix" for this is to set a dummy password in KeychainStore if no password is passed in > engineGetKey, e.g. like this: > > > if (password == null || password.length ==0) { > password = "DUMMY".toCharArray(); > } > > Well, not really a fix, but rather a POC that the empty password is in fact the problem. > > I've not found out what exactly it is that the private key is not loaded, I just verified that the > empty password passed by javaws causes it. Before I try to dig into KeychainStore - any idea why > the private keys are not loaded if the password is empty? > > regards, > > Florian > From hs at tagtraum.com Sat Jul 19 14:20:53 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Sat, 19 Jul 2014 16:20:53 +0200 Subject: New button styles in Yosemite Message-ID: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> Hey Guys, Yosemite seems to offer some new button styles, e.g. in Finder. It would be nice, if those could also be used from Java, in the spirit of https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html Is this on your radar? Cheers, -hendrik From petr.pchelko at oracle.com Mon Jul 21 06:43:54 2014 From: petr.pchelko at oracle.com (Petr Pchelko) Date: Mon, 21 Jul 2014 10:43:54 +0400 Subject: New button styles in Yosemite In-Reply-To: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> References: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> Message-ID: <6D0782C7-A12C-420F-944A-5D9BAE871E37@oracle.com> Hello, Hendrik. > Yosemite seems to offer some new button styles, e.g. in Finder. Yosemite is completely redesigned and it's not limited only to new button styles. Most of the controls are redesigned. > Is this on your radar? We are looking at this and thinking what can be done here. With best regards. Petr. On 19 ???? 2014 ?., at 18:20, Hendrik Schreiber wrote: > Hey Guys, > > Yosemite seems to offer some new button styles, e.g. in Finder. > It would be nice, if those could also be used from Java, in the spirit of https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html > > Is this on your radar? > > Cheers, > > -hendrik From hs at tagtraum.com Mon Jul 21 06:45:40 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Mon, 21 Jul 2014 08:45:40 +0200 Subject: New button styles in Yosemite In-Reply-To: <6D0782C7-A12C-420F-944A-5D9BAE871E37@oracle.com> References: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> <6D0782C7-A12C-420F-944A-5D9BAE871E37@oracle.com> Message-ID: <406DCE24-DD42-4F16-B02C-D469E636C155@tagtraum.com> > We are looking at this and thinking what can be done here. Hey Petr, glad to hear you're thinking about it :-) -hendrik From tobi at ultramixer.com Mon Jul 21 07:07:00 2014 From: tobi at ultramixer.com (Tobias Bley) Date: Mon, 21 Jul 2014 09:07:00 +0200 Subject: New button styles in Yosemite In-Reply-To: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> References: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> Message-ID: <5D8B3505-35F8-4C76-A380-E6B68500EF55@ultramixer.com> Hi guys,hi @AquaFX, what about AquaFX ;) Tobi > Am 19.07.2014 um 16:20 schrieb Hendrik Schreiber : > > Hey Guys, > > Yosemite seems to offer some new button styles, e.g. in Finder. > It would be nice, if those could also be used from Java, in the spirit of https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html > > Is this on your radar? > > Cheers, > > -hendrik From hs at tagtraum.com Mon Jul 21 07:31:55 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Mon, 21 Jul 2014 09:31:55 +0200 Subject: New button styles in Yosemite In-Reply-To: <5D8B3505-35F8-4C76-A380-E6B68500EF55@ultramixer.com> References: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> <5D8B3505-35F8-4C76-A380-E6B68500EF55@ultramixer.com> Message-ID: <8311E767-F3F9-4F61-BA79-EE55FD726108@tagtraum.com> On Jul 21, 2014, at 9:07, Tobias Bley wrote: > Hi guys,hi @AquaFX, > > what about AquaFX ;) What about it? -hendrik From tobi at ultramixer.com Mon Jul 21 07:36:19 2014 From: tobi at ultramixer.com (Tobias Bley) Date: Mon, 21 Jul 2014 09:36:19 +0200 Subject: New button styles in Yosemite In-Reply-To: <8311E767-F3F9-4F61-BA79-EE55FD726108@tagtraum.com> References: <42D169CB-F47F-4C96-A008-5B9D6ABE4907@tagtraum.com> <5D8B3505-35F8-4C76-A380-E6B68500EF55@ultramixer.com> <8311E767-F3F9-4F61-BA79-EE55FD726108@tagtraum.com> Message-ID: <8781B30E-DF15-446B-8250-ECAB5889A401@ultramixer.com> Do you plan tu update AquaFX for 10.10? > Am 21.07.2014 um 09:31 schrieb Hendrik Schreiber : > > On Jul 21, 2014, at 9:07, Tobias Bley wrote: > >> Hi guys,hi @AquaFX, >> >> what about AquaFX ;) > > What about it? > > -hendrik > From hs at tagtraum.com Wed Jul 23 17:32:41 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Wed, 23 Jul 2014 19:32:41 +0200 Subject: IllegalArgumentException on Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) Message-ID: <6A4DE755-D525-47D5-8592-A7CBC8759692@tagtraum.com> Hi, on calling Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) I get the following exception: java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:895) at java.util.TimSort.mergeAt(TimSort.java:512) at java.util.TimSort.mergeCollapse(TimSort.java:437) at java.util.TimSort.sort(TimSort.java:241) at java.util.Arrays.sort(Arrays.java:1438) at sun.awt.datatransfer.DataTransferer.setToSortedDataFlavorArray(DataTransferer.java:2399) at sun.awt.datatransfer.ClipboardTransferable.(ClipboardTransferable.java:101) at sun.awt.datatransfer.SunClipboard.getContents(SunClipboard.java:144) I was not able to reproduce this, but as this happened on startup, I guess it has to do with whatever was already in the system clipboard.. Perhaps somebody wants to take a look at this. Cheers, -hendrik java version "1.8.0_20-ea" Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23) Java HotSpot(TM) 64-Bit Server VM (build 25.20-b22, mixed mode) From petr.pchelko at oracle.com Wed Jul 23 18:37:38 2014 From: petr.pchelko at oracle.com (Petr Pchelko) Date: Wed, 23 Jul 2014 22:37:38 +0400 Subject: IllegalArgumentException on Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) In-Reply-To: <6A4DE755-D525-47D5-8592-A7CBC8759692@tagtraum.com> References: <6A4DE755-D525-47D5-8592-A7CBC8759692@tagtraum.com> Message-ID: <41EDA40C-BD09-4B10-8817-73B3DDB0A696@oracle.com> Hello, Hendrik. Interesting, because there was a similar problem that?s been fixed in 7u60 and 8: https://bugs.openjdk.java.net/browse/JDK-7173464 I?ll have a look at this, thank you for your report. With best regards. Petr. > On Jul 23, 2014, at 9:32 PM, Hendrik Schreiber wrote: > > Hi, > > on calling Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) I get the following exception: > > java.lang.IllegalArgumentException: Comparison method violates its general contract! > at java.util.TimSort.mergeHi(TimSort.java:895) > at java.util.TimSort.mergeAt(TimSort.java:512) > at java.util.TimSort.mergeCollapse(TimSort.java:437) > at java.util.TimSort.sort(TimSort.java:241) > at java.util.Arrays.sort(Arrays.java:1438) > at sun.awt.datatransfer.DataTransferer.setToSortedDataFlavorArray(DataTransferer.java:2399) > at sun.awt.datatransfer.ClipboardTransferable.(ClipboardTransferable.java:101) > at sun.awt.datatransfer.SunClipboard.getContents(SunClipboard.java:144) > > I was not able to reproduce this, but as this happened on startup, I guess it has to do with whatever was already in the system clipboard.. > Perhaps somebody wants to take a look at this. > > Cheers, > > -hendrik > > java version "1.8.0_20-ea" > Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23) > Java HotSpot(TM) 64-Bit Server VM (build 25.20-b22, mixed mode) From philip.race at oracle.com Wed Jul 23 18:50:13 2014 From: philip.race at oracle.com (Phil Race) Date: Wed, 23 Jul 2014 11:50:13 -0700 Subject: IllegalArgumentException on Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) In-Reply-To: <41EDA40C-BD09-4B10-8817-73B3DDB0A696@oracle.com> References: <6A4DE755-D525-47D5-8592-A7CBC8759692@tagtraum.com> <41EDA40C-BD09-4B10-8817-73B3DDB0A696@oracle.com> Message-ID: <53D003E5.1060507@oracle.com> I see there's also an "web bug incident" (so not public) that was closed out as a dup of that even though it was being reported against Linux on JDK 8 GA so is not likely a duplicate. I'll forward you that. -phil. On 7/23/14 11:37 AM, Petr Pchelko wrote: > Hello, Hendrik. > > Interesting, because there was a similar problem that?s been fixed in 7u60 and 8: > https://bugs.openjdk.java.net/browse/JDK-7173464 > > I?ll have a look at this, thank you for your report. > > With best regards. Petr. > >> On Jul 23, 2014, at 9:32 PM, Hendrik Schreiber wrote: >> >> Hi, >> >> on calling Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) I get the following exception: >> >> java.lang.IllegalArgumentException: Comparison method violates its general contract! >> at java.util.TimSort.mergeHi(TimSort.java:895) >> at java.util.TimSort.mergeAt(TimSort.java:512) >> at java.util.TimSort.mergeCollapse(TimSort.java:437) >> at java.util.TimSort.sort(TimSort.java:241) >> at java.util.Arrays.sort(Arrays.java:1438) >> at sun.awt.datatransfer.DataTransferer.setToSortedDataFlavorArray(DataTransferer.java:2399) >> at sun.awt.datatransfer.ClipboardTransferable.(ClipboardTransferable.java:101) >> at sun.awt.datatransfer.SunClipboard.getContents(SunClipboard.java:144) >> >> I was not able to reproduce this, but as this happened on startup, I guess it has to do with whatever was already in the system clipboard.. >> Perhaps somebody wants to take a look at this. >> >> Cheers, >> >> -hendrik >> >> java version "1.8.0_20-ea" >> Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23) >> Java HotSpot(TM) 64-Bit Server VM (build 25.20-b22, mixed mode) From hs at tagtraum.com Thu Jul 24 07:37:14 2014 From: hs at tagtraum.com (Hendrik Schreiber) Date: Thu, 24 Jul 2014 09:37:14 +0200 Subject: IllegalArgumentException on Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) In-Reply-To: <53D003E5.1060507@oracle.com> References: <6A4DE755-D525-47D5-8592-A7CBC8759692@tagtraum.com> <41EDA40C-BD09-4B10-8817-73B3DDB0A696@oracle.com> <53D003E5.1060507@oracle.com> Message-ID: Thanks, guys for looking into this despite the quite weak bug report. -hendrik From krueger at lesspain.de Fri Jul 25 06:34:59 2014 From: krueger at lesspain.de (=?UTF-8?Q?Robert_Kr=C3=BCger?=) Date: Fri, 25 Jul 2014 08:34:59 +0200 Subject: Horizontal scrolling not possible with touchpad with Metal and Nimbus L&F when both scrollbars are visible Message-ID: Hi, horizontal scrolling in a JScrollPane does not work with a touchpad with Metal and Nimbus Look & Feel when both scrollbars are visible. It does work with Aqua. This little example demonstrates the problem: import javax.swing.*; public class TestTreeScrolling { public static void main(String[] args) throws Exception { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if (info.getName().startsWith("Nimbus")) { UIManager.setLookAndFeel(info.getClassName()); break; } } final JFrame frame = new JFrame(TestTreeScrolling.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JScrollPane scrollPane = new JScrollPane(new JTree()); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); frame.getContentPane().add(scrollPane); frame.pack(); frame.setVisible(true); } } Expand the tree a bit and resize the window so that both scrollbars are visible. Making a horizontal scroll gesture on the touchpad results in vertical scrolling. Tested systematically with JDKs 6_51 and 8_11 but observed with all production releases of 8 before as well. Is this a known bug? Is there a known workaround (hacking the Look & Feel is also an option because we override it in our application anyway)? There must be as IntelliJ Idea does not have this problem and they are not using Aqua but I have failed to find it in their code. Does it make sense to file a bug report and if so where? Best, Robert From alexandr.scherbatiy at oracle.com Fri Jul 25 14:23:09 2014 From: alexandr.scherbatiy at oracle.com (Alexander Scherbatiy) Date: Fri, 25 Jul 2014 18:23:09 +0400 Subject: Horizontal scrolling not possible with touchpad with Metal and Nimbus L&F when both scrollbars are visible In-Reply-To: References: Message-ID: <53D2684D.6090207@oracle.com> Please, file the bug report in http://bugreport.java.com/bugreport Thanks, Alexandr. On 7/25/2014 10:34 AM, Robert Kr?ger wrote: > Hi, > > horizontal scrolling in a JScrollPane does not work with a touchpad > with Metal and Nimbus Look & Feel when both scrollbars are visible. > It does work with Aqua. > > This little example demonstrates the problem: > > import javax.swing.*; > > public class TestTreeScrolling { > public static void main(String[] args) throws Exception { > for (UIManager.LookAndFeelInfo info : > UIManager.getInstalledLookAndFeels()) { > if (info.getName().startsWith("Nimbus")) { > UIManager.setLookAndFeel(info.getClassName()); > break; > } > } > final JFrame frame = new > JFrame(TestTreeScrolling.class.getSimpleName()); > frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); > > final JScrollPane scrollPane = new JScrollPane(new JTree()); > scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); > scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); > frame.getContentPane().add(scrollPane); > frame.pack(); > frame.setVisible(true); > } > } > > Expand the tree a bit and resize the window so that both scrollbars > are visible. Making a horizontal scroll gesture on the touchpad > results in vertical scrolling. > > Tested systematically with JDKs 6_51 and 8_11 but observed with all > production releases of 8 before as well. > > Is this a known bug? > > Is there a known workaround (hacking the Look & Feel is also an option > because we override it in our application anyway)? There must be as > IntelliJ Idea does not have this problem and they are not using Aqua > but I have failed to find it in their code. > > Does it make sense to file a bug report and if so where? > > Best, > > Robert From krueger at lesspain.de Sat Jul 26 11:54:54 2014 From: krueger at lesspain.de (=?UTF-8?Q?Robert_Kr=C3=BCger?=) Date: Sat, 26 Jul 2014 13:54:54 +0200 Subject: Horizontal scrolling not possible with touchpad with Metal and Nimbus L&F when both scrollbars are visible In-Reply-To: <53D2684D.6090207@oracle.com> References: <53D2684D.6090207@oracle.com> Message-ID: OK, I have done that. Btw, are there any concrete plans to migrate that to Jira as well? Thanks, Robert On Fri, Jul 25, 2014 at 4:23 PM, Alexander Scherbatiy wrote: > > Please, file the bug report in http://bugreport.java.com/bugreport > > Thanks, > Alexandr. > > > On 7/25/2014 10:34 AM, Robert Kr?ger wrote: >> >> Hi, >> >> horizontal scrolling in a JScrollPane does not work with a touchpad >> with Metal and Nimbus Look & Feel when both scrollbars are visible. >> It does work with Aqua. >> >> This little example demonstrates the problem: >> >> import javax.swing.*; >> >> public class TestTreeScrolling { >> public static void main(String[] args) throws Exception { >> for (UIManager.LookAndFeelInfo info : >> UIManager.getInstalledLookAndFeels()) { >> if (info.getName().startsWith("Nimbus")) { >> UIManager.setLookAndFeel(info.getClassName()); >> break; >> } >> } >> final JFrame frame = new >> JFrame(TestTreeScrolling.class.getSimpleName()); >> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); >> >> final JScrollPane scrollPane = new JScrollPane(new JTree()); >> >> scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); >> >> scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); >> frame.getContentPane().add(scrollPane); >> frame.pack(); >> frame.setVisible(true); >> } >> } >> >> Expand the tree a bit and resize the window so that both scrollbars >> are visible. Making a horizontal scroll gesture on the touchpad >> results in vertical scrolling. >> >> Tested systematically with JDKs 6_51 and 8_11 but observed with all >> production releases of 8 before as well. >> >> Is this a known bug? >> >> Is there a known workaround (hacking the Look & Feel is also an option >> because we override it in our application anyway)? There must be as >> IntelliJ Idea does not have this problem and they are not using Aqua >> but I have failed to find it in their code. >> >> Does it make sense to file a bug report and if so where? >> >> Best, >> >> Robert > > -- Robert Kr?ger Managing Partner Lesspain GmbH & Co. KG www.lesspain-software.com From florian.bruckner at 3kraft.com Tue Jul 29 08:36:19 2014 From: florian.bruckner at 3kraft.com (Florian Bruckner (3kraft)) Date: Tue, 29 Jul 2014 10:36:19 +0200 Subject: apple.security.KeychainStore does not load private key (when called from javaws) In-Reply-To: <53C4ECC8.3020909@3kraft.com> References: <53C40783.4060204@3kraft.com> <53C4ECC8.3020909@3kraft.com> Message-ID: <53D75D03.4070403@3kraft.com> Hey guys, any feedback on this? What is the process to have a patch like this accepted? regards, Florian On 15.07.14 10:56, Florian Bruckner (3kraft) wrote: > To answer my own question: > > KeychainStore loads the private key through native code in KeystoreImpl.m. KeystoreImpl.m uses > this osx API to retrieve a PKCS#12 bag: > > https://developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#jumpTo_63 > > > The API documentation says the PKCS#12 keystore requires a password. This is either supplied by > the caller or the user is prompted (if a flag is set, which is not the case). > > KeychainStore then goes on to extract the private key from the returned PKCS#12 store and decrypts > it with the password. > > Therefore, the password passed into engineGetKey is actually used to encrypt and decrypt only in > the scope of this method. Therefore, the approach to create a dummy password for this use case is > not as weird as I initially thought. > > Please consider these patches to fix this issue: > > For jdk7u-dev: > > diff -r 35aabd00a534 src/macosx/classes/apple/security/KeychainStore.java > --- a/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 02:26:55 2014 +0400 > +++ b/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 10:52:44 2014 +0200 > @@ -134,7 +134,7 @@ > * password to recover it. > * > * @param alias the alias name > - * @param password the password for recovering the key > + * @param password the password for recovering the key. This password is not used to access > the private key in KeyChain, it is used internally only. > * > * @return the requested key, or null if the given alias does not exist > * or does not identify a key entry. > @@ -148,6 +148,16 @@ > throws NoSuchAlgorithmException, UnrecoverableKeyException > { > permissionCheck(); > + // An empty password is rejected by MacOS API, no private key data > + // is exported. If no password is passed (as is the case when > + // this implementation is used as browser keystore in various > + // deployment scenarios like webstart, JFX and applets), create > + // a dummy password to MacOS API is happy. > + if (password == null || password.length ==0) { > + // Must not be a char array with only a 0, as this is an empty > + // string. Therefore use a single character. > + password = new char[]{'A'} > + } > > Object entry = entries.get(alias.toLowerCase()); > > > > For jdk8u-dev: > > diff -r baec3649f6c0 src/macosx/classes/apple/security/KeychainStore.java > --- a/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 02:00:52 2014 +0400 > +++ b/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 10:54:45 2014 +0200 > @@ -140,7 +140,7 @@ > * password to recover it. > * > * @param alias the alias name > - * @param password the password for recovering the key > + * @param password the password for recovering the key. This password is not used to access > the private key in KeyChain, it is used internally only. > * > * @return the requested key, or null if the given alias does not exist > * or does not identify a key entry. > @@ -154,7 +154,16 @@ > throws NoSuchAlgorithmException, UnrecoverableKeyException > { > permissionCheck(); > - > + // An empty password is rejected by MacOS API, no private key data > + // is exported. If no password is passed (as is the case when > + // this implementation is used as browser keystore in various > + // deployment scenarios like webstart, JFX and applets), create > + // a dummy password to MacOS API is happy. > + if (password == null || password.length ==0) { > + // Must not be a char array with only a 0, as this is an empty > + // string. Therefore use a single character. > + password = new char[]{'A'} > + } > Object entry = entries.get(alias.toLowerCase()); > > if (entry == null || !(entry instanceof KeyEntry)) { > > > With best regards, > > Florian > From petr.pchelko at oracle.com Tue Jul 29 08:50:02 2014 From: petr.pchelko at oracle.com (Petr Pchelko) Date: Tue, 29 Jul 2014 12:50:02 +0400 Subject: apple.security.KeychainStore does not load private key (when called from javaws) In-Reply-To: <53D75D03.4070403@3kraft.com> References: <53C40783.4060204@3kraft.com> <53C4ECC8.3020909@3kraft.com> <53D75D03.4070403@3kraft.com> Message-ID: <0F9AD930-8C72-4BC9-A0FA-A5A5CDA850FC@oracle.com> Added security-dev. With best regards. Petr. > On Jul 29, 2014, at 12:36 PM, Florian Bruckner (3kraft) wrote: > > Hey guys, > > any feedback on this? > > What is the process to have a patch like this accepted? > > regards, > > Florian > > On 15.07.14 10:56, Florian Bruckner (3kraft) wrote: >> To answer my own question: >> >> KeychainStore loads the private key through native code in KeystoreImpl.m. KeystoreImpl.m uses this osx API to retrieve a PKCS#12 bag: >> >> https://developer.apple.com/library/mac/documentation/security/Reference/keychainservices/Reference/reference.html#jumpTo_63 >> >> The API documentation says the PKCS#12 keystore requires a password. This is either supplied by the caller or the user is prompted (if a flag is set, which is not the case). >> >> KeychainStore then goes on to extract the private key from the returned PKCS#12 store and decrypts it with the password. >> >> Therefore, the password passed into engineGetKey is actually used to encrypt and decrypt only in the scope of this method. Therefore, the approach to create a dummy password for this use case is not as weird as I initially thought. >> >> Please consider these patches to fix this issue: >> >> For jdk7u-dev: >> >> diff -r 35aabd00a534 src/macosx/classes/apple/security/KeychainStore.java >> --- a/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 02:26:55 2014 +0400 >> +++ b/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 10:52:44 2014 +0200 >> @@ -134,7 +134,7 @@ >> * password to recover it. >> * >> * @param alias the alias name >> - * @param password the password for recovering the key >> + * @param password the password for recovering the key. This password is not used to access the private key in KeyChain, it is used internally only. >> * >> * @return the requested key, or null if the given alias does not exist >> * or does not identify a key entry. >> @@ -148,6 +148,16 @@ >> throws NoSuchAlgorithmException, UnrecoverableKeyException >> { >> permissionCheck(); >> + // An empty password is rejected by MacOS API, no private key data >> + // is exported. If no password is passed (as is the case when >> + // this implementation is used as browser keystore in various >> + // deployment scenarios like webstart, JFX and applets), create >> + // a dummy password to MacOS API is happy. >> + if (password == null || password.length ==0) { >> + // Must not be a char array with only a 0, as this is an empty >> + // string. Therefore use a single character. >> + password = new char[]{'A'} >> + } >> >> Object entry = entries.get(alias.toLowerCase()); >> >> >> >> For jdk8u-dev: >> >> diff -r baec3649f6c0 src/macosx/classes/apple/security/KeychainStore.java >> --- a/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 02:00:52 2014 +0400 >> +++ b/src/macosx/classes/apple/security/KeychainStore.java Tue Jul 15 10:54:45 2014 +0200 >> @@ -140,7 +140,7 @@ >> * password to recover it. >> * >> * @param alias the alias name >> - * @param password the password for recovering the key >> + * @param password the password for recovering the key. This password is not used to access the private key in KeyChain, it is used internally only. >> * >> * @return the requested key, or null if the given alias does not exist >> * or does not identify a key entry. >> @@ -154,7 +154,16 @@ >> throws NoSuchAlgorithmException, UnrecoverableKeyException >> { >> permissionCheck(); >> - >> + // An empty password is rejected by MacOS API, no private key data >> + // is exported. If no password is passed (as is the case when >> + // this implementation is used as browser keystore in various >> + // deployment scenarios like webstart, JFX and applets), create >> + // a dummy password to MacOS API is happy. >> + if (password == null || password.length ==0) { >> + // Must not be a char array with only a 0, as this is an empty >> + // string. Therefore use a single character. >> + password = new char[]{'A'} >> + } >> Object entry = entries.get(alias.toLowerCase()); >> >> if (entry == null || !(entry instanceof KeyEntry)) { >> >> >> With best regards, >> >> Florian >> > From alexandr.scherbatiy at oracle.com Tue Jul 29 14:44:43 2014 From: alexandr.scherbatiy at oracle.com (Alexander Scherbatiy) Date: Tue, 29 Jul 2014 18:44:43 +0400 Subject: [OpenJDK 2D-Dev] [9] Review request for 8029339 Custom MultiResolution image support on HiDPI displays In-Reply-To: <53BC0803.6090704@oracle.com> References: <52D51764.8020103@oracle.com> <52DF2F98.3030503@oracle.com> <52F4BCEB.9040702@oracle.com> <52F5782A.9060300@oracle.com> <52FB7E3E.6050000@oracle.com> <52FC14EC.9080503@oracle.com> <53037D3D.80709@oracle.com> <5307E71E.50607@oracle.com> <530F3592.40600@oracle.com> <532B00AD.1000704@oracle.com> <532B7EC5.9000206@oracle.com> <532C4DD7.1080804@oracle.com> <532CD202.5070508@oracle.com> <53302A8E.6090107@oracle.com> <53343914.6090004@oracle.com> <533C8DDB.5000406@oracle.com> <533E9D42.10409@oracle.com> <53598D86.5020607@oracle.com> <535A7509.6050802@oracle.com> <5370DC41.5080608@oracle.com> <537639D5.9000206@oracle.com> <53764700.2060309@oracle.com> <5379E117.6010202@oracle.com> <538F2D56.80609@oracle.com> <5396220E.9030708@oracle.com> <5397180C.5040105@oracle.com> <53987361.5040903@oracle.com> <53BC0803.6090704@oracle.com> Message-ID: <53D7B35B.1010703@oracle.com> Just friendly remainder. Thanks, Alexandr. On 7/8/2014 7:02 PM, Alexander Scherbatiy wrote: > > > Hi Phil, > > Could you review the fix? > > Thanks, > Alexandr. > > > On 6/11/2014 7:18 PM, Alexander Scherbatiy wrote: >> >> Hi Phil , >> >> I just prepared a simple FAQ about the Custom MultiResolution image >> API. Hope it will be helpful. >> >> 1. Scale naming convention for high-resolution images. >> >> Different OSes use different "scale" naming convention for >> high-resolution images: >> Mac OS X: image.ext, image at 2x.ext >> Windows: image.scale-100.ext, image.scale-140.ext, image.scale-180.ext >> >> Q: Does "scale" naming convention supported in JDK? >> A: Mac OS X "scale" naming convention are supported in JDK 8u20 (see >> JDK-8011059) >> It is planned to support the Windows "scale" naming convention >> as well. >> >> Q. How does it work in JDK? >> A. Bundle image.ext and image at 2x.ext images with your app on Mac OS >> X and call Toolkit.getImage(...) method: >> Image image = Toolkit.getDefaultToolkit().getImage("image.ext"); >> Graphics2D g2d = // get graphics >> g2d.drawImage(image, 0, 0, null) >> SunGraphics2D automatically queries and draws the provided >> high-resolution image. >> >> Q: There are different "scale" naming conventions on Mac OS X and >> Windows. >> May be it is better to have unified "scale" naming conventions >> for all OSes in Java like image[java-scale-Nx].ext? >> A: It seems reasonable and can be filled as a new JDK enhancement. >> >> Q: Does using "scale" naming conventions solves all problems. >> A: There are tasks like image processing/programmatically generated >> images/loading images from non-standard sources >> that can't be solved with predefined set of images. >> Q: Are there any tools that support these tasks? >> A: Cocoa API contains NSImage that allows to work with image >> representations: addRepresentation/removeRepresentation/representations >> JDK uses these methods to get/set multi-resolution images for >> the Native system (see sun.lwawt.macosx.CImage class). >> >> 2. Graphics2D >> Q: How SunGraphics2D deals with multi-resolution images? >> A: SunGraphics2D queries a resolution variant using DPI scale factors >> and transformed base image sizes >> // logicalDPIX, logicalDPIY - DPI scale factors >> // destImageWidth, destImageHeight - transformed base image >> sizes including DPI scale factors >> multiResolutionImage.getResolutionVariant(logicalDPIX, >> logicalDPIY, destImageWidth, destImageHeight); >> >> Q: Which algorithm multi-resolution image is used in >> getResolutionVariant(...) method? >> A: ToolkitImage returned by toolkit.loadImage() method should behave >> like the native system. >> It means that it should use transformed image sizes on Mac OS X >> and only DPI scale factors on Windows. >> it looks like: >> ----------------- >> // logicalDPIX, logicalDPIY - DPI scale factors >> // destImageWidth, destImageHeight - transformed base image >> sizes including DPI scale factors >> public Image getResolutionVariant(float logicalDPIX, float >> logicalDPIY, >> float destImageWidth, float destImageHeight) { >> if (Mac OS X) { >> return resolution variant best fitted to the >> destImageWidth and destImageHeight >> } else if (Windows){ >> return resolution variant best fitted to the >> logicalDPIX and logicalDPIY scale factors >> } >> } >> ----------------- >> >> 3. Custom multi-resolution image. >> Q: The custom multi-resolution image should be able to return an >> image according to the requested >> transformed image size and DPI scale factors. Is it enough? >> A: There are task like setting custom cursor that require to get >> all resolution variants. >> So the custom multi-resolution image should also contain the >> getResolutionVariants(): >> >> Q: Should the custom multi-resolution image be class or interface? >> A: There is ToolkitImage that should also have resolution variants. >> It is not possible to extend it from MultiResolutionImage class. >> The current proposal introduces the MultiResolutionImage as an >> interface. >> >> Q: MultiResolutionImage interface sounds strange for me. >> A: The better name can be suggested. >> >> Q: What does the Custom MultiResolution image API suggest? >> A: The current proposal provides MultiResolutionImage interface >> with the following methods: >> --------------------------- >> Image getResolutionVariant(float logicalDPIX, float logicalDPIY, >> float destImageWidth, float destImageHeight); >> >> List getResolutionVariants(); >> --------------------------- >> and AbstractMultiResolutionImage class. See samples below. >> >> >> 4. Memory cost >> Q: Can the the implementation be "lazy"? >> A: SunGraphics2D does not require full list of resolution variants. >> It queries only the image with necessary resolution. >> It means that resolution variants can be loaded by demand. >> Setting a custom cursor requires all resolution variants. >> >> 5. Rendering hints. >> Q: Why rendering hints are added. >> A: Provided rendering hints affects only multi-resolution images and >> allows to disable >> resolution variants usage in app. It can be useful for >> performance reasons. >> >> 6. Samples. >> Q: It is interesting to look at samples. >> A: Below are 3 samples: >> 1. Draw an image with "Hello World!" text >> 2. Set a lightened custom cursor >> 3. Draw a multi-resolution image created from the program >> >> Sample 1. Draw a image with "Hello World!" text. The text is drawn >> both on the base image and on high-resolution image. >> disk: duke.png, duke at 2x.png >> ------------------------------- >> public static void main(String[] args) { >> >> Image image = >> Toolkit.getDefaultToolkit().getImage("duke.png"); // duke.png and >> duke at 2x.png images are loaded by MR-ToolkitImage >> >> Image imagewithText = image instanceof MultiResolutionImage >> ? new TextMultiresolutionImage(image) : drawText(image); >> >> Graphics2D g2d = // get graphics 2D >> g2d.drawImage(imagewithText, x, y, null); >> } >> >> static Image drawText(Image image) { >> // return an image with "Hello World!" text >> } >> >> static class TextMultiresolutionImage extends >> AbstractMultiResolutionImage { >> >> private final Image baseImage; >> >> public TextMultiresolutionImage(Image baseImage) { >> this.baseImage = baseImage; >> } >> >> @Override >> public Image getResolutionVariant(float logicalDPIX, float >> logicalDPIY, >> float destImageWidth, float destImageHeight) { >> Image rvImage = ((MultiResolutionImage) baseImage). >> getResolutionVariant(logicalDPIX, logicalDPIY, >> destImageWidth, destImageHeight); >> return drawText(rvImage); >> } >> >> @Override >> public List getResolutionVariants() { >> // this method is not used by SunGraphics2D to draw >> the image. >> // we just skip it in this example >> } >> >> @Override >> protected Image getBaseImage() { >> return drawText(baseImage); >> } >> } >> ------------------------------- >> >> Sample 2. Using filters to create a lightened custom cursor. >> The filter is applied to both the base and high-resolution image. >> ------------------------------- >> public static void main(String[] args) { >> >> Image image = >> Toolkit.getDefaultToolkit().getImage("cursor.png"); // cursor.png and >> cursor at 2x.png files are provided >> Image lightenedImage = image instanceof MultiResolutionImage >> ? new LigtenedMultiresolutionImage(image) : >> applyFilter(image); >> >> Cursor lightenedCursor = Toolkit.getDefaultToolkit(). >> createCustomCursor(lightenedImage, new Point(0, 0), >> "Lightened Cursor"); >> JFrame frame = new JFrame("Frame with lightened cursor"); >> frame.setCursor(lightenedCursor); >> } >> >> static Image applyFilter(Image image) { >> GrayFilter filter = new GrayFilter(true, 50); >> final ImageProducer prod = new >> FilteredImageSource(image.getSource(), filter); >> return Toolkit.getDefaultToolkit().createImage(prod); >> } >> >> static class LigtenedMultiresolutionImage extends >> AbstractMultiResolutionImage { >> >> private final Image baseImage; >> >> public LigtenedMultiresolutionImage(Image baseImage) { >> this.baseImage = baseImage; >> } >> >> @Override >> public Image getResolutionVariant(float logicalDPIX, float >> logicalDPIY, >> float destImageWidth, float destImageHeight) { >> // this method is not necessary for the custom cursor >> creation >> // we just skip it >> } >> >> // all resolution variants are created to pass them to >> NSImage for the custom cursor on Mac OS X. >> @Override >> public List getResolutionVariants() { >> List resolutionVariants = new LinkedList<>(); >> for (Image rvImage : ((MultiResolutionImage) baseImage). >> getResolutionVariants()) { >> resolutionVariants.add(applyFilter(rvImage)); >> } >> return resolutionVariants; >> } >> >> @Override >> protected Image getBaseImage() { >> return applyFilter(baseImage); >> } >> } >> ------------------------------- >> >> Sample 3. Draw a multi-resolution image created from the program: >> ------------------------------- >> public static void main(String[] args) { >> >> Image image = generateImage(1); >> Image image2x = generateImage(2); >> Image mrImage = new CustomMultiresolutionImage(image, image2x); >> >> Graphics2D g2d = // get graphics2D >> g2d.drawImage(mrImage, 0, 0, null); >> } >> >> static Image generateImage(float scaleFactor) { >> // generate image according to the scale factor >> } >> >> static class CustomMultiresolutionImage extends >> AbstractMultiResolutionImage { >> >> private final Image image; >> private final Image highResolutionImage; >> >> public CustomMultiresolutionImage(Image baseImage, Image >> highResolutionImage) { >> this.image = baseImage; >> this.highResolutionImage = highResolutionImage; >> } >> >> @Override >> public Image getResolutionVariant(float logicalDPIX, float >> logicalDPIY, >> float destImageWidth, float destImageHeight) { >> // destImageWidth and destImageHeight includes both >> transforms >> // DPI scale factors from Graphics >> if (destImageWidth <= image.getWidth(null) >> && destImageHeight <= image.getHeight(null)) { >> return image; >> } >> return highResolutionImage; >> } >> >> @Override >> public List getResolutionVariants() { >> return Arrays.asList(image, highResolutionImage); >> } >> >> @Override >> protected Image getBaseImage() { >> return image; >> } >> } >> ------------------------------- >> Thanks, >> Alexandr. >> >> >> On 6/10/2014 6:37 PM, Alexander Scherbatiy wrote: >>> On 6/10/2014 1:07 AM, Phil Race wrote: >>>> Why the split ? >>>> If you look only at the first part. If you can do that then why is >>>> the 2nd part needed ? >>> The second part introduces algorithms that can be used to >>> retrieve a resolution variant >>> from a set of images. It can be DPI based, transform based, OS >>> based and so on. >>> The first part can be implemented without the second part. >>> >>>> The name "MultiResolutionImage" implies to me that this is a >>>> sub-class of Image. >>>> But its not, its a way to get images. AbstractMultiResolutionImage, >>>> however is >>>> a subclass and it implements the former. >>> >>> Could you suggest the better name? It really needs to have an >>> interface if existed image implementation >>> is supposed to have resolution variants. The example which is >>> used in JDK is ToolkitImage. >>> Toolkit.getImage(filename) method returns ToolkitImage which is >>> loaded by demand. >>> LWCToolkit should return an image with resolution variants on Mac >>> OS X if both image and image at 2x >>> are provided. What we need here is the ToolkitImage that >>> contains resolution variants. >>> It can be done if the MultiResolutionImage is an interface and it >>> is not possible to do if MultiResolutionImage is a class. >>> Here is the MultiResolutionToolkitImage implementation: >>> http://hg.openjdk.java.net/jdk9/client/jdk/file/b7ef5e2d252c/src/share/classes/sun/awt/image/MultiResolutionToolkitImage.java >>> >>> >>>> I am supposing (since you don't explain) that you want an Image >>>> sub-class here >>>> so that the app can specify it where ever an Image is currently >>>> accepted by API >>>> and the API that is "aware" can accept it. >>> If an image implements the MultiResolutionImage interface, >>> SunGraphics2D can use it >>> to draw an image with necessary resolution on HiDPI display. >>> >>>> I worry about the memory cost of all of this. Can the the >>>> implementation be "lazy"? >>> Yes. See the MultiResolutionCachedImage implementation: >>> http://hg.openjdk.java.net/jdk9/client/jdk/file/b7ef5e2d252c/src/share/classes/sun/awt/image/MultiResolutionCachedImage.java >>> >>>> ie even if I call getResolutionVariants() do those images all have >>>> to be fully initialised before >>>> they are used? It looks like the app probably has to do so .. >>> If it needs to pass resolution variants to the native system >>> like setting a custom cursor on Mac OS X >>> it really needs to initialize all resolution variants. >>> >>> If it needs to create one multi-resolution image based on >>> another multi-resolution image like >>> generating a lightening image using a filter, it possible to do >>> this lazy. >>> See the map(Function mapper) method in the >>> MultiResolutionCachedImage. >>> >>> SunGraphics2D class uses only getResolutionVariant( ...) method >>> to retrieve necessary resolution variant. >>> It does not call getResolutionVariants() methods so all >>> resolution variants are not created during image drawing. >>> >>>> >>>> Also it precludes being able to return "on demand" an image that is >>>> rendered to >>>> be exactly the size requested. That could be created, drawn using >>>> graphics primitives >>>> and created precisely and only if needed. >>>> >>>> Instead we have an API that requires you to apparentlty eagerly >>>> create even the >>>> highest res image when you are on a device that has no need for it. >>>> >>>> Who will actually call getResolutionVariants() ? >>> Both. >>>> Is it us (the implementation) because we >>> We use it to create an NSImage from a custom cursor. See >>> Toolkit.createCustomCursor() >>> and CImage.createFromImage(final Image image) methods. >>> >>> Developers can use it to show all resolution variants in some >>> image tool. >>> >>>> don't trust the app to make the right selection based on the >>>> parameterised call >>>> getResolutionVariant() ? >>> As it shown, the getResolutionVariant(...) and >>> getResolutionVariants() methods are used >>> for different purposes. >>> getResolutionVariant(...) method is used by SunGraphics2D class >>> to pickup an image >>> with necessary resolution variant. >>> getResolutionVariants() method is used when an application needs >>> to use all resolution variants. >>> >>>> >>>> Which approach do we use to pick the image ? If its the former, the >>>> app controls it, >>> It is the former. >>> We also use it MR-ToolkitImage to get a resolution variant >>> according to the current system (for example, transforms >>> are included to get resolution variant size on Mac OS X). >>> >>>> if its the latter its us. But which ? >>>> >>>> I am still stuck on the parameters to getResolutionVariant >>>> >>>> * @param baseImageWidth the width of the base image. >>>> >>>> >>>> Isn't the base image always the smallest ? >>> No for general case. May be it would be possible to print a >>> multi-resolution image >>> on a printer that can have low DPI. >>> >>>> Why are we, the caller, supposed >>>> to say what that size to the class that has that image. >>> >>> This question has already had long discussion. The answer is that >>> we do it because it is free for us. >>> SunGraphics2D already gets the base image size because it uses it >>> for resolution image size calculation. >>> If you have objections against this, let's remove the base image >>> size parameters. >>> Developer always can obtain this information calling >>> getWidth()/Height() methods. >>> >>>> So I'd really like to see the example of that method in >>>> CustomMultiResolutionImage >>>> filled out so we can see what is imagined here .. >>> >>> Below are two samples. >>> The first one loads a multi-resolution image from disk, and >>> writes text "Hello World!" on it. Only getResolutionVariant(...) >>> method is used >>> by system in SunGraphics2D. The getResolutionVariants() method is >>> not used. >>> >>> The second one creates a lightened custom cursor. The >>> getResolutionVariants() method is called by system to create NSImage >>> with necessary image representations. >>> >>> Note that Toolkit.getImage(filename) method is already able to >>> load both image and image at 2x images on Mac OS X. >>> >>> Sample 1. Draw an image with "Hello World!" text: >>> disk: duke.png, duke at 2x.png >>> ------------------------------- >>> public static void main(String[] args) { >>> >>> Image image = >>> Toolkit.getDefaultToolkit().getImage("duke.png"); // duke.png and >>> duke at 2x.png images are loaded by MR-ToolkitImage >>> >>> Image imagewithText = image instanceof MultiResolutionImage >>> ? new TextMultiresolutionImage(image) : >>> drawText(image); >>> >>> Graphics2D g2d = // get graphics 2D >>> g2d.drawImage(imagewithText, x, y, null); >>> } >>> >>> static Image drawText(Image image) { >>> // return an image with "Hello World!" text >>> } >>> >>> static class TextMultiresolutionImage extends >>> AbstractMultiResolutionImage { >>> >>> private final Image baseImage; >>> >>> public TextMultiresolutionImage(Image baseImage) { >>> this.baseImage = baseImage; >>> } >>> >>> @Override >>> public Image getResolutionVariant(float destImageWidth, >>> float destImageHeight) { >>> Image rvImage = ((MultiResolutionImage) baseImage). >>> getResolutionVariant(destImageWidth, >>> destImageHeight); >>> return drawText(rvImage); >>> } >>> >>> // this method is not used by SunGraphics2D to draw the image >>> @Override >>> public List getResolutionVariants() { >>> List resolutionvariants = new LinkedList<>(); >>> for (Image image : ((MultiResolutionImage) baseImage). >>> getResolutionVariants()) { >>> resolutionvariants.add(drawText(image)); >>> } >>> return resolutionvariants; >>> } >>> >>> @Override >>> protected Image getBaseImage() { >>> return drawText(baseImage); >>> } >>> } >>> ------------------------------- >>> >>> Sample 2. Using filters to create a lightened custom cursor. >>> ------------------------------- >>> public static void main(String[] args) { >>> >>> Image image = >>> Toolkit.getDefaultToolkit().getImage("cursor.png"); // cursor.png >>> and cursor at 2x.png files are provided >>> Image lightenedImage = image instanceof MultiResolutionImage >>> ? new LigtenedMultiresolutionImage(image) : >>> applyFilter(image); >>> >>> Cursor lightenedCursor = Toolkit.getDefaultToolkit(). >>> createCustomCursor(lightenedImage, new Point(0, 0), >>> "Lightened Cursor"); >>> JFrame frame = new JFrame("Frame with lightened cursor"); >>> frame.setCursor(lightenedCursor); >>> } >>> >>> static Image applyFilter(Image image) { >>> // apply a filter to create ligtened image >>> } >>> >>> static class LigtenedMultiresolutionImage extends >>> AbstractMultiResolutionImage { >>> >>> private final Image baseImage; >>> >>> public LigtenedMultiresolutionImage(Image baseImage) { >>> this.baseImage = baseImage; >>> } >>> >>> @Override >>> public Image getResolutionVariant(float destImageWidth, >>> float destImageHeight) { >>> Image rvImage = ((MultiResolutionImage) baseImage). >>> getResolutionVariant(destImageWidth, >>> destImageHeight); >>> return applyFilter(rvImage); >>> } >>> >>> // all resolution variants are created to pass them to NSImage >>> @Override >>> public List getResolutionVariants() { >>> List resolutionvariants = new LinkedList<>(); >>> for (Image image : ((MultiResolutionImage) baseImage). >>> getResolutionVariants()) { >>> resolutionvariants.add(applyFilter(image)); >>> } >>> return resolutionvariants; >>> } >>> >>> @Override >>> protected Image getBaseImage() { >>> return applyFilter(baseImage); >>> } >>> } >>> ------------------------------- >>>> >>>> Based solely on the usage I see here, its not clear why >>>> MultiResolutionImage needs >>>> to separately exist. what would implement MultiResolutionImage >>>> except for >>>> a class that extends AbstractMultiResolutionImage ? Where would >>>> you use >>>> a straight implementation of MultiResolutionImage ? >>> See sun.awt.image.MultiResolutionToolkitImage in JDK 9. Both >>> ToolkitImage and MultiResolutionImage should be used in this case. >>> >>>> >>>> Actually I am not sure you answered Jim's question as to who is >>>> requesting these APIs. >>>> "The AWT team" doesn't need them as they won't be writing the apps. >>> >>> There was a long thread about the image with sub-pixel resolution >>> drawing on Mac OS X: >>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005559.html >>> >>> >>> It was pointed out that Icon images that can be programmatically >>> generated also need to have HiDPI support: >>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005566.html >>> >>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005569.html >>> >>> >>> All requests about Mac OS X HiDPI support were included to the >>> umbrella issue: >>> 7124410 [macosx] Lion HiDPI support >>> https://bugs.openjdk.java.net/browse/JDK-7124410 >>> >>>> >>>> If the 99% use case will be to provide a way for apps to provide >>>> images at custom sizes >>>> then we seem to be making them write new code. SFAIK FX found a way >>>> to do something >>>> similar to what OS X and Windows do which is to load based on file >>>> name convention. >>> JDK 8 have already loaded images with @2x name convention on >>> Mac OS X. >>> See the fix for the issue JDK-8011059 [macosx] Support >>> automatic @2x images loading on Mac OS X >>> https://bugs.openjdk.java.net/browse/JDK-8011059 >>>> If we can do that, we load just the one we need. Is the point >>>> of use so far removed from the loading logic that we can't do this ? >>> >>> Mac OS X has both ways to create images: using @2x name >>> convention for files >>> and NSImage with methods >>> addRepresentation/removeRepresentation/representations. >>> >>> The current API is proposed to dial with images that can have >>> source that is different from files. >>> It is also used to process already loaded images. >>> See the provided two samples with lightened custom cursor and >>> text on image. >>> Is it possible to write the same samples on JavaFX? >>> >>>> And none of this seems to help anyone who calls new >>>> BufferedImage(w, h, type) .. >>> >>> Yes. It needs to create a BufferedImage for each screen >>> resolution and put them to a multi-resolution image. >>> >>>> >>>> BTW I am not sold on the need for the RenderingHint. Where did the >>>> idea come from ? >>>> It would affect all rendering using that graphics instance, not >>>> just a specific image and >>>> if someone doesn't want a MultiRes image used, then maybe they just >>>> don't provide one .. >>> >>> KEY_RESOLUTION_VARIANT is used to switch on/off resolution >>> variants usage. >>> VALUE_RESOLUTION_VARIANT_ON - SunGraphics2D queries resolution >>> variants from multi-resolution image on HiDPI displays. >>> VALUE_RESOLUTION_VARIANT_OFF - SunGraphics2D does not use >>> resolution variants. Only base image is used. >>> >>>> In any case, without a solid demonstrated need I would not add the >>>> API. >>>> >>> See provided 2 samples. >>> >>> Thanks, >>> Alexandr. >>>> >>>> -phil. >>>> >>>> On 6/4/2014 7:29 AM, Alexander Scherbatiy wrote: >>>>> >>>>> Hi Phil, >>>>> >>>>> Could you review the fix where only new MultiResolutionImage >>>>> interface and AbstractMultiResolutionImage class are added: >>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.05/ >>>>> >>>>> Thanks, >>>>> Alexandr. >>>>> >>>>> >>>>> On 5/19/2014 2:46 PM, Alexander Scherbatiy wrote: >>>>>> >>>>>> Hi Phil, >>>>>> >>>>>> On 5/16/2014 9:12 PM, Phil Race wrote: >>>>>>> I think Jim was looking at this. I am not sure if you yet >>>>>>> answered all his questions/concerns. >>>>>>> >>>>>>> There's a lot of API here and it will take more time than I have >>>>>>> right now just to get >>>>>>> my head around it so do not expect a quick answer. >>>>>>> >>>>>>> 1. Why is there no javadoc on the new API on Toolkit ? >>>>>> It was decided to split the original issue on two parts: >>>>>> - this fix adds only MultiResolutionImage interface and >>>>>> AbstractMultiResolutionImage class. >>>>>> Here is the webrev for it: >>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.05/ >>>>>> - the Toolkit related API is moved to the separate issue >>>>>> >>>>>> Could you review the current fix: >>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.05/ >>>>>> >>>>>>> 2. What kinds of classes are expected to implement >>>>>>> MultiResolutionImage >>>>>>> Application ones or platform ones ? >>>>>> Both. >>>>>> - Application: A developer can provide a set of images with >>>>>> different resolutions to create a multi-resolution image. An >>>>>> image with best-fitting resolution >>>>>> will be drawn on HiDPI display. >>>>>> - Platform: we used it to support Aqua L&F on HiDPI displays. >>>>>> >>>>>>> 3. can you better explain all these parameters : >>>>>>> >>>>>>> 49 * @param logicalDPIX the logical horizontal DPI of the >>>>>>> desktop. >>>>>>> 50 * @param logicalDPIY the logical vertical DPI of the >>>>>>> desktop. >>>>>>> 51 * @param baseImageWidth the width of the base image. >>>>>>> 52 * @param baseImageHeight the height of the base image. >>>>>>> 53 * @param destImageWidth the width of the destination >>>>>>> image. >>>>>>> 54 * @param destImageHeight the height of the destination >>>>>>> image. >>>>>>> 55 * @return image resolution variant. >>>>>> >>>>>> Could we postpone it to the CCC request? >>>>>> >>>>>>> >>>>>>> 4. public List getResolutionVariants(); >>>>>>> >>>>>>> So this implies a fixed, known ahead of time set of images ? >>>>>>> Why is it required to have this API ? How will anyone be able to >>>>>>> tell which is which and use the list ? >>>>>> >>>>>> Here are some usages from the JDK code: >>>>>> - AquaImagefactory.getAppIconCompositedOn(final Image >>>>>> background) >>>>>> The original multi-resolution image is used to create >>>>>> another multi-resolution image with the background >>>>>> - AquaUtils.generateLightenedImage(Image image, ImageFilter >>>>>> filter) >>>>>> The original multi-resolution image is used to create >>>>>> lightening multi-resolution image >>>>>> - CImage.createFromImage(final Image image) >>>>>> Resolution variants from a multi-resolution image are >>>>>> used to create an NSImage >>>>>> - CCustomCursor: it is possible set a custom cursor which >>>>>> contains resolution variants to the native system >>>>>> >>>>>> Usually the getResolutionVariants() method is used to create >>>>>> one multi-resolution image based on the another multi-resolution >>>>>> image. >>>>>> >>>>>>> 5. Why is the rendering hint needed ? >>>>>> Someone can manually switch off the multi-resolution image >>>>>> drawing from graphics so only the base image will be drawn. >>>>>> It is useful for the performance reason. There is a choice >>>>>> to draw the high-resolution image slowly or the low-resolution >>>>>> image faster. >>>>>> >>>>>> Thanks, >>>>>> Alexandr. >>>>>>> -phil. >>>>>>> >>>>>>> >>>>>>> On 5/16/2014 9:16 AM, Alexander Scherbatiy wrote: >>>>>>>> >>>>>>>> Hi Phil, >>>>>>>> >>>>>>>> I need a reviewer from the 2d group for the fix. Could you >>>>>>>> take a look at the fix and review it? >>>>>>>> >>>>>>>> Thanks, >>>>>>>> Alexandr. >>>>>>>> >>>>>>>> >>>>>>>> On 5/12/2014 6:35 PM, Alexander Scherbatiy wrote: >>>>>>>>> >>>>>>>>> There was a long thread about the image with sub-pixel >>>>>>>>> resolution drawing on Mac OS X: >>>>>>>>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005559.html >>>>>>>>> >>>>>>>>> >>>>>>>>> It was pointed out that Icon images that can be >>>>>>>>> programmatically generated also need to have HiDPI support: >>>>>>>>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005566.html >>>>>>>>> >>>>>>>>> http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-April/005569.html >>>>>>>>> >>>>>>>>> >>>>>>>>> All requests about Mac OS X HiDPI support were included to >>>>>>>>> the umbrella issue: >>>>>>>>> 7124410 [macosx] Lion HiDPI support >>>>>>>>> https://bugs.openjdk.java.net/browse/JDK-7124410 >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Alexandr. >>>>>>>>> >>>>>>>>> On 4/25/2014 6:45 PM, Alexander Scherbatiy wrote: >>>>>>>>>> On 4/25/2014 2:17 AM, Jim Graham wrote: >>>>>>>>>>> Hi Alexandr, >>>>>>>>>>> >>>>>>>>>>> I asked for who was requesting these facilities and you >>>>>>>>>>> responded with the solution you are planning to provide. >>>>>>>>>>> >>>>>>>>>>> I don't care what the solution looks like if we have nobody >>>>>>>>>>> asking for the feature - I am asking who is asking for these >>>>>>>>>>> capabilities? >>>>>>>>>> >>>>>>>>>> This is the request from the AWT team for the HiDPI support. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> Alexandr. >>>>>>>>>>> >>>>>>>>>>> ...jim >>>>>>>>>>> >>>>>>>>>>> On 4/4/14 4:53 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>> On 4/3/2014 2:23 AM, Jim Graham wrote: >>>>>>>>>>>>> Hi Alexandr, >>>>>>>>>>>>> >>>>>>>>>>>>> The back and forth is getting confusing here, so I thought >>>>>>>>>>>>> I'd try to >>>>>>>>>>>>> summarize and start fresh(ish): >>>>>>>>>>>>> >>>>>>>>>>>>> 1. We need to support @2x internally for MacOS >>>>>>>>>>>>> compatibility (done). >>>>>>>>>>>>> >>>>>>>>>>>>> 2. We will need to support _DPI images for Win-DPI >>>>>>>>>>>>> compatibility (TBD). >>>>>>>>>>>>> >>>>>>>>>>>>> 3. Customers may have their own collection of images to >>>>>>>>>>>>> bundle >>>>>>>>>>>>> together into an MR image (working on that here). What is >>>>>>>>>>>>> the push >>>>>>>>>>>>> for this? Is this simply parity with Mac interfaces? >>>>>>>>>>>> >>>>>>>>>>>> ---------- >>>>>>>>>>>> Image[] resolutionVariants = // get sorted by >>>>>>>>>>>> sizes array of >>>>>>>>>>>> resolution variants; >>>>>>>>>>>> Image mrImage = >>>>>>>>>>>> Toolkit.getDefaultToolkit().createMRImage(baseImageIndex, >>>>>>>>>>>> resolutionVariants); >>>>>>>>>>>> ---------- >>>>>>>>>>>> >>>>>>>>>>>> Here is the proposed patch: >>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.04/ >>>>>>>>>>>> >>>>>>>>>>>>> 4. Customers may want to synthetically generate images at >>>>>>>>>>>>> arbitrary >>>>>>>>>>>>> resolutions (a variation that is impacting this solution). >>>>>>>>>>>>> What is >>>>>>>>>>>>> the push for this? >>>>>>>>>>>> ---------- >>>>>>>>>>>> Image mrImage = >>>>>>>>>>>> Toolkit.getDefaultToolkit().createMRImage(baseImageWidth, >>>>>>>>>>>> baseImageHeight, >>>>>>>>>>>> new float[][]{{100, 100}, {150, 150}, >>>>>>>>>>>> {200, 200}}, // >>>>>>>>>>>> resolution variants sizes >>>>>>>>>>>> (rvWidth, rvHeight) -> { /* generate a >>>>>>>>>>>> resolution >>>>>>>>>>>> variant */ }); >>>>>>>>>>>> ---------- >>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> 5. I'm guessing that customers might want to override the >>>>>>>>>>>>> logic to >>>>>>>>>>>>> choose from among multiple resolutions. That came from me >>>>>>>>>>>>> based on >>>>>>>>>>>>> seeing Mac and Win using different selection logic and our >>>>>>>>>>>>> history of >>>>>>>>>>>>> developers split between those wanting cross-platform >>>>>>>>>>>>> consistency and >>>>>>>>>>>>> those wanting consistency with native apps on each >>>>>>>>>>>>> platform. Also, >>>>>>>>>>>>> the needs of an animator may differ from the needs of a >>>>>>>>>>>>> resolution-settable-document editor as to how dynamically >>>>>>>>>>>>> the images >>>>>>>>>>>>> shift between resolution variants. >>>>>>>>>>>> ---------- >>>>>>>>>>>> Image[] resolutionVariants = // get sorted by >>>>>>>>>>>> sizes array of >>>>>>>>>>>> resolution variants; >>>>>>>>>>>> Image mrImage = ImageResolutionHelper.createMRImage( >>>>>>>>>>>> (rvWidth, rvHeight, resolutionVariants) -> >>>>>>>>>>>> { /*use a >>>>>>>>>>>> custom logic to choose a resolution variant from an array >>>>>>>>>>>> of images*/}, >>>>>>>>>>>> (logicalDPI, baseImageSize, destImageSize) -> >>>>>>>>>>>> destImageSize, // calculate the custom aware resolution >>>>>>>>>>>> variant size >>>>>>>>>>>> baseImageIndex, resolutionVariants); >>>>>>>>>>>> ---------- >>>>>>>>>>>> >>>>>>>>>>>> or just extend the CustomMultiResolutionImage which has >>>>>>>>>>>> Image as the >>>>>>>>>>>> parent class: >>>>>>>>>>>> >>>>>>>>>>>> -------------------- >>>>>>>>>>>> public class CustomMultiResolutionImage extends >>>>>>>>>>>> AbstractMultiResolutionImage { >>>>>>>>>>>> >>>>>>>>>>>> @Override >>>>>>>>>>>> public Image getResolutionVariant(float logicalDPIX, >>>>>>>>>>>> float >>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>> float baseImageWidth, float baseImageHeight, >>>>>>>>>>>> float destImageWidth, float destImageHeight) { >>>>>>>>>>>> // return a resolution variant based on the given >>>>>>>>>>>> logical DPI, >>>>>>>>>>>> // base image size, or destination image size >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> @Override >>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>> // return a list of resolution variants >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> @Override >>>>>>>>>>>> protected Image getBaseImage() { >>>>>>>>>>>> // return the base image >>>>>>>>>>>> } >>>>>>>>>>>> } >>>>>>>>>>>> -------------------- >>>>>>>>>>>>> >>>>>>>>>>>>> Is that a fair summary of all of the considerations so >>>>>>>>>>>>> far, or did I >>>>>>>>>>>>> miss something? >>>>>>>>>>>> I think it should cover the main needs. >>>>>>>>>>>> >>>>>>>>>>>> Thanks, >>>>>>>>>>>> Alexandr. >>>>>>>>>>>>> >>>>>>>>>>>>> ...jim >>>>>>>>>>>>> >>>>>>>>>>>>> On 3/27/14 7:43 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>> >>>>>>>>>>>>>> Below are some thoughts about TK.createMRImage(...) method >>>>>>>>>>>>>> >>>>>>>>>>>>>> On 3/24/2014 4:52 PM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Could you review the updated fix: >>>>>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.03/ >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> - baseImageWidth/Height arguments are added to the >>>>>>>>>>>>>>> getResolutionVariant(...) method >>>>>>>>>>>>>>> - dest image sizes are reverted to included DPI scale >>>>>>>>>>>>>>> - AbstractMultiResolutionImage is added. It needs only >>>>>>>>>>>>>>> to implement >>>>>>>>>>>>>>> only 3 methods from the AbstractMultiResolutionImage class >>>>>>>>>>>>>>> to create a custom multi-resolution image. For example: >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> On 3/22/2014 3:57 AM, Jim Graham wrote: >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> Your code example below can be expressed as an >>>>>>>>>>>>>>>> implementation of the >>>>>>>>>>>>>>>> single-method, lambda-compatible interface that >>>>>>>>>>>>>>>> expresses just the >>>>>>>>>>>>>>>> getRV() method. They could easily do: >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> final Image baseImage = ...; >>>>>>>>>>>>>>>> TK.createMRImage(new RVInterface() { >>>>>>>>>>>>>>>> public Image getRV(...) { >>>>>>>>>>>>>>>> // calculate rvWidth and rvHeight >>>>>>>>>>>>>>>> // look up rvWidth/rvHeight in a database of >>>>>>>>>>>>>>>> images >>>>>>>>>>>>>>>> // possibly contruct a new image >>>>>>>>>>>>>>>> return rvImage; >>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>> }, baseImage); >>>>>>>>>>>>>>>> >>>>>>>>>>>>>> The RVInterface mixes the logic that construct an >>>>>>>>>>>>>> image and >>>>>>>>>>>>>> chooses the necessary resolution variant. >>>>>>>>>>>>>> It is ok if a developer always implements this >>>>>>>>>>>>>> interface. If it >>>>>>>>>>>>>> needs to have DPI/Transform/Platform aware RVInterface >>>>>>>>>>>>>> the image >>>>>>>>>>>>>> construction logic should be separated. >>>>>>>>>>>>>> >>>>>>>>>>>>>> Does TK.createMRImage() method implies that >>>>>>>>>>>>>> Platform aware logic >>>>>>>>>>>>>> should be used for a resolution-variant choosing? >>>>>>>>>>>>>> If so, may be general createMRImage() can be placed >>>>>>>>>>>>>> in the >>>>>>>>>>>>>> ImageResolutionHelper. >>>>>>>>>>>>>>>> The main issue I see is if you might want the newly >>>>>>>>>>>>>>>> constructed >>>>>>>>>>>>>>>> variants to appear in the List returned from the >>>>>>>>>>>>>>>> getVariants() >>>>>>>>>>>>>>>> method. I'm not sure what value that would have beyond >>>>>>>>>>>>>>>> simply >>>>>>>>>>>>>>>> returning the base media that the object uses from >>>>>>>>>>>>>>>> which to construct >>>>>>>>>>>>>>>> its variants...? >>>>>>>>>>>>>> >>>>>>>>>>>>>> It can be solved by using something like array of >>>>>>>>>>>>>> image sizes or >>>>>>>>>>>>>> other seeds and a mapper that can create an image from >>>>>>>>>>>>>> the given seed. >>>>>>>>>>>>>> >>>>>>>>>>>>>> It can look like: >>>>>>>>>>>>>> ------------------------- >>>>>>>>>>>>>> public class ImageResolutionHelper { >>>>>>>>>>>>>> public interface RVChooser { >>>>>>>>>>>>>> >>>>>>>>>>>>>> public Image getRV( >>>>>>>>>>>>>> float logicalDPIX, float logicalDPIY, >>>>>>>>>>>>>> float baseImageWidth, float >>>>>>>>>>>>>> baseImageHeight, >>>>>>>>>>>>>> float destImageWidth, float >>>>>>>>>>>>>> destImageHeight, >>>>>>>>>>>>>> final Image... resolutionVariants); >>>>>>>>>>>>>> } >>>>>>>>>>>>>> >>>>>>>>>>>>>> public static final RVChooser DPI_AWARE = ...; >>>>>>>>>>>>>> public static final RVChooser TRANSFORM_AWARE = ...; >>>>>>>>>>>>>> >>>>>>>>>>>>>> // resolutionVariants is an array of sorted by >>>>>>>>>>>>>> width/height images >>>>>>>>>>>>>> static Image createMRImage(final RVChooser rvChooser, >>>>>>>>>>>>>> final int baseImageIndex, final Image... >>>>>>>>>>>>>> resolutionVariants) { ... } >>>>>>>>>>>>>> >>>>>>>>>>>>>> // sorted by width/height images should be generated >>>>>>>>>>>>>> from seeds >>>>>>>>>>>>>> static Image createMRImage(final RVChooser >>>>>>>>>>>>>> rvChooser, >>>>>>>>>>>>>> final Type baseImageSeed, final >>>>>>>>>>>>>> Function >>>>>>>>>>>>>> mapper, final Type... rvSeeds) {...} >>>>>>>>>>>>>> } >>>>>>>>>>>>>> >>>>>>>>>>>>>> public abstract class Toolkit { >>>>>>>>>>>>>> public abstract Image createMRImage(int >>>>>>>>>>>>>> baseImageIndex, Image... >>>>>>>>>>>>>> resolutionVariants); // Platform aware rv chooser is used >>>>>>>>>>>>>> public abstract RVChooser getPlatformRVChooser() ; >>>>>>>>>>>>>> } >>>>>>>>>>>>>> -------------------------- >>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>> >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> I think it is better to provide both the >>>>>>>>>>>>>>>>> MultiResolutionImage >>>>>>>>>>>>>>>>> and >>>>>>>>>>>>>>>>> its implementation based on the given resolution >>>>>>>>>>>>>>>>> variants array. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> It occurs to me that even if we don't go with a >>>>>>>>>>>>>>>> lambda-factory-based >>>>>>>>>>>>>>>> approach like what I'm describing, it might make sense >>>>>>>>>>>>>>>> to provide a >>>>>>>>>>>>>>>> baseMR implementation that they can subclass to keep >>>>>>>>>>>>>>>> them from trying >>>>>>>>>>>>>>>> to subclass off of BufferedImage instead. I really >>>>>>>>>>>>>>>> would like to >>>>>>>>>>>>>>>> avoid "custom MR images are subclasses of BufImg" if we >>>>>>>>>>>>>>>> can as I >>>>>>>>>>>>>>>> think the mix of concepts is a little jarring... >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> The implementation could look like: >>>>>>>>>>>>>>>>> --------------------------------- >>>>>>>>>>>>>>>>> public class CustomMultiResolutionImage extends Image >>>>>>>>>>>>>>>>> implements >>>>>>>>>>>>>>>>> MultiResolutionImage { >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> int baseImageIndex; >>>>>>>>>>>>>>>>> Image[] resolutionVariants; >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> public CustomMultiResolutionImage(int >>>>>>>>>>>>>>>>> baseImageIndex, >>>>>>>>>>>>>>>>> Image... resolutionVariants) { >>>>>>>>>>>>>>>>> this.baseImageIndex = baseImageIndex; >>>>>>>>>>>>>>>>> this.resolutionVariants = resolutionVariants; >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public int getWidth(ImageObserver observer) { >>>>>>>>>>>>>>>>> return getBaseImage().getWidth(null); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public int getHeight(ImageObserver observer) { >>>>>>>>>>>>>>>>> return getBaseImage().getHeight(null); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public ImageProducer getSource() { >>>>>>>>>>>>>>>>> return getBaseImage().getSource(); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public Graphics getGraphics() { >>>>>>>>>>>>>>>>> return getBaseImage().getGraphics(); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public Object getProperty(String name, >>>>>>>>>>>>>>>>> ImageObserver observer) { >>>>>>>>>>>>>>>>> return getBaseImage().getProperty(name, >>>>>>>>>>>>>>>>> observer); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public Image getResolutionVariant(float >>>>>>>>>>>>>>>>> logicalDPIX, float >>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>> float destinationImageWidth, float >>>>>>>>>>>>>>>>> destinationImageHeight) { >>>>>>>>>>>>>>>>> // calculate resolution variant width/height >>>>>>>>>>>>>>>>> return getResolutionVariant(rvWidth, rvHeight); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>>>>>>> return Arrays.asList(resolutionVariants); >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> private Image getResolutionVariant(float rvWidth, >>>>>>>>>>>>>>>>> float >>>>>>>>>>>>>>>>> rvHeight) { >>>>>>>>>>>>>>>>> // return a resolution variant based on the >>>>>>>>>>>>>>>>> given width and >>>>>>>>>>>>>>>>> height >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> private Image getBaseImage() { >>>>>>>>>>>>>>>>> return resolutionVariants[baseImageIndex]; >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>> --------------------------------- >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> Then we provide one of these from >>>>>>>>>>>>>>>>>> TK.get/createImage() when the >>>>>>>>>>>>>>>>>> platform detects @2x, or Win8-style variants. >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> For custom images we provide TK.createMRImage(lambda >>>>>>>>>>>>>>>>>> getRV, Image >>>>>>>>>>>>>>>>>> variants...) and TK.createMRImage(Image variants...); >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> Since the get method is just bookkeeping, I >>>>>>>>>>>>>>>>>> don't see them >>>>>>>>>>>>>>>>>> needing to override it, so the getRV() method is >>>>>>>>>>>>>>>>>> really the only >>>>>>>>>>>>>>>>>> thing >>>>>>>>>>>>>>>>>> they might want to override, and we can tie into the >>>>>>>>>>>>>>>>>> new Lambda >>>>>>>>>>>>>>>>>> capabilities by making a single-method interface for >>>>>>>>>>>>>>>>>> it that they >>>>>>>>>>>>>>>>>> supply in a factory method. >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> I realize that the interface you created is more >>>>>>>>>>>>>>>>>> fundamentally >>>>>>>>>>>>>>>>>> OO, but >>>>>>>>>>>>>>>>>> the Image class has always been special in this >>>>>>>>>>>>>>>>>> regard in the AWT >>>>>>>>>>>>>>>>>> ecosystem (in so far as we do not support someone >>>>>>>>>>>>>>>>>> implementing their >>>>>>>>>>>>>>>>>> own Image subclass even though it is technically >>>>>>>>>>>>>>>>>> possible). >>>>>>>>>>>>>>>>>> Because of >>>>>>>>>>>>>>>>>> this special nature of Image, we end up with the >>>>>>>>>>>>>>>>>> situation that if >>>>>>>>>>>>>>>>>> someone were given a need to create a subclass of >>>>>>>>>>>>>>>>>> Image, then they >>>>>>>>>>>>>>>>>> would turn to BufImg as their superclass even though >>>>>>>>>>>>>>>>>> BufImg is >>>>>>>>>>>>>>>>>> essentially an implementation-specific leaf node on >>>>>>>>>>>>>>>>>> the Image class >>>>>>>>>>>>>>>>>> hierarchy. This approach with a factory method to >>>>>>>>>>>>>>>>>> create an >>>>>>>>>>>>>>>>>> internal >>>>>>>>>>>>>>>>>> subclass of the new MRI class mirrors the existing >>>>>>>>>>>>>>>>>> cases of Image >>>>>>>>>>>>>>>>>> objects that come from factories as well. >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> Thoughts? >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> On 3/20/14 7:52 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> Could you review the updated version of the fix: >>>>>>>>>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.01/ >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> - The "getResolutionVariant(int width, int >>>>>>>>>>>>>>>>>>> height)" method from >>>>>>>>>>>>>>>>>>> MultiResolutionImage class is changed to >>>>>>>>>>>>>>>>>>> Image getResolutionVariant(float logicalDPIX, float >>>>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>>>> float width, float height, AffineTransform transform); >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> - sun.awt.image.ImageResolutionHelper class is >>>>>>>>>>>>>>>>>>> added. The >>>>>>>>>>>>>>>>>>> sun.awt.image.MultiResolutionToolkitImage and >>>>>>>>>>>>>>>>>>> sun.awt.image.MultiResolutionBufferedImage classes >>>>>>>>>>>>>>>>>>> are used >>>>>>>>>>>>>>>>>>> PLATFORM ImageResolutionHelper. >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> The MultiResolutionImage interface implementation >>>>>>>>>>>>>>>>>>> could look >>>>>>>>>>>>>>>>>>> like: >>>>>>>>>>>>>>>>>>> ------------------------------ >>>>>>>>>>>>>>>>>>> public class CustomMultiResolutionImage extends >>>>>>>>>>>>>>>>>>> BufferedImage >>>>>>>>>>>>>>>>>>> implements >>>>>>>>>>>>>>>>>>> MultiResolutionImage { >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> private final Image[] resolutionVariants; >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> public CustomMultiResolutionImage(int >>>>>>>>>>>>>>>>>>> baseIndex, Image... >>>>>>>>>>>>>>>>>>> images) { >>>>>>>>>>>>>>>>>>> super(images[baseIndex].getWidth(null), >>>>>>>>>>>>>>>>>>> images[baseIndex].getHeight(null), >>>>>>>>>>>>>>>>>>> BufferedImage.TYPE_INT_RGB); >>>>>>>>>>>>>>>>>>> this.resolutionVariants = images; >>>>>>>>>>>>>>>>>>> Graphics g = getGraphics(); >>>>>>>>>>>>>>>>>>> g.drawImage(images[baseIndex], 0, 0, null); >>>>>>>>>>>>>>>>>>> g.dispose(); >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(float >>>>>>>>>>>>>>>>>>> logicalDPIX, float >>>>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>>>> float width, float height, AffineTransform >>>>>>>>>>>>>>>>>>> transform) { >>>>>>>>>>>>>>>>>>> return getResolutionVariant(logicalDPIX * >>>>>>>>>>>>>>>>>>> width, >>>>>>>>>>>>>>>>>>> logicalDPIY * >>>>>>>>>>>>>>>>>>> height); >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>>>>>>>>> return Arrays.asList(resolutionVariants); >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(double width, >>>>>>>>>>>>>>>>>>> double >>>>>>>>>>>>>>>>>>> height) { >>>>>>>>>>>>>>>>>>> for (Image image : resolutionVariants) { >>>>>>>>>>>>>>>>>>> if (width <= image.getWidth(null) && >>>>>>>>>>>>>>>>>>> height <= >>>>>>>>>>>>>>>>>>> image.getHeight(null)) { >>>>>>>>>>>>>>>>>>> return image; >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> return this; >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>> ------------------------------ >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> On 2/27/2014 4:54 PM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>> On 2/22/2014 3:54 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>> Hi Alexandr, >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> On 2/18/14 7:33 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>> Hi Jim, >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> Let's divide the discussion into two part. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> 1. Where it is better to hold resolution variants? >>>>>>>>>>>>>>>>>>>>>> Putting resolution variants in Image class >>>>>>>>>>>>>>>>>>>>>> brings some >>>>>>>>>>>>>>>>>>>>>> questions like: >>>>>>>>>>>>>>>>>>>>>> - Some type of images do not need to have >>>>>>>>>>>>>>>>>>>>>> resolution variants >>>>>>>>>>>>>>>>>>>>>> - Should resolution variants have the same >>>>>>>>>>>>>>>>>>>>>> type as the base >>>>>>>>>>>>>>>>>>>>>> image? >>>>>>>>>>>>>>>>>>>>>> - getResolutionVariants() method can return >>>>>>>>>>>>>>>>>>>>>> copy of the >>>>>>>>>>>>>>>>>>>>>> original >>>>>>>>>>>>>>>>>>>>>> list >>>>>>>>>>>>>>>>>>>>>> so add/removeRV methods should be also added. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> There are pros and cons for placing resolution >>>>>>>>>>>>>>>>>>>>>> variants to >>>>>>>>>>>>>>>>>>>>>> Image >>>>>>>>>>>>>>>>>>>>>> class or to a separate intreface. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> I agree that this could be a separate interface. >>>>>>>>>>>>>>>>>>>>> In my examples >>>>>>>>>>>>>>>>>>>>> below I was just sticking them inside an "Image{}" >>>>>>>>>>>>>>>>>>>>> to show where >>>>>>>>>>>>>>>>>>>>> they >>>>>>>>>>>>>>>>>>>>> lived in the set of involved objects, not a specific >>>>>>>>>>>>>>>>>>>>> recommendation >>>>>>>>>>>>>>>>>>>>> that they actually be new methods on the base >>>>>>>>>>>>>>>>>>>>> class itself. I >>>>>>>>>>>>>>>>>>>>> probably should have put a comment there about that. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> With respect to add/remove - that is assuming a >>>>>>>>>>>>>>>>>>>>> need for manual >>>>>>>>>>>>>>>>>>>>> construction of an image set, right? Forgive me if >>>>>>>>>>>>>>>>>>>>> I'm >>>>>>>>>>>>>>>>>>>>> forgetting >>>>>>>>>>>>>>>>>>>>> something, but I seem to recall that manual >>>>>>>>>>>>>>>>>>>>> Multi-Res images was >>>>>>>>>>>>>>>>>>>>> proposed as a way for developers to introduce @2x >>>>>>>>>>>>>>>>>>>>> support >>>>>>>>>>>>>>>>>>>>> themselves, >>>>>>>>>>>>>>>>>>>>> but if we are internally managing @2x and -DPI >>>>>>>>>>>>>>>>>>>>> variants for them, >>>>>>>>>>>>>>>>>>>>> then I'm not sure if there is actual developer >>>>>>>>>>>>>>>>>>>>> need to manually >>>>>>>>>>>>>>>>>>>>> construct their own. Am I forgetting something? >>>>>>>>>>>>>>>>>>>> The NSImage has >>>>>>>>>>>>>>>>>>>> addRepresentation/removeRepresentation >>>>>>>>>>>>>>>>>>>> methods to >>>>>>>>>>>>>>>>>>>> work with image representations on Mac OS X. >>>>>>>>>>>>>>>>>>>> The java.awt.Image class should provide similar >>>>>>>>>>>>>>>>>>>> functionality to >>>>>>>>>>>>>>>>>>>> have the possibilities as Cocoa on HiDPI displays. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> 2. Using scale factor/image sizes/scaled image >>>>>>>>>>>>>>>>>>>>>> sizes to >>>>>>>>>>>>>>>>>>>>>> retreive a >>>>>>>>>>>>>>>>>>>>>> resolution variant. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> May be it is better to have a structure that >>>>>>>>>>>>>>>>>>>>>> provide all >>>>>>>>>>>>>>>>>>>>>> necessary >>>>>>>>>>>>>>>>>>>>>> information to query the resolution variant: >>>>>>>>>>>>>>>>>>>>>> scale factor, >>>>>>>>>>>>>>>>>>>>>> draw area >>>>>>>>>>>>>>>>>>>>>> width/height, transformed area width/height? >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> For example: >>>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>>> public interface MultiResolutionImage { >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> interface DrawAreaInfo { >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> float getScaleFactor(); >>>>>>>>>>>>>>>>>>>>>> float getAreaWidth(); >>>>>>>>>>>>>>>>>>>>>> float getAreaHeight(); >>>>>>>>>>>>>>>>>>>>>> float getTransformedAreaWidth(); >>>>>>>>>>>>>>>>>>>>>> float getTransformedAreaHeight(); >>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> public Image >>>>>>>>>>>>>>>>>>>>>> getResolutionVariant(DrawAreaInfo >>>>>>>>>>>>>>>>>>>>>> drawAreaInfo) ; >>>>>>>>>>>>>>>>>>>>>> public List getResolutionVariants(); >>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> The problem with a constructor is that this is >>>>>>>>>>>>>>>>>>>>> something that is >>>>>>>>>>>>>>>>>>>>> (potentially) done on every drawImage() call, >>>>>>>>>>>>>>>>>>>>> which means we are >>>>>>>>>>>>>>>>>>>>> inviting GC into the equation. If we can come up >>>>>>>>>>>>>>>>>>>>> with a simple >>>>>>>>>>>>>>>>>>>>> "just >>>>>>>>>>>>>>>>>>>>> a couple/3/4 numbers" way to embed that data into >>>>>>>>>>>>>>>>>>>>> a method call >>>>>>>>>>>>>>>>>>>>> argument list then we can make this lighter weight. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> What about simply having floating point (double) >>>>>>>>>>>>>>>>>>>>> dimensions on >>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>> rendered size >>>>>>>>>>>>>>>>>>>> There should be a way to choose a resolution >>>>>>>>>>>>>>>>>>>> variant >>>>>>>>>>>>>>>>>>>> based on >>>>>>>>>>>>>>>>>>>> requested drawing size or transformed drawing size. >>>>>>>>>>>>>>>>>>>> At least a current transformation should be >>>>>>>>>>>>>>>>>>>> included too. >>>>>>>>>>>>>>>>>>>>> plus a single floating point "logical DPI" for the >>>>>>>>>>>>>>>>>>>>> screen? >>>>>>>>>>>>>>>>>>>> There is the ID2D1Factory::GetDesktopDpi >>>>>>>>>>>>>>>>>>>> method which returns >>>>>>>>>>>>>>>>>>>> dpiX and dpiY. >>>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/windows/apps/dd371316 >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> That means that logicalDPIX/Y can have >>>>>>>>>>>>>>>>>>>> different values. >>>>>>>>>>>>>>>>>>>> At least it is described in the >>>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/windows/apps/ff684173 >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> "To get the DPI setting, call the >>>>>>>>>>>>>>>>>>>> ID2D1Factory::GetDesktopDpi >>>>>>>>>>>>>>>>>>>> method. The DPI is returned as two floating-point >>>>>>>>>>>>>>>>>>>> values, one for >>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>> x-axis and one for the y-axis. In theory, these >>>>>>>>>>>>>>>>>>>> values can differ. >>>>>>>>>>>>>>>>>>>> Calculate a separate scaling factor for each axis." >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> The getResolutionVariant method could look like: >>>>>>>>>>>>>>>>>>>> -------------------------------------- >>>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(float >>>>>>>>>>>>>>>>>>>> logicalDPIX, float >>>>>>>>>>>>>>>>>>>> logicalDPIY, >>>>>>>>>>>>>>>>>>>> float widthX, float widthY, >>>>>>>>>>>>>>>>>>>> AffineTransform >>>>>>>>>>>>>>>>>>>> transform); >>>>>>>>>>>>>>>>>>>> -------------------------------------- >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> If the image is known (either passed as an >>>>>>>>>>>>>>>>>>>>> argument or the >>>>>>>>>>>>>>>>>>>>> method is >>>>>>>>>>>>>>>>>>>>> called on the image), then it can provide the >>>>>>>>>>>>>>>>>>>>> original WH. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> The MultiResolutionImage default implementation >>>>>>>>>>>>>>>>>>>>>> could allow >>>>>>>>>>>>>>>>>>>>>> to use >>>>>>>>>>>>>>>>>>>>>> different strategies like scale >>>>>>>>>>>>>>>>>>>>>> factor/transfom/OS based >>>>>>>>>>>>>>>>>>>>>> to query a resolution variant. The OS based >>>>>>>>>>>>>>>>>>>>>> strategy can be >>>>>>>>>>>>>>>>>>>>>> used by >>>>>>>>>>>>>>>>>>>>>> default. >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> For Mac policy, all we need is the transformed >>>>>>>>>>>>>>>>>>>>> dimensions, which >>>>>>>>>>>>>>>>>>>>> can >>>>>>>>>>>>>>>>>>>>> be passed in as FP for generality. For Windows >>>>>>>>>>>>>>>>>>>>> policy, all we >>>>>>>>>>>>>>>>>>>>> need >>>>>>>>>>>>>>>>>>>>> is logical DPI for the screen. What other >>>>>>>>>>>>>>>>>>>>> information would we >>>>>>>>>>>>>>>>>>>>> need, or would an algorithm like to use, that >>>>>>>>>>>>>>>>>>>>> can't be computed >>>>>>>>>>>>>>>>>>>>> from >>>>>>>>>>>>>>>>>>>>> those 2 pieces? >>>>>>>>>>>>>>>>>>>> The aim is to provide a base class that can be >>>>>>>>>>>>>>>>>>>> used to >>>>>>>>>>>>>>>>>>>> create a >>>>>>>>>>>>>>>>>>>> MultiResolutionImage like: >>>>>>>>>>>>>>>>>>>> http://hg.openjdk.java.net/jdk9/client/jdk/diff/ae53ebce5fa3/src/share/classes/sun/awt/image/MultiResolutionBufferedImage.java >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> A developer should be able to implement a >>>>>>>>>>>>>>>>>>>> custom algorithm to >>>>>>>>>>>>>>>>>>>> query a resolution variant. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> It can be done by overriding the >>>>>>>>>>>>>>>>>>>> getResolutionVariant image: >>>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>>> Image mrImage = new >>>>>>>>>>>>>>>>>>>> MultiResolutionBufferedImage(){ >>>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(...) { >>>>>>>>>>>>>>>>>>>> // Custom logic here >>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>> }; >>>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> Or it can be done by using resolution variant >>>>>>>>>>>>>>>>>>>> choosers so a >>>>>>>>>>>>>>>>>>>> developer can implement custom resolution variant >>>>>>>>>>>>>>>>>>>> query: >>>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>>> public class MultiResolutionBufferedImage implements >>>>>>>>>>>>>>>>>>>> MultiResolutionImage{ >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> interface ResolutionVariantChooser{ >>>>>>>>>>>>>>>>>>>> Image getResolutionVariant(dpi, size,..., >>>>>>>>>>>>>>>>>>>> List >>>>>>>>>>>>>>>>>>>> resolutionVariants); >>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>> ResolutionVariantChooser TRANSFORM_BASED = null; >>>>>>>>>>>>>>>>>>>> ResolutionVariantChooser DPI_BASED = null; >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> ResolutionVariantChooser rvChooser; >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(dpi, >>>>>>>>>>>>>>>>>>>> size,...,) { >>>>>>>>>>>>>>>>>>>> return rvChooser.getResolutionVariant(dpi, >>>>>>>>>>>>>>>>>>>> size,..., >>>>>>>>>>>>>>>>>>>> getResolutionVariants()); >>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>> ----------------------- >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> On 2/13/2014 4:42 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>>>> On 2/12/14 5:59 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>>>> On 2/8/2014 4:19 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>>>>>> The primary thing that I was concerned about >>>>>>>>>>>>>>>>>>>>>>>>> was the >>>>>>>>>>>>>>>>>>>>>>>>> presence of >>>>>>>>>>>>>>>>>>>>>>>>> integers in the API when Windows uses >>>>>>>>>>>>>>>>>>>>>>>>> non-integer multiples >>>>>>>>>>>>>>>>>>>>>>>> It would make sense to pass real numbers >>>>>>>>>>>>>>>>>>>>>>>> to the >>>>>>>>>>>>>>>>>>>>>>>> getResolutionVariant() method if the difference >>>>>>>>>>>>>>>>>>>>>>>> between >>>>>>>>>>>>>>>>>>>>>>>> resolution >>>>>>>>>>>>>>>>>>>>>>>> variants sizes is 1. >>>>>>>>>>>>>>>>>>>>>>>> It seems that it is not a common case. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> I was thinking of other API that is related to >>>>>>>>>>>>>>>>>>>>>>> this, such as >>>>>>>>>>>>>>>>>>>>>>> the API >>>>>>>>>>>>>>>>>>>>>>> that queries the scaling factor from a >>>>>>>>>>>>>>>>>>>>>>> SurfaceManager. I >>>>>>>>>>>>>>>>>>>>>>> seem to >>>>>>>>>>>>>>>>>>>>>>> remember some integer return values in that, but >>>>>>>>>>>>>>>>>>>>>>> Windows might >>>>>>>>>>>>>>>>>>>>>>> have >>>>>>>>>>>>>>>>>>>>>>> the answer 1.4 or 1.8, depending on the screen >>>>>>>>>>>>>>>>>>>>>>> scaling factor >>>>>>>>>>>>>>>>>>>>>>> that was >>>>>>>>>>>>>>>>>>>>>>> determined from the UI. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> In terms of the getResolutionVariant() method >>>>>>>>>>>>>>>>>>>>>>> here, those >>>>>>>>>>>>>>>>>>>>>>> non-integer >>>>>>>>>>>>>>>>>>>>>>> screen scaling factors don't directly impact >>>>>>>>>>>>>>>>>>>>>>> this API. But, we >>>>>>>>>>>>>>>>>>>>>>> have >>>>>>>>>>>>>>>>>>>>>>> some issues with the use of integers there from >>>>>>>>>>>>>>>>>>>>>>> other sources: >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - That API assumes that the caller will >>>>>>>>>>>>>>>>>>>>>>> determine the pixel >>>>>>>>>>>>>>>>>>>>>>> size >>>>>>>>>>>>>>>>>>>>>>> needed, but the actual media choice is >>>>>>>>>>>>>>>>>>>>>>> determined with >>>>>>>>>>>>>>>>>>>>>>> different >>>>>>>>>>>>>>>>>>>>>>> techniques on Mac and Windows so this means that >>>>>>>>>>>>>>>>>>>>>>> the caller >>>>>>>>>>>>>>>>>>>>>>> will >>>>>>>>>>>>>>>>>>>>>>> have >>>>>>>>>>>>>>>>>>>>>>> to worry about platform conventions. Is that the >>>>>>>>>>>>>>>>>>>>>>> right >>>>>>>>>>>>>>>>>>>>>>> tradeoff? >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - The technique recommended for Mac involves >>>>>>>>>>>>>>>>>>>>>>> computing the >>>>>>>>>>>>>>>>>>>>>>> precise >>>>>>>>>>>>>>>>>>>>>>> size desired using the current transform, which >>>>>>>>>>>>>>>>>>>>>>> may be a >>>>>>>>>>>>>>>>>>>>>>> floating >>>>>>>>>>>>>>>>>>>>>>> point value, so the integer values used in this >>>>>>>>>>>>>>>>>>>>>>> API are already >>>>>>>>>>>>>>>>>>>>>>> approximations and there is no documentation on >>>>>>>>>>>>>>>>>>>>>>> how to >>>>>>>>>>>>>>>>>>>>>>> generate the >>>>>>>>>>>>>>>>>>>>>>> proper integer. In particular, the current code >>>>>>>>>>>>>>>>>>>>>>> in SG2D >>>>>>>>>>>>>>>>>>>>>>> naively >>>>>>>>>>>>>>>>>>>>>>> uses >>>>>>>>>>>>>>>>>>>>>>> a cast to integer to determine the values to >>>>>>>>>>>>>>>>>>>>>>> supply which >>>>>>>>>>>>>>>>>>>>>>> means a >>>>>>>>>>>>>>>>>>>>>>> transformed size of W+0.5 will be truncated to W >>>>>>>>>>>>>>>>>>>>>>> and the lower >>>>>>>>>>>>>>>>>>>>>>> resolution image will be used. Does that conform >>>>>>>>>>>>>>>>>>>>>>> to Mac >>>>>>>>>>>>>>>>>>>>>>> guidelines? Do >>>>>>>>>>>>>>>>>>>>>>> they require the truncated size to reach W+1 >>>>>>>>>>>>>>>>>>>>>>> before the next >>>>>>>>>>>>>>>>>>>>>>> size is >>>>>>>>>>>>>>>>>>>>>>> used? Passing in float or double values would >>>>>>>>>>>>>>>>>>>>>>> sidestep all of >>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>> since then the comparisons would be done with >>>>>>>>>>>>>>>>>>>>>>> full precision, >>>>>>>>>>>>>>>>>>>>>>> but as >>>>>>>>>>>>>>>>>>>>>>> long as we can determine a "best practices >>>>>>>>>>>>>>>>>>>>>>> compatible with all >>>>>>>>>>>>>>>>>>>>>>> platforms" rule on how to round to integers, >>>>>>>>>>>>>>>>>>>>>>> then integers >>>>>>>>>>>>>>>>>>>>>>> are OK >>>>>>>>>>>>>>>>>>>>>>> there. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - The Windows document you cite below suggests >>>>>>>>>>>>>>>>>>>>>>> that the >>>>>>>>>>>>>>>>>>>>>>> determination >>>>>>>>>>>>>>>>>>>>>>> should be made by looking at the Screen DPI and >>>>>>>>>>>>>>>>>>>>>>> choosing the >>>>>>>>>>>>>>>>>>>>>>> next >>>>>>>>>>>>>>>>>>>>>>> higher media variant based on that screen DPI. >>>>>>>>>>>>>>>>>>>>>>> They do not >>>>>>>>>>>>>>>>>>>>>>> specify >>>>>>>>>>>>>>>>>>>>>>> choosing media based on the current transform as >>>>>>>>>>>>>>>>>>>>>>> is done for >>>>>>>>>>>>>>>>>>>>>>> Mac. If >>>>>>>>>>>>>>>>>>>>>>> we stick with supplying values that are used to >>>>>>>>>>>>>>>>>>>>>>> determine which >>>>>>>>>>>>>>>>>>>>>>> media >>>>>>>>>>>>>>>>>>>>>>> to use, then on Windows we should not take the >>>>>>>>>>>>>>>>>>>>>>> transform into >>>>>>>>>>>>>>>>>>>>>>> account, >>>>>>>>>>>>>>>>>>>>>>> but instead query the SurfaceManager for the >>>>>>>>>>>>>>>>>>>>>>> scale factor and >>>>>>>>>>>>>>>>>>>>>>> only >>>>>>>>>>>>>>>>>>>>>>> transform by those values (even if the current >>>>>>>>>>>>>>>>>>>>>>> transform was >>>>>>>>>>>>>>>>>>>>>>> manually >>>>>>>>>>>>>>>>>>>>>>> overridden to identity). >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> There are pros and cons to both approaches. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> Mac ensures that you are always using the best >>>>>>>>>>>>>>>>>>>>>>> media for any >>>>>>>>>>>>>>>>>>>>>>> given >>>>>>>>>>>>>>>>>>>>>>> render operation. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> But, Windows ensure more consistency in the face >>>>>>>>>>>>>>>>>>>>>>> of other >>>>>>>>>>>>>>>>>>>>>>> scaling. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> The thing to consider is that if you have a >>>>>>>>>>>>>>>>>>>>>>> 500x500 image >>>>>>>>>>>>>>>>>>>>>>> with a >>>>>>>>>>>>>>>>>>>>>>> 1000x1000 variant and you rendering it at >>>>>>>>>>>>>>>>>>>>>>> 500x500 and then >>>>>>>>>>>>>>>>>>>>>>> 501x501, >>>>>>>>>>>>>>>>>>>>>>> that first jump will be fairly jarring as the >>>>>>>>>>>>>>>>>>>>>>> scaled version >>>>>>>>>>>>>>>>>>>>>>> of the >>>>>>>>>>>>>>>>>>>>>>> 1000x1000 will not look precisely like the >>>>>>>>>>>>>>>>>>>>>>> original 500x500 >>>>>>>>>>>>>>>>>>>>>>> did. >>>>>>>>>>>>>>>>>>>>>>> With >>>>>>>>>>>>>>>>>>>>>>> @2x images only, this effect is minimized so the >>>>>>>>>>>>>>>>>>>>>>> advantage of >>>>>>>>>>>>>>>>>>>>>>> always >>>>>>>>>>>>>>>>>>>>>>> using "the best media for a given render >>>>>>>>>>>>>>>>>>>>>>> operation" may >>>>>>>>>>>>>>>>>>>>>>> outweigh the >>>>>>>>>>>>>>>>>>>>>>> inconsistency issue. But, on Windows where the >>>>>>>>>>>>>>>>>>>>>>> media are >>>>>>>>>>>>>>>>>>>>>>> 1.4x or >>>>>>>>>>>>>>>>>>>>>>> 1.8x >>>>>>>>>>>>>>>>>>>>>>> in size, a downscaled image will start to show more >>>>>>>>>>>>>>>>>>>>>>> interpolation >>>>>>>>>>>>>>>>>>>>>>> noise and so the balance of the two choices may >>>>>>>>>>>>>>>>>>>>>>> shift more >>>>>>>>>>>>>>>>>>>>>>> towards not >>>>>>>>>>>>>>>>>>>>>>> wanting a jarring shift. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> We might want one or more of the following: >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - Developer chooses policy (TX_AWARE, DPI_AWARE, >>>>>>>>>>>>>>>>>>>>>>> ALWAYS_LARGEST, >>>>>>>>>>>>>>>>>>>>>>> NONE, >>>>>>>>>>>>>>>>>>>>>>> PLATFORM) where the last policy would use >>>>>>>>>>>>>>>>>>>>>>> TX_AWARE on Mac and >>>>>>>>>>>>>>>>>>>>>>> DPI_AWARE on Windows >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - We create our own policy and always use it >>>>>>>>>>>>>>>>>>>>>>> (TX_AWARE? or >>>>>>>>>>>>>>>>>>>>>>> DPI_AWARE?) >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - We create our own policy that dynamically >>>>>>>>>>>>>>>>>>>>>>> chooses one of the >>>>>>>>>>>>>>>>>>>>>>> above >>>>>>>>>>>>>>>>>>>>>>> strategies depending on platform or available >>>>>>>>>>>>>>>>>>>>>>> media or ??? >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> - We could create an optional interface for them >>>>>>>>>>>>>>>>>>>>>>> to install >>>>>>>>>>>>>>>>>>>>>>> their >>>>>>>>>>>>>>>>>>>>>>> own >>>>>>>>>>>>>>>>>>>>>>> algorithm as well. I think it would work best >>>>>>>>>>>>>>>>>>>>>>> as a delegate >>>>>>>>>>>>>>>>>>>>>>> interface >>>>>>>>>>>>>>>>>>>>>>> that one installs into Image so that it can be >>>>>>>>>>>>>>>>>>>>>>> used with any >>>>>>>>>>>>>>>>>>>>>>> image >>>>>>>>>>>>>>>>>>>>>>> without having to subclass (it wouldn't really >>>>>>>>>>>>>>>>>>>>>>> have much to do >>>>>>>>>>>>>>>>>>>>>>> for >>>>>>>>>>>>>>>>>>>>>>> BufferedImages or VolatileImages, though): >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> class Image { >>>>>>>>>>>>>>>>>>>>>>> void >>>>>>>>>>>>>>>>>>>>>>> setResolutionHelper(ImageResolutionHelper foo); >>>>>>>>>>>>>>>>>>>>>>> List getResolutionVariants(); >>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> or: >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> class Graphics { >>>>>>>>>>>>>>>>>>>>>>> void >>>>>>>>>>>>>>>>>>>>>>> setResolutionHelper(ImageResolutionHelper foo); >>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> or - anywhere else it could be installed more >>>>>>>>>>>>>>>>>>>>>>> centrally (per >>>>>>>>>>>>>>>>>>>>>>> App >>>>>>>>>>>>>>>>>>>>>>> context)? >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> and the interface would be something like one of >>>>>>>>>>>>>>>>>>>>>>> these >>>>>>>>>>>>>>>>>>>>>>> variants: >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> interface ImageResolutionHelper { >>>>>>>>>>>>>>>>>>>>>>> // This version would prevent substituting a >>>>>>>>>>>>>>>>>>>>>>> random image: >>>>>>>>>>>>>>>>>>>>>>> // They have to return an index into the >>>>>>>>>>>>>>>>>>>>>>> List for >>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>> image... >>>>>>>>>>>>>>>>>>>>>>> public int chooseVariant(Image img, double >>>>>>>>>>>>>>>>>>>>>>> dpi, number w, >>>>>>>>>>>>>>>>>>>>>>> number h); >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> or: >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> // This version would allow substituting an >>>>>>>>>>>>>>>>>>>>>>> arbitrary >>>>>>>>>>>>>>>>>>>>>>> image: >>>>>>>>>>>>>>>>>>>>>>> public Image getVariant(Image img, double >>>>>>>>>>>>>>>>>>>>>>> dpi, number w, >>>>>>>>>>>>>>>>>>>>>>> number >>>>>>>>>>>>>>>>>>>>>>> h); >>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> Since they would be in full control of the >>>>>>>>>>>>>>>>>>>>>>> policy, though, we >>>>>>>>>>>>>>>>>>>>>>> would >>>>>>>>>>>>>>>>>>>>>>> unfortunately always have to call this, there >>>>>>>>>>>>>>>>>>>>>>> would be no more >>>>>>>>>>>>>>>>>>>>>>> testing >>>>>>>>>>>>>>>>>>>>>>> in SG2D to see "if" we need to deal with DPI, >>>>>>>>>>>>>>>>>>>>>>> though perhaps we >>>>>>>>>>>>>>>>>>>>>>> could >>>>>>>>>>>>>>>>>>>>>>> document some internal conditions in which we do >>>>>>>>>>>>>>>>>>>>>>> not call it >>>>>>>>>>>>>>>>>>>>>>> for >>>>>>>>>>>>>>>>>>>>>>> common cases (but that would have to be well >>>>>>>>>>>>>>>>>>>>>>> agreed not to >>>>>>>>>>>>>>>>>>>>>>> get in >>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>> way of reasonable uses of the API and well >>>>>>>>>>>>>>>>>>>>>>> documented)? >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> Note that we would have to do a security audit >>>>>>>>>>>>>>>>>>>>>>> to make sure >>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>> random image substitution couldn't allow any >>>>>>>>>>>>>>>>>>>>>>> sort of "screen >>>>>>>>>>>>>>>>>>>>>>> phishing" >>>>>>>>>>>>>>>>>>>>>>> exploit. >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> and also what policy they use for choosing >>>>>>>>>>>>>>>>>>>>>>>>> scaled images. >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> I don't see a mention of taking the current >>>>>>>>>>>>>>>>>>>>>>>>> transform into >>>>>>>>>>>>>>>>>>>>>>>>> account, >>>>>>>>>>>>>>>>>>>>>>>>> just physical issues like screen DPI and form >>>>>>>>>>>>>>>>>>>>>>>>> factor. They >>>>>>>>>>>>>>>>>>>>>>>>> talk >>>>>>>>>>>>>>>>>>>>>>>>> about >>>>>>>>>>>>>>>>>>>>>>>>> resolution plateaus and in their >>>>>>>>>>>>>>>>>>>>>>>>> recommendations section they >>>>>>>>>>>>>>>>>>>>>>>>> tell the >>>>>>>>>>>>>>>>>>>>>>>>> developer to use a particular property that >>>>>>>>>>>>>>>>>>>>>>>>> tells them the >>>>>>>>>>>>>>>>>>>>>>>>> screen >>>>>>>>>>>>>>>>>>>>>>>>> resolution to figure out which image to load >>>>>>>>>>>>>>>>>>>>>>>>> if they are >>>>>>>>>>>>>>>>>>>>>>>>> loading >>>>>>>>>>>>>>>>>>>>>>>>> manually. There is no discussion about >>>>>>>>>>>>>>>>>>>>>>>>> dynamically loading >>>>>>>>>>>>>>>>>>>>>>>>> multiple >>>>>>>>>>>>>>>>>>>>>>>>> versions of the image based on a dynamic >>>>>>>>>>>>>>>>>>>>>>>>> program-applied >>>>>>>>>>>>>>>>>>>>>>>>> transform >>>>>>>>>>>>>>>>>>>>>>>>> factor as is done on MacOS. >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> Also, they tell developers to draw images to a >>>>>>>>>>>>>>>>>>>>>>>>> specific size >>>>>>>>>>>>>>>>>>>>>>>>> rather >>>>>>>>>>>>>>>>>>>>>>>>> than using auto-sizing. That begs the question >>>>>>>>>>>>>>>>>>>>>>>>> as to how >>>>>>>>>>>>>>>>>>>>>>>>> they >>>>>>>>>>>>>>>>>>>>>>>>> interpret a call to draw an image just using a >>>>>>>>>>>>>>>>>>>>>>>>> location in >>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>> presence of various DPI factors. >>>>>>>>>>>>>>>>>>>>>>>> There is an interesting doc that >>>>>>>>>>>>>>>>>>>>>>>> describes how to write >>>>>>>>>>>>>>>>>>>>>>>> DPI-aware >>>>>>>>>>>>>>>>>>>>>>>> Win32 applications: >>>>>>>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/dd464646%28v=vs.85%29.aspx >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> It is suggested to handle WM_DPICHANGED >>>>>>>>>>>>>>>>>>>>>>>> message, load >>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>> graphic >>>>>>>>>>>>>>>>>>>>>>>> that has slightly greater resolution to the >>>>>>>>>>>>>>>>>>>>>>>> current DPI and >>>>>>>>>>>>>>>>>>>>>>>> use >>>>>>>>>>>>>>>>>>>>>>>> StretchBlt >>>>>>>>>>>>>>>>>>>>>>>> to scale down the image. >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>> On 2/7/14 3:00 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>>>>>> On 1/22/2014 6:40 AM, Jim Graham wrote: >>>>>>>>>>>>>>>>>>>>>>>>>>> Hi Alexander, >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> Before we get too far down the road on this >>>>>>>>>>>>>>>>>>>>>>>>>>> API, I think we >>>>>>>>>>>>>>>>>>>>>>>>>>> understand >>>>>>>>>>>>>>>>>>>>>>>>>>> the way in which MacOS processes >>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution images >>>>>>>>>>>>>>>>>>>>>>>>>>> for >>>>>>>>>>>>>>>>>>>>>>>>>>> HiDPI >>>>>>>>>>>>>>>>>>>>>>>>>>> screens, but have we investigated the >>>>>>>>>>>>>>>>>>>>>>>>>>> processes that >>>>>>>>>>>>>>>>>>>>>>>>>>> Windows >>>>>>>>>>>>>>>>>>>>>>>>>>> uses >>>>>>>>>>>>>>>>>>>>>>>>>>> under Windows 8? My impression is that >>>>>>>>>>>>>>>>>>>>>>>>>>> Windows 8 has >>>>>>>>>>>>>>>>>>>>>>>>>>> included a >>>>>>>>>>>>>>>>>>>>>>>>>>> number of new techniques for dealing with >>>>>>>>>>>>>>>>>>>>>>>>>>> the high >>>>>>>>>>>>>>>>>>>>>>>>>>> resolution >>>>>>>>>>>>>>>>>>>>>>>>>>> displays >>>>>>>>>>>>>>>>>>>>>>>>>>> that it will run on in the Windows tablet >>>>>>>>>>>>>>>>>>>>>>>>>>> and mobile >>>>>>>>>>>>>>>>>>>>>>>>>>> industries >>>>>>>>>>>>>>>>>>>>>>>>>>> and >>>>>>>>>>>>>>>>>>>>>>>>>>> that these will also come into play as 4K >>>>>>>>>>>>>>>>>>>>>>>>>>> displays (already >>>>>>>>>>>>>>>>>>>>>>>>>>> available) >>>>>>>>>>>>>>>>>>>>>>>>>>> become more common on the desktop. We should >>>>>>>>>>>>>>>>>>>>>>>>>>> make sure >>>>>>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>>>>>> what we >>>>>>>>>>>>>>>>>>>>>>>>>>> come up with here can provide native >>>>>>>>>>>>>>>>>>>>>>>>>>> compatibility with >>>>>>>>>>>>>>>>>>>>>>>>>>> either >>>>>>>>>>>>>>>>>>>>>>>>>>> platform's policies and standard practices. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> If you've investigated the MS policies I'd >>>>>>>>>>>>>>>>>>>>>>>>>>> like to see a >>>>>>>>>>>>>>>>>>>>>>>>>>> summary so >>>>>>>>>>>>>>>>>>>>>>>>>>> that we can consider them as we review this >>>>>>>>>>>>>>>>>>>>>>>>>>> API... >>>>>>>>>>>>>>>>>>>>>>>>>> There is the Windows Guidelines for >>>>>>>>>>>>>>>>>>>>>>>>>> scaling to pixel >>>>>>>>>>>>>>>>>>>>>>>>>> density: >>>>>>>>>>>>>>>>>>>>>>>>>> http://msdn.microsoft.com/en-us/library/windows/apps/hh465362.aspx >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> which says that Windows has automatic >>>>>>>>>>>>>>>>>>>>>>>>>> resource loading >>>>>>>>>>>>>>>>>>>>>>>>>> that >>>>>>>>>>>>>>>>>>>>>>>>>> supports >>>>>>>>>>>>>>>>>>>>>>>>>> three version of images scaling (100%, 140%, >>>>>>>>>>>>>>>>>>>>>>>>>> and 180%) >>>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>>> Without scaling, as the pixel density of a >>>>>>>>>>>>>>>>>>>>>>>>>> display device >>>>>>>>>>>>>>>>>>>>>>>>>> increases, the >>>>>>>>>>>>>>>>>>>>>>>>>> physical sizes of objects on screen get smaller. >>>>>>>>>>>>>>>>>>>>>>>>>> When UI would otherwise be too small to touch >>>>>>>>>>>>>>>>>>>>>>>>>> and when text >>>>>>>>>>>>>>>>>>>>>>>>>> gets >>>>>>>>>>>>>>>>>>>>>>>>>> too >>>>>>>>>>>>>>>>>>>>>>>>>> small to read, >>>>>>>>>>>>>>>>>>>>>>>>>> Windows scales the system and app UI to one >>>>>>>>>>>>>>>>>>>>>>>>>> of the following >>>>>>>>>>>>>>>>>>>>>>>>>> scaling >>>>>>>>>>>>>>>>>>>>>>>>>> plateaus: >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> 1.0 (100%, no scaling is applied) >>>>>>>>>>>>>>>>>>>>>>>>>> 1.4 (140% scaling) >>>>>>>>>>>>>>>>>>>>>>>>>> 1.8 (180% scaling) >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> Windows determines which scaling plateau to >>>>>>>>>>>>>>>>>>>>>>>>>> use based on the >>>>>>>>>>>>>>>>>>>>>>>>>> physical >>>>>>>>>>>>>>>>>>>>>>>>>> screen size, the screen resolution, the DPI >>>>>>>>>>>>>>>>>>>>>>>>>> of the >>>>>>>>>>>>>>>>>>>>>>>>>> screen, and >>>>>>>>>>>>>>>>>>>>>>>>>> form >>>>>>>>>>>>>>>>>>>>>>>>>> factor. >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> Use resource loading for bitmap images in the >>>>>>>>>>>>>>>>>>>>>>>>>> app package >>>>>>>>>>>>>>>>>>>>>>>>>> For >>>>>>>>>>>>>>>>>>>>>>>>>> bitmap >>>>>>>>>>>>>>>>>>>>>>>>>> images stored >>>>>>>>>>>>>>>>>>>>>>>>>> in the app package, provide a separate image >>>>>>>>>>>>>>>>>>>>>>>>>> for each >>>>>>>>>>>>>>>>>>>>>>>>>> scaling >>>>>>>>>>>>>>>>>>>>>>>>>> factor(100%, 140%, and 180%), >>>>>>>>>>>>>>>>>>>>>>>>>> and name your image files using the "scale" >>>>>>>>>>>>>>>>>>>>>>>>>> naming >>>>>>>>>>>>>>>>>>>>>>>>>> convention >>>>>>>>>>>>>>>>>>>>>>>>>> described >>>>>>>>>>>>>>>>>>>>>>>>>> below. >>>>>>>>>>>>>>>>>>>>>>>>>> Windows loads the right image for the current >>>>>>>>>>>>>>>>>>>>>>>>>> scale >>>>>>>>>>>>>>>>>>>>>>>>>> automatically. >>>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> The image name convention for the various >>>>>>>>>>>>>>>>>>>>>>>>>> scales is: >>>>>>>>>>>>>>>>>>>>>>>>>> images/logo.scale-100.png >>>>>>>>>>>>>>>>>>>>>>>>>> images/logo.scale-140.png >>>>>>>>>>>>>>>>>>>>>>>>>> images/logo.scale-180.png >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> The 'ms-appx:///images/logo.png' uri is >>>>>>>>>>>>>>>>>>>>>>>>>> used to load the >>>>>>>>>>>>>>>>>>>>>>>>>> image >>>>>>>>>>>>>>>>>>>>>>>>>> in an >>>>>>>>>>>>>>>>>>>>>>>>>> application. >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> If we want to support this in the same way >>>>>>>>>>>>>>>>>>>>>>>>>> as it is done >>>>>>>>>>>>>>>>>>>>>>>>>> for Mac >>>>>>>>>>>>>>>>>>>>>>>>>> OS X >>>>>>>>>>>>>>>>>>>>>>>>>> the WToolkit should return MultiResolution >>>>>>>>>>>>>>>>>>>>>>>>>> image in >>>>>>>>>>>>>>>>>>>>>>>>>> case if >>>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>>> loaded image has .scale-* qualifiers. >>>>>>>>>>>>>>>>>>>>>>>>>> The Graphics class can request an image >>>>>>>>>>>>>>>>>>>>>>>>>> with necessary >>>>>>>>>>>>>>>>>>>>>>>>>> resolution >>>>>>>>>>>>>>>>>>>>>>>>>> from the MultiResolution image. >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> It seems that nothing should be changed in >>>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>>> MultiResolution >>>>>>>>>>>>>>>>>>>>>>>>>> interface in this case. >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> ...jim >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> On 1/14/14 2:54 AM, Alexander Scherbatiy wrote: >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> Hello, >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> Could you review the fix: >>>>>>>>>>>>>>>>>>>>>>>>>>>> bug: >>>>>>>>>>>>>>>>>>>>>>>>>>>> https://bugs.openjdk.java.net/browse/JDK-8029339 >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> webrev: >>>>>>>>>>>>>>>>>>>>>>>>>>>> http://cr.openjdk.java.net/~alexsch/8029339/webrev.00 >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> This is a proposal to introduce an API >>>>>>>>>>>>>>>>>>>>>>>>>>>> that allows to >>>>>>>>>>>>>>>>>>>>>>>>>>>> create a >>>>>>>>>>>>>>>>>>>>>>>>>>>> custom >>>>>>>>>>>>>>>>>>>>>>>>>>>> multi resolution image. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> I. It seems reasonable that the API should >>>>>>>>>>>>>>>>>>>>>>>>>>>> provide two >>>>>>>>>>>>>>>>>>>>>>>>>>>> basic >>>>>>>>>>>>>>>>>>>>>>>>>>>> operations: >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Get the resolution variant based on >>>>>>>>>>>>>>>>>>>>>>>>>>>> the requested >>>>>>>>>>>>>>>>>>>>>>>>>>>> image >>>>>>>>>>>>>>>>>>>>>>>>>>>> width and >>>>>>>>>>>>>>>>>>>>>>>>>>>> height: >>>>>>>>>>>>>>>>>>>>>>>>>>>> - Image getResolutionVariant(int >>>>>>>>>>>>>>>>>>>>>>>>>>>> width, int height) >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> Usually the system provides the scale >>>>>>>>>>>>>>>>>>>>>>>>>>>> factor which >>>>>>>>>>>>>>>>>>>>>>>>>>>> represents >>>>>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>>>>> number of pixels corresponding to each >>>>>>>>>>>>>>>>>>>>>>>>>>>> linear unit on the >>>>>>>>>>>>>>>>>>>>>>>>>>>> display. >>>>>>>>>>>>>>>>>>>>>>>>>>>> However, it has sense to combine the >>>>>>>>>>>>>>>>>>>>>>>>>>>> scale factor and >>>>>>>>>>>>>>>>>>>>>>>>>>>> the >>>>>>>>>>>>>>>>>>>>>>>>>>>> current >>>>>>>>>>>>>>>>>>>>>>>>>>>> transformations to get the actual image >>>>>>>>>>>>>>>>>>>>>>>>>>>> size to be >>>>>>>>>>>>>>>>>>>>>>>>>>>> displayed. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Get all provided resolution variants: >>>>>>>>>>>>>>>>>>>>>>>>>>>> - List getResolutionVariants() >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> There are several uses cases: >>>>>>>>>>>>>>>>>>>>>>>>>>>> - Create a new multi-resolution image >>>>>>>>>>>>>>>>>>>>>>>>>>>> based on the >>>>>>>>>>>>>>>>>>>>>>>>>>>> given >>>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution image. >>>>>>>>>>>>>>>>>>>>>>>>>>>> - Pass to the native system the >>>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution >>>>>>>>>>>>>>>>>>>>>>>>>>>> image. For >>>>>>>>>>>>>>>>>>>>>>>>>>>> example, >>>>>>>>>>>>>>>>>>>>>>>>>>>> a use can set to the system the custom >>>>>>>>>>>>>>>>>>>>>>>>>>>> multi-resolution >>>>>>>>>>>>>>>>>>>>>>>>>>>> cursor. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> II. There are some possible ways where the >>>>>>>>>>>>>>>>>>>>>>>>>>>> new API can be >>>>>>>>>>>>>>>>>>>>>>>>>>>> added >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. java.awt.Image. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> The 2 new methods can be added to the >>>>>>>>>>>>>>>>>>>>>>>>>>>> Image class. A >>>>>>>>>>>>>>>>>>>>>>>>>>>> user >>>>>>>>>>>>>>>>>>>>>>>>>>>> can >>>>>>>>>>>>>>>>>>>>>>>>>>>> override >>>>>>>>>>>>>>>>>>>>>>>>>>>> the getResolutionVariant() and >>>>>>>>>>>>>>>>>>>>>>>>>>>> getResolutionVariants() >>>>>>>>>>>>>>>>>>>>>>>>>>>> methods to >>>>>>>>>>>>>>>>>>>>>>>>>>>> provide the resolution variants >>>>>>>>>>>>>>>>>>>>>>>>>>>> or there can be default implementations >>>>>>>>>>>>>>>>>>>>>>>>>>>> of these >>>>>>>>>>>>>>>>>>>>>>>>>>>> methods >>>>>>>>>>>>>>>>>>>>>>>>>>>> if a >>>>>>>>>>>>>>>>>>>>>>>>>>>> user >>>>>>>>>>>>>>>>>>>>>>>>>>>> puts resolution variants >>>>>>>>>>>>>>>>>>>>>>>>>>>> to the list in the sorted order. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> To check that the image has resolution >>>>>>>>>>>>>>>>>>>>>>>>>>>> variants the >>>>>>>>>>>>>>>>>>>>>>>>>>>> following >>>>>>>>>>>>>>>>>>>>>>>>>>>> statement can be used: >>>>>>>>>>>>>>>>>>>>>>>>>>>> image.getResolutionVariants().size() >>>>>>>>>>>>>>>>>>>>>>>>>>>> != 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> The disadvantage is that there is an >>>>>>>>>>>>>>>>>>>>>>>>>>>> overhead that the >>>>>>>>>>>>>>>>>>>>>>>>>>>> Image >>>>>>>>>>>>>>>>>>>>>>>>>>>> class >>>>>>>>>>>>>>>>>>>>>>>>>>>> should contain the List object and not all >>>>>>>>>>>>>>>>>>>>>>>>>>>> images can have resolution variants. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Introduce new MultiResolutionImage >>>>>>>>>>>>>>>>>>>>>>>>>>>> interface. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> A user should extend Image class and >>>>>>>>>>>>>>>>>>>>>>>>>>>> implement the >>>>>>>>>>>>>>>>>>>>>>>>>>>> MultiResolutionImage interface. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> For example: >>>>>>>>>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>>> public class >>>>>>>>>>>>>>>>>>>>>>>>>>>> CustomMultiResolutionImage extends >>>>>>>>>>>>>>>>>>>>>>>>>>>> BufferedImage >>>>>>>>>>>>>>>>>>>>>>>>>>>> implements MultiResolutionImage { >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> Image highResolutionImage; >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> public >>>>>>>>>>>>>>>>>>>>>>>>>>>> CustomMultiResolutionImage(BufferedImage >>>>>>>>>>>>>>>>>>>>>>>>>>>> baseImage, >>>>>>>>>>>>>>>>>>>>>>>>>>>> BufferedImage highResolutionImage) { >>>>>>>>>>>>>>>>>>>>>>>>>>>> super(baseImage.getWidth(), >>>>>>>>>>>>>>>>>>>>>>>>>>>> baseImage.getHeight(), >>>>>>>>>>>>>>>>>>>>>>>>>>>> baseImage.getType()); >>>>>>>>>>>>>>>>>>>>>>>>>>>> this.highResolutionImage = >>>>>>>>>>>>>>>>>>>>>>>>>>>> highResolutionImage; >>>>>>>>>>>>>>>>>>>>>>>>>>>> Graphics g = getGraphics(); >>>>>>>>>>>>>>>>>>>>>>>>>>>> g.drawImage(baseImage, 0, 0, null); >>>>>>>>>>>>>>>>>>>>>>>>>>>> g.dispose(); >>>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>>>>>>>>>>> public Image getResolutionVariant(int >>>>>>>>>>>>>>>>>>>>>>>>>>>> width, int >>>>>>>>>>>>>>>>>>>>>>>>>>>> height) { >>>>>>>>>>>>>>>>>>>>>>>>>>>> return ((width <= getWidth() && height <= >>>>>>>>>>>>>>>>>>>>>>>>>>>> getHeight())) >>>>>>>>>>>>>>>>>>>>>>>>>>>> ? this : highResolutionImage; >>>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> @Override >>>>>>>>>>>>>>>>>>>>>>>>>>>> public List getResolutionVariants() { >>>>>>>>>>>>>>>>>>>>>>>>>>>> return Arrays.asList(this, >>>>>>>>>>>>>>>>>>>>>>>>>>>> highResolutionImage); >>>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>>> } >>>>>>>>>>>>>>>>>>>>>>>>>>>> --------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> The current fix adds the >>>>>>>>>>>>>>>>>>>>>>>>>>>> MultiResolutionImage interface >>>>>>>>>>>>>>>>>>>>>>>>>>>> and >>>>>>>>>>>>>>>>>>>>>>>>>>>> public >>>>>>>>>>>>>>>>>>>>>>>>>>>> resolution variant rendering hints. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>> Thanks, >>>>>>>>>>>>>>>>>>>>>>>>>>>> Alexandr. >>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > From swingler at apple.com Wed Jul 30 15:43:40 2014 From: swingler at apple.com (Mike Swingler) Date: Wed, 30 Jul 2014 08:43:40 -0700 Subject: Horizontal scrolling not possible with touchpad with Metal and Nimbus L&F when both scrollbars are visible In-Reply-To: References: <53D2684D.6090207@oracle.com> Message-ID: FYI, the code to do horizontal scroll in Aqua is in . The whole point of this class is to do the "grody hack". ;-) Cheers, Mike Swingler Apple Inc. On Jul 26, 2014, at 4:54 AM, Robert Kr?ger wrote: > OK, I have done that. Btw, are there any concrete plans to migrate > that to Jira as well? > > Thanks, > > Robert > > On Fri, Jul 25, 2014 at 4:23 PM, Alexander Scherbatiy > wrote: >> >> Please, file the bug report in http://bugreport.java.com/bugreport >> >> Thanks, >> Alexandr. >> >> >> On 7/25/2014 10:34 AM, Robert Kr?ger wrote: >>> >>> Hi, >>> >>> horizontal scrolling in a JScrollPane does not work with a touchpad >>> with Metal and Nimbus Look & Feel when both scrollbars are visible. >>> It does work with Aqua. >>> >>> This little example demonstrates the problem: >>> >>> import javax.swing.*; >>> >>> public class TestTreeScrolling { >>> public static void main(String[] args) throws Exception { >>> for (UIManager.LookAndFeelInfo info : >>> UIManager.getInstalledLookAndFeels()) { >>> if (info.getName().startsWith("Nimbus")) { >>> UIManager.setLookAndFeel(info.getClassName()); >>> break; >>> } >>> } >>> final JFrame frame = new >>> JFrame(TestTreeScrolling.class.getSimpleName()); >>> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); >>> >>> final JScrollPane scrollPane = new JScrollPane(new JTree()); >>> >>> scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); >>> >>> scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); >>> frame.getContentPane().add(scrollPane); >>> frame.pack(); >>> frame.setVisible(true); >>> } >>> } >>> >>> Expand the tree a bit and resize the window so that both scrollbars >>> are visible. Making a horizontal scroll gesture on the touchpad >>> results in vertical scrolling. >>> >>> Tested systematically with JDKs 6_51 and 8_11 but observed with all >>> production releases of 8 before as well. >>> >>> Is this a known bug? >>> >>> Is there a known workaround (hacking the Look & Feel is also an option >>> because we override it in our application anyway)? There must be as >>> IntelliJ Idea does not have this problem and they are not using Aqua >>> but I have failed to find it in their code. >>> >>> Does it make sense to file a bug report and if so where? >>> >>> Best, >>> >>> Robert >> >> > > > > -- > Robert Kr?ger > Managing Partner > Lesspain GmbH & Co. KG > > www.lesspain-software.com From gregg at wonderly.org Thu Jul 31 03:32:31 2014 From: gregg at wonderly.org (Gregg Wonderly) Date: Wed, 30 Jul 2014 22:32:31 -0500 Subject: Horizontal scrolling not possible with touchpad with Metal and Nimbus L&F when both scrollbars are visible In-Reply-To: References: <53D2684D.6090207@oracle.com> Message-ID: <5CD988FB-F203-441A-B19F-64646B3D50A8@wonderly.org> It would be prudent to have a try {} finally {} around the disable/enable so that runtime exceptions don?t leave the UI in an odd state. Gregg Wonderly On Jul 30, 2014, at 10:43 AM, Mike Swingler wrote: > FYI, the code to do horizontal scroll in Aqua is in . The whole point of this class is to do the "grody hack". ;-) > > Cheers, > Mike Swingler > Apple Inc. > > On Jul 26, 2014, at 4:54 AM, Robert Kr?ger wrote: > >> OK, I have done that. Btw, are there any concrete plans to migrate >> that to Jira as well? >> >> Thanks, >> >> Robert >> >> On Fri, Jul 25, 2014 at 4:23 PM, Alexander Scherbatiy >> wrote: >>> >>> Please, file the bug report in http://bugreport.java.com/bugreport >>> >>> Thanks, >>> Alexandr. >>> >>> >>> On 7/25/2014 10:34 AM, Robert Kr?ger wrote: >>>> >>>> Hi, >>>> >>>> horizontal scrolling in a JScrollPane does not work with a touchpad >>>> with Metal and Nimbus Look & Feel when both scrollbars are visible. >>>> It does work with Aqua. >>>> >>>> This little example demonstrates the problem: >>>> >>>> import javax.swing.*; >>>> >>>> public class TestTreeScrolling { >>>> public static void main(String[] args) throws Exception { >>>> for (UIManager.LookAndFeelInfo info : >>>> UIManager.getInstalledLookAndFeels()) { >>>> if (info.getName().startsWith("Nimbus")) { >>>> UIManager.setLookAndFeel(info.getClassName()); >>>> break; >>>> } >>>> } >>>> final JFrame frame = new >>>> JFrame(TestTreeScrolling.class.getSimpleName()); >>>> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); >>>> >>>> final JScrollPane scrollPane = new JScrollPane(new JTree()); >>>> >>>> scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); >>>> >>>> scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); >>>> frame.getContentPane().add(scrollPane); >>>> frame.pack(); >>>> frame.setVisible(true); >>>> } >>>> } >>>> >>>> Expand the tree a bit and resize the window so that both scrollbars >>>> are visible. Making a horizontal scroll gesture on the touchpad >>>> results in vertical scrolling. >>>> >>>> Tested systematically with JDKs 6_51 and 8_11 but observed with all >>>> production releases of 8 before as well. >>>> >>>> Is this a known bug? >>>> >>>> Is there a known workaround (hacking the Look & Feel is also an option >>>> because we override it in our application anyway)? There must be as >>>> IntelliJ Idea does not have this problem and they are not using Aqua >>>> but I have failed to find it in their code. >>>> >>>> Does it make sense to file a bug report and if so where? >>>> >>>> Best, >>>> >>>> Robert >>> >>> >> >> >> >> -- >> Robert Kr?ger >> Managing Partner >> Lesspain GmbH & Co. KG >> >> www.lesspain-software.com >