use of org.cytoscape.application.swing.search.NetworkSearchTaskFactory in project cytoscape-impl by cytoscape.
the class NetworkSearchMediator method addListeners.
/**
* Add listeners to UI components.
*/
private void addListeners() {
networkSearchBar.addPropertyChangeListener("selectedProvider", evt -> {
NetworkSearchTaskFactory tf = (NetworkSearchTaskFactory) evt.getNewValue();
if (tf != null)
updateSelectedProvider(tf);
updateSelectedSearchComponent(tf);
networkSearchBar.updateProvidersButton();
networkSearchBar.updateSearchEnabled();
});
networkSearchBar.getSearchTextField().getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
updateSelectedProvider(networkSearchBar.getSelectedProvider());
networkSearchBar.updateSearchButton();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateSelectedProvider(networkSearchBar.getSelectedProvider());
networkSearchBar.updateSearchButton();
}
@Override
public void changedUpdate(DocumentEvent e) {
// Nothing to do here...
}
});
networkSearchBar.getSearchTextField().addActionListener(evt -> {
runSearch();
});
networkSearchBar.getOptionsButton().addActionListener(evt -> {
if (networkSearchBar.getSelectedProvider() != null && networkSearchBar.getOptionsButton().isSelected())
networkSearchBar.showOptionsDialog(optionsComponents.get(networkSearchBar.getSelectedProvider()));
});
networkSearchBar.getSearchButton().addActionListener(evt -> {
runSearch();
});
}
use of org.cytoscape.application.swing.search.NetworkSearchTaskFactory in project cytoscape-impl by cytoscape.
the class NetworkSearchBar method updateSearchButton.
void updateSearchButton() {
NetworkSearchTaskFactory tf = getSelectedProvider();
getSearchButton().setEnabled(tf != null && tf.isReady());
}
use of org.cytoscape.application.swing.search.NetworkSearchTaskFactory 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);
}
use of org.cytoscape.application.swing.search.NetworkSearchTaskFactory in project cytoscape-impl by cytoscape.
the class NetworkSearchBar method setSelectedProvider.
public void setSelectedProvider(NetworkSearchTaskFactory newValue) {
if (newValue != selectedProvider) {
// Get the actual "current" provider
NetworkSearchTaskFactory oldValue = getSelectedProvider();
selectedProvider = newValue;
// Save the last selected provider now, so it can be selected by default when Cytoscape restarts
setDefaultProvider(newValue);
if (newValue != oldValue)
firePropertyChange("selectedProvider", oldValue, newValue);
}
}
use of org.cytoscape.application.swing.search.NetworkSearchTaskFactory in project cytoscape-impl by cytoscape.
the class NetworkSearchBar method updateProvidersButton.
void updateProvidersButton() {
NetworkSearchTaskFactory currentProvider = getSelectedProvider();
if (currentProvider != null) {
Icon icon = providerIcons.get(currentProvider);
getProvidersButton().setIcon(icon != null ? icon : emptyIcon);
getProvidersButton().setToolTipText(currentProvider.getName());
} else {
getProvidersButton().setIcon(emptyIcon);
getProvidersButton().setToolTipText("Please select a search provider...");
}
getProvidersButton().setEnabled(!providers.isEmpty());
getProviderSelectorButton().setEnabled(!providers.isEmpty());
}
Aggregations