@Test public void testSetMinAndMax() { System.out.println("setMinAndMax"); Integer min = 6; Integer max = 3; Integer badMin = 0; Integer badMax = 10001; MinMaxSpinValueHandler instance = new MinMaxSpinValueHandler(new JSpinner(), new JSpinner()); instance.setMinAndMax(min, max); instance.setMinAndMax(badMin, max); instance.setMinAndMax(min, badMax); ArrayList<Integer> expResult = new ArrayList<>(); for (int i = 3; i <= 6; i++) { expResult.add(i); } ArrayList<Integer> result = instance.getValues(); assertTrue(expResult.equals(result)); }
public synchronized void setMinAndMax(Integer min, Integer max) { reacts = true; if (min <= 10000 && min >= 1 && max <= 10000 && max >= 1) { minSpinner.setValue(java.lang.Math.min(min, max)); maxSpinner.setValue(java.lang.Math.max(min, max)); } else { minSpinner.setValue(minBefore); maxSpinner.setValue(maxBefore); } Integer minAfter = Integer.parseInt(minSpinner.getValue().toString()); Integer maxAfter = Integer.parseInt(maxSpinner.getValue().toString()); if (minBefore == null || !(minBefore.equals(minAfter) && maxBefore.equals(maxAfter))) { minBefore = minAfter; maxBefore = maxAfter; setHasChanged(true); } reacts = false; }
MinMaxSpinValueHandler implements ChangeListener { public synchronized void setMinAndMax(Integer min, Integer max) { reacts = true; if (min <= 10000 && min >= 1 && max <= 10000 && max >= 1) { minSpinner.setValue(java.lang.Math.min(min, max)); maxSpinner.setValue(java.lang.Math.max(min, max)); } else { minSpinner.setValue(minBefore); maxSpinner.setValue(maxBefore); } Integer minAfter = Integer.parseInt(minSpinner.getValue().toString()); Integer maxAfter = Integer.parseInt(maxSpinner.getValue().toString()); if (minBefore == null || !(minBefore.equals(minAfter) && maxBefore.equals(maxAfter))) { minBefore = minAfter; maxBefore = maxAfter; setHasChanged(true); } reacts = false; } }
MinMaxSpinValueHandler implements ChangeListener { public synchronized void setMinAndMax(Integer min, Integer max) { reacts = true; if (min <= 10000 && min >= 1 && max <= 10000 && max >= 1) { minSpinner.setValue(java.lang.Math.min(min, max)); maxSpinner.setValue(java.lang.Math.max(min, max)); } else { minSpinner.setValue(minBefore); maxSpinner.setValue(maxBefore); } Integer minAfter = Integer.parseInt(minSpinner.getValue().toString()); Integer maxAfter = Integer.parseInt(maxSpinner.getValue().toString()); if (minBefore == null || !(minBefore.equals(minAfter) && maxBefore.equals(maxAfter))) { minBefore = minAfter; maxBefore = maxAfter; setHasChanged(true); } reacts = false; } MinMaxSpinValueHandler(JSpinner minSpinner, JSpinner maxSpinner); }
MinMaxSpinValueHandler implements ChangeListener { public synchronized void setMinAndMax(Integer min, Integer max) { reacts = true; if (min <= 10000 && min >= 1 && max <= 10000 && max >= 1) { minSpinner.setValue(java.lang.Math.min(min, max)); maxSpinner.setValue(java.lang.Math.max(min, max)); } else { minSpinner.setValue(minBefore); maxSpinner.setValue(maxBefore); } Integer minAfter = Integer.parseInt(minSpinner.getValue().toString()); Integer maxAfter = Integer.parseInt(maxSpinner.getValue().toString()); if (minBefore == null || !(minBefore.equals(minAfter) && maxBefore.equals(maxAfter))) { minBefore = minAfter; maxBefore = maxAfter; setHasChanged(true); } reacts = false; } MinMaxSpinValueHandler(JSpinner minSpinner, JSpinner maxSpinner); ArrayList<Integer> getValues(); synchronized void setMinAndMax(Integer min, Integer max); @Override synchronized void stateChanged(ChangeEvent e); }
MinMaxSpinValueHandler implements ChangeListener { public synchronized void setMinAndMax(Integer min, Integer max) { reacts = true; if (min <= 10000 && min >= 1 && max <= 10000 && max >= 1) { minSpinner.setValue(java.lang.Math.min(min, max)); maxSpinner.setValue(java.lang.Math.max(min, max)); } else { minSpinner.setValue(minBefore); maxSpinner.setValue(maxBefore); } Integer minAfter = Integer.parseInt(minSpinner.getValue().toString()); Integer maxAfter = Integer.parseInt(maxSpinner.getValue().toString()); if (minBefore == null || !(minBefore.equals(minAfter) && maxBefore.equals(maxAfter))) { minBefore = minAfter; maxBefore = maxAfter; setHasChanged(true); } reacts = false; } MinMaxSpinValueHandler(JSpinner minSpinner, JSpinner maxSpinner); ArrayList<Integer> getValues(); synchronized void setMinAndMax(Integer min, Integer max); @Override synchronized void stateChanged(ChangeEvent e);  }