[9926] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[10144] | 2 | package org.openstreetmap.josm.gui.dialogs.layer;
|
---|
[9926] | 3 |
|
---|
| 4 | import static org.junit.Assert.assertEquals;
|
---|
[10011] | 5 | import static org.junit.Assert.assertFalse;
|
---|
[9926] | 6 | import static org.junit.Assert.assertTrue;
|
---|
| 7 |
|
---|
[12394] | 8 | import org.junit.BeforeClass;
|
---|
[10467] | 9 | import org.junit.Rule;
|
---|
[9926] | 10 | import org.junit.Test;
|
---|
[12394] | 11 | import org.openstreetmap.josm.JOSMFixture;
|
---|
[9926] | 12 | import org.openstreetmap.josm.Main;
|
---|
[10144] | 13 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
---|
[9926] | 14 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
|
---|
| 15 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
| 16 | import org.openstreetmap.josm.gui.layer.TMSLayerTest;
|
---|
[10467] | 17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
[9926] | 18 |
|
---|
[10467] | 19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 20 |
|
---|
[9926] | 21 | /**
|
---|
[10144] | 22 | * Unit tests of {@link LayerVisibilityAction} class.
|
---|
[9926] | 23 | */
|
---|
[10144] | 24 | public class LayerVisibilityActionTest {
|
---|
[9926] | 25 | /**
|
---|
[10467] | 26 | * TMS layer needs prefs. Platform for LayerListDialog shortcuts.
|
---|
[9926] | 27 | */
|
---|
[10467] | 28 | @Rule
|
---|
| 29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
| 30 | public JOSMTestRules test = new JOSMTestRules().preferences().projection().platform();
|
---|
[9926] | 31 |
|
---|
| 32 | /**
|
---|
[12394] | 33 | * Somewhere deep down the dependencies we need shortcuts
|
---|
| 34 | */
|
---|
| 35 | @BeforeClass
|
---|
| 36 | public static void setUp() {
|
---|
| 37 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
[10011] | 41 | * Unit test of {@link LayerVisibilityAction} class.
|
---|
[9926] | 42 | */
|
---|
| 43 | @Test
|
---|
[10011] | 44 | public void testLayerVisibilityAction() {
|
---|
[9926] | 45 | TMSLayer layer = TMSLayerTest.createTmsLayer();
|
---|
[10467] | 46 | LayerListModel model = new LayerListDialog(Main.getLayerManager()) {
|
---|
| 47 | @Override
|
---|
| 48 | protected void registerInWindowMenu() {
|
---|
| 49 | // ignore
|
---|
| 50 | }
|
---|
| 51 | }.getModel();
|
---|
| 52 | LayerVisibilityAction action = new LayerVisibilityAction(model);
|
---|
| 53 | action.updateEnabledState();
|
---|
| 54 | assertFalse(action.isEnabled());
|
---|
[9926] | 55 |
|
---|
[10467] | 56 | Main.getLayerManager().addLayer(layer);
|
---|
| 57 | model.setSelectedLayer(layer);
|
---|
| 58 | action.updateEnabledState();
|
---|
| 59 | assertTrue(action.isEnabled());
|
---|
| 60 | assertTrue(action.supportLayers(model.getSelectedLayers()));
|
---|
[10011] | 61 |
|
---|
[10467] | 62 | // now check values
|
---|
| 63 | action.updateValues();
|
---|
| 64 | assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
|
---|
| 65 | assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
|
---|
[10011] | 66 |
|
---|
[10467] | 67 | action.opacitySlider.setRealValue(.5);
|
---|
| 68 | action.updateValues();
|
---|
[10011] | 69 |
|
---|
[10467] | 70 | assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
|
---|
| 71 | assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
|
---|
[10011] | 72 |
|
---|
[10467] | 73 | action.setVisibleFlag(false);
|
---|
| 74 | action.updateValues();
|
---|
| 75 | assertFalse(layer.isVisible());
|
---|
[10011] | 76 |
|
---|
[10467] | 77 | action.setVisibleFlag(true);
|
---|
| 78 | action.updateValues();
|
---|
| 79 | assertTrue(layer.isVisible());
|
---|
[10011] | 80 |
|
---|
[10467] | 81 | // layer stays visible during adjust
|
---|
[12394] | 82 | action.opacitySlider.slider.setValueIsAdjusting(true);
|
---|
[10467] | 83 | action.opacitySlider.setRealValue(0);
|
---|
| 84 | assertEquals(0, layer.getOpacity(), 1e-15);
|
---|
| 85 | layer.setOpacity(.1); // to make layer.isVisible work
|
---|
| 86 | assertTrue(layer.isVisible());
|
---|
| 87 | layer.setOpacity(0);
|
---|
[10011] | 88 |
|
---|
[12394] | 89 | action.opacitySlider.slider.setValueIsAdjusting(false);
|
---|
[10467] | 90 | action.opacitySlider.setRealValue(0);
|
---|
| 91 | assertEquals(0, layer.getOpacity(), 1e-15);
|
---|
| 92 | layer.setOpacity(.1); // to make layer.isVisible work
|
---|
| 93 | assertFalse(layer.isVisible());
|
---|
| 94 | layer.setOpacity(0);
|
---|
| 95 | action.updateValues();
|
---|
[10011] | 96 |
|
---|
[10467] | 97 | // Opacity reset when it was 0 and user set layer to visible.
|
---|
| 98 | action.setVisibleFlag(true);
|
---|
| 99 | action.updateValues();
|
---|
| 100 | assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
|
---|
| 101 | assertEquals(1.0, layer.getOpacity(), 1e-15);
|
---|
[9926] | 102 | }
|
---|
| 103 | }
|
---|