jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r660637743



##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the 
project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return 
<b>SourceVersion.latest()</b>; most Processors are not affected by future 
language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:

Review comment:
       Maybe we could annotate shortcut keys for both JTextAreas and JCheckBox 
components with & character?

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the 
project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return 
<b>SourceVersion.latest()</b>; most Processors are not affected by future 
language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:
+CheckRegexTopComponent.exampleLabel.text=Example:
+CheckRegexTopComponent.strictCheckBox.text=Strict Check
+
+#{0}: PatternSyntaxException.getDescription()

Review comment:
       Commented out code should be removed.

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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.java.hints.jdk;
+
+import java.awt.Color;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+import org.openide.windows.TopComponent;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.Mode;
+import org.openide.windows.WindowManager;
+
+/**
+ * Top component which displays something.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
[email protected](
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
[email protected](mode = "output", openAtStartup = false, position = 
13000)
+@ActionID(category = "Window", id = 
"org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 
950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
[email protected](
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        
regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        
exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, 
javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, 
javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, 
javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new 
javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            
exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 
exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, 
javax.swing.GroupLayout.PREFERRED_SIZE, 17, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            
.addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, 
javax.swing.GroupLayout.PREFERRED_SIZE, 320, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            
exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                
.addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, 
javax.swing.GroupLayout.PREFERRED_SIZE, 18, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE))
+            
.addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, 
javax.swing.GroupLayout.PREFERRED_SIZE, 44, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, 
javax.swing.GroupLayout.PREFERRED_SIZE, 320, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 
layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, 
javax.swing.GroupLayout.PREFERRED_SIZE, 42, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) 
{//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) 
{//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) 
{//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // End of variables declaration//GEN-END:variables
+    @Override
+    public void componentOpened() {
+        // TODO add custom code on component opening
+    }
+
+    @Override
+    public void componentClosed() {
+        // TODO add custom code on component closing
+    }
+
+    void writeProperties(java.util.Properties p) {
+        // better to version settings since initial version as advocated at
+        // http://wiki.apidesign.org/wiki/PropertyFiles
+        p.setProperty("version", "1.0");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // 
NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = 
WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not 
be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + 
PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected 
behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the 
Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to 
match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match 
the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the 
Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || 
exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            
errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       I am afraid that because of this removal of all highlights if one 
selects an example text it just disappears. Please reconsider this solution.




-- 
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

Reply via email to