eirikbakke commented on a change in pull request #3459: URL: https://github.com/apache/netbeans/pull/3459#discussion_r785316712
########## File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/resources/uimanager-icons.properties ########## @@ -0,0 +1,63 @@ +# 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. + +# This file lists icons to be replaced by URL-loaded images. +# The format is j.u.Properties; if value is missing, the key will be prefixed +# with org/netbeans/modules/nbcode/integration/resources/uidefaults/, suffix +# .png. If the value is present, it must be the full path to the resource incl. +# extension, that can be loaded by ImageUtilities.loadImage. +# +# Buildscript will automatically create stub resources for keys without value. + +CheckBox.icon +ComboBox.icon +ETableHeader.ascendingIcon +ETableHeader.descendingIcon +FileChooser.homeFolderIcon +FileChooser.newFolderIcon +FileChooser.upFolderIcon +Menu.arrowIcon +MSG_WaitScan +nb.bigclose.tab.icon.enabled.icon +nb.bigclose.tab.icon.pressed.icon +nb.bigclose.tab.icon.rollover.icon +nb.close.tab.icon.enabled.icon +nb.close.tab.icon.pressed.icon +nb.close.tab.icon.rollover.icon +nb.multitabs.button.dropdown.icon +nb.multitabs.button.left.icon +nb.multitabs.button.maximize.icon +nb.multitabs.button.right.icon +nb.popupswitcher.closebutton.defaultIcon +nb.popupswitcher.closebutton.rolloverIcon +nb.tabcontrol.busy.icon.normal +nb.tabcontrol.busy.icon.selected +OptionPane.informationIcon +OptionPane.warningIcon +PropSheet.customButtonIcon +RadioButton.icon +Table.columnSelection +ToolBar.handleIcon +Nb.Explorer.Folder.icon +Nb.Explorer.Folder.openedIcon +Tree.gtk_collapsedIcon +Tree.gtk_expandedIcon +Tree.closedIcon=org/netbeans/modules/nbcode/integration/resources/uidefaults/Tree.closedIcon.png +Tree.collapsedIcon +Tree.expandedIcon +Tree.leafIcon==org/netbeans/modules/nbcode/integration/resources/uidefaults/Tree.leafIcon.png Review comment: Typo with the double equals here? ########## File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/resources/uimanager-icons.properties ########## @@ -0,0 +1,63 @@ +# 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. + +# This file lists icons to be replaced by URL-loaded images. +# The format is j.u.Properties; if value is missing, the key will be prefixed +# with org/netbeans/modules/nbcode/integration/resources/uidefaults/, suffix +# .png. If the value is present, it must be the full path to the resource incl. +# extension, that can be loaded by ImageUtilities.loadImage. +# +# Buildscript will automatically create stub resources for keys without value. + +CheckBox.icon +ComboBox.icon +ETableHeader.ascendingIcon +ETableHeader.descendingIcon +FileChooser.homeFolderIcon +FileChooser.newFolderIcon +FileChooser.upFolderIcon +Menu.arrowIcon +MSG_WaitScan +nb.bigclose.tab.icon.enabled.icon +nb.bigclose.tab.icon.pressed.icon +nb.bigclose.tab.icon.rollover.icon +nb.close.tab.icon.enabled.icon +nb.close.tab.icon.pressed.icon +nb.close.tab.icon.rollover.icon +nb.multitabs.button.dropdown.icon +nb.multitabs.button.left.icon +nb.multitabs.button.maximize.icon +nb.multitabs.button.right.icon +nb.popupswitcher.closebutton.defaultIcon +nb.popupswitcher.closebutton.rolloverIcon +nb.tabcontrol.busy.icon.normal +nb.tabcontrol.busy.icon.selected +OptionPane.informationIcon +OptionPane.warningIcon +PropSheet.customButtonIcon +RadioButton.icon +Table.columnSelection +ToolBar.handleIcon +Nb.Explorer.Folder.icon +Nb.Explorer.Folder.openedIcon +Tree.gtk_collapsedIcon +Tree.gtk_expandedIcon +Tree.closedIcon=org/netbeans/modules/nbcode/integration/resources/uidefaults/Tree.closedIcon.png Review comment: Will this new png file show up somewhere in the GUI? There are better open/closed folder icons available in the codebase (and even SVG versions)... but I assume this is just a placeholder default. ########## File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/TreeItem.java ########## @@ -56,6 +55,27 @@ public String resourceUri; // ?: string | MarkdownString | undefined public Object tooltip; + + // NBLS-specific items, to be processed by the client: + // Metadata for the icon. + public IconDescriptor iconDescriptor; + // The icon's index + public int iconIndex; + + /** + * Metadata that describe an icon origin or contents. + */ + public static class IconDescriptor { + /** + * Base URI / imageId of the icon. + */ + public URI baseUri; + + /** + * Supplemental IDs from composed merged-in images or applied filters. + */ + public String[] composition; Review comment: As discussed earlier, trying to replace icons after they have already been loaded and even merged with badges etc. seems like a big hack. But you know the requirements here better than me, and it's localized to the LSP server stuff, so it's fine with me. ########## File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/UIDefaultsIconMetadata.java ########## @@ -0,0 +1,92 @@ +/* + * 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.EventQueue; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.UIDefaults; +import javax.swing.UIDefaults.LazyValue; +import javax.swing.UIManager; +import org.openide.modules.OnStart; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; + +/** + * Goes through UIDefaults and replaces Icons and Images with variants that + * return image's URL from the 'url' property. Review comment: Could you add a comment to this Javadoc pointing out that this will only run during the headless LSP stuff, and not during regular NetBeans IDE execution? ########## File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/UIDefaultsIconMetadata.java ########## @@ -0,0 +1,92 @@ +/* + * 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.EventQueue; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.UIDefaults; +import javax.swing.UIDefaults.LazyValue; +import javax.swing.UIManager; +import org.openide.modules.OnStart; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; + +/** + * 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()); + private static final String RESOURCE_PREFIX = "org/netbeans/modules/nbcode/integration/resources/uidefaults/"; // NOI18N + @Override + public void run() { + EventQueue.invokeLater(() -> { + // force LaF initialization before the UIDefaults are read/patched. + UIManager.get("force.laf.initialization"); + replaceIconsAndImages(UIManager.getDefaults()); + }); + } + + static void replaceIconsAndImages(UIDefaults defs) { + ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class); + try (InputStream is = UIDefaultsIconMetadata.class.getResourceAsStream("resources/uimanager-icons.properties")) { // NOI18N + Properties p = new Properties(); + p.load(is); + // UIDefaults.keySet() is so lazy implemented that it does not enumerate any items ... but entrySet Review comment: Yeah, I've noticed this in the past, too. Using entrySet to get all the keys is fine. -- 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
