JaroslavTulach commented on a change in pull request #3414:
URL: https://github.com/apache/netbeans/pull/3414#discussion_r779680223
##########
File path: java/java.lsp.server/vscode/package.json
##########
@@ -661,8 +661,79 @@
"group": "inline@1"
}
]
- }
+ },
+
+ "netbeans.iconMapping" : [
+ {
Review comment:
APIs, APIs...
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/TreeNodeRegistryImpl.java
##########
@@ -248,10 +249,33 @@ public boolean imageUpdate(Image img, int infoflags, int
x, int y, int width, in
}
synchronized (this) {
if (res == null) {
- res = new ImageDataOrIndex(imageURI, imageCounter++);
+ res = new ImageDataOrIndex(imageURI, imageCounter++).
+ baseURL(findImageURI(i));
}
images.put(i, res);
}
return res;
}
+
+
+ public static URI findImageURI(Image i) {
Review comment:
I'd prefer to get rid of having `"uri"` and `"url"`. However, should
they stay, it'd be better to encapsulate access to them into
`ImageUtilities.findImageURI(...)` method. That would certainly be better than
spreding this `if instanceof ... else if instanceof else` cascades across the
codebase.
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -352,7 +369,14 @@ private static ToolTipImage icon2ToolTipImage(Icon icon,
URL url) {
should really only be called on the Event Dispatch Thread.
Constructing the component once
on the EDT fixed the problem. Read-only operations from non-EDT
threads shouldn't really be
a problem; most Icon implementations won't ever access the component
parameter anyway. */
- icon.paintIcon(dummyIconComponent, g, 0, 0);
+ try {
+ icon.paintIcon(dummyIconComponent, g, 0, 0);
+ } catch (ClassCastException ex) {
+ // java.desktop/javax.swing.plaf.metal.OceanTheme$IFIcon.paintIcon
assumes a different component,
+ // so let's try second most used one type, it satisfies
AbstractButton, JCheckbox. Not all cases are
+ // covered, however.
Review comment:
Tough problem.
##########
File path: java/java.lsp.server/vscode/schemas/package.schema.json
##########
@@ -0,0 +1,42 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "LSP Image Resource Mapping contributions to package.json",
+ "type": "object",
+ "properties": {
+ "contributes": {
+ "type": "object",
+ "properties": {
+ "netbeans.iconMapping" : {
Review comment:
Let's consider this the description of the API. Please state the
stability category of the API at least in this PR.
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -1178,23 +1281,27 @@ logical pixel position (7,0) would map to device pixel
position (10.5,0).
@Override
public Object getProperty(String name, ImageObserver observer) {
- if ("url".equals(name)) { // NOI18N
+ if ("url".equals(name) || "uri".equals(name)) { // NOI18N
Review comment:
Document in `arch.xml` as `<api group="property" .../>`.
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/api/TreeItemData.java
##########
@@ -83,7 +83,7 @@ public TreeItemData setContextValues(String... contextValues)
{
this.contextValues = contextValues;
return this;
}
-
+
Review comment:
Single needless change in the whole file...
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/DefaultDecorationsImpl.java
##########
@@ -56,6 +56,7 @@
public static final String EXPLORER_ROOT = "Explorers"; // NOI18N
public static final String COOKIES_EXT = "contextValues"; // NOI18N
+ public static final String CTXVALUE_FILE = "is:file"; // NOI18N
Review comment:
Probably it should be documented somewhere.
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -1069,31 +1140,55 @@ public static ToolTipImage createNew(String
toolTipText, Image image, URL url) {
if (url == null) {
Object value = image.getProperty("url", null);
url = (value instanceof URL) ? (URL) value : null;
- }
- Icon icon = (image instanceof ToolTipImage)
- ? ((ToolTipImage) image).getDelegateIcon() : null;
+ }
+ if (uri == null) {
+ Object value = image.getProperty("uri", null);
Review comment:
Do you know that you can instantiate any `URL` even those that do not
have global `URLHandler`? Just use [this
constructor](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#URL-java.net.URL-java.lang.String-java.net.URLStreamHandler-).
Possibly, by using this constructor we could eliminate the need for
introducing the `URI` contract.
##########
File path:
java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/UIDefaultsIconMetadata.java
##########
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import org.openide.modules.OnStart;
+import org.openide.util.ImageUtilities;
+
+/**
+ * Goes through UIDefaults and replaces Icons and Images with variants that
+ * return image's URL from the 'url' property.
+ * @author sdedic
+ */
+@OnStart
+public class UIDefaultsIconMetadata implements Runnable {
+ private static final Logger LOG =
Logger.getLogger(UIDefaultsIconMetadata.class.getName());
+
+ public static final String PROP_URI = "uri"; // NOI18N
+ public static final String PROP_URL = "url"; // NOI18N
+ public static final String PROP_ORIGINAL_ICON = "originalIcon"; // NOI18N
+ public static final String PROP_ORIGINAL_IMAGE = "originalImage"; // NOI18N
+
+ private static final String URN_DEFAULTS_PREFIX = "urn:uidefaults:"; //
NOI18N
Review comment:
Is the whole introduction of `"uri"` because you want to use this
`URN_DEFAULTS_PREFIX`!? I understand that when starting from scratch the
ability to have real `URI` with its "magical strings" might be beneficial, but
we are not starting from scratch. We have `"url"` on images - it'd be more
hidden if we could reuse it and just enhance it.
##########
File path:
java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/UIDefaultsIconMetadata.java
##########
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import org.openide.modules.OnStart;
+import org.openide.util.ImageUtilities;
+
+/**
+ * Goes through UIDefaults and replaces Icons and Images with variants that
+ * return image's URL from the 'url' property.
+ * @author sdedic
+ */
+@OnStart
+public class UIDefaultsIconMetadata implements Runnable {
+ private static final Logger LOG =
Logger.getLogger(UIDefaultsIconMetadata.class.getName());
+
+ public static final String PROP_URI = "uri"; // NOI18N
+ public static final String PROP_URL = "url"; // NOI18N
+ public static final String PROP_ORIGINAL_ICON = "originalIcon"; // NOI18N
+ public static final String PROP_ORIGINAL_IMAGE = "originalImage"; // NOI18N
+
+ private static final String URN_DEFAULTS_PREFIX = "urn:uidefaults:"; //
NOI18N
+
+ private static Image wrapImage(String key, Image image, Object... meta) {
+ Object o = image.getProperty(PROP_URL, null); // NOI18N
+ if (o instanceof URL) {
+ return image;
+ }
+
+ o = image.getProperty(PROP_URI, null);
+ if (o instanceof String || o instanceof URI) {
+ return image;
+ } else {
+
+ try {
+ Object[] a;
+
+ if (meta == null || meta.length == 0) {
+ a = new Object[] { PROP_URI, new URI(URN_DEFAULTS_PREFIX +
key) };
+ } else {
+ a = Arrays.copyOf(meta, meta.length + 2);
+ a[meta.length] = PROP_URI;
+ a[meta.length + 1] = new URI(URN_DEFAULTS_PREFIX + key);
+ }
+ return new MetadataImage(image, a);
+ } catch (URISyntaxException ex) {
+ return image;
+ }
+ }
+ }
+
+ @Override
+ public void run() {
+ EventQueue.invokeLater(() -> decorateUIDefaults());
+ }
+
+ public static void decorateUIDefaults() {
+ UIDefaults defs = UIManager.getDefaults();
+
+ for (Enumeration en = defs.keys(); en.hasMoreElements(); ) {
Review comment:
Replacing `UIManager.getDefaults()` and decorating the original items
when one asks for them would also be an option. Faster on startup, probably.
Converting only the icons that are needed.
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -825,22 +850,62 @@ private static final ToolTipImage doMergeImages(Image
image1, Image image2, int
str.append(toolTip);
}
Object firstUrl = image1.getProperty("url", null);
+ Object firstUri = image1.getProperty("uri", null);
ColorModel model = colorModel(bitmask? Transparency.BITMASK:
Transparency.TRANSLUCENT);
// Provide a delegate Icon for scalable rendering.
Icon delegateIcon = new MergedIcon(image2Icon(image1),
image2Icon(image2), x, y);
ToolTipImage buffImage = new ToolTipImage(str.toString(), delegateIcon,
- model, model.createCompatibleWritableRaster(w, h),
model.isAlphaPremultiplied(), null, firstUrl instanceof URL ? (URL)firstUrl :
null
+ model, model.createCompatibleWritableRaster(w, h),
model.isAlphaPremultiplied(), null,
+ firstUrl instanceof URL ? (URL)firstUrl : null,
+ firstUri instanceof URI ? (URI)firstUri : null
);
// Also provide an Image-based rendering for backwards-compatibility.
java.awt.Graphics g = buffImage.createGraphics();
- g.drawImage(image1, 0, 0, null);
- g.drawImage(image2, x, y, null);
+ drawImage(g, image1, 0, 0, null);
+ drawImage(g, image2, x, y, null);
g.dispose();
return buffImage;
}
+
+ /**
+ * Retrieves the original icon from a possible wrapper.
+ * @param image image
+ * @return the icon, if reachable.
+ */
+ private static Icon originalIcon(Image image) {
+ if (image instanceof ToolTipImage) {
+ return ((ToolTipImage) image).getDelegateIcon();
+ }
+ Object o = image.getProperty("originalIcon", null); // NOI18N
Review comment:
New API, right?
##########
File path:
java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/UIDefaultsIconMetadata.java
##########
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import org.openide.modules.OnStart;
+import org.openide.util.ImageUtilities;
+
+/**
+ * Goes through UIDefaults and replaces Icons and Images with variants that
+ * return image's URL from the 'url' property.
+ * @author sdedic
+ */
+@OnStart
+public class UIDefaultsIconMetadata implements Runnable {
+ private static final Logger LOG =
Logger.getLogger(UIDefaultsIconMetadata.class.getName());
+
+ public static final String PROP_URI = "uri"; // NOI18N
+ public static final String PROP_URL = "url"; // NOI18N
+ public static final String PROP_ORIGINAL_ICON = "originalIcon"; // NOI18N
+ public static final String PROP_ORIGINAL_IMAGE = "originalImage"; // NOI18N
+
+ private static final String URN_DEFAULTS_PREFIX = "urn:uidefaults:"; //
NOI18N
+
+ private static Image wrapImage(String key, Image image, Object... meta) {
+ Object o = image.getProperty(PROP_URL, null); // NOI18N
+ if (o instanceof URL) {
+ return image;
+ }
+
+ o = image.getProperty(PROP_URI, null);
+ if (o instanceof String || o instanceof URI) {
+ return image;
+ } else {
+
+ try {
+ Object[] a;
+
+ if (meta == null || meta.length == 0) {
+ a = new Object[] { PROP_URI, new URI(URN_DEFAULTS_PREFIX +
key) };
+ } else {
+ a = Arrays.copyOf(meta, meta.length + 2);
+ a[meta.length] = PROP_URI;
+ a[meta.length + 1] = new URI(URN_DEFAULTS_PREFIX + key);
+ }
+ return new MetadataImage(image, a);
+ } catch (URISyntaxException ex) {
+ return image;
+ }
+ }
+ }
+
+ @Override
+ public void run() {
+ EventQueue.invokeLater(() -> decorateUIDefaults());
+ }
+
+ public static void decorateUIDefaults() {
+ UIDefaults defs = UIManager.getDefaults();
+
+ for (Enumeration en = defs.keys(); en.hasMoreElements(); ) {
+ Object ok = en.nextElement();
+ Object o = defs.get(ok);
+ try {
+
+ if (o instanceof ImageIcon) {
+ ImageIcon ii = (ImageIcon)o;
+ Image wrapper = wrapImage(ok.toString(), ii.getImage(),
Review comment:
OK, wrapping the images to have attributes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists