Package com.nomagic.magicdraw.properties
Class Style
- java.lang.Object
-
- com.nomagic.magicdraw.properties.Style
-
- All Implemented Interfaces:
com.nomagic.magicdraw.core.project.options.PersistentStyle
,PropertyVisitorAcceptor
,java.beans.PropertyChangeListener
,java.lang.Cloneable
,java.util.EventListener
@OpenApiAll public class Style extends java.lang.Object implements java.lang.Cloneable, PropertyVisitorAcceptor, java.beans.PropertyChangeListener, com.nomagic.magicdraw.core.project.options.PersistentStyle
Style stores and manages a set ofPropertyManagers
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Style.CollectionWithModificationTracking<T>
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ADDED_STYLE_MANAGER
Deprecated.private java.util.Map<java.lang.String,java.lang.Object>
byName
static java.lang.String
CHANGE_STYLE_PROPERTY
Name of property fired on some style change.static java.lang.String
CHANGE_STYLE_PROPERTY_VALUE
private java.lang.String
id
ID of style, used to restore references from not loaded diagrams.private boolean
isDefault
Style is default one?private java.util.Set<java.lang.String>
knownStereotypes
private com.nomagic.utils.AList<java.beans.PropertyChangeListener>
listeners
The element can registry a property change listeners and fire property change events on some property value change.private static java.util.Comparator<PropertyManager>
MANAGER_BY_NAME_COMPARATOR
The comparator for comparing twoPropertyManagers
by name.private Style.CollectionWithModificationTracking<PropertyManager>
managers
Collection of property managers registered by name.static java.lang.String
MERGED
static java.lang.String
MERGED_PRE1704
private java.lang.String
name
The name of the style.static java.lang.String
SHARED
-
Constructor Summary
Constructors Constructor Description Style()
Constructs new Style.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(PropertyVisitor visitor)
Accepts the given visitor.void
addManager(PropertyManager manager)
Adds given property manager.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Registers the listener to the element.void
append(Style s)
Adds all managers from given style to this style.void
appendExtendedManagers(Style s)
private void
appendManagerByNameCache(PropertyManager manager)
java.util.Map<PropertyManager,PropertyManager>
apply(Style s)
Applies all managers from given style to the existing managers here.private void
changeProperty(Property p)
Replaces existing property in all managers with the given one.java.lang.Object
clone()
/** Creates and returns a copy of this style.protected void
cloneManagers(Style newS)
private void
createManagersList()
private void
fillStereotypes()
static PropertyManager
findPropertyManagerWithPath(Style findIn, java.util.Collection<PropertyManager> path)
static PropertyManager
findPropertyManagerWithSamePath(Style findIn, PropertyManager find)
Finds same property manager(with same path) in given style.private void
firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
DelegatesfirePropertyChange
to thePropertyChangeSupport
, the member of this class, which reports a bound property update to any registered listeners.static void
generateDefaultDescriptionID(Style style)
Generate default description id.void
generateID()
java.lang.String
getClassType()
Returns property class type.private static java.lang.String
getCompareKey(PropertyManager propertyManager)
java.lang.String
getID()
PropertyManager
getManager(java.lang.String name)
Returns property manager with given name.int
getManagerCount()
Returns managers count.java.util.Collection<PropertyManager>
getManagers()
Returns a collection of all managers.java.util.List<PropertyManager>
getManagersFromParent(PropertyManager root)
private java.util.HashMap<java.lang.String,PropertyManager>
getManagersMap()
java.lang.String
getName()
Returns the name of the style.java.util.List<PropertyManager>
getOrderedManagers()
Returns collection of managers sorted by name.boolean
hasStereotype(java.lang.String id)
Check if style has stereotype with given id.boolean
isDefault()
Is this style a default one?boolean
isDiagramStyle()
boolean
isEqual(Style style)
Checks if given style has same property managers with same values.private static boolean
isIDEqual(PropertyManager manager1, PropertyManager manager2)
boolean
isSnapshotStyleForDiagramSymbols()
private java.util.Map<PropertyManager,PropertyManager>
proceedLevel(Style s, PropertyManager parent1, PropertyManager parent2, boolean apply)
void
propertyChange(java.beans.PropertyChangeEvent evt)
On CHANGE_STYLE_PROPERTY property change takes the manager from property's new Value and replaces itself properties with properties from this manager.void
propertyManagerNameChanged(PropertyManager manager)
Called when property manager name is changedprivate void
rebuildByName()
void
removeManager(PropertyManager manager)
Removes given property manager.private void
removeManagerByNameCache(PropertyManager manager)
void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Unregisters the given listener from the element.private void
resetKnownStereotypes()
void
setAppliedPropertyManagerIDs(java.util.Map<PropertyManager,PropertyManager> propertyManagers)
Sets applied property manager id to managers which does not have it.void
setDefault(boolean def)
Sets default flag value.void
setID(java.lang.String id)
Set Idvoid
setManagers(java.util.Collection<PropertyManager> managers)
Sets the collection of all managers.void
setName(java.lang.String name)
Set the name of the style.java.lang.String
toString()
Returns a string representation of the style.void
updateDefinedIn(Style src)
Update allExtendablePropertyManager
in this style defined in.
-
-
-
Field Detail
-
SHARED
public static final java.lang.String SHARED
- See Also:
- Constant Field Values
-
MERGED
public static final java.lang.String MERGED
- See Also:
- Constant Field Values
-
MERGED_PRE1704
public static final java.lang.String MERGED_PRE1704
- See Also:
- Constant Field Values
-
CHANGE_STYLE_PROPERTY
public static final java.lang.String CHANGE_STYLE_PROPERTY
Name of property fired on some style change.- See Also:
- Constant Field Values
-
CHANGE_STYLE_PROPERTY_VALUE
public static final java.lang.String CHANGE_STYLE_PROPERTY_VALUE
- See Also:
- Constant Field Values
-
ADDED_STYLE_MANAGER
@Deprecated public static final java.lang.String ADDED_STYLE_MANAGER
Deprecated.- See Also:
- Constant Field Values
-
managers
private Style.CollectionWithModificationTracking<PropertyManager> managers
Collection of property managers registered by name. Order of managers is not important.
-
byName
@CheckForNull private java.util.Map<java.lang.String,java.lang.Object> byName
-
name
private java.lang.String name
The name of the style.
-
isDefault
private boolean isDefault
Style is default one?
-
listeners
@CheckForNull private com.nomagic.utils.AList<java.beans.PropertyChangeListener> listeners
The element can registry a property change listeners and fire property change events on some property value change. This member keeps a reference to thePropertyChangeSupport
.
-
id
private java.lang.String id
ID of style, used to restore references from not loaded diagrams.
-
MANAGER_BY_NAME_COMPARATOR
private static final java.util.Comparator<PropertyManager> MANAGER_BY_NAME_COMPARATOR
The comparator for comparing twoPropertyManagers
by name.
-
knownStereotypes
@CheckForNull private java.util.Set<java.lang.String> knownStereotypes
-
-
Method Detail
-
getCompareKey
private static java.lang.String getCompareKey(PropertyManager propertyManager)
-
createManagersList
private void createManagersList()
-
addManager
public void addManager(@CheckForNull PropertyManager manager)
Adds given property manager.- Parameters:
manager
- the manager to add.
-
resetKnownStereotypes
private void resetKnownStereotypes()
-
removeManager
public void removeManager(PropertyManager manager)
Removes given property manager.- Parameters:
manager
- the manager to remove.
-
getManagerCount
public int getManagerCount()
Returns managers count.- Returns:
- count of managers.
-
setManagers
public void setManagers(java.util.Collection<PropertyManager> managers)
Sets the collection of all managers.- Parameters:
managers
- a collection of new managers.
-
getName
public java.lang.String getName()
Returns the name of the style.- Returns:
- name of the style.
-
setName
public void setName(java.lang.String name)
Set the name of the style.- Parameters:
name
- the new name of the style.
-
setAppliedPropertyManagerIDs
public void setAppliedPropertyManagerIDs(java.util.Map<PropertyManager,PropertyManager> propertyManagers)
Sets applied property manager id to managers which does not have it.- Parameters:
propertyManagers
- property managers to analyze
-
toString
public java.lang.String toString()
Returns a string representation of the style. Used for debug.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string representation.
-
setDefault
public void setDefault(boolean def)
Sets default flag value.- Parameters:
def
- new flag value.
-
isDefault
public boolean isDefault()
Is this style a default one?- Returns:
- default flag value.
-
clone
public java.lang.Object clone()
/** Creates and returns a copy of this style. Does deep clone.- Overrides:
clone
in classjava.lang.Object
- Returns:
- the clone of this style.
-
cloneManagers
protected void cloneManagers(Style newS)
-
getManagers
public java.util.Collection<PropertyManager> getManagers()
Returns a collection of all managers.- Returns:
- all managers.
-
getOrderedManagers
public java.util.List<PropertyManager> getOrderedManagers()
Returns collection of managers sorted by name.- Returns:
- collection of managers sorted by name.
-
getManager
@CheckForNull public PropertyManager getManager(java.lang.String name)
Returns property manager with given name.- Parameters:
name
- the name of manager.- Returns:
- manager with given name or null.
-
rebuildByName
private void rebuildByName()
-
appendManagerByNameCache
private void appendManagerByNameCache(PropertyManager manager)
-
removeManagerByNameCache
private void removeManagerByNameCache(PropertyManager manager)
-
accept
public void accept(PropertyVisitor visitor) throws java.lang.Exception
Accepts the given visitor.- Specified by:
accept
in interfacePropertyVisitorAcceptor
- Parameters:
visitor
- the PropertyVisitor.- Throws:
java.lang.Exception
-
getClassType
public java.lang.String getClassType()
Returns property class type.- Specified by:
getClassType
in interfacePropertyVisitorAcceptor
- Returns:
- PropertyID.SIMPLE_STYLE
- See Also:
PropertyID.SIMPLE_STYLE
-
append
public void append(Style s)
Adds all managers from given style to this style. If some manager exists in given style, but does not exist in this style - clone this manager and add. If some manager exists in given style and exists in this style - append properties from given manager to this manager.- Parameters:
s
- the given style.
-
apply
public java.util.Map<PropertyManager,PropertyManager> apply(Style s)
Applies all managers from given style to the existing managers here. If some manager exists in given style, but does not exist in this style - do nothing.- Parameters:
s
- the given style.
-
appendExtendedManagers
public void appendExtendedManagers(Style s)
-
proceedLevel
private java.util.Map<PropertyManager,PropertyManager> proceedLevel(Style s, @CheckForNull PropertyManager parent1, @CheckForNull PropertyManager parent2, boolean apply)
-
isDiagramStyle
public boolean isDiagramStyle()
- Returns:
- if it is diagram style
-
changeProperty
private void changeProperty(Property p)
Replaces existing property in all managers with the given one.- Parameters:
p
- the given property.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
On CHANGE_STYLE_PROPERTY property change takes the manager from property's new Value and replaces itself properties with properties from this manager.- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Parameters:
evt
- PropertyChangeEvent.
-
getManagersFromParent
public java.util.List<PropertyManager> getManagersFromParent(@CheckForNull PropertyManager root)
-
isIDEqual
private static boolean isIDEqual(@CheckForNull PropertyManager manager1, @CheckForNull PropertyManager manager2)
-
findPropertyManagerWithSamePath
@CheckForNull public static PropertyManager findPropertyManagerWithSamePath(Style findIn, PropertyManager find)
Finds same property manager(with same path) in given style.- Parameters:
findIn
- style where find manager.find
- manager to find.- Returns:
- found manager, or null if not found.
-
findPropertyManagerWithPath
@CheckForNull public static PropertyManager findPropertyManagerWithPath(Style findIn, java.util.Collection<PropertyManager> path)
-
generateID
public void generateID()
-
getID
public java.lang.String getID()
- Returns:
- Returns the iD. Can return null if ID was not generated. ID is generated only for styles used for not loaded diagrams.
-
setID
public void setID(java.lang.String id)
Set Id- Parameters:
id
- given ID.
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Registers the listener to the element. The given listener will get notifications about property changes in this element.- Parameters:
listener
- thePropertyChangeListener
to be added.- See Also:
PropertyChangeSupport
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Unregisters the given listener from the element. The given listener will not get any notifications about property changes in this element.- Parameters:
listener
- the PropertyChangeListener to be removed.- See Also:
PropertyChangeSupport
-
firePropertyChange
private void firePropertyChange(java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, java.lang.Object newValue)
DelegatesfirePropertyChange
to thePropertyChangeSupport
, the member of this class, which reports a bound property update to any registered listeners. No event is fired if old and new values are equal or null.- Parameters:
propertyName
- the programmatic name of the property that was changed.oldValue
- the old value of the propertynewValue
- the new value of the property- See Also:
PropertyChangeSupport
-
generateDefaultDescriptionID
public static void generateDefaultDescriptionID(Style style)
Generate default description id.- Parameters:
style
- style
-
isSnapshotStyleForDiagramSymbols
public boolean isSnapshotStyleForDiagramSymbols()
- Returns:
- true if style is clone used for diagram style preserving.
-
isEqual
public boolean isEqual(Style style)
Checks if given style has same property managers with same values.- Parameters:
style
- given style.- Returns:
- true if given style has same values as this style.
-
updateDefinedIn
public void updateDefinedIn(Style src)
Update allExtendablePropertyManager
in this style defined in.- Parameters:
src
- source to get defined in values
-
getManagersMap
private java.util.HashMap<java.lang.String,PropertyManager> getManagersMap()
-
hasStereotype
public boolean hasStereotype(java.lang.String id)
Check if style has stereotype with given id. This method is faster than iterate through all property managers.- Parameters:
id
- stereotype id- Returns:
- true if stereotype with given id has property manager in this style.
-
fillStereotypes
private void fillStereotypes()
-
propertyManagerNameChanged
public void propertyManagerNameChanged(PropertyManager manager)
Called when property manager name is changed- Parameters:
manager
- manager which name is changed
-
-