- All Implemented Interfaces:
FigureFactory
- Direct Known Subclasses:
DefaultFigureFactory
- Author:
- Werner Randelshofer
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractFigureFactory(@Nullable org.jhotdraw8.base.converter.IdFactory idFactory) -
Method Summary
Modifier and TypeMethodDescription<T> voidaddConverter(MapAccessor<T> key, org.jhotdraw8.base.converter.Converter<T> converter) Adds a converter for the specified key.voidaddConverterForType(Type fullValueType, org.jhotdraw8.base.converter.Converter<?> converter) Adds a converter.voidaddConverterForType(Type fullValueType, org.jhotdraw8.base.converter.Converter<?> converter, boolean force) <T> voidaddDefaultValue(Class<? extends Figure> figure, MapAccessor<T> acc, T value) voidAdds the provided mappings of XML attribute names from/toFigures.voidaddFigureAttributeKeys(Class<? extends Figure> f, Iterable<MapAccessor<?>> keys) Adds the provided keys to the figure.voidaddFigureKeysAndNames(Class<? extends Figure> f, Collection<MapAccessor<?>> keys) voidaddFigureKeysAndNames(String figureName, Class<? extends Figure> f) voidaddFigureKeysAndNames(String figureName, Class<? extends Figure> f, Iterable<MapAccessor<?>> keys) voidaddKey(Class<? extends Figure> figure, String name, MapAccessor<?> key) Adds the provided mapping of XML attribute names from/toMapAccessors.voidAdds the provided mapping of XML attribute names from/toMapAccessors.voidaddNodeListKey(Class<? extends Figure> figure, String name, MapAccessor<?> key) Adds the provided keys to the figure.voidaddSkipAttribute(Class<? extends Figure> figure, String attributeName) Adds an attribute to the list of attributes which will be skipped when reading the DOM.voidaddSkipElement(String elementName) Adds an element to the list of elements which will be skipped when reading the DOM.voidaddSkipFigure(Class<? extends Figure> figure) Adds a figure class to the list ofFigures which will be skipped when writing the DOM.voidcheckConverters(boolean throwException, Consumer<String> logger) voidClears the mapping of XML attributes from/toMapAccessors.voidClears the mapping of XML attributes from/toMapAccessors.createFigureByElementName(String elementName) Creates a new figure given the name of an XML element.Set<MapAccessor<?>> Returns all keys for the specified figure which should be converted into element attributes.Set<MapAccessor<?>> Returns all keys for the specified figure which should be converted into a node list.getAttributeNameByKey(Figure f, MapAccessor<?> key) Maps a key to a XML attribute name.protected <T> org.jhotdraw8.base.converter.Converter<T> getConverter(MapAccessor<T> key) <T> TgetDefaultValue(Figure f, MapAccessor<T> key) Returns the default for the key.@Nullable StringMaps a figure to an XML element name.getElementNameByKey(Figure f, MapAccessor<?> key) Maps a key to a XML element name.@Nullable org.jhotdraw8.base.converter.IdFactory@Nullable MapAccessor<?> getKeyByAttributeName(Figure f, String attributeName) Maps an XML attribute name to a key.MapAccessor<?> getKeyByElementName(Figure f, String elementName) Maps an XML element name to a key.Returns the name of the object id attribute.<T> booleanisDefaultValue(Figure f, MapAccessor<T> key, @Nullable T value) Returns true if the specified value is the default for the given key.<T> booleanneedsIdResolver(MapAccessor<T> key) <T> TnodeListToValue(MapAccessor<T> key, List<Node> nodeList) Maps a XML node list to a value.voidremoveKey(MapAccessor<?> key) Globally removes the specified key.voidsetIdFactory(@Nullable org.jhotdraw8.base.converter.IdFactory idFactory) voidsetObjectIdAttribute(String newValue) Sets the name of the object id attribute.<T> TstringToValue(MapAccessor<T> key, String string) Maps an XML attribute value to a value.voidvalueToNodeList(MapAccessor<?> key, Object value, XMLStreamWriter w) Maps a value to a XML node list.<T> StringvalueToString(MapAccessor<T> key, T value) Maps a value to an XML attribute value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.draw.io.FigureFactory
fromExternalDrawing, getStylesheetsKey, toExternalDrawing
-
Constructor Details
-
AbstractFigureFactory
public AbstractFigureFactory() -
AbstractFigureFactory
public AbstractFigureFactory(@Nullable org.jhotdraw8.base.converter.IdFactory idFactory)
-
-
Method Details
-
addConverter
public <T> void addConverter(MapAccessor<T> key, org.jhotdraw8.base.converter.Converter<T> converter) Adds a converter for the specified key.- Type Parameters:
T- the type of the value- Parameters:
key- the keyconverter- the converter
-
addConverterForType
public void addConverterForType(Type fullValueType, org.jhotdraw8.base.converter.Converter<?> converter) Adds a converter.- Parameters:
fullValueType- A value type returned byMapAccessor.getFullValueType();.converter- the converter
-
addConverterForType
public void addConverterForType(Type fullValueType, org.jhotdraw8.base.converter.Converter<?> converter, boolean force) -
addDefaultValue
-
addFigure
Adds the provided mappings of XML attribute names from/toFigures.figureClass.newInstance()is used to instantiate a figure from a name.If a figure with this name has already been added, it will be replaced by this figure.
- Parameters:
name- The element namefigureClass- The figure class is used both for instantiation of a new figure and for determining the name of a figure.
-
addFigureAttributeKeys
Adds the provided keys to the figure.- Parameters:
f- the figurekeys- the keys
-
addFigureKeysAndNames
-
addFigureKeysAndNames
public void addFigureKeysAndNames(String figureName, Class<? extends Figure> f, Iterable<MapAccessor<?>> keys) -
addFigureKeysAndNames
-
addKey
Adds the provided mapping of XML attribute names from/toMapAccessors.The same key can be added more than once.
- Parameters:
figure- the figurename- The attribute namekey- The key
-
addKeys
Adds the provided mapping of XML attribute names from/toMapAccessors.The same key can be added more than once.
- Parameters:
f- The figurekeys- The mapping from attribute names to keys
-
addNodeListKey
Adds the provided keys to the figure.- Parameters:
figure- the figurename- the element namekey- the keys
-
addSkipAttribute
Adds an attribute to the list of attributes which will be skipped when reading the DOM.- Parameters:
figure- the figure classattributeName- the attribute name
-
addSkipElement
Adds an element to the list of elements which will be skipped when reading the DOM.- Parameters:
elementName- the element name
-
addSkipFigure
Adds a figure class to the list ofFigures which will be skipped when writing the DOM.- Parameters:
figure- The figure class
-
checkConverters
public void checkConverters(boolean throwException, Consumer<String> logger) throws IllegalStateException - Throws:
IllegalStateException
-
clearAttributeMap
public void clearAttributeMap()Clears the mapping of XML attributes from/toMapAccessors. -
clearElementMap
public void clearElementMap()Clears the mapping of XML attributes from/toMapAccessors. -
getKeyByElementName
Description copied from interface:FigureFactoryMaps an XML element name to a key.- Specified by:
getKeyByElementNamein interfaceFigureFactory- Parameters:
f- the figureelementName- the name- Returns:
- the key
- Throws:
IOException- if the factory does not support the name for the specified figure
-
figureAttributeKeys
Description copied from interface:FigureFactoryReturns all keys for the specified figure which should be converted into element attributes.- Specified by:
figureAttributeKeysin interfaceFigureFactory- Parameters:
f- The figure- Returns:
- an immutable set
-
figureNodeListKeys
Description copied from interface:FigureFactoryReturns all keys for the specified figure which should be converted into a node list.- Specified by:
figureNodeListKeysin interfaceFigureFactory- Parameters:
f- The figure- Returns:
- an immutable set
-
getElementNameByFigure
Description copied from interface:FigureFactoryMaps a figure to an XML element name.- Specified by:
getElementNameByFigurein interfaceFigureFactory- Parameters:
f- the figure- Returns:
- the name
- Throws:
IOException- if the factory does not support this figure
-
getDefaultValue
Description copied from interface:FigureFactoryReturns the default for the key. The default value used for persistent storage may be different from the default value defined in the key.- Specified by:
getDefaultValuein interfaceFigureFactory- Type Parameters:
T- The type of the value- Parameters:
f- The figurekey- The key- Returns:
- the default value
-
getIdFactory
public @Nullable org.jhotdraw8.base.converter.IdFactory getIdFactory() -
setIdFactory
public void setIdFactory(@Nullable org.jhotdraw8.base.converter.IdFactory idFactory) -
getObjectIdAttribute
Returns the name of the object id attribute. The object id attribute is used for referencing other objects in the XML file.The default value is "oid".
- Specified by:
getObjectIdAttributein interfaceFigureFactory- Returns:
- name of the object id attribute
-
setObjectIdAttribute
Sets the name of the object id attribute. The object id attribute is used for referencing other objects in the XML file.- Parameters:
newValue- name of the object id attribute
-
isDefaultValue
Description copied from interface:FigureFactoryReturns true if the specified value is the default for the given key.- Specified by:
isDefaultValuein interfaceFigureFactory- Type Parameters:
T- The type of the value- Parameters:
f- The figurekey- The keyvalue- the value- Returns:
- true if the value is the default value
-
getElementNameByKey
Description copied from interface:FigureFactoryMaps a key to a XML element name. The name used for persistent storage may be different from the name defined in the key.The name can be an empty String
""for the key returned byFigureFactory.figureNodeListKeys(org.jhotdraw8.draw.figure.Figure)if the figure has exactly one node list key. In this case, the node list will be added directly as children to the figure. The name of a node list key must not be equal to the name of a figure, because child figure elements are also added as child elements.- Specified by:
getElementNameByKeyin interfaceFigureFactory- Parameters:
f- the figurekey- the key- Returns:
- The name.
- Throws:
IOException- if the factory does not support the key for the specified figure
-
getAttributeNameByKey
Description copied from interface:FigureFactoryMaps a key to a XML attribute name. The name used for persistent storage may be different from the name defined in the key.- Specified by:
getAttributeNameByKeyin interfaceFigureFactory- Parameters:
f- the figurekey- the key- Returns:
- The name.
- Throws:
IOException- if the factory does not support the key for the specified figure
-
createFigureByElementName
Description copied from interface:FigureFactoryCreates a new figure given the name of an XML element.- Specified by:
createFigureByElementNamein interfaceFigureFactory- Parameters:
elementName- the name- Returns:
- the figure
- Throws:
IOException- if the factory does not support this name
-
getKeyByAttributeName
Description copied from interface:FigureFactoryMaps an XML attribute name to a key.- Specified by:
getKeyByAttributeNamein interfaceFigureFactory- Parameters:
f- the figureattributeName- the name- Returns:
- the key
-
nodeListToValue
Description copied from interface:FigureFactoryMaps a XML node list to a value.The node list does not contain elements with a name that conflicts with the names returned by
FigureFactory.getElementNameByFigure(org.jhotdraw8.draw.figure.Figure).- Specified by:
nodeListToValuein interfaceFigureFactory- Type Parameters:
T- the type of the value- Parameters:
key- the keynodeList- the nodeList- Returns:
- the mapped attribute value.
-
removeKey
Globally removes the specified key.- Parameters:
key- the key
-
needsIdResolver
- Specified by:
needsIdResolverin interfaceFigureFactory- Throws:
IOException
-
stringToValue
Description copied from interface:FigureFactoryMaps an XML attribute value to a value.- Specified by:
stringToValuein interfaceFigureFactory- Type Parameters:
T- the type of the value- Parameters:
key- the keystring- the XML attribute value- Returns:
- the mapped value
- Throws:
IOException- if the factory does not support a mapping for the specified key
-
getConverter
protected <T> org.jhotdraw8.base.converter.Converter<T> getConverter(MapAccessor<T> key) throws IOException - Throws:
IOException
-
valueToNodeList
public void valueToNodeList(MapAccessor<?> key, Object value, XMLStreamWriter w) throws XMLStreamException Description copied from interface:FigureFactoryMaps a value to a XML node list.The node list may not contain elements with a name that conflicts with the names returned by
FigureFactory.getElementNameByFigure(org.jhotdraw8.draw.figure.Figure).- Specified by:
valueToNodeListin interfaceFigureFactory- Parameters:
key- the keyvalue- the valuew- the writer for creating the node list.- Throws:
XMLStreamException
-
valueToString
Description copied from interface:FigureFactoryMaps a value to an XML attribute value.- Specified by:
valueToStringin interfaceFigureFactory- Type Parameters:
T- the type of the value- Parameters:
key- the keyvalue- the value- Returns:
- the mapped attribute value
- Throws:
IOException- if the factory does not support a mapping for the specified key
-