- Timestamp:
- 2012-08-21T00:06:32+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences/imagery
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r5464 r5465 33 33 import javax.swing.Box; 34 34 import javax.swing.JButton; 35 import javax.swing.JCheckBox;36 import javax.swing.JColorChooser;37 35 import javax.swing.JEditorPane; 38 36 import javax.swing.JLabel; … … 41 39 import javax.swing.JScrollPane; 42 40 import javax.swing.JSeparator; 43 import javax.swing.JSlider;44 import javax.swing.JSpinner;45 41 import javax.swing.JTabbedPane; 46 42 import javax.swing.JTable; 47 import javax.swing.JTextField;48 43 import javax.swing.JToolBar; 49 import javax.swing.SpinnerNumberModel;50 44 import javax.swing.SwingUtilities; 51 import javax.swing.event.ChangeEvent;52 import javax.swing.event.ChangeListener;53 45 import javax.swing.event.ListSelectionEvent; 54 46 import javax.swing.event.ListSelectionListener; … … 71 63 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 72 64 import org.openstreetmap.josm.data.imagery.Shape; 73 import org.openstreetmap.josm.gui.layer.ImageryLayer;74 import org.openstreetmap.josm.gui.layer.TMSLayer;75 import org.openstreetmap.josm.gui.layer.WMSLayer;76 65 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; 77 66 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 78 67 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 79 68 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 80 import org.openstreetmap.josm.gui.widgets.JosmComboBox;81 import org.openstreetmap.josm.io.imagery.HTMLGrabber;82 import org.openstreetmap.josm.io.imagery.OffsetServer;83 import org.openstreetmap.josm.io.imagery.OsmosnimkiOffsetServer;84 import org.openstreetmap.josm.tools.ColorHelper;85 69 import org.openstreetmap.josm.tools.GBC; 86 70 import org.openstreetmap.josm.tools.ImageProvider; … … 102 86 private ImageryLayerInfo layerInfo; 103 87 104 // Common settings 105 private Color colFadeColor; 106 private JButton btnFadeColor; 107 private JSlider fadeAmount = new JSlider(0, 100); 108 private JosmComboBox sharpen; 109 private JCheckBox useOffsetServer; 110 private JTextField offsetServerUrl; 111 112 // WMS Settings 113 private JosmComboBox browser; 114 private JCheckBox overlapCheckBox; 115 private JSpinner spinEast; 116 private JSpinner spinNorth; 117 private JSpinner spinSimConn; 118 119 //TMS settings controls 120 private JCheckBox autozoomActive = new JCheckBox(); 121 private JCheckBox autoloadTiles = new JCheckBox(); 122 private JSpinner minZoomLvl; 123 private JSpinner maxZoomLvl; 124 private JCheckBox addToSlippyMapChosser = new JCheckBox(); 125 private JTextField tilecacheDir = new JTextField(); 126 127 private JPanel buildCommonSettingsPanel(final PreferenceTabbedPane gui) { 128 final JPanel p = new JPanel(new GridBagLayout()); 129 130 this.colFadeColor = ImageryLayer.PROP_FADE_COLOR.get(); 131 this.btnFadeColor = new JButton(); 132 133 this.btnFadeColor.addActionListener(new ActionListener() { 134 @Override 135 public void actionPerformed(ActionEvent e) { 136 JColorChooser chooser = new JColorChooser(colFadeColor); 137 int answer = JOptionPane.showConfirmDialog( 138 gui, chooser, 139 tr("Choose a color for {0}", tr("imagery fade")), 140 JOptionPane.OK_CANCEL_OPTION, 141 JOptionPane.PLAIN_MESSAGE); 142 if (answer == JOptionPane.OK_OPTION) { 143 colFadeColor = chooser.getColor(); 144 btnFadeColor.setBackground(colFadeColor); 145 btnFadeColor.setText(ColorHelper.color2html(colFadeColor)); 146 } 147 } 148 }); 149 150 p.add(new JLabel(tr("Fade Color: ")), GBC.std()); 151 p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 152 p.add(this.btnFadeColor, GBC.eol().fill(GBC.HORIZONTAL)); 153 154 p.add(new JLabel(tr("Fade amount: ")), GBC.std()); 155 p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 156 p.add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL)); 157 158 this.sharpen = new JosmComboBox(new String[] { 159 tr("None"), 160 tr("Soft"), 161 tr("Strong")}); 162 p.add(new JLabel(tr("Sharpen (requires layer re-add): "))); 163 p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 164 p.add(this.sharpen, GBC.eol().fill(GBC.HORIZONTAL)); 165 166 this.useOffsetServer = new JCheckBox(tr("Use offset server: ")); 167 this.offsetServerUrl = new JTextField(); 168 this.useOffsetServer.addChangeListener(new ChangeListener() { 169 @Override 170 public void stateChanged(ChangeEvent e) { 171 offsetServerUrl.setEnabled(useOffsetServer.isSelected()); 172 } 173 }); 174 offsetServerUrl.setEnabled(useOffsetServer.isSelected()); 175 p.add(this.useOffsetServer, GBC.eol().fill(GBC.HORIZONTAL)); 176 p.add(this.offsetServerUrl, GBC.eol().fill(GBC.HORIZONTAL)); 177 return p; 178 } 179 180 private JPanel buildWMSSettingsPanel() { 181 final JPanel p = new JPanel(new GridBagLayout()); 182 browser = new JosmComboBox(new String[] { 183 "webkit-image {0}", 184 "gnome-web-photo --mode=photo --format=png {0} /dev/stdout", 185 "gnome-web-photo-fixed {0}", 186 "webkit-image-gtk {0}"}); 187 browser.setEditable(true); 188 p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL)); 189 p.add(browser); 190 191 // Overlap 192 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 193 194 overlapCheckBox = new JCheckBox(tr("Overlap tiles")); 195 JLabel labelEast = new JLabel(tr("% of east:")); 196 JLabel labelNorth = new JLabel(tr("% of north:")); 197 spinEast = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_EAST.get().intValue(), 1, 50, 1)); 198 spinNorth = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_NORTH.get().intValue(), 1, 50, 1)); 199 200 JPanel overlapPanel = new JPanel(new FlowLayout()); 201 overlapPanel.add(overlapCheckBox); 202 overlapPanel.add(labelEast); 203 overlapPanel.add(spinEast); 204 overlapPanel.add(labelNorth); 205 overlapPanel.add(spinNorth); 206 207 p.add(overlapPanel); 208 209 // Simultaneous connections 210 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 211 JLabel labelSimConn = new JLabel(tr("Simultaneous connections")); 212 spinSimConn = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get().intValue(), 1, 30, 1)); 213 JPanel overlapPanelSimConn = new JPanel(new FlowLayout(FlowLayout.LEFT)); 214 overlapPanelSimConn.add(labelSimConn); 215 overlapPanelSimConn.add(spinSimConn); 216 p.add(overlapPanelSimConn, GBC.eol().fill(GBC.HORIZONTAL)); 217 218 return p; 219 } 220 221 private JPanel buildTMSSettingsPanel() { 222 JPanel tmsTab = new JPanel(new GridBagLayout()); 223 224 minZoomLvl = new JSpinner(new SpinnerNumberModel(TMSLayer.DEFAULT_MIN_ZOOM, TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1)); 225 maxZoomLvl = new JSpinner(new SpinnerNumberModel(TMSLayer.DEFAULT_MAX_ZOOM, TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1)); 226 227 tmsTab.add(new JLabel(tr("Auto zoom by default: ")), GBC.std()); 228 tmsTab.add(GBC.glue(5, 0), GBC.std()); 229 tmsTab.add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 230 231 tmsTab.add(new JLabel(tr("Autoload tiles by default: ")), GBC.std()); 232 tmsTab.add(GBC.glue(5, 0), GBC.std()); 233 tmsTab.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL)); 234 235 tmsTab.add(new JLabel(tr("Min. zoom level: ")), GBC.std()); 236 tmsTab.add(GBC.glue(5, 0), GBC.std()); 237 tmsTab.add(this.minZoomLvl, GBC.eol()); 238 239 tmsTab.add(new JLabel(tr("Max. zoom level: ")), GBC.std()); 240 tmsTab.add(GBC.glue(5, 0), GBC.std()); 241 tmsTab.add(this.maxZoomLvl, GBC.eol()); 242 243 tmsTab.add(new JLabel(tr("Add to slippymap chooser: ")), GBC.std()); 244 tmsTab.add(GBC.glue(5, 0), GBC.std()); 245 tmsTab.add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL)); 246 247 tmsTab.add(new JLabel(tr("Tile cache directory: ")), GBC.std()); 248 tmsTab.add(GBC.glue(5, 0), GBC.std()); 249 tmsTab.add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL)); 250 251 return tmsTab; 252 } 88 private CommonSettingsPanel commonSettings; 89 private WMSSettingsPanel wmsSettings; 90 private TMSSettingsPanel tmsSettings; 253 91 254 92 private void addSettingsSection(final JPanel p, String name, JPanel section) { 255 93 addSettingsSection(p, name, section, GBC.eol()); 256 94 } 95 257 96 private void addSettingsSection(final JPanel p, String name, JPanel section, GBC gbc) { 258 97 final JLabel lbl = new JLabel(name); … … 267 106 p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 268 107 269 addSettingsSection(p, tr("Common Settings"), buildCommonSettingsPanel(gui)); 270 addSettingsSection(p, tr("WMS Settings"), buildWMSSettingsPanel()); 271 addSettingsSection(p, tr("TMS Settings"), buildTMSSettingsPanel(), 108 addSettingsSection(p, tr("Common Settings"), commonSettings = new CommonSettingsPanel()); 109 addSettingsSection(p, tr("WMS Settings"), wmsSettings = new WMSSettingsPanel(), 110 GBC.eol().fill(GBC.HORIZONTAL)); 111 addSettingsSection(p, tr("TMS Settings"), tmsSettings = new TMSSettingsPanel(), 272 112 GBC.eol().fill(GBC.HORIZONTAL)); 273 113 … … 297 137 298 138 private void loadSettings() { 299 // Common settings 300 this.btnFadeColor.setBackground(colFadeColor); 301 this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor)); 302 this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get()); 303 this.sharpen.setSelectedIndex(Math.max(0, Math.min(2, ImageryLayer.PROP_SHARPEN_LEVEL.get()))); 304 this.useOffsetServer.setSelected(OffsetServer.PROP_SERVER_ENABLED.get()); 305 this.offsetServerUrl.setText(OsmosnimkiOffsetServer.PROP_SERVER_URL.get()); 306 307 // WMS Settings 308 this.browser.setSelectedItem(HTMLGrabber.PROP_BROWSER.get()); 309 this.overlapCheckBox.setSelected(WMSLayer.PROP_OVERLAP.get()); 310 this.spinEast.setValue(WMSLayer.PROP_OVERLAP_EAST.get()); 311 this.spinNorth.setValue(WMSLayer.PROP_OVERLAP_NORTH.get()); 312 this.spinSimConn.setValue(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get()); 313 314 // TMS Settings 315 this.autozoomActive.setSelected(TMSLayer.PROP_DEFAULT_AUTOZOOM.get()); 316 this.autoloadTiles.setSelected(TMSLayer.PROP_DEFAULT_AUTOLOAD.get()); 317 this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get()); 318 this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null)); 319 this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null)); 320 this.tilecacheDir.setText(TMSLayer.PROP_TILECACHE_DIR.get()); 139 commonSettings.loadSettings(); 140 wmsSettings.loadSettings(); 141 tmsSettings.loadSettings(); 321 142 } 322 143 323 144 @Override 324 145 public boolean ok() { 325 boolean restartRequired = false;326 146 layerInfo.save(); 327 147 ImageryLayerInfo.instance.clear(); … … 331 151 OffsetBookmark.saveBookmarks(); 332 152 333 WMSLayer.PROP_OVERLAP.put(overlapCheckBox.getModel().isSelected()); 334 WMSLayer.PROP_OVERLAP_EAST.put((Integer) spinEast.getModel().getValue()); 335 WMSLayer.PROP_OVERLAP_NORTH.put((Integer) spinNorth.getModel().getValue()); 336 WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.put((Integer) spinSimConn.getModel().getValue()); 337 338 HTMLGrabber.PROP_BROWSER.put(browser.getEditor().getItem().toString()); 339 OffsetServer.PROP_SERVER_ENABLED.put(useOffsetServer.isSelected()); 340 OsmosnimkiOffsetServer.PROP_SERVER_URL.put(offsetServerUrl.getText()); 341 342 if (TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get() != this.addToSlippyMapChosser.isSelected()) { 343 restartRequired = true; 344 } 345 TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.put(this.addToSlippyMapChosser.isSelected()); 346 TMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected()); 347 TMSLayer.PROP_DEFAULT_AUTOLOAD.put(this.autoloadTiles.isSelected()); 348 TMSLayer.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue()); 349 TMSLayer.setMinZoomLvl((Integer)this.minZoomLvl.getValue()); 350 TMSLayer.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText()); 351 352 ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue()); 353 ImageryLayer.PROP_FADE_COLOR.put(this.colFadeColor); 354 ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex()); 355 356 return restartRequired; 357 } 358 153 boolean commonRestartRequired = commonSettings.saveSettings(); 154 boolean wmsRestartRequired = wmsSettings.saveSettings(); 155 boolean tmsRestartRequired = tmsSettings.saveSettings(); 156 157 return commonRestartRequired || wmsRestartRequired || tmsRestartRequired; 158 } 359 159 360 160 /**
Note:
See TracChangeset
for help on using the changeset viewer.