예제 #1
0
        static void Main(string[] args)
        {
            IComponent <string> album = new Composite <string>("Album");
            IComponent <string> point = album;

            string[] s;
            string   command, parameter;

            Stream       stream   = new FileStream("Composite.dat", FileMode.Open);
            StreamReader instream = new StreamReader(stream);

            do
            {
                string t = instream.ReadLine();
                Console.WriteLine("\t\t\t\t" + t);
                s       = t.Split();
                command = s[0];

                if (s.Length > 1)
                {
                    parameter = s[1];
                }
                else
                {
                    parameter = null;
                }

                switch (command)
                {
                case "AddSet":
                    IComponent <string> c = new Composite <string>(parameter);
                    point.Add(c);
                    point = c;
                    break;

                case "AddPhoto":
                    point.Add(new Component <string>(parameter));
                    break;

                case "Remove":
                    point = point.Remove(parameter);
                    break;

                case "Find":
                    point = album.Find(parameter);
                    break;

                case "Display":
                    Console.WriteLine(album.Display(0));
                    break;

                case "Quit":
                    break;

                default:
                    break;
                }
            }while (!command.Equals("Quit"));
        }
예제 #2
0
        static void Main()
        {
            IComponent <string> album   = new Composite <string>("Album");
            IComponent <string> point   = album;
            IComponent <string> archive = new Composite <string>("Archive");

            string[] s; string command, parameter;

            // Create and manipulate a structure
            StreamReader instream = new StreamReader("prototype.dat");

            do
            {
                string t = instream.ReadLine();
                Console.WriteLine("\t\t\t\t" + t);
                s       = t.Split();
                command = s[0];
                if (s.Length > 1)
                {
                    parameter = s[1];
                }
                else
                {
                    parameter = null;
                }
                switch (command)
                {
                case "AddSet":
                    IComponent <string> c = new Composite <string>(parameter);
                    point.Add(c);
                    point = c;
                    break;

                case "AddPhoto": point.Add(new Component <string>(parameter)); break;

                case "Remove": point = point.Remove(parameter); break;

                case "Find": point = album.Find(parameter); break;

                case "Display":
                    if (parameter == null)
                    {
                        Console.WriteLine(album.Display(0));
                    }
                    else
                    {
                        Console.WriteLine(archive.Display(0));
                    }
                    break;

                case "Archive": archive = point.Share(parameter, archive); break;

                case "Retrieve": point = archive.Share(parameter, album); break;

                case "Quit": break;
                }
            }while (!command.Equals("Quit"));
        }
        private void InitializeColorComponents()
        {
            reds    = new Composite <Rectangle>();
            blues   = new Composite <Rectangle>();
            yellows = new Composite <Rectangle>();

            var AllColors = typeof(Colors).GetRuntimeProperties().Select(x => new { Color = (Color)x.GetValue(null), Name = x.Name });

            foreach (var color in AllColors)
            {
                if (color.Name.ToLower().Contains("blue"))
                {
                    blues.Add(new Component <Rectangle>(CreateRectItem(new SolidColorBrush(color.Color))));
                }
                else if (color.Name.ToLower().Contains("yellow"))
                {
                    yellows.Add(new Component <Rectangle>(CreateRectItem(new SolidColorBrush(color.Color))));
                }
                else if (color.Name.ToLower().Contains("red"))
                {
                    reds.Add(new Component <Rectangle>(CreateRectItem(new SolidColorBrush(color.Color))));
                }
            }

            redGridView.ItemsSource    = CreateRectList(reds);
            blueGridView.ItemsSource   = CreateRectList(blues);
            yellowGridView.ItemsSource = CreateRectList(yellows);
        }
예제 #4
0
        public IComponent <T> Share(T set, IComponent <T> toHere)
        {
            IPrototype <IComponent <T> > prototype = this.Find(set) as IPrototype <IComponent <T> >;
            IComponent <T> copy = prototype.Clone() as IComponent <T>;

            toHere.Add(copy);
            return(toHere);
        }
        public override void Init()
        {
            IComponent <string> album = new Component <string>("Album");
            IComponent <string> point = album;

            string[] s;
            string   command, parameter;
            //create and manipulate a structure
            StreamReader instream = new StreamReader(@"Structural\Composite\Composite.dat");

            do
            {
                string t = instream.ReadLine();
                Console.WriteLine("\t\t\t\t" + t);
                s         = t.Split();
                command   = s[0];
                parameter = s.Length > 1 ? s[1] : null;
                switch (command)
                {
                case "AddSet":
                    IComponent <string> c = new Composite <string>(parameter);
                    point.Add(c);
                    point = c;
                    break;

                case "AddPhoto":
                    point.Add(new Component <string>(parameter));
                    break;

                case "Remove":
                    point = point.Remove(parameter);
                    break;

                case "Find":
                    point = album.Find(parameter);
                    break;

                case "Display":
                    Console.WriteLine(album.Display(0));
                    break;

                case "Quit":
                    break;
                }
            } while (!command.Equals("Quit"));
        }
예제 #6
0
        private static void AddChildren(IComponent p, int level, string name)
        {
            Composite leaf = new Composite();

            leaf.Level = level;
            leaf.Name  = name;
            p.Add(leaf);
        }
예제 #7
0
        public void CreateComponent()
        {
            _rect = new Rectangle();
            IComponent circle  = new Circle();
            IComponent circlea = new Circle();
            IComponent circleb = new Circle();
            IComponent text    = new Text();
            IComponent texta   = new Text();
            IComponent textb   = new Text();

            circle.Add(text);
            circlea.Add(texta);
            circle.Add(circlea);
            _rect.Add(circle);
        }
예제 #8
0
        private void btnComposite_Click(object sender, EventArgs e)
        {
            IComponent <string> album = new Composite <string>("Album");
            IComponent <string> point = album;

            string [] s;
            string    command, parameter;

            txtResult.Text = "";
            StreamReader instream = new StreamReader("Composite.txt");

            do
            {
                string line = instream.ReadLine();
                if (line == null)
                {
                    return;
                }

                txtResult.Text += line + Environment.NewLine;

                s       = line.Split();
                command = s[0];

                if (s.Length > 1)
                {
                    parameter = s[1];
                }
                else
                {
                    parameter = null;
                }

                switch (command)
                {
                case "AddSet":
                    IComponent <string> c = new Composite <string>(parameter);
                    point.Add(c);
                    point = c;
                    break;

                case "AddPhoto":
                    point.Add(new Component <string>(parameter));
                    break;

                case "Remove":
                    point = point.Remove(parameter);
                    break;

                case "Find":
                    point = album.Find(parameter);
                    break;

                case "Display":
                    txtResult.Text += album.Display(0) + Environment.NewLine;
                    break;

                case "Quit":
                    break;
                }
            } while (!command.Equals("Quit"));
        }