/*
* JAME 6.2.1
* http://jame.sourceforge.net
*
* Copyright 2001, 2016 Andrea Medeghini
*
* This file is part of JAME.
*
* JAME is an application for creating fractals and other graphics artifacts.
*
* JAME is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JAME is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with JAME. If not, see <http://www.gnu.org/licenses/>.
*
*/
package net.sf.jame.contextfree.extensions.pathReplacement;
import java.util.ArrayList;
import java.util.List;
import net.sf.jame.contextfree.CFDGBuilder;
import net.sf.jame.contextfree.common.FillRuleElement;
import net.sf.jame.contextfree.pathAdjustment.PathAdjustmentConfigElement;
import net.sf.jame.contextfree.pathReplacement.extension.PathReplacementExtensionConfig;
import net.sf.jame.core.config.ConfigElement;
import net.sf.jame.core.config.ListConfigElement;
/**
* @author Andrea Medeghini
*/
public class FillPathReplacementConfig extends PathReplacementExtensionConfig {
private static final long serialVersionUID = 1L;
private FillRuleElement ruleElement;
private ListConfigElement<PathAdjustmentConfigElement> pathAdjustmentListElement;
/**
*
*/
@Override
protected void createConfigElements() {
ruleElement = new FillRuleElement("non-zero");
pathAdjustmentListElement = new ListConfigElement<PathAdjustmentConfigElement>("pathAdjustmentListElement");
}
/**
* @see net.sf.jame.core.extension.ExtensionConfig#getConfigElements()
*/
@Override
public List<ConfigElement> getConfigElements() {
final List<ConfigElement> elements = new ArrayList<ConfigElement>(1);
elements.add(ruleElement);
elements.add(pathAdjustmentListElement);
return elements;
}
/**
* @return
*/
public FillRuleElement getRuleElement() {
return ruleElement;
}
/**
* @return
*/
public String getRule() {
return ruleElement.getValue();
}
/**
* @param value
*/
public void setRule(final String value) {
ruleElement.setValue(value);
}
/**
* @return
*/
public ListConfigElement<PathAdjustmentConfigElement> getPathAdjustmentListElement() {
return pathAdjustmentListElement;
}
/**
* Returns a pathAdjustment element.
*
* @param index the pathAdjustment index.
* @return the pathAdjustment.
*/
public PathAdjustmentConfigElement getPathAdjustmentConfigElement(final int index) {
return pathAdjustmentListElement.getElement(index);
}
/**
* Returns a pathAdjustment element index.
*
* @param pathAdjustmentElement the pathAdjustment element.
* @return the index.
*/
public int indexOfPathAdjustmentConfigElement(final PathAdjustmentConfigElement pathAdjustmentElement) {
return pathAdjustmentListElement.indexOfElement(pathAdjustmentElement);
}
/**
* Returns the number of pathAdjustment elements.
*
* @return the number of pathAdjustment elements.
*/
public int getPathAdjustmentConfigElementCount() {
return pathAdjustmentListElement.getElementCount();
}
/**
* Adds a pathAdjustment element.
*
* @param pathAdjustmentElement the pathAdjustment to add.
*/
public void appendPathAdjustmentConfigElement(final PathAdjustmentConfigElement pathAdjustmentElement) {
pathAdjustmentListElement.appendElement(pathAdjustmentElement);
}
/**
* Adds a pathAdjustment element.
*
* @param index the index.
* @param pathAdjustmentElement the pathAdjustment to add.
*/
public void insertPathAdjustmentConfigElementAfter(final int index, final PathAdjustmentConfigElement pathAdjustmentElement) {
pathAdjustmentListElement.insertElementAfter(index, pathAdjustmentElement);
}
/**
* Adds a pathAdjustment element.
*
* @param index the index.
* @param pathAdjustmentElement the pathAdjustment to add.
*/
public void insertPathAdjustmentConfigElementBefore(final int index, final PathAdjustmentConfigElement pathAdjustmentElement) {
pathAdjustmentListElement.insertElementBefore(index, pathAdjustmentElement);
}
/**
* Removes a pathAdjustment element.
*
* @param index the element index to remove.
*/
public void removePathAdjustmentConfigElement(final int index) {
pathAdjustmentListElement.removeElement(index);
}
/**
* Removes a pathAdjustment element.
*
* @param pathAdjustmentElement the pathAdjustment to remove.
*/
public void removePathAdjustmentConfigElement(final PathAdjustmentConfigElement pathAdjustmentElement) {
pathAdjustmentListElement.removeElement(pathAdjustmentElement);
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
final FillPathReplacementConfig other = (FillPathReplacementConfig) obj;
if (ruleElement == null) {
if (other.ruleElement != null) {
return false;
}
}
else if (!ruleElement.equals(other.ruleElement)) {
return false;
}
if (pathAdjustmentListElement == null) {
if (other.pathAdjustmentListElement != null) {
return false;
}
}
else if (!pathAdjustmentListElement.equals(other.pathAdjustmentListElement)) {
return false;
}
return true;
}
/**
* @return
*/
@Override
public FillPathReplacementConfig clone() {
final FillPathReplacementConfig config = new FillPathReplacementConfig();
config.setRule(getRule());
config.pathAdjustmentListElement.copyFrom(getPathAdjustmentListElement());
return config;
}
@Override
public void toCFDG(CFDGBuilder builder) {
builder.appendTabs();
builder.append("FILL {");
if (ruleElement.getValue() != null) {
if (ruleElement.getValue().equals("even-odd")) {
builder.append(" p evenodd");
} else if (ruleElement.getValue().equals("non-zero")) {
builder.append(" p nonzero");
}
}
for (int i = 0; i < pathAdjustmentListElement.getElementCount(); i++) {
builder.append(" ");
pathAdjustmentListElement.getElement(i).toCFDG(builder);
}
builder.append(" }");
}
}