public static StyleFactory LoadFromFile(string fileName) { StyleFactory result = new StyleFactory(); Memento styles = Memento.ReadFromFile(fileName); foreach (Memento s in styles.Children) { ShapeStyle newStyle = ShapeStyle.CreateFromMemento(s); result.Add(newStyle.Name, newStyle); } return(result); }
public void AddStyle( string name, Color borderColor, Color fillColor, Color fontColor) { ShapeStyle s = new ShapeStyle(); s.FontStyleInfo.ForeColor = fontColor; s.LineColor = borderColor; s.FillColor = fillColor; Add(name, s); }
public SampleStyleFactory() { AddStyle("TextBoxBlock", Color.White, Color.FloralWhite); AddStyle("TextBoxBlock_selected", Color.LightYellow, Color.LightYellow); AddStyle("SampleBlock", Color.White, Color.White); AddStyle("SampleBlock_selected", Color.LightYellow, Color.LightYellow); AddStyle("ButtonBlock", Color.DarkRed, Color.Linen, Color.PeachPuff, FillMode.VerticalGradient); AddStyle("ButtonBlock_selected", Color.DarkRed, Color.Linen, Color.SandyBrown, FillMode.VerticalGradient); AddStyle("LabelBlock", Color.White); AddStyle("LabelBlock_selected", Color.Wheat, Color.LightYellow); AddStyle("TextSelectionBlock", Color.White); AddStyle("SelectionLabelBlock_selected", Color.Wheat, Color.LightYellow); AddStyle("FocusableLabelBlock", Color.White); AddStyle("FocusableLabelBlock_selected", Color.Wheat, Color.LightYellow); AddStyle("TreeViewNode", Color.Transparent, Color.Transparent); AddStyle("TreeViewNode_selected", Color.Wheat, Color.LightYellow); AddStyle("LayoutTestBlock", Color.Black, Color.LightGray); AddStyle("LayoutTestBlock_selected", Color.Black, Color.Gray); ShapeStyle TreeViewStyle = new ShapeStyle(Color.Transparent); TreeViewStyle.FontStyleInfo = RendererSingleton.StyleFactory.ProduceNewFontStyleInfo ("Tahoma", (float) 9, FontStyle.Regular); //TreeViewStyle.FontStyleInfo = // RendererSingleton.StyleFactory.ProduceNewFontStyleInfo // (System.Drawing.SystemFonts.DialogFont.Name, // System.Drawing.SystemFonts.DialogFont.SizeInPoints, // System.Drawing.SystemFonts.DialogFont.Style); Add("TreeViewLabelBlock", TreeViewStyle); }
public void AddStyle( string name, Color borderColor, Color fillColor, Color fontColor, string fontName, int fontSize, FontStyle fontStyle) { ShapeStyle s = new ShapeStyle(); s.LineColor = borderColor; s.FillColor = fillColor; s.FontStyleInfo = RendererSingleton.StyleFactory.ProduceNewFontStyleInfo(fontName, fontSize, fontStyle); s.FontStyleInfo.ForeColor = fontColor; Add(name, s); }
public static ShapeStyle CreateFromMemento(Memento snapshot) { //<ShapeStyle name="TypeName"> // <LineStyle color="16777215" width="1" /> // <FillStyle color="16777215" gradientColor="-1" mode="Solid" /> // <FontStyle color="-13921873" fontName="Consolas" size="10" bold="False" italic="False" underline="False" /> //</ShapeStyle> ShapeStyle result = new ShapeStyle(); result.Name = snapshot["name"]; Memento line = snapshot.FindChild("LineStyle"); if (line != null) { Color foreColor = line.GetColor("color"); int width = line.GetInt("width"); if (width == 0) { width = 1; } result.LineStyleInfo = RendererSingleton.StyleFactory.ProduceNewLineStyleInfo(foreColor, width); } Memento fill = snapshot.FindChild("FillStyle"); if (fill != null) { Color fillColor = fill.GetColor("color"); Color gradientColor = Color.Transparent; FillMode mode = FillMode.Solid; if (!string.IsNullOrEmpty(fill["mode"])) { gradientColor = fill.GetColor("gradientColor"); mode = fill.Get<FillMode>("mode"); } result.FillStyleInfo = RendererSingleton.StyleFactory.ProduceNewFillStyleInfo( fillColor, gradientColor, mode); } Memento font = snapshot.FindChild("FontStyle"); if (font != null) { Color fontColor = font.GetColor("color"); string fontName = font["fontName"]; int size = font.GetInt("size"); bool bold = font.GetBool("bold"); bool italic = font.GetBool("italic"); bool underline = font.GetBool("underline"); FontStyle style = FontStyle.Regular; if (bold) { style |= FontStyle.Bold; } if (italic) { style |= FontStyle.Italic; } if (underline) { style |= FontStyle.Underline; } result.FontStyleInfo = RendererSingleton.StyleFactory.ProduceNewFontStyleInfo( fontName, size, style); result.FontColor = fontColor; } return result; }
public static ShapeStyle CreateFromMemento(Memento snapshot) { //<ShapeStyle name="TypeName"> // <LineStyle color="16777215" width="1" /> // <FillStyle color="16777215" gradientColor="-1" mode="Solid" /> // <FontStyle color="-13921873" fontName="Consolas" size="10" bold="False" italic="False" underline="False" /> //</ShapeStyle> ShapeStyle result = new ShapeStyle(); result.Name = snapshot["name"]; Memento line = snapshot.FindChild("LineStyle"); if (line != null) { Color foreColor = line.GetColor("color"); int width = line.GetInt("width"); if (width == 0) { width = 1; } result.LineStyleInfo = RendererSingleton.StyleFactory.ProduceNewLineStyleInfo(foreColor, width); } Memento fill = snapshot.FindChild("FillStyle"); if (fill != null) { Color fillColor = fill.GetColor("color"); Color gradientColor = Color.Transparent; FillMode mode = FillMode.Solid; if (!string.IsNullOrEmpty(fill["mode"])) { gradientColor = fill.GetColor("gradientColor"); mode = fill.Get <FillMode>("mode"); } result.FillStyleInfo = RendererSingleton.StyleFactory.ProduceNewFillStyleInfo( fillColor, gradientColor, mode); } Memento font = snapshot.FindChild("FontStyle"); if (font != null) { Color fontColor = font.GetColor("color"); string fontName = font["fontName"]; int size = font.GetInt("size"); bool bold = font.GetBool("bold"); bool italic = font.GetBool("italic"); bool underline = font.GetBool("underline"); FontStyle style = FontStyle.Regular; if (bold) { style |= FontStyle.Bold; } if (italic) { style |= FontStyle.Italic; } if (underline) { style |= FontStyle.Underline; } result.FontStyleInfo = RendererSingleton.StyleFactory.ProduceNewFontStyleInfo( fontName, size, style); result.FontColor = fontColor; } return(result); }
/// <summary> /// Is a template method which calls virtual methods /// InitStyle and InitSelectedStyle /// Just override these methods in children classes /// to define a style for a block /// </summary> private void InitStyleBase() { Style = new ShapeStyle(); SelectedStyle = new ShapeStyle(); InitStyle(); InitSelectedStyle(); if (Style == null || SelectedStyle == null) { // TODO: Make a new RecoverableException class // <Kirill 2005-10-30> // what does this mean? // What do you mean by RecoverableException // and why would we need it here? // </Kirill> // most probably RecoverableException could be suppressed // at some outer stage, in contrast to other (unrecoverable) // exceptions which would lead to the // unrecoverable exception / bug report dialog throw new Exception("InitStyle() or InitSelectedStyle() has set the style to a null value."); } }