Changeset 24548 in osm for applications/editors
- Timestamp:
- 2010-12-03T12:57:17+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryPreferenceEditor.java
r24544 r24548 4 4 import static org.openstreetmap.josm.tools.I18n.trc; 5 5 6 import java.awt.Color; 6 7 import java.awt.Component; 7 8 import java.awt.Dimension; … … 22 23 import javax.swing.JButton; 23 24 import javax.swing.JCheckBox; 25 import javax.swing.JColorChooser; 24 26 import javax.swing.JComboBox; 25 27 import javax.swing.JEditorPane; … … 44 46 import org.openstreetmap.josm.plugins.imagery.wms.AddWMSLayerPanel; 45 47 import org.openstreetmap.josm.plugins.imagery.wms.WMSAdapter; 48 import org.openstreetmap.josm.tools.ColorHelper; 46 49 import org.openstreetmap.josm.tools.GBC; 47 50 … … 50 53 private JComboBox browser; 51 54 55 // Common settings 56 private Color colFadeColor; 57 private JButton btnFadeColor; 58 private JSlider fadeAmount = new JSlider(0, 100); 59 60 // WMS Settings 52 61 JCheckBox overlapCheckBox; 53 62 JSpinner spinEast; … … 62 71 private JCheckBox autozoomActive = new JCheckBox(); 63 72 private JCheckBox autoloadTiles = new JCheckBox(); 73 private JSpinner minZoomLvl; 64 74 private JSpinner maxZoomLvl; 65 private JSpinner minZoomLvl = new JSpinner();66 private JSlider fadeBackground = new JSlider(0, 100);67 75 68 76 … … 186 194 } 187 195 196 private JPanel buildCommonSettingsPanel(final PreferenceTabbedPane gui) { 197 final JPanel p = new JPanel(new GridBagLayout()); 198 199 this.colFadeColor = ImageryPreferences.getFadeColor(); 200 this.btnFadeColor = new JButton(); 201 this.btnFadeColor.setBackground(colFadeColor); 202 this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor)); 203 204 this.btnFadeColor.addActionListener(new ActionListener() { 205 @Override 206 public void actionPerformed(ActionEvent e) { 207 JColorChooser chooser = new JColorChooser(colFadeColor); 208 int answer = JOptionPane.showConfirmDialog( 209 gui, chooser, 210 tr("Choose a color for {0}", tr("imagery fade")), 211 JOptionPane.OK_CANCEL_OPTION, 212 JOptionPane.PLAIN_MESSAGE); 213 if (answer == JOptionPane.OK_OPTION) { 214 colFadeColor = chooser.getColor(); 215 btnFadeColor.setBackground(colFadeColor); 216 btnFadeColor.setText(ColorHelper.color2html(colFadeColor)); 217 } 218 } 219 }); 220 221 p.add(new JLabel(tr("Fade Color: ")), GBC.std()); 222 p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 223 p.add(this.btnFadeColor, GBC.eol().fill(GBC.HORIZONTAL)); 224 225 p.add(new JLabel(tr("Fade amount: ")), GBC.std()); 226 p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 227 p.add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL)); 228 229 this.fadeAmount.setValue(ImageryPreferences.PROP_FADE_AMOUNT.get()); 230 return p; 231 } 232 188 233 private JPanel buildWMSSettingsPanel() { 189 final JPanel p nlW= new JPanel(new GridBagLayout());234 final JPanel p = new JPanel(new GridBagLayout()); 190 235 browser = new JComboBox(new String[] { 191 236 "webkit-image {0}", … … 195 240 browser.setEditable(true); 196 241 browser.setSelectedItem(Main.pref.get("wmsplugin.browser", "webkit-image {0}")); 197 p nlW.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL));198 p nlW.add(browser);242 p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL)); 243 p.add(browser); 199 244 200 245 // Overlap 201 p nlW.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));246 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 202 247 203 248 overlapCheckBox = new JCheckBox(tr("Overlap tiles"), wmsAdapter.PROP_OVERLAP.get()); … … 214 259 overlapPanel.add(spinNorth); 215 260 216 p nlW.add(overlapPanel);261 p.add(overlapPanel); 217 262 218 263 // Simultaneous connections 219 p nlW.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));264 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 220 265 JLabel labelSimConn = new JLabel(tr("Simultaneous connections")); 221 266 spinSimConn = new JSpinner(new SpinnerNumberModel(wmsAdapter.PROP_SIMULTANEOUS_CONNECTIONS.get(), 1, 30, 1)); … … 223 268 overlapPanelSimConn.add(labelSimConn); 224 269 overlapPanelSimConn.add(spinSimConn); 225 p nlW.add(overlapPanelSimConn, GBC.eol().fill(GBC.HORIZONTAL));270 p.add(overlapPanelSimConn, GBC.eol().fill(GBC.HORIZONTAL)); 226 271 227 272 allowRemoteControl = Main.pref.getBoolean("wmsplugin.remotecontrol", true); … … 230 275 remotePanel.add(remoteCheckBox); 231 276 232 p nlW.add(remotePanel,GBC.eol().fill(GBC.HORIZONTAL));233 return p nlW;277 p.add(remotePanel,GBC.eol().fill(GBC.HORIZONTAL)); 278 return p; 234 279 } 235 280 … … 255 300 tmsTab.add(this.maxZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 256 301 257 tmsTab.add(new JLabel(tr("Fade background: ")), GBC.std());258 tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));259 tmsTab.add(this.fadeBackground, GBC.eol().fill(GBC.HORIZONTAL));260 261 302 tmsTab.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 262 303 … … 265 306 this.maxZoomLvl.setValue(TMSPreferences.getMaxZoomLvl(null)); 266 307 this.minZoomLvl.setValue(TMSPreferences.getMinZoomLvl(null)); 267 this.fadeBackground.setValue(TMSPreferences.PROP_FADE_BACKGROUND.get());268 308 return tmsTab; 269 309 } 270 310 271 private Component buildSettingsPanel() { 272 // TODO: make some settings common for WMS and TMS 311 private void addSettingsSection(final JPanel p, String name, JPanel section) { 312 final JLabel lbl = new JLabel(name); 313 lbl.setFont(lbl.getFont().deriveFont(Font.BOLD)); 314 p.add(lbl); 315 p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0)); 316 p.add(section,GBC.eol().insets(20,5,0,5)); 317 } 318 319 private Component buildSettingsPanel(final PreferenceTabbedPane gui) { 273 320 final JPanel p = new JPanel(new GridBagLayout()); 274 321 p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 275 322 276 final JLabel lblW = new JLabel(tr("WMS Settings")); 277 lblW.setFont(lblW.getFont().deriveFont(Font.BOLD)); 278 p.add(lblW); 279 p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0)); 280 p.add(buildWMSSettingsPanel(),GBC.eol().insets(20,5,0,0)); 281 282 final JLabel lblT = new JLabel(tr("TMS Settings")); 283 lblT.setFont(lblT.getFont().deriveFont(Font.BOLD)); 284 p.add(lblT); 285 p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0)); 286 p.add(buildTMSSettingsPanel(),GBC.eol().insets(20,5,0,0)); 323 addSettingsSection(p, tr("Common Settings"), buildCommonSettingsPanel(gui)); 324 addSettingsSection(p, tr("WMS Settings"), buildWMSSettingsPanel()); 325 addSettingsSection(p, tr("TMS Settings"), buildTMSSettingsPanel()); 287 326 288 327 p.add(new JPanel(),GBC.eol().fill(GBC.BOTH)); … … 295 334 JTabbedPane pane = new JTabbedPane(); 296 335 pane.add(buildImageryProvidersPanel(gui)); 297 pane.add(buildSettingsPanel( ));336 pane.add(buildSettingsPanel(gui)); 298 337 pane.setTitleAt(0, tr("Imagery providers")); 299 338 pane.setTitleAt(1, tr("Settings")); … … 320 359 TMSPreferences.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue()); 321 360 TMSPreferences.setMinZoomLvl((Integer)this.minZoomLvl.getValue()); 322 TMSPreferences.PROP_FADE_BACKGROUND.put(this.fadeBackground.getValue()); 361 362 ImageryPreferences.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue()); 363 ImageryPreferences.setFadeColor(this.colFadeColor); 323 364 324 365 return false; -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java
r24544 r24548 53 53 import org.openstreetmap.josm.gui.layer.Layer; 54 54 import org.openstreetmap.josm.plugins.imagery.ImageryInfo; 55 import org.openstreetmap.josm.plugins.imagery.ImageryInfo.ImageryType; 55 56 import org.openstreetmap.josm.plugins.imagery.ImageryLayer; 56 import org.openstreetmap.josm.plugins.imagery.Imagery Info.ImageryType;57 import org.openstreetmap.josm.plugins.imagery.ImageryPreferences; 57 58 58 59 /** … … 690 691 img_x_end, img_y_end, 691 692 this); 692 float fadeBackground = TMSPreferences.getFadeBackground(); 693 if (fadeBackground != 0f) { 693 if (ImageryPreferences.PROP_FADE_AMOUNT.get() != 0) { 694 694 // dimm by painting opaque rect... 695 // TODO: make fade color configurable and implement same feature for WMS layers 696 g.setColor(new Color(1f, 1f, 1f, fadeBackground)); 695 g.setColor(ImageryPreferences.getFadeColorWithAlpha()); 697 696 g.fillRect(target.x, target.y, 698 697 target.width, target.height); -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSPreferences.java
r24544 r24548 26 26 public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", DEFAULT_MIN_ZOOM); 27 27 public static final IntegerProperty PROP_MAX_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".max_zoom_lvl", DEFAULT_MAX_ZOOM); 28 public static final IntegerProperty PROP_FADE_BACKGROUND = new IntegerProperty(PREFERENCE_PREFIX + ".fade_background", 0);29 28 public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false); 30 31 public static void setFadeBackground(float fadeBackground) {32 PROP_FADE_BACKGROUND.put(Math.round(fadeBackground*100));33 }34 35 /**36 *37 * @return number between 0 and 1, inclusive38 */39 public static float getFadeBackground() {40 float parsed = (PROP_FADE_BACKGROUND.get())/100.0f;41 if(parsed < 0f) {42 parsed = 0f;43 } else {44 if(parsed > 1f) {45 parsed = 1f;46 }47 }48 return parsed;49 }50 29 51 30 static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) -
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/GeorefImage.java
r24501 r24548 19 19 import org.openstreetmap.josm.data.coor.EastNorth; 20 20 import org.openstreetmap.josm.gui.NavigatableComponent; 21 import org.openstreetmap.josm.plugins.imagery.ImageryPreferences; 21 22 22 23 public class GeorefImage implements Serializable { … … 33 34 private int yIndex; 34 35 36 private static final Color transparentColor = new Color(0,0,0,0); 37 private Color fadeColor = transparentColor; 35 38 36 39 public EastNorth getMin() { … … 122 125 return false; 123 126 127 // TODO: implement per-layer fade color 128 Color newFadeColor; 129 if (ImageryPreferences.PROP_FADE_AMOUNT.get() == 0) 130 newFadeColor = transparentColor; 131 else 132 newFadeColor = ImageryPreferences.getFadeColorWithAlpha(); 133 124 134 BufferedImage img = reImg == null?null:reImg.get(); 125 if(img != null && img.getWidth() == width && img.getHeight() == height ) {135 if(img != null && img.getWidth() == width && img.getHeight() == height && fadeColor.equals(newFadeColor)) { 126 136 g.drawImage(img, x, y, null); 127 137 return true; 128 138 } 139 140 fadeColor = newFadeColor; 129 141 130 142 boolean alphaChannel = WMSLayer.PROP_ALPHA_CHANNEL.get() && getImage().getTransparency() != Transparency.OPAQUE; … … 143 155 // Also prevent caching if we're out of memory soon 144 156 if(width > 2000 || height > 2000 || width*height*multipl > freeMem) { 145 fallbackDraw(g, getImage(), x, y, width, height );157 fallbackDraw(g, getImage(), x, y, width, height, alphaChannel); 146 158 } else { 147 159 // We haven't got a saved resized copy, so resize and cache it … … 151 163 0, 0, getImage().getWidth(null), getImage().getHeight(null), // src 152 164 null); 165 if (!alphaChannel) { 166 drawFadeRect(img.getGraphics(), 0, 0, width, height); 167 } 153 168 img.getGraphics().dispose(); 154 169 g.drawImage(img, x, y, null); … … 156 171 } 157 172 } catch(Exception e) { 158 fallbackDraw(g, getImage(), x, y, width, height );173 fallbackDraw(g, getImage(), x, y, width, height, alphaChannel); 159 174 } 160 175 return true; 161 176 } 162 177 163 private void fallbackDraw(Graphics g, Image img, int x, int y, int width, int height ) {178 private void fallbackDraw(Graphics g, Image img, int x, int y, int width, int height, boolean alphaChannel) { 164 179 flushedResizedCachedInstance(); 165 180 g.drawImage( … … 167 182 0, 0, img.getWidth(null), img.getHeight(null), 168 183 null); 184 if (!alphaChannel) { //FIXME: fading for layers with alpha channel currently is not supported 185 drawFadeRect(g, x, y, width, height); 186 } 187 } 188 189 private void drawFadeRect(Graphics g, int x, int y, int width, int height) { 190 if (fadeColor != transparentColor) { 191 g.setColor(fadeColor); 192 g.fillRect(x, y, width, height); 193 } 169 194 } 170 195
Note:
See TracChangeset
for help on using the changeset viewer.