Skip to content
Snippets Groups Projects
Commit 75348b16 authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Changed PropertyVerifyListener and its subclass VerifyDoubleValueListener....

Changed PropertyVerifyListener and its subclass VerifyDoubleValueListener. Added new class: VerifyIntegerValueListener.
parent 4925aed0
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ import java.util.Iterator;
import fr.ill.ics.core.property.condition.IPropertyCondition;
import fr.ill.ics.core.property.condition.PositivePropertyCondition;
import fr.ill.ics.core.property.condition.StrictlyPositivePropertyCondition;
import fr.ill.ics.core.property.event.NumericVerifyListener;
import fr.ill.ics.core.property.event.VerifyDoubleValueListener;
import fr.ill.ics.core.property.format.DecimalFormat;
import fr.ill.ics.core.property.parser.descriptor.XMLPropertyDescriptor;
......@@ -76,7 +76,7 @@ public abstract class FloatProperty extends Property {
// }
public void setPVerifyListener() {
this.pVerifyListener = new NumericVerifyListener();
this.pVerifyListener = new VerifyDoubleValueListener(acceptNegativeValue);
}
public boolean propertyAcceptsValue(String value, boolean isFinalValue) {
......
......@@ -23,7 +23,7 @@ import java.util.Iterator;
import fr.ill.ics.core.property.condition.IPropertyCondition;
import fr.ill.ics.core.property.condition.PositivePropertyCondition;
import fr.ill.ics.core.property.condition.StrictlyPositivePropertyCondition;
import fr.ill.ics.core.property.event.NumericVerifyListener;
import fr.ill.ics.core.property.event.VerifyIntegerValueListener;
public abstract class IntegerProperty extends Property {
......@@ -73,26 +73,16 @@ public abstract class IntegerProperty extends Property {
// }
public void setPVerifyListener() {
this.pVerifyListener = new NumericVerifyListener();
this.pVerifyListener = new VerifyIntegerValueListener(acceptNegativeValue);
}
public boolean propertyAcceptsValue(String value, boolean isFinalValue) {
try {
int parsedValue = Integer.parseInt(value);
if (parsedValue < 0 && !acceptNegativeValue) {
// if (acceptZeroValue) {
// Recogniser.getInstance().setMessage(name + " " + ConfigManager.getInstance().getString("positiveErrorMessage"));
// } else {
// Recogniser.getInstance().setMessage(name + " " + ConfigManager.getInstance().getString("strictlyPositiveErrorMessage"));
// }
return false;
}
if (parsedValue == 0 && !acceptZeroValue && isFinalValue) {
// if (acceptZeroValue) {
// Recogniser.getInstance().setMessage(name + " " + ConfigManager.getInstance().getString("positiveErrorMessage"));
// } else {
// Recogniser.getInstance().setMessage(name + " " + ConfigManager.getInstance().getString("strictlyPositiveErrorMessage"));
// }
return false;
}
} catch (NumberFormatException nfe) {
......@@ -104,7 +94,6 @@ public abstract class IntegerProperty extends Property {
return true;
}
}
// Recogniser.getInstance().setMessage(name + " " + ConfigManager.getInstance().getString("mustBeAnIntegerMessage"));
return false;
}
return true;
......
......@@ -22,6 +22,13 @@ package fr.ill.ics.core.property.event;
public abstract class PropertyVerifyListener {
protected boolean acceptNegative = false;
public PropertyVerifyListener(boolean acceptNegative) {
this.acceptNegative = acceptNegative;
}
/**
* <p>Sent when the text is about to be modified.</p>
*
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://www.osor.eu/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.core.property.event;
public class VerifyDoubleValueListener extends PropertyVerifyListener {
public VerifyDoubleValueListener(boolean acceptNegative) {
super(acceptNegative);
}
/**
* The text is modified if it is a correct double value.
* The value could be negative if attribute acceptNegative is true.
*
* @see fr.ill.ics.client.control.core.property.event.PropertyVerifyListener#verifyText(PVerifyEvent event)
*/
public boolean verifyText(PVerifyEvent event) {
if ((event.isDeleteKey) || (event.isBackspaceKey)) {
// Accept empty String, Backspace and Delete
return true;
}
if (event.enteredText != null && event.enteredText.length() > 0) {
if (event.enteredText.equals("-")) {
if (acceptNegative) {
// Accept one minus in first position
return (!event.currentText.contains("-") && event.start == 0);
}
return false;
} else if (event.enteredText.equals(".")) {
// Accept first point
return !(event.currentText.contains("."));
}
return event.property.acceptsValue(event.enteredText, false);
}
return true;
}
}
\ No newline at end of file
......@@ -22,10 +22,14 @@ package fr.ill.ics.core.property.event;
public class NumericVerifyListener extends PropertyVerifyListener {
public class VerifyIntegerValueListener extends PropertyVerifyListener {
public VerifyIntegerValueListener(boolean acceptNegative) {
super(acceptNegative);
}
/**
* The text is modified if it is a correct double value.
* The text is modified if it is a correct integer value.
* The value could be negative if attribute acceptNegative is true.
*
* @see fr.ill.ics.client.control.core.property.event.PropertyVerifyListener#verifyText(PVerifyEvent event)
......@@ -37,13 +41,11 @@ public class NumericVerifyListener extends PropertyVerifyListener {
}
if (event.enteredText != null && event.enteredText.length() > 0) {
if (event.enteredText.equals("-")) {
// Accept one minus in first position
return (!event.currentText.contains("-") && event.start == 0);
} else if (event.enteredText.equals(".")) {
// Accept first point
return !(event.currentText.contains("."));
if (acceptNegative) {
// Accept one minus in first position
return (!event.currentText.contains("-") && event.start == 0);
}
return false;
}
return event.property.acceptsValue(event.enteredText, false);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment