Search in sources :

Example 71 with UndoEvent

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

the class TTFDetails method buttonPressed.

/**
 * Button pressed.
 *
 * @param buttonExternal the button external
 */
@Override
public void buttonPressed(Component buttonExternal) {
    CharMap4 charMap4 = new CharMap4();
    charMap4.loadConfig();
    charMap4.setTTFString(fieldConfigVisitor.getText(FieldIdEnum.TTF_SYMBOL));
    String selectedChar = charMap4.showDialog();
    if (selectedChar != null) {
        fieldConfigVisitor.populateTextField(FieldIdEnum.TTF_SYMBOL, selectedChar);
        UndoManager.getInstance().addUndoEvent(new UndoEvent(this, FieldIdEnum.TTF_SYMBOL, oldValueObj, selectedChar));
        oldValueObj = selectedChar;
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                updateSymbol();
            }
        });
    }
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) CharMap4(com.sldeditor.ui.ttf.CharMap4)

Example 72 with UndoEvent

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

the class FieldConfigTransformation method populateField.

/**
 * Populate field.
 *
 * @param value the value
 */
@Override
public void populateField(String value) {
    if (textField != null) {
        textField.setText(value);
        UndoManager.getInstance().addUndoEvent(new UndoEvent(this, getFieldId(), oldValueObj, value));
        oldValueObj = value;
        valueUpdated();
    }
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent)

Example 73 with UndoEvent

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

the class FieldConfigTransformation method populateField.

/**
 * Populate process function field.
 *
 * @param value the value
 */
@Override
public void populateField(ProcessFunction value) {
    processFunction = value;
    if (textField != null) {
        textField.setText(ParameterFunctionUtils.getString(processFunction));
        UndoManager.getInstance().addUndoEvent(new UndoEvent(this, getFieldId(), oldValueObj, value));
        oldValueObj = value;
        valueUpdated();
    }
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent)

Example 74 with UndoEvent

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

the class FieldConfigDateTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigDate field = new FieldConfigDate(new FieldConfigCommonData(Date.class, FieldIdEnum.NAME, "label", false));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    SimpleDateFormat f = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    String dateString1 = "10-01-2012 23:13:26";
    String dateString2 = "05-06-2018 12:34:56";
    Date dateTime1 = null;
    Date dateTime2 = null;
    try {
        dateTime1 = f.parse(dateString1);
        dateTime2 = f.parse(dateString2);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    field.populateField(dateTime1);
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);
    DateFormat tf = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
    String dateFormat1String = String.format("%sT%sZ", df.format(dateTime1), tf.format(dateTime1));
    assertTrue(dateFormat1String.compareTo(field.getStringValue()) == 0);
    field.populateField(dateTime2);
    String dateFormat2String = String.format("%sT%sZ", df.format(dateTime2), tf.format(dateTime2));
    assertTrue(dateFormat2String.compareTo(field.getStringValue()) == 0);
    UndoManager.getInstance().undo();
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo(dateFormat1String) == 0);
    UndoManager.getInstance().redo();
    actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo(dateFormat2String) == 0);
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Also used : FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) UndoEvent(com.sldeditor.common.undo.UndoEvent) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) Test(org.junit.Test)

Example 75 with UndoEvent

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

the class FieldConfigEnumTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigEnum#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigEnum#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    SymbolTypeConfig s1 = new SymbolTypeConfig(null);
    s1.addOption("key1", "Value 1");
    s1.addOption("key2", "Value 2");
    s1.addOption("key3", "Value 3");
    s1.addField(FieldIdEnum.ANCHOR_POINT_H, true);
    s1.addField(FieldIdEnum.ANCHOR_POINT_V, false);
    List<SymbolTypeConfig> configList = new ArrayList<SymbolTypeConfig>();
    configList.add(s1);
    SymbolTypeConfig s2 = new SymbolTypeConfig(null);
    s2.addOption("key4", "Value 4");
    s2.addOption("key5", "Value 5");
    s2.addOption("key6", "Value 6");
    s2.addField(FieldIdEnum.ANGLE, true);
    s2.addField(FieldIdEnum.DESCRIPTION, false);
    configList.add(s2);
    boolean valueOnly = true;
    FieldConfigEnum field = new FieldConfigEnum(new FieldConfigCommonData(Integer.class, FieldIdEnum.NAME, "label", valueOnly));
    field.addConfig(null);
    assertNull(field.getStringValue());
    field.addConfig(configList);
    // Now create the ui
    field.createUI();
    String expectedValue1 = "key2";
    field.populateField(expectedValue1);
    String expectedValue2 = "key6";
    field.populateField(expectedValue2);
    UndoManager.getInstance().undo();
    String actualValueString = field.getStringValue();
    assertTrue(expectedValue1.compareTo(actualValueString) == 0);
    ValueComboBoxData actualValue = field.getEnumValue();
    assertTrue(expectedValue1.compareTo(actualValue.getKey()) == 0);
    UndoManager.getInstance().redo();
    actualValueString = field.getStringValue();
    assertTrue(expectedValue2.compareTo(actualValueString) == 0);
    actualValue = field.getEnumValue();
    assertTrue(expectedValue2.compareTo(actualValue.getKey()) == 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)));
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) FieldConfigEnum(com.sldeditor.ui.detail.config.FieldConfigEnum) ArrayList(java.util.ArrayList) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) SymbolTypeConfig(com.sldeditor.ui.detail.config.symboltype.SymbolTypeConfig) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) 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