Search in sources :

Example 46 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class UndoManagerTest method testCheckPopulationFlag.

/**
 * Test method for {@link com.sldeditor.common.undo.UndoManager#shouldProcessUndoRedoAction()}.
 */
@Test
public void testCheckPopulationFlag() {
    UndoManager.destroyInstance();
    DummyUndo listener = new DummyUndo();
    DummyUndoParent parentListener = new DummyUndoParent();
    UndoManager.getInstance().addListener(listener);
    DummyPopulating populationCheck = new DummyPopulating();
    UndoManager.getInstance().setPopulationCheck(populationCheck);
    // CHECKSTYLE:OFF
    UndoEvent event1 = new UndoEvent(parentListener, FieldIdEnum.ANCHOR_POINT_H, Integer.valueOf(2), Integer.valueOf(3));
    UndoEvent event2 = new UndoEvent(parentListener, FieldIdEnum.ANCHOR_POINT_H, Integer.valueOf(2), Integer.valueOf(3));
    UndoEvent event3 = new UndoEvent(parentListener, FieldIdEnum.DISPLACEMENT_Y, Integer.valueOf(20), Integer.valueOf(900));
    UndoEvent event4 = new UndoEvent(parentListener, FieldIdEnum.DEFAULT_STYLE, Boolean.TRUE, Boolean.FALSE);
    UndoEvent event5 = new UndoEvent(parentListener, FieldIdEnum.HALO_RADIUS, Double.valueOf(44.3), Double.valueOf(67.5));
    // CHECKSTYLE:ON
    UndoManager.getInstance().addUndoEvent(event1);
    assertTrue(listener.undoAllowed);
    assertFalse(listener.redoAllowed);
    populationCheck.setPopulating(true);
    // These should be added
    UndoManager.getInstance().addUndoEvent(event2);
    UndoManager.getInstance().addUndoEvent(event3);
    UndoManager.getInstance().undo();
    assertEquals(event1, parentListener.undoAction);
    assertNull(parentListener.redoAction);
    UndoManager.getInstance().addUndoEvent(event4);
    populationCheck.setPopulating(false);
    UndoManager.getInstance().addUndoEvent(event5);
    UndoManager.getInstance().undo();
    assertEquals(event5, parentListener.undoAction);
    assertNull(parentListener.redoAction);
    UndoManager.getInstance().setPopulationCheck(null);
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) Test(org.junit.Test)

Example 47 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class UndoManagerTest method testFileSaved.

@Test
public void testFileSaved() {
    UndoManager.destroyInstance();
    DummyUndo listener = new DummyUndo();
    DummyUndoParent parentListener = new DummyUndoParent();
    UndoManager.getInstance().addListener(listener);
    UndoEvent event1 = new UndoEvent(parentListener, FieldIdEnum.ANCHOR_POINT_H, Integer.valueOf(2), Integer.valueOf(3));
    UndoEvent event2 = new UndoEvent(parentListener, FieldIdEnum.ANCHOR_POINT_H, Integer.valueOf(2), Integer.valueOf(3));
    UndoEvent event3 = new UndoEvent(parentListener, FieldIdEnum.DISPLACEMENT_Y, Integer.valueOf(20), Integer.valueOf(900));
    UndoEvent event4 = new UndoEvent(parentListener, FieldIdEnum.DEFAULT_STYLE, Boolean.TRUE, Boolean.FALSE);
    UndoEvent event5 = new UndoEvent(parentListener, FieldIdEnum.HALO_RADIUS, Double.valueOf(44.3), Double.valueOf(67.5));
    UndoManager.getInstance().addUndoEvent(event1);
    UndoManager.getInstance().addUndoEvent(event2);
    UndoManager.getInstance().addUndoEvent(event3);
    UndoManager.getInstance().addUndoEvent(event4);
    UndoManager.getInstance().addUndoEvent(event5);
    // This clears out all the undo events
    UndoManager.getInstance().fileSaved();
    assertFalse(listener.undoAllowed);
    assertFalse(listener.redoAllowed);
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) Test(org.junit.Test)

Example 48 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class PrefManagerTest method testUndoAction.

/**
 * Test method for {@link com.sldeditor.common.preferences.PrefManager#undoAction(com.sldeditor.common.undo.UndoInterface)}. Test method for
 * {@link com.sldeditor.common.preferences.PrefManager#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    PrefManager.initialise(null);
    PrefManager.getInstance().finish();
    DummyPropertyManager propertyManager = new DummyPropertyManager();
    PrefManager.initialise(propertyManager);
    // Set up data as if it had been read in
    PrefData prefData = new PrefData();
    prefData.setUseAntiAlias(true);
    Color backgroundColour = Color.GRAY;
    prefData.setBackgroundColour(backgroundColour);
    List<VersionData> vendorOptionList = new ArrayList<VersionData>();
    vendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
    vendorOptionList.add(VersionData.getEarliestVersion(GeoServerVendorOption.class));
    prefData.setVendorOptionVersionList(vendorOptionList);
    String uiLayoutClass = "perfect curve";
    prefData.setUiLayoutClass(uiLayoutClass);
    String lastFolderViewed = "secret";
    prefData.setLastFolderViewed(lastFolderViewed);
    prefData.setLastViewedKey(PrefDataLastViewedEnum.FOLDER);
    prefData.setSaveLastFolderView(true);
    PrefManager.getInstance().setPrefData(prefData);
    PrefData copy = prefData.clone();
    copy.setLastViewedKey(PrefDataLastViewedEnum.GEOSERVER);
    PrefManager.getInstance().setPrefData(copy);
    PrefData actual = PrefManager.getInstance().getPrefData();
    assertEquals(PrefDataLastViewedEnum.GEOSERVER, actual.getLastViewedKey());
    UndoManager.getInstance().undo();
    actual = PrefManager.getInstance().getPrefData();
    assertEquals(PrefDataLastViewedEnum.FOLDER, actual.getLastViewedKey());
    UndoManager.getInstance().redo();
    actual = PrefManager.getInstance().getPrefData();
    assertEquals(PrefDataLastViewedEnum.GEOSERVER, actual.getLastViewedKey());
    // Increase the code coverage
    PrefManager.getInstance().undoAction(null);
    PrefManager.getInstance().undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    PrefManager.getInstance().redoAction(null);
    PrefManager.getInstance().redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) GeoServerVendorOption(com.sldeditor.common.vendoroption.GeoServerVendorOption) PrefData(com.sldeditor.common.preferences.PrefData) VersionData(com.sldeditor.common.vendoroption.VersionData) Color(java.awt.Color) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 49 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class UndoEventTest method testUndoEvent2.

/**
 * Test method for {@link com.sldeditor.common.undo.UndoEvent#UndoEvent(com.sldeditor.common.undo.UndoActionInterface, java.lang.String, java.lang.Object, java.lang.Object)}.
 */
@Test
public void testUndoEvent2() {
    DummyUndoParent parent = new DummyUndoParent();
    Double oldValue = Double.valueOf(22.0);
    Double newValue = Double.valueOf(42.0);
    String expectedField = "one more";
    UndoEvent undoEvent = new UndoEvent(parent, expectedField, oldValue, newValue);
    assertEquals(FieldIdEnum.UNKNOWN, undoEvent.getFieldId());
    assertEquals(oldValue, undoEvent.getOldValue());
    assertEquals(newValue, undoEvent.getNewValue());
    assertNull(parent.redoAction);
    assertNull(parent.undoAction);
    undoEvent.doUndo();
    assertEquals(oldValue, ((UndoEvent) parent.undoAction).getOldValue());
    assertNull(parent.redoAction);
    undoEvent.doRedo();
    assertEquals(newValue, ((UndoEvent) parent.redoAction).getNewValue());
    assertNull(parent.undoAction);
    undoEvent.doUndo();
    assertEquals(oldValue, ((UndoEvent) parent.undoAction).getOldValue());
    assertNull(parent.redoAction);
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) Test(org.junit.Test)

Example 50 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class UndoEventTest method testUndoEvent1.

/**
 * Test method for {@link com.sldeditor.common.undo.UndoEvent#UndoEvent(com.sldeditor.common.undo.UndoActionInterface, com.sldeditor.common.xml.ui.FieldIdEnum, java.lang.Object, java.lang.Object)}.
 */
@Test
public void testUndoEvent1() {
    DummyUndoParent parent = new DummyUndoParent();
    Double oldValue = Double.valueOf(22.0);
    Double newValue = Double.valueOf(42.0);
    FieldIdEnum expectedField = FieldIdEnum.ANGLE;
    UndoEvent undoEvent = new UndoEvent(parent, expectedField, oldValue, newValue);
    assertEquals(expectedField, undoEvent.getFieldId());
    assertEquals(oldValue, undoEvent.getOldValue());
    assertEquals(newValue, undoEvent.getNewValue());
    assertNull(parent.redoAction);
    assertNull(parent.undoAction);
    undoEvent.doUndo();
    assertEquals(oldValue, ((UndoEvent) parent.undoAction).getOldValue());
    assertNull(parent.redoAction);
    undoEvent.doRedo();
    assertEquals(newValue, ((UndoEvent) parent.redoAction).getNewValue());
    assertNull(parent.undoAction);
    undoEvent.doUndo();
    assertEquals(oldValue, ((UndoEvent) parent.undoAction).getOldValue());
    assertNull(parent.redoAction);
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) Test(org.junit.Test)

Aggregations

UndoEvent (com.sldeditor.common.undo.UndoEvent)84 Test (org.junit.Test)27 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)20 UndoActionInterface (com.sldeditor.common.undo.UndoActionInterface)16 FieldPanel (com.sldeditor.ui.widgets.FieldPanel)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)10 Geometry (com.vividsolutions.jts.geom.Geometry)9 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)5 ArrayList (java.util.ArrayList)4 JPanel (javax.swing.JPanel)4 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)4 RenderSymbolInterface (com.sldeditor.datasource.RenderSymbolInterface)3 ValueComboBox (com.sldeditor.ui.widgets.ValueComboBox)3 Color (java.awt.Color)3 JButton (javax.swing.JButton)3 JCheckBox (javax.swing.JCheckBox)3 LineSymbolizer (org.geotools.styling.LineSymbolizer)3