View Javadoc

1   /* OpenLogViewer
2    *
3    * Copyright 2011
4    *
5    * This file is part of the OpenLogViewer project.
6    *
7    * OpenLogViewer software is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * OpenLogViewer software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with any OpenLogViewer software.  If not, see http://www.gnu.org/licenses/
19   *
20   * I ask that if you make any changes to this file you fork the code on github.com!
21   *
22   */
23  
24  package org.diyefi.openlogviewer.optionpanel;
25  
26  import javax.swing.DefaultComboBoxModel;
27  
28  /**
29   *
30   * @author Bryan Harris
31   */
32  public class SortComboBoxModel extends DefaultComboBoxModel{
33  	
34  	public SortComboBoxModel()
35  	{
36  		super();
37  	}
38  
39  
40  	@Override
41  	public void addElement(Object element)
42  	{
43  		insertElementAt(element, 0);
44  	}
45  
46  	@SuppressWarnings("unchecked")
47  	@Override
48  	public void insertElementAt(Object element, int index)
49  	{
50  		int size = getSize();
51  		for (index = 0; index < size; index++)
52  		{
53  				Comparable c = (Comparable)getElementAt( index );
54  				if (c.compareTo(element) > 0)
55  					break;
56  		}
57  		super.insertElementAt(element, index);
58  	}
59  
60  
61  }