- Timestamp:
- 2014-04-27T17:34:22+02:00 (11 years ago)
- 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 48 48 49 49 /** the combo box used as editor */ 50 private JosmComboBox editor;51 private DefaultComboBoxModel editorModel;50 private JosmComboBox<Object> editor; 51 private DefaultComboBoxModel<Object> editorModel; 52 52 private CopyOnWriteArrayList<NavigationListener> listeners; 53 53 … … 78 78 */ 79 79 public MultiValueCellEditor() { 80 editorModel = new DefaultComboBoxModel ();81 editor = new JosmComboBox (editorModel) {80 editorModel = new DefaultComboBoxModel<>(); 81 editor = new JosmComboBox<Object>(editorModel) { 82 82 @Override 83 83 public void processKeyEvent(KeyEvent e) { … … 172 172 * 173 173 */ 174 private static class EditorCellRenderer extends JLabel implements ListCellRenderer {174 private static class EditorCellRenderer extends JLabel implements ListCellRenderer<Object> { 175 175 176 176 /** … … 224 224 225 225 @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) { 227 227 renderColors(isSelected); 228 228 renderValue(value); -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictDecisionEditor.java
r6912 r7015 12 12 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 13 13 14 public class RelationMemberConflictDecisionEditor extends JosmComboBox implements TableCellEditor {14 public class RelationMemberConflictDecisionEditor extends JosmComboBox<RelationMemberConflictDecisionType> implements TableCellEditor { 15 15 16 16 /** -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r7005 r7015 154 154 * @see Arrays#asList(Object[]) 155 155 */ 156 public static List list(Object... args) {156 public static List<Object> list(Object... args) { 157 157 return Arrays.asList(args); 158 158 } -
trunk/src/org/openstreetmap/josm/gui/oauth/AuthorizationProcedureComboBox.java
r7001 r7015 13 13 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 14 14 15 public class AuthorizationProcedureComboBox extends JosmComboBox {15 public class AuthorizationProcedureComboBox extends JosmComboBox<AuthorizationProcedure> { 16 16 17 17 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java
r6890 r7015 61 61 private JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)")); 62 62 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")}); 64 64 private JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX")); 65 65 private JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows")); … … 67 67 private JosmTextField drawGpsArrowsMinDist = new JosmTextField(8); 68 68 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); 70 70 private JosmTextField waypointLabelPattern = new JosmTextField(); 71 private JosmComboBox audioWaypointLabel = new JosmComboBox(LABEL_PATTERN_DESC);71 private JosmComboBox<String> audioWaypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC); 72 72 private JosmTextField audioWaypointLabelPattern = new JosmTextField(); 73 73 private JCheckBox useGpsAntialiasing = new JCheckBox(tr("Smooth GPX graphics (antialiasing)")); … … 368 368 } 369 369 370 371 370 /** 372 371 * Save preferences from UI controls, globally or for a specified layer. … … 443 442 } 444 443 445 private void updateWaypointLabelCombobox(JosmComboBox cb, JosmTextField tf, TemplateEntryProperty property) {444 private void updateWaypointLabelCombobox(JosmComboBox<String> cb, JosmTextField tf, TemplateEntryProperty property) { 446 445 String labelPattern = property.getAsString(); 447 446 boolean found = false; … … 460 459 } 461 460 462 private void updateWaypointPattern(JosmComboBox cb, JosmTextField tf) {461 private void updateWaypointPattern(JosmComboBox<String> cb, JosmTextField tf) { 463 462 if (cb.getSelectedIndex() == WAYPOINT_LABEL_CUSTOM) { 464 463 tf.setEnabled(true); -
trunk/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java
r6957 r7015 49 49 * ComboBox with all look and feels. 50 50 */ 51 private JosmComboBox lafCombo;51 private JosmComboBox<LookAndFeelInfo> lafCombo; 52 52 JPanel panel; 53 53 private JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup")); … … 59 59 @Override 60 60 public void addGui(PreferenceTabbedPane gui) { 61 lafCombo = new JosmComboBox (UIManager.getInstalledLookAndFeels());61 lafCombo = new JosmComboBox<>(UIManager.getInstalledLookAndFeels()); 62 62 63 63 // 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 44 44 45 45 /** the combo box with the available locales */ 46 private JosmComboBox langCombo;46 private JosmComboBox<Locale> langCombo; 47 47 48 48 @Override … … 52 52 // See https://stackoverflow.com/questions/3194958/fast-replacement-for-jcombobox-basiccomboboxui 53 53 model.selectLanguage(Main.pref.get("language")); 54 langCombo = new JosmComboBox (model);54 langCombo = new JosmComboBox<>(model); 55 55 langCombo.setRenderer(new LanguageCellRenderer(langCombo.getRenderer())); 56 56 … … 75 75 } 76 76 77 private static class LanguageComboBoxModel extends DefaultComboBoxModel {77 private static class LanguageComboBoxModel extends DefaultComboBoxModel<Locale> { 78 78 private final List<Locale> data = new ArrayList<>(); 79 79 … … 99 99 100 100 @Override 101 public ObjectgetElementAt(int index) {101 public Locale getElementAt(int index) { 102 102 return data.get(index); 103 103 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java
r6930 r7015 38 38 private final JCheckBox endpoint = new JCheckBox(tr("Store WMS endpoint only, select layers at usage")); 39 39 private final WMSLayerTree tree = new WMSLayerTree(); 40 private final JComboBox formats = new JComboBox();40 private final JComboBox<String> formats = new JComboBox<>(); 41 41 private final JLabel wmsInstruction; 42 42 private final JosmTextArea wmsUrl = new JosmTextArea(3, 40); … … 77 77 wms.attemptGetCapabilities(rawUrl.getText()); 78 78 tree.updateTree(wms); 79 formats.setModel(new DefaultComboBoxModel (wms.getFormats().toArray()));79 formats.setModel(new DefaultComboBoxModel<>(wms.getFormats().toArray(new String[0]))); 80 80 formats.setSelectedItem(wms.getPreferredFormats()); 81 81 } catch (MalformedURLException ex) { -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java
r5808 r7015 30 30 private final JButton btnFadeColor; 31 31 private final JSlider fadeAmount = new JSlider(0, 100); 32 private final JosmComboBox sharpen;32 private final JosmComboBox<String> sharpen; 33 33 34 34 /** … … 65 65 add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL)); 66 66 67 this.sharpen = new JosmComboBox (new String[] {67 this.sharpen = new JosmComboBox<>(new String[] { 68 68 tr("None"), 69 69 tr("Soft"), -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/WMSSettingsPanel.java
r6460 r7015 27 27 // WMS Settings 28 28 private final JCheckBox autozoomActive; 29 private final JosmComboBox browser;29 private final JosmComboBox<String> browser; 30 30 private final JCheckBox overlapCheckBox; 31 31 private final JSpinner spinEast; … … 46 46 47 47 // Downloader 48 browser = new JosmComboBox (new String[] {48 browser = new JosmComboBox<>(new String[] { 49 49 "webkit-image {0}", 50 50 "gnome-web-photo --mode=photo --format=png {0} /dev/stdout", -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/CodeProjectionChoice.java
r7005 r7015 115 115 filter.getDocument().addDocumentListener(this); 116 116 117 selectionList = new JList (data.toArray());117 selectionList = new JList<>(data.toArray(new String[0])); 118 118 selectionList.setModel(model = new ProjectionCodeListModel()); 119 119 JScrollPane scroll = new JScrollPane(selectionList); -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertCC9ZonesProjectionChoice.java
r6792 r7015 37 37 38 38 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) { 40 40 super(entries, initialIndex, label, listener); 41 41 this.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones.png")), GBC.eol().fill(GBC.HORIZONTAL)); … … 85 85 86 86 @Override 87 protected String indexToZone(int i ndex) {88 return Integer.toString(i ndex + 1);87 protected String indexToZone(int idx) { 88 return Integer.toString(idx + 1); 89 89 } 90 90 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertProjectionChoice.java
r6792 r7015 32 32 33 33 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) { 35 35 super(entries, initialIndex, label, listener); 36 36 this.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL)); … … 79 79 80 80 @Override 81 protected String indexToZone(int i ndex) {82 return Integer.toString(i ndex + 1);81 protected String indexToZone(int idx) { 82 return Integer.toString(idx + 1); 83 83 } 84 84 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java
r6889 r7015 21 21 protected int index; // 0-based index 22 22 protected int defaultIndex; 23 protected Object[] entries;23 protected String[] entries; 24 24 protected String label; 25 25 … … 33 33 * @param defaultIndex the default index for the combo-box 34 34 */ 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) { 36 36 super(name, id); 37 37 this.entries = Utils.copyArray(entries); … … 47 47 * @param label a label shown left to the combo-box 48 48 */ 49 public ListProjectionChoice(String name, String id, Object[] entries, String label) {49 public ListProjectionChoice(String name, String id, String[] entries, String label) { 50 50 this(name, id, entries, label, 0); 51 51 } … … 54 54 * Convert 0-based index to preference value. 55 55 */ 56 protected abstract String indexToZone(int i ndex);56 protected abstract String indexToZone(int idx); 57 57 58 58 /** … … 67 67 zone = args.iterator().next(); 68 68 } 69 int i ndex;69 int idx; 70 70 if (zone == null) { 71 i ndex = defaultIndex;71 idx = defaultIndex; 72 72 } else { 73 i ndex = zoneToIndex(zone);74 if (i ndex < 0 || index >= entries.length) {75 i ndex = defaultIndex;73 idx = zoneToIndex(zone); 74 if (idx < 0 || idx >= entries.length) { 75 idx = defaultIndex; 76 76 } 77 77 } 78 this.index = i ndex;78 this.index = idx; 79 79 } 80 80 81 81 protected class CBPanel extends JPanel { 82 public JosmComboBox prefcb;82 public JosmComboBox<String> prefcb; 83 83 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); 86 86 87 87 prefcb.setSelectedIndex(initialIndex); … … 109 109 } 110 110 CBPanel p = (CBPanel) panel; 111 int i ndex = p.prefcb.getSelectedIndex();112 return Collections.singleton(indexToZone(i ndex));111 int idx = p.prefcb.getSelectedIndex(); 112 return Collections.singleton(indexToZone(idx)); 113 113 } 114 115 114 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r7005 r7015 258 258 * Combobox with all projections available 259 259 */ 260 private final JosmComboBox projectionCombo = new JosmComboBox(projectionChoices.toArray());260 private final JosmComboBox<ProjectionChoice> projectionCombo = new JosmComboBox<>(projectionChoices.toArray(new ProjectionChoice[0])); 261 261 262 262 /** 263 263 * Combobox with all coordinate display possibilities 264 264 */ 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); 268 268 269 269 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMProjectionChoice.java
r7005 r7015 44 44 */ 45 45 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")); 47 47 } 48 48 … … 51 51 public JRadioButton north, south; 52 52 53 public UTMPanel( Object[] entries, int initialIndex, String label, ActionListener listener) {53 public UTMPanel(String[] entries, int initialIndex, String label, ActionListener listener) { 54 54 super(entries, initialIndex, label, listener); 55 55 56 //Hemisphere57 56 north = new JRadioButton(); 58 57 north.setSelected(hemisphere == Hemisphere.North); … … 110 109 } 111 110 UTMPanel p = (UTMPanel) panel; 112 int i ndex = p.prefcb.getSelectedIndex();113 Hemisphere hem isphere= p.south.isSelected()?Hemisphere.South:Hemisphere.North;114 return Arrays.asList(indexToZone(i ndex), 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()); 115 114 } 116 115 … … 119 118 List<String> projections = new ArrayList<>(60*4); 120 119 for (int zone = 1;zone <= 60; zone++) { 121 for (Hemisphere hem isphere: Hemisphere.values()) {122 projections.add("EPSG:" + (32600 + zone + (hem isphere== Hemisphere.South?100:0)));120 for (Hemisphere hem : Hemisphere.values()) { 121 projections.add("EPSG:" + (32600 + zone + (hem == Hemisphere.South?100:0))); 123 122 } 124 123 } … … 131 130 if (code.startsWith("EPSG:326") || code.startsWith("EPSG:327")) { 132 131 try { 133 Hemisphere hem isphere= code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South;132 Hemisphere hem = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South; 134 133 String zonestring = code.substring(8); 135 134 int zoneval = Integer.parseInt(zonestring); 136 135 if(zoneval > 0 && zoneval <= 60) 137 return Arrays.asList(zonestring, hem isphere.toString());136 return Arrays.asList(zonestring, hem.toString()); 138 137 } catch(NumberFormatException e) { 139 138 Main.warn(e); … … 146 145 public void setPreferences(Collection<String> args) { 147 146 super.setPreferences(args); 148 Hemisphere hem isphere= DEFAULT_HEMISPHERE;147 Hemisphere hem = DEFAULT_HEMISPHERE; 149 148 150 149 if (args != null) { … … 152 151 153 152 if (array.length > 1) { 154 hem isphere= Hemisphere.valueOf(array[1]);153 hem = Hemisphere.valueOf(array[1]); 155 154 } 156 155 } 157 this.hemisphere = hem isphere;156 this.hemisphere = hem; 158 157 } 159 158 160 159 @Override 161 protected String indexToZone(int i ndex) {162 return Integer.toString(i ndex + 1);160 protected String indexToZone(int idx) { 161 return Integer.toString(idx + 1); 163 162 } 164 163 -
trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java
r7005 r7015 97 97 private JCheckBox cbDefault = new JCheckBox(); 98 98 private JCheckBox cbDisable = new JCheckBox(); 99 private JosmComboBox tfKey = new JosmComboBox();99 private JosmComboBox<String> tfKey = new JosmComboBox<>(); 100 100 101 101 JTable shortcutTable = new JTable(); … … 218 218 cbAlt.setText(ALT); // see above for why no tr() 219 219 tfKey.setAction(action); 220 tfKey.setModel(new DefaultComboBoxModel (keyList.values().toArray()));220 tfKey.setModel(new DefaultComboBoxModel<>(keyList.values().toArray(new String[0]))); 221 221 cbMeta.setAction(action); 222 222 cbMeta.setText(META); // see above for why no tr() -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r7005 r7015 618 618 } else { 619 619 // 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])); 621 621 comboBox.setEditable(true); 622 622 comboBox.setEditor(textField); … … 697 697 private static String getValue(Component comp) { 698 698 if (comp instanceof JosmComboBox) { 699 return ((JosmComboBox ) comp).getEditor().getItem().toString();699 return ((JosmComboBox<?>) comp).getEditor().getItem().toString(); 700 700 } else if (comp instanceof JosmTextField) { 701 701 return ((JosmTextField) comp).getText(); … … 1174 1174 1175 1175 public boolean editable = true; 1176 protected JosmComboBox combo;1176 protected JosmComboBox<PresetListEntry> combo; 1177 1177 public String length; 1178 1178 … … 1198 1198 lhm.put("", new PresetListEntry("")); 1199 1199 1200 combo = new JosmComboBox (lhm.values().toArray());1200 combo = new JosmComboBox<>(lhm.values().toArray(new PresetListEntry[0])); 1201 1201 component = combo; 1202 1202 combo.setRenderer(getListCellRenderer()); … … 1265 1265 @Override 1266 1266 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])); 1268 1268 component = list; 1269 ListCellRenderer renderer = getListCellRenderer();1269 ListCellRenderer<PresetListEntry> renderer = getListCellRenderer(); 1270 1270 list.setCellRenderer(renderer); 1271 1271 … … 1315 1315 * string (extracted from TaggingPreset) 1316 1316 */ 1317 private static class ConcatenatingJList extends JList {1317 private static class ConcatenatingJList extends JList<PresetListEntry> { 1318 1318 private String delimiter; 1319 public ConcatenatingJList(String del, Object[] o) {1319 public ConcatenatingJList(String del, PresetListEntry[] o) { 1320 1320 super(o); 1321 1321 delimiter = del; … … 1328 1328 String s = o.toString(); 1329 1329 TreeSet<String> parts = new TreeSet<>(Arrays.asList(s.split(delimiter))); 1330 ListModel lm = getModel();1330 ListModel<PresetListEntry> lm = getModel(); 1331 1331 int[] intParts = new int[lm.getSize()]; 1332 1332 int j = 0; 1333 1333 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))) { 1335 1335 intParts[j++]=i; 1336 1336 } … … 1345 1345 1346 1346 public String getSelectedItem() { 1347 ListModel lm = getModel();1347 ListModel<PresetListEntry> lm = getModel(); 1348 1348 int[] si = getSelectedIndices(); 1349 1349 StringBuilder builder = new StringBuilder(); … … 1352 1352 builder.append(delimiter); 1353 1353 } 1354 builder.append( ((PresetListEntry)lm.getElementAt(si[i])).value);1354 builder.append(lm.getElementAt(si[i]).value); 1355 1355 } 1356 1356 return builder.toString(); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSelector.java
r7005 r7015 82 82 private static class ResultListCellRenderer extends DefaultListCellRenderer { 83 83 @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) { 86 85 JLabel result = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 87 86 TaggingPreset tp = (TaggingPreset)value; -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r7001 r7015 30 30 * @author guilhem.bonnefille@gmail.com 31 31 */ 32 public class AutoCompletingComboBox extends JosmComboBox {32 public class AutoCompletingComboBox extends JosmComboBox<AutoCompletionListItem> { 33 33 34 34 private boolean autocompleteEnabled = true; … … 43 43 */ 44 44 class AutoCompletingComboBoxDocument extends PlainDocument { 45 private JosmComboBox comboBox;45 private JosmComboBox<AutoCompletionListItem> comboBox; 46 46 private boolean selecting = false; 47 47 48 public AutoCompletingComboBoxDocument(final JosmComboBox comboBox) {48 public AutoCompletingComboBoxDocument(final JosmComboBox<AutoCompletionListItem> comboBox) { 49 49 this.comboBox = comboBox; 50 50 } … … 114 114 } 115 115 } 116 JTextComponent editor = (JTextComponent)comboBox.getEditor().getEditorComponent();116 JTextComponent editorComponent = (JTextComponent)comboBox.getEditor().getEditorComponent(); 117 117 // save unix system selection (middle mouse paste) 118 118 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 119 119 if(sysSel != null) { 120 120 Transferable old = sysSel.getContents(null); 121 editor .select(start, end);121 editorComponent.select(start, end); 122 122 sysSel.setContents(old, null); 123 123 } else { 124 editor .select(start, end);124 editorComponent.select(start, end); 125 125 } 126 126 } … … 133 133 134 134 private Object lookupItem(String pattern, boolean match) { 135 ComboBoxModel model = comboBox.getModel();135 ComboBoxModel<AutoCompletionListItem> model = comboBox.getModel(); 136 136 AutoCompletionListItem bestItem = null; 137 137 for (int i = 0, n = model.getSize(); i < n; i++) { … … 153 153 */ 154 154 public AutoCompletingComboBox() { 155 this( JosmComboBox.DEFAULT_PROTOTYPE_DISPLAY_VALUE);155 this("Foo"); 156 156 } 157 157 … … 165 165 super(new AutoCompletionListItem(prototype)); 166 166 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( 170 170 new FocusListener() { 171 171 @Override … … 178 178 if(sysSel != null) { 179 179 Transferable old = sysSel.getContents(null); 180 editor .selectAll();180 editorComponent.selectAll(); 181 181 sysSel.setContents(old, null); 182 182 } else { 183 editor .selectAll();183 editorComponent.selectAll(); 184 184 } 185 185 } … … 188 188 } 189 189 190 public void setMaxTextLength(int length) 191 { 190 public void setMaxTextLength(int length) { 192 191 this.maxTextLength = length; 193 192 } 194 193 195 194 /** 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. 198 196 * 199 * @param editor the editor197 * @param cbEditor the editor 200 198 * @param item excepts AutoCompletionListItem, String and null 201 199 */ 202 @Override public void configureEditor(ComboBoxEditor editor, Object item) { 200 @Override 201 public void configureEditor(ComboBoxEditor cbEditor, Object item) { 203 202 if (item == null) { 204 editor.setItem(null);203 cbEditor.setItem(null); 205 204 } else if (item instanceof String) { 206 editor.setItem(item);205 cbEditor.setItem(item); 207 206 } else if (item instanceof AutoCompletionListItem) { 208 editor.setItem(((AutoCompletionListItem)item).getValue());207 cbEditor.setItem(((AutoCompletionListItem)item).getValue()); 209 208 } else 210 209 throw new IllegalArgumentException(); … … 215 214 * @param item excepts AutoCompletionListItem, String and null 216 215 */ 217 @Override public void setSelectedItem(Object item) { 216 @Override 217 public void setSelectedItem(Object item) { 218 218 if (item == null) { 219 219 super.setSelectedItem(null); … … 239 239 */ 240 240 public void setPossibleItems(Collection<String> elems) { 241 DefaultComboBoxModel model = (DefaultComboBoxModel)this.getModel();241 DefaultComboBoxModel<AutoCompletionListItem> model = (DefaultComboBoxModel<AutoCompletionListItem>)this.getModel(); 242 242 Object oldValue = this.getEditor().getItem(); // Do not use getSelectedItem(); (fix #8013) 243 243 model.removeAllElements(); … … 245 245 model.addElement(new AutoCompletionListItem(elem, AutoCompletionItemPriority.UNKNOWN)); 246 246 } 247 // disable autocomplete to prevent unnecessary actions in 248 // AutoCompletingComboBoxDocument#insertString 247 // disable autocomplete to prevent unnecessary actions in AutoCompletingComboBoxDocument#insertString 249 248 autocompleteEnabled = false; 250 249 this.getEditor().setItem(oldValue); // Do not use setSelectedItem(oldValue); (fix #8013) … … 256 255 */ 257 256 public void setPossibleACItems(Collection<AutoCompletionListItem> elems) { 258 DefaultComboBoxModel model = (DefaultComboBoxModel)this.getModel();257 DefaultComboBoxModel<AutoCompletionListItem> model = (DefaultComboBoxModel<AutoCompletionListItem>)this.getModel(); 259 258 Object oldValue = getSelectedItem(); 260 259 Object editorOldValue = this.getEditor().getItem(); … … 266 265 this.getEditor().setItem(editorOldValue); 267 266 } 268 269 267 270 268 protected boolean isAutocompleteEnabled() { -
trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java
r7005 r7015 10 10 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 11 11 12 public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<AutoCompletionListItem> {12 public class ComboBoxHistory extends DefaultComboBoxModel<AutoCompletionListItem> implements Iterable<AutoCompletionListItem> { 13 13 14 14 private int maxSize = 10; … … 20 20 } 21 21 22 public void addElement(String s) { 23 addElement(new AutoCompletionListItem(s)); 24 } 25 22 26 /** 23 27 * Adds or moves an element to the top of the history 24 28 */ 25 29 @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) { 31 31 String newEntry = ((AutoCompletionListItem)o).getValue(); 32 32 … … 77 77 return (AutoCompletionListItem)getElementAt(position); 78 78 } 79 80 79 }; 81 80 } -
trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBox.java
r4018 r7015 14 14 public static final int DEFAULT_SEARCH_HISTORY_SIZE = 15; 15 15 16 /** 17 * Constructs a new {@code HistoryComboBox}. 18 */ 16 19 public HistoryComboBox() { 17 20 int maxsize = Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE); … … 31 34 32 35 public void addCurrentItemToHistory() { 33 String regex = (String)getEditor().getItem(); 34 model.addElement(regex); 36 model.addElement((String)getEditor().getItem()); 35 37 } 36 38 -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java
r7005 r7015 15 15 16 16 import javax.accessibility.Accessible; 17 import javax.swing.ComboBoxEditor;18 17 import javax.swing.ComboBoxModel; 19 18 import javax.swing.DefaultComboBoxModel; … … 26 25 * Class overriding each {@link JComboBox} in JOSM to control consistently the number of displayed items at once.<br> 27 26 * 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 28 28 * 29 * @since 5429 29 * @since 5429 (creation) 30 * @since 7015 (generics for Java 7) 30 31 */ 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"; 32 public class JosmComboBox<E> extends JComboBox<E> { 38 33 39 34 /** … … 46 41 */ 47 42 public JosmComboBox() { 48 this(DEFAULT_PROTOTYPE_DISPLAY_VALUE);43 init(null); 49 44 } 50 45 … … 63 58 * @since 5450 64 59 */ 65 public JosmComboBox(Object prototypeDisplayValue) { 66 super(); 60 public JosmComboBox(E prototypeDisplayValue) { 67 61 init(prototypeDisplayValue); 68 62 } … … 79 73 * @see DefaultComboBoxModel 80 74 */ 81 public JosmComboBox(ComboBoxModel aModel) {75 public JosmComboBox(ComboBoxModel<E> aModel) { 82 76 super(aModel); 83 List< Object> list = new ArrayList<>(aModel.getSize());77 List<E> list = new ArrayList<>(aModel.getSize()); 84 78 for (int i = 0; i<aModel.getSize(); i++) { 85 79 list.add(aModel.getElementAt(i)); … … 96 90 * @see DefaultComboBoxModel 97 91 */ 98 public JosmComboBox( Object[] items) {92 public JosmComboBox(E[] items) { 99 93 super(items); 100 94 init(findPrototypeDisplayValue(Arrays.asList(items))); … … 107 101 * @since 5558 108 102 */ 109 protected final Object findPrototypeDisplayValue(Collection<?> possibleValues) {110 Objectresult = null;103 protected final E findPrototypeDisplayValue(Collection<E> possibleValues) { 104 E result = null; 111 105 int maxHeight = -1; 112 106 if (possibleValues != null) { 113 107 // Remind old prototype to restore it later 114 ObjectoldPrototype = getPrototypeDisplayValue();108 E oldPrototype = getPrototypeDisplayValue(); 115 109 // Get internal JList to directly call the renderer 116 JList list = getList();110 JList<E> list = getList(); 117 111 try { 118 112 // Index to give to renderer 119 113 int i = 0; 120 for ( Objectvalue : possibleValues) {114 for (E value : possibleValues) { 121 115 if (value != null) { 122 116 // With a "classic" renderer, we could call setPrototypeDisplayValue(value) + getPreferredSize() … … 144 138 } 145 139 146 protected final JList getList() { 140 @SuppressWarnings("unchecked") 141 protected final JList<E> getList() { 147 142 for (int i = 0; i < getUI().getAccessibleChildrenCount(this); i++) { 148 143 Accessible child = getUI().getAccessibleChild(this, i); … … 154 149 } 155 150 156 protected final void init( Objectprototype) {151 protected final void init(E prototype) { 157 152 if (prototype != null) { 158 153 setPrototypeDisplayValue(prototype); … … 163 158 // If possible, adjust the maximum number of items with the real height of items 164 159 // It is not granted this works on every platform (tested OK on Windows) 165 JList list = getList();160 JList<E> list = getList(); 166 161 if (list != null) { 167 162 if (list.getPrototypeCellValue() != prototype) { … … 203 198 private void enableMenu() { 204 199 if (launcher == null) { 205 ComboBoxEditor editor = getEditor();206 200 if (editor != null) { 207 201 Component editorComponent = editor.getEditorComponent(); … … 224 218 } 225 219 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 } 228 229 229 230 private void processEvent(MouseEvent e) { … … 241 242 * @since 5558 242 243 */ 243 public final void reinitialize(Collection< ?> values) {244 public final void reinitialize(Collection<E> values) { 244 245 init(findPrototypeDisplayValue(values)); 245 246 } -
trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitiveTypesComboBox.java
r5453 r7015 10 10 * @since 2923 11 11 */ 12 public class OsmPrimitiveTypesComboBox extends JosmComboBox {12 public class OsmPrimitiveTypesComboBox extends JosmComboBox<Object> { 13 13 14 14 /**
Note:
See TracChangeset
for help on using the changeset viewer.