Changeset 3733 in josm
- Timestamp:
- 2010-12-20T18:00:55+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r3720 r3733 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.data.imagery.ImageryInfo; 10 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 10 11 import org.openstreetmap.josm.gui.layer.ImageryLayer; 11 12 … … 15 16 16 17 public AddImageryLayerAction(ImageryInfo info) { 17 super(info.getMenuName(), "imagery_menu", tr("Add imagery layer {0}",info.getName()), null, false );18 super(info.getMenuName(), "imagery_menu", tr("Add imagery layer {0}",info.getName()), null, false, false); 18 19 putValue("toolbar", "imagery_" + info.getToolbarName()); 19 20 this.info = info; 21 installAdapters(); 20 22 } 21 23 22 24 @Override 23 25 public void actionPerformed(ActionEvent e) { 26 if (!isEnabled()) return; 24 27 ImageryLayer wmsLayer = ImageryLayer.create(info); 25 28 Main.main.addLayer(wmsLayer); 26 29 } 27 }; 30 31 @Override 32 protected void updateEnabledState() { 33 setEnabled(info.getImageryType() == ImageryType.TMS 34 || info.getImageryType() == ImageryType.BING 35 || (Main.map != null && Main.map.mapView != null 36 && !Main.map.mapView.getAllLayers().isEmpty())); 37 } 38 } -
trunk/src/org/openstreetmap/josm/actions/Map_Rectifier_WMSmenuAction.java
r3720 r3733 112 112 @Override 113 113 public void actionPerformed(ActionEvent e) { 114 if (!isEnabled()) return; 114 115 JPanel panel = new JPanel(new GridBagLayout()); 115 116 panel.add(new JLabel(tr("Supported Rectifier Services:")), GBC.eol()); … … 123 124 for(RectifierService s : services) { 124 125 JRadioButton serviceBtn = new JRadioButton(s.name); 125 if(firstBtn == null) 126 if(firstBtn == null) { 126 127 firstBtn = serviceBtn; 128 } 127 129 // Checks clipboard contents against current service if no match has been found yet. 128 130 // If the contents match, they will be inserted into the text field and the corresponding … … 138 140 panel.add(serviceBtn, GBC.std()); 139 141 panel.add(new UrlLabel(s.url, tr("Visit Homepage")), GBC.eol().anchor(GridBagConstraints.EAST)); 140 } else 142 } else { 141 143 panel.add(serviceBtn, GBC.eol().anchor(GridBagConstraints.WEST)); 144 } 142 145 } 143 146 144 147 // Fallback in case no match was found 145 if(tfWmsUrl.getText().equals("") && firstBtn != null) 148 if(tfWmsUrl.getText().equals("") && firstBtn != null) { 146 149 firstBtn.setSelected(true); 150 } 147 151 148 152 panel.add(new JLabel(tr("WMS URL or Image ID:")), GBC.eol()); … … 162 166 int answer = diag.getValue(); 163 167 // Break loop when the user cancels 164 if(answer != 1) 168 if(answer != 1) { 165 169 break; 170 } 166 171 167 172 String text = tfWmsUrl.getText().trim(); 168 173 // Loop all services until we find the selected one 169 174 for(RectifierService s : services) { 170 if(!s.isSelected()) 175 if(!s.isSelected()) { 171 176 continue; 177 } 172 178 173 179 // We've reached the custom WMS URL service … … 237 243 return result.trim(); 238 244 } 245 246 @Override 247 protected void updateEnabledState() { 248 setEnabled(Main.map != null && Main.map.mapView != null && !Main.map.mapView.getAllLayers().isEmpty()); 249 } 239 250 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r3715 r3733 7 7 import static org.openstreetmap.josm.tools.I18n.trc; 8 8 9 import java.awt.Component;10 9 import java.awt.event.ActionEvent; 11 10 import java.awt.event.KeyEvent; … … 58 57 import org.openstreetmap.josm.actions.OpenLocationAction; 59 58 import org.openstreetmap.josm.actions.OrthogonalizeAction; 59 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 60 60 import org.openstreetmap.josm.actions.PasteAction; 61 61 import org.openstreetmap.josm.actions.PasteTagsAction; … … 82 82 import org.openstreetmap.josm.actions.ZoomInAction; 83 83 import org.openstreetmap.josm.actions.ZoomOutAction; 84 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;85 84 import org.openstreetmap.josm.actions.audio.AudioBackAction; 86 85 import org.openstreetmap.josm.actions.audio.AudioFasterAction; … … 98 97 import org.openstreetmap.josm.gui.layer.WMSLayer; 99 98 import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction; 99 import org.openstreetmap.josm.tools.ImageProvider; 100 100 import org.openstreetmap.josm.tools.Shortcut; 101 101 … … 392 392 393 393 public class ImageryMenuUpdater implements MapView.LayerChangeListener { 394 JMenu offsetSubMenu = new JMenu(trc("layer","Offset")); 394 JMenuItem disabledOffset = new JMenuItem(trc("layer","Offset")); 395 JMenuItem offsetSubMenu = disabledOffset; 396 int offsPos; 395 397 396 398 public ImageryMenuUpdater() { 397 399 MapView.addLayerChangeListener(this); 400 disabledOffset.setEnabled(false); 398 401 } 399 402 … … 403 406 // for each configured WMSInfo, add a menu entry. 404 407 for (final ImageryInfo u : ImageryLayerInfo.instance.getLayers()) { 405 imageryMenu.add(new JMenuItem(new AddImageryLayerAction(u)));408 imageryMenu.add(new AddImageryLayerAction(u)); 406 409 } 407 410 imageryMenu.addSeparator(); … … 409 412 410 413 imageryMenu.addSeparator(); 414 offsPos = imageryMenu.getMenuComponentCount(); 411 415 imageryMenu.add(offsetSubMenu); 412 416 imageryMenu.addSeparator(); 413 imageryMenu.add(new JMenuItem(new 414 JosmAction(tr("Blank Layer"), "blankmenu", tr("Open a blank WMS layer to load data from a file"), null, false) {417 imageryMenu.add(new JMenuItem(new JosmAction( 418 tr("Blank Layer"), "blankmenu", tr("Open a blank WMS layer to load data from a file"), null, false) { 415 419 @Override 416 420 public void actionPerformed(ActionEvent ev) { 421 if (!isEnabled()) return; 417 422 Main.main.addLayer(new WMSLayer()); 418 423 } 424 425 @Override 426 protected void updateEnabledState() { 427 setEnabled(Main.map != null && Main.map.mapView != null && !Main.map.mapView.getAllLayers().isEmpty()); 428 } 419 429 })); 420 refreshEnabled(); 421 } 422 423 public void refreshEnabled() { 424 imageryMenu.setEnabled(Main.map != null 425 && Main.map.mapView !=null 426 ); 430 } 431 432 private JMenuItem getNewOffsetMenu(){ 433 if (Main.map == null || Main.map.mapView == null) 434 return disabledOffset; 435 List<ImageryLayer> layers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 436 if (layers.isEmpty()) 437 return disabledOffset; 438 if (layers.size() == 1) 439 return layers.get(0).getOffsetMenuItem(); 440 JMenu newMenu = new JMenu(trc("layer","Offset")); 441 newMenu.setIcon(ImageProvider.get("mapmode", "adjustimg")); 442 for (ImageryLayer layer : layers) { 443 JMenuItem layerMenu = layer.getOffsetMenuItem(); 444 layerMenu.setText(layer.getName()); 445 layerMenu.setIcon(layer.getIcon()); 446 newMenu.add(layerMenu); 447 } 448 return newMenu; 427 449 } 428 450 429 451 public void refreshOffsetMenu() { 430 offsetSubMenu.removeAll(); 431 if (Main.map == null || Main.map.mapView == null) { 432 offsetSubMenu.setEnabled(false); 433 return; 434 } 435 List<ImageryLayer> layers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 436 if (layers.isEmpty()) { 437 offsetSubMenu.setEnabled(false); 438 return; 439 } 440 offsetSubMenu.setEnabled(true); 441 if (layers.size() == 1) { 442 for (Component c : layers.get(0).getOffsetMenu()) { 443 offsetSubMenu.add(c); 444 } 445 return; 446 } 447 for (ImageryLayer layer : layers) { 448 JMenu subMenu = new JMenu(layer.getName()); 449 subMenu.setIcon(layer.getIcon()); 450 for (Component c : layer.getOffsetMenu()) { 451 subMenu.add(c); 452 } 453 offsetSubMenu.add(subMenu); 454 } 452 JMenuItem newItem = getNewOffsetMenu(); 453 imageryMenu.remove(offsetSubMenu); 454 imageryMenu.add(newItem, offsPos); 455 offsetSubMenu = newItem; 455 456 } 456 457 … … 464 465 refreshOffsetMenu(); 465 466 } 466 refreshEnabled();467 467 } 468 468 … … 472 472 refreshOffsetMenu(); 473 473 } 474 refreshEnabled();475 474 } 476 475 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r3729 r3733 7 7 import java.awt.Color; 8 8 import java.awt.Component; 9 import java.awt.Container;10 9 import java.awt.Font; 11 10 import java.awt.Graphics; … … 15 14 import java.awt.image.ConvolveOp; 16 15 import java.awt.image.Kernel; 17 import java.util.ArrayList;18 16 import java.util.List; 19 17 … … 32 30 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 33 31 import org.openstreetmap.josm.data.preferences.IntegerProperty; 34 import org.openstreetmap.josm.gui.MapView;35 32 import org.openstreetmap.josm.tools.ImageProvider; 36 33 … … 55 52 56 53 protected final ImageryInfo info; 57 protected MapView mv;58 54 59 55 protected double dx = 0.0; … … 65 61 super(info.getName()); 66 62 this.info = info; 67 this.mv = Main.map.mapView;68 63 this.sharpenLevel = PROP_SHARPEN_LEVEL.get(); 69 64 } 70 65 71 66 public double getPPD(){ 72 ProjectionBounds bounds = mv.getProjectionBounds(); 73 return mv.getWidth() / (bounds.max.east() - bounds.min.east()); 67 if (Main.map == null || Main.map.mapView == null) return Main.proj.getDefaultZoomInPPD(); 68 ProjectionBounds bounds = Main.map.mapView.getProjectionBounds(); 69 return Main.map.mapView.getWidth() / (bounds.max.east() - bounds.min.east()); 74 70 } 75 71 … … 132 128 public void actionPerformed(ActionEvent ev) { 133 129 setOffset(b.dx, b.dy); 130 Main.main.menu.imageryMenuUpdater.refreshOffsetMenu(); 134 131 Main.map.repaint(); 135 if (!(ev.getSource() instanceof Component)) return;136 Component source = (Component)ev.getSource();137 if (source.getParent() == null) return;138 Container m = source.getParent();139 for (Component c : m.getComponents()) {140 if (c instanceof JCheckBoxMenuItem && c != source) {141 ((JCheckBoxMenuItem)c).setSelected(false);142 }143 }144 132 } 145 133 } … … 149 137 public void actionPerformed(ActionEvent e) { 150 138 } 139 151 140 @Override 152 141 public Component createMenuComponent() { 153 JMenu menu = new JMenu(trc("layer", "Offset")); 154 menu.setIcon(ImageProvider.get("mapmode", "adjustimg")); 155 for (Component item : getOffsetMenu()) { 156 menu.add(item); 157 } 158 return menu; 159 } 142 return getOffsetMenuItem(); 143 } 144 160 145 @Override 161 146 public boolean supportLayers(List<Layer> layers) { … … 164 149 } 165 150 166 public List<Component> getOffsetMenu() { 167 List<Component> result = new ArrayList<Component>(); 168 result.add(new JMenuItem(new ImageryAdjustAction(this))); 169 if (OffsetBookmark.allBookmarks.isEmpty()) return result; 170 171 result.add(new JSeparator(JSeparator.HORIZONTAL)); 151 ImageryAdjustAction adjustAction = new ImageryAdjustAction(this); 152 153 public JMenuItem getOffsetMenuItem() { 154 JMenuItem adjustMenuItem = new JMenuItem(adjustAction); 155 if (OffsetBookmark.allBookmarks.isEmpty()) return adjustMenuItem; 156 157 JMenu subMenu = new JMenu(trc("layer", "Offset")); 158 subMenu.setIcon(ImageProvider.get("mapmode", "adjustimg")); 159 subMenu.add(adjustMenuItem); 160 subMenu.add(new JSeparator()); 161 boolean hasBookmarks = false; 172 162 for (OffsetBookmark b : OffsetBookmark.allBookmarks) { 173 163 if (!b.isUsable(this)) { … … 178 168 item.setSelected(true); 179 169 } 180 result.add(item); 181 } 182 return result; 170 subMenu.add(item); 171 hasBookmarks = true; 172 } 173 return hasBookmarks ? subMenu : adjustMenuItem; 183 174 } 184 175 -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r3720 r3733 259 259 260 260 private double getPPDeg() { 261 MapView mv = Main.map.mapView; 261 262 return mv.getWidth()/(mv.getLatLon(mv.getWidth(), mv.getHeight()/2).lon()-mv.getLatLon(0, mv.getHeight()/2).lon()); 262 263 } 263 264 264 265 private int getBestZoom() { 266 if (Main.map == null || Main.map.mapView == null) return 3; 265 267 double ret = Math.log(getPPDeg()*360/tileSource.getTileSize())/Math.log(2); 266 System.out.println("Detected best zoom " + ret);267 268 return (int)Math.round(ret); 268 269 } -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r3720 r3733 31 31 import org.openstreetmap.josm.actions.SaveActionBase; 32 32 import org.openstreetmap.josm.data.Bounds; 33 import org.openstreetmap.josm.data.ProjectionBounds;34 33 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 35 34 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 35 import org.openstreetmap.josm.data.ProjectionBounds; 36 36 import org.openstreetmap.josm.data.coor.EastNorth; 37 37 import org.openstreetmap.josm.data.imagery.GeorefImage; 38 import org.openstreetmap.josm.data.imagery.GeorefImage.State; 38 39 import org.openstreetmap.josm.data.imagery.ImageryInfo; 40 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 39 41 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 40 import org.openstreetmap.josm.data.imagery.GeorefImage.State;41 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;42 42 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 43 43 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 77 77 protected boolean settingsChanged; 78 78 protected ImageryInfo info; 79 protected final MapView mv; 79 80 80 81 // Image index boundary for current view … … 109 110 public WMSLayer(ImageryInfo info) { 110 111 super(info); 112 mv = Main.map.mapView; 111 113 setBackgroundLayer(true); /* set global background variable */ 112 114 initializeImages();
Note:
See TracChangeset
for help on using the changeset viewer.