Skip to content

Commit

Permalink
Merge pull request #461 from knime-ip/improveSegmentFilterDialog
Browse files Browse the repository at this point in the history
Improve segment filter dialog
  • Loading branch information
dietzc authored Apr 8, 2017
2 parents 89a276a + 14240b0 commit 3323da7
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.List;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
Expand Down Expand Up @@ -94,6 +95,12 @@ public class DialogComponentFilterSelection<L extends Comparable<L>> extends Dia

private final JPanel m_textFieldsPanel;

private final JCheckBox m_caseSensitiveMatch;

private final JCheckBox m_containsWildCards;

private final JCheckBox m_regularExpression;

private GridBagConstraints m_textFieldsGBC;

/**
Expand Down Expand Up @@ -130,6 +137,36 @@ public void actionPerformed(final ActionEvent e) {

m_operatorBox = new JComboBox(RulebasedLabelFilter.Operator.values());

m_caseSensitiveMatch = new JCheckBox("Case Sensitive Match");
m_caseSensitiveMatch.setEnabled(false);

m_containsWildCards = new JCheckBox("Contains Wild Cards");
m_containsWildCards.setEnabled(false);
m_containsWildCards.addChangeListener(new ChangeListener() {

@Override
public void stateChanged(final ChangeEvent e) {
if ((e.getSource() == m_containsWildCards) && m_containsWildCards.isSelected()) {
m_regularExpression.setSelected(false);
}
}
});

m_regularExpression = new JCheckBox("Regular Expression");
m_regularExpression.setEnabled(false);
m_regularExpression.addChangeListener(new ChangeListener() {

@Override
public void stateChanged(final ChangeEvent e) {
if ((e.getSource() == m_regularExpression) && m_regularExpression.isSelected()) {
m_containsWildCards.setSelected(false);
}
}
});

final JPanel ruleConfigurationPanel = new JPanel(new GridBagLayout());


getComponentPanel().setLayout(new GridBagLayout());

final GridBagConstraints dialogGBC = new GridBagConstraints();
Expand All @@ -138,9 +175,20 @@ public void actionPerformed(final ActionEvent e) {
dialogGBC.weighty = 1;
dialogGBC.gridx = 0;
dialogGBC.gridy = 0;
dialogGBC.insets = new Insets(2, 2, 2, 2);
dialogGBC.anchor = GridBagConstraints.NORTH;

ruleConfigurationPanel.add(m_caseSensitiveMatch, dialogGBC);
dialogGBC.gridx++;
ruleConfigurationPanel.add(m_regularExpression, dialogGBC);
dialogGBC.gridx++;
ruleConfigurationPanel.add(m_containsWildCards, dialogGBC);

dialogGBC.gridx = 0;
dialogGBC.insets = new Insets(2, 2, 2, 2);

getComponentPanel().add(ruleConfigurationPanel, dialogGBC);
dialogGBC.gridy++;

getComponentPanel().add(m_textFieldsPanel, dialogGBC);
dialogGBC.fill = GridBagConstraints.NONE;
dialogGBC.anchor = GridBagConstraints.CENTER;
Expand Down Expand Up @@ -197,6 +245,12 @@ public void actionPerformed(final ActionEvent e) {
m_textFieldsPanel.remove(removeButton.getParent());
getComponentPanel().updateUI();
m_textFieldsGBC.gridy--;

if (m_textFieldsGBC.gridy == 0) {
m_caseSensitiveMatch.setEnabled(false);
m_containsWildCards.setEnabled(false);
m_regularExpression.setEnabled(false);
}
}
});

Expand All @@ -208,6 +262,10 @@ public void actionPerformed(final ActionEvent e) {
m_textFieldsPanel.add(oneFieldRow, m_textFieldsGBC);
m_textFieldsGBC.gridy++;

m_caseSensitiveMatch.setEnabled(true);
m_containsWildCards.setEnabled(true);
m_regularExpression.setEnabled(true);

getComponentPanel().updateUI();

}
Expand Down Expand Up @@ -259,6 +317,10 @@ protected void updateComponent() {
m_operatorBox.setSelectedItem(model.getOperator());
getComponentPanel().updateUI();
setEnabledComponents(getModel().isEnabled());

m_caseSensitiveMatch.setSelected(model.getCaseSensitiveMatch());
m_containsWildCards.setSelected(model.getContainsWildCards());
m_regularExpression.setSelected(model.getRegularExpression());
}

private void updateModel() {
Expand All @@ -273,6 +335,9 @@ private void updateModel() {
model.setRules(tmp);
model.setOperator((RulebasedLabelFilter.Operator)m_operatorBox.getSelectedItem());

model.setCaseSensitiveMatch(m_caseSensitiveMatch.isSelected());
model.setContainsWildCards(m_containsWildCards.isSelected());
model.setRegularExpression(m_regularExpression.isSelected());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
package org.knime.knip.base.node.nodesettings;

import java.util.Arrays;
import java.util.regex.Pattern;

import org.knime.core.node.InvalidSettingsException;
import org.knime.core.node.NodeSettingsRO;
Expand All @@ -70,6 +71,12 @@
*/
public class SettingsModelFilterSelection<L extends Comparable<L>> extends SettingsModel {

private final String m_caseSensitiveMatchCFG = "caseSensitiveMatchCFG";

private final String m_containsWildCardsCFG = "containsWildCardsCFG";

private final String m_regularExpressionCFG = "regularExpressionCFG";

/*
*
*/
Expand All @@ -85,6 +92,12 @@ public class SettingsModelFilterSelection<L extends Comparable<L>> extends Setti
*/
private String[] m_rules = new String[0];

private boolean m_caseSensitiveMatch = false;

private boolean m_containsWildCards = false;

private boolean m_regularExpression = false;

/**
* Constructor
*
Expand Down Expand Up @@ -127,11 +140,12 @@ public RulebasedLabelFilter<L> getRulebasedFilter() {

final String[] rules = getRules().clone();

final Pattern[] patterns = new Pattern[rules.length];
for (int r = 0; r < rules.length; r++) {
rules[r] = RulebasedLabelFilter.formatRegExp(rules[r]);
patterns[r] = RulebasedLabelFilter.compileRegularExpression(m_caseSensitiveMatch, m_containsWildCards, m_regularExpression, rules[r]);
}

return new RulebasedLabelFilter<L>(rules, getOperator());
return new RulebasedLabelFilter<L>(patterns, getOperator());
}

/**
Expand Down Expand Up @@ -161,6 +175,16 @@ protected void loadSettingsForModel(final NodeSettingsRO settings) throws Invali

m_operator = RulebasedLabelFilter.Operator.values()[lists.getInt("operator")];

try {
m_caseSensitiveMatch = lists.getBoolean(m_caseSensitiveMatchCFG);
m_containsWildCards = lists.getBoolean(m_containsWildCardsCFG);
m_regularExpression = lists.getBoolean(m_regularExpressionCFG);
} catch (InvalidSettingsException e) {
// introduced in KNIP 1.5.4
m_caseSensitiveMatch = true;
m_containsWildCards = true;
m_regularExpression = false;
}
}

@Override
Expand All @@ -178,6 +202,10 @@ protected void saveSettingsForModel(final NodeSettingsWO settings) {
}

lists.addInt("operator", m_operator.ordinal());

lists.addBoolean(m_caseSensitiveMatchCFG, m_caseSensitiveMatch);
lists.addBoolean(m_containsWildCardsCFG, m_containsWildCards);
lists.addBoolean(m_regularExpressionCFG, m_regularExpression);
}

/**
Expand Down Expand Up @@ -211,5 +239,82 @@ protected void validateSettingsForModel(final NodeSettingsRO settings) throws In
}

m_operator = RulebasedLabelFilter.Operator.values()[lists.getInt("operator")];

try {
m_caseSensitiveMatch = lists.getBoolean(m_caseSensitiveMatchCFG);
m_containsWildCards = lists.getBoolean(m_containsWildCardsCFG);
m_regularExpression = lists.getBoolean(m_regularExpressionCFG);
} catch (InvalidSettingsException e) {
// introduced in KNIP 1.5.4
m_caseSensitiveMatch = true;
m_containsWildCards = true;
m_regularExpression = false;
}
}

/**
* Is caseSensitiveMatch active.
*
* @param status
*/
public void setCaseSensitiveMatch(final boolean status) {
this.m_caseSensitiveMatch = status;
}

/**
* CaseSensitveMatch status.
*
* @return status
*/
public boolean getCaseSensitiveMatch() {
return this.m_caseSensitiveMatch;
}

/**
* Is containsWildCards active.
* Note: if containsWildCards is true, regularExpression has to be false.
*
* @param status
*/
public void setContainsWildCards(final boolean status) {
if (status) {
this.m_containsWildCards = true;
this.m_regularExpression = false;
} else {
this.m_containsWildCards = false;
}
}

/**
* ContainsWildCards status.
*
* @return status
*/
public boolean getContainsWildCards() {
return this.m_containsWildCards;
}

/**
* Is regularExpression active.
* Note: if regularExpression is true, containsWildCards has to be false.
*
* @param status
*/
public void setRegularExpression(final boolean status) {
if (status) {
this.m_regularExpression = true;
this.m_containsWildCards = false;
} else {
this.m_regularExpression = false;
}
}

/**
* RegularExpression status.
*
* @return status
*/
public boolean getRegularExpression() {
return this.m_regularExpression;
}
}
1 change: 1 addition & 0 deletions org.knime.knip.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ Export-Package: org.knime.knip.core,
org.knime.knip.core.util.waitingindicator,
org.knime.knip.core.util.waitingindicator.libs,
org.knime.knip.io.nodes.annotation.deprecated
Import-Package: org.knime.base.util
Loading

0 comments on commit 3323da7

Please sign in to comment.