Search in sources :

Example 1 with ColorUndoable

use of com.ray3k.skincomposer.UndoableManager.ColorUndoable in project skin-composer by raeleus.

the class DialogColors method result.

@Override
protected void result(Object object) {
    if (styleProperty != null) {
        if (object instanceof ColorData) {
            main.getProjectData().setChangesSaved(false);
            ColorData color = (ColorData) object;
            ColorUndoable undoable = new ColorUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, color.getName());
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if ((boolean) object) {
                main.getProjectData().setChangesSaved(false);
                ColorUndoable undoable = new ColorUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, null);
                main.getUndoableManager().addUndoable(undoable, true);
            } else {
                boolean hasColor = false;
                for (ColorData color : main.getJsonData().getColors()) {
                    if (color.getName().equals(styleProperty.value)) {
                        hasColor = true;
                        break;
                    }
                }
                if (!hasColor) {
                    main.getProjectData().setChangesSaved(false);
                    styleProperty.value = null;
                    main.getRootTable().setStatusBarMessage("Deleted color for \"" + styleProperty.name + "\"");
                    main.getRootTable().refreshStyleProperties(true);
                }
            }
        }
    } else if (customProperty != null) {
        if (object instanceof ColorData) {
            main.getProjectData().setChangesSaved(false);
            ColorData color = (ColorData) object;
            CustomColorUndoable undoable = new UndoableManager.CustomColorUndoable(main, customProperty, color.getName());
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if ((boolean) object) {
                main.getProjectData().setChangesSaved(false);
                CustomColorUndoable undoable = new UndoableManager.CustomColorUndoable(main, customProperty, null);
                main.getUndoableManager().addUndoable(undoable, true);
                main.getRootTable().setStatusBarMessage("Emptied color for \"" + customProperty.getName() + "\"");
                main.getRootTable().refreshStyleProperties(true);
            } else {
                boolean hasColor = false;
                for (ColorData color : main.getJsonData().getColors()) {
                    if (color.getName().equals(customProperty.getValue())) {
                        hasColor = true;
                        break;
                    }
                }
                if (!hasColor) {
                    main.getProjectData().setChangesSaved(false);
                    customProperty.setValue(null);
                    main.getRootTable().setStatusBarMessage("Deleted color for \"" + customProperty.getName() + "\"");
                    main.getRootTable().refreshStyleProperties(true);
                }
            }
        }
    }
    if (listener != null) {
        if (object instanceof ColorData) {
            listener.handle((ColorData) object);
        } else {
            listener.handle(null);
        }
    }
}
Also used : ColorData(com.ray3k.skincomposer.data.ColorData) CustomColorUndoable(com.ray3k.skincomposer.UndoableManager.CustomColorUndoable) UndoableManager(com.ray3k.skincomposer.UndoableManager) CustomColorUndoable(com.ray3k.skincomposer.UndoableManager.CustomColorUndoable) ColorUndoable(com.ray3k.skincomposer.UndoableManager.ColorUndoable) CustomColorUndoable(com.ray3k.skincomposer.UndoableManager.CustomColorUndoable)

Aggregations

UndoableManager (com.ray3k.skincomposer.UndoableManager)1 ColorUndoable (com.ray3k.skincomposer.UndoableManager.ColorUndoable)1 CustomColorUndoable (com.ray3k.skincomposer.UndoableManager.CustomColorUndoable)1 ColorData (com.ray3k.skincomposer.data.ColorData)1