Search in sources :

Example 81 with UndoEvent

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

the class FieldConfigFeatureTypeConstraintTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigFeatureTypeConstraint field = new FieldConfigFeatureTypeConstraint(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", true));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeConstraint expectedValue1 = styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);
    List<FeatureTypeConstraint> testValue = new ArrayList<FeatureTypeConstraint>();
    testValue.add(expectedValue1);
    field.populateField(testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
    FeatureTypeConstraint expectedValue2 = styleFactory.createFeatureTypeConstraint("Feature2", Filter.INCLUDE, new Extent[0]);
    List<FeatureTypeConstraint> testValue2 = new ArrayList<FeatureTypeConstraint>();
    testValue2.add(expectedValue1);
    testValue2.add(expectedValue2);
    field.populateField(testValue2);
    UndoManager.getInstance().undo();
    assertEquals(1, field.getFeatureTypeConstraint().size());
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
    UndoManager.getInstance().redo();
    assertEquals(2, field.getFeatureTypeConstraint().size());
    assertEquals(expectedValue2, field.getFeatureTypeConstraint().get(1));
    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) UndoEvent(com.sldeditor.common.undo.UndoEvent) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) FieldConfigFeatureTypeConstraint(com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) ArrayList(java.util.ArrayList) FieldConfigFeatureTypeConstraint(com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint) Test(org.junit.Test)

Example 82 with UndoEvent

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

the class FieldConfigFontTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    boolean valueOnly = true;
    FieldConfigFont field = new FieldConfigFont(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
    String expectedDefaultValue1 = fontFamilies[0];
    field.createUI();
    field.populateField(expectedDefaultValue1);
    String actualValue1 = field.getStringValue();
    assertTrue(expectedDefaultValue1.compareTo(actualValue1) == 0);
    String expectedDefaultValue2 = fontFamilies[0];
    field.populateField(expectedDefaultValue2);
    String actualValue2 = field.getStringValue();
    assertTrue(expectedDefaultValue2.compareTo(actualValue2) == 0);
    UndoManager.getInstance().undo();
    String actualValue = field.getStringValue();
    assertTrue(expectedDefaultValue1.compareTo(actualValue) == 0);
    UndoManager.getInstance().redo();
    actualValue = field.getStringValue();
    assertTrue(expectedDefaultValue2.compareTo(actualValue) == 0);
    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, Double.valueOf(1.0), Double.valueOf(2.0)));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, Double.valueOf(1.0), Double.valueOf(2.0)));
}
Also used : FieldConfigFont(com.sldeditor.ui.detail.config.font.FieldConfigFont) UndoEvent(com.sldeditor.common.undo.UndoEvent) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 83 with UndoEvent

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

the class FieldConfigSymbolTypeTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigSymbolType#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigSymbolType#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    UndoManager.getInstance().setPopulationCheck(Controller.getInstance());
    boolean valueOnly = true;
    FieldConfigSymbolType field = new FieldConfigSymbolType(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    field.createUI();
    FieldConfigMarker marker = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.ANGLE, "label", valueOnly), null, null, null);
    marker.createUI();
    List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>();
    dataList.add(new ValueComboBoxData("key 1", "Value 1", FieldConfigMarker.class));
    dataList.add(new ValueComboBoxData("key 2", "Value 2", FieldConfigMarker.class));
    dataList.add(new ValueComboBoxData("key 3", "Value 3", FieldConfigMarker.class));
    List<ValueComboBoxDataGroup> combinedSymbolList = new ArrayList<ValueComboBoxDataGroup>();
    combinedSymbolList.add(new ValueComboBoxDataGroup(dataList));
    field.createUI();
    field.addField(marker);
    field.populate(null, combinedSymbolList);
    String expectedValue2 = "key 2";
    field.populateExpression(expectedValue2);
    String actualValue2 = field.getStringValue();
    assertTrue(actualValue2.compareTo(field.getStringValue()) == 0);
    ValueComboBoxData actualValueObj2 = field.getEnumValue();
    assertNotNull(actualValueObj2.getKey());
    assertTrue(actualValueObj2.getKey().compareTo(expectedValue2) == 0);
    String expectedValue3 = "key 1";
    field.populateField(expectedValue3);
    String actualValue3 = field.getStringValue();
    assertTrue(expectedValue3.compareTo(actualValue3) == 0);
    String expectedValue4 = "key 3";
    field.populateField(expectedValue4);
    String actualValue4 = field.getStringValue();
    assertTrue(expectedValue4.compareTo(actualValue4) == 0);
    UndoManager.getInstance().undo();
    String actualValue = field.getStringValue();
    assertTrue(expectedValue3.compareTo(actualValue) == 0);
    UndoManager.getInstance().redo();
    actualValue = field.getStringValue();
    assertTrue(expectedValue4.compareTo(actualValue) == 0);
    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, Double.valueOf(0), Double.valueOf(23)));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, Double.valueOf(0), Double.valueOf(54)));
    UndoManager.getInstance().setPopulationCheck(null);
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) ValueComboBoxDataGroup(com.sldeditor.ui.widgets.ValueComboBoxDataGroup) FieldConfigMarker(com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) ArrayList(java.util.ArrayList) FieldConfigSymbolType(com.sldeditor.ui.detail.config.FieldConfigSymbolType) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) Test(org.junit.Test)

Example 84 with UndoEvent

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

the class DataSourceConfigPanel method applyData.

/**
 * Apply data.
 *
 * @param parentObj the parent obj
 */
protected void applyData(final UndoActionInterface parentObj) {
    Object oldValueObj = attributeData;
    Object newValueObj = dataModel.getAttributeData();
    UndoManager.getInstance().addUndoEvent(new UndoEvent(parentObj, "Preferences", oldValueObj, newValueObj));
    attributeData = (DataSourceAttributeListInterface) newValueObj;
    dataSource.updateFields(attributeData);
    dataChanged = false;
    updateButtonState();
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent)

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