JAL-3162 only allow start <= end while modifying bug/JAL-3162featureStartLtEnd
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 26 Nov 2018 16:24:32 +0000 (16:24 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 26 Nov 2018 16:24:32 +0000 (16:24 +0000)
src/jalview/gui/FeatureEditor.java

index f14d657..ab69f45 100644 (file)
@@ -33,7 +33,10 @@ import javax.swing.JScrollPane;
 import javax.swing.JSpinner;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
+import javax.swing.SpinnerNumberModel;
 import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 
@@ -168,10 +171,34 @@ public class FeatureEditor
     });
 
     description = new JTextArea(3, 25);
+    
     start = new JSpinner();
     end = new JSpinner();
     start.setPreferredSize(new Dimension(80, 20));
     end.setPreferredSize(new Dimension(80, 20));
+    
+    /*
+     * ensure that start can never be more than end
+     */
+    start.addChangeListener(new ChangeListener() 
+    {
+      @Override
+      public void stateChanged(ChangeEvent e)
+      {
+        Integer startVal = (Integer) start.getValue(); 
+        ((SpinnerNumberModel) end.getModel()).setMinimum(startVal);
+      }
+    });
+    end.addChangeListener(new ChangeListener() 
+    {
+      @Override
+      public void stateChanged(ChangeEvent e)
+      {
+        Integer endVal = (Integer) end.getValue(); 
+        ((SpinnerNumberModel) start.getModel()).setMaximum(endVal);
+      }
+    });
+
     final JLabel colour = new JLabel();
     colour.setOpaque(true);
     colour.setMaximumSize(new Dimension(30, 16));
@@ -266,6 +293,8 @@ public class FeatureEditor
             group.setText(sf.getFeatureGroup());
             start.setValue(new Integer(sf.getBegin()));
             end.setValue(new Integer(sf.getEnd()));
+            ((SpinnerNumberModel) start.getModel()).setMaximum(sf.getEnd());
+            ((SpinnerNumberModel) end.getModel()).setMinimum(sf.getBegin());
 
             SearchResultsI highlight = new SearchResults();
             highlight.addResult(sequences.get(0), sf.getBegin(),
@@ -353,6 +382,9 @@ public class FeatureEditor
 
     start.setValue(new Integer(firstFeature.getBegin()));
     end.setValue(new Integer(firstFeature.getEnd()));
+    ((SpinnerNumberModel) start.getModel()).setMaximum(firstFeature.getEnd());
+    ((SpinnerNumberModel) end.getModel()).setMinimum(firstFeature.getBegin());
+
     description.setText(firstFeature.getDescription());
     featureColour = fr.getFeatureStyle(featureType);
     oldColour = featureColour;