package fortiss.gui.listeners.textfield;

import fortiss.gui.listeners.helper.InsertionVerifier;

public class BPortListener extends TextFieldListener {

	public BPortListener() {
		super("Error. Invalid port number. Only numbers between 1024 and 49151, and 0 are valid.");
	}
	
	@Override
	boolean isValidField(String text) {
		boolean valid = false;
		if (!text.isEmpty()) {
			int num = Integer.parseUnsignedInt(text);
			if (num == 0 || (num > 1024 && num < 49151))
				valid = true;
		}
		return valid;
	}
	
	@Override
	boolean isValidCharacter(char c, String text) {
		InsertionVerifier v = new InsertionVerifier();
		return v.isNumber(c, text);
	}
	
	@Override
	void update(String text) {
		building.setPort(Integer.parseUnsignedInt(text));
	}

	@Override
	boolean isValidLength(String text) {
		return text.length() < 5;
	}

	@Override
	String getAttribute() {
		return String.valueOf(building.getPort());
	}
}

@@ -58,40 +58,115 @@
 gui.
-listeners.helper.InsertionVerifi
+DesignerPanel;%0Aimport fortiss.gui.listeners.helper.InsertionVerifier;%0Aimport fortiss.simulation.helper.Logg
 er;%0A
@@ -445,16 +445,26 @@
 ty()) %7B%0A
+%09%09%09try %7B%0A%09
 %09%09%09int n
@@ -499,17 +499,19 @@
 t(text);
-%0A
+%09%0A%09
 %09%09%09if (n
@@ -554,16 +554,17 @@
 1))%0A%09%09%09%09
+%09
 valid = 
@@ -569,16 +569,166 @@
 = true;%0A
+%09%09%09%7D catch (NumberFormatException e) %7B%0A%09%09%09%09Logger.getInstance().writeError(%22Number format exception. Expected an integer and received %22 + text);%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%09re
@@ -927,16 +927,25 @@
 text) %7B%0A
+%09%09try %7B%0A%09
 %09%09buildi
@@ -988,16 +988,204 @@
 text));%0A
+%09%09%7D catch (NumberFormatException e) %7B%0A%09%09%09Logger.getInstance().writeError(%22Number format exception. Expected an integer and received %22 + text);%0A%09%09%09DesignerPanel.pl_ems_detail.update();%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Ov

Handle number format exception: building port