Пример #1
0
        public override void load(StreamReader sr)
        {
            string[] data = sr.ReadLine().Split();
            int      n    = Int32.Parse(data[0]);

            brush.setColor(System.Drawing.ColorTranslator.FromHtml(data[1]));
            brush.setBrushW(Int32.Parse(data[2]));
            x     = Int32.Parse(data[3]);
            y     = Int32.Parse(data[4]);
            R     = Double.Parse(data[5]);
            angle = float.Parse(data[6]);


            FactoryShape factory   = new FactoryShape();
            string       className = "";
            char         ch        = (char)sr.Read();

            for (int i = 0; i < n; i++)
            {
                while (ch != ' ')
                {
                    className += ch;
                    ch         = (char)sr.Read();
                }

                Shape shape = factory.createShape(className);
                shape.load(sr);
                if (shape.brush.isSelect())
                {
                    shape.brush.select();
                }
                calcWH((VShape)shape);
                className = "";
                if (i < n - 1)
                {
                    ch = (char)sr.Read();
                }
                children.Add(shape);
            }
        }
Пример #2
0
        public void loadShapes(Iterator <Shape> it)
        {
            StreamReader sr = new StreamReader(Form1.mainPath, System.Text.Encoding.Default);

            try {
                int n = Int32.Parse(sr.ReadLine());
                if (n > 0)
                {
                    Clear();
                    FactoryShape factory   = new FactoryShape();
                    string       className = "";
                    char         ch        = (char)sr.Read();
                    for (int i = 0; i < n; i++)
                    {
                        while (ch != ' ')
                        {
                            className += ch;
                            ch         = (char)sr.Read();
                        }
                        Shape shape = factory.createShape(className);

                        if (shape != null)
                        {
                            shape.load(sr);
                            className = "";
                            ch        = (char)sr.Read();
                            it.addNext(shape);
                        }
                    }
                }
                sr.Close();
            } catch (Exception e) {
                //
            } finally {
                sr.Dispose();
            }

            notifyAll();
        }
Пример #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            brush_w         = bar_pen_w.Value;
            starVertexCount = 5;

            curColor        = Color.Black;
            backgroundColor = SystemColors.ControlLight;
            gr = this.CreateGraphics();

            cont         = new Container <Shape>();
            contObserver = new ContainerObs(treeView1.Nodes);
            cont.addObserver(contObserver);     // подпишемся на события контейнера для treeView

            rand      = new Random();
            factory   = new FactoryShape();
            iter      = cont.iterator();
            paintIter = cont.iterator();

            commands      = new Dictionary <char, Command>();
            commands['8'] = new MoveCommand(0, -STEP);        // up
            commands['4'] = new MoveCommand(-STEP, 0);        // left
            commands['2'] = new MoveCommand(0, STEP);         // down
            commands['6'] = new MoveCommand(STEP, 0);         // right

            commands['7'] = new RotationCommand(-ROTATION_K); // rot L
            commands['9'] = new RotationCommand(ROTATION_K);  // rot R

            commands['+'] = new SizeCommand(STEP);            // size +
            commands['-'] = new SizeCommand(-STEP);           // size -
            //commands['c'] = new DrawCommand(gr, "Circle");

            history = new Stack <Command>();

            openFileDialog        = new OpenFileDialog();
            saveFileDialog        = new SaveFileDialog();
            openFileDialog.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
            saveFileDialog.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
        }