- Timestamp:
- 2012-08-18T14:58:25+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java
r5429 r5450 8 8 import java.util.List; 9 9 10 import javax.swing.DefaultComboBoxModel;11 10 import javax.swing.DefaultListCellRenderer; 12 11 import javax.swing.Icon; … … 58 57 59 58 protected Layer askTargetLayer(List<Layer> targetLayers) { 60 JosmComboBox layerList = new JosmComboBox( );59 JosmComboBox layerList = new JosmComboBox(targetLayers.toArray()); 61 60 layerList.setRenderer(new LayerListCellRenderer()); 62 layerList.setModel(new DefaultComboBoxModel(targetLayers.toArray()));63 61 layerList.setSelectedIndex(0); 64 62 65 JPanel pnl = new JPanel(); 66 pnl.setLayout(new GridBagLayout()); 63 JPanel pnl = new JPanel(new GridBagLayout()); 67 64 pnl.add(new JLabel(tr("Please select the target layer.")), GBC.eol()); 68 65 pnl.add(layerList, GBC.eol()); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r5437 r5450 1776 1776 public void removeObsolete() { 1777 1777 String[] obsolete = { 1778 " edit.make-parallel-way-action.snap-threshold", // 10/2011 - replaced by snap-threshold-percent. Can be removed mid 20121778 "gui.combobox.maximum-row-count", // 08/2012 - briefly introduced with #7917, can be removed end 2012 1779 1779 }; 1780 1780 for (String key : obsolete) { -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictDecisionEditor.java
r5429 r5450 5 5 import java.util.EventObject; 6 6 7 import javax.swing.DefaultComboBoxModel;8 7 import javax.swing.JTable; 9 8 import javax.swing.event.CellEditorListener; … … 16 15 17 16 public RelationMemberConflictDecisionEditor() { 17 super(RelationMemberConflictDecisionType.values()); 18 18 setOpaque(true); 19 DefaultComboBoxModel model = new DefaultComboBoxModel();20 model.addElement(RelationMemberConflictDecisionType.KEEP);21 model.addElement(RelationMemberConflictDecisionType.REMOVE);22 model.addElement(RelationMemberConflictDecisionType.UNDECIDED);23 setModel(model);24 19 setRenderer(new RelationMemberConflictDecisionRenderer()); 25 20 tableCellEditorSupport = new TableCellEditorSupport(this); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5433 r5450 113 113 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 114 114 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 115 import org.openstreetmap.josm.gui.widgets.JosmComboBox;116 115 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 117 116 import org.openstreetmap.josm.tools.GBC; … … 711 710 private final JTable membershipTable = new JTable(membershipData); 712 711 713 public JosmComboBox taggingPresets = new JosmComboBox();714 715 712 /** 716 713 * The Add/Edit/Delete buttons (needed to be able to disable them) -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r5266 r5450 322 322 public void focusGained(FocusEvent e) { 323 323 AutoCompletionList list = tfRole.getAutoCompletionList(); 324 list.clear(); 325 getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list); 324 if (list != null) { 325 list.clear(); 326 getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list); 327 } 326 328 } 327 329 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r5438 r5450 42 42 import javax.swing.Action; 43 43 import javax.swing.BorderFactory; 44 import javax.swing.DefaultComboBoxModel;45 44 import javax.swing.Icon; 46 45 import javax.swing.JComponent; … … 1398 1397 } 1399 1398 1400 JosmComboBox layerList = new JosmComboBox( );1399 JosmComboBox layerList = new JosmComboBox(targetLayers.toArray()); 1401 1400 layerList.setRenderer(new LayerListCellRenderer()); 1402 layerList.setModel(new DefaultComboBoxModel(targetLayers.toArray()));1403 1401 layerList.setSelectedIndex(0); 1404 1402 1405 JPanel pnl = new JPanel(); 1406 pnl.setLayout(new GridBagLayout()); 1403 JPanel pnl = new JPanel(new GridBagLayout()); 1407 1404 pnl.add(new JLabel(tr("Please select the imagery layer.")), GBC.eol()); 1408 1405 pnl.add(layerList, GBC.eol()); … … 1417 1414 return null; 1418 1415 1419 WMSLayer targetLayer = (WMSLayer) layerList.getSelectedItem(); 1420 return targetLayer; 1416 return (WMSLayer) layerList.getSelectedItem(); 1421 1417 } 1422 1418 -
trunk/src/org/openstreetmap/josm/gui/oauth/AuthorizationProcedureComboBox.java
r5429 r5450 6 6 import java.awt.Component; 7 7 8 import javax.swing.DefaultComboBoxModel;9 8 import javax.swing.JLabel; 10 9 import javax.swing.JList; … … 17 16 18 17 public AuthorizationProcedureComboBox() { 19 s etModel(new AuthorisationProcedureComboBoxModel());18 super(AuthorizationProcedure.values()); 20 19 setRenderer(new AuthorisationProcedureCellRenderer()); 21 20 setSelectedItem(AuthorizationProcedure.FULLY_AUTOMATIC); 22 }23 24 static private class AuthorisationProcedureComboBoxModel extends DefaultComboBoxModel {25 @Override26 public Object getElementAt(int index) {27 switch(index) {28 case 0: return AuthorizationProcedure.FULLY_AUTOMATIC;29 case 1: return AuthorizationProcedure.SEMI_AUTOMATIC;30 case 2: return AuthorizationProcedure.MANUALLY;31 }32 return null;33 }34 35 @Override36 public int getSize() {37 return 3;38 }39 21 } 40 22 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r5429 r5450 826 826 AutoCompletingTextField tf = new AutoCompletingTextField(); 827 827 initAutoCompletionField(tf, key); 828 tf.getAutoCompletionList().add(getDisplayValues(), AutoCompletionItemPritority.IS_IN_STANDARD); 828 AutoCompletionList acList = tf.getAutoCompletionList(); 829 if (acList != null) { 830 acList.add(getDisplayValues(), AutoCompletionItemPritority.IS_IN_STANDARD); 831 } 829 832 combo.setEditor(tf); 830 833 -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r5429 r5450 147 147 148 148 public AutoCompletingComboBox() { 149 super(new AutoCompletionListItem(JosmComboBox.DEFAULT_PROTOTYPE_DISPLAY_VALUE)); 149 150 setRenderer(new AutoCompleteListCellRenderer()); 150 151 final JTextComponent editor = (JTextComponent) this.getEditor().getEditorComponent(); -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java
r5429 r5450 2 2 package org.openstreetmap.josm.gui.widgets; 3 3 4 import java.awt.Toolkit; 4 5 import java.util.Vector; 5 6 7 import javax.accessibility.Accessible; 6 8 import javax.swing.ComboBoxModel; 7 9 import javax.swing.DefaultComboBoxModel; 8 10 import javax.swing.JComboBox; 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 12 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 11 import javax.swing.JList; 12 import javax.swing.plaf.basic.ComboPopup; 13 13 14 14 /** 15 15 * Class overriding each {@link JComboBox} in JOSM to control consistently the number of displayed items at once.<br/> 16 * This is needed because of the default Java behaviour that may display the top-down list off the screen (see #). 17 * <p> 18 * The property {@code gui.combobox.maximum-row-count} can be setup to control this behaviour. 16 * This is needed because of the default Java behaviour that may display the top-down list off the screen (see #7917). 19 17 * 20 18 * @since 5429 21 19 */ 22 public class JosmComboBox extends JComboBox implements PreferenceChangedListener{20 public class JosmComboBox extends JComboBox { 23 21 24 22 /** 25 * This property allows to control the {@link #getMaximumRowCount} of all combo boxes used in JOSM. 23 * The default prototype value used to compute the maximum number of elements to be displayed at once before 24 * displaying a scroll bar 26 25 */ 27 public static final String PROP_MAXIMUM_ROW_COUNT = "gui.combobox.maximum-row-count";26 public static final String DEFAULT_PROTOTYPE_DISPLAY_VALUE = "Prototype display value"; 28 27 29 28 /** 30 29 * Creates a <code>JosmComboBox</code> with a default data model. 31 30 * The default data model is an empty list of objects. 32 * Use <code>addItem</code> to add items. 31 * Use <code>addItem</code> to add items. By default the first item 33 32 * in the data model becomes selected. 34 33 * … … 36 35 */ 37 36 public JosmComboBox() { 37 this(DEFAULT_PROTOTYPE_DISPLAY_VALUE); 38 } 39 40 /** 41 * Creates a <code>JosmComboBox</code> with a default data model and 42 * the specified prototype display value. 43 * The default data model is an empty list of objects. 44 * Use <code>addItem</code> to add items. By default the first item 45 * in the data model becomes selected. 46 * 47 * @param prototypeDisplayValue the <code>Object</code> used to compute 48 * the maximum number of elements to be displayed at once before 49 * displaying a scroll bar 50 * 51 * @see DefaultComboBoxModel 52 * @since 5450 53 */ 54 public JosmComboBox(Object prototypeDisplayValue) { 38 55 super(); 39 init( );56 init(prototypeDisplayValue); 40 57 } 41 58 42 59 /** 43 60 * Creates a <code>JosmComboBox</code> that takes its items from an 44 * existing <code>ComboBoxModel</code>. 61 * existing <code>ComboBoxModel</code>. Since the 45 62 * <code>ComboBoxModel</code> is provided, a combo box created using 46 63 * this constructor does not create a default combo box model and … … 53 70 public JosmComboBox(ComboBoxModel aModel) { 54 71 super(aModel); 55 init( );72 init(aModel != null && aModel.getSize() > 0 ? aModel.getElementAt(0) : DEFAULT_PROTOTYPE_DISPLAY_VALUE); 56 73 } 57 74 58 75 /** 59 76 * Creates a <code>JosmComboBox</code> that contains the elements 60 * in the specified array. 77 * in the specified array. By default the first item in the array 61 78 * (and therefore the data model) becomes selected. 62 79 * … … 66 83 public JosmComboBox(Object[] items) { 67 84 super(items); 68 init( );85 init(items != null && items.length > 0 ? items[0] : DEFAULT_PROTOTYPE_DISPLAY_VALUE); 69 86 } 70 87 71 88 /** 72 89 * Creates a <code>JosmComboBox</code> that contains the elements 73 * in the specified Vector. 90 * in the specified Vector. By default the first item in the vector 74 91 * (and therefore the data model) becomes selected. 75 92 * … … 79 96 public JosmComboBox(Vector<?> items) { 80 97 super(items); 81 init( );98 init(items != null && !items.isEmpty() ? items.get(0) : DEFAULT_PROTOTYPE_DISPLAY_VALUE); 82 99 } 83 100 84 protected void init() { 85 setMaximumRowCount(Main.pref.getInteger(PROP_MAXIMUM_ROW_COUNT, 20)); 86 } 87 88 /** 89 * Registers this combo box to the change of the property {@code gui.combobox.maximum-row-count}.<br/> 90 * Do not forget to call {@link #unregisterFromPreferenceChange} when the combo box is no longer needed. 91 * @see #unregisterFromPreferenceChange 92 */ 93 public final void registerToPreferenceChange() { 94 Main.pref.addPreferenceChangeListener(this); 95 } 96 97 /** 98 * Unregisters this combo box previously registered by {@link #registerToPreferenceChange}. 99 * @see #registerToPreferenceChange 100 */ 101 public final void unregisterFromPreferenceChange() { 102 Main.pref.removePreferenceChangeListener(this); 103 } 104 105 @Override 106 public void preferenceChanged(PreferenceChangeEvent e) { 107 if (PROP_MAXIMUM_ROW_COUNT.equals(e.getKey())) { 108 setMaximumRowCount(Main.pref.getInteger(PROP_MAXIMUM_ROW_COUNT, 20)); 101 protected void init(Object prototype) { 102 if (prototype != null) { 103 setPrototypeDisplayValue(prototype); 104 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; 105 // Compute maximum number of visible items based on the preferred size of the combo box. 106 // This assumes that items have the same height as the combo box, which is not granted by the look and feel 107 int maxsize = (screenHeight/getPreferredSize().height) / 2; 108 // If possible, adjust the maximum number of items with the real height of items 109 // It is not granted this works on every platform (tested OK on Windows) 110 for (int i = 0; i < getUI().getAccessibleChildrenCount(this); i++) { 111 Accessible child = getUI().getAccessibleChild(this, i); 112 if (child instanceof ComboPopup) { 113 JList list = ((ComboPopup)child).getList(); 114 if (list != null) { 115 if (list.getPrototypeCellValue() != prototype) { 116 list.setPrototypeCellValue(prototype); 117 } 118 int height = list.getFixedCellHeight(); 119 if (height > 0) { 120 maxsize = (screenHeight/height) / 2; 121 } 122 } 123 break; 124 } 125 } 126 setMaximumRowCount(Math.max(getMaximumRowCount(), maxsize)); 109 127 } 110 128 } -
trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitiveTypesComboBox.java
r5429 r5450 10 10 11 11 public OsmPrimitiveTypesComboBox() { 12 for (OsmPrimitiveType type: OsmPrimitiveType.values()){ 13 if(type.getOsmClass() != null) 14 addItem(type); 15 } 12 super(OsmPrimitiveType.dataValues()); 16 13 } 17 14 -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r4998 r5450 5 5 6 6 import java.awt.event.KeyEvent; 7 import java.io.File;8 7 import java.io.IOException; 9 8 import java.lang.reflect.InvocationHandler; 10 9 import java.lang.reflect.Method; 11 10 import java.lang.reflect.Proxy; 12 import java.util.HashMap;13 11 14 12 import javax.swing.UIManager; … … 17 15 18 16 /** 19 * see PlatformHook.java17 * @see PlatformHook 20 18 */ 21 19 public class PlatformHookOsx extends PlatformHookUnixoid implements PlatformHook, InvocationHandler {
Note:
See TracChangeset
for help on using the changeset viewer.