use of org.cytoscape.internal.util.RandomImage in project cytoscape-impl by cytoscape.
the class NetworkSearchBar method update.
void update(Collection<NetworkSearchTaskFactory> newProviders) {
NetworkSearchTaskFactory oldSelected = getSelectedProvider();
providers.clear();
providerIcons.clear();
if (newProviders != null) {
providers.addAll(newProviders);
newProviders.forEach(p -> {
Icon icon = p.getIcon();
if (icon instanceof ImageIcon) {
ImageIcon ii = (ImageIcon) icon;
if (ii.getIconWidth() > ICON_SIZE || ii.getIconHeight() > ICON_SIZE)
icon = new ImageIcon(ii.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_SMOOTH));
}
providerIcons.put(p, icon != null ? icon : new ImageIcon(new RandomImage(ICON_SIZE, ICON_SIZE)));
});
}
if (selectedProvider != null && !newProviders.contains(selectedProvider))
selectedProvider = null;
// We are not changing the selectedProvider field here (only the user should do it),
// but still need to let the widget know that the actual "current" provider has changed.
// This is done this way to prevent a core provider from preventing another preferred one
// (from third-party apps) from being pre-selected when Cytoscape restarts,
// since the preferred one is auto-selected only when the user has not selected another provider yet.
NetworkSearchTaskFactory newSelected = getSelectedProvider();
if (newSelected != oldSelected)
firePropertyChange("selectedProvider", oldSelected, newSelected);
}
Aggregations