Changeset 24670 in osm for applications/editors/josm
- Timestamp:
- 2010-12-09T19:30:13+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryAdjustAction.java
r24543 r24670 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Component;6 5 import java.awt.Cursor; 7 6 import java.awt.GridBagLayout; 7 import java.awt.Insets; 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.MouseEvent; 9 10 import java.awt.event.MouseListener; 10 11 import java.awt.event.MouseMotionListener; 11 import java.util.List; 12 import java.beans.PropertyChangeEvent; 13 import java.beans.PropertyChangeListener; 14 import java.text.DecimalFormat; 12 15 13 import javax.swing.DefaultComboBoxModel; 14 import javax.swing.DefaultListCellRenderer; 15 import javax.swing.Icon; 16 import javax.swing.JComboBox; 16 import javax.swing.JFormattedTextField; 17 17 import javax.swing.JLabel; 18 import javax.swing.JList;19 import javax.swing.JOptionPane;20 18 import javax.swing.JPanel; 19 import javax.swing.JTextField; 21 20 22 21 import org.openstreetmap.josm.Main; … … 24 23 import org.openstreetmap.josm.data.coor.EastNorth; 25 24 import org.openstreetmap.josm.gui.ExtendedDialog; 26 import org.openstreetmap.josm.gui.MapFrame;27 import org.openstreetmap.josm.gui.layer.Layer;28 25 import org.openstreetmap.josm.tools.GBC; 29 26 import org.openstreetmap.josm.tools.ImageProvider; … … 31 28 32 29 public class ImageryAdjustAction extends MapMode implements MouseListener, MouseMotionListener{ 30 static ImageryOffsetDialog offsetDialog; 31 static Cursor cursor = ImageProvider.getCursor("normal", "move"); 33 32 33 double oldDx, oldDy; 34 34 boolean mouseDown; 35 35 EastNorth prevEastNorth; 36 private ImageryLayer adjustingLayer;36 private ImageryLayer layer; 37 37 38 public ImageryAdjustAction(MapFrame mapFrame) { 39 super(tr("Adjust imagery"), "adjustimg", 40 tr("Adjust the position of the selected imagery layer"), mapFrame, 41 ImageProvider.getCursor("normal", "move")); 38 public ImageryAdjustAction(ImageryLayer layer) { 39 super(tr("New offset"), "adjustimg", 40 tr("Adjust the position of the selected imagery layer"), Main.map, 41 cursor); 42 this.layer = layer; 42 43 } 43 44 44 45 @Override public void enterMode() { 45 46 super.enterMode(); 46 if (!hasLayersToAdjust()) { 47 warnNoImageryLayers(); 47 if (layer == null) 48 48 return; 49 } 50 List<ImageryLayer> imageryLayers = Main.map.mapView.getLayersOfType(ImageryLayer.class); 51 if (imageryLayers.size() == 1) { 52 adjustingLayer = imageryLayers.get(0); 53 } else { 54 adjustingLayer = (ImageryLayer)askAdjustLayer(Main.map.mapView.getLayersOfType(ImageryLayer.class)); 55 } 56 if (adjustingLayer == null) 57 return; 58 if (!adjustingLayer.isVisible()) { 59 adjustingLayer.setVisible(true); 49 if (!layer.isVisible()) { 50 layer.setVisible(true); 60 51 } 61 52 Main.map.mapView.addMouseListener(this); 62 53 Main.map.mapView.addMouseMotionListener(this); 54 oldDx = layer.dx; 55 oldDy = layer.dy; 56 offsetDialog = new ImageryOffsetDialog(); 57 offsetDialog.setVisible(true); 63 58 } 64 59 65 60 @Override public void exitMode() { 66 61 super.exitMode(); 62 if (offsetDialog != null) { 63 layer.setOffset(oldDx, oldDy); 64 offsetDialog.setVisible(false); 65 offsetDialog = null; 66 } 67 67 Main.map.mapView.removeMouseListener(this); 68 68 Main.map.mapView.removeMouseMotionListener(this); 69 adjustingLayer = null;70 69 } 71 70 … … 74 73 return; 75 74 76 if ( adjustingLayer.isVisible()) {75 if (layer.isVisible()) { 77 76 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 78 77 Main.map.mapView.setCursor … … 82 81 83 82 @Override public void mouseDragged(MouseEvent e) { 84 if ( adjustingLayer == null || prevEastNorth == null) return;83 if (layer == null || prevEastNorth == null) return; 85 84 EastNorth eastNorth = 86 85 Main.map.mapView.getEastNorth(e.getX(),e.getY()); 87 adjustingLayer.displace( 88 eastNorth.east()-prevEastNorth.east(), 89 eastNorth.north()-prevEastNorth.north() 90 ); 86 double dx = layer.getDx()+eastNorth.east()-prevEastNorth.east(); 87 double dy = layer.getDy()+eastNorth.north()-prevEastNorth.north(); 88 if (offsetDialog != null) { 89 offsetDialog.easting.setValue(dx); 90 offsetDialog.northing.setValue(dy); 91 } 91 92 prevEastNorth = eastNorth; 92 Main.map.mapView.repaint();93 93 } 94 94 … … 100 100 101 101 @Override 102 public void mouseEntered(MouseEvent e) { 102 public void actionPerformed(ActionEvent e) { 103 if (offsetDialog != null || layer == null) 104 return; 105 super.actionPerformed(e); 103 106 } 104 107 105 @Override106 public void mouseExited(MouseEvent e) {107 }108 108 109 @Override 110 public void mouseMoved(MouseEvent e) { 111 } 112 113 @Override public void mouseClicked(MouseEvent e) { 114 } 115 116 @Override public boolean layerIsSupported(Layer l) { 117 return hasLayersToAdjust(); 118 } 119 120 /** 121 * the list cell renderer used to render layer list entries 122 * 123 */ 124 static public class LayerListCellRenderer extends DefaultListCellRenderer { 125 126 protected boolean isActiveLayer(Layer layer) { 127 if (Main.map == null) 128 return false; 129 if (Main.map.mapView == null) 130 return false; 131 return Main.map.mapView.getActiveLayer() == layer; 109 class ImageryOffsetDialog extends ExtendedDialog implements PropertyChangeListener { 110 public final JFormattedTextField easting = new JFormattedTextField(new DecimalFormat("0.0000E0")); 111 public final JFormattedTextField northing = new JFormattedTextField(new DecimalFormat("0.0000E0")); 112 JTextField tBookmarkName = new JTextField(); 113 public ImageryOffsetDialog() { 114 super(Main.parent, 115 tr("Adjust imagery offset"), 116 new String[] { tr("OK"),tr("Cancel") }, 117 false); 118 setButtonIcons(new String[] { "mapmode/adjustimg", "cancel" }); 119 contentInsets = new Insets(15, 15, 5, 15); 120 JPanel pnl = new JPanel(); 121 pnl.setLayout(new GridBagLayout()); 122 pnl.add(new JLabel(tr("Easting") + ": "),GBC.std()); 123 pnl.add(easting,GBC.std().fill(GBC.HORIZONTAL).insets(0, 0, 5, 0)); 124 pnl.add(new JLabel(tr("Northing") + ": "),GBC.std()); 125 pnl.add(northing,GBC.eol()); 126 pnl.add(new JLabel(tr("Bookmark name: ")),GBC.eol().insets(0,5,0,0)); 127 pnl.add(tBookmarkName,GBC.eol().fill(GBC.HORIZONTAL)); 128 easting.setColumns(8); 129 northing.setColumns(8); 130 easting.setValue(layer.getDx()); 131 northing.setValue(layer.getDy()); 132 easting.addPropertyChangeListener("value",this); 133 northing.addPropertyChangeListener("value",this); 134 setContent(pnl); 135 setupDialog(); 132 136 } 133 137 134 138 @Override 135 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 136 boolean cellHasFocus) { 137 Layer layer = (Layer) value; 138 JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected, 139 cellHasFocus); 140 Icon icon = layer.getIcon(); 141 label.setIcon(icon); 142 label.setToolTipText(layer.getToolTipText()); 143 return label; 139 public void propertyChange(PropertyChangeEvent evt) { 140 layer.setOffset(((Number)easting.getValue()).doubleValue(), ((Number)northing.getValue()).doubleValue()); 141 Main.map.repaint(); 142 } 143 144 @Override 145 protected void buttonAction(int buttonIndex, ActionEvent evt) { 146 super.buttonAction(buttonIndex, evt); 147 offsetDialog = null; 148 if (buttonIndex == 2) { 149 layer.setOffset(oldDx, oldDy); 150 } else if (tBookmarkName.getText() != null && !"".equals(tBookmarkName.getText())) { 151 OffsetBookmark b = new OffsetBookmark( 152 Main.proj,layer.getInfo().getName(), 153 tBookmarkName.getText(), 154 layer.getDx(),layer.getDy()); 155 OffsetBookmark.allBookmarks.add(b); 156 OffsetBookmark.saveBookmarks(); 157 } 158 Main.map.selectSelectTool(false); 144 159 } 145 160 } 146 147 /**148 * Prompts the user with a list of imagery layers which can be adjusted149 *150 * @param adjustableLayers the list of adjustable layers151 * @return the selected layer; null, if no layer was selected152 */153 protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) {154 JComboBox layerList = new JComboBox();155 layerList.setRenderer(new LayerListCellRenderer());156 layerList.setModel(new DefaultComboBoxModel(adjustableLayers.toArray()));157 layerList.setSelectedIndex(0);158 159 JPanel pnl = new JPanel();160 pnl.setLayout(new GridBagLayout());161 pnl.add(new JLabel(tr("Please select the imagery layer to adjust.")), GBC.eol());162 pnl.add(layerList, GBC.eol());163 164 ExtendedDialog diag = new ExtendedDialog(165 Main.parent,166 tr("Select imagery layer"),167 new String[] { tr("Start adjusting"),tr("Cancel") }168 );169 diag.setContent(pnl);170 diag.setButtonIcons(new String[] { "mapmode/adjustimg", "cancel" });171 diag.showDialog();172 int decision = diag.getValue();173 if (decision != 1)174 return null;175 Layer adjustLayer = (Layer) layerList.getSelectedItem();176 return adjustLayer;177 }178 179 /**180 * Displays a warning message if there are no imagery layers to adjust181 *182 */183 protected void warnNoImageryLayers() {184 JOptionPane.showMessageDialog(185 Main.parent,186 tr("There are currently no imagery layer to adjust."),187 tr("No layers to adjust"),188 JOptionPane.WARNING_MESSAGE189 );190 }191 192 /**193 * Replies true if there is at least one WMS layer194 *195 * @return true if there is at least one WMS layer196 */197 protected boolean hasLayersToAdjust() {198 if (Main.map == null) return false;199 if (Main.map.mapView == null) return false;200 return ! Main.map.mapView.getLayersOfType(ImageryLayer.class).isEmpty();201 }202 203 @Override204 protected void updateEnabledState() {205 setEnabled(hasLayersToAdjust());206 }207 161 } -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryLayer.java
r24615 r24670 1 1 package org.openstreetmap.josm.plugins.imagery; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 3 import static org.openstreetmap.josm.tools.I18n.trc; 5 4 6 5 import java.awt.Component; 7 import java.awt.GridBagLayout;8 6 import java.awt.Toolkit; 9 7 import java.awt.event.ActionEvent; … … 12 10 import java.awt.image.ConvolveOp; 13 11 import java.awt.image.Kernel; 12 import java.util.ArrayList; 14 13 import java.util.List; 15 14 16 15 import javax.swing.AbstractAction; 17 import javax.swing.Action;18 16 import javax.swing.Icon; 19 17 import javax.swing.ImageIcon; 20 18 import javax.swing.JCheckBoxMenuItem; 21 import javax.swing.JLabel;22 19 import javax.swing.JMenu; 23 import javax.swing.JOptionPane; 24 import javax.swing.JPanel; 25 import javax.swing.JTextField; 20 import javax.swing.JMenuItem; 21 import javax.swing.JSeparator; 26 22 27 23 import org.openstreetmap.josm.Main; … … 32 28 import org.openstreetmap.josm.plugins.imagery.tms.TMSLayer; 33 29 import org.openstreetmap.josm.plugins.imagery.wms.WMSLayer; 34 import org.openstreetmap.josm.tools.GBC;35 30 import org.openstreetmap.josm.tools.ImageProvider; 36 31 … … 121 116 } 122 117 123 class NewBookmarkAction extends AbstractAction { 124 private class BookmarkNamePanel extends JPanel { 125 public JTextField text = new JTextField(); 126 public BookmarkNamePanel() { 127 super(new GridBagLayout()); 128 add(new JLabel(tr("Bookmark name: ")),GBC.eol()); 129 add(text,GBC.eol().fill(GBC.HORIZONTAL)); 130 } 131 } 132 public NewBookmarkAction() { 133 super(tr("(save current)")); 134 } 135 @Override 136 public void actionPerformed(ActionEvent arg0) { 137 BookmarkNamePanel p = new BookmarkNamePanel(); 138 int answer = JOptionPane.showConfirmDialog( 139 Main.parent, p, 140 tr("Add offset bookmark"), 141 JOptionPane.OK_CANCEL_OPTION); 142 if (answer == JOptionPane.OK_OPTION) { 143 OffsetBookmark b = 144 new OffsetBookmark(Main.proj,info.getName(),p.text.getText(),getDx(),getDy()); 145 OffsetBookmark.allBookmarks.add(b); 146 OffsetBookmark.saveBookmarks(); 147 } 148 } 149 } 150 151 class OffsetAction extends AbstractAction implements LayerAction { 118 public class OffsetAction extends AbstractAction implements LayerAction { 152 119 @Override 153 120 public void actionPerformed(ActionEvent e) { … … 157 124 JMenu menu = new JMenu(trc("layer", "Offset")); 158 125 menu.setIcon(ImageProvider.get("mapmode", "adjustimg")); 159 boolean haveCurrent = false; 160 for (OffsetBookmark b : OffsetBookmark.allBookmarks) { 161 if (!b.isUsable(ImageryLayer.this)) continue; 162 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 163 if (b.dx == dx && b.dy == dy) { 164 item.setSelected(true); 165 haveCurrent = true; 166 } 126 for (Component item : getOffsetMenu()) { 167 127 menu.add(item); 168 }169 if (!haveCurrent) {170 menu.insert(new NewBookmarkAction(), 0);171 128 } 172 129 return menu; … … 178 135 } 179 136 180 public Action getOffsetAction() { 181 return new OffsetAction(); 137 public List<Component> getOffsetMenu() { 138 List<Component> result = new ArrayList<Component>(); 139 result.add(new JMenuItem(new ImageryAdjustAction(this))); 140 if (OffsetBookmark.allBookmarks.isEmpty()) return result; 141 142 result.add(new JSeparator(JSeparator.HORIZONTAL)); 143 for (OffsetBookmark b : OffsetBookmark.allBookmarks) { 144 if (!b.isUsable(this)) continue; 145 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 146 if (b.dx == dx && b.dy == dy) { 147 item.setSelected(true); 148 } 149 result.add(item); 150 } 151 return result; 182 152 } 183 153 -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPlugin.java
r24620 r24670 18 18 import org.openstreetmap.josm.actions.ExtensionFileFilter; 19 19 import org.openstreetmap.josm.actions.JosmAction; 20 import org.openstreetmap.josm.gui.IconToggleButton;21 20 import org.openstreetmap.josm.gui.MainMenu; 22 21 import org.openstreetmap.josm.gui.MapFrame; … … 257 256 if (oldFrame==null && newFrame!=null) { 258 257 setEnabledAll(true); 259 Main.map.addMapMode(new IconToggleButton260 (new ImageryAdjustAction(Main.map)));261 258 } else if (oldFrame!=null && newFrame==null ) { 262 259 setEnabledAll(false); -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/BingAerialTileSource.java
r24660 r24670 31 31 public void run() { 32 32 attributions = loadAttributionText(); 33 System.err.println("Added " + attributions.size() + " attributions.");34 33 } 35 34 }); 36 35 t.setDaemon(true); 37 t. run();36 t.start(); 38 37 } 39 38 } … … 109 108 parser.setContentHandler(handler); 110 109 parser.parse(new InputSource(stream)); 110 System.err.println("Added " + handler.attributions.size() + " attributions."); 111 111 return handler.attributions; 112 112 } catch (IOException e) { -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
r24620 r24670 1129 1129 SeparatorLayerAction.INSTANCE, 1130 1130 // color, 1131 getOffsetAction(),1131 new OffsetAction(), 1132 1132 new RenameLayerAction(this.getAssociatedFile(), this), 1133 1133 SeparatorLayerAction.INSTANCE, -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/WMSLayer.java
r24620 r24670 359 359 LayerListDialog.getInstance().createDeleteLayerAction(), 360 360 SeparatorLayerAction.INSTANCE, 361 getOffsetAction(),361 new OffsetAction(), 362 362 new LoadWmsAction(), 363 363 new SaveWmsAction(),
Note:
See TracChangeset
for help on using the changeset viewer.