Changeset 7015 in josm for trunk


Ignore:
Timestamp:
2014-04-27T17:34:22+02:00 (11 years ago)
Author:
Don-vip
Message:

see #8465 - fix generics for JComboBox/JList

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellEditor.java

    r7005 r7015  
    4848
    4949    /** the combo box used as editor */
    50     private JosmComboBox editor;
    51     private DefaultComboBoxModel editorModel;
     50    private JosmComboBox<Object> editor;
     51    private DefaultComboBoxModel<Object> editorModel;
    5252    private CopyOnWriteArrayList<NavigationListener> listeners;
    5353
     
    7878     */
    7979    public MultiValueCellEditor() {
    80         editorModel = new DefaultComboBoxModel();
    81         editor = new JosmComboBox(editorModel) {
     80        editorModel = new DefaultComboBoxModel<>();
     81        editor = new JosmComboBox<Object>(editorModel) {
    8282            @Override
    8383            public void processKeyEvent(KeyEvent e) {
     
    172172     *
    173173     */
    174     private static class EditorCellRenderer extends JLabel implements ListCellRenderer {
     174    private static class EditorCellRenderer extends JLabel implements ListCellRenderer<Object> {
    175175
    176176        /**
     
    224224
    225225        @Override
    226         public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
     226        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    227227            renderColors(isSelected);
    228228            renderValue(value);
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictDecisionEditor.java

    r6912 r7015  
    1212import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    1313
    14 public class RelationMemberConflictDecisionEditor extends JosmComboBox implements TableCellEditor {
     14public class RelationMemberConflictDecisionEditor extends JosmComboBox<RelationMemberConflictDecisionType> implements TableCellEditor {
    1515
    1616    /**
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r7005 r7015  
    154154         * @see Arrays#asList(Object[])
    155155         */
    156         public static List list(Object... args) {
     156        public static List<Object> list(Object... args) {
    157157            return Arrays.asList(args);
    158158        }
  • trunk/src/org/openstreetmap/josm/gui/oauth/AuthorizationProcedureComboBox.java

    r7001 r7015  
    1313import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    1414
    15 public class AuthorizationProcedureComboBox extends JosmComboBox {
     15public class AuthorizationProcedureComboBox extends JosmComboBox<AuthorizationProcedure> {
    1616
    1717    /**
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java

    r6890 r7015  
    6161    private JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)"));
    6262    private JRadioButton colorTypeGlobal  = new JRadioButton(tr("Use global settings"));
    63     private JosmComboBox colorTypeVelocityTune = new JosmComboBox(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")});
     63    private JosmComboBox<String> colorTypeVelocityTune = new JosmComboBox<>(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")});
    6464    private JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX"));
    6565    private JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows"));
     
    6767    private JosmTextField drawGpsArrowsMinDist = new JosmTextField(8);
    6868    private JCheckBox colorDynamic = new JCheckBox(tr("Dynamic color range based on data limits"));
    69     private JosmComboBox waypointLabel = new JosmComboBox(LABEL_PATTERN_DESC);
     69    private JosmComboBox<String> waypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC);
    7070    private JosmTextField waypointLabelPattern = new JosmTextField();
    71     private JosmComboBox audioWaypointLabel = new JosmComboBox(LABEL_PATTERN_DESC);
     71    private JosmComboBox<String> audioWaypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC);
    7272    private JosmTextField audioWaypointLabelPattern = new JosmTextField();
    7373    private JCheckBox useGpsAntialiasing = new JCheckBox(tr("Smooth GPX graphics (antialiasing)"));
     
    368368    }
    369369
    370 
    371370    /**
    372371     * Save preferences from UI controls, globally or for a specified layer.
     
    443442    }
    444443
    445     private void updateWaypointLabelCombobox(JosmComboBox cb, JosmTextField tf, TemplateEntryProperty property) {
     444    private void updateWaypointLabelCombobox(JosmComboBox<String> cb, JosmTextField tf, TemplateEntryProperty property) {
    446445        String labelPattern = property.getAsString();
    447446        boolean found = false;
     
    460459    }
    461460
    462     private void updateWaypointPattern(JosmComboBox cb, JosmTextField tf) {
     461    private void updateWaypointPattern(JosmComboBox<String> cb, JosmTextField tf) {
    463462        if (cb.getSelectedIndex() == WAYPOINT_LABEL_CUSTOM) {
    464463            tf.setEnabled(true);
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java

    r6957 r7015  
    4949     * ComboBox with all look and feels.
    5050     */
    51     private JosmComboBox lafCombo;
     51    private JosmComboBox<LookAndFeelInfo> lafCombo;
    5252    JPanel panel;
    5353    private JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup"));
     
    5959    @Override
    6060    public void addGui(PreferenceTabbedPane gui) {
    61         lafCombo = new JosmComboBox(UIManager.getInstalledLookAndFeels());
     61        lafCombo = new JosmComboBox<>(UIManager.getInstalledLookAndFeels());
    6262
    6363        // let's try to load additional LookAndFeels and put them into the list
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LanguagePreference.java

    r7005 r7015  
    4444
    4545    /** the combo box with the available locales */
    46     private JosmComboBox langCombo;
     46    private JosmComboBox<Locale> langCombo;
    4747
    4848    @Override
     
    5252        // See https://stackoverflow.com/questions/3194958/fast-replacement-for-jcombobox-basiccomboboxui
    5353        model.selectLanguage(Main.pref.get("language"));
    54         langCombo = new JosmComboBox(model);
     54        langCombo = new JosmComboBox<>(model);
    5555        langCombo.setRenderer(new LanguageCellRenderer(langCombo.getRenderer()));
    5656
     
    7575    }
    7676
    77     private static class LanguageComboBoxModel extends DefaultComboBoxModel {
     77    private static class LanguageComboBoxModel extends DefaultComboBoxModel<Locale> {
    7878        private final List<Locale> data = new ArrayList<>();
    7979
     
    9999
    100100        @Override
    101         public Object getElementAt(int index) {
     101        public Locale getElementAt(int index) {
    102102            return data.get(index);
    103103        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java

    r6930 r7015  
    3838    private final JCheckBox endpoint = new JCheckBox(tr("Store WMS endpoint only, select layers at usage"));
    3939    private final WMSLayerTree tree = new WMSLayerTree();
    40     private final JComboBox formats = new JComboBox();
     40    private final JComboBox<String> formats = new JComboBox<>();
    4141    private final JLabel wmsInstruction;
    4242    private final JosmTextArea wmsUrl = new JosmTextArea(3, 40);
     
    7777                    wms.attemptGetCapabilities(rawUrl.getText());
    7878                    tree.updateTree(wms);
    79                     formats.setModel(new DefaultComboBoxModel(wms.getFormats().toArray()));
     79                    formats.setModel(new DefaultComboBoxModel<>(wms.getFormats().toArray(new String[0])));
    8080                    formats.setSelectedItem(wms.getPreferredFormats());
    8181                } catch (MalformedURLException ex) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java

    r5808 r7015  
    3030    private final JButton btnFadeColor;
    3131    private final JSlider fadeAmount = new JSlider(0, 100);
    32     private final JosmComboBox sharpen;
     32    private final JosmComboBox<String> sharpen;
    3333
    3434    /**
     
    6565        add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL));
    6666
    67         this.sharpen = new JosmComboBox(new String[] {
     67        this.sharpen = new JosmComboBox<>(new String[] {
    6868                tr("None"),
    6969                tr("Soft"),
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/WMSSettingsPanel.java

    r6460 r7015  
    2727    // WMS Settings
    2828    private final JCheckBox autozoomActive;
    29     private final JosmComboBox browser;
     29    private final JosmComboBox<String> browser;
    3030    private final JCheckBox overlapCheckBox;
    3131    private final JSpinner spinEast;
     
    4646
    4747        // Downloader
    48         browser = new JosmComboBox(new String[] {
     48        browser = new JosmComboBox<>(new String[] {
    4949                "webkit-image {0}",
    5050                "gnome-web-photo --mode=photo --format=png {0} /dev/stdout",
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CodeProjectionChoice.java

    r7005 r7015  
    115115            filter.getDocument().addDocumentListener(this);
    116116
    117             selectionList = new JList(data.toArray());
     117            selectionList = new JList<>(data.toArray(new String[0]));
    118118            selectionList.setModel(model = new ProjectionCodeListModel());
    119119            JScrollPane scroll = new JScrollPane(selectionList);
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertCC9ZonesProjectionChoice.java

    r6792 r7015  
    3737
    3838    private class LambertCC9CBPanel extends CBPanel {
    39         public LambertCC9CBPanel(Object[] entries, int initialIndex, String label, ActionListener listener) {
     39        public LambertCC9CBPanel(String[] entries, int initialIndex, String label, ActionListener listener) {
    4040            super(entries, initialIndex, label, listener);
    4141            this.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));
     
    8585
    8686    @Override
    87     protected String indexToZone(int index) {
    88         return Integer.toString(index + 1);
     87    protected String indexToZone(int idx) {
     88        return Integer.toString(idx + 1);
    8989    }
    9090
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertProjectionChoice.java

    r6792 r7015  
    3232
    3333    private class LambertCBPanel extends CBPanel {
    34         public LambertCBPanel(Object[] entries, int initialIndex, String label, ActionListener listener) {
     34        public LambertCBPanel(String[] entries, int initialIndex, String label, ActionListener listener) {
    3535            super(entries, initialIndex, label, listener);
    3636            this.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));
     
    7979
    8080    @Override
    81     protected String indexToZone(int index) {
    82         return Integer.toString(index + 1);
     81    protected String indexToZone(int idx) {
     82        return Integer.toString(idx + 1);
    8383    }
    8484
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java

    r6889 r7015  
    2121    protected int index;        // 0-based index
    2222    protected int defaultIndex;
    23     protected Object[] entries;
     23    protected String[] entries;
    2424    protected String label;
    2525
     
    3333     * @param defaultIndex the default index for the combo-box
    3434     */
    35     public ListProjectionChoice(String name, String id, Object[] entries, String label, int defaultIndex) {
     35    public ListProjectionChoice(String name, String id, String[] entries, String label, int defaultIndex) {
    3636        super(name, id);
    3737        this.entries = Utils.copyArray(entries);
     
    4747     * @param label a label shown left to the combo-box
    4848     */
    49     public ListProjectionChoice(String name, String id, Object[] entries, String label) {
     49    public ListProjectionChoice(String name, String id, String[] entries, String label) {
    5050        this(name, id, entries, label, 0);
    5151    }
     
    5454     * Convert 0-based index to preference value.
    5555     */
    56     protected abstract String indexToZone(int index);
     56    protected abstract String indexToZone(int idx);
    5757
    5858    /**
     
    6767            zone = args.iterator().next();
    6868        }
    69         int index;
     69        int idx;
    7070        if (zone == null) {
    71             index = defaultIndex;
     71            idx = defaultIndex;
    7272        } else {
    73             index = zoneToIndex(zone);
    74             if (index < 0 || index >= entries.length) {
    75                 index = defaultIndex;
     73            idx = zoneToIndex(zone);
     74            if (idx < 0 || idx >= entries.length) {
     75                idx = defaultIndex;
    7676            }
    7777        }
    78         this.index = index;
     78        this.index = idx;
    7979    }
    8080
    8181    protected class CBPanel extends JPanel {
    82         public JosmComboBox prefcb;
     82        public JosmComboBox<String> prefcb;
    8383
    84         public CBPanel(Object[] entries, int initialIndex, String label, final ActionListener listener) {
    85             prefcb = new JosmComboBox(entries);
     84        public CBPanel(String[] entries, int initialIndex, String label, final ActionListener listener) {
     85            prefcb = new JosmComboBox<>(entries);
    8686
    8787            prefcb.setSelectedIndex(initialIndex);
     
    109109        }
    110110        CBPanel p = (CBPanel) panel;
    111         int index = p.prefcb.getSelectedIndex();
    112         return Collections.singleton(indexToZone(index));
     111        int idx = p.prefcb.getSelectedIndex();
     112        return Collections.singleton(indexToZone(idx));
    113113    }
    114 
    115114}
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r7005 r7015  
    258258     * Combobox with all projections available
    259259     */
    260     private final JosmComboBox projectionCombo = new JosmComboBox(projectionChoices.toArray());
     260    private final JosmComboBox<ProjectionChoice> projectionCombo = new JosmComboBox<>(projectionChoices.toArray(new ProjectionChoice[0]));
    261261
    262262    /**
    263263     * Combobox with all coordinate display possibilities
    264264     */
    265     private final JosmComboBox coordinatesCombo = new JosmComboBox(CoordinateFormat.values());
    266 
    267     private final JosmComboBox unitsCombo = new JosmComboBox(unitsValuesTr);
     265    private final JosmComboBox<CoordinateFormat> coordinatesCombo = new JosmComboBox<>(CoordinateFormat.values());
     266
     267    private final JosmComboBox<String> unitsCombo = new JosmComboBox<>(unitsValuesTr);
    268268
    269269    /**
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMProjectionChoice.java

    r7005 r7015  
    4444     */
    4545    public UTMProjectionChoice() {
    46         super(tr("UTM"), "core:utm", cbEntries.toArray(), tr("UTM Zone"));
     46        super(tr("UTM"), "core:utm", cbEntries.toArray(new String[0]), tr("UTM Zone"));
    4747    }
    4848
     
    5151        public JRadioButton north, south;
    5252
    53         public UTMPanel(Object[] entries, int initialIndex, String label, ActionListener listener) {
     53        public UTMPanel(String[] entries, int initialIndex, String label, ActionListener listener) {
    5454            super(entries, initialIndex, label, listener);
    5555
    56             //Hemisphere
    5756            north = new JRadioButton();
    5857            north.setSelected(hemisphere == Hemisphere.North);
     
    110109        }
    111110        UTMPanel p = (UTMPanel) panel;
    112         int index = p.prefcb.getSelectedIndex();
    113         Hemisphere hemisphere = p.south.isSelected()?Hemisphere.South:Hemisphere.North;
    114         return Arrays.asList(indexToZone(index), hemisphere.toString());
     111        int idx = p.prefcb.getSelectedIndex();
     112        Hemisphere hem = p.south.isSelected()?Hemisphere.South:Hemisphere.North;
     113        return Arrays.asList(indexToZone(idx), hem.toString());
    115114    }
    116115
     
    119118        List<String> projections = new ArrayList<>(60*4);
    120119        for (int zone = 1;zone <= 60; zone++) {
    121             for (Hemisphere hemisphere : Hemisphere.values()) {
    122                 projections.add("EPSG:" + (32600 + zone + (hemisphere == Hemisphere.South?100:0)));
     120            for (Hemisphere hem : Hemisphere.values()) {
     121                projections.add("EPSG:" + (32600 + zone + (hem == Hemisphere.South?100:0)));
    123122            }
    124123        }
     
    131130        if (code.startsWith("EPSG:326") || code.startsWith("EPSG:327")) {
    132131            try {
    133                 Hemisphere hemisphere = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South;
     132                Hemisphere hem = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South;
    134133                String zonestring = code.substring(8);
    135134                int zoneval = Integer.parseInt(zonestring);
    136135                if(zoneval > 0 && zoneval <= 60)
    137                     return Arrays.asList(zonestring, hemisphere.toString());
     136                    return Arrays.asList(zonestring, hem.toString());
    138137            } catch(NumberFormatException e) {
    139138                Main.warn(e);
     
    146145    public void setPreferences(Collection<String> args) {
    147146        super.setPreferences(args);
    148         Hemisphere hemisphere = DEFAULT_HEMISPHERE;
     147        Hemisphere hem = DEFAULT_HEMISPHERE;
    149148
    150149        if (args != null) {
     
    152151
    153152            if (array.length > 1) {
    154                 hemisphere = Hemisphere.valueOf(array[1]);
     153                hem = Hemisphere.valueOf(array[1]);
    155154            }
    156155        }
    157         this.hemisphere = hemisphere;
     156        this.hemisphere = hem;
    158157    }
    159158
    160159    @Override
    161     protected String indexToZone(int index) {
    162         return Integer.toString(index + 1);
     160    protected String indexToZone(int idx) {
     161        return Integer.toString(idx + 1);
    163162    }
    164163
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r7005 r7015  
    9797    private JCheckBox cbDefault = new JCheckBox();
    9898    private JCheckBox cbDisable = new JCheckBox();
    99     private JosmComboBox tfKey = new JosmComboBox();
     99    private JosmComboBox<String> tfKey = new JosmComboBox<>();
    100100
    101101    JTable shortcutTable = new JTable();
     
    218218        cbAlt.setText(ALT); // see above for why no tr()
    219219        tfKey.setAction(action);
    220         tfKey.setModel(new DefaultComboBoxModel(keyList.values().toArray()));
     220        tfKey.setModel(new DefaultComboBoxModel<>(keyList.values().toArray(new String[0])));
    221221        cbMeta.setAction(action);
    222222        cbMeta.setText(META); // see above for why no tr()
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r7005 r7015  
    618618            } else {
    619619                // the objects have different values
    620                 JosmComboBox comboBox = new JosmComboBox(usage.values.toArray());
     620                JosmComboBox<String> comboBox = new JosmComboBox<>(usage.values.toArray(new String[0]));
    621621                comboBox.setEditable(true);
    622622                comboBox.setEditor(textField);
     
    697697        private static String getValue(Component comp) {
    698698            if (comp instanceof JosmComboBox) {
    699                 return ((JosmComboBox) comp).getEditor().getItem().toString();
     699                return ((JosmComboBox<?>) comp).getEditor().getItem().toString();
    700700            } else if (comp instanceof JosmTextField) {
    701701                return ((JosmTextField) comp).getText();
     
    11741174
    11751175        public boolean editable = true;
    1176         protected JosmComboBox combo;
     1176        protected JosmComboBox<PresetListEntry> combo;
    11771177        public String length;
    11781178
     
    11981198            lhm.put("", new PresetListEntry(""));
    11991199
    1200             combo = new JosmComboBox(lhm.values().toArray());
     1200            combo = new JosmComboBox<>(lhm.values().toArray(new PresetListEntry[0]));
    12011201            component = combo;
    12021202            combo.setRenderer(getListCellRenderer());
     
    12651265        @Override
    12661266        protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
    1267             list = new ConcatenatingJList(delimiter, lhm.values().toArray());
     1267            list = new ConcatenatingJList(delimiter, lhm.values().toArray(new PresetListEntry[0]));
    12681268            component = list;
    1269             ListCellRenderer renderer = getListCellRenderer();
     1269            ListCellRenderer<PresetListEntry> renderer = getListCellRenderer();
    12701270            list.setCellRenderer(renderer);
    12711271
     
    13151315    * string (extracted from TaggingPreset)
    13161316    */
    1317     private static class ConcatenatingJList extends JList {
     1317    private static class ConcatenatingJList extends JList<PresetListEntry> {
    13181318        private String delimiter;
    1319         public ConcatenatingJList(String del, Object[] o) {
     1319        public ConcatenatingJList(String del, PresetListEntry[] o) {
    13201320            super(o);
    13211321            delimiter = del;
     
    13281328                String s = o.toString();
    13291329                TreeSet<String> parts = new TreeSet<>(Arrays.asList(s.split(delimiter)));
    1330                 ListModel lm = getModel();
     1330                ListModel<PresetListEntry> lm = getModel();
    13311331                int[] intParts = new int[lm.getSize()];
    13321332                int j = 0;
    13331333                for (int i = 0; i < lm.getSize(); i++) {
    1334                     if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value))) {
     1334                    if (parts.contains((lm.getElementAt(i).value))) {
    13351335                        intParts[j++]=i;
    13361336                    }
     
    13451345
    13461346        public String getSelectedItem() {
    1347             ListModel lm = getModel();
     1347            ListModel<PresetListEntry> lm = getModel();
    13481348            int[] si = getSelectedIndices();
    13491349            StringBuilder builder = new StringBuilder();
     
    13521352                    builder.append(delimiter);
    13531353                }
    1354                 builder.append(((PresetListEntry)lm.getElementAt(si[i])).value);
     1354                builder.append(lm.getElementAt(si[i]).value);
    13551355            }
    13561356            return builder.toString();
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSelector.java

    r7005 r7015  
    8282    private static class ResultListCellRenderer extends DefaultListCellRenderer {
    8383        @Override
    84         public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
    85                 boolean cellHasFocus) {
     84        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    8685            JLabel result = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    8786            TaggingPreset tp = (TaggingPreset)value;
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r7001 r7015  
    3030 * @author guilhem.bonnefille@gmail.com
    3131 */
    32 public class AutoCompletingComboBox extends JosmComboBox {
     32public class AutoCompletingComboBox extends JosmComboBox<AutoCompletionListItem> {
    3333
    3434    private boolean autocompleteEnabled = true;
     
    4343     */
    4444    class AutoCompletingComboBoxDocument extends PlainDocument {
    45         private JosmComboBox comboBox;
     45        private JosmComboBox<AutoCompletionListItem> comboBox;
    4646        private boolean selecting = false;
    4747
    48         public AutoCompletingComboBoxDocument(final JosmComboBox comboBox) {
     48        public AutoCompletingComboBoxDocument(final JosmComboBox<AutoCompletionListItem> comboBox) {
    4949            this.comboBox = comboBox;
    5050        }
     
    114114                }
    115115            }
    116             JTextComponent editor = (JTextComponent)comboBox.getEditor().getEditorComponent();
     116            JTextComponent editorComponent = (JTextComponent)comboBox.getEditor().getEditorComponent();
    117117            // save unix system selection (middle mouse paste)
    118118            Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
    119119            if(sysSel != null) {
    120120                Transferable old = sysSel.getContents(null);
    121                 editor.select(start, end);
     121                editorComponent.select(start, end);
    122122                sysSel.setContents(old, null);
    123123            } else {
    124                 editor.select(start, end);
     124                editorComponent.select(start, end);
    125125            }
    126126        }
     
    133133
    134134        private Object lookupItem(String pattern, boolean match) {
    135             ComboBoxModel model = comboBox.getModel();
     135            ComboBoxModel<AutoCompletionListItem> model = comboBox.getModel();
    136136            AutoCompletionListItem bestItem = null;
    137137            for (int i = 0, n = model.getSize(); i < n; i++) {
     
    153153     */
    154154    public AutoCompletingComboBox() {
    155         this(JosmComboBox.DEFAULT_PROTOTYPE_DISPLAY_VALUE);
     155        this("Foo");
    156156    }
    157157
     
    165165        super(new AutoCompletionListItem(prototype));
    166166        setRenderer(new AutoCompleteListCellRenderer());
    167         final JTextComponent editor = (JTextComponent) this.getEditor().getEditorComponent();
    168         editor.setDocument(new AutoCompletingComboBoxDocument(this));
    169         editor.addFocusListener(
     167        final JTextComponent editorComponent = (JTextComponent) this.getEditor().getEditorComponent();
     168        editorComponent.setDocument(new AutoCompletingComboBoxDocument(this));
     169        editorComponent.addFocusListener(
    170170                new FocusListener() {
    171171                    @Override
     
    178178                        if(sysSel != null) {
    179179                            Transferable old = sysSel.getContents(null);
    180                             editor.selectAll();
     180                            editorComponent.selectAll();
    181181                            sysSel.setContents(old, null);
    182182                        } else {
    183                             editor.selectAll();
     183                            editorComponent.selectAll();
    184184                        }
    185185                    }
     
    188188    }
    189189
    190     public void setMaxTextLength(int length)
    191     {
     190    public void setMaxTextLength(int length) {
    192191        this.maxTextLength = length;
    193192    }
    194193
    195194    /**
    196      * Convert the selected item into a String
    197      * that can be edited in the editor component.
     195     * Convert the selected item into a String that can be edited in the editor component.
    198196     *
    199      * @param editor    the editor
     197     * @param cbEditor    the editor
    200198     * @param item      excepts AutoCompletionListItem, String and null
    201199     */
    202     @Override public void configureEditor(ComboBoxEditor editor, Object item) {
     200    @Override
     201    public void configureEditor(ComboBoxEditor cbEditor, Object item) {
    203202        if (item == null) {
    204             editor.setItem(null);
     203            cbEditor.setItem(null);
    205204        } else if (item instanceof String) {
    206             editor.setItem(item);
     205            cbEditor.setItem(item);
    207206        } else if (item instanceof AutoCompletionListItem) {
    208             editor.setItem(((AutoCompletionListItem)item).getValue());
     207            cbEditor.setItem(((AutoCompletionListItem)item).getValue());
    209208        } else
    210209            throw new IllegalArgumentException();
     
    215214     * @param item      excepts AutoCompletionListItem, String and null
    216215     */
    217     @Override public void setSelectedItem(Object item) {
     216    @Override
     217    public void setSelectedItem(Object item) {
    218218        if (item == null) {
    219219            super.setSelectedItem(null);
     
    239239     */
    240240    public void setPossibleItems(Collection<String> elems) {
    241         DefaultComboBoxModel model = (DefaultComboBoxModel)this.getModel();
     241        DefaultComboBoxModel<AutoCompletionListItem> model = (DefaultComboBoxModel<AutoCompletionListItem>)this.getModel();
    242242        Object oldValue = this.getEditor().getItem(); // Do not use getSelectedItem(); (fix #8013)
    243243        model.removeAllElements();
     
    245245            model.addElement(new AutoCompletionListItem(elem, AutoCompletionItemPriority.UNKNOWN));
    246246        }
    247         // disable autocomplete to prevent unnecessary actions in
    248         // AutoCompletingComboBoxDocument#insertString
     247        // disable autocomplete to prevent unnecessary actions in AutoCompletingComboBoxDocument#insertString
    249248        autocompleteEnabled = false;
    250249        this.getEditor().setItem(oldValue); // Do not use setSelectedItem(oldValue); (fix #8013)
     
    256255     */
    257256    public void setPossibleACItems(Collection<AutoCompletionListItem> elems) {
    258         DefaultComboBoxModel model = (DefaultComboBoxModel)this.getModel();
     257        DefaultComboBoxModel<AutoCompletionListItem> model = (DefaultComboBoxModel<AutoCompletionListItem>)this.getModel();
    259258        Object oldValue = getSelectedItem();
    260259        Object editorOldValue = this.getEditor().getItem();
     
    266265        this.getEditor().setItem(editorOldValue);
    267266    }
    268 
    269267
    270268    protected boolean isAutocompleteEnabled() {
  • trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java

    r7005 r7015  
    1010import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    1111
    12 public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<AutoCompletionListItem> {
     12public class ComboBoxHistory extends DefaultComboBoxModel<AutoCompletionListItem> implements Iterable<AutoCompletionListItem> {
    1313
    1414    private int maxSize = 10;
     
    2020    }
    2121
     22    public void addElement(String s) {
     23        addElement(new AutoCompletionListItem(s));
     24    }
     25   
    2226    /**
    2327     * Adds or moves an element to the top of the history
    2428     */
    2529    @Override
    26     public void addElement(Object o) {
    27         if (o instanceof String) {
    28             o = new AutoCompletionListItem((String) o);
    29         }
    30 
     30    public void addElement(AutoCompletionListItem o) {
    3131        String newEntry = ((AutoCompletionListItem)o).getValue();
    3232
     
    7777                return (AutoCompletionListItem)getElementAt(position);
    7878            }
    79 
    8079        };
    8180    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBox.java

    r4018 r7015  
    1414    public static final int DEFAULT_SEARCH_HISTORY_SIZE = 15;
    1515
     16    /**
     17     * Constructs a new {@code HistoryComboBox}.
     18     */
    1619    public HistoryComboBox() {
    1720        int maxsize = Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE);
     
    3134
    3235    public void addCurrentItemToHistory() {
    33         String regex = (String)getEditor().getItem();
    34         model.addElement(regex);
     36        model.addElement((String)getEditor().getItem());
    3537    }
    3638
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java

    r7005 r7015  
    1515
    1616import javax.accessibility.Accessible;
    17 import javax.swing.ComboBoxEditor;
    1817import javax.swing.ComboBoxModel;
    1918import javax.swing.DefaultComboBoxModel;
     
    2625 * Class overriding each {@link JComboBox} in JOSM to control consistently the number of displayed items at once.<br>
    2726 * This is needed because of the default Java behaviour that may display the top-down list off the screen (see #7917).
     27 * @param <E> the type of the elements of this combo box
    2828 *
    29  * @since 5429
     29 * @since 5429 (creation)
     30 * @since 7015 (generics for Java 7)
    3031 */
    31 public class JosmComboBox extends JComboBox {
    32 
    33     /**
    34      * The default prototype value used to compute the maximum number of elements to be displayed at once before
    35      * displaying a scroll bar
    36      */
    37     public static final String DEFAULT_PROTOTYPE_DISPLAY_VALUE = "Prototype display value";
     32public class JosmComboBox<E> extends JComboBox<E> {
    3833
    3934    /**
     
    4641     */
    4742    public JosmComboBox() {
    48         this(DEFAULT_PROTOTYPE_DISPLAY_VALUE);
     43        init(null);
    4944    }
    5045
     
    6358     * @since 5450
    6459     */
    65     public JosmComboBox(Object prototypeDisplayValue) {
    66         super();
     60    public JosmComboBox(E prototypeDisplayValue) {
    6761        init(prototypeDisplayValue);
    6862    }
     
    7973     * @see DefaultComboBoxModel
    8074     */
    81     public JosmComboBox(ComboBoxModel aModel) {
     75    public JosmComboBox(ComboBoxModel<E> aModel) {
    8276        super(aModel);
    83         List<Object> list = new ArrayList<>(aModel.getSize());
     77        List<E> list = new ArrayList<>(aModel.getSize());
    8478        for (int i = 0; i<aModel.getSize(); i++) {
    8579            list.add(aModel.getElementAt(i));
     
    9690     * @see DefaultComboBoxModel
    9791     */
    98     public JosmComboBox(Object[] items) {
     92    public JosmComboBox(E[] items) {
    9993        super(items);
    10094        init(findPrototypeDisplayValue(Arrays.asList(items)));
     
    107101     * @since 5558
    108102     */
    109     protected final Object findPrototypeDisplayValue(Collection<?> possibleValues) {
    110         Object result = null;
     103    protected final E findPrototypeDisplayValue(Collection<E> possibleValues) {
     104        E result = null;
    111105        int maxHeight = -1;
    112106        if (possibleValues != null) {
    113107            // Remind old prototype to restore it later
    114             Object oldPrototype = getPrototypeDisplayValue();
     108            E oldPrototype = getPrototypeDisplayValue();
    115109            // Get internal JList to directly call the renderer
    116             JList list = getList();
     110            JList<E> list = getList();
    117111            try {
    118112                // Index to give to renderer
    119113                int i = 0;
    120                 for (Object value : possibleValues) {
     114                for (E value : possibleValues) {
    121115                    if (value != null) {
    122116                        // With a "classic" renderer, we could call setPrototypeDisplayValue(value) + getPreferredSize()
     
    144138    }
    145139
    146     protected final JList getList() {
     140    @SuppressWarnings("unchecked")
     141    protected final JList<E> getList() {
    147142        for (int i = 0; i < getUI().getAccessibleChildrenCount(this); i++) {
    148143            Accessible child = getUI().getAccessibleChild(this, i);
     
    154149    }
    155150
    156     protected final void init(Object prototype) {
     151    protected final void init(E prototype) {
    157152        if (prototype != null) {
    158153            setPrototypeDisplayValue(prototype);
     
    163158            // If possible, adjust the maximum number of items with the real height of items
    164159            // It is not granted this works on every platform (tested OK on Windows)
    165             JList list = getList();
     160            JList<E> list = getList();
    166161            if (list != null) {
    167162                if (list.getPrototypeCellValue() != prototype) {
     
    203198        private void enableMenu() {
    204199            if (launcher == null) {
    205                 ComboBoxEditor editor = getEditor();
    206200                if (editor != null) {
    207201                    Component editorComponent = editor.getEditorComponent();
     
    224218        }
    225219
    226         @Override public void mousePressed(MouseEvent e) { processEvent(e); }
    227         @Override public void mouseReleased(MouseEvent e) { processEvent(e); }
     220        @Override
     221        public void mousePressed(MouseEvent e) {
     222            processEvent(e);
     223        }
     224
     225        @Override
     226        public void mouseReleased(MouseEvent e) {
     227            processEvent(e);
     228        }
    228229
    229230        private void processEvent(MouseEvent e) {
     
    241242     * @since 5558
    242243     */
    243     public final void reinitialize(Collection<?> values) {
     244    public final void reinitialize(Collection<E> values) {
    244245        init(findPrototypeDisplayValue(values));
    245246    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitiveTypesComboBox.java

    r5453 r7015  
    1010 * @since 2923
    1111 */
    12 public class OsmPrimitiveTypesComboBox extends JosmComboBox {
     12public class OsmPrimitiveTypesComboBox extends JosmComboBox<Object> {
    1313
    1414    /**
Note: See TracChangeset for help on using the changeset viewer.