--- a/api.search/apichanges.xml +++ a/api.search/apichanges.xml @@ -105,6 +105,27 @@ + + + Added method getIcon to class SearchScopeDefinition + + + + + +

+ Search scope can define an icon that will be shown in the + UI, usually in the combo box for search scope selection. +

+

+ To use a custom scope icon, override method + SearchScopeDefinition.getIcon(). +

+
+ + +
+ Added ReplacePattern and replace history to SearchHistory class --- a/api.search/manifest.mf +++ a/api.search/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.search OpenIDE-Module-Localizing-Bundle: org/netbeans/api/search/Bundle.properties -OpenIDE-Module-Specification-Version: 1.9 +OpenIDE-Module-Specification-Version: 1.10 --- a/api.search/src/org/netbeans/api/search/ui/ScopeController.java +++ a/api.search/src/org/netbeans/api/search/ui/ScopeController.java @@ -41,12 +41,16 @@ */ package org.netbeans.api.search.ui; +import java.awt.Component; import java.awt.Dialog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyListener; +import javax.swing.DefaultListCellRenderer; import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -84,6 +88,7 @@ this.extraSearchScopes = extraSearchScopes; component.addHierarchyListener(new ScopeComboBoxHierarchyListener()); component.setEditable(false); + component.setRenderer(new ScopeCellRenderer()); } private String chooseId() { @@ -294,4 +299,22 @@ active = false; } } + + private static class ScopeCellRenderer extends DefaultListCellRenderer { + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + Component component = super.getListCellRendererComponent( + list, value, index, isSelected, cellHasFocus); + if (component instanceof JLabel) { + JLabel label = (JLabel) component; + if (value instanceof ScopeItem) { + ScopeItem item = (ScopeItem) value; + label.setIcon(item.getSearchScope().getIcon()); + } + } + return component; + } + } }; --- a/api.search/src/org/netbeans/modules/search/SearchScopeBrowse.java +++ a/api.search/src/org/netbeans/modules/search/SearchScopeBrowse.java @@ -46,6 +46,8 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import javax.swing.Icon; +import javax.swing.UIManager; import org.netbeans.api.search.SearchRoot; import org.netbeans.api.search.SearchScopeOptions; import org.netbeans.api.search.provider.SearchInfo; @@ -59,6 +61,7 @@ import org.openide.filesystems.FileChooserBuilder; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; /** @@ -71,10 +74,23 @@ */ public class SearchScopeBrowse { + private static final String ICON_KEY_UIMANAGER_NB = + "Nb.Explorer.Folder.openedIcon"; //NOI18N + private static final Icon ICON; + private static FileObject[] roots = null; private SearchScopeDefinition browseScope = new BrowseScope(); private SearchScopeDefinition getLastScope = new GetLastScope(); + static { + Icon icon = UIManager.getIcon(ICON_KEY_UIMANAGER_NB); + if (icon == null) { + icon = ImageUtilities.loadImageIcon( + "org/openide/loaders/defaultFolder.gif", false); //NOI18N + } + ICON = icon; + } + /** * Search Scope with title "Browse..." that can open file chooser to get * search roots. @@ -123,6 +139,11 @@ chooseRoots(); notifyListeners(); } + + @Override + public Icon getIcon() { + return ICON; + } } /** @@ -164,6 +185,11 @@ @Override public void clean() { } + + @Override + public Icon getIcon() { + return ICON; + } } /** --- a/api.search/src/org/netbeans/spi/search/SearchScopeDefinition.java +++ a/api.search/src/org/netbeans/spi/search/SearchScopeDefinition.java @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.List; +import javax.swing.Icon; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.api.annotations.common.CheckForNull; @@ -170,4 +171,15 @@ */ public void selected() { } + + /** + * Get icon to show in the combo box. The default implementation returns + * null. + * + * @since api.search/1.10 + * @return The icon, or null. + */ + public @CheckForNull Icon getIcon() { + return null; + } } --- a/utilities.project/nbproject/project.xml +++ a/utilities.project/nbproject/project.xml @@ -63,7 +63,7 @@ - 1.0 + 1.10 --- a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeCurrentProject.java +++ a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeCurrentProject.java @@ -43,6 +43,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.swing.Icon; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; @@ -66,6 +67,7 @@ private PropertyChangeListener pcl; private boolean applicable = true; private String name = null; + private Icon icon; private Project project = null; public SearchScopeCurrentProject() { @@ -104,9 +106,11 @@ applicable = true; name = NbBundle.getMessage(SearchScopeCurrentProject.class, "SearchScopeCurrentProject", shortName(project)); //NOI18N + icon = ProjectUtils.getInformation(project).getIcon(); } else { applicable = false; name = ""; //NOI18N + icon = null; } notifyListeners(); } @@ -164,4 +168,9 @@ name = null; project = null; } + + @Override + public Icon getIcon() { + return icon; + } } --- a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeMainProject.java +++ a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeMainProject.java @@ -44,7 +44,10 @@ package org.netbeans.modules.search.project; +import javax.swing.Icon; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.api.search.provider.SearchInfo; import org.netbeans.api.search.provider.SearchInfoUtils; @@ -103,5 +106,16 @@ public int getPriority() { return 100; } - + + @Override + public Icon getIcon() { + Project p = OpenProjects.getDefault().getMainProject(); + if (p != null) { + ProjectInformation pi = ProjectUtils.getInformation(p); + if (pi != null) { + return pi.getIcon(); + } + } + return null; + } } --- a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeNodeSelection.java +++ a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeNodeSelection.java @@ -44,15 +44,21 @@ package org.netbeans.modules.search.project; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.beans.BeanInfo; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.swing.Icon; +import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.api.search.provider.SearchInfo; import org.netbeans.api.search.provider.SearchInfoUtils; import org.netbeans.spi.search.SearchScopeDefinition; import org.openide.nodes.Node; +import org.openide.util.ImageUtilities; import org.openide.util.Lookup; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; @@ -69,10 +75,23 @@ */ final class SearchScopeNodeSelection extends SearchScopeDefinition implements LookupListener { - + @StaticResource + private static final String MORE_ICON_ID = + "org/netbeans/modules/search/project/resources/more.png"; //NOI18N + + @StaticResource + private static final String MULTI_SELECTION_ID = + "org/netbeans/modules/search/project/resources/pages_qualifier.png"; //NOI18N + private static final Icon MULTI_SELECTION_ICON; + private final Lookup.Result lookupResult; private LookupListener lookupListener; + static { + MULTI_SELECTION_ICON = ImageUtilities.loadImageIcon( + MULTI_SELECTION_ID, false); + } + public SearchScopeNodeSelection() { Lookup lookup = Utilities.actionsGlobalContext(); lookupResult = lookup.lookupResult(Node.class); @@ -324,4 +343,22 @@ public void resultChanged(LookupEvent ev) { notifyListeners(); } + + @Override + public Icon getIcon() { + Node[] nodes = getNodes(); + if (nodes.length > 1) { + return MULTI_SELECTION_ICON; + } else if (nodes.length == 1 && nodes[0] != null) { + Node n = nodes[0]; + Image image = n.getIcon(BeanInfo.ICON_COLOR_16x16); + if (image != null) { + return ImageUtilities.image2Icon(image); + } else { + return null; + } + } else { + return null; + } + } } --- a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeOpenProjects.java +++ a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeOpenProjects.java @@ -44,10 +44,13 @@ package org.netbeans.modules.search.project; +import javax.swing.Icon; +import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.api.project.Project; import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.api.search.provider.SearchInfo; import org.netbeans.api.search.provider.SearchInfoUtils; +import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; /** @@ -56,7 +59,16 @@ * @author Marian Petras */ final class SearchScopeOpenProjects extends AbstractProjectSearchScope { - + + @StaticResource + private static final String ALL_PROJECTS_ICON = + "org/netbeans/modules/search/project/resources/all_projects.png"; //NOI18N + private static final Icon ICON; + + static { + ICON = ImageUtilities.loadImageIcon(ALL_PROJECTS_ICON, false); + } + SearchScopeOpenProjects() { super(OpenProjects.PROPERTY_OPEN_PROJECTS); } @@ -111,4 +123,9 @@ public int getPriority() { return 200; } + + @Override + public Icon getIcon() { + return ICON; + } }