public void setUIPropertyValueByStateIndex(java.lang.String propertyName,
+ int stateIndex)
+
Sets the UIProperty propertyName's value to value of the stateIndexth state. This method calls the
+ UIProperty's method to set the value, which will in turn call the corresponding MMProperty's
+ method. Since the change will be notified to all the UIProperties listening to the MMProperty
+ (through triggerPropertyHasChanged(String, String)), this method runs on an independent
+ thread (that is, not on the EDT).
public void setUIPropertyValueByState(java.lang.String propertyName,
+ java.lang.String stateName)
+
Sets the UIProperty propertyName's value to value of the state labeled stateIndex. This method calls the
+ UIProperty's method to set the value, which will in turn call the corresponding MMProperty's
+ method. Since the change will be notified to all the UIProperties listening to the MMProperty
+ (through triggerPropertyHasChanged(String, String)), this method runs on an independent
+ thread (that is, not on the EDT).
An InternalProperty is aimed at passing information between ConfigurablePanels
diff --git a/docs/de/embl/rieslab/emu/ui/internalproperties/package-tree.html b/docs/de/embl/rieslab/emu/ui/internalproperties/package-tree.html
index 4689930..8f3eea0 100644
--- a/docs/de/embl/rieslab/emu/ui/internalproperties/package-tree.html
+++ b/docs/de/embl/rieslab/emu/ui/internalproperties/package-tree.html
@@ -2,9 +2,9 @@
-
+
de.embl.rieslab.emu.ui.internalproperties Class Hierarchy
-
+
@@ -81,6 +81,9 @@
public boolean setStateNames(java.lang.String[] stateNames)
Gives names to the states. If stateNames has less entries than the number of states, then only
- the corresponding states will be updated. If it has more entries, then the supernumerary entries
- will be ignored.
+ the corresponding states will be updated. If it has more entries, then supernumerary entries
+ will be ignored. The method does not check for duplicated names, in such a case, only the first
+ occurrence will be set.
Parameters:
stateNames - State names
@@ -506,7 +520,9 @@
getStateNameFromValue
setPropertyValue
public boolean setPropertyValue(java.lang.String val)
Sets the value of the MMProperty to val if val
- equals either one of the state values or one of the state names.
+ equals either one of the state values, state names or state indices
+ (in that order). To avoid collisions, you can use setPropertyValueByState
+ or setPropertyValueByStateIndex.
public boolean setPropertyValueByState(java.lang.String stateName)
+
Sets the value of the assigned MMProperty to the value in the state labeled newState.
+ If newState is not a valid state name, then the regular setPropertyValue method is called.
public boolean setPropertyValueByState(java.lang.String stateName)
+
Sets the value of the assigned MMProperty to the value in the state labeled newState.
+ If newState is not a valid state name, then the regular setPropertyValue method is called.
public boolean setPropertyValueByState(java.lang.String stateName)
+
Sets the value of the assigned MMProperty to the value in the state labeled newState.
+ If newState is not a valid state name, then the regular setPropertyValue method is called.
public boolean setPropertyValueByState(java.lang.String newState)
+
Sets the value of the assigned MMProperty to newState. For a pure UIProperty, this method is equivalent
+ to setPropertyValue (subclasses might have a different implementation).
public boolean setPropertyValueByStateIndex(int stateIndex)
+
Sets the value of the assigned MMProperty to newState. For a pure UIProperty, this method is equivalent
+ to setPropertyValue (subclasses might have a different implementation).
Constructor, it sets up the JMenu, calls ConfigurableMainFrame.initComponents() from the subclass, then links InternaProperties and
gather UIPropertiers and UIParameters.
diff --git a/src/main/java/de/embl/rieslab/emu/plugin/examples/simpleui/FilterWheelPanel.java b/src/main/java/de/embl/rieslab/emu/plugin/examples/simpleui/FilterWheelPanel.java
index cbb444f..2b6a60c 100644
--- a/src/main/java/de/embl/rieslab/emu/plugin/examples/simpleui/FilterWheelPanel.java
+++ b/src/main/java/de/embl/rieslab/emu/plugin/examples/simpleui/FilterWheelPanel.java
@@ -139,11 +139,7 @@ protected void initializeParameters() {
@Override
protected void initializeProperties() {
// Description of the UIProperty
- String description = "Filter wheel position property. Note: the property actually receives "
- + "the state number and not the state values. To avoid collisions, if you need to use a "
- + "state value that is an integer smaller than the number of states, place it in the state"
- + "with a number equal to the value (e.g.: \"state 1\" with value \"1\"). Alternatively, you"
- + "can use the label mechanism available in Micro-Manager or define a configuration preset group.";
+ String description = "Filter wheel position property.";
// We create a MultiStateUIProperty with 6 states.
addUIProperty(new MultiStateUIProperty(this, FW_POSITION, description, NUM_POS));
diff --git a/src/main/java/de/embl/rieslab/emu/ui/ConfigurablePanel.java b/src/main/java/de/embl/rieslab/emu/ui/ConfigurablePanel.java
index 700ec5c..09ddefb 100644
--- a/src/main/java/de/embl/rieslab/emu/ui/ConfigurablePanel.java
+++ b/src/main/java/de/embl/rieslab/emu/ui/ConfigurablePanel.java
@@ -264,6 +264,68 @@ public void run() {
t.start();
}
}
+ /**
+ * Sets the UIProperty {@code propertyName}'s value to value of the {@code stateIndex}th state. This method calls the
+ * UIProperty's method to set the value, which will in turn call the corresponding MMProperty's
+ * method. Since the change will be notified to all the UIProperties listening to the MMProperty
+ * (through {@link #triggerPropertyHasChanged(String, String)}), this method runs on an independent
+ * thread (that is, not on the EDT).
+ *
+ * @param propertyName UIProperty's name
+ * @param stateIndex New state's index
+ */
+ public void setUIPropertyValueByStateIndex(String propertyName, int stateIndex){
+
+ // this should be a protected method, but in order to call it in SwingUIListeners it was set to public...
+ // passing it as lambdas could be a solution
+
+ if(propertyName == null) {
+ throw new NullPointerException("The UIProperty's label cannot be null.");
+ }
+
+ if(isComponentTriggeringEnabled()) {
+ // makes sure the call does NOT run on EDT
+ Thread t = new Thread("Property change: " + propertyName) {
+ public void run() {
+ if (properties_.containsKey(propertyName)) {
+ properties_.get(propertyName).setPropertyValueByStateIndex(stateIndex);
+ }
+ }
+ };
+ t.start();
+ }
+ }
+ /**
+ * Sets the UIProperty {@code propertyName}'s value to value of the state labeled {@code stateIndex}. This method calls the
+ * UIProperty's method to set the value, which will in turn call the corresponding MMProperty's
+ * method. Since the change will be notified to all the UIProperties listening to the MMProperty
+ * (through {@link #triggerPropertyHasChanged(String, String)}), this method runs on an independent
+ * thread (that is, not on the EDT).
+ *
+ * @param propertyName UIProperty's name
+ * @param stateName New state's name
+ */
+ public void setUIPropertyValueByState(String propertyName, String stateName){
+
+ // this should be a protected method, but in order to call it in SwingUIListeners it was set to public...
+ // passing it as lambdas could be a solution
+
+ if(propertyName == null) {
+ throw new NullPointerException("The UIProperty's label cannot be null.");
+ }
+
+ if(isComponentTriggeringEnabled()) {
+ // makes sure the call does NOT run on EDT
+ Thread t = new Thread("Property change: " + propertyName) {
+ public void run() {
+ if (properties_.containsKey(propertyName)) {
+ properties_.get(propertyName).setPropertyValueByState(stateName);
+ }
+ }
+ };
+ t.start();
+ }
+ }
/**
* Sets the value of the IntegerInternalProperty called {@code propertyName} to {@code newValue}.
diff --git a/src/main/java/de/embl/rieslab/emu/ui/swinglisteners/SwingUIListeners.java b/src/main/java/de/embl/rieslab/emu/ui/swinglisteners/SwingUIListeners.java
index 23d56c5..d8e5ba4 100644
--- a/src/main/java/de/embl/rieslab/emu/ui/swinglisteners/SwingUIListeners.java
+++ b/src/main/java/de/embl/rieslab/emu/ui/swinglisteners/SwingUIListeners.java
@@ -112,8 +112,8 @@ public static void addActionListenerOnSelectedIndex(final ConfigurablePanel cp,
cbx.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
- String val = String.valueOf(cbx.getSelectedIndex());
- cp.setUIPropertyValue(propertyKey,val);
+ int val = cbx.getSelectedIndex();
+ cp.setUIPropertyValueByStateIndex(propertyKey,val);
}
});
}
@@ -145,7 +145,7 @@ public static void addActionListenerOnSelectedIndex(final ConfigurablePanel cp,
AbstractButton btn = enm.nextElement();
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
- cp.setUIPropertyValue(propertyKey,String.valueOf(pos));
+ cp.setUIPropertyValueByStateIndex(propertyKey,pos);
}
});
@@ -189,7 +189,7 @@ public static void addActionListenerOnSelectedIndex(final ConfigurablePanel cp,
AbstractButton btn = enm.nextElement();
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
- cp.setUIPropertyValue(propertyKey,values[pos]);
+ cp.setUIPropertyValueByState(propertyKey,values[pos]);
}
});
@@ -230,7 +230,7 @@ public void actionPerformed(ActionEvent e){
int ind = cbx.getSelectedIndex();
if(ind < values.length && ind >= 0) {
String val = values[ind];
- cp.setUIPropertyValue(propertyKey,val);
+ cp.setUIPropertyValueByState(propertyKey,val);
}
}
});
diff --git a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/MultiStateUIProperty.java b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/MultiStateUIProperty.java
index 6693fd8..b90d340 100644
--- a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/MultiStateUIProperty.java
+++ b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/MultiStateUIProperty.java
@@ -97,8 +97,9 @@ public boolean setStateValues(String[] vals){
/**
* Gives names to the states. If stateNames has less entries than the number of states, then only
- * the corresponding states will be updated. If it has more entries, then the supernumerary entries
- * will be ignored.
+ * the corresponding states will be updated. If it has more entries, then supernumerary entries
+ * will be ignored. The method does not check for duplicated names, in such a case, only the first
+ * occurrence will be set.
*
* @param stateNames State names
* @return True if some names were set, false otherwise.
@@ -207,7 +208,9 @@ public String getStateNameFromValue(String value){
/**
* Sets the value of the MMProperty to {@code val} if {@code val}
- * equals either one of the state values or one of the state names.
+ * equals either one of the state values, state names or state indices
+ * (in that order). To avoid collisions, you can use setPropertyValueByState
+ * or setPropertyValueByStateIndex.
*
*/
@Override
@@ -237,6 +240,45 @@ public boolean setPropertyValue(String val) {
return false;
}
+ /**
+ * Sets the value of the assigned MMProperty to the value in the state labeled {@code newState}.
+ * If newState is not a valid state name, then the regular setPropertyValue method is called.
+ *
+ * @param stateName New state's name
+ * @return True if the value was set, false otherwise.
+ */
+ @Override
+ public boolean setPropertyValueByState(String stateName) {
+ if (isAssigned()) {
+ // if it corresponds to a valid state name
+ for (int i = 0; i < statenames_.length; i++) {
+ if (statenames_[i].equals(stateName)) {
+ return getMMProperty().setValue(states_[i], this);
+ }
+ }
+
+ // otherwise, call the regular method
+ return setPropertyValue(stateName);
+ }
+ return false;
+ }
+
+ /**
+ * Sets the value of the assigned MMProperty to the {@code stateIntex}th state.
+ *
+ * @param stateIndex New state's index
+ * @return True if the value was set, false otherwise.
+ */
+ @Override
+ public boolean setPropertyValueByStateIndex(int stateIndex) {
+ if (isAssigned()) {
+ if (stateIndex >= 0 && stateIndex < states_.length) {
+ return getMMProperty().setValue(states_[stateIndex], this);
+ }
+ }
+ return false;
+ }
+
/**
* Returns the generic name for state i.
*
diff --git a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/SingleStateUIProperty.java b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/SingleStateUIProperty.java
index 3efa509..9006eb9 100644
--- a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/SingleStateUIProperty.java
+++ b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/SingleStateUIProperty.java
@@ -70,12 +70,50 @@ public String getStateValue(){
*/
@Override
public boolean setPropertyValue(String val) {
- if (val != null && isAssigned() && (val.equals(state_) || val.equals(SingleStateUIProperty.getStateLabel()))) {
+ if (val != null && isAssigned() && (val.equals(state_) || val.equals(getStateLabel()))) {
return getMMProperty().setValue(state_, this);
}
return false;
}
+
+ /**
+ * Sets the value of the assigned MMProperty to the value in the state labeled {@code newState}.
+ * If newState is not a valid state name, then the regular setPropertyValue method is called.
+ *
+ * @param stateName New state's name
+ * @return True if the value was set, false otherwise.
+ */
+ @Override
+ public boolean setPropertyValueByState(String stateName) {
+ if (isAssigned()) {
+ // if it corresponds to a valid state name
+ if (getStateLabel().equals(stateName)) {
+ return getMMProperty().setValue(state_, this);
+ }
+
+ // otherwise, call the regular method
+ return setPropertyValue(stateName);
+ }
+ return false;
+ }
+
+ /**
+ * Sets the value of the assigned MMProperty to the property state if stateIndex equals 0.
+ *
+ * @param stateIndex New state's index
+ * @return True if the value was set, false otherwise.
+ */
+ @Override
+ public boolean setPropertyValueByStateIndex(int stateIndex) {
+ if (isAssigned()) {
+ if (stateIndex == 0) {
+ return getMMProperty().setValue(state_, this);
+ }
+ }
+ return false;
+ }
+
/**
* Returns the name of the state.
*
diff --git a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/TwoStateUIProperty.java b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/TwoStateUIProperty.java
index 5028e54..72876d6 100644
--- a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/TwoStateUIProperty.java
+++ b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/TwoStateUIProperty.java
@@ -111,7 +111,8 @@ public String getOffStateValue(){
/**
* Sets the value of the UIproperty to {@code newValue} if {@code newValue}
- * is either equal to the ON state or to the OFF state, or their respective value.
+ * is either equal to the ON state or to the OFF state, or their respective value. The
+ * method also accepts 1/0 or true/false as state labels.
*/
@Override
public boolean setPropertyValue(String newValue) {
@@ -131,7 +132,47 @@ public boolean setPropertyValue(String newValue) {
return false;
}
+ /**
+ * Sets the value of the assigned MMProperty to the value in the state labeled {@code newState}.
+ * If newState is not a valid state name, then the regular setPropertyValue method is called.
+ *
+ * @param stateName New state's name
+ * @return True if the value was set, false otherwise.
+ */
+ @Override
+ public boolean setPropertyValueByState(String stateName) {
+ if (isAssigned()) {
+ // if it corresponds to a valid state name
+ if (getOnStateLabel().equals(stateName)) {
+ return getMMProperty().setValue(getOnStateValue(), this);
+ } else if(getOffStateLabel().equals(stateName)) {
+ return getMMProperty().setValue(getOffStateValue(), this);
+ }
+
+ // otherwise, call the regular method
+ return setPropertyValue(stateName);
+ }
+ return false;
+ }
+ /**
+ * Sets the value of the assigned MMProperty to the On/Off state if stateIndex equals to 1/0 respectively.
+ *
+ * @param stateIndex New state's index
+ * @return True if the value was set, false otherwise.
+ */
+ @Override
+ public boolean setPropertyValueByStateIndex(int stateIndex) {
+ if (isAssigned()) {
+ if (stateIndex == 0) {
+ return getMMProperty().setValue(getOffStateValue(), this);
+ } else if(stateIndex == 1) {
+ return getMMProperty().setValue(getOnStateValue(), this);
+ }
+ }
+ return false;
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/UIProperty.java b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/UIProperty.java
index 9fc3935..269d5ba 100644
--- a/src/main/java/de/embl/rieslab/emu/ui/uiproperties/UIProperty.java
+++ b/src/main/java/de/embl/rieslab/emu/ui/uiproperties/UIProperty.java
@@ -199,6 +199,28 @@ public boolean setPropertyValue(String newValue){
}
return false;
}
+
+ /**
+ * Sets the value of the assigned MMProperty to {@code newState}. For a pure UIProperty, this method is equivalent
+ * to setPropertyValue (subclasses might have a different implementation).
+ *
+ * @param newState New state
+ * @return True if the value was set, false otherwise.
+ */
+ public boolean setPropertyValueByState(String newState) {
+ return mmproperty_.setValue(newState, this);
+ }
+
+ /**
+ * Sets the value of the assigned MMProperty to {@code newState}. For a pure UIProperty, this method is equivalent
+ * to setPropertyValue (subclasses might have a different implementation).
+ *
+ * @param stateIndex New state
+ * @return True if the value was set, false otherwise.
+ */
+ public boolean setPropertyValueByStateIndex(int stateIndex) {
+ return mmproperty_.setValue(String.valueOf(stateIndex), this);
+ }
/**
* Returns the assigned MMProperty.
diff --git a/src/test/java/de/embl/rieslab/emu/micromanager/mmproperties/MultiStateUIPropertyTest.java b/src/test/java/de/embl/rieslab/emu/micromanager/mmproperties/MultiStateUIPropertyTest.java
index 64d4ca7..63708fa 100644
--- a/src/test/java/de/embl/rieslab/emu/micromanager/mmproperties/MultiStateUIPropertyTest.java
+++ b/src/test/java/de/embl/rieslab/emu/micromanager/mmproperties/MultiStateUIPropertyTest.java
@@ -382,6 +382,12 @@ public boolean setValue(String stringval, UIProperty source){
assertTrue(b);
assertEquals(vals[i], cp.property.getPropertyValue());
}
+
+ for(int i=0;i