Changeset 24584 in osm for applications/editors
- Timestamp:
- 2010-12-04T21:20:38+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryLayer.java
r24555 r24584 1 1 package org.openstreetmap.josm.plugins.imagery; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.trc; 5 6 import java.awt.Component; 7 import java.awt.GridBagLayout; 3 8 import java.awt.Toolkit; 9 import java.awt.event.ActionEvent; 10 import java.util.List; 4 11 12 import javax.swing.AbstractAction; 13 import javax.swing.Action; 5 14 import javax.swing.Icon; 6 15 import javax.swing.ImageIcon; 16 import javax.swing.JCheckBoxMenuItem; 17 import javax.swing.JLabel; 18 import javax.swing.JMenu; 19 import javax.swing.JOptionPane; 20 import javax.swing.JPanel; 21 import javax.swing.JTextField; 7 22 8 23 import org.openstreetmap.josm.Main; … … 13 28 import org.openstreetmap.josm.plugins.imagery.tms.TMSLayer; 14 29 import org.openstreetmap.josm.plugins.imagery.wms.WMSLayer; 30 import org.openstreetmap.josm.tools.GBC; 31 import org.openstreetmap.josm.tools.ImageProvider; 15 32 16 33 public abstract class ImageryLayer extends Layer { … … 18 35 new ImageIcon(Toolkit.getDefaultToolkit().createImage(ImageryPlugin.class.getResource("/images/imagery_small.png"))); 19 36 20 protected ImageryInfo info;37 protected final ImageryInfo info; 21 38 protected MapView mv; 22 39 … … 30 47 } 31 48 32 33 49 public double getPPD(){ 34 50 ProjectionBounds bounds = mv.getProjectionBounds(); 35 51 return mv.getWidth() / (bounds.max.east() - bounds.min.east()); 36 }37 38 public void displace(double dx, double dy) {39 this.dx += dx;40 this.dy += dy;41 52 } 42 53 … … 47 58 public double getDy() { 48 59 return dy; 60 } 61 62 public void setOffset(double dx, double dy) { 63 this.dx = dx; 64 this.dy = dy; 65 } 66 67 public void displace(double dx, double dy) { 68 setOffset(this.dx += dx, this.dy += dy); 49 69 } 50 70 … … 79 99 } else throw new AssertionError(); 80 100 } 101 102 class ApplyOffsetAction extends AbstractAction { 103 private OffsetBookmark b; 104 ApplyOffsetAction(OffsetBookmark b) { 105 super(b.name); 106 this.b = b; 107 } 108 109 @Override 110 public void actionPerformed(ActionEvent arg0) { 111 setOffset(b.dx, b.dy); 112 Main.map.repaint(); 113 } 114 } 115 116 class NewBookmarkAction extends AbstractAction { 117 private class BookmarkNamePanel extends JPanel { 118 public JTextField text = new JTextField(); 119 public BookmarkNamePanel() { 120 super(new GridBagLayout()); 121 add(new JLabel(tr("Bookmark name: ")),GBC.eol()); 122 add(text,GBC.eol().fill(GBC.HORIZONTAL)); 123 } 124 } 125 public NewBookmarkAction() { 126 super(tr("(save current)")); 127 } 128 @Override 129 public void actionPerformed(ActionEvent arg0) { 130 BookmarkNamePanel p = new BookmarkNamePanel(); 131 int answer = JOptionPane.showConfirmDialog( 132 Main.parent, p, 133 tr("Add offset bookmark"), 134 JOptionPane.OK_CANCEL_OPTION); 135 if (answer == JOptionPane.OK_OPTION) { 136 OffsetBookmark b = 137 new OffsetBookmark(Main.proj,info.getName(),p.text.getText(),getDx(),getDy()); 138 OffsetBookmark.allBookmarks.add(b); 139 OffsetBookmark.saveBookmarks(); 140 } 141 } 142 } 143 144 class OffsetAction extends AbstractAction implements LayerAction { 145 @Override 146 public void actionPerformed(ActionEvent e) { 147 } 148 @Override 149 public Component createMenuComponent() { 150 JMenu menu = new JMenu(trc("layer", "Offset")); 151 menu.setIcon(ImageProvider.get("mapmode", "adjustimg")); 152 boolean haveCurrent = false; 153 for (OffsetBookmark b : OffsetBookmark.allBookmarks) { 154 if (!b.isUsable(ImageryLayer.this)) continue; 155 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 156 if (b.dx == dx && b.dy == dy) { 157 item.setSelected(true); 158 haveCurrent = true; 159 } 160 menu.add(item); 161 } 162 if (!haveCurrent) { 163 menu.insert(new NewBookmarkAction(), 0); 164 } 165 return menu; 166 } 167 @Override 168 public boolean supportLayers(List<Layer> layers) { 169 return false; 170 } 171 } 172 173 public Action getOffsetAction() { 174 return new OffsetAction(); 175 } 176 81 177 } -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPlugin.java
r24572 r24584 40 40 41 41 public ImageryLayerInfo info = new ImageryLayerInfo(); 42 43 42 // remember state of menu item to restore on changed preferences 44 43 private boolean menuEnabled = false; … … 205 204 instance = this; 206 205 this.info.load(); 206 OffsetBookmark.loadBookmarks(); 207 207 refreshMenu(); 208 208 initRemoteControl(); -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPreferenceEditor.java
r24575 r24584 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.trc;5 4 6 5 import java.awt.Color; 7 6 import java.awt.Component; 8 import java.awt.Dimension;9 7 import java.awt.FlowLayout; 10 8 import java.awt.Font; 11 import java.awt.GridBagConstraints;12 9 import java.awt.GridBagLayout; 13 10 import java.awt.event.ActionEvent; 14 11 import java.awt.event.ActionListener; 15 import java.awt.event.MouseEvent;16 import java.io.IOException;17 import java.net.MalformedURLException;18 import java.net.URL;19 import java.util.Locale;20 12 21 13 import javax.swing.BorderFactory; … … 25 17 import javax.swing.JColorChooser; 26 18 import javax.swing.JComboBox; 27 import javax.swing.JEditorPane;28 19 import javax.swing.JLabel; 29 20 import javax.swing.JOptionPane; … … 34 25 import javax.swing.JSpinner; 35 26 import javax.swing.JTabbedPane; 36 import javax.swing.JTable;37 27 import javax.swing.SpinnerNumberModel; 38 import javax.swing.table.DefaultTableModel;39 import javax.swing.table.TableColumnModel;40 28 41 29 import org.openstreetmap.josm.Main; 42 30 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 43 31 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 44 import org.openstreetmap.josm.plugins.imagery.ImageryInfo.ImageryType;45 32 import org.openstreetmap.josm.plugins.imagery.tms.TMSPreferences; 46 import org.openstreetmap.josm.plugins.imagery.wms.AddWMSLayerPanel;47 33 import org.openstreetmap.josm.plugins.imagery.wms.WMSAdapter; 48 34 import org.openstreetmap.josm.tools.ColorHelper; … … 50 36 51 37 public class ImageryPreferenceEditor implements PreferenceSetting { 52 private ImageryLayerTableModel model; 53 private JComboBox browser; 38 ImageryProvidersPanel imageryProviders; 54 39 55 40 // Common settings … … 61 46 62 47 // WMS Settings 48 private JComboBox browser; 63 49 JCheckBox overlapCheckBox; 64 50 JSpinner spinEast; … … 73 59 private JSpinner minZoomLvl; 74 60 private JSpinner maxZoomLvl; 75 76 77 private JPanel buildImageryProvidersPanel(final PreferenceTabbedPane gui) {78 final JPanel p = new JPanel(new GridBagLayout());79 model = new ImageryLayerTableModel();80 final JTable list = new JTable(model) {81 @Override82 public String getToolTipText(MouseEvent e) {83 java.awt.Point p = e.getPoint();84 return model.getValueAt(rowAtPoint(p), columnAtPoint(p)).toString();85 }86 };87 JScrollPane scroll = new JScrollPane(list);88 p.add(scroll, GBC.eol().fill(GridBagConstraints.BOTH));89 scroll.setPreferredSize(new Dimension(200, 200));90 91 final ImageryDefaultLayerTableModel modeldef = new ImageryDefaultLayerTableModel();92 final JTable listdef = new JTable(modeldef) {93 @Override94 public String getToolTipText(MouseEvent e) {95 java.awt.Point p = e.getPoint();96 return (String) modeldef.getValueAt(rowAtPoint(p), columnAtPoint(p));97 }98 };99 JScrollPane scrolldef = new JScrollPane(listdef);100 // scrolldef is added after the buttons so it's clearer the buttons101 // control the top list and not the default one102 scrolldef.setPreferredSize(new Dimension(200, 200));103 104 TableColumnModel mod = listdef.getColumnModel();105 mod.getColumn(1).setPreferredWidth(800);106 mod.getColumn(0).setPreferredWidth(200);107 mod = list.getColumnModel();108 mod.getColumn(2).setPreferredWidth(50);109 mod.getColumn(1).setPreferredWidth(800);110 mod.getColumn(0).setPreferredWidth(200);111 112 JPanel buttonPanel = new JPanel(new FlowLayout());113 114 JButton add = new JButton(tr("Add"));115 buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0));116 add.addActionListener(new ActionListener() {117 @Override118 public void actionPerformed(ActionEvent e) {119 AddWMSLayerPanel p = new AddWMSLayerPanel();120 int answer = JOptionPane.showConfirmDialog(121 gui, p,122 tr("Add Imagery URL"),123 JOptionPane.OK_CANCEL_OPTION);124 if (answer == JOptionPane.OK_OPTION) {125 model.addRow(new ImageryInfo(p.getUrlName(), p.getUrl()));126 }127 }128 });129 130 JButton delete = new JButton(tr("Delete"));131 buttonPanel.add(delete, GBC.std().insets(0, 5, 0, 0));132 delete.addActionListener(new ActionListener() {133 @Override134 public void actionPerformed(ActionEvent e) {135 if (list.getSelectedRow() == -1)136 JOptionPane.showMessageDialog(gui, tr("Please select the row to delete."));137 else {138 Integer i;139 while ((i = list.getSelectedRow()) != -1)140 model.removeRow(i);141 }142 }143 });144 145 JButton copy = new JButton(tr("Copy Selected Default(s)"));146 buttonPanel.add(copy, GBC.std().insets(0, 5, 0, 0));147 copy.addActionListener(new ActionListener() {148 @Override149 public void actionPerformed(ActionEvent e) {150 int[] lines = listdef.getSelectedRows();151 if (lines.length == 0) {152 JOptionPane.showMessageDialog(153 gui,154 tr("Please select at least one row to copy."),155 tr("Information"),156 JOptionPane.INFORMATION_MESSAGE);157 return;158 }159 160 outer: for (int i = 0; i < lines.length; i++) {161 ImageryInfo info = modeldef.getRow(lines[i]);162 163 // Check if an entry with exactly the same values already164 // exists165 for (int j = 0; j < model.getRowCount(); j++) {166 if (info.equalsBaseValues(model.getRow(j))) {167 // Select the already existing row so the user has168 // some feedback in case an entry exists169 list.getSelectionModel().setSelectionInterval(j, j);170 list.scrollRectToVisible(list.getCellRect(j, 0, true));171 continue outer;172 }173 }174 175 if (info.eulaAcceptanceRequired != null) {176 if (!confirmeEulaAcceptance(gui, info.eulaAcceptanceRequired))177 continue outer;178 }179 180 model.addRow(new ImageryInfo(info));181 int lastLine = model.getRowCount() - 1;182 list.getSelectionModel().setSelectionInterval(lastLine, lastLine);183 list.scrollRectToVisible(list.getCellRect(lastLine, 0, true));184 }185 }186 });187 188 p.add(buttonPanel);189 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));190 // Add default item list191 p.add(scrolldef, GBC.eol().insets(0, 5, 0, 0).fill(GridBagConstraints.BOTH));192 193 return p;194 }195 61 196 62 private JPanel buildCommonSettingsPanel(final PreferenceTabbedPane gui) { … … 331 197 JPanel p = gui.createPreferenceTab("imagery", tr("Imagery Preferences"), tr("Modify list of imagery layers displayed in the Imagery menu")); 332 198 JTabbedPane pane = new JTabbedPane(); 333 pane.add(buildImageryProvidersPanel(gui)); 199 imageryProviders = new ImageryProvidersPanel(gui, plugin.info); 200 pane.add(imageryProviders); 334 201 pane.add(buildSettingsPanel(gui)); 202 pane.add(new OffsetBookmarksPanel(gui)); 335 203 pane.setTitleAt(0, tr("Imagery providers")); 336 204 pane.setTitleAt(1, tr("Settings")); 205 pane.setTitleAt(2, tr("Offset bookmarks")); 337 206 p.add(pane,GBC.std().fill(GBC.BOTH)); 338 207 } … … 342 211 plugin.info.save(); 343 212 plugin.refreshMenu(); 213 OffsetBookmark.saveBookmarks(); 344 214 345 215 wmsAdapter.PROP_OVERLAP.put(overlapCheckBox.getModel().isSelected()); … … 373 243 */ 374 244 public void setServerUrl(String server, String url) { 375 for (int i = 0; i < model.getRowCount(); i++) {376 if (server.equals( model.getValueAt(i, 0).toString())) {377 model.setValueAt(url, i, 1);245 for (int i = 0; i < imageryProviders.model.getRowCount(); i++) { 246 if (server.equals(imageryProviders.model.getValueAt(i, 0).toString())) { 247 imageryProviders.model.setValueAt(url, i, 1); 378 248 return; 379 249 } 380 250 } 381 model.addRow(new String[] { server, url });251 imageryProviders.model.addRow(new String[] { server, url }); 382 252 } 383 253 … … 390 260 */ 391 261 public String getServerUrl(String server) { 392 for (int i = 0; i < model.getRowCount(); i++) {393 if (server.equals( model.getValueAt(i, 0).toString())) {394 return model.getValueAt(i, 1).toString();262 for (int i = 0; i < imageryProviders.model.getRowCount(); i++) { 263 if (server.equals(imageryProviders.model.getValueAt(i, 0).toString())) { 264 return imageryProviders.model.getValueAt(i, 1).toString(); 395 265 } 396 266 } 397 267 return null; 398 268 } 399 400 /**401 * The table model for the WMS layer402 *403 */404 class ImageryLayerTableModel extends DefaultTableModel {405 public ImageryLayerTableModel() {406 setColumnIdentifiers(new String[] { tr("Menu Name"), tr("Imagery URL"), trc("layer", "Zoom") });407 }408 409 public ImageryInfo getRow(int row) {410 return plugin.info.layers.get(row);411 }412 413 public void addRow(ImageryInfo i) {414 plugin.info.add(i);415 int p = getRowCount() - 1;416 fireTableRowsInserted(p, p);417 }418 419 @Override420 public void removeRow(int i) {421 plugin.info.remove(getRow(i));422 fireTableRowsDeleted(i, i);423 }424 425 @Override426 public int getRowCount() {427 return plugin.info.layers.size();428 }429 430 @Override431 public Object getValueAt(int row, int column) {432 ImageryInfo info = plugin.info.layers.get(row);433 switch (column) {434 case 0:435 return info.name;436 case 1:437 return info.getFullURL();438 case 2:439 return (info.imageryType == ImageryType.WMS) ? (info.pixelPerDegree == 0.0 ? "" : info.pixelPerDegree)440 : (info.maxZoom == 0 ? "" : info.maxZoom);441 default:442 throw new ArrayIndexOutOfBoundsException();443 }444 }445 446 @Override447 public void setValueAt(Object o, int row, int column) {448 ImageryInfo info = plugin.info.layers.get(row);449 switch (column) {450 case 0:451 info.name = (String) o;452 break;453 case 1:454 info.setURL((String)o);455 break;456 case 2:457 info.pixelPerDegree = 0;458 info.maxZoom = 0;459 try {460 if(info.imageryType == ImageryType.WMS)461 info.pixelPerDegree = Double.parseDouble((String) o);462 else463 info.maxZoom = Integer.parseInt((String) o);464 } catch (NumberFormatException e) {465 }466 break;467 default:468 throw new ArrayIndexOutOfBoundsException();469 }470 }471 472 @Override473 public boolean isCellEditable(int row, int column) {474 return true;475 }476 }477 478 /**479 * The table model for the WMS layer480 *481 */482 class ImageryDefaultLayerTableModel extends DefaultTableModel {483 public ImageryDefaultLayerTableModel() {484 setColumnIdentifiers(new String[] { tr("Menu Name (Default)"), tr("Imagery URL (Default)") });485 }486 487 public ImageryInfo getRow(int row) {488 return plugin.info.defaultLayers.get(row);489 }490 491 @Override492 public int getRowCount() {493 return plugin.info.defaultLayers.size();494 }495 496 @Override497 public Object getValueAt(int row, int column) {498 ImageryInfo info = plugin.info.defaultLayers.get(row);499 switch (column) {500 case 0:501 return info.name;502 case 1:503 return info.getFullURL();504 }505 return null;506 }507 508 @Override509 public boolean isCellEditable(int row, int column) {510 return false;511 }512 }513 514 private boolean confirmeEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) {515 URL url = null;516 try {517 url = new URL(eulaUrl.replaceAll("\\{lang\\}", Locale.getDefault().toString()));518 JEditorPane htmlPane = null;519 try {520 htmlPane = new JEditorPane(url);521 } catch (IOException e1) {522 // give a second chance with a default Locale 'en'523 try {524 url = new URL(eulaUrl.replaceAll("\\{lang\\}", "en"));525 htmlPane = new JEditorPane(url);526 } catch (IOException e2) {527 JOptionPane.showMessageDialog(gui ,tr("EULA license URL not available: {0}", eulaUrl));528 return false;529 }530 }531 Box box = Box.createVerticalBox();532 htmlPane.setEditable(false);533 JScrollPane scrollPane = new JScrollPane(htmlPane);534 scrollPane.setPreferredSize(new Dimension(400, 400));535 box.add(scrollPane);536 int option = JOptionPane.showConfirmDialog(Main.parent, box, tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,537 JOptionPane.WARNING_MESSAGE);538 if (option == JOptionPane.YES_OPTION) {539 return true;540 }541 } catch (MalformedURLException e2) {542 JOptionPane.showMessageDialog(gui ,tr("Malformed URL for the EULA licence: {0}", eulaUrl));543 }544 return false;545 }546 269 } -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPreferences.java
r24572 r24584 24 24 Main.pref.putColor("imagery.fade", color); 25 25 } 26 27 28 26 } -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
r24567 r24584 161 161 162 162 @Override 163 public void displace(double dx, double dy) {164 super. displace(dx, dy);163 public void setOffset(double dx, double dy) { 164 super.setOffset(dx, dy); 165 165 needRedraw = true; 166 166 } … … 1138 1138 SeparatorLayerAction.INSTANCE, 1139 1139 // color, 1140 getOffsetAction(), 1140 1141 new RenameLayerAction(this.getAssociatedFile(), this), 1141 1142 SeparatorLayerAction.INSTANCE, -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/WMSLayer.java
r24555 r24584 30 30 import org.openstreetmap.josm.actions.SaveActionBase; 31 31 import org.openstreetmap.josm.data.Bounds; 32 import org.openstreetmap.josm.data.ProjectionBounds; 32 33 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 33 34 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 34 import org.openstreetmap.josm.data.ProjectionBounds;35 35 import org.openstreetmap.josm.data.coor.EastNorth; 36 36 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 42 42 import org.openstreetmap.josm.io.CacheFiles; 43 43 import org.openstreetmap.josm.plugins.imagery.ImageryInfo; 44 import org.openstreetmap.josm.plugins.imagery.ImageryInfo.ImageryType;45 44 import org.openstreetmap.josm.plugins.imagery.ImageryLayer; 46 45 import org.openstreetmap.josm.plugins.imagery.ImageryPlugin; 46 import org.openstreetmap.josm.plugins.imagery.ImageryInfo.ImageryType; 47 47 import org.openstreetmap.josm.plugins.imagery.wms.GeorefImage.State; 48 48 import org.openstreetmap.josm.tools.ImageProvider; … … 69 69 protected boolean autoDownloadEnabled = true; 70 70 protected boolean settingsChanged; 71 protected ImageryInfo info; 71 72 72 73 // Image index boundary for current view … … 242 243 243 244 @Override 244 public void displace(double dx, double dy) {245 super. displace(dx, dy);245 public void setOffset(double dx, double dy) { 246 super.setOffset(dx, dy); 246 247 settingsChanged = true; 247 248 } … … 357 358 LayerListDialog.getInstance().createDeleteLayerAction(), 358 359 SeparatorLayerAction.INSTANCE, 360 getOffsetAction(), 359 361 new LoadWmsAction(), 360 362 new SaveWmsAction(),
Note:
See TracChangeset
for help on using the changeset viewer.