Search in sources :

Example 11 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterReader method read.

/**
 *  Construct the filter objects based on the string representation of each filter.
 */
public Collection<CompositeFilter> read(final InputStream in) {
    final Collection<CompositeFilter> filters = new LinkedHashSet<CompositeFilter>();
    final InputStreamReader reader = new InputStreamReader(in);
    try {
        final BufferedReader br = new BufferedReader(reader);
        String oneLine = br.readLine();
        if (oneLine == null)
            return null;
        double filterVersion = 0.0;
        if (oneLine.trim().startsWith("FilterVersion")) {
            String versionStr = oneLine.trim().substring(14);
            filterVersion = Double.valueOf(versionStr);
        }
        // Ignore filters from the old version
        if (filterVersion < 0.2)
            return null;
        while (oneLine != null) {
            // ignore comment, empty line or the version line
            if (oneLine.startsWith("#") || oneLine.trim().equals("") || oneLine.startsWith("FilterVersion")) {
                oneLine = br.readLine();
                continue;
            }
            if (oneLine.trim().startsWith("<Composite>") || oneLine.trim().startsWith("<TopologyFilter>") || oneLine.trim().startsWith("<InteractionFilter>")) {
                List<String> filterStrVect = new ArrayList<String>();
                filterStrVect.add(oneLine);
                while ((oneLine = br.readLine()) != null) {
                    filterStrVect.add(oneLine);
                    if (oneLine.trim().startsWith("</Composite>") || oneLine.trim().startsWith("</TopologyFilter>") || oneLine.trim().startsWith("</InteractionFilter>")) {
                        break;
                    }
                }
                CompositeFilter aFilter = getFilterFromStrList(filterStrVect, filters);
                if (aFilter != null && !FilterUtil.isFilterNameDuplicated(filters, aFilter.getName())) {
                    filters.add(aFilter);
                }
            }
            oneLine = br.readLine();
        }
    } catch (Exception ex) {
        logger.error("Filter Read error", ex);
    }
    return filters;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterSettingPanel method addNewWidget.

public void addNewWidget(Object pObj) {
    // It can be either (1) a string with prefix "node."/"edge." (2) a CompositeFilter object
    if (pObj instanceof CompositeFilter) {
        if (pObj == theFilter) {
            // Ignore if try to add self
            return;
        }
        CompositeFilter theCompositeFilter = (CompositeFilter) pObj;
        addWidgetRow(theCompositeFilter, theFilter.getChildren().size() * 2);
        // Update theFilter object
        theFilter.addChild(theCompositeFilter, new Boolean(false));
        // determine the filter selection type
        if (theCompositeFilter.getAdvancedSetting().isNodeChecked()) {
            theFilter.getAdvancedSetting().setNode(true);
        }
        if (theCompositeFilter.getAdvancedSetting().isEdgeChecked()) {
            theFilter.getAdvancedSetting().setEdge(true);
        }
    } else {
        // (pObj instanceof String)
        String tmpObj = (String) pObj;
        String ctrlAttribute = tmpObj.substring(5);
        int indexType = QuickFind.INDEX_NODES;
        if (tmpObj.startsWith("edge.")) {
            indexType = QuickFind.INDEX_EDGES;
            // determine the filter selection type
            theFilter.getAdvancedSetting().setEdge(true);
        } else {
            theFilter.getAdvancedSetting().setNode(true);
        }
        AtomicFilter newChildFilter = getAtomicFilterFromStr(ctrlAttribute, indexType);
        addWidgetRow(newChildFilter, theFilter.getChildren().size() * 2);
        // Update theFilter object
        theFilter.addChild(newChildFilter);
    }
    // Update selection type of the filter setting
    updateSelectionType();
    // Update the selection on screen
    doSelection();
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) AtomicFilter(org.cytoscape.filter.internal.filters.model.AtomicFilter)

Example 13 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterApp method handleEvent.

@Override
public void handleEvent(SessionAboutToBeSavedEvent e) {
    Vector<CompositeFilter> allFilters = modelLocator.getFilters();
    List<CompositeFilter> saveList = new ArrayList<CompositeFilter>();
    for (CompositeFilter cf : allFilters) {
        if (cf.getAdvancedSetting().isSessionChecked())
            saveList.add(cf);
    }
    if (!saveList.isEmpty()) {
        try {
            // Create an empty file on system temp directory
            File tmpFile = new File(System.getProperty("java.io.tmpdir"), FilterUtil.SESSION_FILE_NAME);
            tmpFile.deleteOnExit();
            // Write to the file
            writer.write(saveList, tmpFile);
            // Add it to the apps list
            List<File> fileList = new ArrayList<File>();
            fileList.add(tmpFile);
            e.addAppFiles(FilterUtil.FILTER_APP_NAME, fileList);
        } catch (Exception ex) {
            logger.error("Error adding filter files to be saved in the session.", ex);
        }
    }
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException)

Example 14 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterApp method handleEvent.

@Override
public void handleEvent(SessionLoadedEvent e) {
    // Remove current session-only filters
    List<CompositeFilter> removeList = new ArrayList<CompositeFilter>();
    Set<String> globalNames = new HashSet<String>();
    for (CompositeFilter cf : modelLocator.getFilters()) {
        if (!cf.getAdvancedSetting().isGlobalChecked())
            removeList.add(cf);
        else
            globalNames.add(cf.getName());
    }
    modelLocator.removeFilters(removeList);
    // Add new session filters
    Collection<CompositeFilter> addList = null;
    CySession sess = e.getLoadedSession();
    if (sess != null) {
        Map<String, List<File>> filesMap = sess.getAppFileListMap();
        if (filesMap != null) {
            List<File> files = filesMap.get(FilterUtil.FILTER_APP_NAME);
            if (// Try the old (2.x) name
            files == null)
                files = filesMap.get("FilterPlugin");
            if (files != null) {
                for (File f : files) {
                    if (f.getName().endsWith(FilterUtil.SESSION_FILE_NAME)) {
                        // There should be only one file!
                        addList = reader.read(f);
                        break;
                    }
                }
                if (addList != null) {
                    // TODO: Do not add session filters that have the same name of current global filters?
                    Iterator<CompositeFilter> iter = addList.iterator();
                    while (iter.hasNext()) {
                        if (globalNames.contains(iter.next().getName()))
                            iter.remove();
                    }
                }
            }
        }
    }
    if (addList != null)
        modelLocator.addFilters(addList);
}
Also used : CySession(org.cytoscape.session.CySession) CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 15 with CompositeFilter

use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.

the class FilterMainPanel method handleNetworkFocused.

private void handleNetworkFocused(final CyNetwork net) {
    if (net == null)
        return;
    handleAttributesChanged();
    // Refresh indices for UI widgets after network switch
    CompositeFilter selectedFilter = (CompositeFilter) cmbFilters.getSelectedItem();
    if (selectedFilter != null) {
        selectedFilter.setNetwork(net);
        FilterSettingPanel theSettingPanel = filter2SettingPanelMap.get(selectedFilter);
        if (theSettingPanel != null) {
            theSettingPanel.refreshIndicesForWidgets();
            updateFeedbackTableModel();
        }
    }
}
Also used : CompositeFilter(org.cytoscape.filter.internal.filters.model.CompositeFilter)

Aggregations

CompositeFilter (org.cytoscape.filter.internal.filters.model.CompositeFilter)25 ArrayList (java.util.ArrayList)5 File (java.io.File)4 IOException (java.io.IOException)4 LinkedHashSet (java.util.LinkedHashSet)4 Vector (java.util.Vector)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)3 EdgeInteractionFilter (org.cytoscape.filter.internal.filters.model.EdgeInteractionFilter)3 NodeInteractionFilter (org.cytoscape.filter.internal.filters.model.NodeInteractionFilter)3 TopologyFilter (org.cytoscape.filter.internal.filters.model.TopologyFilter)3 CyNetwork (org.cytoscape.model.CyNetwork)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 AdvancedSetting (org.cytoscape.filter.internal.filters.model.AdvancedSetting)2 AtomicFilter (org.cytoscape.filter.internal.filters.model.AtomicFilter)2 CyFilter (org.cytoscape.filter.internal.filters.model.CyFilter)2 InteractionFilter (org.cytoscape.filter.internal.filters.model.InteractionFilter)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1