use of org.cytoscape.filter.internal.filters.model.StringFilter in project cytoscape-impl by cytoscape.
the class ApplyFilterThread method passAtomicFilter.
private boolean passAtomicFilter(CyNetwork network, Object pObject, AtomicFilter pAtomicFilter) {
CyRow data = null;
if (pObject instanceof CyNode) {
CyNode node = (CyNode) pObject;
data = network.getRow(node);
} else {
CyEdge edge = (CyEdge) pObject;
data = network.getRow(edge);
}
if (pAtomicFilter instanceof StringFilter) {
StringFilter theStringFilter = (StringFilter) pAtomicFilter;
String value = data.get(theStringFilter.getControllingAttribute().substring(5), String.class);
if (value == null) {
return false;
}
if (theStringFilter == null) {
return false;
}
if (theStringFilter.getSearchStr() == null) {
return false;
}
String[] pattern = theStringFilter.getSearchStr().split("\\s");
for (int p = 0; p < pattern.length; ++p) {
if (!Strings.isLike(value, pattern[p], 0, true)) {
// this is an OR function
return false;
}
}
} else if (pAtomicFilter instanceof NumericFilter) {
NumericFilter theNumericFilter = (NumericFilter) pAtomicFilter;
Number value;
if (data.getTable().getColumn(theNumericFilter.getControllingAttribute().substring(5)).getType() == Double.class)
value = data.get(theNumericFilter.getControllingAttribute().substring(5), Double.class);
else
value = data.get(theNumericFilter.getControllingAttribute().substring(5), Integer.class);
if (value == null) {
return false;
}
Double lowValue = (Double) theNumericFilter.getLowBound();
Double highValue = (Double) theNumericFilter.getHighBound();
// To correct the boundary values for lowValue and highValue
if (lowValue.doubleValue() > 0.0) {
lowValue = lowValue * 0.99999;
} else {
lowValue = lowValue * 1.00001;
}
if (highValue.doubleValue() > 0.0) {
highValue = highValue * 1.00001;
} else {
highValue = highValue * 0.99999;
}
// if (!(value.doubleValue() >= lowValue.doubleValue() && value.doubleValue()<= highValue.doubleValue())) {
if (!((Double.compare(value.doubleValue(), lowValue.doubleValue()) >= 0) && (Double.compare(value.doubleValue(), highValue.doubleValue())) <= 0)) {
return false;
}
}
return true;
}
use of org.cytoscape.filter.internal.filters.model.StringFilter in project cytoscape-impl by cytoscape.
the class FilterSettingPanel method refreshIndicesForWidgets.
// Refresh indices for widget after network switch or Cytoscape.ATTRIBUTES_CHANGED event is received
// The method may be triggered by event of NETWORK_VIEW_FOCUSED
public void refreshIndicesForWidgets() {
// Check if each widget has associatd index, if not, try to create one
// System.out.println("FilterSettingpanel:refreshIndicesForWidgets()...\n");
List<CyFilter> children = theFilter.getChildren();
if ((children == null) || (children.size() == 0)) {
return;
}
CyNetwork network = applicationManager.getCurrentNetwork();
for (int i = 0; i < children.size(); i++) {
CyFilter child = children.get(i);
if (child instanceof StringFilter) {
if (pnlCustomSettings.getComponent(i * 5 + 3) instanceof TextIndexComboBox) {
TextIndexComboBox theBox = (TextIndexComboBox) pnlCustomSettings.getComponent(i * 5 + 3);
if (network != null) {
CyNetworkView networkView = applicationManager.getCurrentNetworkView();
if (networkView != null) {
TextIndex textIndex = createTextIndex((StringFilter) child);
;
if (textIndex != null) {
theBox.setTextIndex(textIndex);
StringFilter aFilter = (StringFilter) child;
aFilter.setIndex(textIndex);
}
}
}
}
}
if (child instanceof NumericFilter) {
if (pnlCustomSettings.getComponent(i * 5 + 3) instanceof JRangeSliderExtended) {
JRangeSliderExtended theSlider = (JRangeSliderExtended) pnlCustomSettings.getComponent(i * 5 + 3);
if (network != null) {
CyNetworkView networkView = applicationManager.getCurrentNetworkView();
if (networkView != null) {
NumberIndex numIndex = createNumberIndex((NumericFilter) child);
;
if (numIndex != null) {
NumberRangeModel rangeModel = (NumberRangeModel) theSlider.getModel();
rangeModel.setMinValue(numIndex.getMinimumValue());
rangeModel.setMaxValue(numIndex.getMaximumValue());
NumericFilter aFilter = (NumericFilter) child;
aFilter.setIndex(numIndex);
}
}
}
}
}
}
}
use of org.cytoscape.filter.internal.filters.model.StringFilter in project cytoscape-impl by cytoscape.
the class FilterSettingPanel method getAtomicFilterFromStr.
private AtomicFilter getAtomicFilterFromStr(String pCtrlAttribute, int pIndexType) {
AtomicFilter retFilter = null;
// quickFind.addNetwork(cyNetwork, new TaskMonitorBase());
// index_by_UniqueIdentification = (TextIndex) quickFind.getIndex(cyNetwork);
CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
quickFind.reindexNetwork(cyNetwork, pIndexType, pCtrlAttribute, new TaskMonitorBase());
Class<?> attributeType = null;
if (pIndexType == QuickFind.INDEX_NODES) {
if (cyNetwork.getNodeCount() > 0) {
attributeType = cyNetwork.getDefaultNodeTable().getColumn(pCtrlAttribute).getType();
}
} else if (pIndexType == QuickFind.INDEX_EDGES) {
if (cyNetwork.getEdgeCount() > 0) {
attributeType = cyNetwork.getDefaultEdgeTable().getColumn(pCtrlAttribute).getType();
}
}
if ((attributeType == Integer.class) || (attributeType == Double.class)) {
retFilter = new NumericFilter(quickFind);
retFilter.setControllingAttribute(pCtrlAttribute);
retFilter.setIndexType(pIndexType);
// NumberIndex index_by_thisAttr = (NumberIndex) quickFind.getIndex(Cytoscape.getCurrentNetwork());
retFilter.setIndex(quickFind.getIndex(cyNetwork));
} else if ((attributeType == String.class || (attributeType == List.class || (attributeType == Boolean.class)))) {
retFilter = new StringFilter(quickFind);
retFilter.setControllingAttribute(pCtrlAttribute);
retFilter.setIndexType(pIndexType);
// TextIndex index_by_thisAttr = (TextIndex) quickFind.getIndex(Cytoscape.getCurrentNetwork());
retFilter.setIndex(quickFind.getIndex(cyNetwork));
} else {
logger.error("AttributeType is not numeric/string/list/boolean.");
}
if (retFilter != null) {
retFilter.setNetwork(cyNetwork);
}
return retFilter;
}
use of org.cytoscape.filter.internal.filters.model.StringFilter in project cytoscape-impl by cytoscape.
the class FilterSettingPanel method addWidgetRow.
private void addWidgetRow(CyFilter pFilter, int pGridY) {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
if (pGridY > 0) {
// add a row to indicate the relationship between the widgets
String relationStr = "AND";
if (theFilter.getAdvancedSetting().getRelation() == Relation.OR) {
relationStr = "OR";
}
// Col 2 ---> Label to indicate relationship between widgets
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = pGridY - 1;
JLabel lbRelation = new JLabel(relationStr);
lbRelation.setName("RelationLabel");
pnlCustomSettings.add(lbRelation, gridBagConstraints);
}
// Col 0 -- label with attributeName/Filter
JLabel theLabel_col0 = new JLabel();
if (pFilter instanceof AtomicFilter) {
AtomicFilter atomicFilter = (AtomicFilter) pFilter;
theLabel_col0.setText(atomicFilter.getControllingAttribute());
} else {
theLabel_col0.setText("Filter");
}
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridy = pGridY;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
// gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
pnlCustomSettings.add(theLabel_col0, gridBagConstraints);
// Col 1 ---> chk box -- NOT
final JCheckBox chkNot = new JCheckBox("Not");
chkNot.setName(Integer.toString(pGridY));
chkNot.setSelected(pFilter.getNegation());
chkNot.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateNegationStatus(chkNot);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridy = pGridY;
// gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
pnlCustomSettings.add(chkNot, gridBagConstraints);
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
// Col 2 ---> Widget if atomicFilter
if (pFilter instanceof StringFilter) {
JComboBox aBox = getTextIndexComboBox((StringFilter) pFilter);
pnlCustomSettings.add(aBox, gridBagConstraints);
} else if (pFilter instanceof NumericFilter) {
JRangeSliderExtended theSlider = getRangerSlider((NumericFilter) pFilter);
pnlCustomSettings.add(theSlider, gridBagConstraints);
} else {
// CompositeFilter
gridBagConstraints.fill = java.awt.GridBagConstraints.NONE;
// gridBagConstraints.weightx = 0.0;
// gridBagConstraints.anchor = java.awt.GridBagConstraints.
pnlCustomSettings.add(new JLabel(pFilter.getName()), gridBagConstraints);
}
gridBagConstraints.weightx = 0.0;
// Col 3 ---> label (a trash can) for delete of the row
JLabel theDelLabel = new JLabel();
theDelLabel.setIcon(delIcon);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridy = pGridY;
// gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
pnlCustomSettings.add(theDelLabel, gridBagConstraints);
theDelLabel.setName(Integer.toString(pGridY));
theDelLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
removeFilterWidget(e);
}
});
this.validate();
}
use of org.cytoscape.filter.internal.filters.model.StringFilter in project cytoscape-impl by cytoscape.
the class FilterReader method getFilterFromStrList.
private CompositeFilter getFilterFromStrList(List<String> strList, Collection<CompositeFilter> filters) {
boolean isTopologyFilter = false;
boolean isInteractionFilter = false;
if (strList.get(0).startsWith("<TopologyFilter>")) {
isTopologyFilter = true;
}
if (strList.get(0).startsWith("<InteractionFilter>")) {
isInteractionFilter = true;
}
List<String> advSettingStrVect = new ArrayList<String>();
List<String> filterStrVect = new ArrayList<String>();
// Seperate AdvancedSetting from the rest
int startIndex = -1, endIndex = -1;
String line = null;
for (int i = 0; i < strList.size(); i++) {
line = strList.get(i);
if (line.startsWith("<AdvancedSetting>")) {
startIndex = i;
}
if (line.startsWith("</AdvancedSetting>")) {
endIndex = i;
break;
}
}
advSettingStrVect.addAll(strList.subList(startIndex + 1, endIndex));
filterStrVect.addAll(strList.subList(1, startIndex));
filterStrVect.addAll(strList.subList(endIndex + 1, strList.size()));
CompositeFilter retFilter = new CompositeFilter(ServicesUtil.cyApplicationManagerServiceRef);
retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
if (isTopologyFilter) {
retFilter = new TopologyFilter(ServicesUtil.cyApplicationManagerServiceRef);
retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
getTopologyFilterFromStr((TopologyFilter) retFilter, filterStrVect, filters);
return retFilter;
}
if (isInteractionFilter) {
AdvancedSetting advSetting = getAdvancedSettingFromStr(advSettingStrVect);
if (advSetting.isNodeChecked()) {
retFilter = new NodeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
} else {
// advSetting.isEdgeChecked() == true
retFilter = new EdgeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
}
retFilter.setAdvancedSetting(advSetting);
getInteractionFilterFromStr((InteractionFilter) retFilter, filterStrVect, filters);
return retFilter;
}
Collection<CompositeFilter> allFilters = new LinkedHashSet<CompositeFilter>();
for (int i = 0; i < filterStrVect.size(); i++) {
line = filterStrVect.get(i);
if (line.startsWith("name=")) {
String name = line.substring(5);
retFilter.setName(name);
}
if (line.startsWith("Negation=true")) {
retFilter.setNegation(true);
}
if (line.startsWith("Negation=false")) {
retFilter.setNegation(false);
}
if (line.startsWith("StringFilter=")) {
String _stringFilterValue = line.substring(13);
String[] _values = _stringFilterValue.split(":");
// controllingAttribute+":" + negation+ ":"+searchStr+":"+index_type;
StringFilter _strFilter = new StringFilter(quickFind);
_strFilter.setParent(retFilter);
_strFilter.setControllingAttribute(_values[0]);
_strFilter.setNegation((new Boolean(_values[1])).booleanValue());
// handle the case where ':' is part of the search string
String _searchStr = _stringFilterValue.substring(_values[0].length() + _values[1].length() + 2, _stringFilterValue.length() - _values[_values.length - 1].length() - 1);
_strFilter.setSearchStr(_searchStr);
_strFilter.setIndexType((new Integer(_values[_values.length - 1])).intValue());
retFilter.addChild(_strFilter);
}
if (line.startsWith("NumericFilter=")) {
String[] _values = line.substring(14).split(":");
// controllingAttribute + ":" + negation+ ":"+lowBound+":" +
// highBound+ ":"+index_type;
// Determine data type of the attribute
String dataType = "int";
if (_values[2].indexOf(".") >= 0 || _values[2].indexOf("E") >= 0 || _values[3].indexOf(".") >= 0 || _values[3].indexOf("E") >= 0) {
dataType = "double";
}
if (dataType.equalsIgnoreCase("double")) {
NumericFilter<Double> _numFilter = new NumericFilter<Double>(quickFind);
_numFilter.setParent(retFilter);
_numFilter.setControllingAttribute(_values[0]);
_numFilter.setNegation((new Boolean(_values[1])).booleanValue());
_numFilter.setLowBound(Double.valueOf(_values[2]));
_numFilter.setHighBound(Double.valueOf(_values[3]));
_numFilter.setIndexType((new Integer(_values[4])).intValue());
retFilter.addChild(_numFilter);
} else {
// dataType = "int"
NumericFilter<Integer> _numFilter = new NumericFilter<Integer>(quickFind);
_numFilter.setParent(retFilter);
_numFilter.setControllingAttribute(_values[0]);
_numFilter.setNegation((new Boolean(_values[1])).booleanValue());
_numFilter.setLowBound(Integer.valueOf(_values[2]));
_numFilter.setHighBound(Integer.valueOf(_values[3]));
_numFilter.setIndexType((new Integer(_values[4])).intValue());
retFilter.addChild(_numFilter);
}
}
if (line.startsWith("CompositeFilter=")) {
// e.g. CompositeFilter=AAA:true
String[] _values = line.substring(16).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference CompositeFilter
CompositeFilter cmpFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
cmpFilter = cf;
break;
}
}
if (cmpFilter != null) {
retFilter.addChild(cmpFilter, (new Boolean(notValue)).booleanValue());
}
}
if (line.startsWith("TopologyFilter=")) {
// e.g. TopologyFilter=AAA:true
String[] _values = line.substring(15).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference TopologyFilter
TopologyFilter topoFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
topoFilter = (TopologyFilter) cf;
break;
}
}
if (topoFilter != null) {
retFilter.addChild(topoFilter, (new Boolean(notValue)).booleanValue());
}
}
if (line.startsWith("InteractionFilter=")) {
// e.g. InteractionFilter=AAA:true
String[] _values = line.substring(15).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference InteractionFilter
InteractionFilter interactionFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
interactionFilter = (InteractionFilter) cf;
break;
}
}
if (interactionFilter != null) {
retFilter.addChild(interactionFilter, (new Boolean(notValue)).booleanValue());
}
}
}
return retFilter;
}
Aggregations