JAL-633 simple concrete parameter and option objects for use within Jalview
authorjprocter <jprocter@compbio.dundee.ac.uk>
Mon, 29 Aug 2011 12:49:17 +0000 (13:49 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Mon, 29 Aug 2011 12:49:17 +0000 (13:49 +0100)
src/jalview/ws/params/simple/BooleanOption.java [new file with mode: 0644]
src/jalview/ws/params/simple/IntegerParameter.java [new file with mode: 0644]
src/jalview/ws/params/simple/Option.java [new file with mode: 0644]
src/jalview/ws/params/simple/Parameter.java [new file with mode: 0644]
src/jalview/ws/params/simple/StringChoiceParameter.java [new file with mode: 0644]

diff --git a/src/jalview/ws/params/simple/BooleanOption.java b/src/jalview/ws/params/simple/BooleanOption.java
new file mode 100644 (file)
index 0000000..d9b294d
--- /dev/null
@@ -0,0 +1,18 @@
+package jalview.ws.params.simple;
+
+import java.net.URL;
+import java.util.Arrays;
+
+import jalview.ws.params.OptionI;
+
+public class BooleanOption extends Option implements OptionI
+{
+
+  public BooleanOption(String name, String descr, boolean required, boolean defVal,
+          boolean val, URL link)
+  {
+    
+    super(name,descr,required,(defVal ? name:""),(val ? name:""),Arrays.asList(new String[] {name}),link);
+  }
+  
+}
diff --git a/src/jalview/ws/params/simple/IntegerParameter.java b/src/jalview/ws/params/simple/IntegerParameter.java
new file mode 100644 (file)
index 0000000..29df95d
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * 
+ */
+package jalview.ws.params.simple;
+
+import jalview.ws.params.ParameterI;
+import jalview.ws.params.ValueConstrainI;
+
+import compbio.metadata.ValueConstrain.Type;
+
+/**
+ * @author jimp
+ *
+ */
+public class IntegerParameter extends Option implements ParameterI 
+{
+  int defval;
+  int min,max;
+  public ValueConstrainI getValidValue() {
+    return new ValueConstrainI()
+    {
+      
+      @Override
+      public ValueType getType()
+      {
+        return ValueType.Integer;
+      }
+      
+      @Override
+      public Number getMin()
+      {
+        if (min<max)
+        {
+        return min;
+        } else {
+          return null;
+        }
+      }
+      
+      @Override
+      public Number getMax()
+      {
+        if (min<max)
+        {
+          return max;
+        } else {
+          return null;
+        }
+      }
+    };
+  }
+  public IntegerParameter(IntegerParameter parm)
+  {
+    super(parm);
+    max = parm.max;
+    min = parm.min;
+  }
+
+  public IntegerParameter(String name, String description, boolean required, int defValue,
+          int min, int max)
+  {
+    super(name, description, required, String.valueOf(defValue), null, null, null);
+    defval = defValue;
+    this.min = min;
+    this.max = max;
+  }
+
+  public IntegerParameter(String name, String description, boolean required, int defValue, int value,
+          int min, int max)
+  {
+    super(name, description, required, String.valueOf(defValue), String.valueOf(value), null, null);
+    defval = defValue;
+    this.min = min;
+    this.max = max;
+  }
+  @Override
+  public IntegerParameter copy()
+  {
+    return new IntegerParameter(this);    
+  }
+  
+}
diff --git a/src/jalview/ws/params/simple/Option.java b/src/jalview/ws/params/simple/Option.java
new file mode 100644 (file)
index 0000000..eb993c2
--- /dev/null
@@ -0,0 +1,101 @@
+package jalview.ws.params.simple;
+
+import jalview.ws.params.OptionI;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class Option implements OptionI {
+
+  
+  String name, value, defvalue,description;
+  ArrayList<String> possibleVals=new ArrayList<String>();
+  boolean required;
+  URL fdetails;
+  @Override
+  public String getName()
+  {
+    return name;
+  }
+
+  @Override
+  public String getValue()
+  {
+    return value==null ? defvalue : value;
+  }
+
+  @Override
+  public void setValue(String selectedItem)
+  {
+    value = selectedItem;
+  }
+
+  @Override
+  public URL getFurtherDetails()
+  {
+    return fdetails;
+  }
+
+  @Override
+  public boolean isRequired()
+  {
+    return required;
+  }
+
+  @Override
+  public String getDescription()
+  {
+    return description;
+  }
+
+  @Override
+  public List<String> getPossibleValues()
+  {
+    return possibleVals;
+  }
+  public Option(Option opt)
+  {
+    name = new String(opt.name);
+    if (opt.value!=null) 
+      value = new String(opt.value);
+    if (opt.defvalue!=null)
+      defvalue=new String(opt.defvalue);
+    if (opt.description!=null)
+      description=new String(opt.description);
+    if (opt.possibleVals!=null) {
+      possibleVals = (ArrayList<String>)opt.possibleVals.clone();
+    }
+    required = opt.required;
+    // URLs are singletons - so we copy by reference. nasty but true.
+    fdetails = opt.fdetails;
+  }
+  public Option()
+  {
+  }
+
+  public Option(String name2, String description2, boolean isrequired,
+          String defValue, String value, Collection<String> possibleVals, URL fdetails)
+  {
+    name = name2;
+    description = description2;
+    this.value = value;
+    this.required = isrequired;
+    this.defvalue = defValue;
+    if (possibleVals!=null)
+    {
+      this.possibleVals = new ArrayList<String>();
+      this.possibleVals.addAll(possibleVals);
+    }
+    this.fdetails = fdetails;
+  }
+
+
+  @Override
+  public OptionI copy()
+  {
+    Option opt = new Option(this);
+    return opt;
+  }
+}
\ No newline at end of file
diff --git a/src/jalview/ws/params/simple/Parameter.java b/src/jalview/ws/params/simple/Parameter.java
new file mode 100644 (file)
index 0000000..a2eb5ef
--- /dev/null
@@ -0,0 +1,25 @@
+package jalview.ws.params.simple;
+
+import jalview.ws.params.OptionI;
+import jalview.ws.params.ParameterI;
+import jalview.ws.params.ValueConstrainI;
+
+public abstract class Parameter extends Option implements OptionI,ParameterI {
+  ValueConstrainI validator;
+  @Override
+  public ValueConstrainI getValidValue()
+  {
+    return validator;
+  }
+  public Parameter(Parameter parm)
+  {
+    super(parm);
+  }
+  public Parameter(ValueConstrainI validator)
+  {
+    super();
+    this.validator = validator;
+  }
+  @Override
+  public abstract Parameter copy();
+}
\ No newline at end of file
diff --git a/src/jalview/ws/params/simple/StringChoiceParameter.java b/src/jalview/ws/params/simple/StringChoiceParameter.java
new file mode 100644 (file)
index 0000000..1d56cf6
--- /dev/null
@@ -0,0 +1,6 @@
+package jalview.ws.params.simple;
+
+public class StringChoiceParameter extends Option
+{
+
+}