Ignore:
Timestamp:
17.06.2009 10:04:22 (3 years ago)
Author:
stoecker
Message:

remove all these ugly tab stops introduced in the last half year

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/historycombobox/ComboBoxHistory.java

    r1575 r1677  
    11/* Copyright (c) 2008, Henrik Niehaus 
    22 * All rights reserved. 
    3  *  
     3 * 
    44 * Redistribution and use in source and binary forms, with or without 
    55 * modification, are permitted provided that the following conditions are met: 
    6  *  
     6 * 
    77 * 1. Redistributions of source code must retain the above copyright notice, 
    88 *    this list of conditions and the following disclaimer. 
    9  * 2. Redistributions in binary form must reproduce the above copyright notice,  
    10  *    this list of conditions and the following disclaimer in the documentation  
     9 * 2. Redistributions in binary form must reproduce the above copyright notice, 
     10 *    this list of conditions and the following disclaimer in the documentation 
    1111 *    and/or other materials provided with the distribution. 
    12  * 3. Neither the name of the project nor the names of its  
    13  *    contributors may be used to endorse or promote products derived from this  
     12 * 3. Neither the name of the project nor the names of its 
     13 *    contributors may be used to endorse or promote products derived from this 
    1414 *    software without specific prior written permission. 
    15  *  
     15 * 
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     
    3737public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<String> { 
    3838 
    39         private int maxSize = 10; 
    40          
    41         private List<HistoryChangedListener> listeners = new ArrayList<HistoryChangedListener>(); 
    42          
    43         public ComboBoxHistory(int size) { 
    44                 maxSize = size; 
    45         } 
    46          
    47         /** 
    48          * Adds or moves an element to the top of the history 
    49          */ 
    50         public void addElement(Object o) { 
    51                 String newEntry = (String)o; 
    52                  
    53                 // if history contains this object already, delete it, 
    54                 // so that it looks like a move to the top 
    55                 for (int i = 0; i < getSize(); i++) { 
    56                         String oldEntry = (String) getElementAt(i); 
    57                         if(oldEntry.equals(newEntry)) { 
    58                                 removeElementAt(i); 
    59                         } 
    60                 } 
    61                  
    62                 // insert element at the top 
    63                 insertElementAt(o, 0); 
    64                  
    65                 // remove an element, if the history gets too large 
    66                 if(getSize()> maxSize) { 
    67                         removeElementAt(getSize()-1); 
    68                 } 
    69                  
    70                 // set selected item to the one just added 
    71                 setSelectedItem(o); 
    72                  
    73                 fireHistoryChanged(); 
    74         } 
    75          
    76         public Iterator<String> iterator() { 
    77                 return new Iterator<String>() { 
     39    private int maxSize = 10; 
    7840 
    79                         private int position = -1; 
    80                          
    81                         public void remove() { 
    82                                 removeElementAt(position); 
    83                         } 
     41    private List<HistoryChangedListener> listeners = new ArrayList<HistoryChangedListener>(); 
    8442 
    85                         public boolean hasNext() { 
    86                                 if(position < getSize()-1 && getSize()>0) { 
    87                                         return true; 
    88                                 } 
    89                                 return false; 
    90                         } 
     43    public ComboBoxHistory(int size) { 
     44        maxSize = size; 
     45    } 
    9146 
    92                         public String next() { 
    93                                 position++; 
    94                                 return getElementAt(position).toString(); 
    95                         } 
    96                          
    97                 }; 
    98         } 
     47    /** 
     48     * Adds or moves an element to the top of the history 
     49     */ 
     50    public void addElement(Object o) { 
     51        String newEntry = (String)o; 
    9952 
    100         public void setItems(List<String> items) { 
    101             removeAllElements(); 
    102             Collections.reverse(items); 
    103             for (String item : items) { 
     53        // if history contains this object already, delete it, 
     54        // so that it looks like a move to the top 
     55        for (int i = 0; i < getSize(); i++) { 
     56            String oldEntry = (String) getElementAt(i); 
     57            if(oldEntry.equals(newEntry)) { 
     58                removeElementAt(i); 
     59            } 
     60        } 
     61 
     62        // insert element at the top 
     63        insertElementAt(o, 0); 
     64 
     65        // remove an element, if the history gets too large 
     66        if(getSize()> maxSize) { 
     67            removeElementAt(getSize()-1); 
     68        } 
     69 
     70        // set selected item to the one just added 
     71        setSelectedItem(o); 
     72 
     73        fireHistoryChanged(); 
     74    } 
     75 
     76    public Iterator<String> iterator() { 
     77        return new Iterator<String>() { 
     78 
     79            private int position = -1; 
     80 
     81            public void remove() { 
     82                removeElementAt(position); 
     83            } 
     84 
     85            public boolean hasNext() { 
     86                if(position < getSize()-1 && getSize()>0) { 
     87                    return true; 
     88                } 
     89                return false; 
     90            } 
     91 
     92            public String next() { 
     93                position++; 
     94                return getElementAt(position).toString(); 
     95            } 
     96 
     97        }; 
     98    } 
     99 
     100    public void setItems(List<String> items) { 
     101        removeAllElements(); 
     102        Collections.reverse(items); 
     103        for (String item : items) { 
    104104            addElement(item); 
    105105        } 
    106             Collections.reverse(items); 
    107         } 
    108          
     106        Collections.reverse(items); 
     107    } 
     108 
    109109    public List<String> asList() { 
    110110        List<String> list = new ArrayList<String>(maxSize); 
     
    114114        return list; 
    115115    } 
    116      
     116 
    117117    public void addHistoryChangedListener(HistoryChangedListener l) { 
    118118        listeners.add(l); 
    119119    } 
    120      
     120 
    121121    public void removeHistoryChangedListener(HistoryChangedListener l) { 
    122122        listeners.remove(l); 
    123123    } 
    124      
     124 
    125125    private void fireHistoryChanged() { 
    126126        for (HistoryChangedListener l : listeners) { 
Note: See TracChangeset for help on using the changeset viewer.