Nevron .NET Vision Documentation
Styles, Style Composition and Style Sheets

Nevron Diagram for .NET provides a flexible and consistent way for defining the element styles as well as reusing style definitions via different types of style inheritance.

Style Attribute

In Nevron Diagram for .NET the appearance of every element is consistently controlled with the help of a NStyle attribute. The style of an element is used as a place holder for all the atomic styles, which an element may need to display itself.currently the NStyle attribute can contain the following atomic styles:

If the property value corresponding to the respective atomic style is equal to null, then the style has no local setting for this atomic style and the element will try to obtain it via the style inheritance mechanism (explained below). The process of obtaining a valid style reference is called style composition.

A style itself is only used to hold local values for the atomic styles the element may need. It is up to the element to implement the respective style composition.

Style Composition

In Nevron Diagram for .NET all elements, which can be involved in style composition must implement the INStyleComposer interface. A core implementation of this interface can be found in the NStyleComposerElement class. It basically defines ComposeXXX methods, which elements can use to obtain valid atomic style instances.

All elements, which contain a local style attribute must implement the INStyleable interface (derived from INStyleComposer). A core implementation of this interface can be found in the following DOM classes:

The base stylesheet can also have a base stylesheet and so on. This style inheritance feature is often called cascade style sheets.
Style Sheets

Stylesheets are elements, which have a style attribute. The style of a stylesheet can be reused from styleable elements and/or other stylesheets. The stylesheets of a drawing are contained in an instance of the NStyleSheetCollection class, which can be obtained from the StyleSheets property of the NDrawingDocument class. Stylesheets themselves are represented by an instance of the NStyleSheet class.

The following code creates three cascade stylesheets:

C#
Copy Code
NStyleSheet stylesheet1 = new NStyleSheet("BASE");
stylesheet1.Style.StrokeStyle = new NStrokeStyle(2, Color.Blue);
drawingDocument.StyleSheets.AddChild(stylesheet1);
NStyleSheet stylesheet2 = new NStyleSheet("RED");
stylesheet2.BaseStyleSheetName = "BASE";
stylesheet2.Style.FillStyle = new NColorFillStyle(Color.Red);
drawingDocument.StyleSheets.AddChild(stylesheet2);
NStyleSheet stylesheet3 = new NStyleSheet("GREEN");
stylesheet3.BaseStyleSheetName = "BASE";
stylesheet3.Style.FillStyle = new NColorFillStyle(Color.Green);
drawingDocument.StyleSheets.AddChild(stylesheet3);
Visual Basic
Copy Code
Dim stylesheet1 As New NStyleSheet("BASE")
stylesheet1.Style.StrokeStyle = New NStrokeStyle(2, Color.Blue)
drawingDocument.StyleSheets.AddChild(stylesheet1)
Dim stylesheet2 As New NStyleSheet("RED")
stylesheet2.BaseStyleSheetName = "BASE"
stylesheet2.Style.FillStyle = New NColorFillStyle(Color.Red)
drawingDocument.StyleSheets.AddChild(stylesheet2)
Dim stylesheet3 As New NStyleSheet("GREEN")
stylesheet3.BaseStyleSheetName = "BASE"
stylesheet3.Style.FillStyle = New NColorFillStyle(Color.Green)
drawingDocument.StyleSheets.AddChild(stylesheet3)

In this example the first stylesheet defines a blue stroke style and is used as a base stylesheet for the other two stylesheets. The second and the third stylesheets reference the first stylesheet. The base stylesheet is specified by the BaseStyleSheetName property. The second and the third stylesheets define solid color red and green fillings.

The effect of this construction is that when a styleable element (any element derived from the NStyleableElement class - e.g. layer, model, shape, path, label etc.) references the RED stylesheet it will inherit red filling and blue stroke style. Analogously if it references the GREEN stylesheet it will inherit green filling and blue stroke style. The stylesheet of a styleable element is specified by its StyleSheetName property. For example:

C#
Copy Code
NRectangleShape rect1 = new NRectangleShape(50, 50, 100, 100);
rect1.StyleSheetName = "RED";
drawingDocument.ActiveLayer.AddChild(rect1);

NRectangleShape rect2 = new NRectangleShape(200, 50, 100, 100);
rect2.StyleSheetName = "GREEN";
drawingDocument.ActiveLayer.AddChild(rect2); 
Visual Basic
Copy Code
Dim rect1 As New NRectangleShape(50, 50, 100, 100)
rect1.StyleSheetName = "RED"
drawingDocument.ActiveLayer.AddChild(rect1)

Dim rect2 As New NRectangleShape(200, 50, 100, 100)
rect2.StyleSheetName = "GREEN"
drawingDocument.ActiveLayer.AddChild(rect2) 

This code will produce the following drawing:

By default each drawing document has the following stylesheets:

How to Use Styles Efficiently

Styles and style inheritance can greatly help you minimize the effort of designing and changing the appearance of your diagrams. Following are some guidelines, which will help you use these efforts:

Other Considerations

Not all styleable elements create a valid style attribute instance by default. For example the NRectanglePath primitive is a styleable element, but by default its Style property returns null. This was done in order to minimize the memory footprint of primitives. The following code demonstrates how to apply local fill style to a rectangle path:

C#
Copy Code
NRectanglePath rect = new NRectanglePath(0, 0, 100, 100);
rect.Style = new NStyle();
rect.Style.FillStyle = new NColorFillStyle(Color.Red); 
Visual Basic
Copy Code
Dim rect As New NRectanglePath(0, 0, 100, 100)
rect.Style = New NStyle()
rect.Style.FillStyle = New NColorFillStyle(Color.Red) 

The NStyle class provides several static methods, which help you safely create a style attribute and set a respective atomic style. For example:

C#
Copy Code
NRectanglePath rect = new NRectanglePath(0, 0, 100, 100);
NStyle.SetFillStyle(rect, new NColorFillStyle(Color.Red));
Visual Basic
Copy Code
Dim rect As New NRectanglePath(0, 0, 100, 100)
NStyle.SetFillStyle(rect, New NColorFillStyle(Color.Red))
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback