fiore@0: /* fiore@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool fiore@0: fiore@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) fiore@0: fiore@0: This program is free software: you can redistribute it and/or modify fiore@0: it under the terms of the GNU General Public License as published by fiore@0: the Free Software Foundation, either version 3 of the License, or fiore@0: (at your option) any later version. fiore@0: fiore@0: This program is distributed in the hope that it will be useful, fiore@0: but WITHOUT ANY WARRANTY; without even the implied warranty of fiore@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fiore@0: GNU General Public License for more details. fiore@0: fiore@0: You should have received a copy of the GNU General Public License fiore@0: along with this program. If not, see . fiore@0: */ fiore@0: package uk.ac.qmul.eecs.ccmi.gui; fiore@0: fiore@0: import javax.swing.SpinnerNumberModel; fiore@0: fiore@0: /** fiore@0: * A SpinnerNumberModel which overrides the default behaviour when selecting items by the keyboard fiore@0: * up and down arrow keys. fiore@0: * When the maximum value is reached, a call to getNextValue() fiore@0: * will return the minimum value, instead of returning null. Likewise, fiore@0: * when the minimum value is reached, a call to getPreviousValue() will return the maximum value fiore@0: * instead of returning null. fiore@0: * fiore@0: * fiore@0: */ fiore@0: @SuppressWarnings("serial") fiore@0: public class LoopSpinnerNumberModel extends SpinnerNumberModel { fiore@0: public LoopSpinnerNumberModel(int value, int minimum, int maximum){ fiore@0: super(value,minimum,maximum,1); fiore@0: } fiore@0: fiore@0: @Override fiore@0: public Object getNextValue(){ fiore@0: Object nextValue = super.getNextValue(); fiore@0: if(nextValue == null) fiore@0: return getMinimum(); fiore@0: else fiore@0: return nextValue; fiore@0: } fiore@0: fiore@0: @Override fiore@0: public Object getPreviousValue(){ fiore@0: Object previousValue = super.getPreviousValue(); fiore@0: if(previousValue == null) fiore@0: return getMaximum(); fiore@0: else fiore@0: return previousValue; fiore@0: } fiore@0: fiore@0: public Object getValue(){ fiore@0: return super.getValue(); fiore@0: } fiore@0: }