Changeset 5803 in josm
- Timestamp:
- 2013-03-27T12:20:35+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
r5733 r5803 6 6 7 7 import java.awt.Component; 8 import java.awt.MenuComponent; 8 9 import java.awt.Toolkit; 9 10 import java.awt.event.ActionEvent; 11 import java.util.ArrayList; 10 12 import java.util.HashSet; 11 13 import java.util.Iterator; … … 79 81 private JMenuItem offsetMenuItem = singleOffset; 80 82 private Map_Rectifier_WMSmenuAction rectaction = new Map_Rectifier_WMSmenuAction(); 83 private boolean bottomItemAdded = false; 81 84 82 85 public ImageryMenu() { … … 114 117 */ 115 118 public void refreshImageryMenu() { 116 remove All();119 removeDynamicItems(); 117 120 118 121 // for each configured ImageryInfo, add a menu entry. 119 122 for (final ImageryInfo u : ImageryLayerInfo.instance.getLayers()) { 120 add(new AddImageryLayerAction(u)); 123 addDynamic(new AddImageryLayerAction(u)); 121 124 } 122 125 … … 150 153 } 151 154 if (!inViewLayers.isEmpty()) { 152 addSeparator(); 155 addDynamicSeparator(); 153 156 for (ImageryInfo i : inViewLayers) { 154 add(new AddImageryLayerAction(i)); 155 } 156 } 157 } 158 159 addSeparator(); 160 add (new JMenuItem(rectaction));161 162 addSeparator(); 163 add(offsetMenuItem); 157 addDynamic(new AddImageryLayerAction(i)); 158 } 159 } 160 } 161 162 addDynamicSeparator(); 163 addDynamic(rectaction); 164 165 addDynamicSeparator(); 166 addDynamic(offsetMenuItem); 164 167 } 165 168 … … 217 220 } 218 221 } 222 223 /** 224 * Collection to store temporary menu items. They will be deleted 225 * (and possibly recreated) when refreshImageryMenu() is called. 226 * @since 5803 227 */ 228 private List <Object> dynamicItems = new ArrayList<Object>(20); 229 230 /** 231 * Remove all the items in @field dynamicItems collection 232 * @since 5803 233 */ 234 private void removeDynamicItems() { 235 for (Object item : dynamicItems) { 236 if (item instanceof JMenuItem) { 237 remove((JMenuItem)item); 238 } 239 if (item instanceof MenuComponent) { 240 remove((MenuComponent)item); 241 } 242 if (item instanceof Component) { 243 remove((Component)item); 244 } 245 } 246 dynamicItems.clear(); 247 } 248 249 private void addDynamicSeparator() { 250 JPopupMenu.Separator s = new JPopupMenu.Separator(); 251 dynamicItems.add(s); 252 add(s); 253 } 254 255 private void addDynamic(Action a) { 256 dynamicItems.add( this.add(a) ); 257 } 258 259 private void addDynamic(JMenuItem it) { 260 dynamicItems.add( this.add(it) ); 261 } 219 262 }
Note:
See TracChangeset
for help on using the changeset viewer.