| | 156 | |
| | 157 | assertEquals("Green Tiles", Main.pref.get("slippy_map_chooser.mapstyle", "Fail")); |
| | 158 | } |
| | 159 | |
| | 160 | @Test |
| | 161 | public void testSourcePrefObeyed() throws Throwable { |
| | 162 | Main.pref.put("slippy_map_chooser.mapstyle", "Green Tiles"); |
| | 163 | |
| | 164 | MinimapDialog dlg = new MinimapDialog(); |
| | 165 | dlg.setSize(300, 200); |
| | 166 | dlg.showDialog(); |
| | 167 | SlippyMapBBoxChooser slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(dlg, "slippyMap"); |
| | 168 | SourceButton sourceButton = (SourceButton) TestUtils.getPrivateField(slippyMap, "iSourceButton"); |
| | 169 | |
| | 170 | // get dlg in a paintable state |
| | 171 | dlg.addNotify(); |
| | 172 | dlg.doLayout(); |
| | 173 | |
| | 174 | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Green Tiles"); |
| | 175 | |
| | 176 | BufferedImage image = new BufferedImage( |
| | 177 | slippyMap.getSize().width, |
| | 178 | slippyMap.getSize().height, |
| | 179 | BufferedImage.TYPE_INT_RGB |
| | 180 | ); |
| | 181 | |
| | 182 | Graphics2D g = image.createGraphics(); |
| | 183 | // an initial paint operation is required to trigger the tile fetches |
| | 184 | slippyMap.paintAll(g); |
| | 185 | g.setBackground(Color.BLUE); |
| | 186 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
| | 187 | g.dispose(); |
| | 188 | |
| | 189 | Thread.sleep(500); |
| | 190 | |
| | 191 | g = image.createGraphics(); |
| | 192 | slippyMap.paintAll(g); |
| | 193 | |
| | 194 | assertEquals(0xff00ff00, image.getRGB(0, 0)); |
| | 195 | |
| | 196 | getSourceMenuItemByLabel(sourceButton.getPopupMenu(), "Magenta Tiles").doClick(); |
| | 197 | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "Magenta Tiles"); |
| | 198 | |
| | 199 | assertEquals("Magenta Tiles", Main.pref.get("slippy_map_chooser.mapstyle", "Fail")); |
| | 200 | } |
| | 201 | |
| | 202 | @Test |
| | 203 | public void testSourcePrefInvalid() throws Throwable { |
| | 204 | Main.pref.put("slippy_map_chooser.mapstyle", "Hooloovoo Tiles"); |
| | 205 | |
| | 206 | MinimapDialog dlg = new MinimapDialog(); |
| | 207 | dlg.setSize(300, 200); |
| | 208 | dlg.showDialog(); |
| | 209 | SlippyMapBBoxChooser slippyMap = (SlippyMapBBoxChooser) TestUtils.getPrivateField(dlg, "slippyMap"); |
| | 210 | SourceButton sourceButton = (SourceButton) TestUtils.getPrivateField(slippyMap, "iSourceButton"); |
| | 211 | |
| | 212 | // get dlg in a paintable state |
| | 213 | dlg.addNotify(); |
| | 214 | dlg.doLayout(); |
| | 215 | |
| | 216 | assertSingleSelectedSourceLabel(sourceButton.getPopupMenu(), "White Tiles"); |
| | 217 | |
| | 218 | BufferedImage image = new BufferedImage( |
| | 219 | slippyMap.getSize().width, |
| | 220 | slippyMap.getSize().height, |
| | 221 | BufferedImage.TYPE_INT_RGB |
| | 222 | ); |
| | 223 | |
| | 224 | Graphics2D g = image.createGraphics(); |
| | 225 | // an initial paint operation is required to trigger the tile fetches |
| | 226 | slippyMap.paintAll(g); |
| | 227 | g.setBackground(Color.BLUE); |
| | 228 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
| | 229 | g.dispose(); |
| | 230 | |
| | 231 | Thread.sleep(500); |
| | 232 | |
| | 233 | g = image.createGraphics(); |
| | 234 | slippyMap.paintAll(g); |
| | 235 | |
| | 236 | assertEquals(0xffffffff, image.getRGB(0, 0)); |