package org.zu.ardulink.gui.facility;

import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

public class IntMinMaxModel extends AbstractListModel<Integer> implements
		ComboBoxModel<Integer> {

	private static final long serialVersionUID = -6314940179491347446L;

	private int low;
	private int high;

	private Integer selectedItem;

	public IntMinMaxModel(int low, int high) {
		this.low = low;
		this.high = high;
	}

	@Override
	public int getSize() {
		return high - low + 1;
	}

	@Override
	public Integer getElementAt(int index) {
		return Integer.valueOf(index + low);
	}

	@Override
	public void setSelectedItem(Object selectedItem) {
		this.selectedItem = (Integer) selectedItem;
	}

	@Override
	public Integer getSelectedItem() {
		return selectedItem;
	}

	public IntMinMaxModel withSelectedItem(int selectedItem) {
		setSelectedItem(Integer.valueOf(selectedItem));
		return this;
	}

	public IntMinMaxModel withFirstItemSelected() {
		selectIndex(0);
		return this;
	}

	public IntMinMaxModel withLastItemSelected() {
		selectIndex(getSize() - 1);
		return this;
	}

	private void selectIndex(int index) {
		if (index < getSize()) {
			withSelectedItem(getElementAt(index));
		}
	}

}
@@ -1138,28 +1138,74 @@
 %0A%09%09i
-f (index %3C getSize()
+nt size = getSize();%0A%09%09if (size != 0 && index %3E= 0 && index %3C size
 ) %7B%0A

check for lower bound