From 3d84015f86457014b7e953cc908a9698d51d96c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Wed, 17 Sep 2025 14:03:39 +0200 Subject: [PATCH 1/5] Fix warnings: ELOccurrencesFinder, CssOccurrencesFinder, ScssCslLanguage, PHP OccurrencesFinderImpl --- .../modules/web/el/ELOccurrencesFinder.java | 40 ++++++------------- .../css/editor/csl/CssOccurrencesFinder.java | 10 ++--- .../css/prep/editor/scss/ScssCslLanguage.java | 1 - .../php/editor/csl/OccurrencesFinderImpl.java | 27 +++++-------- 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java b/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java index 2659e60b65b5..36370adb593a 100644 --- a/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java @@ -21,23 +21,18 @@ import com.sun.el.parser.AstIdentifier; import com.sun.el.parser.Node; -import com.sun.el.parser.NodeVisitor; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.el.ELException; import javax.lang.model.element.Element; -import org.netbeans.api.java.source.ClasspathInfo; import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.JavaSource; -import org.netbeans.api.java.source.Task; import org.netbeans.modules.csl.api.ColoringAttributes; import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.OffsetRange; -import org.netbeans.modules.parsing.spi.Parser.Result; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; import org.openide.filesystems.FileObject; @@ -49,7 +44,7 @@ * * @author Erno Mononen */ -final class ELOccurrencesFinder extends OccurrencesFinder { +final class ELOccurrencesFinder extends OccurrencesFinder { private int caretPosition; private boolean cancelled; @@ -64,17 +59,17 @@ public void setCaretPosition(int position) { } @Override - public Map getOccurrences() { + public Map getOccurrences() { return occurrences; } @Override - public void run(Result result, SchedulerEvent event) { + public void run(ELParserResult result, SchedulerEvent event) { occurrences.clear(); if (checkAndResetCancel()) { return; } - computeOccurrences((ELParserResult) result); + computeOccurrences(result); } @Override @@ -111,33 +106,24 @@ private void computeOccurrences(final ELParserResult parserResult) { if (!eLElement.isValid()) { continue; } - eLElement.getNode().accept(new NodeVisitor() { - - @Override - public void visit(Node node) throws ELException { - if (node.getClass().equals(targetNode.getClass()) - && targetNode.getImage().equals(node.getImage())) { - matching.add(Pair.of(eLElement, node)); - } + eLElement.getNode().accept((Node node) -> { + if (node.getClass().equals(targetNode.getClass()) + && targetNode.getImage().equals(node.getImage())) { + matching.add(Pair.of(eLElement, node)); } }); } final FileObject file = parserResult.getFileObject(); JavaSource jsource = JavaSource.create(ELTypeUtilities.getElimplExtendedCPI(file)); try { - jsource.runUserActionTask(new Task() { - - @Override - public void run(CompilationController info) throws Exception { - info.toPhase(JavaSource.Phase.RESOLVED); - occurrences.putAll(findMatchingTypes(CompilationContext.create(file, info), parserResult, target, matching)); - - } + jsource.runUserActionTask((CompilationController info) -> { + info.toPhase(JavaSource.Phase.RESOLVED); + occurrences.putAll(findMatchingTypes(CompilationContext.create(file, info), target, matching)); }, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } - + if (this.occurrences.isEmpty()) { // perhaps the caret is on a resource bundle key node occurrences.putAll(findMatchingResourceBundleKeys(target, parserResult)); @@ -185,7 +171,7 @@ private Map findMatchingResourceBundleKeys(Pair return result; } - private Map findMatchingTypes(CompilationContext info, ELParserResult parserResult, Pair target, List> candidates) { + private Map findMatchingTypes(CompilationContext info, Pair target, List> candidates) { Element targetType = ELTypeUtilities.resolveElement(info, target.first(), target.second()); Map result = new HashMap<>(); diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java b/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java index 20eccb40f136..bb79f654b28a 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java @@ -30,14 +30,13 @@ import org.netbeans.modules.css.editor.module.spi.EditorFeatureContext; import org.netbeans.modules.css.editor.module.spi.FeatureCancel; import org.netbeans.modules.css.lib.api.CssParserResult; -import org.netbeans.modules.parsing.spi.Parser.Result; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; /** * @author mfukala@netbeans.org */ -public class CssOccurrencesFinder extends OccurrencesFinder { +public class CssOccurrencesFinder extends OccurrencesFinder { private int caretDocumentPosition; private Map occurrencesMap = Collections.emptyMap(); @@ -63,13 +62,12 @@ public void cancel() { private void resume() { featureCancel = new FeatureCancel(); } - + @Override - public void run(Result result, SchedulerEvent event) { + public void run(CssParserResult parserResultWrapper, SchedulerEvent event) { resume(); - + try { - CssParserResult parserResultWrapper = (CssParserResult)result; EditorFeatureContext context = new EditorFeatureContext(parserResultWrapper, caretDocumentPosition); Set occurrences = CssModuleSupport.getMarkOccurrences(context, featureCancel); diff --git a/ide/css.prep/src/org/netbeans/modules/css/prep/editor/scss/ScssCslLanguage.java b/ide/css.prep/src/org/netbeans/modules/css/prep/editor/scss/ScssCslLanguage.java index b32e83ba3106..919fb52a31e5 100644 --- a/ide/css.prep/src/org/netbeans/modules/css/prep/editor/scss/ScssCslLanguage.java +++ b/ide/css.prep/src/org/netbeans/modules/css/prep/editor/scss/ScssCslLanguage.java @@ -22,7 +22,6 @@ import org.netbeans.core.spi.multiview.MultiViewElement; import org.netbeans.core.spi.multiview.text.MultiViewEditorElement; import org.netbeans.modules.csl.api.DeclarationFinder; -import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.StructureScanner; import org.netbeans.modules.csl.spi.DefaultLanguageConfig; import org.netbeans.modules.csl.spi.LanguageRegistration; diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java b/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java index 3af852dbd642..f10ec02f0f53 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; @@ -34,8 +33,6 @@ import org.netbeans.modules.csl.api.ColoringAttributes; import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.OffsetRange; -import org.netbeans.modules.csl.spi.ParserResult; -import org.netbeans.modules.parsing.spi.Parser.Result; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; import org.netbeans.modules.php.editor.api.PhpElementKind; @@ -56,7 +53,7 @@ * * @author Radek Matous */ -public class OccurrencesFinderImpl extends OccurrencesFinder { +public class OccurrencesFinderImpl extends OccurrencesFinder { private Map range2Attribs = Collections.emptyMap(); private int caretPosition; private volatile boolean cancelled; @@ -78,7 +75,7 @@ public void cancel() { } @Override - public void run(Result result, SchedulerEvent event) { + public void run(PHPParseResult result, SchedulerEvent event) { if (cancelled) { cancelled = false; return; @@ -87,7 +84,7 @@ public void run(Result result, SchedulerEvent event) { Preferences node = MarkOccurencesSettings.getCurrentNode(); Map localRange2Attribs = new HashMap<>(); if (node.getBoolean(MarkOccurencesSettings.ON_OFF, true)) { - for (OffsetRange r : compute((ParserResult) result, caretPosition)) { + for (OffsetRange r : compute(result, caretPosition)) { localRange2Attribs.put(r, ColoringAttributes.MARK_OCCURRENCES); } } @@ -107,18 +104,12 @@ public void run(Result result, SchedulerEvent event) { } } - private Collection compute(final ParserResult parameter, final int offset) { - final PHPParseResult parseResult = (PHPParseResult) parameter; - Set result = new TreeSet<>(new Comparator() { - @Override - public int compare(OffsetRange o1, OffsetRange o2) { - return o1.compareTo(o2); - } - }); + private Collection compute(final PHPParseResult parseResult, final int offset) { + Set result = new TreeSet<>(); final TokenHierarchy tokenHierarchy = parseResult.getSnapshot().getTokenHierarchy(); TokenSequence tokenSequence = tokenHierarchy != null ? LexUtilities.getPHPTokenSequence(tokenHierarchy, offset) : null; if (cancelled) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } OffsetRange referenceSpan = tokenSequence != null ? DeclarationFinderImpl.getReferenceSpan(tokenSequence, offset, parseResult.getModel()) : OffsetRange.NONE; if (!referenceSpan.equals(OffsetRange.NONE)) { @@ -138,11 +129,11 @@ private Collection getOccurrences(Model model, OffsetRange referenc Collection result = new TreeSet<>(); OccurencesSupport occurencesSupport = model.getOccurencesSupport(referenceSpan); if (cancelled) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } Occurence caretOccurence = occurencesSupport.getOccurence(); if (cancelled) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } if (caretOccurence != null) { final EnumSet handledAccuracyFlags = EnumSet.of( @@ -205,7 +196,7 @@ public Class getSchedulerClass() { } private static final class OccurrenceHighlighterImpl implements OccurrenceHighlighter { - private Set offsetRanges = new TreeSet<>(); + private final Set offsetRanges = new TreeSet<>(); @Override public void add(OffsetRange offsetRange) { From 8816020b802f7160145946feba9b5e69e1041e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Wed, 17 Sep 2025 15:25:34 +0200 Subject: [PATCH 2/5] GSF/CSL Languages: Centralize "Enable Occurrences Hightlight" and "Keep Marks" Handling According to the documentation of OccurrencesFinder the occurrences scanning should be stateless. The current API holds a calculate and a getter method, but in the spirit of keeping it mostly stateless, more state should not be added. The OccurrencesFinder implementation returns a set of occurrenes corresponding to the currently highlighted area. These areas are described by integer arrays (2 elements, start and end index). Given the return types these areas are only valid until the next edit occurrs. On each input the highlights are recalculated. That works fine until "Keep Marks" is activated. "Keep Marks" keeps the marks, when the caret is moved of a highlightable variable. If "Keep Marks" is enabled the marks will be retained then until the caret is placed onto another highlightable element. The marks in this case must adapt to changes of the content of the element. Swing Document provides the "Position" class for this. That class is used by GsfSemanticLayer to hold the areas returned by the OccurrencesFinder implementation. So to support "Keep Marks" the CSL/GSF layer has to be aware of this, so that the GsfSemanticLayer can retain the highlights. In addition to this there is no need to scan for occurrences if the highlighting is disabled, so that also moves to the CSL/GSF layer. Closes: #8803 --- ide/csl.api/apichanges.xml | 19 +++++++ .../modules/csl/api/OccurrencesFinder.java | 24 +++++++++ .../semantic/MarkOccurrencesHighlighter.java | 29 ++++++++--- .../php/editor/csl/OccurrencesFinderImpl.java | 28 ++++++----- .../editor/options/MarkOccurencesPanel.form | 42 +++++----------- .../editor/options/MarkOccurencesPanel.java | 49 ++++++++----------- 6 files changed, 114 insertions(+), 77 deletions(-) diff --git a/ide/csl.api/apichanges.xml b/ide/csl.api/apichanges.xml index 570bf5ef1e67..0791e4386bb2 100644 --- a/ide/csl.api/apichanges.xml +++ b/ide/csl.api/apichanges.xml @@ -25,6 +25,25 @@ Common Scripting Language API + + + Enable controlling highlighting of occurrences + + + + + +

+ Add two accessors isMarkOccurrencesEnabled and + isKeepMarks to OccurrencesFinder. The + intention is, that implementors of OccurrencesFinder + can indicate, whether highlighting of occurrenes is enabled and + if highlights should be retained, after the caret is moved off + the highlighted item. +

+
+ +
Adding a new StructureItem.InheritedItem interface diff --git a/ide/csl.api/src/org/netbeans/modules/csl/api/OccurrencesFinder.java b/ide/csl.api/src/org/netbeans/modules/csl/api/OccurrencesFinder.java index 457641092d24..c8617ca37083 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/api/OccurrencesFinder.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/api/OccurrencesFinder.java @@ -49,4 +49,28 @@ public abstract class OccurrencesFinder extends ParserR * {@link #run}. */ public abstract @NonNull Map getOccurrences(); + + /** + * Control occurrence highlight visibility. + * + * @return {@code false} to disable occurrence highlighting. Default value + * is {@code true}. + * + * @since 2.88.0 + */ + public boolean isMarkOccurrencesEnabled() { + return true; + } + + /** + * Control retaining highlights when carret is moved off a highlightable + * element. If {@code true} highlights will be retained if carret is moved + * off a highlightable element, if {@code false} the highlights will be + * removed. + * + * @since 2.88.0 + */ + public boolean isKeepMarks() { + return true; + } } diff --git a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java index e3ddaa984915..a3889cf8e0f1 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java @@ -19,6 +19,7 @@ package org.netbeans.modules.csl.editor.semantic; import java.awt.Color; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.SortedSet; @@ -107,11 +108,10 @@ public void run(ParserResult info, SchedulerEvent event) { return; } - List bag = processImpl(info, doc, caretPosition); - if (cancel.isCancelled()) { - //the occurrences finder haven't found anything, just ignore the result - //and keep the previous occurrences - return ; + List bag = Collections.emptyList(); + + if (snapshotOffset >= 0) { + bag = processImpl(info, doc, caretPosition); } GsfSemanticLayer layer = GsfSemanticLayer.getLayer(MarkOccurrencesHighlighter.class, doc); @@ -124,9 +124,22 @@ public void run(ParserResult info, SchedulerEvent event) { } catch (BadLocationException ex) {} } } - layer.setColorings(seqs); - OccurrencesMarkProvider.get(doc).setOccurrences(OccurrencesMarkProvider.createMarks(doc, bag, ES_COLOR, NbBundle.getMessage(MarkOccurrencesHighlighter.class, "LBL_ES_TOOLTIP"))); + boolean updateHighlights = false; + if(seqs.isEmpty()) { + OccurrencesFinder finder = language.getOccurrencesFinder(); + if (finder == null || !finder.isMarkOccurrencesEnabled() || !finder.isKeepMarks()) { + updateHighlights = true; + } + } else { + updateHighlights = true; + } + + if(updateHighlights) { + // Update both editor highlighs and sidebar marks + layer.setColorings(seqs); + OccurrencesMarkProvider.get(doc).setOccurrences(OccurrencesMarkProvider.createMarks(doc, bag, ES_COLOR, NbBundle.getMessage(MarkOccurrencesHighlighter.class, "LBL_ES_TOOLTIP"))); + } } finally { SpiSupportAccessor.getInstance().removeCancelSupport(cancel); } @@ -135,7 +148,7 @@ public void run(ParserResult info, SchedulerEvent event) { @NonNull List processImpl(ParserResult info, Document doc, int caretPosition) { OccurrencesFinder finder = language.getOccurrencesFinder(); - if(finder == null) { + if (finder == null || !finder.isMarkOccurrencesEnabled()) { return List.of(); } diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java b/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java index f10ec02f0f53..a9c3a5cbd88c 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import java.util.prefs.Preferences; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; @@ -81,9 +80,8 @@ public void run(PHPParseResult result, SchedulerEvent event) { return; } - Preferences node = MarkOccurencesSettings.getCurrentNode(); Map localRange2Attribs = new HashMap<>(); - if (node.getBoolean(MarkOccurencesSettings.ON_OFF, true)) { + if (isMarkOccurrencesEnabled()) { for (OffsetRange r : compute(result, caretPosition)) { localRange2Attribs.put(r, ColoringAttributes.MARK_OCCURRENCES); } @@ -94,14 +92,22 @@ public void run(PHPParseResult result, SchedulerEvent event) { return; } - if (!localRange2Attribs.isEmpty()) { - // store the new occurrences if any were found - range2Attribs = Collections.unmodifiableMap(localRange2Attribs); - } else if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true)) { - // clear occurrences if "Keep Marks" is not selected. If "Keep Marks" - // is enabled, the old ranges must be retained. - range2Attribs = Collections.emptyMap(); - } + // store the new occurrences if any were found + range2Attribs = Collections.unmodifiableMap(localRange2Attribs); + } + + @Override + public boolean isKeepMarks() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.ON_OFF, true); } private Collection compute(final PHPParseResult parseResult, final int offset) { diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.form b/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.form index aaf8211e1925..e5d4009587ac 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.form +++ b/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.form @@ -50,38 +50,10 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -102,6 +74,11 @@ + + + + + @@ -110,6 +87,11 @@ + + + + + diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java b/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java index 1b013c071de2..55f39f2f3ca3 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java @@ -97,6 +97,7 @@ public boolean changed() { */ // //GEN-BEGIN:initComponents private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; onOffCheckBox = new javax.swing.JCheckBox(); keepMarksCheckBox = new javax.swing.JCheckBox(); @@ -124,40 +125,32 @@ public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, }} ); + setLayout(new java.awt.GridBagLayout()); org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - - keepMarksCheckBox.setMnemonic('s'); - org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // 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() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(onOffCheckBox)) - .addGroup(layout.createSequentialGroup() - .addGap(37, 37, 37) - .addComponent(keepMarksCheckBox))) - .addContainerGap(226, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(onOffCheckBox) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(keepMarksCheckBox) - .addContainerGap(237, Short.MAX_VALUE)) - ); - + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N }// //GEN-END:initComponents From 5f76b96390e5b9167e4996aa4d9b367d576bf460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Wed, 17 Sep 2025 16:18:23 +0200 Subject: [PATCH 3/5] Make occurrence highlighting configurable: Antlr 3+4, Groovy, Expression Language, CSS, JS, JSON --- enterprise/web.el/nbproject/project.xml | 8 + .../modules/web/el/ELOccurrencesFinder.java | 15 ++ .../src/org/netbeans/modules/web/el/layer.xml | 10 + .../modules/web/el/options/Bundle.properties | 23 ++ .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../web/el/options/MarkOccurencesPanel.form | 102 +++++++++ .../web/el/options/MarkOccurencesPanel.java | 197 +++++++++++++++++ .../el/options/MarkOccurencesSettings.java | 46 ++++ .../api/parser/GroovyOccurrencesFinder.java | 15 ++ .../groovy/editor/options/Bundle.properties | 23 ++ .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../editor/options/MarkOccurencesPanel.form | 102 +++++++++ .../editor/options/MarkOccurencesPanel.java | 196 +++++++++++++++++ .../options/MarkOccurencesSettings.java | 46 ++++ .../modules/groovy/editor/resources/layer.xml | 10 + ide/css.editor/nbproject/project.xml | 19 +- .../css/editor/csl/CssOccurrencesFinder.java | 14 ++ .../css/editor/options/Bundle.properties | 23 ++ .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../editor/options/MarkOccurencesPanel.form | 102 +++++++++ .../editor/options/MarkOccurencesPanel.java | 195 +++++++++++++++++ .../options/MarkOccurencesSettings.java | 46 ++++ .../netbeans/modules/css/resources/layer.xml | 10 + java/languages.antlr/nbproject/project.xml | 9 + .../antlr/AntlrOccurrencesFinder.java | 17 +- .../modules/languages/antlr/layer.xml | 16 ++ .../languages/antlr/v3/Antlr3Language.java | 2 +- .../languages/antlr/v3/Bundle.properties | 23 ++ .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../antlr/v3/MarkOccurencesPanel.form | 102 +++++++++ .../antlr/v3/MarkOccurencesPanel.java | 196 +++++++++++++++++ .../antlr/v3/MarkOccurencesSettings.java | 42 ++++ .../languages/antlr/v4/Antlr4Language.java | 2 +- .../languages/antlr/v4/Bundle.properties | 23 ++ .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../antlr/v4/MarkOccurencesPanel.form | 102 +++++++++ .../antlr/v4/MarkOccurencesPanel.java | 200 ++++++++++++++++++ .../antlr/v4/MarkOccurencesSettings.java | 42 ++++ .../navigation/JsonOccurrencesFinder.java | 15 ++ .../navigation/OccurrencesFinderImpl.java | 15 ++ .../editor/options/ui/Bundle.properties | 7 + .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../options/ui/MarkOccurencesPanel.form | 102 +++++++++ .../options/ui/MarkOccurencesPanel.java | 196 +++++++++++++++++ .../options/ui/MarkOccurencesSettings.java | 42 ++++ .../editor/options/ui/json/Bundle.properties | 7 + .../MarkOccurencesOptionsPanelController.java | 95 +++++++++ .../options/ui/json/MarkOccurencesPanel.form | 102 +++++++++ .../options/ui/json/MarkOccurencesPanel.java | 196 +++++++++++++++++ .../ui/json/MarkOccurencesSettings.java | 42 ++++ .../javascript2/editor/resources/layer.xml | 16 ++ 51 files changed, 3375 insertions(+), 8 deletions(-) create mode 100644 enterprise/web.el/src/org/netbeans/modules/web/el/options/Bundle.properties create mode 100644 enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesOptionsPanelController.java create mode 100644 enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.form create mode 100644 enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.java create mode 100644 enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesSettings.java create mode 100644 groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/Bundle.properties create mode 100644 groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesOptionsPanelController.java create mode 100644 groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.form create mode 100644 groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java create mode 100644 groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesSettings.java create mode 100644 ide/css.editor/src/org/netbeans/modules/css/editor/options/Bundle.properties create mode 100644 ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesOptionsPanelController.java create mode 100644 ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.form create mode 100644 ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java create mode 100644 ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesSettings.java create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Bundle.properties create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesOptionsPanelController.java create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.form create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesSettings.java create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Bundle.properties create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesOptionsPanelController.java create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.form create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java create mode 100644 java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesSettings.java create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesOptionsPanelController.java create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.form create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesSettings.java create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesOptionsPanelController.java create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.form create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java create mode 100644 webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesSettings.java diff --git a/enterprise/web.el/nbproject/project.xml b/enterprise/web.el/nbproject/project.xml index 433e454cafe2..2e7872d6e8eb 100644 --- a/enterprise/web.el/nbproject/project.xml +++ b/enterprise/web.el/nbproject/project.xml @@ -304,6 +304,14 @@ 1.11 + + org.openide.awt + + + + 7.98 + + org.openide.filesystems diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java b/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java index 36370adb593a..1134afae8f0c 100644 --- a/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/ELOccurrencesFinder.java @@ -35,6 +35,7 @@ import org.netbeans.modules.csl.api.OffsetRange; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; +import org.netbeans.modules.web.el.options.MarkOccurencesSettings; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; import org.openide.util.Pair; @@ -87,6 +88,20 @@ public void cancel() { this.cancelled = true; } + @Override + public boolean isKeepMarks() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.ON_OFF, true); + } + private void computeOccurrences(final ELParserResult parserResult) { ELElement current = parserResult.getElementAt(caretPosition); if (current == null) { diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/layer.xml b/enterprise/web.el/src/org/netbeans/modules/web/el/layer.xml index a0082690ff45..a05c67cb12ab 100644 --- a/enterprise/web.el/src/org/netbeans/modules/web/el/layer.xml +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/layer.xml @@ -70,6 +70,16 @@ + + + + + + + + + + diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/options/Bundle.properties b/enterprise/web.el/src/org/netbeans/modules/web/el/options/Bundle.properties new file mode 100644 index 000000000000..44044ae5d335 --- /dev/null +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/options/Bundle.properties @@ -0,0 +1,23 @@ +# 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. + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for Expression Language Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=Expression Language Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesOptionsPanelController.java b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..5da340aec708 --- /dev/null +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.web.el.options; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.el.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.form b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.form new file mode 100644 index 000000000000..f6361b565434 --- /dev/null +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.java b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.java new file mode 100644 index 000000000000..d049cc7bbed3 --- /dev/null +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesPanel.java @@ -0,0 +1,197 @@ +/* + * 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.web.el.options; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.awt.*; +import org.openide.util.Exceptions; + +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + keepMarksCheckBox.setMnemonic('s'); + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesSettings.java b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesSettings.java new file mode 100644 index 000000000000..9dcee3063fdc --- /dev/null +++ b/enterprise/web.el/src/org/netbeans/modules/web/el/options/MarkOccurencesSettings.java @@ -0,0 +1,46 @@ +/* + * 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.web.el.options; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +/** + * + * @author Jan Lahoda + */ +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyOccurrencesFinder.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyOccurrencesFinder.java index 86c84a8ba506..67442b590074 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyOccurrencesFinder.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyOccurrencesFinder.java @@ -35,6 +35,7 @@ import org.netbeans.modules.groovy.editor.api.ASTUtils.FakeASTNode; import org.netbeans.modules.groovy.editor.occurrences.VariableScopeVisitor; import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities; +import org.netbeans.modules.groovy.editor.options.MarkOccurencesSettings; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; import org.openide.filesystems.FileObject; @@ -165,6 +166,20 @@ public void setCaretPosition(int position) { LOG.log(Level.FINEST, "\n\nsetCaretPosition() = {0}\n", position); //NOI18N } + @Override + public boolean isKeepMarks() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.ON_OFF, true); + } + private static void highlight(AstPath path, Map highlights, BaseDocument document, int cursorOffset) { ASTNode root = path.root(); assert root instanceof ModuleNode; diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/Bundle.properties b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/Bundle.properties new file mode 100644 index 000000000000..eea87d0fdd28 --- /dev/null +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/Bundle.properties @@ -0,0 +1,23 @@ +# 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. + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for Groovy Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=Groovy Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesOptionsPanelController.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..107c8944db0b --- /dev/null +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.groovy.editor.options; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.groovy.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.form b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.form new file mode 100644 index 000000000000..a028370a77b4 --- /dev/null +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java new file mode 100644 index 000000000000..662606999f0b --- /dev/null +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java @@ -0,0 +1,196 @@ +/* + * 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.groovy.editor.options; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.util.Exceptions; + +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + keepMarksCheckBox.setMnemonic('s'); + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesSettings.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesSettings.java new file mode 100644 index 000000000000..7c58d8fb2020 --- /dev/null +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesSettings.java @@ -0,0 +1,46 @@ +/* + * 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.groovy.editor.options; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +/** + * + * @author Jan Lahoda + */ +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/resources/layer.xml b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/resources/layer.xml index 49fa9ab0650c..a4ad0e51ef03 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/resources/layer.xml +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/resources/layer.xml @@ -160,6 +160,16 @@ + + + + + + + + + + diff --git a/ide/css.editor/nbproject/project.xml b/ide/css.editor/nbproject/project.xml index 88c6824b0158..8cfd63f079c9 100644 --- a/ide/css.editor/nbproject/project.xml +++ b/ide/css.editor/nbproject/project.xml @@ -185,6 +185,15 @@ 1.26
+ + org.netbeans.modules.options.api + + + + 1 + 1.75 + + org.netbeans.modules.parsing.api @@ -317,7 +326,7 @@ - org.openide.util.ui + org.openide.util @@ -325,19 +334,19 @@ - org.openide.util + org.openide.util.lookup - 9.3 + 8.0 - org.openide.util.lookup + org.openide.util.ui - 8.0 + 9.3 diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java b/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java index bb79f654b28a..bd7e45742df8 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/csl/CssOccurrencesFinder.java @@ -29,6 +29,7 @@ import org.netbeans.modules.css.editor.module.CssModuleSupport; import org.netbeans.modules.css.editor.module.spi.EditorFeatureContext; import org.netbeans.modules.css.editor.module.spi.FeatureCancel; +import org.netbeans.modules.css.editor.options.MarkOccurencesSettings; import org.netbeans.modules.css.lib.api.CssParserResult; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; @@ -96,5 +97,18 @@ public Class getSchedulerClass() { return null; } + @Override + public boolean isKeepMarks() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.ON_OFF, true); + } } diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/options/Bundle.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/options/Bundle.properties new file mode 100644 index 000000000000..49115a03b3a2 --- /dev/null +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/options/Bundle.properties @@ -0,0 +1,23 @@ +# 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. + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for CSS Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=CSS Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesOptionsPanelController.java b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..0f65e26b8f97 --- /dev/null +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.css.editor.options; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.css.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.form b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.form new file mode 100644 index 000000000000..425dcccf947d --- /dev/null +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java new file mode 100644 index 000000000000..ee773eb01ae5 --- /dev/null +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java @@ -0,0 +1,195 @@ +/* + * 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.css.editor.options; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.util.Exceptions; + +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesSettings.java b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesSettings.java new file mode 100644 index 000000000000..8ee8dc38f6c1 --- /dev/null +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesSettings.java @@ -0,0 +1,46 @@ +/* + * 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.css.editor.options; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +/** + * + * @author Jan Lahoda + */ +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/ide/css.editor/src/org/netbeans/modules/css/resources/layer.xml b/ide/css.editor/src/org/netbeans/modules/css/resources/layer.xml index 95b40fdafee6..7b36e137050f 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/resources/layer.xml +++ b/ide/css.editor/src/org/netbeans/modules/css/resources/layer.xml @@ -209,6 +209,16 @@ + + + + + + + + + + diff --git a/java/languages.antlr/nbproject/project.xml b/java/languages.antlr/nbproject/project.xml index 05c1ef1db2fd..ee0039180180 100644 --- a/java/languages.antlr/nbproject/project.xml +++ b/java/languages.antlr/nbproject/project.xml @@ -149,6 +149,15 @@ 1.0
+ + org.netbeans.modules.options.api + + + + 1 + 1.75 + + org.netbeans.modules.parsing.api diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrOccurrencesFinder.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrOccurrencesFinder.java index 7b4f35b8353d..b95f4112d915 100644 --- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrOccurrencesFinder.java +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrOccurrencesFinder.java @@ -19,14 +19,15 @@ package org.netbeans.modules.languages.antlr; import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.prefs.Preferences; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.modules.csl.api.ColoringAttributes; import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.OffsetRange; +import org.netbeans.modules.languages.antlr.v4.MarkOccurencesSettings; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; @@ -39,6 +40,11 @@ public class AntlrOccurrencesFinder extends OccurrencesFinder private int caretPosition; private boolean cancelled; private final Map occurrences = new HashMap<>(); + private final Preferences markOccurrencesPreferences; + + public AntlrOccurrencesFinder(Preferences markOccurrencesPreferences) { + this.markOccurrencesPreferences = markOccurrencesPreferences; + } @Override public void setCaretPosition(int position) { @@ -74,6 +80,15 @@ public void cancel() { this.cancelled = true; } + @Override + public boolean isKeepMarks() { + return markOccurrencesPreferences.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return markOccurrencesPreferences.getBoolean(MarkOccurencesSettings.ON_OFF, true); + } private boolean checkAndResetCancel() { if (cancelled) { diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/layer.xml b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/layer.xml index d956ef1f3046..161cd01c1d26 100644 --- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/layer.xml +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/layer.xml @@ -94,6 +94,22 @@ + + + + + + + + + + + + + + + + diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Antlr3Language.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Antlr3Language.java index 296990aded43..476dfdd7f956 100644 --- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Antlr3Language.java +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Antlr3Language.java @@ -172,7 +172,7 @@ public boolean hasStructureScanner() { @Override public OccurrencesFinder getOccurrencesFinder() { - return new AntlrOccurrencesFinder(); + return new AntlrOccurrencesFinder(MarkOccurencesSettings.getCurrentNode()); } @Override diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Bundle.properties b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Bundle.properties new file mode 100644 index 000000000000..1f4ab4b30fc0 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/Bundle.properties @@ -0,0 +1,23 @@ +# 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. + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for Antlr 3 Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=Antlr 3 Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesOptionsPanelController.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..e631692deab9 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.languages.antlr.v3; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.antlr3.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.form b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.form new file mode 100644 index 000000000000..288a611ea315 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java new file mode 100644 index 000000000000..7358e774e5ec --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java @@ -0,0 +1,196 @@ +/* + * 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.languages.antlr.v3; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.util.Exceptions; + +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + keepMarksCheckBox.setMnemonic('s'); + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesSettings.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesSettings.java new file mode 100644 index 000000000000..de673e17c0eb --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesSettings.java @@ -0,0 +1,42 @@ +/* + * 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.languages.antlr.v3; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node("antlr3").node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4Language.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4Language.java index 88fa824a6a5c..b384e0020333 100644 --- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4Language.java +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4Language.java @@ -179,7 +179,7 @@ public boolean hasStructureScanner() { @Override public OccurrencesFinder getOccurrencesFinder() { - return new AntlrOccurrencesFinder(); + return new AntlrOccurrencesFinder(MarkOccurencesSettings.getCurrentNode()); } @Override diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Bundle.properties b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Bundle.properties new file mode 100644 index 000000000000..d80651699620 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Bundle.properties @@ -0,0 +1,23 @@ +# 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. + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for Antlr 4 Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=Antlr 4 Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesOptionsPanelController.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..37ba94bb5043 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.languages.antlr.v4; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.antlr4.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.form b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.form new file mode 100644 index 000000000000..f3019d220e18 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java new file mode 100644 index 000000000000..c66f2a071a14 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java @@ -0,0 +1,200 @@ +/* + * 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.languages.antlr.v4; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.util.Exceptions; + +/** + * + * @author Petr Hrebejk + */ +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + keepMarksCheckBox.setMnemonic('s'); + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesSettings.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesSettings.java new file mode 100644 index 000000000000..68c7192c5af9 --- /dev/null +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesSettings.java @@ -0,0 +1,42 @@ +/* + * 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.languages.antlr.v4; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node("antlr4").node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/JsonOccurrencesFinder.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/JsonOccurrencesFinder.java index 56150ac66e5e..23e2934f876a 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/JsonOccurrencesFinder.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/JsonOccurrencesFinder.java @@ -32,6 +32,7 @@ import org.netbeans.modules.csl.api.ColoringAttributes; import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.OffsetRange; +import org.netbeans.modules.javascript2.editor.options.ui.json.MarkOccurencesSettings; import org.netbeans.modules.javascript2.editor.parser.JsonParserResult; import org.netbeans.modules.javascript2.lexer.api.JsTokenId; import org.netbeans.modules.javascript2.lexer.api.LexUtilities; @@ -84,6 +85,20 @@ public void cancel() { cancelled.set(true); } + @Override + public boolean isKeepMarks() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.ON_OFF, true); + } + @NonNull public static Set calculateOccurances( @NonNull final ParserResult result, diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/OccurrencesFinderImpl.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/OccurrencesFinderImpl.java index 512db9486ea3..12546a4a53c7 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/OccurrencesFinderImpl.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/navigation/OccurrencesFinderImpl.java @@ -30,6 +30,7 @@ import org.netbeans.modules.csl.api.Modifier; import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.OffsetRange; +import org.netbeans.modules.javascript2.editor.options.ui.MarkOccurencesSettings; import org.netbeans.modules.javascript2.model.api.JsElement.Kind; import org.netbeans.modules.javascript2.model.api.JsObject; import org.netbeans.modules.javascript2.model.api.JsReference; @@ -100,6 +101,20 @@ public void cancel() { cancelled = true; } + @Override + public boolean isKeepMarks() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.KEEP_MARKS, true); + } + + @Override + public boolean isMarkOccurrencesEnabled() { + return MarkOccurencesSettings + .getCurrentNode() + .getBoolean(MarkOccurencesSettings.ON_OFF, true); + } + private static List findMemberUsage(JsObject object, String fqnType, String property, int offset, Set processedObjects) { List result = new ArrayList<>(); if (ModelUtils.wasProcessed(object, processedObjects)) { diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/Bundle.properties b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/Bundle.properties index 7559654a7163..0b9ec6b71887 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/Bundle.properties +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/Bundle.properties @@ -27,3 +27,10 @@ CodeCompletionPanel.autoCompletionFullRadioButton.text=&All Possible Situations CodeCompletionPanel.enableAutocompletionLabel.text=&Enable Auto Popup Completion Window for: CodeCompletionPanel.autoCompletionAfterDotCheckBox.text=&After "." CodeCompletionPanel.codeCompletionSignatureWidthLabel.text=Code Completion Item Signature Char &Width: + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for Javascript Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=Javascript Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesOptionsPanelController.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..90d15a5abf96 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.javascript2.editor.options.ui; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.js.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.form b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.form new file mode 100644 index 000000000000..2028b51f4128 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java new file mode 100644 index 000000000000..25cec8c13fa6 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java @@ -0,0 +1,196 @@ +/* + * 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.javascript2.editor.options.ui; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.util.Exceptions; + +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + keepMarksCheckBox.setMnemonic('s'); + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesSettings.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesSettings.java new file mode 100644 index 000000000000..0298af7d2498 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesSettings.java @@ -0,0 +1,42 @@ +/* + * 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.javascript2.editor.options.ui; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node("js").node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/Bundle.properties b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/Bundle.properties index fa96553a35fb..c305a3ce2a81 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/Bundle.properties +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/Bundle.properties @@ -19,3 +19,10 @@ CodeCompletionPanel.AccessibleContext.accessibleDescription=Panel for JSON code CodeCompletionPanel.AccessibleContext.accessibleName=JSON Code Completion Configuration Panel CodeCompletionPanel.autoCompletionSmartQuotesCheckBox.text=Use Sma&rt Quotes (" and ') Completion (after text selection, etc.) CodeCompletionPanel.autoCompletionSmartQuotesLabel.text=&Quotes Completion: + +CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret +ACSD_OnOff_CB=Checkbox switching mark occurrences on/off +MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for JSON Mark Occurrences +MarkOccurrencesPanel.AccessibleContext.accessibleName=JSON Mark Occurrences Panel +MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret +MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks \ No newline at end of file diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesOptionsPanelController.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesOptionsPanelController.java new file mode 100644 index 000000000000..67caf45a9ef2 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * 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.javascript2.editor.options.ui.json; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +public final class MarkOccurencesOptionsPanelController extends OptionsPanelController { + + private MarkOccurencesPanel panel; + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(this); + } + + @Override + public void applyChanges() { + getPanel().store(); + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return true; // Always valid + } + + @Override + public boolean isChanged() { + return getPanel().changed(); + } + + @Override + public HelpCtx getHelpCtx() { + return new HelpCtx("netbeans.optionsDialog.json.markoccurrences"); + } + + @Override + public synchronized JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public synchronized MarkOccurencesPanel getPanel() { + if (panel == null) { + panel = new MarkOccurencesPanel(this); + } + return panel; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.form b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.form new file mode 100644 index 000000000000..45d7edf3367c --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.form @@ -0,0 +1,102 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java new file mode 100644 index 000000000000..317cb2e50b40 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java @@ -0,0 +1,196 @@ +/* + * 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.javascript2.editor.options.ui.json; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.openide.util.Exceptions; + +public class MarkOccurencesPanel extends javax.swing.JPanel { + + private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on + private List boxes; + private MarkOccurencesOptionsPanelController controller; + + /* Creates new form MarkOccurencesPanel */ + public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { + initComponents(); + fillBoxes(); + addListeners(); + load(controller); + } + + public void load(MarkOccurencesOptionsPanelController controller) { + this.controller = controller; + + Preferences node = MarkOccurencesSettings.getCurrentNode(); + + for (JCheckBox box : boxes) { + box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); + } + + componentsSetEnabled(); + + } + + public void store() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (javax.swing.JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), + DEFAULT_VALUE); + + if (value != original) { + node.putBoolean(box.getActionCommand(), value); + } + } + try { + node.flush(); + } catch (BackingStoreException ex) { + Exceptions.printStackTrace(ex); + } + } + + public boolean changed() { + Preferences node = MarkOccurencesSettings.getCurrentNode(); + for (JCheckBox box : boxes) { + boolean value = box.isSelected(); + boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); + if (value != original) { + return true; + } + } + return 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + onOffCheckBox = new javax.swing.JCheckBox(); + keepMarksCheckBox = new javax.swing.JCheckBox(); + + setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); + setFocusCycleRoot(true); + setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { + public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getDefaultComponent + + public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getFirstComponent + + public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ + return onOffCheckBox; + }//end getLastComponent + + public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentAfter + } + public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ + return onOffCheckBox;//end getComponentBefore + + }} + ); + setLayout(new java.awt.GridBagLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N + onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(onOffCheckBox, gridBagConstraints); + onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N + onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N + + keepMarksCheckBox.setMnemonic('s'); + org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 20, 8, 0); + add(keepMarksCheckBox, gridBagConstraints); + keepMarksCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox keepMarksCheckBox; + private javax.swing.JCheckBox onOffCheckBox; + // End of variables declaration//GEN-END:variables + // End of variables declaration + + private void fillBoxes() { + boxes = new ArrayList<>(); + boxes.add(onOffCheckBox); + boxes.add(keepMarksCheckBox); + onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); + keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); + } + + private void addListeners() { + ItemListener itemListener = new CheckItemListener(); + for (JCheckBox box : boxes) { + box.addItemListener(itemListener); + } + } + + private void componentsSetEnabled() { + for (int i = 1; i < boxes.size(); i++) { + boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes + } + } + + private class CheckItemListener implements ItemListener { + + @Override + public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == onOffCheckBox) { + componentsSetEnabled(); + } + controller.changed(); + } + + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesSettings.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesSettings.java new file mode 100644 index 000000000000..b90dfa5ed354 --- /dev/null +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesSettings.java @@ -0,0 +1,42 @@ +/* + * 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.javascript2.editor.options.ui.json; + +import java.util.prefs.Preferences; +import org.openide.util.NbPreferences; + +public final class MarkOccurencesSettings { + + private static final String MARK_OCCURENCES = "MarkOccurences"; // NOI18N + public static final String ON_OFF = "OnOff"; // NOI18N + public static final String KEEP_MARKS = "KeepMarks"; // NOI18N + + private MarkOccurencesSettings() { + } + + public static Preferences getCurrentNode() { + Preferences preferences = NbPreferences.forModule(MarkOccurencesOptionsPanelController.class); + return preferences.node("json").node(MARK_OCCURENCES).node(getCurrentProfileId()); + } + + private static String getCurrentProfileId() { + return "default"; // NOI18N + } + +} diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/resources/layer.xml b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/resources/layer.xml index dcfab8a8dbdc..bd9ca3eb6ed5 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/resources/layer.xml +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/resources/layer.xml @@ -359,6 +359,22 @@
+ + + + + + + + + + + + + + + +
From cb90b49abec3983874e9e5f74a0c6c32925b6436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 21 Sep 2025 17:56:14 +0200 Subject: [PATCH 4/5] Address review comments (to be squashed with 8816020) --- .../csl/editor/semantic/MarkOccurrencesHighlighter.java | 6 +++--- .../modules/php/editor/options/MarkOccurencesPanel.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java index a3889cf8e0f1..342c3871c9e9 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java @@ -126,7 +126,7 @@ public void run(ParserResult info, SchedulerEvent event) { } boolean updateHighlights = false; - if(seqs.isEmpty()) { + if (seqs.isEmpty()) { OccurrencesFinder finder = language.getOccurrencesFinder(); if (finder == null || !finder.isMarkOccurrencesEnabled() || !finder.isKeepMarks()) { updateHighlights = true; @@ -135,7 +135,7 @@ public void run(ParserResult info, SchedulerEvent event) { updateHighlights = true; } - if(updateHighlights) { + if (updateHighlights) { // Update both editor highlighs and sidebar marks layer.setColorings(seqs); OccurrencesMarkProvider.get(doc).setOccurrences(OccurrencesMarkProvider.createMarks(doc, bag, ES_COLOR, NbBundle.getMessage(MarkOccurrencesHighlighter.class, "LBL_ES_TOOLTIP"))); @@ -144,7 +144,7 @@ public void run(ParserResult info, SchedulerEvent event) { SpiSupportAccessor.getInstance().removeCancelSupport(cancel); } } - + @NonNull List processImpl(ParserResult info, Document doc, int caretPosition) { OccurrencesFinder finder = language.getOccurrencesFinder(); diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java b/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java index 55f39f2f3ca3..598667216bbc 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/options/MarkOccurencesPanel.java @@ -26,13 +26,14 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; /** * * @author Petr Hrebejk */ -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes; From 87105248fa29e0d2d175df298cb738d909e43100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 21 Sep 2025 18:06:00 +0200 Subject: [PATCH 5/5] Address review comments (to be squashed with 5f76b96) --- .../modules/groovy/editor/options/MarkOccurencesPanel.java | 3 ++- .../modules/css/editor/options/MarkOccurencesPanel.java | 3 ++- .../modules/languages/antlr/v3/MarkOccurencesPanel.java | 3 ++- .../modules/languages/antlr/v4/MarkOccurencesPanel.java | 7 ++----- .../javascript2/editor/options/ui/MarkOccurencesPanel.java | 3 ++- .../editor/options/ui/json/MarkOccurencesPanel.java | 3 ++- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java index 662606999f0b..00208926fecf 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/options/MarkOccurencesPanel.java @@ -26,9 +26,10 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes; diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java index ee773eb01ae5..4e00643cb8ff 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/options/MarkOccurencesPanel.java @@ -26,9 +26,10 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes; diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java index 7358e774e5ec..6318992d51d2 100644 --- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v3/MarkOccurencesPanel.java @@ -26,9 +26,10 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes; diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java index c66f2a071a14..0c2df883f572 100644 --- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java +++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/MarkOccurencesPanel.java @@ -26,13 +26,10 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; -/** - * - * @author Petr Hrebejk - */ -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes; diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java index 25cec8c13fa6..f3abf9270ba8 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/MarkOccurencesPanel.java @@ -26,9 +26,10 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes; diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java index 317cb2e50b40..036740e872b5 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/options/ui/json/MarkOccurencesPanel.java @@ -26,9 +26,10 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.swing.JCheckBox; +import javax.swing.JPanel; import org.openide.util.Exceptions; -public class MarkOccurencesPanel extends javax.swing.JPanel { +public class MarkOccurencesPanel extends JPanel { private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on private List boxes;