neilcsmith-net commented on code in PR #9627: URL: https://github.com/apache/netbeans/pull/9627#discussion_r4045464637
########## ide/projectui/src/org/netbeans/modules/project/ui/ProjectsLaF.java: ########## @@ -0,0 +1,66 @@ +/* + * 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.project.ui; + +import java.awt.Color; +import javax.swing.UIManager; + +final class ProjectsLaF { + private ProjectsLaF() { + } + + /** Computes customized, or defaulted indentation prefix for + * {@link ProjectsRootNode}. Reads two {@link UIManager} properties: + * <ul> + * <li><code>nb.project.identation.char</code> - can be set to -1 to + * disable indentation altogether<li> + * <li><code>nb.project.indentation.color</code> - a color to use + * when rendering the indentation character in HTML + * </ul> + * both values come with reasonable defaults for L&Fs that don't specify them. + * + * @param html should we use or avoid HTML formatting + * @return {@code null} when indentation is disabled, otherwise returns + * a text to insert on each indentation level + */ + static String indentationPrefix(boolean html) { + int indentChar = UIManager.getInt("nb.project.identation.char"); // NOI18N + if (indentChar < 0) { + // no indentation when explicitly set to negative + return null; + } + if (indentChar == 0) { + indentChar = 0xbb; + } + if (html) { + Color indentColor = UIManager.getColor("nb.project.indentation.color"); // NOI18N + if (indentColor == null) { + indentColor = Color.gray; + } + int r = indentColor.getRed(); + int g = indentColor.getGreen(); + int b = indentColor.getBlue(); + + return String.format("<font color='#%02x%02x%02x'>&#%d; </font>", r, g, b, indentChar); // NOI18N + } else { Review Comment: Why this code? Is this designed for use outside `HtmlRenderer`? Because that supports direct usage via eg. `<font color='!nb.project.indentation.color'>` Does it need its own key rather than just picking one already used? Personally, I'd use `<font color='!controlShadow'>` like the [project node linked above](https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/nodes/MavenProjectNode.java#L119) Full customization is not my concern - ensuring we have a colour that has sufficient contrast with the background colour when people switch to dark, set a high contrast, etc. is. ########## ide/projectui/src/org/netbeans/modules/project/ui/ProjectsLaF.java: ########## @@ -0,0 +1,66 @@ +/* + * 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.project.ui; + +import java.awt.Color; +import javax.swing.UIManager; + +final class ProjectsLaF { + private ProjectsLaF() { + } + + /** Computes customized, or defaulted indentation prefix for + * {@link ProjectsRootNode}. Reads two {@link UIManager} properties: + * <ul> + * <li><code>nb.project.identation.char</code> - can be set to -1 to + * disable indentation altogether<li> + * <li><code>nb.project.indentation.color</code> - a color to use + * when rendering the indentation character in HTML + * </ul> + * both values come with reasonable defaults for L&Fs that don't specify them. + * + * @param html should we use or avoid HTML formatting + * @return {@code null} when indentation is disabled, otherwise returns + * a text to insert on each indentation level + */ + static String indentationPrefix(boolean html) { + int indentChar = UIManager.getInt("nb.project.identation.char"); // NOI18N + if (indentChar < 0) { + // no indentation when explicitly set to negative + return null; + } + if (indentChar == 0) { + indentChar = 0xbb; Review Comment: Why a `char` and not the indent `String`? This seems unnecessarily complicated, and means the space is still hardcoded. People could set to `""`, `"» "` or `" »»"`, or whatever. And it's a lot easier to explain. Would require the HTML escapes listed at https://github.com/apache/netbeans/blob/master/ide/editor.util/src/org/netbeans/lib/editor/util/StringEscapeUtils.java#L30 but anything else should be OK? -- 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
