public static void TestFactory()
        {
            Console.WriteLine("-- TEST FACTORY --");

            //Factory that creates all shapes but with different factory implementations
            Console.WriteLine("\nShapeFactory");
            IFactory factory  = new FactoryShape();
            IShape   square   = factory.CreateInstance("shapesquare", 5);
            IShape   triangle = factory.CreateInstance("shapetriangle", 5);

            Console.WriteLine(square.GetInfo());
            Console.WriteLine(triangle.GetInfo());

            Console.WriteLine("\nShapeDoubleSideFactory");
            IFactory doubleFactory  = new FactoryShapeDoubleSide();
            IShape   doubleSquare   = doubleFactory.CreateInstance("shapesquare", 5);
            IShape   doubleTriangle = doubleFactory.CreateInstance("shapetriangle", 5);

            Console.WriteLine(doubleSquare.GetInfo());
            Console.WriteLine(doubleTriangle.GetInfo());

            //Load a Factory to create a specific type of ICar
            ICarFactory bmwFactory  = FactoryLoader.GetCarFactory("FactoryBMW");
            ICarFactory miniFactory = FactoryLoader.GetCarFactory("FactoryMiniCooper");
            ICar        bmw         = bmwFactory.CreateInstance();
            ICar        mini        = miniFactory.CreateInstance();

            Console.WriteLine(bmw.TurnOn());
            Console.WriteLine(bmw.TurnOff());
            Console.WriteLine(mini.TurnOn());
            Console.WriteLine(mini.TurnOff());
        }
        //
        public void CreateWindow()
        {
            FactoryShape  factory = FactoryManager.getInstance().GetSelectedTool();
            ElementWindow model   = (ElementWindow)factory.CreateControl();

            m_Window        = (ElementWindow)model;
            model.Container = m_Canvas;

            bool[] hotSpot = { false, false };
            mSceneCanvas.Add(model);

            ElementProperty prop = FactoryActionParam.CreateParam(model);

            model.Property = prop;
            factory.PopulatePropertyList(prop);
            m_GridView.Tag       = prop;
            m_ActionWindow       = new ActionAdd(factory);
            m_ActionWindow.Model = model;
            // Assign a copy of Param.....
            m_ActionWindow.SetParam(prop);
            mHostory.ExcuteAction(m_ActionWindow);

            //mSceneCanvas.Canvas.Invalidate();
            PopulateControlList();
            ElementTracker.Instance.AttachHotSpotObserver(this);
            //m_Window.PropertyChangeObserver = this;
            model.OnSizeChanged();
        }
        //
        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int          index        = m_listItems.SelectedIndex + 1;
            FactoryShape factoryShape = FactoryManager.getInstance().SelectTool(index);
            DrawElement  model        = factoryShape.CreateControl();

            ElementProperty prop   = FactoryActionParam.CreateParam(model);
            int             id     = m_Window.List.Count + 1;
            String          strVal = factoryShape.Name + factoryShape.List.Count.ToString();

            model.Property = prop;
            prop.SetValue("Name", strVal.Trim());
            prop.SetValue("Id", id.ToString());
            prop.SetValue("Location", model.Location.X.ToString() + "," + model.Location.Y.ToString());
            prop.SetValue("Text", model.Text);
            prop.SetValue("Size", model.Width.ToString() + "," + model.Height.ToString());
            //
            factoryShape.PopulatePropertyList(prop);
            m_GridView.Tag = prop;
            //
            Action action = factoryShape.CreateAddAction(model, m_Window);

            action.SetParam(prop);
            mHostory.ExcuteAction(action);
        }
        //
        public void CreateElementWindow(XmlNode node)
        {
            FactoryShape  factory = FactoryManager.getInstance().GetFactory(node.Name);
            ElementWindow model   = (ElementWindow)factory.CreateControl();

            m_Window        = (ElementWindow)model;
            model.Container = m_Canvas;

            bool[] hotSpot = { false, false };
            mSceneCanvas.Add(model);

            ElementProperty prop = FactoryActionParam.CreateParam(model);

            model.Property = prop;
            factory.PopulatePropertyList(prop);
            m_GridView.Tag = prop;

            foreach (XmlAttribute attr in node.Attributes)
            {
                prop.SetValue(attr.Name, attr.Value);
            }

            //FIXME use Factory for action...
            m_ActionWindow       = new ActionAdd(factory);
            m_ActionWindow.Model = model;
            // Assign a copy of Param.....
            m_ActionWindow.SetParam(prop);
            mHostory.ExcuteAction(m_ActionWindow);

            //mSceneCanvas.Canvas.Invalidate();
            PopulateControlList();
            ElementTracker.Instance.AttachHotSpotObserver(this);
            //m_Window.PropertyChangeObserver = this;
            model.OnSizeChanged();

            foreach (XmlNode child in node.ChildNodes)
            {
                // We only need Control elements..
                if (child.Name == "Properties")
                {
                    continue;
                }
                //
                CreateChildlement(child);
            }
        }
        //
        public void CreateChildlement(XmlNode node)
        {
            FactoryShape factoryShape = FactoryManager.getInstance().GetFactory(node.Name);
            DrawElement  model        = factoryShape.CreateControl();

            ElementProperty prop = FactoryActionParam.CreateParam(model);

            model.Property = prop;

            foreach (XmlAttribute attr in node.Attributes)
            {
                prop.SetValue(attr.Name, attr.Value);
            }


            try
            {
                XmlNodeList propertiesNodes = node.FirstChild.ChildNodes;
                foreach (XmlNode nodeProp in propertiesNodes)
                {
                    prop.SetValue(nodeProp.Name, nodeProp.InnerText);
                }
            }
            catch (Exception e)
            {
            }



            factoryShape.PopulatePropertyList(prop);
            m_GridView.Tag = prop;
            Action action = factoryShape.CreateAddAction(model, m_Window);

            action.SetParam(prop);
            //
            mHostory.ExcuteAction(action);
        }
Example #6
0
 public static void Run()
 {
     IShape circle = FactoryShape.GetInstance("rectangle");
     IShape square = FactoryShape.GetInstance("square");
 }
Example #7
0
        public void TestEquilateralTriangleArea()
        {
            var shape = FactoryShape.Create(ShapeType.EquilateralTriangle, 5);

            Assert.AreEqual(shape.Area, 10.83);
        }
Example #8
0
        public void TestCircleArea()
        {
            var shape = FactoryShape.Create(ShapeType.Circle, 5);

            Assert.AreEqual(shape.Area, 78.54);
        }
Example #9
0
        public void TestSquareArea()
        {
            var shape = FactoryShape.Create(ShapeType.Square, 5);

            Assert.AreEqual(shape.Area, 25);
        }
Example #10
0
        public void TestEquilateralTriangleType()
        {
            var shape = FactoryShape.Create(ShapeType.EquilateralTriangle, 5);

            Assert.IsInstanceOfType(shape, typeof(EquilateralTriangle));
        }
Example #11
0
        public void TestCircleType()
        {
            var shape = FactoryShape.Create(ShapeType.Circle, 5);

            Assert.IsInstanceOfType(shape, typeof(Circle));
        }
Example #12
0
        public void TestSquareType()
        {
            var shape = FactoryShape.Create(ShapeType.Square, 5);

            Assert.IsInstanceOfType(shape, typeof(Square));
        }