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;
}
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();
}
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);
}
}
}
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);
}
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();
}
}
}
Aggregations