Changeset 1399 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-02-14T12:42:59+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java
r1195 r1399 37 37 public static Collection<TaggingPreset> taggingPresets; 38 38 private JList taggingPresetSources; 39 private JCheckBox sortMenu; 39 40 private JCheckBox enableDefault; 40 41 … … 42 43 43 44 taggingPresetSources = new JList(new DefaultListModel()); 45 sortMenu = new JCheckBox(tr("Sort presets menu"), 46 Main.pref.getBoolean("taggingpreset.sortmenu", false)); 44 47 enableDefault = new JCheckBox(tr("Enable built-in defaults"), 45 48 Main.pref.getBoolean("taggingpreset.enable-defaults", true)); … … 91 94 tpPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray), tr("Tagging Presets"))); 92 95 tpPanel.setLayout(new GridBagLayout()); 96 tpPanel.add(sortMenu, GBC.eol().insets(5,5,5,0)); 93 97 tpPanel.add(enableDefault, GBC.eol().insets(5,5,5,0)); 94 98 tpPanel.add(new JLabel(tr("Tagging preset sources")), GBC.eol().insets(5,5,5,0)); … … 104 108 105 109 public boolean ok() { 110 boolean restart; 106 111 Main.pref.put("taggingpreset.enable-defaults", enableDefault.getSelectedObjects() != null); 112 restart = Main.pref.put("taggingpreset.sortmenu", sortMenu.getSelectedObjects() != null); 107 113 int num = taggingPresetSources.getModel().getSize(); 108 boolean restart;109 114 if (num > 0) 110 115 { … … 112 117 for (int i = 0; i < num; ++i) 113 118 l.add((String)taggingPresetSources.getModel().getElementAt(i)); 114 restart = Main.pref.putCollection("taggingpreset.sources", l); 119 if(Main.pref.putCollection("taggingpreset.sources", l)) 120 restart = true; 115 121 } 116 else 117 restart = Main.pref.putCollection("taggingpreset.sources", null);122 else if(Main.pref.putCollection("taggingpreset.sources", null)) 123 restart = true; 118 124 return restart; 119 125 } … … 150 156 } 151 157 } 158 if(Main.pref.getBoolean("taggingpreset.sortmenu")) 159 TaggingPresetMenu.sortMenu(Main.main.menu.presetsMenu); 152 160 } 153 161 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetMenu.java
r1339 r1399 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.Component; 8 import java.util.ArrayList; 9 import java.util.Collections; 8 10 9 11 import javax.swing.Action; … … 14 16 15 17 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 18 import org.openstreetmap.josm.tools.PresetTextComparator; 16 19 17 20 public class TaggingPresetMenu extends TaggingPreset { … … 46 49 } 47 50 } 51 /** 52 * Sorts the menu items using the translated item text 53 */ 54 public void sortMenu(){ 55 TaggingPresetMenu.sortMenu(this.menu); 56 } 57 58 /** 59 * Sorts the menu items using the translated item text 60 */ 61 public static void sortMenu(JMenu menu){ 62 Component[] items = menu.getMenuComponents(); 63 PresetTextComparator comp = new PresetTextComparator(); 64 ArrayList<JMenuItem> sortarray = new ArrayList<JMenuItem>(); 65 int lastSeperator = 0; 66 for (int i = 0; i < items.length; i++) { 67 Object item = items[i]; 68 if (item instanceof JMenu){ 69 sortMenu((JMenu)item); 70 } 71 if (item instanceof JMenuItem){ 72 sortarray.add((JMenuItem)item); 73 if (i == items.length-1){ 74 Collections.sort(sortarray, comp); 75 int pos = 0; 76 for (JMenuItem menuItem : sortarray) { 77 int oldPos; 78 if(lastSeperator == 0){ 79 oldPos=pos; 80 }else { 81 oldPos = pos+lastSeperator+1; 82 } 83 menu.add(menuItem, oldPos); 84 pos++; 85 } 86 sortarray = new ArrayList<JMenuItem>(); 87 lastSeperator = 0; 88 } 89 }else if (item instanceof JSeparator){ 90 Collections.sort(sortarray, comp); 91 int pos = 0; 92 for (JMenuItem menuItem : sortarray) { 93 int oldPos; 94 if(lastSeperator == 0){ 95 oldPos=pos; 96 }else { 97 oldPos = pos+lastSeperator+1; 98 } 99 menu.add(menuItem, oldPos); 100 pos++; 101 } 102 sortarray = new ArrayList<JMenuItem>(); 103 lastSeperator = i; 104 } 105 } 106 } 48 107 }
Note:
See TracChangeset
for help on using the changeset viewer.