Search in sources :

Example 1 with NetworkSearchTaskFactory

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();
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) AbstractNetworkSearchTaskFactory(org.cytoscape.application.swing.search.AbstractNetworkSearchTaskFactory) NetworkSearchTaskFactory(org.cytoscape.application.swing.search.NetworkSearchTaskFactory) DocumentEvent(javax.swing.event.DocumentEvent)

Example 2 with NetworkSearchTaskFactory

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());
}
Also used : NetworkSearchTaskFactory(org.cytoscape.application.swing.search.NetworkSearchTaskFactory)

Example 3 with NetworkSearchTaskFactory

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);
}
Also used : ImageIcon(javax.swing.ImageIcon) NetworkSearchTaskFactory(org.cytoscape.application.swing.search.NetworkSearchTaskFactory) RandomImage(org.cytoscape.internal.util.RandomImage) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon)

Example 4 with NetworkSearchTaskFactory

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);
    }
}
Also used : NetworkSearchTaskFactory(org.cytoscape.application.swing.search.NetworkSearchTaskFactory)

Example 5 with NetworkSearchTaskFactory

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());
}
Also used : NetworkSearchTaskFactory(org.cytoscape.application.swing.search.NetworkSearchTaskFactory) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon)

Aggregations

NetworkSearchTaskFactory (org.cytoscape.application.swing.search.NetworkSearchTaskFactory)6 Icon (javax.swing.Icon)2 ImageIcon (javax.swing.ImageIcon)2 AbstractNetworkSearchTaskFactory (org.cytoscape.application.swing.search.AbstractNetworkSearchTaskFactory)2 DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 RandomImage (org.cytoscape.internal.util.RandomImage)1 TaskObserver (org.cytoscape.work.TaskObserver)1 DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)1