mbien commented on code in PR #9748: URL: https://github.com/apache/netbeans/pull/9748#discussion_r4567579932
########## ide/properties/src/org/netbeans/modules/properties/formatter/FmtEncoding.java: ########## @@ -0,0 +1,105 @@ +/* + * 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.properties.formatter; + + +import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; +import org.netbeans.modules.properties.formatter.FmtOptions.CategorySupport; + +import static org.netbeans.modules.properties.formatter.FmtOptions.CategorySupport.OPTION_ID; +import static org.netbeans.modules.properties.formatter.FmtOptions.useProjectEncoding; + + +public class FmtEncoding extends javax.swing.JPanel { + + /** Creates new form FmtEncoding */ + @SuppressWarnings("LeakingThisInConstructor") + public FmtEncoding() { + initComponents(); + + useProjectEncodingCB.putClientProperty(OPTION_ID, useProjectEncoding); + } + + public static PreferencesCustomizer.Factory getController() { + String preview = """ + # Comment + key1.title=Demo Title + key2.title=Unicode symbols can be encoded to ASCII + """; + + return new CategorySupport.Factory("encoding", FmtEncoding.class, preview);//NOI18N + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + useProjectEncodingCB = new javax.swing.JCheckBox(); + jLabel1 = new javax.swing.JLabel(); + + setName(org.openide.util.NbBundle.getMessage(FmtEncoding.class, "FmtEncoding.name")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(useProjectEncodingCB, org.openide.util.NbBundle.getMessage(FmtEncoding.class, "FmtEncoding.useProjectEncodingCB.text")); // NOI18N + useProjectEncodingCB.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + useProjectEncodingCBActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(FmtEncoding.class, "FmtEncoding.useProjectEncodingCB.info")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addComponent(jLabel1)) + .addComponent(useProjectEncodingCB)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(useProjectEncodingCB) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel1) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// </editor-fold>//GEN-END:initComponents + + private void useProjectEncodingCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useProjectEncodingCBActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_useProjectEncodingCBActionPerformed + Review Comment: unused event handler ########## ide/properties/src/org/netbeans/modules/properties/formatter/FmtOptions.java: ########## @@ -0,0 +1,599 @@ +/* + * 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.properties.formatter; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.prefs.AbstractPreferences; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.ComboBoxModel; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JEditorPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.netbeans.api.editor.document.AtomicLockDocument; +import org.netbeans.api.editor.document.LineDocumentUtils; +import org.netbeans.api.editor.settings.SimpleValueNames; +import org.netbeans.modules.editor.indent.api.Reformat; +import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; +import org.netbeans.modules.options.editor.spi.PreviewProvider; +import org.openide.text.CloneableEditorSupport; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; + +/** + * + * @author phrebejk + * + */ +public class FmtOptions { + + private static final Logger LOGGER = Logger.getLogger(FmtOptions.class.getName()); + + public static final String expandTabToSpaces = SimpleValueNames.EXPAND_TABS; + public static final String tabSize = SimpleValueNames.TAB_SIZE; + public static final String spacesPerTab = SimpleValueNames.SPACES_PER_TAB; + public static final String indentSize = SimpleValueNames.INDENT_SHIFT_WIDTH; + public static final String rightMargin = SimpleValueNames.TEXT_LIMIT_WIDTH; + public static final String useProjectEncoding = "useProjectEncoding"; //NOI18N + + + private FmtOptions() {} + + public static int getDefaultAsInt(String key) { + return Integer.parseInt(defaults.get(key)); + } + + public static boolean getDefaultAsBoolean(String key) { + return Boolean.parseBoolean(defaults.get(key)); + } + + public static String getDefaultAsString(String key) { + return defaults.get(key); + } + + // Private section --------------------------------------------------------- + + private static final String TRUE = "true"; // NOI18N + private static final String FALSE = "false"; // NOI18N + + + private static Map<String,String> defaults; + + static { + createDefaults(); + } + + private static void createDefaults() { + String defaultValues[][] = { + { expandTabToSpaces, TRUE}, //NOI18N + { tabSize, "8"}, //NOI18N + { indentSize, "4"}, //NOI18N + { useProjectEncoding, "true"}, //NOI18N + { rightMargin, "80"}, //NOI18N + }; + + defaults = new HashMap<>(); + + for (java.lang.String[] strings : defaultValues) { + defaults.put(strings[0], strings[1]); + } + + } + + // Support section --------------------------------------------------------- + + public static class CategorySupport implements ActionListener, DocumentListener, PreviewProvider, PreferencesCustomizer { + + public static final String OPTION_ID = "org.netbeans.modules.properties.formatter.FormatingOptions.ID"; + + private static final int LOAD = 0; + private static final int STORE = 1; + private static final int ADD_LISTENERS = 2; + + private final String previewText; + private final String id; + protected final JPanel panel; + private final List<JComponent> components = new LinkedList<>(); + private JEditorPane previewPane; + + private final Preferences preferences; + private final Preferences previewPrefs; + + protected CategorySupport(Preferences preferences, String id, + JPanel panel, String previewText, String[]... forcedOptions) { + this.preferences = preferences; + this.id = id; + this.panel = panel; + this.previewText = previewText != null ? previewText : NbBundle.getMessage(FmtOptions.class, "SAMPLE_Default"); //NOI18N Review Comment: `SAMPLE_Default` might not exist. Can't find it at least -- 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
